Skip to content

Commit

Permalink
Moesif policy (#244)
Browse files Browse the repository at this point in the history
* new moesif policy docs

* oops, fixed

* updated sidebar and typo

* fixed link
  • Loading branch information
joshtwist authored Oct 5, 2023
1 parent 0f3c283 commit 737b142
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"editor.wordWrap": "bounded",
"editor.wordWrapColumn": 80
},
"cSpell.words": ["Amberflo", "asns", "overridable", "Supabase"]
"cSpell.words": ["Amberflo", "asns", "Moesif", "overridable", "Supabase"]
}
22 changes: 22 additions & 0 deletions policies/moesif-inbound/doc.md
Original file line number Diff line number Diff line change
@@ -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",
},
});
```
9 changes: 9 additions & 0 deletions policies/moesif-inbound/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions policies/moesif-inbound/intro.md
Original file line number Diff line number Diff line change
@@ -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.
57 changes: 57 additions & 0 deletions policies/moesif-inbound/schema.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
}
}
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down

1 comment on commit 737b142

@vercel
Copy link

@vercel vercel bot commented on 737b142 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./

docs.zuplosite.com
docs-git-main.zuplosite.com
docs-site.zuplosite.com
docs.zuplopreview.net

Please sign in to comment.