@tailor-platform/sdk 1.4.2 → 1.6.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/dist/application-D5kzHyuG.mjs +5 -0
  3. package/dist/{list-QT92XcP3.mjs → application-D9mwb5eH.mjs} +2349 -11656
  4. package/dist/application-D9mwb5eH.mjs.map +1 -0
  5. package/dist/auth-0Zh4xp4z.mjs +772 -0
  6. package/dist/auth-0Zh4xp4z.mjs.map +1 -0
  7. package/dist/cli/index.mjs +247 -26
  8. package/dist/cli/index.mjs.map +1 -1
  9. package/dist/cli/lib.d.mts +292 -20
  10. package/dist/cli/lib.mjs +4 -3
  11. package/dist/cli/lib.mjs.map +1 -1
  12. package/dist/configure/index.d.mts +3 -3
  13. package/dist/configure/index.mjs +40 -5
  14. package/dist/configure/index.mjs.map +1 -1
  15. package/dist/{index-lDsl6VDv.d.mts → index-C_yeYBC8.d.mts} +45 -10
  16. package/dist/{types-BWzDv7TK.d.mts → index-k5hWCs5L.d.mts} +885 -861
  17. package/dist/{jiti-31_Wx1yz.mjs → jiti-SMSW3TA0.mjs} +1 -1
  18. package/dist/{jiti-31_Wx1yz.mjs.map → jiti-SMSW3TA0.mjs.map} +1 -1
  19. package/dist/job-8XfvLyxH.mjs +21 -0
  20. package/dist/job-8XfvLyxH.mjs.map +1 -0
  21. package/dist/list-C_lrs5OC.mjs +11935 -0
  22. package/dist/list-C_lrs5OC.mjs.map +1 -0
  23. package/dist/{src-Bhwd-tei.mjs → src-qLXX6nub.mjs} +1 -1
  24. package/dist/{src-Bhwd-tei.mjs.map → src-qLXX6nub.mjs.map} +1 -1
  25. package/dist/utils/test/index.d.mts +4 -3
  26. package/dist/utils/test/index.mjs +3 -1
  27. package/dist/utils/test/index.mjs.map +1 -1
  28. package/docs/cli/application.md +23 -187
  29. package/docs/cli/tailordb.md +621 -0
  30. package/docs/cli-reference.md +31 -15
  31. package/docs/services/auth.md +35 -1
  32. package/docs/testing.md +81 -0
  33. package/package.json +11 -1
  34. package/dist/config-CBpYlVa-.mjs +0 -664
  35. package/dist/config-CBpYlVa-.mjs.map +0 -1
  36. package/dist/list-QT92XcP3.mjs.map +0 -1
@@ -32,6 +32,10 @@ const auth = defineAuth("my-auth", {
32
32
  usernameField: "email",
33
33
  attributes: { role: true },
34
34
  },
35
+ // Optional when you don't define userProfile:
36
+ // machineUserAttributes: {
37
+ // role: t.string(),
38
+ // },
35
39
  machineUsers: {
36
40
  "admin-machine-user": {
37
41
  attributes: { role: "ADMIN" },
@@ -84,6 +88,36 @@ export const user = db.type("User", {
84
88
 
85
89
  **attributes**: Specifies which fields from the TailorDB type are used as user attributes. Set to `true` to enable a field. Enabled attributes must be assigned values in all machine user definitions.
86
90
 
91
+ ## Machine User Attributes (without userProfile)
92
+
93
+ When you want to use machine users without defining a `userProfile`, define `machineUserAttributes` instead. These attributes are used for:
94
+
95
+ - type-safe `machineUsers[*].attributes`
96
+ - `context.user.attributes` typing (via `user-defined.d.ts`)
97
+
98
+ ```typescript
99
+ import { defineAuth, t } from "@tailor-platform/sdk";
100
+
101
+ export const auth = defineAuth("my-auth", {
102
+ machineUserAttributes: {
103
+ role: t.string(),
104
+ isActive: t.bool(),
105
+ tags: t.string({ array: true }),
106
+ },
107
+ machineUsers: {
108
+ "admin-machine-user": {
109
+ attributes: { role: "ADMIN", isActive: true, tags: ["root"] },
110
+ },
111
+ },
112
+ });
113
+ ```
114
+
115
+ To update types in `user-defined.d.ts`, run:
116
+
117
+ ```bash
118
+ tailor-sdk generate
119
+ ```
120
+
87
121
  ## Machine Users
88
122
 
89
123
  Service accounts for automated access without user interaction:
@@ -99,7 +133,7 @@ machineUsers: {
99
133
  },
100
134
  ```
101
135
 
102
- **attributes**: Values for attributes enabled in `userProfile.attributes`. All fields marked as `true` in `userProfile.attributes` must be set here. These values are accessible via `user.attributes`:
136
+ **attributes**: Values for attributes enabled in `userProfile.attributes` (or all fields defined in `machineUserAttributes` when `userProfile` is omitted). All enabled fields must be set here. These values are accessible via `user.attributes`:
103
137
 
104
138
  ```typescript
105
139
  // In a resolver
package/docs/testing.md CHANGED
@@ -171,6 +171,87 @@ describe("decrementUserAge resolver", () => {
171
171
  - Mock high-level operations instead of low-level SQL queries
172
172
  - **Best for:** Complex business logic with multiple database operations
173
173
 
174
+ ## Workflow Tests
175
+
176
+ Test workflows locally without deploying to Tailor Platform.
177
+
178
+ ### Job Unit Tests
179
+
180
+ Test individual job logic by calling `.body()` directly:
181
+
182
+ ```typescript
183
+ import workflow, { addNumbers, calculate } from "./workflows/calculation";
184
+
185
+ describe("workflow jobs", () => {
186
+ test("addNumbers.body() adds two numbers", () => {
187
+ const result = addNumbers.body({ a: 2, b: 3 }, { env: {} });
188
+ expect(result).toBe(5);
189
+ });
190
+ });
191
+ ```
192
+
193
+ ### Mocking Dependent Jobs
194
+
195
+ For jobs that trigger other jobs, mock the dependencies using `vi.spyOn()`:
196
+
197
+ ```typescript
198
+ import { afterEach, vi } from "vitest";
199
+ import workflow, { addNumbers, calculate, multiplyNumbers } from "./workflows/calculation";
200
+
201
+ describe("workflow with dependencies", () => {
202
+ afterEach(() => {
203
+ vi.restoreAllMocks();
204
+ });
205
+
206
+ test("calculate.body() with mocked dependent jobs", async () => {
207
+ // Mock the trigger methods for dependent jobs
208
+ vi.spyOn(addNumbers, "trigger").mockResolvedValue(5);
209
+ vi.spyOn(multiplyNumbers, "trigger").mockResolvedValue(10);
210
+
211
+ const result = await calculate.body({ a: 2, b: 3 }, { env: {} });
212
+
213
+ expect(addNumbers.trigger).toHaveBeenCalledWith({ a: 2, b: 3 });
214
+ expect(result).toBe(10);
215
+ });
216
+ });
217
+ ```
218
+
219
+ **Note:** To execute dependent jobs without mocking, and they require `env`, use `vi.stubEnv(WORKFLOW_TEST_ENV_KEY, ...)` and call `.trigger()` directly as shown in the integration test section below.
220
+
221
+ ### Integration Tests with `.trigger()`
222
+
223
+ Test the full workflow execution using `workflow.mainJob.trigger()`:
224
+
225
+ ```typescript
226
+ import { WORKFLOW_TEST_ENV_KEY } from "@tailor-platform/sdk/test";
227
+ import { afterEach, vi } from "vitest";
228
+ import workflow from "./workflows/calculation";
229
+
230
+ describe("workflow integration", () => {
231
+ afterEach(() => {
232
+ vi.unstubAllEnvs();
233
+ });
234
+
235
+ test("workflow.mainJob.trigger() executes all jobs", async () => {
236
+ // Set environment variables for the workflow
237
+ vi.stubEnv(WORKFLOW_TEST_ENV_KEY, JSON.stringify({ NODE_ENV: "test" }));
238
+
239
+ // No mocking - all jobs execute their actual body functions
240
+ const result = await workflow.mainJob.trigger({ a: 3, b: 4 });
241
+
242
+ expect(result).toBe(21); // (3 + 4) * 3 = 21
243
+ });
244
+ });
245
+ ```
246
+
247
+ **Key points:**
248
+
249
+ - Use `.body()` for unit testing individual job logic
250
+ - Use `vi.spyOn(job, "trigger").mockResolvedValue(...)` to mock dependent jobs when they don't need `env`
251
+ - If dependent jobs require `env`, use `vi.stubEnv(WORKFLOW_TEST_ENV_KEY, ...)` and call `.trigger()` instead of mocking
252
+ - Use `workflow.mainJob.trigger()` to execute the full workflow chain and get the result
253
+ - **Best for:** Testing workflow orchestration and job dependencies
254
+
174
255
  ## End-to-End (E2E) Tests
175
256
 
176
257
  E2E tests verify your application works correctly when deployed to Tailor Platform. They test the full stack including GraphQL API, database operations, and authentication.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailor-platform/sdk",
3
- "version": "1.4.2",
3
+ "version": "1.6.0",
4
4
  "description": "Tailor Platform SDK - The SDK to work with Tailor Platform",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -74,6 +74,7 @@
74
74
  },
75
75
  "devDependencies": {
76
76
  "@eslint/js": "9.39.2",
77
+ "@tailor-platform/function-kysely-tailordb": "0.1.3",
77
78
  "@tailor-platform/function-types": "0.8.0",
78
79
  "@toiroakr/lines-db": "0.6.1",
79
80
  "@types/madge": "5.0.3",
@@ -86,6 +87,7 @@
86
87
  "eslint-plugin-jsdoc": "62.1.0",
87
88
  "eslint-plugin-oxlint": "1.39.0",
88
89
  "globals": "17.0.0",
90
+ "kysely": "0.28.2",
89
91
  "oxlint": "1.39.0",
90
92
  "oxlint-tsgolint": "0.11.1",
91
93
  "sonda": "0.10.1",
@@ -96,12 +98,20 @@
96
98
  },
97
99
  "peerDependencies": {
98
100
  "@liam-hq/cli": "*",
101
+ "@tailor-platform/function-kysely-tailordb": "*",
102
+ "kysely": "*",
99
103
  "serve": "*"
100
104
  },
101
105
  "peerDependenciesMeta": {
102
106
  "@liam-hq/cli": {
103
107
  "optional": true
104
108
  },
109
+ "@tailor-platform/function-kysely-tailordb": {
110
+ "optional": true
111
+ },
112
+ "kysely": {
113
+ "optional": true
114
+ },
105
115
  "serve": {
106
116
  "optional": true
107
117
  }