@tailor-platform/sdk 0.9.0 → 0.10.0
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 +29 -0
- package/dist/cli/api.d.mts +1 -1
- package/dist/cli/api.mjs +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/configure/index.d.mts +2 -2
- package/dist/{index-DHpKRtq3.d.mts → index-DxmBZtRb.d.mts} +15 -2
- package/dist/{token-DwKmpi9i.mjs → token-BD9c1mlS.mjs} +60 -19
- package/dist/{types-CPcmGK_X.d.mts → types-DcpYyMM2.d.mts} +4 -3
- package/dist/utils/test/index.d.mts +2 -2
- package/docs/configuration.md +31 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @tailor-platform/sdk
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#25](https://github.com/tailor-platform/sdk/pull/25) [`50069ae`](https://github.com/tailor-platform/sdk/commit/50069aeebeb1c0e09cf66f660367cd26cc565f29) Thanks [@haru0017](https://github.com/haru0017)! - Define environment variables in `defineConfig()` and access them in resolvers and executors via the `env` parameter.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
name: "my-app",
|
|
12
|
+
env: { logLevel: "debug", cacheTtl: 3600 },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Access in resolver
|
|
16
|
+
body: ({ input, env }) => {
|
|
17
|
+
// env.logLevel, env.cacheTtl available with full type safety
|
|
18
|
+
};
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#33](https://github.com/tailor-platform/sdk/pull/33) [`1f73bd1`](https://github.com/tailor-platform/sdk/commit/1f73bd1d7abaa0a55358086a0d1b7f7c00cccbf3) Thanks [@remiposo](https://github.com/remiposo)! - Confirm important resource deletion
|
|
24
|
+
|
|
25
|
+
Added a confirmation prompt when attempting to delete resources that would result in data loss (tailordb and staticwebsite).
|
|
26
|
+
This can be skipped with the `--yes` flag.
|
|
27
|
+
|
|
28
|
+
- [#31](https://github.com/tailor-platform/sdk/pull/31) [`5fc5594`](https://github.com/tailor-platform/sdk/commit/5fc5594e0b7b1cdf72dadce505aa58a8ae2e5f4a) Thanks [@remiposo](https://github.com/remiposo)! - Make appName for the Executor's GraphQL target optional
|
|
29
|
+
|
|
30
|
+
The default value is its own application name.
|
|
31
|
+
|
|
3
32
|
## 0.9.0
|
|
4
33
|
|
|
5
34
|
### Minor Changes
|
package/dist/cli/api.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference path="./../plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { AppConfig, CodeGeneratorBase, Executor, Generator, Resolver, TailorDBTypeConfig } from "../types-
|
|
3
|
+
import { AppConfig, CodeGeneratorBase, Executor, Generator, Resolver, TailorDBTypeConfig } from "../types-DcpYyMM2.mjs";
|
|
4
4
|
import "citty";
|
|
5
5
|
import "zod";
|
|
6
6
|
import "@bufbuild/protobuf/wkt";
|
package/dist/cli/api.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { apply, generate, generateUserTypes, loadConfig, machineUserList, machineUserToken, show, workspaceCreate, workspaceDelete, workspaceList } from "../token-
|
|
1
|
+
import { apply, generate, generateUserTypes, loadConfig, machineUserList, machineUserToken, show, workspaceCreate, workspaceDelete, workspaceList } from "../token-BD9c1mlS.mjs";
|
|
2
2
|
import "../auth-Di3vQUrT.mjs";
|
|
3
3
|
|
|
4
4
|
export { apply, generate, generateUserTypes, loadConfig, machineUserList, machineUserToken, show, workspaceCreate, workspaceDelete, workspaceList };
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { PATScope, applyCommand, commonArgs, createCommand, deleteCommand, fetchAll, fetchLatestToken, formatArgs, generateCommand, initOperatorClient, listCommand as listCommand$4, listCommand$1 as listCommand, loadAccessToken, loadConfig, loadConfigPath, loadWorkspaceId, parseFormat, printWithFormat, readPackageJson, readPlatformConfig, showCommand, tokenCommand, userAgent, withCommonArgs, writePlatformConfig } from "../token-
|
|
2
|
+
import { PATScope, applyCommand, commonArgs, createCommand, deleteCommand, fetchAll, fetchLatestToken, formatArgs, generateCommand, initOperatorClient, listCommand as listCommand$4, listCommand$1 as listCommand, loadAccessToken, loadConfig, loadConfigPath, loadWorkspaceId, parseFormat, printWithFormat, readPackageJson, readPlatformConfig, showCommand, tokenCommand, userAgent, withCommonArgs, writePlatformConfig } from "../token-BD9c1mlS.mjs";
|
|
3
3
|
import "../auth-Di3vQUrT.mjs";
|
|
4
4
|
import { register } from "node:module";
|
|
5
5
|
import { defineCommand, runCommand, runMain } from "citty";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference path="./../plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { AuthConfig, AuthServiceInput, BuiltinIdP, ExecutorServiceConfig, ExecutorServiceInput, IDToken, IdPConfig, IdProviderConfig, OAuth2Client, OAuth2ClientGrantType, OIDC, PermissionCondition, QueryType, Resolver, ResolverServiceConfig, ResolverServiceInput, SAML, SCIMAttribute, SCIMAttributeMapping, SCIMAttributeType, SCIMAuthorization, SCIMConfig, SCIMResource, StaticWebsiteConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, TenantProviderConfig, UserAttributeKey, UserAttributeListKey, UserAttributeMap, UsernameFieldKey, ValueOperand, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, unauthenticatedTailorUser } from "../types-
|
|
4
|
-
import { FunctionOperation, GqlOperation, IncomingWebhookArgs, IncomingWebhookRequest, IncomingWebhookTrigger, Operation, RecordCreatedArgs, RecordDeletedArgs, RecordTrigger, RecordUpdatedArgs, ResolverExecutedArgs, ResolverExecutedTrigger, ScheduleTrigger, Trigger, WebhookOperation, createExecutor, createResolver, incomingWebhookTrigger, infer, output, recordCreatedTrigger, recordDeletedTrigger, recordUpdatedTrigger, resolverExecutedTrigger, scheduleTrigger, t } from "../index-
|
|
3
|
+
import { AuthConfig, AuthServiceInput, BuiltinIdP, ExecutorServiceConfig, ExecutorServiceInput, IDToken, IdPConfig, IdProviderConfig, OAuth2Client, OAuth2ClientGrantType, OIDC, PermissionCondition, QueryType, Resolver, ResolverServiceConfig, ResolverServiceInput, SAML, SCIMAttribute, SCIMAttributeMapping, SCIMAttributeType, SCIMAuthorization, SCIMConfig, SCIMResource, StaticWebsiteConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, TenantProviderConfig, UserAttributeKey, UserAttributeListKey, UserAttributeMap, UsernameFieldKey, ValueOperand, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, unauthenticatedTailorUser } from "../types-DcpYyMM2.mjs";
|
|
4
|
+
import { FunctionOperation, GqlOperation, IncomingWebhookArgs, IncomingWebhookRequest, IncomingWebhookTrigger, Operation, RecordCreatedArgs, RecordDeletedArgs, RecordTrigger, RecordUpdatedArgs, ResolverExecutedArgs, ResolverExecutedTrigger, ScheduleTrigger, Trigger, WebhookOperation, createExecutor, createResolver, incomingWebhookTrigger, infer, output, recordCreatedTrigger, recordDeletedTrigger, recordUpdatedTrigger, resolverExecutedTrigger, scheduleTrigger, t } from "../index-DxmBZtRb.mjs";
|
|
5
5
|
export { AuthConfig, AuthServiceInput, BuiltinIdP, ExecutorServiceConfig, ExecutorServiceInput, FunctionOperation, GqlOperation, IDToken, IdPConfig, IdProviderConfig, IncomingWebhookArgs, IncomingWebhookRequest, IncomingWebhookTrigger, OAuth2Client, OAuth2ClientGrantType, OIDC, Operation, PermissionCondition, QueryType, RecordCreatedArgs, RecordDeletedArgs, RecordTrigger, RecordUpdatedArgs, Resolver, ResolverExecutedArgs, ResolverExecutedTrigger, ResolverServiceConfig, ResolverServiceInput, SAML, SCIMAttribute, SCIMAttributeMapping, SCIMAttributeType, SCIMAuthorization, SCIMConfig, SCIMResource, ScheduleTrigger, StaticWebsiteConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, TenantProviderConfig, Trigger, UserAttributeKey, UserAttributeListKey, UserAttributeMap, UsernameFieldKey, ValueOperand, WebhookOperation, createExecutor, createResolver, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, incomingWebhookTrigger, infer, output, recordCreatedTrigger, recordDeletedTrigger, recordUpdatedTrigger, resolverExecutedTrigger, scheduleTrigger, t, unauthenticatedTailorUser };
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
/// <reference path="./plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { AllowedValues, AllowedValuesOutput, ArrayFieldOutput, ExecutorInput, FieldMetadata, FieldOptions, FieldOutput, FunctionOperation, GqlOperation, IncomingWebhookTrigger as IncomingWebhookTrigger$1, InferFieldsOutput, RecordTrigger as RecordTrigger$1, ResolverExecutedTrigger as ResolverExecutedTrigger$1, ResolverInput, ScheduleTriggerInput, TailorDBType, TailorField, TailorUser, WebhookOperation, output as output$1 } from "./types-
|
|
3
|
+
import { AllowedValues, AllowedValuesOutput, ArrayFieldOutput, ExecutorInput, FieldMetadata, FieldOptions, FieldOutput, FunctionOperation, GqlOperation, IncomingWebhookTrigger as IncomingWebhookTrigger$1, InferFieldsOutput, RecordTrigger as RecordTrigger$1, ResolverExecutedTrigger as ResolverExecutedTrigger$1, ResolverInput, ScheduleTriggerInput, TailorDBType, TailorField, TailorUser, WebhookOperation, output as output$1 } from "./types-DcpYyMM2.mjs";
|
|
4
4
|
import { EmptyObject } from "type-fest";
|
|
5
5
|
import { Client } from "@urql/core";
|
|
6
6
|
import { StandardCRON } from "ts-cron-validator";
|
|
7
7
|
|
|
8
|
+
//#region src/configure/types/env.d.ts
|
|
9
|
+
declare global {
|
|
10
|
+
namespace TailorSDK {
|
|
11
|
+
interface Env {}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
type InferredEnv = keyof TailorSDK.Env extends never ? Record<string, string> : TailorSDK.Env;
|
|
15
|
+
/** Represents environment variables in the Tailor platform. */
|
|
16
|
+
type TailorEnv = InferredEnv;
|
|
17
|
+
//#endregion
|
|
8
18
|
//#region src/configure/services/resolver/resolver.d.ts
|
|
9
19
|
type Context<Input extends Record<string, TailorField<any>> | undefined> = {
|
|
10
20
|
input: Input extends Record<string, TailorField<any>> ? InferFieldsOutput<Input> : never;
|
|
11
21
|
user: TailorUser;
|
|
22
|
+
env: TailorEnv;
|
|
12
23
|
};
|
|
13
24
|
type OutputType<O> = O extends TailorField<any> ? output$1<O> : O extends Record<string, TailorField<any>> ? InferFieldsOutput<O> : never;
|
|
14
25
|
declare function createResolver<Input extends Record<string, TailorField<any>> | undefined = undefined, Output extends TailorField<any> | Record<string, TailorField<any>> = TailorField<any>>(config: Omit<ResolverInput, "input" | "output" | "body"> & Readonly<{
|
|
@@ -30,7 +41,9 @@ type ResolverConfig = ReturnType<typeof createResolver<any, any>>;
|
|
|
30
41
|
//#endregion
|
|
31
42
|
//#region src/configure/services/executor/operation.d.ts
|
|
32
43
|
type FunctionOperation$1<Args> = Omit<FunctionOperation, "body"> & {
|
|
33
|
-
body: (args: Args
|
|
44
|
+
body: (args: Args & {
|
|
45
|
+
env: TailorEnv;
|
|
46
|
+
}) => void | Promise<void>;
|
|
34
47
|
};
|
|
35
48
|
type UrqlOperationArgs = Parameters<Client["query"] | Client["mutation"]>;
|
|
36
49
|
type GqlOperation$1<Args> = Omit<GqlOperation, "query" | "variables"> & {
|
|
@@ -156,7 +156,7 @@ const FunctionOperationSchema = z.object({
|
|
|
156
156
|
});
|
|
157
157
|
const GqlOperationSchema = z.object({
|
|
158
158
|
kind: z.literal("graphql"),
|
|
159
|
-
appName: z.string(),
|
|
159
|
+
appName: z.string().optional(),
|
|
160
160
|
query: z.string(),
|
|
161
161
|
variables: functionSchema.optional(),
|
|
162
162
|
invoker: InvokerSchema.optional()
|
|
@@ -467,9 +467,11 @@ var Application = class {
|
|
|
467
467
|
_subgraphs = [];
|
|
468
468
|
_executorService = void 0;
|
|
469
469
|
_staticWebsiteServices = [];
|
|
470
|
+
_env = {};
|
|
470
471
|
constructor(name, config) {
|
|
471
472
|
this.name = name;
|
|
472
473
|
this.config = config;
|
|
474
|
+
this._env = config.env || {};
|
|
473
475
|
}
|
|
474
476
|
addSubgraph(type, name) {
|
|
475
477
|
this._subgraphs.push({
|
|
@@ -498,6 +500,9 @@ var Application = class {
|
|
|
498
500
|
get staticWebsiteServices() {
|
|
499
501
|
return this._staticWebsiteServices;
|
|
500
502
|
}
|
|
503
|
+
get env() {
|
|
504
|
+
return this._env;
|
|
505
|
+
}
|
|
501
506
|
get applications() {
|
|
502
507
|
return [this];
|
|
503
508
|
}
|
|
@@ -1579,13 +1584,20 @@ async function loadConfig(configPath) {
|
|
|
1579
1584
|
function extractAttributesFromConfig(config) {
|
|
1580
1585
|
return collectAttributesFromConfig(config);
|
|
1581
1586
|
}
|
|
1582
|
-
function generateTypeDefinition(attributeMap, attributeList) {
|
|
1587
|
+
function generateTypeDefinition(attributeMap, attributeList, env) {
|
|
1583
1588
|
const mapFields = attributeMap ? Object.entries(attributeMap).map(([key, value]) => ` ${key}: ${value};`).join("\n") : "";
|
|
1584
1589
|
const mapBody = !attributeMap || Object.keys(attributeMap).length === 0 ? "{}" : `{
|
|
1585
1590
|
${mapFields}
|
|
1586
1591
|
}`;
|
|
1587
1592
|
const listBody = `{
|
|
1588
1593
|
__tuple?: ${attributeList ? `[${attributeList.map(() => "string").join(", ")}]` : "[]"};
|
|
1594
|
+
}`;
|
|
1595
|
+
const envFields = env ? Object.entries(env).map(([key, value]) => {
|
|
1596
|
+
const valueType = typeof value === "string" ? `"${value}"` : String(value);
|
|
1597
|
+
return ` ${key}: ${valueType};`;
|
|
1598
|
+
}).join("\n") : "";
|
|
1599
|
+
const envBody = !env || Object.keys(env).length === 0 ? "{}" : `{
|
|
1600
|
+
${envFields}
|
|
1589
1601
|
}`;
|
|
1590
1602
|
return ml`
|
|
1591
1603
|
// This file is auto-generated by @tailor-platform/sdk
|
|
@@ -1596,6 +1608,7 @@ declare global {
|
|
|
1596
1608
|
namespace TailorSDK {
|
|
1597
1609
|
interface AttributeMap ${mapBody}
|
|
1598
1610
|
interface AttributeList ${listBody}
|
|
1611
|
+
interface Env ${envBody}
|
|
1599
1612
|
}
|
|
1600
1613
|
}
|
|
1601
1614
|
|
|
@@ -1640,13 +1653,12 @@ function resolveTypeDefinitionPath(configPath) {
|
|
|
1640
1653
|
async function generateUserTypes(config, configPath) {
|
|
1641
1654
|
try {
|
|
1642
1655
|
const { attributeMap, attributeList } = extractAttributesFromConfig(config);
|
|
1643
|
-
if (!attributeMap && !attributeList)
|
|
1644
|
-
console.log(styleText("cyan", "No attributes found in configuration"));
|
|
1645
|
-
return;
|
|
1646
|
-
}
|
|
1656
|
+
if (!attributeMap && !attributeList) console.log(styleText("cyan", "No attributes found in configuration"));
|
|
1647
1657
|
if (attributeMap) console.log("Extracted AttributeMap:", attributeMap);
|
|
1648
1658
|
if (attributeList) console.log("Extracted AttributeList:", attributeList);
|
|
1649
|
-
const
|
|
1659
|
+
const env = config.env;
|
|
1660
|
+
if (env) console.log("Extracted Env:", env);
|
|
1661
|
+
const typeDefContent = generateTypeDefinition(attributeMap, attributeList, env);
|
|
1650
1662
|
const outputPath = resolveTypeDefinitionPath(configPath);
|
|
1651
1663
|
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
1652
1664
|
fs.writeFileSync(outputPath, typeDefContent);
|
|
@@ -3811,6 +3823,25 @@ async function confirmUnmanagedResources(resources, appName, yes) {
|
|
|
3811
3823
|
To override, run again and confirm, or use --yes flag.
|
|
3812
3824
|
`);
|
|
3813
3825
|
}
|
|
3826
|
+
async function confirmImportantResourceDeletion(resources, yes) {
|
|
3827
|
+
if (resources.length === 0) return;
|
|
3828
|
+
consola.warn("The following resources will be deleted:");
|
|
3829
|
+
console.log(` ${chalk.cyan("Resources")}:`);
|
|
3830
|
+
for (const r of resources) console.log(` • ${chalk.bold(r.resourceType)} ${chalk.red(`"${r.resourceName}"`)}`);
|
|
3831
|
+
console.log("");
|
|
3832
|
+
console.log(chalk.yellow(" Deleting these resources will permanently remove all associated data."));
|
|
3833
|
+
if (yes) {
|
|
3834
|
+
consola.success("Deleting resources (--yes flag specified)...");
|
|
3835
|
+
return;
|
|
3836
|
+
}
|
|
3837
|
+
if (!await consola.prompt("Are you sure you want to delete these resources?", {
|
|
3838
|
+
type: "confirm",
|
|
3839
|
+
initial: false
|
|
3840
|
+
})) throw new Error(ml`
|
|
3841
|
+
Apply cancelled. Resources will not be deleted.
|
|
3842
|
+
To override, run again and confirm, or use --yes flag.
|
|
3843
|
+
`);
|
|
3844
|
+
}
|
|
3814
3845
|
|
|
3815
3846
|
//#endregion
|
|
3816
3847
|
//#region src/cli/apply/services/executor.ts
|
|
@@ -3871,7 +3902,7 @@ async function planExecutor({ client, workspaceId, application }) {
|
|
|
3871
3902
|
name: executor.name,
|
|
3872
3903
|
request: {
|
|
3873
3904
|
workspaceId,
|
|
3874
|
-
executor: protoExecutor(executor)
|
|
3905
|
+
executor: protoExecutor(application.name, executor, application.env)
|
|
3875
3906
|
},
|
|
3876
3907
|
metaRequest
|
|
3877
3908
|
});
|
|
@@ -3880,7 +3911,7 @@ async function planExecutor({ client, workspaceId, application }) {
|
|
|
3880
3911
|
name: executor.name,
|
|
3881
3912
|
request: {
|
|
3882
3913
|
workspaceId,
|
|
3883
|
-
executor: protoExecutor(executor)
|
|
3914
|
+
executor: protoExecutor(application.name, executor, application.env)
|
|
3884
3915
|
},
|
|
3885
3916
|
metaRequest
|
|
3886
3917
|
});
|
|
@@ -3904,7 +3935,7 @@ async function planExecutor({ client, workspaceId, application }) {
|
|
|
3904
3935
|
resourceOwners
|
|
3905
3936
|
};
|
|
3906
3937
|
}
|
|
3907
|
-
function protoExecutor(executor) {
|
|
3938
|
+
function protoExecutor(appName, executor, env) {
|
|
3908
3939
|
const trigger = executor.trigger;
|
|
3909
3940
|
let triggerType;
|
|
3910
3941
|
let triggerConfig;
|
|
@@ -3993,7 +4024,7 @@ function protoExecutor(executor) {
|
|
|
3993
4024
|
targetConfig = { config: {
|
|
3994
4025
|
case: "tailorGraphql",
|
|
3995
4026
|
value: {
|
|
3996
|
-
appName: target.appName,
|
|
4027
|
+
appName: target.appName ?? appName,
|
|
3997
4028
|
query: target.query,
|
|
3998
4029
|
variables: target.variables ? { expr: `(${target.variables.toString()})(args)` } : void 0,
|
|
3999
4030
|
invoker: target.invoker ? {
|
|
@@ -4014,7 +4045,7 @@ function protoExecutor(executor) {
|
|
|
4014
4045
|
value: {
|
|
4015
4046
|
name: `${executor.name}__target`,
|
|
4016
4047
|
script,
|
|
4017
|
-
variables: { expr:
|
|
4048
|
+
variables: { expr: `({ ...args, appNamespace: args.namespaceName, env: ${JSON.stringify(env)} })` },
|
|
4018
4049
|
invoker: target.invoker ? {
|
|
4019
4050
|
namespace: target.invoker.authName,
|
|
4020
4051
|
machineUserName: target.invoker.machineUser
|
|
@@ -4097,7 +4128,7 @@ async function planPipeline({ client, workspaceId, application }) {
|
|
|
4097
4128
|
const executors = Object.values(await application.executorService?.loadExecutors() ?? {});
|
|
4098
4129
|
const { changeSet: serviceChangeSet, conflicts, unmanaged, resourceOwners } = await planServices$1(client, workspaceId, application.name, pipelines);
|
|
4099
4130
|
const deletedServices = serviceChangeSet.deletes.map((del) => del.name);
|
|
4100
|
-
const resolverChangeSet = await planResolvers(client, workspaceId, pipelines, executors, deletedServices);
|
|
4131
|
+
const resolverChangeSet = await planResolvers(client, workspaceId, pipelines, executors, deletedServices, application.env);
|
|
4101
4132
|
serviceChangeSet.print();
|
|
4102
4133
|
resolverChangeSet.print();
|
|
4103
4134
|
return {
|
|
@@ -4188,7 +4219,7 @@ async function planServices$1(client, workspaceId, appName, pipelines) {
|
|
|
4188
4219
|
resourceOwners
|
|
4189
4220
|
};
|
|
4190
4221
|
}
|
|
4191
|
-
async function planResolvers(client, workspaceId, pipelines, executors, deletedServices) {
|
|
4222
|
+
async function planResolvers(client, workspaceId, pipelines, executors, deletedServices, env) {
|
|
4192
4223
|
const changeSet = new ChangeSet("Pipeline resolvers");
|
|
4193
4224
|
const fetchResolvers = (namespaceName) => {
|
|
4194
4225
|
return fetchAll(async (pageToken) => {
|
|
@@ -4219,7 +4250,7 @@ async function planResolvers(client, workspaceId, pipelines, executors, deletedS
|
|
|
4219
4250
|
request: {
|
|
4220
4251
|
workspaceId,
|
|
4221
4252
|
namespaceName: pipeline.namespace,
|
|
4222
|
-
pipelineResolver: processResolver(resolver, executorUsedResolvers)
|
|
4253
|
+
pipelineResolver: processResolver(resolver, executorUsedResolvers, env)
|
|
4223
4254
|
}
|
|
4224
4255
|
});
|
|
4225
4256
|
existingNameSet.delete(resolver.name);
|
|
@@ -4228,7 +4259,7 @@ async function planResolvers(client, workspaceId, pipelines, executors, deletedS
|
|
|
4228
4259
|
request: {
|
|
4229
4260
|
workspaceId,
|
|
4230
4261
|
namespaceName: pipeline.namespace,
|
|
4231
|
-
pipelineResolver: processResolver(resolver, executorUsedResolvers)
|
|
4262
|
+
pipelineResolver: processResolver(resolver, executorUsedResolvers, env)
|
|
4232
4263
|
}
|
|
4233
4264
|
});
|
|
4234
4265
|
existingNameSet.forEach((name) => {
|
|
@@ -4254,7 +4285,7 @@ async function planResolvers(client, workspaceId, pipelines, executors, deletedS
|
|
|
4254
4285
|
});
|
|
4255
4286
|
return changeSet;
|
|
4256
4287
|
}
|
|
4257
|
-
function processResolver(resolver, executorUsedResolvers) {
|
|
4288
|
+
function processResolver(resolver, executorUsedResolvers, env) {
|
|
4258
4289
|
const functionPath = path.join(getDistDir(), "functions", `${resolver.name}__body.js`);
|
|
4259
4290
|
let functionCode = "";
|
|
4260
4291
|
try {
|
|
@@ -4268,7 +4299,7 @@ function processResolver(resolver, executorUsedResolvers) {
|
|
|
4268
4299
|
description: `${resolver.name} function body`,
|
|
4269
4300
|
operationType: PipelineResolver_OperationType.FUNCTION,
|
|
4270
4301
|
operationSource: functionCode,
|
|
4271
|
-
operationHook: { expr: `({ ...context.pipeline, input: context.args, user: ${tailorUserMap} });` },
|
|
4302
|
+
operationHook: { expr: `({ ...context.pipeline, input: context.args, user: ${tailorUserMap}, env: ${JSON.stringify(env)} });` },
|
|
4272
4303
|
postScript: `args.body`
|
|
4273
4304
|
}];
|
|
4274
4305
|
const typeBaseName = inflection.camelize(resolver.name);
|
|
@@ -5012,6 +5043,7 @@ async function apply(options) {
|
|
|
5012
5043
|
...pipeline.conflicts,
|
|
5013
5044
|
...executor.conflicts
|
|
5014
5045
|
];
|
|
5046
|
+
await confirmOwnerConflict(allConflicts, application.name, yes);
|
|
5015
5047
|
const allUnmanaged = [
|
|
5016
5048
|
...tailorDB.unmanaged,
|
|
5017
5049
|
...staticWebsite.unmanaged,
|
|
@@ -5020,8 +5052,17 @@ async function apply(options) {
|
|
|
5020
5052
|
...pipeline.unmanaged,
|
|
5021
5053
|
...executor.unmanaged
|
|
5022
5054
|
];
|
|
5023
|
-
await confirmOwnerConflict(allConflicts, application.name, yes);
|
|
5024
5055
|
await confirmUnmanagedResources(allUnmanaged, application.name, yes);
|
|
5056
|
+
const importantDeletions = [];
|
|
5057
|
+
for (const del of tailorDB.changeSet.type.deletes) importantDeletions.push({
|
|
5058
|
+
resourceType: "TailorDB type",
|
|
5059
|
+
resourceName: del.name
|
|
5060
|
+
});
|
|
5061
|
+
for (const del of staticWebsite.changeSet.deletes) importantDeletions.push({
|
|
5062
|
+
resourceType: "StaticWebsite",
|
|
5063
|
+
resourceName: del.name
|
|
5064
|
+
});
|
|
5065
|
+
await confirmImportantResourceDeletion(importantDeletions, yes);
|
|
5025
5066
|
const resourceOwners = new Set([
|
|
5026
5067
|
...tailorDB.resourceOwners,
|
|
5027
5068
|
...staticWebsite.resourceOwners,
|
|
@@ -1252,8 +1252,9 @@ type GeneratorConfig = z.input<typeof BaseGeneratorConfigSchema>;
|
|
|
1252
1252
|
type CodeGeneratorBase = z.output<typeof CodeGeneratorSchema>;
|
|
1253
1253
|
//#endregion
|
|
1254
1254
|
//#region src/configure/config.d.ts
|
|
1255
|
-
interface AppConfig<Auth extends AuthConfig = AuthConfig, Idp extends IdPConfig[] = IdPConfig[], StaticWebsites extends StaticWebsiteConfig[] = StaticWebsiteConfig[]> {
|
|
1255
|
+
interface AppConfig<Auth extends AuthConfig = AuthConfig, Idp extends IdPConfig[] = IdPConfig[], StaticWebsites extends StaticWebsiteConfig[] = StaticWebsiteConfig[], Env extends Record<string, string | number | boolean> = Record<string, string | number | boolean>> {
|
|
1256
1256
|
name: string;
|
|
1257
|
+
env?: Env;
|
|
1257
1258
|
cors?: string[];
|
|
1258
1259
|
allowedIPAddresses?: string[];
|
|
1259
1260
|
disableIntrospection?: boolean;
|
|
@@ -1321,7 +1322,7 @@ declare const FunctionOperationSchema: z.ZodObject<{
|
|
|
1321
1322
|
}, z.core.$strip>;
|
|
1322
1323
|
declare const GqlOperationSchema: z.ZodObject<{
|
|
1323
1324
|
kind: z.ZodLiteral<"graphql">;
|
|
1324
|
-
appName: z.ZodString
|
|
1325
|
+
appName: z.ZodOptional<z.ZodString>;
|
|
1325
1326
|
query: z.ZodString;
|
|
1326
1327
|
variables: z.ZodOptional<z.ZodCustom<Function, Function>>;
|
|
1327
1328
|
invoker: z.ZodOptional<z.ZodObject<{
|
|
@@ -1373,7 +1374,7 @@ declare const ExecutorSchema: z.ZodObject<{
|
|
|
1373
1374
|
}, z.core.$strip>>;
|
|
1374
1375
|
}, z.core.$strip>, z.ZodObject<{
|
|
1375
1376
|
kind: z.ZodLiteral<"graphql">;
|
|
1376
|
-
appName: z.ZodString
|
|
1377
|
+
appName: z.ZodOptional<z.ZodString>;
|
|
1377
1378
|
query: z.ZodString;
|
|
1378
1379
|
variables: z.ZodOptional<z.ZodCustom<Function, Function>>;
|
|
1379
1380
|
invoker: z.ZodOptional<z.ZodObject<{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference path="./../../plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { TailorDBType, TailorField, TailorUser } from "../../types-
|
|
4
|
-
import { output } from "../../index-
|
|
3
|
+
import { TailorDBType, TailorField, TailorUser } from "../../types-DcpYyMM2.mjs";
|
|
4
|
+
import { output } from "../../index-DxmBZtRb.mjs";
|
|
5
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
6
|
|
|
7
7
|
//#region src/utils/test/index.d.ts
|
package/docs/configuration.md
CHANGED
|
@@ -130,3 +130,34 @@ export default defineConfig({
|
|
|
130
130
|
**description**: Description of the site.
|
|
131
131
|
|
|
132
132
|
**allowedIPAddresses**: List of IP addresses allowed to access the site in CIDR format.
|
|
133
|
+
|
|
134
|
+
### Environment Variables
|
|
135
|
+
|
|
136
|
+
Define environment variables that can be accessed in resolvers and executors:
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
export default defineConfig({
|
|
140
|
+
name: "my-app",
|
|
141
|
+
env: {
|
|
142
|
+
foo: 1,
|
|
143
|
+
bar: "hello",
|
|
144
|
+
baz: true,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
// In resolvers
|
|
151
|
+
body: ({ input, env }) => {
|
|
152
|
+
return {
|
|
153
|
+
result: input.multiplier * env.foo,
|
|
154
|
+
message: env.bar,
|
|
155
|
+
enabled: env.baz,
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// In executors
|
|
160
|
+
body: ({ newRecord, env }) => {
|
|
161
|
+
console.log(`Environment: ${env.bar}, User: ${newRecord.name}`);
|
|
162
|
+
};
|
|
163
|
+
```
|