@tailor-platform/sdk 0.10.4 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1179,6 +1179,15 @@ declare function defineStaticWebSite(name: string, config: Omit<StaticWebsiteInp
1179
1179
  } & StaticWebsiteDefinitionBrand;
1180
1180
  type StaticWebsiteConfig = Omit<ReturnType<typeof defineStaticWebSite>, "url">;
1181
1181
  //#endregion
1182
+ //#region src/configure/services/workflow/types.d.ts
1183
+ type WorkflowServiceConfig = {
1184
+ files: string[];
1185
+ job_files?: string[];
1186
+ ignores?: string[];
1187
+ job_ignores?: string[];
1188
+ };
1189
+ type WorkflowServiceInput = WorkflowServiceConfig;
1190
+ //#endregion
1182
1191
  //#region src/parser/generator-config/index.d.ts
1183
1192
  declare const CodeGeneratorSchema: z.ZodObject<{
1184
1193
  id: z.ZodString;
@@ -1278,6 +1287,7 @@ interface AppConfig<Auth extends AuthConfig = AuthConfig, Idp extends IdPConfig[
1278
1287
  idp?: Idp;
1279
1288
  auth?: Auth;
1280
1289
  executor?: ExecutorServiceInput;
1290
+ workflow?: WorkflowServiceInput;
1281
1291
  staticWebsites?: StaticWebsites;
1282
1292
  }
1283
1293
  declare function defineConfig<const Config extends AppConfig & Record<Exclude<keyof Config, keyof AppConfig>, never>>(config: Config): Config;
@@ -1418,4 +1428,5 @@ type WebhookOperation = z.infer<typeof WebhookOperationSchema>;
1418
1428
  type Executor = z.infer<typeof ExecutorSchema>;
1419
1429
  type ExecutorInput = z.input<typeof ExecutorSchema>;
1420
1430
  //#endregion
1421
- export { AllowedValues, AllowedValuesOutput, AppConfig, ArrayFieldOutput, AuthConfig, AuthExternalConfig, AuthOwnConfig, type AuthServiceInput, type BuiltinIdP, CodeGeneratorBase, Executor, ExecutorInput, ExecutorServiceConfig, ExecutorServiceInput, FieldMetadata, FieldOptions, FieldOutput, FunctionOperation, Generator, GqlOperation, type IDToken, IdPConfig, IdPExternalConfig, type IdProviderConfig, IncomingWebhookTrigger, InferFieldsOutput, type OAuth2Client, type OAuth2ClientGrantType, type OIDC, PermissionCondition, QueryType, RecordTrigger, Resolver, ResolverExecutedTrigger, ResolverExternalConfig, ResolverInput, ResolverServiceConfig, ResolverServiceInput, type SAML, type SCIMAttribute, type SCIMAttributeMapping, type SCIMAttributeType, type SCIMAuthorization, type SCIMConfig, type SCIMResource, ScheduleTriggerInput, StaticWebsiteConfig, TailorDBField, TailorDBInstance, TailorDBType, TailorDBTypeConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, type TenantProviderConfig, type UserAttributeKey, type UserAttributeListKey, type UserAttributeMap, type UsernameFieldKey, type ValueOperand, WebhookOperation, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, output, unauthenticatedTailorUser };
1431
+ export { AllowedValues, AllowedValuesOutput, AppConfig, ArrayFieldOutput, AuthConfig, AuthExternalConfig, AuthOwnConfig, type AuthServiceInput, type BuiltinIdP, CodeGeneratorBase, Executor, ExecutorInput, ExecutorServiceConfig, ExecutorServiceInput, FieldMetadata, FieldOptions, FieldOutput, FunctionOperation, Generator, GqlOperation, type IDToken, IdPConfig, IdPExternalConfig, type IdProviderConfig, IncomingWebhookTrigger, InferFieldsOutput, type OAuth2Client, type OAuth2ClientGrantType, type OIDC, PermissionCondition, QueryType, RecordTrigger, Resolver, ResolverExecutedTrigger, ResolverExternalConfig, ResolverInput, ResolverServiceConfig, ResolverServiceInput, type SAML, type SCIMAttribute, type SCIMAttributeMapping, type SCIMAttributeType, type SCIMAuthorization, type SCIMConfig, type SCIMResource, ScheduleTriggerInput, StaticWebsiteConfig, TailorDBField, TailorDBInstance, TailorDBType, TailorDBTypeConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, type TenantProviderConfig, type UserAttributeKey, type UserAttributeListKey, type UserAttributeMap, type UsernameFieldKey, type ValueOperand, WebhookOperation, WorkflowServiceConfig, WorkflowServiceInput, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, output, unauthenticatedTailorUser };
1432
+ //# sourceMappingURL=types-C5oBGPO0.d.mts.map
@@ -1,7 +1,7 @@
1
1
  /// <reference path="./../../plugin-generated.d.ts" />
2
2
 
3
- import { TailorDBType, TailorField, TailorUser } from "../../types-CCSNkBzX.mjs";
4
- import { output } from "../../index-DENkoB_m.mjs";
3
+ import { TailorDBType, TailorField, TailorUser } from "../../types-C5oBGPO0.mjs";
4
+ import { output } from "../../index-DIPoP-nY.mjs";
5
5
  import { StandardSchemaV1 } from "@standard-schema/spec";
6
6
 
7
7
  //#region src/utils/test/index.d.ts
@@ -37,4 +37,5 @@ declare function createStandardSchema<T = Record<string, unknown>>(schemaType: T
37
37
  };
38
38
  };
39
39
  //#endregion
40
- export { createStandardSchema, createTailorDBHook, unauthenticatedTailorUser };
40
+ export { createStandardSchema, createTailorDBHook, unauthenticatedTailorUser };
41
+ //# sourceMappingURL=index.d.mts.map
@@ -60,4 +60,5 @@ function createStandardSchema(schemaType, hook) {
60
60
  }
61
61
 
62
62
  //#endregion
63
- export { createStandardSchema, createTailorDBHook, unauthenticatedTailorUser };
63
+ export { createStandardSchema, createTailorDBHook, unauthenticatedTailorUser };
64
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["unauthenticatedTailorUser: TailorUser"],"sources":["../../../src/utils/test/index.ts"],"sourcesContent":["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\n/** Represents an unauthenticated user in the Tailor platform. */\nexport const unauthenticatedTailorUser: TailorUser = {\n id: \"00000000-0000-0000-0000-000000000000\",\n type: \"\",\n workspaceId: \"00000000-0000-0000-0000-000000000000\",\n attributes: null,\n attributeList: [],\n} as const;\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 *\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\"\n ? (data as Record<string, unknown>)[key]\n : undefined;\n hooked[key] = existingId ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n hooked[key] = createTailorDBHook({ fields: field.fields } as any)(\n (data as Record<string, unknown>)[key],\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 } 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 *\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":";;AAMA,MAAaA,4BAAwC;CACnD,IAAI;CACJ,MAAM;CACN,aAAa;CACb,YAAY;CACZ,eAAe,EAAE;CAClB;;;;;;;;;;;AAaD,SAAgB,mBAAqD,MAAS;AAC5E,SAAQ,SAAkB;AACxB,SAAO,OAAO,QAAQ,KAAK,OAAO,CAAC,QAChC,QAAQ,CAAC,KAAK,WAAW;GAExB,MAAM,QAAQ;AACd,OAAI,QAAQ,KAMV,QAAO,QAHL,QAAQ,OAAO,SAAS,WACnB,KAAiC,OAClC,WACsB,OAAO,YAAY;YACtC,MAAM,SAAS,SAExB,QAAO,OAAO,mBAAmB,EAAE,QAAQ,MAAM,QAAQ,CAAQ,CAC9D,KAAiC,KACnC;YACQ,MAAM,SAAS,OAAO,OAC/B,QAAO,OAAO,MAAM,SAAS,MAAM,OAAO;IACxC,OAAQ,KAAiC;IACnC;IACN,MAAM;IACP,CAAC;YACO,QAAQ,OAAO,SAAS,SACjC,QAAO,OAAQ,KAAiC;AAElD,UAAO;KAET,EAAE,CACH;;;;;;;;;;;;AAaL,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"}
@@ -41,6 +41,9 @@ export default defineConfig({
41
41
  executor: {
42
42
  files: ["executors/**/*.ts"],
43
43
  },
44
+ workflow: {
45
+ files: ["workflows/**/*.ts"],
46
+ },
44
47
  });
45
48
  ```
46
49
 
@@ -161,3 +164,20 @@ body: ({ newRecord, env }) => {
161
164
  console.log(`Environment: ${env.bar}, User: ${newRecord.name}`);
162
165
  };
163
166
  ```
167
+
168
+ ### Workflow Service
169
+
170
+ Configure Workflow service by specifying glob patterns for workflow files:
171
+
172
+ ```typescript
173
+ export default defineConfig({
174
+ workflow: {
175
+ files: ["workflows/**/*.ts"],
176
+ ignores: ["workflows/**/*.draft.ts"],
177
+ },
178
+ });
179
+ ```
180
+
181
+ **files**: Glob patterns to match workflow files. Required.
182
+
183
+ **ignores**: Glob patterns to exclude files. Optional.
@@ -502,3 +502,117 @@ Context varies based on trigger type:
502
502
  - `resolverName`: Name of the resolver
503
503
  - `result`: Resolver's return value (when execution succeeds)
504
504
  - `error`: Error object (when execution fails)
505
+
506
+ ### Workflow Concepts
507
+
508
+ Define Workflows in files matching glob patterns specified in `tailor.config.ts`. Workflows orchestrate multiple jobs that can depend on each other.
509
+
510
+ #### Workflow Rules
511
+
512
+ **Important**: All workflow components must follow these rules:
513
+
514
+ | Rule | Required | Description |
515
+ | ---------------------------------------------- | -------- | --------------------------------------------------- |
516
+ | `createWorkflow` result must be default export | Yes | Workflow files must export the workflow as default |
517
+ | All jobs must be named exports | Yes | Every job used in a workflow must be a named export |
518
+ | Job names must be unique | Yes | Job names must be unique across the entire project |
519
+ | `mainJob` is required | Yes | Every workflow must specify a `mainJob` |
520
+ | Jobs in `deps` must be job objects | Yes | Pass job objects, not strings |
521
+
522
+ #### Workflow Job Definition
523
+
524
+ Define workflow jobs using `createWorkflowJob`:
525
+
526
+ ```typescript
527
+ import { createWorkflowJob } from "@tailor-platform/sdk";
528
+ import { getDB } from "../generated/tailordb";
529
+
530
+ // All jobs must be named exports
531
+ export const fetchCustomer = createWorkflowJob({
532
+ name: "fetch-customer",
533
+ body: async (input: { customerId: string }) => {
534
+ const db = getDB("tailordb");
535
+ const customer = await db
536
+ .selectFrom("Customer")
537
+ .selectAll()
538
+ .where("id", "=", input.customerId)
539
+ .executeTakeFirst();
540
+ return customer;
541
+ },
542
+ });
543
+ ```
544
+
545
+ #### Job Dependencies
546
+
547
+ Jobs can depend on other jobs using the `deps` array. Dependent jobs are accessible via the second argument of `body` function with hyphens replaced by underscores:
548
+
549
+ ```typescript
550
+ import { createWorkflowJob } from "@tailor-platform/sdk";
551
+ import { fetchCustomer } from "./jobs/fetch-customer";
552
+ import { sendNotification } from "./jobs/send-notification";
553
+
554
+ // All jobs must be named exports - including jobs with dependencies
555
+ export const processOrder = createWorkflowJob({
556
+ name: "process-order",
557
+ deps: [fetchCustomer, sendNotification],
558
+ body: async (input: { orderId: string; customerId: string }, jobs) => {
559
+ // Access dependent jobs with hyphens replaced by underscores
560
+ // "fetch-customer" -> jobs.fetch_customer()
561
+ // "send-notification" -> jobs.send_notification()
562
+ const customer = await jobs.fetch_customer({
563
+ customerId: input.customerId,
564
+ });
565
+
566
+ const notification = await jobs.send_notification({
567
+ message: `Order ${input.orderId} is being processed`,
568
+ recipient: customer.email,
569
+ });
570
+
571
+ return {
572
+ orderId: input.orderId,
573
+ customerEmail: customer.email,
574
+ notificationSent: notification.sent,
575
+ };
576
+ },
577
+ });
578
+ ```
579
+
580
+ #### Workflow Definition
581
+
582
+ Define a workflow using `createWorkflow` and export it as default:
583
+
584
+ ```typescript
585
+ import { createWorkflow, createWorkflowJob } from "@tailor-platform/sdk";
586
+ import { fetchCustomer } from "./jobs/fetch-customer";
587
+ import { sendNotification } from "./jobs/send-notification";
588
+
589
+ // Jobs must be named exports
590
+ export const processOrder = createWorkflowJob({
591
+ name: "process-order",
592
+ deps: [fetchCustomer, sendNotification],
593
+ body: async (input, jobs) => {
594
+ // ... job logic
595
+ },
596
+ });
597
+
598
+ // Workflow must be default export
599
+ export default createWorkflow({
600
+ name: "order-processing",
601
+ mainJob: processOrder,
602
+ });
603
+ ```
604
+
605
+ #### File Organization
606
+
607
+ Recommended file structure for workflows:
608
+
609
+ ```
610
+ workflows/
611
+ ├── jobs/
612
+ │ ├── fetch-customer.ts # export const fetchCustomer = createWorkflowJob(...)
613
+ │ └── send-notification.ts # export const sendNotification = createWorkflowJob(...)
614
+ └── order-processing.ts # export const processOrder = createWorkflowJob(...)
615
+ # export default createWorkflow(...)
616
+ ```
617
+
618
+ All jobs can be in a single file or split across multiple files, as long as they are named exports.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailor-platform/sdk",
3
- "version": "0.10.4",
3
+ "version": "0.11.1",
4
4
  "description": "Tailor Platform SDK - The SDK to work with Tailor Platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/configure/index.mjs",
@@ -55,6 +55,7 @@
55
55
  "madge": "8.0.0",
56
56
  "multiline-ts": "4.0.1",
57
57
  "open": "10.2.0",
58
+ "oxc-parser": "0.98.0",
58
59
  "pkg-types": "2.3.0",
59
60
  "rolldown": "1.0.0-beta.41",
60
61
  "smol-toml": "1.4.2",
@@ -70,9 +71,10 @@
70
71
  "@eslint/js": "9.39.1",
71
72
  "@tailor-platform/function-types": "0.7.2",
72
73
  "@types/madge": "5.0.3",
73
- "@types/node": "22.19.0",
74
+ "@types/node": "22.19.1",
74
75
  "eslint": "9.39.1",
75
76
  "globals": "16.5.0",
77
+ "sonda": "0.10.0",
76
78
  "tsdown": "0.15.6",
77
79
  "typescript": "5.9.3",
78
80
  "typescript-eslint": "8.47.0",
@@ -85,6 +87,7 @@
85
87
  "lint:fix": "eslint --cache . --fix",
86
88
  "typecheck": "tsc --noEmit",
87
89
  "prepublish": "pnpm run build",
88
- "postinstall": "node postinstall.mjs"
90
+ "postinstall": "node postinstall.mjs",
91
+ "measure:bundle": "node ../../scripts/measure-bundle-size-sonda.js"
89
92
  }
90
93
  }