@tailor-platform/sdk 1.40.1 → 1.43.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 +44 -0
- package/README.md +23 -0
- package/dist/{actor-B2oEmlTc.d.mts → actor-DzCuoMlP.d.mts} +2 -2
- package/dist/{application-EvhIIVg0.mjs → application-DQpD_kHR.mjs} +87 -8
- package/dist/application-DQpD_kHR.mjs.map +1 -0
- package/dist/application-DUcmoFdc.mjs +4 -0
- package/dist/brand-Ll48SMXe.mjs.map +1 -1
- package/dist/cli/index.mjs +31 -26
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli/lib.d.mts +49 -7
- package/dist/cli/lib.mjs +3 -3
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/configure/index.d.mts +5 -5
- package/dist/configure/index.mjs +83 -3
- package/dist/configure/index.mjs.map +1 -1
- package/dist/{index-Chvw1Eod.d.mts → index-0Dk-fDWi.d.mts} +2 -2
- package/dist/{index-CiNNNpuH.d.mts → index-BEEL1-6Z.d.mts} +2 -2
- package/dist/{index-D_ezppY7.d.mts → index-Br4XCvX1.d.mts} +103 -86
- package/dist/{index-BtXZdz-F.d.mts → index-DdsUV-aA.d.mts} +2 -2
- package/dist/{index-reFAYSX7.d.mts → index-ZZYEd_0R.d.mts} +2 -2
- package/dist/{job-p6zf8Qpg.mjs → job-BOvKyNdT.mjs} +15 -9
- package/dist/job-BOvKyNdT.mjs.map +1 -0
- package/dist/plugin/builtin/enum-constants/index.d.mts +1 -1
- package/dist/plugin/builtin/file-utils/index.d.mts +1 -1
- package/dist/plugin/builtin/kysely-type/index.d.mts +1 -1
- package/dist/plugin/builtin/seed/index.d.mts +1 -1
- package/dist/plugin/index.d.mts +2 -2
- package/dist/{runtime-B9R1TzLD.mjs → runtime-Bn68JXnL.mjs} +195 -77
- package/dist/runtime-Bn68JXnL.mjs.map +1 -0
- package/dist/{tailor-db-field-CoFKRCYW.d.mts → tailor-db-field-D_z185oq.d.mts} +36 -6
- package/dist/utils/test/index.d.mts +36 -3
- package/dist/utils/test/index.mjs +78 -9
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/{workflow.generated-Btz6srLR.d.mts → workflow.generated-CDCnZNkH.d.mts} +2 -2
- package/docs/cli/function.md +83 -1
- package/docs/cli-reference.md +3 -1
- package/docs/services/executor.md +4 -0
- package/docs/services/idp.md +16 -0
- package/docs/services/resolver.md +4 -2
- package/docs/services/workflow.md +117 -3
- package/docs/testing.md +95 -7
- package/package.json +17 -17
- package/dist/application-CE2s_a6w.mjs +0 -4
- package/dist/application-EvhIIVg0.mjs.map +0 -1
- package/dist/job-p6zf8Qpg.mjs.map +0 -1
- package/dist/runtime-B9R1TzLD.mjs.map +0 -1
|
@@ -17,11 +17,22 @@ type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* A looser version of JsonValue that accepts interfaces.
|
|
20
|
-
* TypeScript interfaces don't have index signatures by default,
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* TypeScript interfaces don't have index signatures by default, so they can't
|
|
21
|
+
* be assigned to JsonValue's `{ [key: string]: JsonValue }`. This type uses a
|
|
22
|
+
* recursive structural check instead.
|
|
23
|
+
*
|
|
24
|
+
* Rejection rules:
|
|
25
|
+
* - Functions are rejected (top-level or as property values).
|
|
26
|
+
* - Objects with a `toJSON` method are rejected (can't faithfully round-trip).
|
|
27
|
+
* - Class instances that expose methods are rejected via the property walk
|
|
28
|
+
* (methods are function-typed properties, which resolve to `never`).
|
|
29
|
+
*
|
|
30
|
+
* Limitation: class instances whose declared type has only data properties
|
|
31
|
+
* (for example `Error`, or user-defined DTO classes) are structurally
|
|
32
|
+
* indistinguishable from plain objects and cannot be rejected here. The
|
|
33
|
+
* platform performs the authoritative check at runtime.
|
|
23
34
|
*/
|
|
24
|
-
type JsonCompatible<T> = T extends string | number | boolean | null | undefined ? T : T extends readonly (infer U)[] ? JsonCompatible<U>[] : T extends object ? T extends {
|
|
35
|
+
type JsonCompatible<T> = T extends string | number | boolean | null | undefined ? T : T extends readonly (infer U)[] ? JsonCompatible<U>[] : T extends Function ? never : T extends object ? T extends {
|
|
25
36
|
toJSON: () => unknown;
|
|
26
37
|
} ? never : { [K in keyof T]: JsonCompatible<T[K]> } : never;
|
|
27
38
|
//#endregion
|
|
@@ -58,6 +69,25 @@ type TailorUser = {
|
|
|
58
69
|
};
|
|
59
70
|
/** Represents an unauthenticated user in the Tailor platform. */
|
|
60
71
|
declare const unauthenticatedTailorUser: TailorUser;
|
|
72
|
+
/**
|
|
73
|
+
* The invoker of the current function execution.
|
|
74
|
+
*
|
|
75
|
+
* Reflects `authInvoker` delegation: when `authInvoker` is specified, this is
|
|
76
|
+
* the machine user; otherwise it is the calling user.
|
|
77
|
+
* Distinct from resolver's `user` (the authenticated caller) and executor's
|
|
78
|
+
* `actor` (the subject of the event).
|
|
79
|
+
*
|
|
80
|
+
* `null` for anonymous requests.
|
|
81
|
+
*
|
|
82
|
+
* TODO(v2): unify with `TailorUser` — same underlying principal shape.
|
|
83
|
+
*/
|
|
84
|
+
type TailorInvoker = {
|
|
85
|
+
/** The ID of the invoker (user ID or machine user ID). */id: string; /** The type of the invoker. */
|
|
86
|
+
type: "user" | "machine_user"; /** The ID of the workspace the invoker belongs to. */
|
|
87
|
+
workspaceId: string; /** A map of the invoker's attributes. */
|
|
88
|
+
attributes: InferredAttributeMap; /** A list of the invoker's attribute IDs. */
|
|
89
|
+
attributeList: InferredAttributeList;
|
|
90
|
+
} | null;
|
|
61
91
|
//#endregion
|
|
62
92
|
//#region src/types/validation.d.ts
|
|
63
93
|
/**
|
|
@@ -1597,5 +1627,5 @@ interface TailorDBType<Fields extends Record<string, TailorAnyDBField> = any, Us
|
|
|
1597
1627
|
type TailorAnyDBType = TailorDBType<any, any>;
|
|
1598
1628
|
type TailorDBInstance<Fields extends Record<string, TailorAnyDBField> = any, User extends object = InferredAttributeMap> = TailorDBType<Fields, User>;
|
|
1599
1629
|
//#endregion
|
|
1600
|
-
export { ResolverInput as $, RelationType as A, FieldMetadata as At, BeforeLoginHookArgs as B, InferredAttributeMap as Bt, ResolverReadyContext as C, SCIMAuthorization as Ct, DefinedDBFieldMetadata as D, ArrayFieldOutput as Dt, DBFieldMetadata as E, TenantProvider as Et, AuthConfig as F, FieldValidateInput as Ft, UserAttributeListKey as G,
|
|
1601
|
-
//# sourceMappingURL=tailor-db-field-
|
|
1630
|
+
export { ResolverInput as $, RelationType as A, FieldMetadata as At, BeforeLoginHookArgs as B, InferredAttributeMap as Bt, ResolverReadyContext as C, SCIMAuthorization as Ct, DefinedDBFieldMetadata as D, ArrayFieldOutput as Dt, DBFieldMetadata as E, TenantProvider as Et, AuthConfig as F, FieldValidateInput as Ft, UserAttributeListKey as G, JsonCompatible as Gt, OAuth2ClientGrantType as H, TailorUser as Ht, AuthConnectionTokenResult as I, Validators as It, ValueOperand as J, output as Jt, UserAttributeMap as K, JsonValue as Kt, AuthExternalConfig as L, AttributeList as Lt, TailorDBServiceInput as M, FieldOutput$1 as Mt, TailorDBType$1 as N, TailorFieldType as Nt, GqlOperationsConfig as O, DefinedFieldMetadata as Ot, TypeSourceInfoEntry as P, TailorToTs as Pt, Resolver as Q, AuthOwnConfig as R, AttributeMap as Rt, ResolverNamespaceData as S, SCIMAttributeMapping as St, TailorDBReadyContext as T, SCIMResource as Tt, SCIMAttributeType as U, unauthenticatedTailorUser as Ut, DefinedAuth as V, TailorInvoker as Vt, UserAttributeKey as W, InferFieldsOutput as Wt, AuthConnectionConfig as X, TailorField as Y, AuthConnectionOAuth2Config as Z, PluginProcessContext as _, IdProvider as _t, NamespacePluginOutput as a, FunctionOperation as at, ExecutorReadyContext as b, SAML as bt, PluginConfigs as c, IncomingWebhookTrigger as ct, PluginGeneratedExecutor as d, TailorDBTrigger as dt, GeneratorConfig as et, PluginGeneratedExecutorWithFile as f, WebhookOperation as ft, PluginOutput as g, IDToken as gt, PluginNamespaceProcessContext as h, BuiltinIdP as ht, TailorDBType as i, ExecutorInput as it, SerialConfig as j, FieldOptions as jt, IndexDef as k, EnumValue as kt, PluginExecutorContext as l, ResolverExecutedTrigger as lt, PluginGeneratedType as m, AuthInvoker as mt, TailorAnyDBType as n, AuthAccessTokenTrigger as nt, Plugin as o, GqlOperation as ot, PluginGeneratedResolver as p, WorkflowOperation as pt, UsernameFieldKey as q, Prettify as qt, TailorDBField as r, Executor as rt, PluginAttachment as s, IdpUserTrigger as st, TailorAnyDBField as t, BaseGeneratorConfig as tt, PluginExecutorContextBase as u, ScheduleTriggerInput as ut, TailorDBTypeForPlugin as v, OAuth2ClientInput as vt, TailorDBNamespaceData as w, SCIMConfig as wt, GeneratorResult as x, SCIMAttribute as xt, TypePluginOutput as y, OIDC as yt, AuthServiceInput as z, InferredAttributeList as zt };
|
|
1631
|
+
//# sourceMappingURL=tailor-db-field-D_z185oq.d.mts.map
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/// <reference types="@tailor-platform/function-types" />
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Vt as TailorInvoker } from "../../tailor-db-field-D_z185oq.mjs";
|
|
3
|
+
import { D as TailorDBType } from "../../workflow.generated-CDCnZNkH.mjs";
|
|
4
|
+
import { dt as WORKFLOW_TEST_ENV_KEY, n as output, yt as TailorField } from "../../index-Br4XCvX1.mjs";
|
|
4
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
6
|
|
|
6
7
|
//#region src/utils/test/mock.d.ts
|
|
7
8
|
type MainFunction = (args: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
8
9
|
type QueryResolver = (query: string, params: unknown[]) => unknown[];
|
|
9
10
|
type JobHandler = (jobName: string, args: unknown) => unknown;
|
|
11
|
+
type WaitHandler = (key: string, payload: unknown) => unknown;
|
|
12
|
+
type ResolveHandler = (executionId: string, key: string, callback: (payload: unknown) => unknown) => Promise<void> | void;
|
|
10
13
|
/**
|
|
11
14
|
* Sets up a mock for `globalThis.tailordb.Client` used in bundled resolver/executor tests.
|
|
12
15
|
* @param resolver - Optional function to resolve query results. Defaults to returning empty arrays.
|
|
@@ -24,6 +27,8 @@ declare function setupTailordbMock(resolver?: QueryResolver): {
|
|
|
24
27
|
};
|
|
25
28
|
/**
|
|
26
29
|
* Sets up a mock for `globalThis.tailor.workflow.triggerJobFunction` used in bundled workflow tests.
|
|
30
|
+
* `wait`/`resolve` are stubbed to throw a helpful error directing to `setupWaitPointMock()`,
|
|
31
|
+
* so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.
|
|
27
32
|
* @param handler - Function that handles triggered job calls and returns results.
|
|
28
33
|
* @returns Object containing an array of triggered jobs for assertions.
|
|
29
34
|
*/
|
|
@@ -33,11 +38,39 @@ declare function setupWorkflowMock(handler: JobHandler): {
|
|
|
33
38
|
args: unknown;
|
|
34
39
|
}[];
|
|
35
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Sets up a mock for `globalThis.tailor.context.getInvoker` used in bundled
|
|
43
|
+
* resolver/executor/workflow tests.
|
|
44
|
+
* @param invoker - The `TailorInvoker` value to return, or `null` for anonymous.
|
|
45
|
+
*/
|
|
46
|
+
declare function setupInvokerMock(invoker: TailorInvoker): void;
|
|
36
47
|
/**
|
|
37
48
|
* Sets up a mock for `globalThis.TailorErrors` used in bundled resolver tests.
|
|
38
49
|
* Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.
|
|
39
50
|
*/
|
|
40
51
|
declare function setupTailorErrorsMock(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.
|
|
54
|
+
* `triggerJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,
|
|
55
|
+
* so mistakenly triggering a job without job mocks produces a clear message instead of silently returning undefined.
|
|
56
|
+
* @param config - Optional handlers for wait and resolve calls.
|
|
57
|
+
* @param config.onWait - Handler called when wait is invoked.
|
|
58
|
+
* @param config.onResolve - Handler called when resolve is invoked.
|
|
59
|
+
* @returns Object containing arrays of wait and resolve calls for assertions.
|
|
60
|
+
*/
|
|
61
|
+
declare function setupWaitPointMock(config?: {
|
|
62
|
+
onWait?: WaitHandler;
|
|
63
|
+
onResolve?: ResolveHandler;
|
|
64
|
+
}): {
|
|
65
|
+
waitCalls: {
|
|
66
|
+
key: string;
|
|
67
|
+
payload: unknown;
|
|
68
|
+
}[];
|
|
69
|
+
resolveCalls: {
|
|
70
|
+
executionId: string;
|
|
71
|
+
key: string;
|
|
72
|
+
}[];
|
|
73
|
+
};
|
|
41
74
|
/**
|
|
42
75
|
* Creates a function that imports a bundled JS file and returns its `main` export.
|
|
43
76
|
* Used to test bundled output from `apply --buildOnly`.
|
|
@@ -83,5 +116,5 @@ declare function createStandardSchema<T = Record<string, unknown>>(schemaType: T
|
|
|
83
116
|
};
|
|
84
117
|
};
|
|
85
118
|
//#endregion
|
|
86
|
-
export { WORKFLOW_TEST_ENV_KEY, createImportMain, createStandardSchema, createTailorDBHook, setupTailorErrorsMock, setupTailordbMock, setupWorkflowMock, unauthenticatedTailorUser };
|
|
119
|
+
export { WORKFLOW_TEST_ENV_KEY, createImportMain, createStandardSchema, createTailorDBHook, setupInvokerMock, setupTailorErrorsMock, setupTailordbMock, setupWaitPointMock, setupWorkflowMock, unauthenticatedTailorUser };
|
|
87
120
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { t as WORKFLOW_TEST_ENV_KEY } from "../../job-
|
|
2
|
+
import { t as WORKFLOW_TEST_ENV_KEY } from "../../job-BOvKyNdT.mjs";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
|
|
@@ -42,6 +42,8 @@ function setupTailordbMock(resolver = () => []) {
|
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Sets up a mock for `globalThis.tailor.workflow.triggerJobFunction` used in bundled workflow tests.
|
|
45
|
+
* `wait`/`resolve` are stubbed to throw a helpful error directing to `setupWaitPointMock()`,
|
|
46
|
+
* so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.
|
|
45
47
|
* @param handler - Function that handles triggered job calls and returns results.
|
|
46
48
|
* @returns Object containing an array of triggered jobs for assertions.
|
|
47
49
|
*/
|
|
@@ -49,17 +51,44 @@ function setupWorkflowMock(handler) {
|
|
|
49
51
|
const triggeredJobs = [];
|
|
50
52
|
GlobalThis.tailor = {
|
|
51
53
|
...GlobalThis.tailor,
|
|
52
|
-
workflow: {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
workflow: {
|
|
55
|
+
wait: () => {
|
|
56
|
+
throw new Error("tailor.workflow.wait is not mocked. Use setupWaitPointMock() in tests.");
|
|
57
|
+
},
|
|
58
|
+
resolve: async () => {
|
|
59
|
+
throw new Error("tailor.workflow.resolve is not mocked. Use setupWaitPointMock() in tests.");
|
|
60
|
+
},
|
|
61
|
+
...GlobalThis.tailor?.workflow,
|
|
62
|
+
triggerJobFunction: (jobName, args) => {
|
|
63
|
+
triggeredJobs.push({
|
|
64
|
+
jobName,
|
|
65
|
+
args
|
|
66
|
+
});
|
|
67
|
+
return handler(jobName, args);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
59
70
|
};
|
|
60
71
|
return { triggeredJobs };
|
|
61
72
|
}
|
|
62
73
|
/**
|
|
74
|
+
* Sets up a mock for `globalThis.tailor.context.getInvoker` used in bundled
|
|
75
|
+
* resolver/executor/workflow tests.
|
|
76
|
+
* @param invoker - The `TailorInvoker` value to return, or `null` for anonymous.
|
|
77
|
+
*/
|
|
78
|
+
function setupInvokerMock(invoker) {
|
|
79
|
+
const raw = invoker ? {
|
|
80
|
+
id: invoker.id,
|
|
81
|
+
type: invoker.type,
|
|
82
|
+
workspaceId: invoker.workspaceId,
|
|
83
|
+
attributes: invoker.attributeList,
|
|
84
|
+
attributeMap: invoker.attributes
|
|
85
|
+
} : null;
|
|
86
|
+
GlobalThis.tailor = {
|
|
87
|
+
...GlobalThis.tailor,
|
|
88
|
+
context: { getInvoker: () => raw }
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
63
92
|
* Sets up a mock for `globalThis.TailorErrors` used in bundled resolver tests.
|
|
64
93
|
* Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.
|
|
65
94
|
*/
|
|
@@ -74,6 +103,46 @@ function setupTailorErrorsMock() {
|
|
|
74
103
|
};
|
|
75
104
|
}
|
|
76
105
|
/**
|
|
106
|
+
* Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.
|
|
107
|
+
* `triggerJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,
|
|
108
|
+
* so mistakenly triggering a job without job mocks produces a clear message instead of silently returning undefined.
|
|
109
|
+
* @param config - Optional handlers for wait and resolve calls.
|
|
110
|
+
* @param config.onWait - Handler called when wait is invoked.
|
|
111
|
+
* @param config.onResolve - Handler called when resolve is invoked.
|
|
112
|
+
* @returns Object containing arrays of wait and resolve calls for assertions.
|
|
113
|
+
*/
|
|
114
|
+
function setupWaitPointMock(config) {
|
|
115
|
+
const waitCalls = [];
|
|
116
|
+
const resolveCalls = [];
|
|
117
|
+
GlobalThis.tailor = {
|
|
118
|
+
...GlobalThis.tailor,
|
|
119
|
+
workflow: {
|
|
120
|
+
triggerJobFunction: () => {
|
|
121
|
+
throw new Error("tailor.workflow.triggerJobFunction is not mocked. Use setupWorkflowMock() in tests.");
|
|
122
|
+
},
|
|
123
|
+
...GlobalThis.tailor?.workflow,
|
|
124
|
+
wait: (key, payload) => {
|
|
125
|
+
waitCalls.push({
|
|
126
|
+
key,
|
|
127
|
+
payload
|
|
128
|
+
});
|
|
129
|
+
return config?.onWait?.(key, payload);
|
|
130
|
+
},
|
|
131
|
+
resolve: async (executionId, key, callback) => {
|
|
132
|
+
resolveCalls.push({
|
|
133
|
+
executionId,
|
|
134
|
+
key
|
|
135
|
+
});
|
|
136
|
+
await config?.onResolve?.(executionId, key, callback);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
waitCalls,
|
|
142
|
+
resolveCalls
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
77
146
|
* Creates a function that imports a bundled JS file and returns its `main` export.
|
|
78
147
|
* Used to test bundled output from `apply --buildOnly`.
|
|
79
148
|
* @param baseDir - Base directory where bundled files are located.
|
|
@@ -156,5 +225,5 @@ function createStandardSchema(schemaType, hook) {
|
|
|
156
225
|
}
|
|
157
226
|
|
|
158
227
|
//#endregion
|
|
159
|
-
export { WORKFLOW_TEST_ENV_KEY, createImportMain, createStandardSchema, createTailorDBHook, setupTailorErrorsMock, setupTailordbMock, setupWorkflowMock, unauthenticatedTailorUser };
|
|
228
|
+
export { WORKFLOW_TEST_ENV_KEY, createImportMain, createStandardSchema, createTailorDBHook, setupInvokerMock, setupTailorErrorsMock, setupTailordbMock, setupWaitPointMock, setupWorkflowMock, unauthenticatedTailorUser };
|
|
160
229
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/mock.ts","../../../src/utils/test/index.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\ntype MainFunction = (args: Record<string, unknown>) => unknown | Promise<unknown>;\ntype QueryResolver = (query: string, params: unknown[]) => unknown[];\ntype JobHandler = (jobName: string, args: unknown) => unknown;\n\ninterface TailordbGlobal {\n tailordb?: {\n Client: new (config: { namespace?: string }) => {\n connect(): Promise<void> | void;\n end(): Promise<void> | void;\n queryObject(\n query: string,\n params?: unknown[],\n ): Promise<{ rows: unknown[] }> | { rows: unknown[] };\n };\n };\n tailor?: {\n workflow: {\n triggerJobFunction: (jobName: string, args: unknown) => unknown;\n };\n };\n}\n\ninterface TailorErrorItem {\n message: string;\n path: (string | number)[];\n}\n\ninterface TailorErrorsGlobal {\n TailorErrors?: new (errors: TailorErrorItem[]) => Error;\n}\n\nconst GlobalThis = globalThis as TailordbGlobal & TailorErrorsGlobal;\n\n/**\n * Sets up a mock for `globalThis.tailordb.Client` used in bundled resolver/executor tests.\n * @param resolver - Optional function to resolve query results. Defaults to returning empty arrays.\n * @returns Object containing arrays of executed queries and created clients for assertions.\n */\nexport function setupTailordbMock(resolver: QueryResolver = () => []): {\n executedQueries: { query: string; params: unknown[] }[];\n createdClients: { namespace?: string; ended: boolean }[];\n} {\n const executedQueries: { query: string; params: unknown[] }[] = [];\n const createdClients: { namespace?: string; ended: boolean }[] = [];\n\n class MockTailordbClient {\n private record: { namespace?: string; ended: boolean };\n\n constructor({ namespace }: { namespace?: string }) {\n this.record = { namespace, ended: false };\n createdClients.push(this.record);\n }\n\n async connect(): Promise<void> {\n /* noop */\n }\n\n async end(): Promise<void> {\n this.record.ended = true;\n }\n\n async queryObject(query: string, params: unknown[] = []): Promise<{ rows: unknown[] }> {\n executedQueries.push({ query, params });\n return { rows: resolver(query, params) ?? [] };\n }\n }\n\n GlobalThis.tailordb = {\n Client: MockTailordbClient,\n } as typeof GlobalThis.tailordb;\n\n return { executedQueries, createdClients };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.workflow.triggerJobFunction` used in bundled workflow tests.\n * @param handler - Function that handles triggered job calls and returns results.\n * @returns Object containing an array of triggered jobs for assertions.\n */\nexport function setupWorkflowMock(handler: JobHandler): {\n triggeredJobs: { jobName: string; args: unknown }[];\n} {\n const triggeredJobs: { jobName: string; args: unknown }[] = [];\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n triggerJobFunction: (jobName: string, args: unknown) => {\n triggeredJobs.push({ jobName, args });\n return handler(jobName, args);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { triggeredJobs };\n}\n\n/**\n * Sets up a mock for `globalThis.TailorErrors` used in bundled resolver tests.\n * Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.\n */\nexport function setupTailorErrorsMock(): void {\n GlobalThis.TailorErrors = class TailorErrors extends Error {\n errors: TailorErrorItem[];\n\n constructor(errors: TailorErrorItem[]) {\n super(`TailorErrors: ${JSON.stringify({ errors })}`);\n this.name = \"TailorErrors\";\n this.errors = errors;\n }\n };\n}\n\n/**\n * Creates a function that imports a bundled JS file and returns its `main` export.\n * Used to test bundled output from `apply --buildOnly`.\n * @param baseDir - Base directory where bundled files are located.\n * @returns An async function that takes a relative path and returns the `main` function.\n */\nexport function createImportMain(baseDir: string): (relativePath: string) => Promise<MainFunction> {\n return async (relativePath: string): Promise<MainFunction> => {\n const fileUrl = pathToFileURL(path.join(baseDir, relativePath));\n fileUrl.searchParams.set(\"v\", `${Date.now()}-${Math.random()}`);\n const module = await import(fileUrl.href);\n const main = module.main;\n if (typeof main !== \"function\") {\n throw new Error(`Expected \"main\" to be a function in ${relativePath}, got ${typeof main}`);\n }\n return main;\n };\n}\n","import type { output, TailorUser } from \"@/configure\";\nimport type { TailorDBType } from \"@/configure/services/tailordb/schema\";\nimport type { TailorField } from \"@/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nexport { WORKFLOW_TEST_ENV_KEY } from \"@/configure/services/workflow/job\";\nexport {\n setupTailordbMock,\n setupTailorErrorsMock,\n setupWorkflowMock,\n createImportMain,\n} from \"./mock\";\n\n/** Represents an unauthenticated user in the Tailor platform. */\nexport const unauthenticatedTailorUser = {\n id: \"00000000-0000-0000-0000-000000000000\",\n type: \"\",\n workspaceId: \"00000000-0000-0000-0000-000000000000\",\n attributes: null,\n attributeList: [],\n} as const satisfies TailorUser;\n\n/**\n * Creates a hook function that processes TailorDB type fields\n * - Uses existing id from data if provided, otherwise generates UUID for id fields\n * - Recursively processes nested types\n * - Executes hooks.create for fields with create hooks\n * @template T - The output type of the hook function\n * @param type - TailorDB type definition\n * @returns A function that transforms input data according to field hooks\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTailorDBHook<T extends TailorDBType<any, any>>(type: T) {\n return (data: unknown) => {\n return Object.entries(type.fields).reduce(\n (hooked, [key, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const field = value as TailorField<any, any, any>;\n if (key === \"id\") {\n // Use existing id from data if provided, otherwise generate new UUID\n const existingId =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\n hooked[key] = existingId ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n const nestedValue =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nestedHook = createTailorDBHook({ fields: field.fields } as any);\n if (field.metadata.array) {\n // For nested array fields, recurse per element and pass through non-array values\n // (e.g. null/undefined for optional fields) so validation sees the original value.\n hooked[key] = Array.isArray(nestedValue)\n ? nestedValue.map((item) => nestedHook(item))\n : nestedValue;\n } else {\n hooked[key] = nestedHook(nestedValue);\n }\n } else if (field.metadata.hooks?.create) {\n hooked[key] = field.metadata.hooks.create({\n value: (data as Record<string, unknown>)[key],\n data: data,\n user: unauthenticatedTailorUser,\n });\n if (hooked[key] instanceof Date) {\n hooked[key] = hooked[key].toISOString();\n }\n } else if (data && typeof data === \"object\") {\n hooked[key] = (data as Record<string, unknown>)[key];\n }\n return hooked;\n },\n {} as Record<string, unknown>,\n ) as Partial<output<T>>;\n };\n}\n\n/**\n * Creates the standard schema definition for lines-db\n * This returns the first argument for defineSchema with the ~standard section\n * @template T - The output type after validation\n * @param schemaType - TailorDB field schema for validation\n * @param hook - Hook function to transform data before validation\n * @returns Schema object with ~standard section for defineSchema\n */\nexport function createStandardSchema<T = Record<string, unknown>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schemaType: TailorField<any, T>,\n hook: (data: unknown) => Partial<T>,\n) {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"@tailor-platform/sdk\",\n validate: (value: unknown) => {\n const hooked = hook(value);\n const result = schemaType.parse({\n value: hooked,\n data: hooked,\n user: unauthenticatedTailorUser,\n });\n if (result.issues) {\n return result;\n }\n return { value: hooked as T };\n },\n },\n } as const satisfies StandardSchemaV1<T>;\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/mock.ts","../../../src/utils/test/index.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { TailorInvoker } from \"@/types/user\";\n\ntype MainFunction = (args: Record<string, unknown>) => unknown | Promise<unknown>;\ntype QueryResolver = (query: string, params: unknown[]) => unknown[];\ntype JobHandler = (jobName: string, args: unknown) => unknown;\ntype WaitHandler = (key: string, payload: unknown) => unknown;\ntype ResolveHandler = (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n) => Promise<void> | void;\n\ninterface TailordbGlobal {\n tailordb?: {\n Client: new (config: { namespace?: string }) => {\n connect(): Promise<void> | void;\n end(): Promise<void> | void;\n queryObject(\n query: string,\n params?: unknown[],\n ): Promise<{ rows: unknown[] }> | { rows: unknown[] };\n };\n };\n tailor?: {\n workflow: {\n triggerJobFunction: (jobName: string, args: unknown) => unknown;\n wait?: (key: string, payload?: unknown) => unknown;\n resolve?: (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => Promise<void>;\n };\n context: {\n getInvoker: () => tailor.context.Invoker | null;\n };\n };\n}\n\ninterface TailorErrorItem {\n message: string;\n path: (string | number)[];\n}\n\ninterface TailorErrorsGlobal {\n TailorErrors?: new (errors: TailorErrorItem[]) => Error;\n}\n\nconst GlobalThis = globalThis as TailordbGlobal & TailorErrorsGlobal;\n\n/**\n * Sets up a mock for `globalThis.tailordb.Client` used in bundled resolver/executor tests.\n * @param resolver - Optional function to resolve query results. Defaults to returning empty arrays.\n * @returns Object containing arrays of executed queries and created clients for assertions.\n */\nexport function setupTailordbMock(resolver: QueryResolver = () => []): {\n executedQueries: { query: string; params: unknown[] }[];\n createdClients: { namespace?: string; ended: boolean }[];\n} {\n const executedQueries: { query: string; params: unknown[] }[] = [];\n const createdClients: { namespace?: string; ended: boolean }[] = [];\n\n class MockTailordbClient {\n private record: { namespace?: string; ended: boolean };\n\n constructor({ namespace }: { namespace?: string }) {\n this.record = { namespace, ended: false };\n createdClients.push(this.record);\n }\n\n async connect(): Promise<void> {\n /* noop */\n }\n\n async end(): Promise<void> {\n this.record.ended = true;\n }\n\n async queryObject(query: string, params: unknown[] = []): Promise<{ rows: unknown[] }> {\n executedQueries.push({ query, params });\n return { rows: resolver(query, params) ?? [] };\n }\n }\n\n GlobalThis.tailordb = {\n Client: MockTailordbClient,\n } as typeof GlobalThis.tailordb;\n\n return { executedQueries, createdClients };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.workflow.triggerJobFunction` used in bundled workflow tests.\n * `wait`/`resolve` are stubbed to throw a helpful error directing to `setupWaitPointMock()`,\n * so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.\n * @param handler - Function that handles triggered job calls and returns results.\n * @returns Object containing an array of triggered jobs for assertions.\n */\nexport function setupWorkflowMock(handler: JobHandler): {\n triggeredJobs: { jobName: string; args: unknown }[];\n} {\n const triggeredJobs: { jobName: string; args: unknown }[] = [];\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n wait: () => {\n throw new Error(\"tailor.workflow.wait is not mocked. Use setupWaitPointMock() in tests.\");\n },\n resolve: async () => {\n throw new Error(\n \"tailor.workflow.resolve is not mocked. Use setupWaitPointMock() in tests.\",\n );\n },\n ...GlobalThis.tailor?.workflow,\n triggerJobFunction: (jobName: string, args: unknown) => {\n triggeredJobs.push({ jobName, args });\n return handler(jobName, args);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { triggeredJobs };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.context.getInvoker` used in bundled\n * resolver/executor/workflow tests.\n * @param invoker - The `TailorInvoker` value to return, or `null` for anonymous.\n */\nexport function setupInvokerMock(invoker: TailorInvoker): void {\n const raw: tailor.context.Invoker | null = invoker\n ? {\n id: invoker.id,\n type: invoker.type,\n workspaceId: invoker.workspaceId,\n attributes: invoker.attributeList as string[],\n attributeMap: invoker.attributes as Record<string, unknown>,\n }\n : null;\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n context: {\n getInvoker: () => raw,\n },\n } as typeof GlobalThis.tailor;\n}\n\n/**\n * Sets up a mock for `globalThis.TailorErrors` used in bundled resolver tests.\n * Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.\n */\nexport function setupTailorErrorsMock(): void {\n GlobalThis.TailorErrors = class TailorErrors extends Error {\n errors: TailorErrorItem[];\n\n constructor(errors: TailorErrorItem[]) {\n super(`TailorErrors: ${JSON.stringify({ errors })}`);\n this.name = \"TailorErrors\";\n this.errors = errors;\n }\n };\n}\n\n/**\n * Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.\n * `triggerJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,\n * so mistakenly triggering a job without job mocks produces a clear message instead of silently returning undefined.\n * @param config - Optional handlers for wait and resolve calls.\n * @param config.onWait - Handler called when wait is invoked.\n * @param config.onResolve - Handler called when resolve is invoked.\n * @returns Object containing arrays of wait and resolve calls for assertions.\n */\nexport function setupWaitPointMock(config?: { onWait?: WaitHandler; onResolve?: ResolveHandler }): {\n waitCalls: { key: string; payload: unknown }[];\n resolveCalls: { executionId: string; key: string }[];\n} {\n const waitCalls: { key: string; payload: unknown }[] = [];\n const resolveCalls: { executionId: string; key: string }[] = [];\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n triggerJobFunction: () => {\n throw new Error(\n \"tailor.workflow.triggerJobFunction is not mocked. Use setupWorkflowMock() in tests.\",\n );\n },\n ...GlobalThis.tailor?.workflow,\n wait: (key: string, payload?: unknown) => {\n waitCalls.push({ key, payload });\n return config?.onWait?.(key, payload);\n },\n resolve: async (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => {\n resolveCalls.push({ executionId, key });\n await config?.onResolve?.(executionId, key, callback);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { waitCalls, resolveCalls };\n}\n\n/**\n * Creates a function that imports a bundled JS file and returns its `main` export.\n * Used to test bundled output from `apply --buildOnly`.\n * @param baseDir - Base directory where bundled files are located.\n * @returns An async function that takes a relative path and returns the `main` function.\n */\nexport function createImportMain(baseDir: string): (relativePath: string) => Promise<MainFunction> {\n return async (relativePath: string): Promise<MainFunction> => {\n const fileUrl = pathToFileURL(path.join(baseDir, relativePath));\n fileUrl.searchParams.set(\"v\", `${Date.now()}-${Math.random()}`);\n const module = await import(fileUrl.href);\n const main = module.main;\n if (typeof main !== \"function\") {\n throw new Error(`Expected \"main\" to be a function in ${relativePath}, got ${typeof main}`);\n }\n return main;\n };\n}\n","import type { output, TailorUser } from \"@/configure\";\nimport type { TailorDBType } from \"@/configure/services/tailordb/schema\";\nimport type { TailorField } from \"@/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nexport { WORKFLOW_TEST_ENV_KEY } from \"@/configure/services/workflow/job\";\nexport {\n setupTailordbMock,\n setupTailorErrorsMock,\n setupWorkflowMock,\n setupInvokerMock,\n setupWaitPointMock,\n createImportMain,\n} from \"./mock\";\n\n/** Represents an unauthenticated user in the Tailor platform. */\nexport const unauthenticatedTailorUser = {\n id: \"00000000-0000-0000-0000-000000000000\",\n type: \"\",\n workspaceId: \"00000000-0000-0000-0000-000000000000\",\n attributes: null,\n attributeList: [],\n} as const satisfies TailorUser;\n\n/**\n * Creates a hook function that processes TailorDB type fields\n * - Uses existing id from data if provided, otherwise generates UUID for id fields\n * - Recursively processes nested types\n * - Executes hooks.create for fields with create hooks\n * @template T - The output type of the hook function\n * @param type - TailorDB type definition\n * @returns A function that transforms input data according to field hooks\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTailorDBHook<T extends TailorDBType<any, any>>(type: T) {\n return (data: unknown) => {\n return Object.entries(type.fields).reduce(\n (hooked, [key, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const field = value as TailorField<any, any, any>;\n if (key === \"id\") {\n // Use existing id from data if provided, otherwise generate new UUID\n const existingId =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\n hooked[key] = existingId ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n const nestedValue =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nestedHook = createTailorDBHook({ fields: field.fields } as any);\n if (field.metadata.array) {\n // For nested array fields, recurse per element and pass through non-array values\n // (e.g. null/undefined for optional fields) so validation sees the original value.\n hooked[key] = Array.isArray(nestedValue)\n ? nestedValue.map((item) => nestedHook(item))\n : nestedValue;\n } else {\n hooked[key] = nestedHook(nestedValue);\n }\n } else if (field.metadata.hooks?.create) {\n hooked[key] = field.metadata.hooks.create({\n value: (data as Record<string, unknown>)[key],\n data: data,\n user: unauthenticatedTailorUser,\n });\n if (hooked[key] instanceof Date) {\n hooked[key] = hooked[key].toISOString();\n }\n } else if (data && typeof data === \"object\") {\n hooked[key] = (data as Record<string, unknown>)[key];\n }\n return hooked;\n },\n {} as Record<string, unknown>,\n ) as Partial<output<T>>;\n };\n}\n\n/**\n * Creates the standard schema definition for lines-db\n * This returns the first argument for defineSchema with the ~standard section\n * @template T - The output type after validation\n * @param schemaType - TailorDB field schema for validation\n * @param hook - Hook function to transform data before validation\n * @returns Schema object with ~standard section for defineSchema\n */\nexport function createStandardSchema<T = Record<string, unknown>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schemaType: TailorField<any, T>,\n hook: (data: unknown) => Partial<T>,\n) {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"@tailor-platform/sdk\",\n validate: (value: unknown) => {\n const hooked = hook(value);\n const result = schemaType.parse({\n value: hooked,\n data: hooked,\n user: unauthenticatedTailorUser,\n });\n if (result.issues) {\n return result;\n }\n return { value: hooked as T };\n },\n },\n } as const satisfies StandardSchemaV1<T>;\n}\n"],"mappings":";;;;;;AAkDA,MAAM,aAAa;;;;;;AAOnB,SAAgB,kBAAkB,iBAAgC,EAAE,EAGlE;CACA,MAAM,kBAA0D,EAAE;CAClE,MAAM,iBAA2D,EAAE;CAEnE,MAAM,mBAAmB;EACvB,AAAQ;EAER,YAAY,EAAE,aAAqC;AACjD,QAAK,SAAS;IAAE;IAAW,OAAO;IAAO;AACzC,kBAAe,KAAK,KAAK,OAAO;;EAGlC,MAAM,UAAyB;EAI/B,MAAM,MAAqB;AACzB,QAAK,OAAO,QAAQ;;EAGtB,MAAM,YAAY,OAAe,SAAoB,EAAE,EAAgC;AACrF,mBAAgB,KAAK;IAAE;IAAO;IAAQ,CAAC;AACvC,UAAO,EAAE,MAAM,SAAS,OAAO,OAAO,IAAI,EAAE,EAAE;;;AAIlD,YAAW,WAAW,EACpB,QAAQ,oBACT;AAED,QAAO;EAAE;EAAiB;EAAgB;;;;;;;;;AAU5C,SAAgB,kBAAkB,SAEhC;CACA,MAAM,gBAAsD,EAAE;AAE9D,YAAW,SAAS;EAClB,GAAG,WAAW;EACd,UAAU;GACR,YAAY;AACV,UAAM,IAAI,MAAM,yEAAyE;;GAE3F,SAAS,YAAY;AACnB,UAAM,IAAI,MACR,4EACD;;GAEH,GAAG,WAAW,QAAQ;GACtB,qBAAqB,SAAiB,SAAkB;AACtD,kBAAc,KAAK;KAAE;KAAS;KAAM,CAAC;AACrC,WAAO,QAAQ,SAAS,KAAK;;GAEhC;EACF;AAED,QAAO,EAAE,eAAe;;;;;;;AAQ1B,SAAgB,iBAAiB,SAA8B;CAC7D,MAAM,MAAqC,UACvC;EACE,IAAI,QAAQ;EACZ,MAAM,QAAQ;EACd,aAAa,QAAQ;EACrB,YAAY,QAAQ;EACpB,cAAc,QAAQ;EACvB,GACD;AAEJ,YAAW,SAAS;EAClB,GAAG,WAAW;EACd,SAAS,EACP,kBAAkB,KACnB;EACF;;;;;;AAOH,SAAgB,wBAA8B;AAC5C,YAAW,eAAe,MAAM,qBAAqB,MAAM;EACzD;EAEA,YAAY,QAA2B;AACrC,SAAM,iBAAiB,KAAK,UAAU,EAAE,QAAQ,CAAC,GAAG;AACpD,QAAK,OAAO;AACZ,QAAK,SAAS;;;;;;;;;;;;;AAcpB,SAAgB,mBAAmB,QAGjC;CACA,MAAM,YAAiD,EAAE;CACzD,MAAM,eAAuD,EAAE;AAE/D,YAAW,SAAS;EAClB,GAAG,WAAW;EACd,UAAU;GACR,0BAA0B;AACxB,UAAM,IAAI,MACR,sFACD;;GAEH,GAAG,WAAW,QAAQ;GACtB,OAAO,KAAa,YAAsB;AACxC,cAAU,KAAK;KAAE;KAAK;KAAS,CAAC;AAChC,WAAO,QAAQ,SAAS,KAAK,QAAQ;;GAEvC,SAAS,OACP,aACA,KACA,aACG;AACH,iBAAa,KAAK;KAAE;KAAa;KAAK,CAAC;AACvC,UAAM,QAAQ,YAAY,aAAa,KAAK,SAAS;;GAExD;EACF;AAED,QAAO;EAAE;EAAW;EAAc;;;;;;;;AASpC,SAAgB,iBAAiB,SAAkE;AACjG,QAAO,OAAO,iBAAgD;EAC5D,MAAM,UAAU,cAAc,KAAK,KAAK,SAAS,aAAa,CAAC;AAC/D,UAAQ,aAAa,IAAI,KAAK,GAAG,KAAK,KAAK,CAAC,GAAG,KAAK,QAAQ,GAAG;EAE/D,MAAM,QADS,MAAM,OAAO,QAAQ,OAChB;AACpB,MAAI,OAAO,SAAS,WAClB,OAAM,IAAI,MAAM,uCAAuC,aAAa,QAAQ,OAAO,OAAO;AAE5F,SAAO;;;;;;;ACjNX,MAAa,4BAA4B;CACvC,IAAI;CACJ,MAAM;CACN,aAAa;CACb,YAAY;CACZ,eAAe,EAAE;CAClB;;;;;;;;;;AAYD,SAAgB,mBAAqD,MAAS;AAC5E,SAAQ,SAAkB;AACxB,SAAO,OAAO,QAAQ,KAAK,OAAO,CAAC,QAChC,QAAQ,CAAC,KAAK,WAAW;GAExB,MAAM,QAAQ;AACd,OAAI,QAAQ,KAIV,QAAO,QADL,QAAQ,OAAO,SAAS,WAAY,KAAiC,OAAO,WAClD,OAAO,YAAY;YACtC,MAAM,SAAS,UAAU;IAClC,MAAM,cACJ,QAAQ,OAAO,SAAS,WAAY,KAAiC,OAAO;IAE9E,MAAM,aAAa,mBAAmB,EAAE,QAAQ,MAAM,QAAQ,CAAQ;AACtE,QAAI,MAAM,SAAS,MAGjB,QAAO,OAAO,MAAM,QAAQ,YAAY,GACpC,YAAY,KAAK,SAAS,WAAW,KAAK,CAAC,GAC3C;QAEJ,QAAO,OAAO,WAAW,YAAY;cAE9B,MAAM,SAAS,OAAO,QAAQ;AACvC,WAAO,OAAO,MAAM,SAAS,MAAM,OAAO;KACxC,OAAQ,KAAiC;KACnC;KACN,MAAM;KACP,CAAC;AACF,QAAI,OAAO,gBAAgB,KACzB,QAAO,OAAO,OAAO,KAAK,aAAa;cAEhC,QAAQ,OAAO,SAAS,SACjC,QAAO,OAAQ,KAAiC;AAElD,UAAO;KAET,EAAE,CACH;;;;;;;;;;;AAYL,SAAgB,qBAEd,YACA,MACA;AACA,QAAO,EACL,aAAa;EACX,SAAS;EACT,QAAQ;EACR,WAAW,UAAmB;GAC5B,MAAM,SAAS,KAAK,MAAM;GAC1B,MAAM,SAAS,WAAW,MAAM;IAC9B,OAAO;IACP,MAAM;IACN,MAAM;IACP,CAAC;AACF,OAAI,OAAO,OACT,QAAO;AAET,UAAO,EAAE,OAAO,QAAa;;EAEhC,EACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="@tailor-platform/function-types" />
|
|
2
|
-
import { A as RelationType, Bt as InferredAttributeMap, D as DefinedDBFieldMetadata, Dt as ArrayFieldOutput, E as DBFieldMetadata, F as AuthConfig, Ft as FieldValidateInput, It as Validators,
|
|
2
|
+
import { A as RelationType, Bt as InferredAttributeMap, D as DefinedDBFieldMetadata, Dt as ArrayFieldOutput, E as DBFieldMetadata, F as AuthConfig, Ft as FieldValidateInput, Ht as TailorUser, It as Validators, Jt as output, M as TailorDBServiceInput, Mt as FieldOutput, O as GqlOperationsConfig, Pt as TailorToTs, Wt as InferFieldsOutput, Y as TailorField, c as PluginConfigs, ht as BuiltinIdP, i as TailorDBType$1, j as SerialConfig, jt as FieldOptions, k as IndexDef, kt as EnumValue, qt as Prettify, r as TailorDBField$1, t as TailorAnyDBField$1 } from "./tailor-db-field-D_z185oq.mjs";
|
|
3
3
|
import { NonEmptyObject } from "type-fest";
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
5
|
|
|
@@ -1204,4 +1204,4 @@ type RetryPolicy = {
|
|
|
1204
1204
|
};
|
|
1205
1205
|
//#endregion
|
|
1206
1206
|
export { TailorTypeGqlPermission as A, TailorAnyDBField as C, TailorDBType as D, TailorDBInstance as E, AllowedValuesOutput as F, unsafeAllowAllGqlPermission as M, unsafeAllowAllTypePermission as N, db as O, AllowedValues as P, IdPInput as S, TailorDBField as T, IdPUserField as _, ResolverExternalConfig as a, IdPGqlOperations as b, WorkflowServiceConfig as c, StaticWebsiteDefinitionBrand as d, StaticWebsiteInput as f, IdPExternalConfig as g, IdPConfig as h, ExecutorServiceInput as i, TailorTypePermission as j, PermissionCondition as k, WorkflowServiceInput as l, SecretsDefinitionBrand as m, AppConfig as n, ResolverServiceConfig as o, SecretsConfig as p, ExecutorServiceConfig as r, ResolverServiceInput as s, RetryPolicy as t, StaticWebsiteConfig as u, IdpDefinitionBrand as v, TailorAnyDBType as w, IdPGqlOperationsInput as x, IdPEmailConfig as y };
|
|
1207
|
-
//# sourceMappingURL=workflow.generated-
|
|
1207
|
+
//# sourceMappingURL=workflow.generated-CDCnZNkH.d.mts.map
|
package/docs/cli/function.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Function Commands
|
|
2
2
|
|
|
3
|
-
Commands for viewing function execution logs.
|
|
3
|
+
Commands for managing function registries and viewing function execution logs.
|
|
4
4
|
|
|
5
5
|
<!-- politty:command:function:heading:start -->
|
|
6
6
|
|
|
@@ -30,6 +30,8 @@ tailor-sdk function [command]
|
|
|
30
30
|
|
|
31
31
|
| Command | Description |
|
|
32
32
|
| ----------------------------------------- | --------------------------------------------------------------- |
|
|
33
|
+
| [`function get`](#function-get) | Get a function registry by name |
|
|
34
|
+
| [`function list`](#function-list) | List function registries in a workspace |
|
|
33
35
|
| [`function logs`](#function-logs) | List or get function execution logs. |
|
|
34
36
|
| [`function test-run`](#function-test-run) | Run a function on the Tailor Platform server without deploying. |
|
|
35
37
|
|
|
@@ -40,6 +42,86 @@ tailor-sdk function [command]
|
|
|
40
42
|
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
41
43
|
|
|
42
44
|
<!-- politty:command:function:global-options-link:end -->
|
|
45
|
+
<!-- politty:command:function get:heading:start -->
|
|
46
|
+
|
|
47
|
+
### function get
|
|
48
|
+
|
|
49
|
+
<!-- politty:command:function get:heading:end -->
|
|
50
|
+
|
|
51
|
+
<!-- politty:command:function get:description:start -->
|
|
52
|
+
|
|
53
|
+
Get a function registry by name
|
|
54
|
+
|
|
55
|
+
<!-- politty:command:function get:description:end -->
|
|
56
|
+
|
|
57
|
+
<!-- politty:command:function get:usage:start -->
|
|
58
|
+
|
|
59
|
+
**Usage**
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
tailor-sdk function get [options]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
<!-- politty:command:function get:usage:end -->
|
|
66
|
+
|
|
67
|
+
<!-- politty:command:function get:options:start -->
|
|
68
|
+
|
|
69
|
+
**Options**
|
|
70
|
+
|
|
71
|
+
| Option | Alias | Description | Required | Default | Env |
|
|
72
|
+
| ------------------------------- | ----- | ----------------- | -------- | ------- | ------------------------------ |
|
|
73
|
+
| `--workspace-id <WORKSPACE_ID>` | `-w` | Workspace ID | No | - | `TAILOR_PLATFORM_WORKSPACE_ID` |
|
|
74
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
|
|
75
|
+
| `--name <NAME>` | `-n` | Function name | Yes | - | - |
|
|
76
|
+
|
|
77
|
+
<!-- politty:command:function get:options:end -->
|
|
78
|
+
|
|
79
|
+
<!-- politty:command:function get:global-options-link:start -->
|
|
80
|
+
|
|
81
|
+
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
82
|
+
|
|
83
|
+
<!-- politty:command:function get:global-options-link:end -->
|
|
84
|
+
<!-- politty:command:function list:heading:start -->
|
|
85
|
+
|
|
86
|
+
### function list
|
|
87
|
+
|
|
88
|
+
<!-- politty:command:function list:heading:end -->
|
|
89
|
+
|
|
90
|
+
<!-- politty:command:function list:description:start -->
|
|
91
|
+
|
|
92
|
+
List function registries in a workspace
|
|
93
|
+
|
|
94
|
+
<!-- politty:command:function list:description:end -->
|
|
95
|
+
|
|
96
|
+
<!-- politty:command:function list:usage:start -->
|
|
97
|
+
|
|
98
|
+
**Usage**
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
tailor-sdk function list [options]
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
<!-- politty:command:function list:usage:end -->
|
|
105
|
+
|
|
106
|
+
<!-- politty:command:function list:options:start -->
|
|
107
|
+
|
|
108
|
+
**Options**
|
|
109
|
+
|
|
110
|
+
| Option | Alias | Description | Required | Default | Env |
|
|
111
|
+
| ------------------------------- | ----- | -------------------------------------------------------- | -------- | -------- | ------------------------------ |
|
|
112
|
+
| `--workspace-id <WORKSPACE_ID>` | `-w` | Workspace ID | No | - | `TAILOR_PLATFORM_WORKSPACE_ID` |
|
|
113
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
|
|
114
|
+
| `--order <ORDER>` | - | Sort order (asc or desc) | No | `"desc"` | - |
|
|
115
|
+
| `--limit <LIMIT>` | `-l` | Maximum number of items to return (0 or omit: unlimited) | No | - | - |
|
|
116
|
+
|
|
117
|
+
<!-- politty:command:function list:options:end -->
|
|
118
|
+
|
|
119
|
+
<!-- politty:command:function list:global-options-link:start -->
|
|
120
|
+
|
|
121
|
+
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
122
|
+
|
|
123
|
+
<!-- politty:command:function list:global-options-link:end -->
|
|
124
|
+
|
|
43
125
|
<!-- politty:command:function logs:heading:start -->
|
|
44
126
|
|
|
45
127
|
### function logs
|
package/docs/cli-reference.md
CHANGED
|
@@ -209,10 +209,12 @@ Commands for managing workflows and executions.
|
|
|
209
209
|
|
|
210
210
|
### [Function Commands](./cli/function.md)
|
|
211
211
|
|
|
212
|
-
Commands for viewing function execution logs.
|
|
212
|
+
Commands for managing function registries and viewing function execution logs.
|
|
213
213
|
|
|
214
214
|
| Command | Description |
|
|
215
215
|
| -------------------------------------------------------- | --------------------------------------------------------------- |
|
|
216
|
+
| [function get](./cli/function.md#function-get) | Get a function registry by name |
|
|
217
|
+
| [function list](./cli/function.md#function-list) | List function registries in a workspace |
|
|
216
218
|
| [function logs](./cli/function.md#function-logs) | List or get function execution logs. |
|
|
217
219
|
| [function test-run](./cli/function.md#function-test-run) | Run a function on the Tailor Platform server without deploying. |
|
|
218
220
|
|
|
@@ -130,6 +130,8 @@ Fire when IdP users are created, updated, or deleted:
|
|
|
130
130
|
idpUserCreatedTrigger();
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
These triggers require the IdP to publish user lifecycle events. The SDK enables `publishUserEvents` on the IdP automatically during `apply` when any executor uses an `idpUser` trigger; set the value explicitly on `defineIdp()` to override. See [IdP service - publishUserEvents](./idp.md#publishuserevents).
|
|
134
|
+
|
|
133
135
|
### Auth Access Token Triggers
|
|
134
136
|
|
|
135
137
|
Fire on auth access token lifecycle events:
|
|
@@ -203,6 +205,8 @@ createExecutor({
|
|
|
203
205
|
});
|
|
204
206
|
```
|
|
205
207
|
|
|
208
|
+
`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 their callbacks.
|
|
209
|
+
|
|
206
210
|
### Job Function Operation
|
|
207
211
|
|
|
208
212
|
For long-running operations, use `jobFunction` which runs asynchronously and supports extended execution times. See [Job Function Operation](https://docs.tailor.tech/guides/executor/job-function-operation) for details.
|
package/docs/services/idp.md
CHANGED
|
@@ -164,6 +164,22 @@ defineIdp("my-idp", {
|
|
|
164
164
|
|
|
165
165
|
**Validation:** Each field must be 200 characters or less and must not contain newline characters.
|
|
166
166
|
|
|
167
|
+
### publishUserEvents
|
|
168
|
+
|
|
169
|
+
Publish IdP user lifecycle events (`idp.user.created`, `idp.user.updated`, `idp.user.deleted`). These events are consumed by executors that use `idpUserCreatedTrigger`, `idpUserUpdatedTrigger`, `idpUserDeletedTrigger`, or `idpUserTrigger`.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
defineIdp("my-idp", {
|
|
173
|
+
clients: ["my-client"],
|
|
174
|
+
publishUserEvents: true,
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Auto-configuration:** When `publishUserEvents` is omitted, the SDK enables it automatically during `apply` if the project defines any executor with an `idpUser` trigger. Set the value explicitly to override:
|
|
179
|
+
|
|
180
|
+
- `publishUserEvents: true`: always publish events.
|
|
181
|
+
- `publishUserEvents: false`: never publish events. The SDK warns when executors with `idpUser` triggers are present, since those executors will not fire for this IdP.
|
|
182
|
+
|
|
167
183
|
## Using idp.provider()
|
|
168
184
|
|
|
169
185
|
The `idp.provider()` method creates a type-safe reference to the IdP for use in Auth configuration. The client name is validated at compile time against the clients defined in the IdP.
|
|
@@ -234,7 +234,9 @@ Validation runs automatically before the `body` function executes. When validati
|
|
|
234
234
|
Define actual resolver logic in the `body` function. Function arguments include:
|
|
235
235
|
|
|
236
236
|
- `input` - Input data from GraphQL request
|
|
237
|
-
- `user` -
|
|
237
|
+
- `user` - The user who called this resolver; unaffected by `authInvoker`
|
|
238
|
+
- `invoker` - The principal running this function; equals `user` by default, or the machine user set by `authInvoker`. `null` for anonymous calls.
|
|
239
|
+
- `env` - Environment variables declared in `tailor.config.ts`
|
|
238
240
|
|
|
239
241
|
### Using Kysely for Database Access
|
|
240
242
|
|
|
@@ -371,4 +373,4 @@ The machine user name is looked up in the auth service configured on your app (`
|
|
|
371
373
|
|
|
372
374
|
> **Deprecated:** `auth.invoker("batch-processor")` still works, but is deprecated. Importing `auth` into runtime files pulls config-layer (Node-only) dependencies into the bundle.
|
|
373
375
|
|
|
374
|
-
**Note:** `authInvoker` controls the permissions for database operations and other platform actions
|
|
376
|
+
**Note:** `authInvoker` controls the permissions for database operations and other platform actions. The `user` object passed to `body` still reflects the original caller, while `invoker` reflects the principal actually running the body.
|