@fayz-ai/sdk 0.1.3 → 0.1.5

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 (45) hide show
  1. package/README.md +20 -1
  2. package/dist/chunk-2N36RVVE.js +620 -0
  3. package/dist/chunk-2N36RVVE.js.map +1 -0
  4. package/dist/chunk-74AXXWNN.cjs +50 -0
  5. package/dist/chunk-74AXXWNN.cjs.map +1 -0
  6. package/dist/chunk-AFBFMBTK.js +45 -0
  7. package/dist/chunk-AFBFMBTK.js.map +1 -0
  8. package/dist/{chunk-REGBJXXB.cjs → chunk-MCB2L25R.cjs} +60 -2
  9. package/dist/chunk-MCB2L25R.cjs.map +1 -0
  10. package/dist/chunk-MPJDNWQY.cjs +623 -0
  11. package/dist/chunk-MPJDNWQY.cjs.map +1 -0
  12. package/dist/{chunk-O6XSRB3Q.js → chunk-R4XVCBFG.js} +60 -2
  13. package/dist/chunk-R4XVCBFG.js.map +1 -0
  14. package/dist/client.cjs +4 -4
  15. package/dist/client.d.ts +54 -0
  16. package/dist/client.d.ts.map +1 -1
  17. package/dist/client.js +1 -1
  18. package/dist/index.cjs +30 -4
  19. package/dist/index.d.ts +5 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +3 -1
  22. package/dist/release-channels.cjs +24 -0
  23. package/dist/release-channels.cjs.map +1 -0
  24. package/dist/release-channels.d.ts +10 -0
  25. package/dist/release-channels.d.ts.map +1 -0
  26. package/dist/release-channels.js +3 -0
  27. package/dist/release-channels.js.map +1 -0
  28. package/dist/shop.cjs +16 -0
  29. package/dist/shop.cjs.map +1 -0
  30. package/dist/shop.d.ts +394 -0
  31. package/dist/shop.d.ts.map +1 -0
  32. package/dist/shop.js +3 -0
  33. package/dist/shop.js.map +1 -0
  34. package/package.json +23 -10
  35. package/src/client.test.ts +135 -0
  36. package/src/client.ts +126 -0
  37. package/src/index.ts +36 -1
  38. package/src/release-channels.json +13 -0
  39. package/src/release-channels.test.ts +42 -0
  40. package/src/release-channels.ts +41 -0
  41. package/src/runtime.test.ts +4 -4
  42. package/src/shop.test.ts +114 -0
  43. package/src/shop.ts +860 -0
  44. package/dist/chunk-O6XSRB3Q.js.map +0 -1
  45. package/dist/chunk-REGBJXXB.cjs.map +0 -1
package/dist/shop.d.ts ADDED
@@ -0,0 +1,394 @@
1
+ export interface FayzShopProviderOptions {
2
+ supabaseUrl?: string;
3
+ publishableKey?: string;
4
+ storeId?: string;
5
+ apiBaseUrl?: string;
6
+ projectId?: string;
7
+ mode?: 'broker' | 'supabase';
8
+ productMetadata?: FayzShopProductMetadataOverlay[];
9
+ fetcher?: typeof fetch;
10
+ }
11
+ export interface FayzShopProductMetadataOverlay {
12
+ sku?: string | null;
13
+ slug?: string | null;
14
+ metadata: Record<string, unknown>;
15
+ }
16
+ export type FayzShopProductStatus = 'draft' | 'active' | 'archived';
17
+ export type FayzShopOrderStatus = 'open' | 'archived' | 'cancelled';
18
+ export type FayzShopFinancialStatus = 'pending' | 'paid' | 'partially_paid' | 'refunded' | 'partially_refunded' | 'voided';
19
+ export type FayzShopFulfillmentStatus = 'unfulfilled' | 'partially_fulfilled' | 'fulfilled';
20
+ export interface FayzShopListProductsOptions {
21
+ status?: FayzShopProductStatus;
22
+ categoryId?: string;
23
+ search?: string;
24
+ slug?: string;
25
+ limit?: number;
26
+ offset?: number;
27
+ orderBy?: 'name' | 'price' | 'created_at' | 'sort_order';
28
+ order?: 'asc' | 'desc';
29
+ }
30
+ export interface FayzShopListOrdersOptions {
31
+ status?: FayzShopOrderStatus;
32
+ financialStatus?: FayzShopFinancialStatus;
33
+ fulfillmentStatus?: FayzShopFulfillmentStatus;
34
+ customerId?: string;
35
+ customerEmail?: string;
36
+ search?: string;
37
+ limit?: number;
38
+ offset?: number;
39
+ }
40
+ export interface FayzShopListCustomersOptions {
41
+ search?: string;
42
+ limit?: number;
43
+ offset?: number;
44
+ }
45
+ export interface FayzShopListDiscountsOptions {
46
+ status?: string;
47
+ type?: string;
48
+ search?: string;
49
+ limit?: number;
50
+ offset?: number;
51
+ }
52
+ export declare class FayzShopError extends Error {
53
+ readonly status: number;
54
+ readonly responseBody?: unknown | undefined;
55
+ constructor(message: string, status: number, responseBody?: unknown | undefined);
56
+ }
57
+ declare function updateOrderPayload(input: {
58
+ status?: FayzShopOrderStatus;
59
+ financialStatus?: FayzShopFinancialStatus;
60
+ fulfillmentStatus?: FayzShopFulfillmentStatus;
61
+ notes?: string;
62
+ }): Record<string, unknown>;
63
+ export declare function createFayzShopProvider(options: FayzShopProviderOptions): {
64
+ listProducts(options?: FayzShopListProductsOptions): Promise<{
65
+ id: string;
66
+ tenantId: string;
67
+ name: string;
68
+ slug: string;
69
+ description: string | null;
70
+ price: number;
71
+ compareAtPrice: number | null;
72
+ currency: string;
73
+ status: FayzShopProductStatus;
74
+ inventoryCount: number;
75
+ sku: string | null;
76
+ sortOrder: number;
77
+ metadata: Record<string, unknown>;
78
+ images: {
79
+ id: string;
80
+ productId: string;
81
+ url: string;
82
+ altText: string | null;
83
+ sortOrder: number;
84
+ isPrimary: boolean;
85
+ createdAt: string;
86
+ }[];
87
+ categoryId: string | null;
88
+ categoryName: string | null;
89
+ isPhysical: boolean;
90
+ weight: number | null;
91
+ weightUnit: string;
92
+ createdAt: string;
93
+ updatedAt: string;
94
+ }[]>;
95
+ getProduct(id: string): Promise<{
96
+ id: string;
97
+ tenantId: string;
98
+ name: string;
99
+ slug: string;
100
+ description: string | null;
101
+ price: number;
102
+ compareAtPrice: number | null;
103
+ currency: string;
104
+ status: FayzShopProductStatus;
105
+ inventoryCount: number;
106
+ sku: string | null;
107
+ sortOrder: number;
108
+ metadata: Record<string, unknown>;
109
+ images: {
110
+ id: string;
111
+ productId: string;
112
+ url: string;
113
+ altText: string | null;
114
+ sortOrder: number;
115
+ isPrimary: boolean;
116
+ createdAt: string;
117
+ }[];
118
+ categoryId: string | null;
119
+ categoryName: string | null;
120
+ isPhysical: boolean;
121
+ weight: number | null;
122
+ weightUnit: string;
123
+ createdAt: string;
124
+ updatedAt: string;
125
+ } | null>;
126
+ createProduct(): Promise<never>;
127
+ updateProduct(): Promise<never>;
128
+ deleteProduct(): Promise<never>;
129
+ uploadProductImage(): Promise<never>;
130
+ deleteProductImage(): Promise<never>;
131
+ listCategories(): Promise<{
132
+ id: string;
133
+ tenantId: string;
134
+ name: string;
135
+ slug: string;
136
+ description: string | null;
137
+ parentId: string | null;
138
+ sortOrder: number;
139
+ imageUrl: string | null;
140
+ createdAt: string;
141
+ }[]>;
142
+ createCategory(): Promise<never>;
143
+ updateCategory(): Promise<never>;
144
+ deleteCategory(): Promise<never>;
145
+ listOrders(options?: FayzShopListOrdersOptions): Promise<{
146
+ id: string;
147
+ tenantId: string;
148
+ orderNumber: number;
149
+ status: FayzShopOrderStatus;
150
+ financialStatus: FayzShopFinancialStatus;
151
+ fulfillmentStatus: FayzShopFulfillmentStatus;
152
+ currency: string;
153
+ subtotal: number;
154
+ taxTotal: number;
155
+ discountTotal: number;
156
+ shippingTotal: number;
157
+ total: number;
158
+ customerId: string | null;
159
+ customerName: string | null;
160
+ customerEmail: string | null;
161
+ discountCode: string | null;
162
+ notes: string | null;
163
+ items: {
164
+ id: string;
165
+ orderId: string;
166
+ productId: string | null;
167
+ name: string;
168
+ sku: string | null;
169
+ quantity: number;
170
+ unitPrice: number;
171
+ total: number;
172
+ imageUrl: string | null;
173
+ }[];
174
+ createdAt: string;
175
+ updatedAt: string;
176
+ }[]>;
177
+ getOrder(id: string): Promise<{
178
+ id: string;
179
+ tenantId: string;
180
+ orderNumber: number;
181
+ status: FayzShopOrderStatus;
182
+ financialStatus: FayzShopFinancialStatus;
183
+ fulfillmentStatus: FayzShopFulfillmentStatus;
184
+ currency: string;
185
+ subtotal: number;
186
+ taxTotal: number;
187
+ discountTotal: number;
188
+ shippingTotal: number;
189
+ total: number;
190
+ customerId: string | null;
191
+ customerName: string | null;
192
+ customerEmail: string | null;
193
+ discountCode: string | null;
194
+ notes: string | null;
195
+ items: {
196
+ id: string;
197
+ orderId: string;
198
+ productId: string | null;
199
+ name: string;
200
+ sku: string | null;
201
+ quantity: number;
202
+ unitPrice: number;
203
+ total: number;
204
+ imageUrl: string | null;
205
+ }[];
206
+ createdAt: string;
207
+ updatedAt: string;
208
+ } | null>;
209
+ createOrder(input: {
210
+ customerId?: string;
211
+ customerName?: string;
212
+ customerEmail?: string;
213
+ currency?: string;
214
+ notes?: string;
215
+ discountCode?: string;
216
+ discountTotal?: number;
217
+ shippingTotal?: number;
218
+ items: Array<{
219
+ productId?: string;
220
+ name: string;
221
+ sku?: string;
222
+ quantity: number;
223
+ unitPrice: number;
224
+ imageUrl?: string;
225
+ }>;
226
+ }): Promise<{
227
+ id: string;
228
+ tenantId: string;
229
+ orderNumber: number;
230
+ status: FayzShopOrderStatus;
231
+ financialStatus: FayzShopFinancialStatus;
232
+ fulfillmentStatus: FayzShopFulfillmentStatus;
233
+ currency: string;
234
+ subtotal: number;
235
+ taxTotal: number;
236
+ discountTotal: number;
237
+ shippingTotal: number;
238
+ total: number;
239
+ customerId: string | null;
240
+ customerName: string | null;
241
+ customerEmail: string | null;
242
+ discountCode: string | null;
243
+ notes: string | null;
244
+ items: {
245
+ id: string;
246
+ orderId: string;
247
+ productId: string | null;
248
+ name: string;
249
+ sku: string | null;
250
+ quantity: number;
251
+ unitPrice: number;
252
+ total: number;
253
+ imageUrl: string | null;
254
+ }[];
255
+ createdAt: string;
256
+ updatedAt: string;
257
+ } | null>;
258
+ updateOrder(id: string, input: Parameters<typeof updateOrderPayload>[0]): Promise<{
259
+ id: string;
260
+ tenantId: string;
261
+ orderNumber: number;
262
+ status: FayzShopOrderStatus;
263
+ financialStatus: FayzShopFinancialStatus;
264
+ fulfillmentStatus: FayzShopFulfillmentStatus;
265
+ currency: string;
266
+ subtotal: number;
267
+ taxTotal: number;
268
+ discountTotal: number;
269
+ shippingTotal: number;
270
+ total: number;
271
+ customerId: string | null;
272
+ customerName: string | null;
273
+ customerEmail: string | null;
274
+ discountCode: string | null;
275
+ notes: string | null;
276
+ items: {
277
+ id: string;
278
+ orderId: string;
279
+ productId: string | null;
280
+ name: string;
281
+ sku: string | null;
282
+ quantity: number;
283
+ unitPrice: number;
284
+ total: number;
285
+ imageUrl: string | null;
286
+ }[];
287
+ createdAt: string;
288
+ updatedAt: string;
289
+ } | null>;
290
+ listCustomers(options?: FayzShopListCustomersOptions): Promise<{
291
+ id: string;
292
+ tenantId: string;
293
+ firstName: string;
294
+ lastName: string;
295
+ email: string | null;
296
+ phone: string | null;
297
+ notes: string | null;
298
+ ordersCount: number;
299
+ totalSpent: number;
300
+ createdAt: string;
301
+ updatedAt: string;
302
+ }[]>;
303
+ getCustomer(id: string): Promise<{
304
+ id: string;
305
+ tenantId: string;
306
+ firstName: string;
307
+ lastName: string;
308
+ email: string | null;
309
+ phone: string | null;
310
+ notes: string | null;
311
+ ordersCount: number;
312
+ totalSpent: number;
313
+ createdAt: string;
314
+ updatedAt: string;
315
+ } | null>;
316
+ createCustomer(input: {
317
+ firstName: string;
318
+ lastName?: string;
319
+ email?: string;
320
+ phone?: string;
321
+ notes?: string;
322
+ }): Promise<{
323
+ id: string;
324
+ tenantId: string;
325
+ firstName: string;
326
+ lastName: string;
327
+ email: string | null;
328
+ phone: string | null;
329
+ notes: string | null;
330
+ ordersCount: number;
331
+ totalSpent: number;
332
+ createdAt: string;
333
+ updatedAt: string;
334
+ }>;
335
+ updateCustomer(id: string, input: {
336
+ firstName?: string;
337
+ lastName?: string;
338
+ email?: string | null;
339
+ phone?: string | null;
340
+ notes?: string | null;
341
+ }): Promise<{
342
+ id: string;
343
+ tenantId: string;
344
+ firstName: string;
345
+ lastName: string;
346
+ email: string | null;
347
+ phone: string | null;
348
+ notes: string | null;
349
+ ordersCount: number;
350
+ totalSpent: number;
351
+ createdAt: string;
352
+ updatedAt: string;
353
+ }>;
354
+ deleteCustomer(id: string): Promise<void>;
355
+ listDiscounts(options?: FayzShopListDiscountsOptions): Promise<{
356
+ id: string;
357
+ tenantId: string;
358
+ title: string;
359
+ code: string | null;
360
+ type: string;
361
+ method: string;
362
+ value: number;
363
+ usageLimit: number | null;
364
+ oncePerCustomer: boolean;
365
+ startsAt: string;
366
+ endsAt: string | null;
367
+ status: string;
368
+ timesUsed: number;
369
+ createdAt: string;
370
+ updatedAt: string;
371
+ }[]>;
372
+ getDiscount(id: string): Promise<{
373
+ id: string;
374
+ tenantId: string;
375
+ title: string;
376
+ code: string | null;
377
+ type: string;
378
+ method: string;
379
+ value: number;
380
+ usageLimit: number | null;
381
+ oncePerCustomer: boolean;
382
+ startsAt: string;
383
+ endsAt: string | null;
384
+ status: string;
385
+ timesUsed: number;
386
+ createdAt: string;
387
+ updatedAt: string;
388
+ } | null>;
389
+ createDiscount(): Promise<never>;
390
+ updateDiscount(): Promise<never>;
391
+ deleteDiscount(): Promise<never>;
392
+ };
393
+ export {};
394
+ //# sourceMappingURL=shop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shop.d.ts","sourceRoot":"","sources":["../src/shop.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC5B,eAAe,CAAC,EAAE,8BAA8B,EAAE,CAAA;IAClD,OAAO,CAAC,EAAE,OAAO,KAAK,CAAA;CACvB;AAED,MAAM,WAAW,8BAA8B;IAC7C,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC;AAED,MAAM,MAAM,qBAAqB,GAAG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AAC,QAAQ,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KACzH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBA0CqB,MAAM,SAAS,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAQ/C,4BAA4B;;;;;;;;;;;;;oBASpC,MAAM;;;;;;;;;;;;;0BAIA;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;;;uBAe3F,MAAM,SAAS;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE;;;;;;;;;;;;;uBAe7H,MAAM;4BAGD,4BAA4B;;;;;;;;;;;;;;;;;oBAWpC,MAAM;;;;;;;;;;;;;;;;;;;;EAc/B"}
package/dist/shop.js ADDED
@@ -0,0 +1,3 @@
1
+ export { FayzShopError, createFayzShopProvider } from './chunk-2N36RVVE.js';
2
+ //# sourceMappingURL=shop.js.map
3
+ //# sourceMappingURL=shop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"shop.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fayz-ai/sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Fayz SDK — API client, app params, runtime broker helpers, and shared types for generated Fayz projects",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -25,6 +25,19 @@
25
25
  "import": "./dist/client.js",
26
26
  "require": "./dist/client.cjs"
27
27
  },
28
+ "./shop": {
29
+ "source": "./src/shop.ts",
30
+ "types": "./dist/shop.d.ts",
31
+ "import": "./dist/shop.js",
32
+ "require": "./dist/shop.cjs"
33
+ },
34
+ "./release-channels": {
35
+ "source": "./src/release-channels.ts",
36
+ "types": "./dist/release-channels.d.ts",
37
+ "import": "./dist/release-channels.js",
38
+ "require": "./dist/release-channels.cjs"
39
+ },
40
+ "./release-channels.json": "./src/release-channels.json",
28
41
  "./runtime": {
29
42
  "source": "./src/runtime.ts",
30
43
  "types": "./dist/runtime.d.ts",
@@ -43,13 +56,6 @@
43
56
  "src",
44
57
  "README.md"
45
58
  ],
46
- "scripts": {
47
- "build": "tsup && tsc --emitDeclarationOnly --declaration --declarationMap --noEmit false",
48
- "dev": "tsup --watch",
49
- "typecheck": "tsc --noEmit",
50
- "test": "vitest run",
51
- "clean": "rm -rf dist"
52
- },
53
59
  "devDependencies": {
54
60
  "tsup": "^8.2.0",
55
61
  "typescript": "^5.5.0",
@@ -73,5 +79,12 @@
73
79
  "fayz-sdk",
74
80
  "runtime",
75
81
  "api-client"
76
- ]
77
- }
82
+ ],
83
+ "scripts": {
84
+ "build": "tsup && tsc --emitDeclarationOnly --declaration --declarationMap --noEmit false",
85
+ "dev": "tsup --watch",
86
+ "typecheck": "tsc --noEmit",
87
+ "test": "vitest run",
88
+ "clean": "rm -rf dist"
89
+ }
90
+ }
@@ -38,4 +38,139 @@ describe('createFayzClient', () => {
38
38
 
39
39
  await expect(client.auth.me()).resolves.toEqual({ id: 'user-2' })
40
40
  })
41
+
42
+ it('lists project table rows through the Fayz data API', async () => {
43
+ const fetcher = vi.fn<typeof fetch>().mockResolvedValue(jsonResponse({
44
+ rows: [{ id: 'booking-1' }],
45
+ total: 12,
46
+ }))
47
+ const client = createFayzClient({
48
+ baseUrl: 'https://api.fayz.ai',
49
+ appId: 'app-1',
50
+ token: async () => 'runtime-token',
51
+ fetcher,
52
+ })
53
+
54
+ const result = await client.data.listRows<{ id: string }>({
55
+ projectId: 'project 1',
56
+ table: 'v_bookings',
57
+ filters: [
58
+ { column: 'starts_at', operator: 'gte', value: '2026-06-14T00:00:00.000Z' },
59
+ { column: 'status', operator: 'neq', value: 'cancelled' },
60
+ ],
61
+ sortColumn: 'starts_at',
62
+ sortDirection: 'asc',
63
+ limit: 20,
64
+ runtime: true,
65
+ })
66
+
67
+ expect(result.rows[0]?.id).toBe('booking-1')
68
+ expect(result.total).toBe(12)
69
+
70
+ const [url, init] = fetcher.mock.calls[0] ?? []
71
+ expect(url).toContain('https://api.fayz.ai/api/v1/runtime/projects/project%201/database/tables/v_bookings/rows?')
72
+ expect(url).toContain('filters=')
73
+ expect(url).toContain('sortColumn=starts_at')
74
+ expect(url).toContain('sortDirection=asc')
75
+ expect(url).toContain('limit=20')
76
+ expect(init).toEqual(expect.objectContaining({
77
+ headers: expect.objectContaining({
78
+ 'X-App-Id': 'app-1',
79
+ Authorization: 'Bearer runtime-token',
80
+ }),
81
+ }))
82
+ })
83
+
84
+ it('counts table rows using the Fayz data API total', async () => {
85
+ const fetcher = vi.fn<typeof fetch>().mockResolvedValue(jsonResponse({
86
+ rows: [],
87
+ total: 7,
88
+ }))
89
+ const client = createFayzClient({ baseUrl: 'https://api.fayz.ai', fetcher })
90
+
91
+ await expect(client.data.countRows({
92
+ projectId: 'project-1',
93
+ table: 'clients',
94
+ filters: [{ column: 'active', operator: 'eq', value: true }],
95
+ })).resolves.toBe(7)
96
+
97
+ const [url] = fetcher.mock.calls[0] ?? []
98
+ expect(url).toContain('/api/projects/project-1/database/tables/clients/rows?')
99
+ expect(url).toContain('page=1')
100
+ expect(url).toContain('limit=1')
101
+ })
102
+
103
+ it('creates table rows through the Fayz data API', async () => {
104
+ const fetcher = vi.fn<typeof fetch>().mockResolvedValue(jsonResponse({ id: 'menu-1', name: 'Burger' }, 201))
105
+ const client = createFayzClient({
106
+ baseUrl: 'https://api.fayz.ai',
107
+ appId: 'app-1',
108
+ token: 'runtime-token',
109
+ fetcher,
110
+ })
111
+
112
+ const row = await client.data.createRow<{ id: string; name: string }>({
113
+ projectId: 'project-1',
114
+ table: 'menu_items',
115
+ schema: 'public',
116
+ runtime: true,
117
+ row: { name: 'Burger' },
118
+ })
119
+
120
+ expect(row).toEqual({ id: 'menu-1', name: 'Burger' })
121
+
122
+ const [url, init] = fetcher.mock.calls[0] ?? []
123
+ expect(url).toBe('https://api.fayz.ai/api/v1/runtime/projects/project-1/database/tables/menu_items/rows?schema=public')
124
+ expect(init).toEqual(expect.objectContaining({
125
+ method: 'POST',
126
+ body: JSON.stringify({ name: 'Burger' }),
127
+ headers: expect.objectContaining({
128
+ 'Content-Type': 'application/json',
129
+ 'X-App-Id': 'app-1',
130
+ Authorization: 'Bearer runtime-token',
131
+ }),
132
+ }))
133
+ })
134
+
135
+ it('updates table rows by primary key through the Fayz data API', async () => {
136
+ const fetcher = vi.fn<typeof fetch>().mockResolvedValue(jsonResponse({ id: 'table-1', status: 'occupied' }))
137
+ const client = createFayzClient({ baseUrl: 'https://api.fayz.ai', fetcher })
138
+
139
+ const row = await client.data.updateRow<{ id: string; status: string }>({
140
+ projectId: 'project-1',
141
+ table: 'restaurant_tables',
142
+ primaryKeys: { id: 'table-1' },
143
+ row: { status: 'occupied' },
144
+ })
145
+
146
+ expect(row.status).toBe('occupied')
147
+
148
+ const [url, init] = fetcher.mock.calls[0] ?? []
149
+ expect(url).toBe('https://api.fayz.ai/api/projects/project-1/database/tables/restaurant_tables/rows')
150
+ expect(init).toEqual(expect.objectContaining({
151
+ method: 'PATCH',
152
+ body: JSON.stringify({
153
+ primaryKeys: { id: 'table-1' },
154
+ data: { status: 'occupied' },
155
+ }),
156
+ }))
157
+ })
158
+
159
+ it('deletes table rows through the Fayz data API', async () => {
160
+ const fetcher = vi.fn<typeof fetch>().mockResolvedValue(jsonResponse({ deletedCount: 1 }))
161
+ const client = createFayzClient({ baseUrl: 'https://api.fayz.ai', fetcher })
162
+
163
+ await expect(client.data.deleteRows({
164
+ projectId: 'project-1',
165
+ table: 'restaurant_tables',
166
+ rows: [{ id: 'table-1' }],
167
+ })).resolves.toEqual({ deletedCount: 1 })
168
+
169
+ const [url, init] = fetcher.mock.calls[0] ?? []
170
+ expect(url).toBe('https://api.fayz.ai/api/projects/project-1/database/tables/restaurant_tables/rows')
171
+ expect(init).toEqual(expect.objectContaining({
172
+ method: 'DELETE',
173
+ body: JSON.stringify({ rows: [{ id: 'table-1' }] }),
174
+ }))
175
+ })
41
176
  })