zuplo 6.72.13 → 6.72.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/docs/articles/migrate-from-apigee.md +1 -1
  2. package/docs/articles/migrate-from-azure-apim.md +1 -1
  3. package/docs/articles/migrate-from-kong.md +4 -4
  4. package/docs/articles/waf-ddos-akamai.md +6 -6
  5. package/docs/articles/waf-ddos-aws-waf-shield.mdx +6 -6
  6. package/docs/articles/waf-ddos-fastly.mdx +6 -6
  7. package/docs/articles/waf-ddos.mdx +1 -1
  8. package/docs/concepts/authentication.mdx +2 -1
  9. package/docs/concepts/request-lifecycle.mdx +1 -1
  10. package/docs/policies/_index.md +1 -13
  11. package/docs/policies/ai-gateway-model-routing-v2-inbound/doc.md +162 -0
  12. package/docs/policies/ai-gateway-model-routing-v2-inbound/intro.md +19 -0
  13. package/docs/policies/ai-gateway-model-routing-v2-inbound/schema.json +263 -0
  14. package/docs/policies/graphql-cache-inbound/doc.md +1 -1
  15. package/package.json +4 -4
  16. package/docs/policies/ab-test-inbound/intro.md +0 -8
  17. package/docs/policies/ab-test-inbound/policy.ts +0 -14
  18. package/docs/policies/ab-test-inbound/schema.json +0 -27
  19. package/docs/policies/ab-test-outbound/intro.md +0 -8
  20. package/docs/policies/ab-test-outbound/policy.ts +0 -26
  21. package/docs/policies/ab-test-outbound/schema.json +0 -27
  22. package/docs/policies/acl-policy-inbound/intro.md +0 -5
  23. package/docs/policies/acl-policy-inbound/policy.ts +0 -32
  24. package/docs/policies/acl-policy-inbound/schema.json +0 -52
  25. package/docs/policies/archive-request-aws-s3-inbound/intro.md +0 -4
  26. package/docs/policies/archive-request-aws-s3-inbound/policy.ts +0 -58
  27. package/docs/policies/archive-request-aws-s3-inbound/schema.json +0 -68
  28. package/docs/policies/archive-request-azure-storage-inbound/doc.md +0 -31
  29. package/docs/policies/archive-request-azure-storage-inbound/intro.md +0 -4
  30. package/docs/policies/archive-request-azure-storage-inbound/policy.ts +0 -54
  31. package/docs/policies/archive-request-azure-storage-inbound/schema.json +0 -53
  32. package/docs/policies/archive-request-gcp-storage-inbound/doc.md +0 -63
  33. package/docs/policies/archive-request-gcp-storage-inbound/intro.md +0 -4
  34. package/docs/policies/archive-request-gcp-storage-inbound/policy.ts +0 -68
  35. package/docs/policies/archive-request-gcp-storage-inbound/schema.json +0 -47
  36. package/docs/policies/archive-response-aws-s3-outbound/intro.md +0 -2
  37. package/docs/policies/archive-response-aws-s3-outbound/policy.ts +0 -59
  38. package/docs/policies/archive-response-aws-s3-outbound/schema.json +0 -68
  39. package/docs/policies/archive-response-azure-storage-outbound/doc.md +0 -31
  40. package/docs/policies/archive-response-azure-storage-outbound/intro.md +0 -3
  41. package/docs/policies/archive-response-azure-storage-outbound/policy.ts +0 -54
  42. package/docs/policies/archive-response-azure-storage-outbound/schema.json +0 -53
  43. package/docs/policies/hmac-auth-inbound/doc.md +0 -30
  44. package/docs/policies/hmac-auth-inbound/intro.md +0 -10
  45. package/docs/policies/hmac-auth-inbound/policy.ts +0 -70
  46. package/docs/policies/hmac-auth-inbound/schema.json +0 -53
  47. package/docs/policies/ip-restriction-inbound/intro.md +0 -8
  48. package/docs/policies/ip-restriction-inbound/policy.ts +0 -40
  49. package/docs/policies/ip-restriction-inbound/schema.json +0 -58
  50. package/docs/policies/rbac-policy-inbound/intro.md +0 -3
  51. package/docs/policies/rbac-policy-inbound/policy.ts +0 -42
  52. package/docs/policies/rbac-policy-inbound/schema.json +0 -52
  53. package/docs/policies/transform-body-inbound/intro.md +0 -8
  54. package/docs/policies/transform-body-inbound/policy.ts +0 -16
  55. package/docs/policies/transform-body-inbound/schema.json +0 -27
  56. package/docs/policies/transform-body-outbound/intro.md +0 -8
  57. package/docs/policies/transform-body-outbound/policy.ts +0 -19
  58. package/docs/policies/transform-body-outbound/schema.json +0 -27
@@ -1,70 +0,0 @@
1
- import { HttpProblems, ZuploContext, ZuploRequest } from "@zuplo/runtime";
2
-
3
- interface PolicyOptions {
4
- secret: string;
5
- headerName: string;
6
- }
7
-
8
- export default async function (
9
- request: ZuploRequest,
10
- context: ZuploContext,
11
- options: PolicyOptions,
12
- policyName: string,
13
- ) {
14
- // Validate the policy options
15
- if (typeof options.secret !== "string") {
16
- throw new Error(
17
- `The option 'secret' on policy '${policyName}' must be a string. Received ${typeof options.secret}.`,
18
- );
19
- }
20
- if (typeof options.headerName !== "string") {
21
- throw new Error(
22
- `The option 'headerName' on policy '${policyName}' must be a string. Received ${typeof options.headerName}.`,
23
- );
24
- }
25
-
26
- // Get the authorization header
27
- const token = request.headers.get(options.headerName);
28
-
29
- // No auth header, unauthorized
30
- if (!token) {
31
- return HttpProblems.unauthorized(request, context);
32
- }
33
-
34
- // Convert the hex encoded token to an Uint8Array
35
- const tokenData = new Uint8Array(
36
- token.match(/../g)!.map((h) => parseInt(h, 16)),
37
- );
38
-
39
- // Get the data to verify
40
- // This could be anything (headers, query parameter, etc.)
41
- // For this example, we will just verify the entire body value
42
- const data = await request.text();
43
-
44
- // Create a crypto key from a secret stored as an environment variable
45
- const encoder = new TextEncoder();
46
- const encodedSecret = encoder.encode(options.secret);
47
- const key = await crypto.subtle.importKey(
48
- "raw",
49
- encodedSecret,
50
- { name: "HMAC", hash: "SHA-256" },
51
- false,
52
- ["verify"],
53
- );
54
-
55
- // Verify that the data
56
- const verified = await crypto.subtle.verify(
57
- "HMAC",
58
- key,
59
- tokenData,
60
- encoder.encode(data),
61
- );
62
-
63
- // Check if the data is verified, if not return unauthorized
64
- if (!verified) {
65
- return HttpProblems.unauthorized(request, context);
66
- }
67
-
68
- // Request is authorized, continue
69
- return request;
70
- }
@@ -1,53 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft-07/schema",
3
- "$id": "http://zuplo.com/schemas/policies/hmac-auth-inbound.json",
4
- "type": "object",
5
- "title": "HMAC Auth",
6
- "isCustom": true,
7
- "products": ["api-gateway"],
8
- "description": "Authenticate requests using the HMAC-SHA256 authentication scheme.",
9
- "required": ["handler"],
10
- "properties": {
11
- "handler": {
12
- "type": "object",
13
- "default": {},
14
- "required": ["export", "module", "options"],
15
- "properties": {
16
- "export": {
17
- "const": "default",
18
- "description": "The export from the custom policy"
19
- },
20
- "module": {
21
- "const": "$import(./modules/YOUR_MODULE)",
22
- "description": "The module containing the policy"
23
- },
24
- "options": {
25
- "type": "object",
26
- "description": "The options for this policy",
27
- "required": ["secret", "headerName"],
28
- "properties": {
29
- "secret": {
30
- "type": "string",
31
- "description": "The secret to use for HMAC authentication"
32
- },
33
- "headerName": {
34
- "type": "string",
35
- "description": "The header where the HMAC signature is send"
36
- }
37
- }
38
- }
39
- },
40
- "examples": [
41
- {
42
- "_name": "basic",
43
- "export": "default",
44
- "module": "$import(./modules/YOUR_MODULE)",
45
- "options": {
46
- "secret": "$env(MY_SECRET)",
47
- "headerName": "signed-request"
48
- }
49
- }
50
- ]
51
- }
52
- }
53
- }
@@ -1,8 +0,0 @@
1
- This custom policy allows you to specify a set of IP addresses that are allowed
2
- or blocked from making requests on your API. This can be useful for adding
3
- light-weight security to your API in non-critical scenarios. For example, if you
4
- want to ensure only employees on your corporate VPN can't access development
5
- environments.
6
-
7
- Generally, this policy shouldn't be relied upon as the only security for
8
- protecting sensitive workloads.
@@ -1,40 +0,0 @@
1
- import { HttpProblems, ZuploContext, ZuploRequest } from "@zuplo/runtime";
2
- import ipRangeCheck from "ip-range-check";
3
-
4
- interface PolicyOptions {
5
- allowedIpAddresses?: string[];
6
- blockedIpAddresses?: string[];
7
- }
8
-
9
- export default async function (
10
- request: ZuploRequest,
11
- context: ZuploContext,
12
- options: PolicyOptions,
13
- policyName: string,
14
- ) {
15
- // TODO: Validate the policy options. Skipping in the example for brevity
16
-
17
- // Get the incoming IP address
18
- const ip = request.headers.get("true-client-ip");
19
-
20
- // If the allowed IP addresses are set, then the incoming IP
21
- // must be in that list
22
- if (options.allowedIpAddresses) {
23
- const allowed = ipRangeCheck(ip, options.allowedIpAddresses);
24
- if (!allowed) {
25
- return HttpProblems.unauthorized(request, context);
26
- }
27
- }
28
-
29
- // If the blocked IP addresses are set, then the incoming IP
30
- // can't be in that list
31
- if (options.blockedIpAddresses) {
32
- const blocked = ipRangeCheck(ip, options.blockedIpAddresses);
33
- if (blocked) {
34
- return HttpProblems.unauthorized(request, context);
35
- }
36
- }
37
-
38
- // If we made it this far, the IP address is allowed, continue
39
- return request;
40
- }
@@ -1,58 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft-07/schema",
3
- "$id": "http://zuplo.com/schemas/policies/ip-restriction-inbound.json",
4
- "type": "object",
5
- "title": "IP Restriction",
6
- "isCustom": true,
7
- "products": ["api-gateway"],
8
- "description": "Block or allow requests based on their IP address.",
9
- "required": ["handler"],
10
- "properties": {
11
- "handler": {
12
- "type": "object",
13
- "default": {},
14
- "required": ["export", "module", "options"],
15
- "properties": {
16
- "export": {
17
- "const": "default",
18
- "description": "The name of the exported type"
19
- },
20
- "module": {
21
- "const": "$import(./modules/YOUR_MODULE)",
22
- "description": "The module containing the policy"
23
- },
24
- "options": {
25
- "type": "object",
26
- "description": "The options for this policy",
27
- "required": [],
28
- "properties": {
29
- "allowedIpAddresses": {
30
- "type": "array",
31
- "items": {
32
- "type": "string"
33
- },
34
- "description": "The IP addresses or CIDR ranges to allow"
35
- },
36
- "blockedIpAddresses": {
37
- "type": "array",
38
- "items": {
39
- "type": "string"
40
- },
41
- "description": "The IP addresses or CIDR ranges to allow"
42
- }
43
- }
44
- }
45
- },
46
- "examples": [
47
- {
48
- "_name": "basic",
49
- "export": "default",
50
- "module": "$import(./modules/YOUR_MODULE)",
51
- "options": {
52
- "allowedIpAddresses": ["184.42.1.4", "102.1.5.2/24"]
53
- }
54
- }
55
- ]
56
- }
57
- }
58
- }
@@ -1,3 +0,0 @@
1
- RBAC policies can be built many ways depending on your requirements. This
2
- example shows how to perform a simple check of whether or not the current user
3
- is a member of a set of allowed roles.
@@ -1,42 +0,0 @@
1
- import { HttpProblems, ZuploContext, ZuploRequest } from "@zuplo/runtime";
2
-
3
- interface PolicyOptions {
4
- allowedRoles: string[];
5
- }
6
-
7
- export default async function (
8
- request: ZuploRequest,
9
- context: ZuploContext,
10
- options: PolicyOptions,
11
- policyName: string,
12
- ) {
13
- // Check that an authenticated user is set
14
- // NOTE: This policy requires an authentication policy to run before
15
- if (!request.user) {
16
- context.log.error(
17
- "User isn't authenticated. A authorization policy must come before the RBAC policy.",
18
- );
19
- return HttpProblems.unauthorized(request, context);
20
- }
21
-
22
- // Check that the user has roles
23
- if (!request.user.data.roles) {
24
- context.log.error("The user isn't assigned any roles.");
25
- return HttpProblems.unauthorized(request, context);
26
- }
27
-
28
- // Check that the user has one of the allowed roles
29
- if (
30
- !options.allowedRoles.some((allowedRole) =>
31
- request.user?.data.roles.includes(allowedRole),
32
- )
33
- ) {
34
- context.log.error(
35
- `The user '${request.user.sub}' isn't authorized to perform this action.`,
36
- );
37
- return HttpProblems.forbidden(request, context);
38
- }
39
-
40
- // If they made it here, they are authorized
41
- return request;
42
- }
@@ -1,52 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft-07/schema",
3
- "$id": "http://zuplo.com/schemas/policies/acl-policy-inbound.json",
4
- "type": "object",
5
- "title": "RBAC Authorization",
6
- "isCustom": true,
7
- "products": ["api-gateway"],
8
- "description": "The RBAC authorization inbound policy limits access to resources based on the roles of the authenticated user.",
9
- "required": ["handler"],
10
- "properties": {
11
- "handler": {
12
- "type": "object",
13
- "default": {},
14
- "required": ["export", "module", "options"],
15
- "properties": {
16
- "export": {
17
- "const": "default",
18
- "description": "The name of the exported type"
19
- },
20
- "module": {
21
- "const": "$import(./modules/YOUR_MODULE)",
22
- "description": "The module containing the policy"
23
- },
24
- "options": {
25
- "type": "object",
26
- "description": "The options for this policy",
27
- "required": ["policies"],
28
- "properties": {
29
- "allowedRoles": {
30
- "type": "array",
31
- "default": [],
32
- "description": "The roles allowed to access the resource",
33
- "items": {
34
- "type": "string"
35
- }
36
- }
37
- }
38
- }
39
- },
40
- "examples": [
41
- {
42
- "_name": "basic",
43
- "export": "default",
44
- "module": "$import(./modules/YOUR_MODULE)",
45
- "options": {
46
- "allowedRoles": ["admin", "editor"]
47
- }
48
- }
49
- ]
50
- }
51
- }
52
- }
@@ -1,8 +0,0 @@
1
- This example policy shows how to use `request.json()` to read the incoming
2
- request as a JSON object. The object can then be modified as appropriate. It's
3
- then converted back to a string and a new `Request` is returned in the policy
4
- with the new body.
5
-
6
- If the incoming request body isn't JSON, you can use `request.text()` or
7
- `request.blob()` to access the contents as raw text or a
8
- [blob](https://developer.mozilla.org/en-US/docs/Web/API/Request/blob).
@@ -1,16 +0,0 @@
1
- import { ZuploContext, ZuploRequest } from "@zuplo/runtime";
2
-
3
- export default async function (request: ZuploRequest, context: ZuploContext) {
4
- // Get the incoming body as an Object
5
- const obj = await request.json();
6
-
7
- // Modify the object as required
8
- obj.myNewProperty = "Hello World";
9
-
10
- // Stringify the object
11
- const body = JSON.stringify(obj);
12
-
13
- // Return a new request based on the
14
- // original but with the new body
15
- return new ZuploRequest(request, { body });
16
- }
@@ -1,27 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft-07/schema",
3
- "$id": "http://zuplo.com/schemas/policies/transform-body-inbound.json",
4
- "type": "object",
5
- "title": "Transform Request Body",
6
- "isCustom": true,
7
- "products": ["api-gateway"],
8
- "description": "Transform the body of an incoming request.",
9
- "required": ["handler"],
10
- "properties": {
11
- "handler": {
12
- "type": "object",
13
- "default": {},
14
- "required": ["export", "module"],
15
- "properties": {
16
- "export": {
17
- "const": "default",
18
- "description": "The export from the custom policy"
19
- },
20
- "module": {
21
- "const": "$import(./modules/YOUR_MODULE)",
22
- "description": "The module containing the policy"
23
- }
24
- }
25
- }
26
- }
27
- }
@@ -1,8 +0,0 @@
1
- This example policy shows how to use `response.json()` to read the outgoing
2
- response as a JSON object. The object can then be modified as appropriate. It's
3
- then converted back to a string and a new `Response` is returned in the policy
4
- with the new body.
5
-
6
- If the incoming response body isn't JSON, you can use `response.text()` or
7
- `response.blob()` to access the contents as raw text or a
8
- [blob](https://developer.mozilla.org/en-US/docs/Web/API/Response/blob).
@@ -1,19 +0,0 @@
1
- import { ZuploContext, ZuploRequest } from "@zuplo/runtime";
2
-
3
- export default async function (
4
- response: Response,
5
- request: ZuploRequest,
6
- context: ZuploContext,
7
- ) {
8
- // Get the outgoing body as an Object
9
- const obj = await response.json();
10
-
11
- // Modify the object as required
12
- obj.myNewProperty = "Hello World";
13
-
14
- // Stringify the object
15
- const body = JSON.stringify(obj);
16
-
17
- // Return a new response with the new body
18
- return new Response(body, request);
19
- }
@@ -1,27 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft-07/schema",
3
- "$id": "http://zuplo.com/schemas/policies/transform-body-outbound.json",
4
- "type": "object",
5
- "title": "Transform Response Body",
6
- "isCustom": true,
7
- "products": ["api-gateway"],
8
- "description": "Transform the body of an outgoing response.",
9
- "required": ["handler"],
10
- "properties": {
11
- "handler": {
12
- "type": "object",
13
- "default": {},
14
- "required": ["export", "module"],
15
- "properties": {
16
- "export": {
17
- "const": "default",
18
- "description": "The export from the custom policy"
19
- },
20
- "module": {
21
- "const": "$import(./modules/YOUR_MODULE)",
22
- "description": "The module containing the policy"
23
- }
24
- }
25
- }
26
- }
27
- }