@tailor-platform/sdk 1.60.1 → 1.60.3
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.
- package/CHANGELOG.md +16 -0
- package/README.md +1 -0
- package/dist/application-D4tRNn90.mjs +4 -0
- package/dist/{application-FnWOxBk7.mjs → application-pusdxz35.mjs} +185 -54
- package/dist/application-pusdxz35.mjs.map +1 -0
- package/dist/cli/index.mjs +2 -2
- package/dist/cli/lib.mjs +2 -2
- package/dist/{runtime-BvKGwZeF.mjs → runtime-C0_FZWdE.mjs} +113 -20
- package/dist/runtime-C0_FZWdE.mjs.map +1 -0
- package/docs/configuration.md +36 -1
- package/docs/multi-environment.md +74 -0
- package/docs/services/executor.md +3 -3
- package/docs/services/staticwebsite.md +2 -0
- package/docs/services/tailordb.md +1 -1
- package/package.json +1 -1
- package/dist/application-FnWOxBk7.mjs.map +0 -1
- package/dist/application-VOdgMtOD.mjs +0 -4
- package/dist/runtime-BvKGwZeF.mjs.map +0 -1
package/docs/configuration.md
CHANGED
|
@@ -13,6 +13,8 @@ For service-specific documentation, see:
|
|
|
13
13
|
- [Static Website](./services/staticwebsite.md) - Static file hosting
|
|
14
14
|
- [Secret Manager](./services/secret.md) - Secure credential storage
|
|
15
15
|
|
|
16
|
+
To deploy the same config to multiple workspaces with per-environment values, see [Multi-Environment Configuration](./multi-environment.md).
|
|
17
|
+
|
|
16
18
|
### Application Settings
|
|
17
19
|
|
|
18
20
|
```typescript
|
|
@@ -105,6 +107,7 @@ When using external resources:
|
|
|
105
107
|
- The resource itself is not deployed by this project
|
|
106
108
|
- The resource must be deployed and available before referencing it
|
|
107
109
|
- You can combine external resources with locally-defined resources
|
|
110
|
+
- TailorDB type names must remain unique across local and external TailorDB namespaces; `deploy` checks external TailorDB type names before applying changes
|
|
108
111
|
- Destructive operations like `tailordb truncate` (and `seedPlugin`'s `seed:reset`) automatically exclude external resources to prevent accidental data loss in shared resources
|
|
109
112
|
|
|
110
113
|
### Built-in IdP
|
|
@@ -183,7 +186,7 @@ export default defineConfig({
|
|
|
183
186
|
|
|
184
187
|
### Environment Variables
|
|
185
188
|
|
|
186
|
-
|
|
189
|
+
Use `env` in `defineConfig()` for non-secret values that application code needs at runtime, such as environment names, feature flags, and public service URLs. Values must be strings, numbers, or booleans.
|
|
187
190
|
|
|
188
191
|
```typescript
|
|
189
192
|
export default defineConfig({
|
|
@@ -196,6 +199,32 @@ export default defineConfig({
|
|
|
196
199
|
});
|
|
197
200
|
```
|
|
198
201
|
|
|
202
|
+
`tailor.config.ts` runs locally when an SDK command loads the config. If values come from your shell or an env file, SDK commands can load them before config evaluation with the global [`--env-file`](./cli-reference.md#environment-file-loading) and `--env-file-if-exists` options:
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
export default defineConfig({
|
|
206
|
+
name: "my-app",
|
|
207
|
+
env: {
|
|
208
|
+
foo: Number(process.env.FOO ?? "1"),
|
|
209
|
+
bar: process.env.BAR ?? "hello",
|
|
210
|
+
baz: (process.env.BAZ ?? "true") === "true",
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
If the same config defines an auth before-login hook, make sure the config module can be evaluated without Node-only globals in the platform runtime. Avoid arbitrary `process.env` reads in that module; pass literal values, or values generated into a config module before deployment, and read them from the hook's `env` argument.
|
|
216
|
+
|
|
217
|
+
When the SDK deploys application code or runs detected service code with `function test-run`, it passes the resolved values as the `env` argument. Do not read `process.env` from deployed resolvers, executors, workflow jobs, auth hooks, or migration scripts; Node-side environment variables are not available there. Put sensitive values in [Secret Manager](./services/secret.md) instead of `env`.
|
|
218
|
+
|
|
219
|
+
| Code location | Runtime access |
|
|
220
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
|
221
|
+
| Resolver body | `body: ({ env }) => ...` |
|
|
222
|
+
| Executor callbacks | `body: ({ env }) => ...`, `url: ({ env }) => String(env.bar)`, `variables: ({ env }) => ({ enabled: env.baz })`, or similar callback args |
|
|
223
|
+
| Workflow job body | `body: (input, { env }) => ...` |
|
|
224
|
+
| Auth before-login hook | `handler: async ({ env }) => ...` |
|
|
225
|
+
| TailorDB migration script | `main(trx, { env }: MigrationContext)` |
|
|
226
|
+
| `function test-run` | Same `env` argument shape as the detected resolver, executor, or workflow job |
|
|
227
|
+
|
|
199
228
|
```typescript
|
|
200
229
|
// In resolvers
|
|
201
230
|
body: ({ input, env }) => {
|
|
@@ -226,6 +255,12 @@ hooks: {
|
|
|
226
255
|
invoker: "hook-invoker",
|
|
227
256
|
},
|
|
228
257
|
};
|
|
258
|
+
|
|
259
|
+
// In TailorDB migration scripts
|
|
260
|
+
export async function main(trx: Transaction, { env }: MigrationContext): Promise<void> {
|
|
261
|
+
if (!env.baz) return;
|
|
262
|
+
await trx.updateTable("User").set({ stage: env.bar }).execute();
|
|
263
|
+
}
|
|
229
264
|
```
|
|
230
265
|
|
|
231
266
|
### Workflow Service
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Multi-Environment Configuration
|
|
2
|
+
|
|
3
|
+
A project typically runs in more than one environment — for example, each developer's own workspace, a staging workspace, and a production workspace. The SDK has no separate "environment" concept: an environment is a workspace you deploy to, and all environments share the same `tailor.config.ts`. This guide shows how to switch the deployment target and how to vary configuration values per environment.
|
|
4
|
+
|
|
5
|
+
The auto-managed `id` in `defineConfig()` identifies the application, not an environment. Keep the same committed `id` when deploying the same config to multiple workspaces; see [Application Settings](./configuration.md#application-settings).
|
|
6
|
+
|
|
7
|
+
## Selecting the target workspace
|
|
8
|
+
|
|
9
|
+
Deployment commands resolve the target workspace from, in priority order, the `--workspace-id` (`-w`) option, the `TAILOR_PLATFORM_WORKSPACE_ID` environment variable, and the active profile. See [Workspace ID Priority](./cli-reference.md#workspace-id-priority).
|
|
10
|
+
|
|
11
|
+
For one-off commands, pass the workspace explicitly:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
tailor-sdk deploy -w <staging-workspace-id>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For environments you switch between regularly, create a named profile per environment with the [profile commands](./cli/workspace.md#profile-create) and select it with `--profile` (`-p`) or `TAILOR_PLATFORM_PROFILE`:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
tailor-sdk profile create staging -u you@example.com -w <staging-workspace-id>
|
|
21
|
+
tailor-sdk profile create production -u you@example.com -w <production-workspace-id> --permission read
|
|
22
|
+
|
|
23
|
+
tailor-sdk deploy -p staging
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Profiles are created with `write` permission by default. The production profile above opts into `--permission read`, which blocks write commands such as `deploy` while the profile is active — a guard against deploying to production by accident. To deploy to production deliberately, pass the workspace explicitly with `-w` without selecting the profile — the guard applies only while a profile is selected via `-p` or `TAILOR_PLATFORM_PROFILE` — or use a separate profile created with `write` permission.
|
|
27
|
+
|
|
28
|
+
## Varying config values per environment
|
|
29
|
+
|
|
30
|
+
`tailor.config.ts` is a TypeScript module evaluated locally each time an SDK command loads it, so any value can branch on `process.env`. If the config also defines an auth before-login hook, mind the `process.env` caveat in [Environment Variables](./configuration.md#environment-variables). Keep one env file per environment and load it with the global [`--env-file`](./cli-reference.md#environment-file-loading) option:
|
|
31
|
+
|
|
32
|
+
```ini
|
|
33
|
+
# .env.production
|
|
34
|
+
APP_ENV=production
|
|
35
|
+
LOG_LEVEL=WARN
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
tailor-sdk deploy -w <production-workspace-id> --env-file .env.production
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
export default defineConfig({
|
|
44
|
+
name: "my-app",
|
|
45
|
+
logLevel: process.env.LOG_LEVEL ?? "DEBUG",
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Variables already set in your shell are not overwritten by env files, and later files override earlier ones — see [Environment File Loading](./cli-reference.md#environment-file-loading).
|
|
50
|
+
|
|
51
|
+
## Passing environment values to application code
|
|
52
|
+
|
|
53
|
+
`process.env` is only available while the config is evaluated locally; deployed resolvers, executors, workflow jobs, auth hooks, and migration scripts cannot read it. To make a value available at runtime, forward it through `env` in `defineConfig()`:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
export default defineConfig({
|
|
57
|
+
name: "my-app",
|
|
58
|
+
env: {
|
|
59
|
+
appEnv: process.env.APP_ENV ?? "development",
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
See [Environment Variables](./configuration.md#environment-variables) for how `env` values reach each code location. For sensitive values such as API keys, use [Secret Manager](./services/secret.md) instead and supply the per-environment value via `process.env` the same way.
|
|
65
|
+
|
|
66
|
+
## Settings that belong to a single environment
|
|
67
|
+
|
|
68
|
+
Some settings reference resources that can exist in only one environment at a time. The static website [customDomains](./services/staticwebsite.md#customdomains) option is an example: a domain is globally unique, so the same `customDomains` value cannot be deployed from two workspaces. Set such values only in the environment that owns the resource:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
defineStaticWebSite("my-website", {
|
|
72
|
+
customDomains: process.env.APP_ENV === "production" ? ["app.example.com"] : undefined,
|
|
73
|
+
});
|
|
74
|
+
```
|
|
@@ -212,14 +212,14 @@ Execute JavaScript/TypeScript functions:
|
|
|
212
212
|
createExecutor({
|
|
213
213
|
operation: {
|
|
214
214
|
kind: "function",
|
|
215
|
-
body: async ({ newRecord }) => {
|
|
216
|
-
console.log(
|
|
215
|
+
body: async ({ newRecord, env }) => {
|
|
216
|
+
console.log(`New record created in ${env.bar}:`, newRecord);
|
|
217
217
|
},
|
|
218
218
|
},
|
|
219
219
|
});
|
|
220
220
|
```
|
|
221
221
|
|
|
222
|
-
`function` and `jobFunction` `body` args include an `invoker` field: the principal running this function, overridden by `authInvoker` when set; `null` for anonymous calls. Other operation kinds (`graphql`, `webhook`, `workflow`) do not pass `invoker` into
|
|
222
|
+
Executor callbacks receive the trigger args, including `env` from `defineConfig({ env })`. `function` and `jobFunction` `body` args also include an `invoker` field: the principal running this function, overridden by `authInvoker` when set; `null` for anonymous calls. Other operation kinds (`graphql`, `webhook`, `workflow`) receive `env` through their callback args but do not pass `invoker` into those callbacks.
|
|
223
223
|
|
|
224
224
|
### Job Function Operation
|
|
225
225
|
|
|
@@ -74,6 +74,8 @@ defineStaticWebSite("my-website", {
|
|
|
74
74
|
|
|
75
75
|
After deploying, use `tailor-sdk staticwebsite domain get <domain>` to check domain status and retrieve the CNAME targets required for DNS configuration.
|
|
76
76
|
|
|
77
|
+
A domain can be associated with only one workspace at a time. To set custom domains only in the workspace that owns the domain, see [Multi-Environment Configuration](../multi-environment.md#settings-that-belong-to-a-single-environment).
|
|
78
|
+
|
|
77
79
|
## Type-safe URL References
|
|
78
80
|
|
|
79
81
|
The returned website object provides a `url` property that resolves to the actual URL at deployment time. Use this for type-safe configuration:
|
|
@@ -23,7 +23,7 @@ Define TailorDB Types in files matching glob patterns specified in `tailor.confi
|
|
|
23
23
|
- **Multiple types per file**: You can define multiple TailorDB types in a single file
|
|
24
24
|
- **Export method**: Use named exports (`export const`)
|
|
25
25
|
- **Export both value and type**: Always export both the runtime value and TypeScript type
|
|
26
|
-
- **Uniqueness**: Type names must be unique across all TailorDB
|
|
26
|
+
- **Uniqueness**: Type names must be unique across all TailorDB namespaces in the application
|
|
27
27
|
|
|
28
28
|
```typescript
|
|
29
29
|
import { db } from "@tailor-platform/sdk";
|