zuplo 6.71.20 → 6.71.22

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.
@@ -96,14 +96,16 @@
96
96
  {
97
97
  "rateLimitBy": "ip",
98
98
  "requestsAllowed": 2,
99
- "timeWindowMinutes": 1
99
+ "timeWindowMinutes": 1,
100
+ "mode": "async"
100
101
  },
101
102
  {
102
103
  "rateLimitBy": "function",
103
104
  "identifier": {
104
105
  "export": "$import(./modules/my-module)",
105
106
  "module": "default"
106
- }
107
+ },
108
+ "mode": "async"
107
109
  }
108
110
  ]
109
111
  }
@@ -115,7 +117,8 @@
115
117
  "options": {
116
118
  "rateLimitBy": "ip",
117
119
  "requestsAllowed": 2,
118
- "timeWindowMinutes": 1
120
+ "timeWindowMinutes": 1,
121
+ "mode": "async"
119
122
  }
120
123
  },
121
124
  {
@@ -126,7 +129,8 @@
126
129
  "identifier": {
127
130
  "export": "$import(./modules/my-module)",
128
131
  "module": "default"
129
- }
132
+ },
133
+ "mode": "async"
130
134
  }
131
135
  }
132
136
  ]
@@ -0,0 +1,67 @@
1
+ On each request this policy selects one of the configured `basePaths` at random,
2
+ weighted by each entry's `weight`. Weights are relative — they do not need to
3
+ add up to 100. The selected URL is written to the request custom context at the
4
+ path given by `customOutputProperty`.
5
+
6
+ ### Using the selected base path
7
+
8
+ The selected URL is stored on `context.custom` and is intended to be consumed by
9
+ a later handler on the same route. Reference it using the `customOutputProperty`
10
+ path you configured. For example, with
11
+ `"customOutputProperty": "trafficSplitting.basePath"`:
12
+
13
+ ```json
14
+ // URL Rewrite handler
15
+ {
16
+ "handler": {
17
+ "export": "urlRewriteHandler",
18
+ "module": "$import(@zuplo/runtime)",
19
+ "options": {
20
+ "rewritePattern": "${context.custom.trafficSplitting.basePath}/users/${params.id}"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ ```json
27
+ // URL Forward handler
28
+ {
29
+ "handler": {
30
+ "export": "urlForwardHandler",
31
+ "module": "$import(@zuplo/runtime)",
32
+ "options": {
33
+ "baseUrl": "${context.custom.trafficSplitting.basePath}"
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ > The `redirect` handler's `location` is not interpolated — use the URL Rewrite
40
+ > or URL Forward handler to route to the selected base path.
41
+
42
+ ### Only one value is in effect
43
+
44
+ `customOutputProperty` resolves to a single value. If more than one Traffic
45
+ Splitting policy on a route writes to the same property, the **last policy to
46
+ run wins** — its selection is the one the handler sees. In practice you should
47
+ configure a single Traffic Splitting policy per output property.
48
+
49
+ ### Environment variables
50
+
51
+ Because each `url` is a string value, you can reference environment variables in
52
+ it, including mixed strings:
53
+
54
+ ```json
55
+ {
56
+ "basePaths": [
57
+ { "url": "$env(STABLE_BASE_URL)", "weight": 90 },
58
+ { "url": "$env(CANARY_BASE_URL)/v2", "weight": 10 }
59
+ ],
60
+ "customOutputProperty": "trafficSplitting.basePath"
61
+ }
62
+ ```
63
+
64
+ ### Logging the selection
65
+
66
+ Set `"logSelection": true` to log which base path was selected on each request.
67
+ This is off by default.
@@ -0,0 +1,5 @@
1
+ The traffic splitting policy randomly distributes incoming requests across a set
2
+ of weighted base paths. It selects one base path per request and writes it to
3
+ the request custom context, where a URL Rewrite or URL Forward handler can use
4
+ it to route the request. This is useful for blue/green rollouts, canary
5
+ releases, or splitting traffic between backends.
@@ -0,0 +1,121 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft-07/schema",
3
+ "$id": "https://cdn.zuplo.com/policies/runtime/schemas/traffic-splitting-inbound.json",
4
+ "type": "object",
5
+ "title": "Traffic Splitting",
6
+ "isDeprecated": false,
7
+ "isPaidAddOn": false,
8
+ "isEnterprise": false,
9
+ "isInternal": false,
10
+ "isBeta": false,
11
+ "isHidden": false,
12
+ "requiresAI": false,
13
+ "products": ["api-gateway"],
14
+ "description": "Splits traffic randomly across a set of weighted base paths. On each request one base path is selected (weighted by `weight`) and written to the request custom context at `customOutputProperty`. Reference it from a later URL Rewrite `rewritePattern` or URL Forward `baseUrl`, e.g. `${context.custom.trafficSplitting.basePath}`.",
15
+ "deprecatedMessage": "",
16
+ "required": ["handler"],
17
+ "properties": {
18
+ "handler": {
19
+ "type": "object",
20
+ "default": {},
21
+ "required": ["export", "module", "options"],
22
+ "properties": {
23
+ "export": {
24
+ "const": "TrafficSplittingInboundPolicy",
25
+ "description": "The name of the exported type"
26
+ },
27
+ "module": {
28
+ "const": "$import(@zuplo/runtime)",
29
+ "description": "The module containing the policy"
30
+ },
31
+ "options": {
32
+ "title": "TrafficSplittingInboundPolicyOptions",
33
+ "type": "object",
34
+ "description": "The options for this policy.",
35
+ "additionalProperties": false,
36
+ "required": ["basePaths", "customOutputProperty"],
37
+ "properties": {
38
+ "basePaths": {
39
+ "type": "array",
40
+ "description": "The set of base paths (URLs) to split traffic across. One entry is selected at random per request, weighted by its `weight`.",
41
+ "items": {
42
+ "type": "object",
43
+ "additionalProperties": false,
44
+ "required": ["url", "weight"],
45
+ "properties": {
46
+ "url": {
47
+ "type": "string",
48
+ "examples": ["https://api-v1.example.com"],
49
+ "description": "The base path (URL) to route to when this entry is selected. Supports environment variables, e.g. `$env(BASE_URL)/v2`."
50
+ },
51
+ "weight": {
52
+ "type": "number",
53
+ "minimum": 0,
54
+ "examples": [80],
55
+ "description": "The relative weight for this base path. Higher weights receive proportionally more traffic. Weights are relative and do not need to add up to 100."
56
+ }
57
+ }
58
+ }
59
+ },
60
+ "customOutputProperty": {
61
+ "type": "string",
62
+ "pattern": "^[A-Za-z_$][A-Za-z0-9_$]*(\\.[A-Za-z_$][A-Za-z0-9_$]*)*$",
63
+ "examples": ["trafficSplitting.basePath"],
64
+ "description": "A simple dotted property path under the request custom context where the selected URL is written (e.g. `trafficSplitting.basePath`). Reference it later in a URL Rewrite `rewritePattern` or URL Forward `baseUrl` as `${context.custom.trafficSplitting.basePath}`. Only one value is in effect; if multiple Traffic Splitting policies write the same property, the last one to run wins. Array indexes and brackets are not allowed."
65
+ },
66
+ "logSelection": {
67
+ "type": "boolean",
68
+ "default": false,
69
+ "x-show-example": false,
70
+ "description": "When `true`, logs which base path was selected for each request. Defaults to `false`."
71
+ }
72
+ },
73
+ "examples": [
74
+ {
75
+ "basePaths": [
76
+ {
77
+ "url": "https://api-v1.example.com",
78
+ "weight": 80
79
+ },
80
+ {
81
+ "url": "https://api-v2.example.com",
82
+ "weight": 15
83
+ },
84
+ {
85
+ "url": "$env(CANARY_BASE_URL)",
86
+ "weight": 5
87
+ }
88
+ ],
89
+ "customOutputProperty": "trafficSplitting.basePath",
90
+ "logSelection": true
91
+ }
92
+ ]
93
+ }
94
+ },
95
+ "examples": [
96
+ {
97
+ "export": "TrafficSplittingInboundPolicy",
98
+ "module": "$import(@zuplo/runtime)",
99
+ "options": {
100
+ "basePaths": [
101
+ {
102
+ "url": "https://api-v1.example.com",
103
+ "weight": 80
104
+ },
105
+ {
106
+ "url": "https://api-v2.example.com",
107
+ "weight": 15
108
+ },
109
+ {
110
+ "url": "$env(CANARY_BASE_URL)",
111
+ "weight": 5
112
+ }
113
+ ],
114
+ "customOutputProperty": "trafficSplitting.basePath",
115
+ "logSelection": true
116
+ }
117
+ }
118
+ ]
119
+ }
120
+ }
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zuplo",
3
- "version": "6.71.20",
3
+ "version": "6.71.22",
4
4
  "type": "module",
5
5
  "description": "The programmable API Gateway",
6
6
  "author": "Zuplo, Inc.",
@@ -19,9 +19,9 @@
19
19
  "zuplo": "zuplo.js"
20
20
  },
21
21
  "dependencies": {
22
- "@zuplo/cli": "6.71.20",
23
- "@zuplo/core": "6.71.20",
24
- "@zuplo/runtime": "6.71.20",
22
+ "@zuplo/cli": "6.71.22",
23
+ "@zuplo/core": "6.71.22",
24
+ "@zuplo/runtime": "6.71.22",
25
25
  "@zuplo/test": "1.4.0"
26
26
  }
27
27
  }