zuplo 6.68.30 → 6.69.1

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.
@@ -64,11 +64,26 @@ variable named `MY_VAR` can't be set on say the **Production** environments.
64
64
 
65
65
  ## Reserved Environment Variables
66
66
 
67
- Environment variables can't start with `ZUPLO` or `__ZUPLO`.
67
+ Environment variables can't start with `ZUPLO_` or `__ZUPLO`. The same
68
+ restriction applies to names beginning with `ZUDOKU_`.
69
+
70
+ If you need a variable that's exposed to the
71
+ [Developer Portal](../dev-portal/introduction.mdx) build, prefix it with
72
+ `ZUPLO_PUBLIC_` (or `ZUDOKU_PUBLIC_`). Public-prefixed variables are bundled
73
+ into the portal's static output and **must not contain secrets**, as they're
74
+ visible to anyone who loads the page.
68
75
 
69
76
  ## Using Environment Variables
70
77
 
71
- Environment variables can be used in several places within your Zuplo project:
78
+ Environment variables can be used in several places in your Zuplo project. Each
79
+ location has its own syntax:
80
+
81
+ | Location | Syntax | Resolved |
82
+ | ----------------------------------------------------- | ---------------------- | --------------------- |
83
+ | Custom code (handlers, policies, hooks) | `environment.VAR_NAME` | Runtime |
84
+ | Configuration files (`policies.json`, OpenAPI routes) | `$env(VAR_NAME)` | Build time |
85
+ | URL Rewrite, URL Forward, and WebSocket handlers | `${env.VAR_NAME}` | Runtime (per request) |
86
+ | Developer Portal config (`zudoku.config.ts`) | `process.env.VAR_NAME` | Portal build time |
72
87
 
73
88
  ### In Code
74
89
 
@@ -77,13 +92,44 @@ See the
77
92
  [Environment Variables API Reference](../programmable-api/environment.mdx) for
78
93
  detailed usage examples and patterns.
79
94
 
95
+ ```ts
96
+ import { environment } from "@zuplo/runtime";
97
+
98
+ const apiKey = environment.API_KEY; // string | undefined
99
+ ```
100
+
80
101
  ### In Configuration Files
81
102
 
82
- Inside some configuration files, environment variables can be referenced with
83
- the pattern `$env(MY_VAR)`.
103
+ Inside policy options, route handler options, and CORS policy options,
104
+ environment variables can be referenced with the `$env(VAR_NAME)` pattern.
105
+ Substitutions happen at build time — the build replaces each `$env()` expression
106
+ with a reference to the runtime `environment` object before the project is
107
+ deployed.
108
+
109
+ #### Where `$env()` is allowed
110
+
111
+ - `config/policies.json` — any property under `policies[].handler.options`,
112
+ including nested objects and array elements
113
+ - `config/policies.json` — any direct property of a `corsPolicies[]` entry, such
114
+ as `allowedOrigins`, `allowedHeaders`, `allowedMethods`, `exposeHeaders`, and
115
+ `maxAge`
116
+ - `config/routes.oas.json` (and other OpenAPI route files) — any property under
117
+ a route's `x-zuplo-route.handler.options`, including nested objects and array
118
+ elements
119
+
120
+ `$env()` is **not** allowed in other locations such as policy `name`,
121
+ `policyType`, `module`, route paths, or top-level OpenAPI fields. Using it
122
+ elsewhere produces a build error:
123
+
124
+ ```text
125
+ An $env() statement is not expected at this location.
126
+ ```
127
+
128
+ #### Standalone substitution
84
129
 
85
- For example, in the `policies.json` file, an environment variable could be set
86
- on a policy option.
130
+ When the value is _only_ an `$env()` expression, the variable's value is
131
+ inserted directly. The runtime type matches the type of the environment variable
132
+ (always a string when set, `undefined` when not).
87
133
 
88
134
  ```json
89
135
  {
@@ -93,23 +139,130 @@ on a policy option.
93
139
  "export": "default",
94
140
  "module": "$import(./modules/YOUR_MODULE)",
95
141
  "options": {
96
- "config1": "$env(MY_CONFIG_VAR)",
142
+ "apiKey": "$env(BACKEND_API_KEY)",
97
143
  "config2": true
98
144
  }
99
145
  }
100
146
  }
101
147
  ```
102
148
 
103
- ### Rewrite & Forwarding Handler
149
+ #### String interpolation
150
+
151
+ You can mix `$env()` with literal text to compose a value. The build wraps the
152
+ result in a JavaScript template literal that's evaluated at runtime, so each
153
+ request gets the current value of the variable.
154
+
155
+ ```json
156
+ {
157
+ "options": {
158
+ "endpoint": "https://$env(API_HOST)/v1",
159
+ "userAgent": "MyGateway/$env(APP_VERSION) ($env(ENVIRONMENT_NAME))"
160
+ }
161
+ }
162
+ ```
163
+
164
+ :::note
165
+
166
+ If the variable isn't set, the interpolated portion resolves to an empty string.
167
+ For example, with `API_HOST` unset, `"https://$env(API_HOST)/v1"` becomes
168
+ `"https:///v1"`. Use a standalone `$env()` (no surrounding text) if you need to
169
+ detect an unset variable in your handler or policy code.
170
+
171
+ :::
172
+
173
+ #### In arrays
174
+
175
+ `$env()` works inside string array elements, including mixed arrays where some
176
+ elements are static and others are interpolated:
177
+
178
+ ```json
179
+ {
180
+ "options": {
181
+ "allowedKeys": ["$env(PRIMARY_KEY)", "$env(SECONDARY_KEY)"],
182
+ "tags": ["public", "$env(REGION)", "tier-$env(SERVICE_TIER)"]
183
+ }
184
+ }
185
+ ```
186
+
187
+ #### In nested objects
188
+
189
+ `$env()` works at any depth within a handler or policy `options` object:
190
+
191
+ ```json
192
+ {
193
+ "options": {
194
+ "database": {
195
+ "host": "$env(DB_HOST)",
196
+ "credentials": {
197
+ "username": "$env(DB_USER)",
198
+ "password": "$env(DB_PASSWORD)"
199
+ }
200
+ }
201
+ }
202
+ }
203
+ ```
204
+
205
+ #### Variable name rules
206
+
207
+ The name inside `$env(...)` is matched literally up to the first closing
208
+ parenthesis. Use only letters, digits, and underscores in the name — matching
209
+ what the [Zuplo Portal](#environment-variable-editor) accepts when you create
210
+ the variable.
211
+
212
+ ### Rewrite, Forwarding, and WebSocket Handlers
213
+
214
+ The URL Rewrite handler's `rewritePattern`, the URL Forward handler's `baseUrl`,
215
+ and the WebSocket handler's `rewritePattern` use a different syntax. These
216
+ options are evaluated as JavaScript template literals at request time, so you
217
+ reference variables with `${env.VAR_NAME}`:
218
+
219
+ ```json
220
+ {
221
+ "handler": {
222
+ "export": "urlForwardHandler",
223
+ "module": "$import(@zuplo/runtime)",
224
+ "options": {
225
+ "baseUrl": "https://${env.BACKEND_HOST}"
226
+ }
227
+ }
228
+ }
229
+ ```
230
+
231
+ Because `rewritePattern` and `baseUrl` run as code, they also have access to the
232
+ request, URL parts, route params, and query string. See the
233
+ [URL Rewrite Handler](../handlers/url-rewrite.mdx) docs for the full list of
234
+ available variables.
104
235
 
105
- When referencing environment variables inside of the URL Rewrite handler and the
106
- URL Forward handler, variables are substituted using JavaScript style string
107
- interpolation.
236
+ :::caution
108
237
 
109
- ```txt
110
- https://${env.API_URL}/path/to/call
238
+ Using `$env(VAR_NAME)` inside `rewritePattern` or `baseUrl` is the most common
239
+ mistake. The build will warn you when it detects this, but the value will be
240
+ passed through to the handler as a literal string and the rewrite will fail at
241
+ runtime. Always use `${env.VAR_NAME}` in these two options.
242
+
243
+ :::
244
+
245
+ ### In the Developer Portal
246
+
247
+ The Developer Portal's `zudoku.config.ts` runs in Node-like build tooling and
248
+ uses `process.env` rather than `$env()`:
249
+
250
+ ```ts title="zudoku.config.ts"
251
+ const config: ZudokuConfig = {
252
+ authentication: {
253
+ type: "auth0",
254
+ domain: process.env.ZUPLO_PUBLIC_AUTH0_DOMAIN,
255
+ clientId: process.env.ZUPLO_PUBLIC_AUTH0_CLIENT_ID,
256
+ },
257
+ };
258
+
259
+ export default config;
111
260
  ```
112
261
 
262
+ Only variables prefixed with `ZUPLO_PUBLIC_` (or `ZUDOKU_PUBLIC_`) are available
263
+ in the portal build, and their values are embedded into the client-side bundle.
264
+ Don't use this prefix for any value that should remain private.
265
+
113
266
  ## System Environment Variables
114
267
 
115
268
  The following variables are automatically set by the system and are available to
@@ -0,0 +1,25 @@
1
+ ---
2
+ title: "Zuplo CLI: Whoami"
3
+ sidebar_label: whoami
4
+ ---
5
+
6
+ <CliCommand
7
+ command="whoami"
8
+ description="Displays the currently authenticated user"
9
+ examples={[
10
+ [
11
+ "$0 whoami",
12
+ "Display the currently authenticated user"
13
+ ]
14
+ ]}
15
+ usage="$0 whoami [options]"
16
+ >
17
+
18
+ </CliCommand>
19
+
20
+ ## Global options
21
+
22
+ The following global options are available for all commands:
23
+
24
+ - [`--help`](./global-options.mdx#help)
25
+ - [`--api-key`](./global-options.mdx#api-key)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zuplo",
3
- "version": "6.68.30",
3
+ "version": "6.69.1",
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.68.30",
23
- "@zuplo/core": "6.68.30",
24
- "@zuplo/runtime": "6.68.30",
22
+ "@zuplo/cli": "6.69.1",
23
+ "@zuplo/core": "6.69.1",
24
+ "@zuplo/runtime": "6.69.1",
25
25
  "@zuplo/test": "1.4.0"
26
26
  }
27
27
  }