diff --git a/.vscode/settings.json b/.vscode/settings.json index 1cdce9cd..7f5a17e5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,5 +12,5 @@ "editor.wordWrap": "bounded", "editor.wordWrapColumn": 80 }, - "cSpell.words": ["Amberflo", "asns", "overridable", "Supabase"] + "cSpell.words": ["Amberflo", "asns", "Moesif", "overridable", "Supabase"] } diff --git a/policies/moesif-inbound/doc.md b/policies/moesif-inbound/doc.md new file mode 100644 index 00000000..b1cadb1e --- /dev/null +++ b/policies/moesif-inbound/doc.md @@ -0,0 +1,22 @@ +By default, Zuplo will read the `request.user.sub` property and assign this as +the moesif `user_id` attribute when sending to Moesif. However, this and the +following attributes can be overriden in a +[custom code policy](/docs/policies/custom-code-inbound). + +- `api_version` +- `company_id` +- `session_token` +- `user_id` +- `metadata` + +Here is some example code that shows how to override two of these attributes + +```ts +setMoesifContext(context, { + userId: "user-1234", + metadata: { + some: "arbitrary", + meta: "data", + }, +}); +``` diff --git a/policies/moesif-inbound/icon.svg b/policies/moesif-inbound/icon.svg new file mode 100644 index 00000000..74e4a3d3 --- /dev/null +++ b/policies/moesif-inbound/icon.svg @@ -0,0 +1,9 @@ + + + moesif-logo + + + + \ No newline at end of file diff --git a/policies/moesif-inbound/intro.md b/policies/moesif-inbound/intro.md new file mode 100644 index 00000000..ad805867 --- /dev/null +++ b/policies/moesif-inbound/intro.md @@ -0,0 +1,6 @@ +Moesif [moesif.com](https://moesif.com) is an API analytics and monetization +platform. This policy allows you to measure (and meter) API calls flowing +through your Zuplo gateway. + +Add the policy to each route you want to meter. Note you can specify the Meter +API Name and Meter Value (meter increment) at the policy level. diff --git a/policies/moesif-inbound/schema.json b/policies/moesif-inbound/schema.json new file mode 100644 index 00000000..2c59ecb9 --- /dev/null +++ b/policies/moesif-inbound/schema.json @@ -0,0 +1,57 @@ +{ + "$schema": "https://json-schema.org/draft-07/schema", + "$id": "http://zuplo.com/schemas/policies/open-id-jwt-auth-inbound.json", + "type": "object", + "title": "Moesif Analytics & Billing", + "isPreview": false, + "description": "Moesif is an API analytics and billing service. This policy allows you to send metering calls for each API to their events batch endpoint.", + "required": ["handler"], + "properties": { + "handler": { + "type": "object", + "default": {}, + "required": ["export", "module", "options"], + "properties": { + "export": { + "const": "MoesifInboundPolicy", + "description": "The name of the exported type" + }, + "module": { + "const": "$import(@zuplo/runtime)", + "description": "The module containing the policy" + }, + "options": { + "type": "object", + "description": "The options for this policy. Many of them can be overridden at the code level in a request using the `AmberfloMeteringPolicy.setRequestProperties` method.", + "required": ["apiKey"], + "properties": { + "applicationId": { + "type": "string", + "description": "Your Moesif application ID (required)" + }, + "logRequestBody": { + "type": "boolean", + "description": "Set to false to disable sending the request body to Moesif (optional)" + }, + "logResponseBody": { + "type": "boolean", + "description": "Set to false to disable sending the response body to Moesif (optional)" + } + } + } + }, + "examples": [ + { + "_name": "basic", + "module": "$import(@zuplo/runtime)", + "export": "AmberfloMeteringInboundPolicy", + "options": { + "applicationId": "YOUR_MOESIF_APPLICATION_ID", + "logRequestBody": true, + "logResponseBody": true + } + } + ] + } + } +} diff --git a/sidebars.js b/sidebars.js index 05a24ef4..62802f4f 100644 --- a/sidebars.js +++ b/sidebars.js @@ -167,6 +167,7 @@ const sidebars = { label: "Metrics, Billing & Quotas", items: [ "policies/quota-inbound", + "policies/moesif-inbound", "policies/amberflo-metering-inbound", "policies/readme-metrics-inbound", ],