@fayz-ai/sdk 0.1.4 → 0.2.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/LICENSE +21 -0
- package/README.md +24 -71
- package/dist/ai-builder.cjs +20 -0
- package/dist/ai-builder.cjs.map +1 -0
- package/dist/ai-builder.d.ts +20 -0
- package/dist/ai-builder.d.ts.map +1 -0
- package/dist/ai-builder.js +3 -0
- package/dist/ai-builder.js.map +1 -0
- package/dist/{chunk-JBQDG2GN.js → chunk-6JDIFOJG.js} +226 -2
- package/dist/chunk-6JDIFOJG.js.map +1 -0
- package/dist/chunk-OXIIHQFK.cjs +63 -0
- package/dist/chunk-OXIIHQFK.cjs.map +1 -0
- package/dist/{chunk-3VVLBMKG.cjs → chunk-RCX43OHW.cjs} +226 -2
- package/dist/chunk-RCX43OHW.cjs.map +1 -0
- package/dist/chunk-UMI2WELN.js +84 -0
- package/dist/chunk-UMI2WELN.js.map +1 -0
- package/dist/chunk-VDWMKACF.cjs +88 -0
- package/dist/chunk-VDWMKACF.cjs.map +1 -0
- package/dist/chunk-VPTVRD5M.cjs +92 -0
- package/dist/chunk-VPTVRD5M.cjs.map +1 -0
- package/dist/chunk-VUSZUJX3.js +58 -0
- package/dist/chunk-VUSZUJX3.js.map +1 -0
- package/dist/chunk-W5RBGSBM.js +87 -0
- package/dist/chunk-W5RBGSBM.js.map +1 -0
- package/dist/index.cjs +38 -8
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/release-channels.cjs +5 -5
- package/dist/release-channels.js +1 -1
- package/dist/shop.cjs +3 -3
- package/dist/shop.d.ts +54 -3
- package/dist/shop.d.ts.map +1 -1
- package/dist/shop.js +1 -1
- package/dist/supported-surface.cjs +24 -0
- package/dist/supported-surface.cjs.map +1 -0
- package/dist/supported-surface.d.ts +19 -0
- package/dist/supported-surface.d.ts.map +1 -0
- package/dist/supported-surface.js +3 -0
- package/dist/supported-surface.js.map +1 -0
- package/package.json +23 -10
- package/src/ai-builder.ts +115 -0
- package/src/index.ts +17 -0
- package/src/release-channels.json +45 -3
- package/src/release-channels.test.ts +3 -4
- package/src/shop.test.ts +31 -0
- package/src/shop.ts +261 -3
- package/src/supported-surface.json +40 -0
- package/src/supported-surface.ts +33 -0
- package/dist/chunk-3VVLBMKG.cjs.map +0 -1
- package/dist/chunk-7FF2FLPG.js +0 -45
- package/dist/chunk-7FF2FLPG.js.map +0 -1
- package/dist/chunk-JBQDG2GN.js.map +0 -1
- package/dist/chunk-JXXIKYP3.cjs +0 -50
- package/dist/chunk-JXXIKYP3.cjs.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Faya Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,89 +1,42 @@
|
|
|
1
1
|
# @fayz-ai/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> The typed client and contract layer every Fayz app talks to.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@fayz-ai/sdk)
|
|
6
|
+
[](https://github.com/FayaLabs/fayz-sdk/blob/main/LICENSE)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
Fayz builds real, multi-tenant SaaS apps by composing plugins. `@fayz-ai/sdk` is the seam between a generated Fayz project and the platform behind it: a typed API client, the shared manifest/user/params types, a runtime broker for OAuth-backed integrations, and the release-channel resolver that keeps every package on a coherent version set.
|
|
9
|
+
|
|
10
|
+
This is the lowest-trust, zero-React layer — no UI, no framework, just the contract. Generated apps call Fayz through the SDK instead of importing provider clients directly, so OAuth secrets and tenant authority stay server-side where they belong. If you're reading Fayz tables, exchanging plugin OAuth grants, or pinning a package channel, you start here.
|
|
11
|
+
|
|
12
|
+
## What's inside
|
|
13
|
+
- `createFayzClient` / `fayz` — typed client with `auth.me()` and `data` row access (`listRows`, `countRows`, `createRow`, `updateRow`, `deleteRows`) plus `FayzApiError`
|
|
14
|
+
- `createFayzRuntimeClient` / `FayzRuntimeError` — runtime OAuth broker for plugin grant exchange and Google Calendar access
|
|
15
|
+
- `createFayzShopProvider` / `FayzShopError` — commerce read provider (products, orders, customers, discounts) with status types
|
|
16
|
+
- `appParams` / `resolveAppParams` — read the app params Fayz injects into a generated project
|
|
17
|
+
- `fayzPackageVersionSets` + `resolveFayzPackage*` — release-channel resolution across the SDK
|
|
18
|
+
- Shared types: `AppManifest`, `PageManifest`, `SurfaceManifest`, `PluginRef`, `FayzUser`, `FayzAuthMeResponse`
|
|
8
19
|
|
|
20
|
+
## Install
|
|
9
21
|
```bash
|
|
10
22
|
npm install @fayz-ai/sdk
|
|
11
23
|
```
|
|
24
|
+
No peer dependencies — framework-agnostic.
|
|
12
25
|
|
|
13
|
-
##
|
|
14
|
-
|
|
26
|
+
## Usage
|
|
15
27
|
```ts
|
|
16
28
|
import { fayz } from '@fayz-ai/sdk'
|
|
17
|
-
import { appParams } from '@fayz-ai/sdk/app-params'
|
|
18
|
-
|
|
19
|
-
const currentUser = await fayz.auth.me()
|
|
20
|
-
|
|
21
|
-
console.log(appParams.appId, currentUser)
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Custom Client
|
|
25
|
-
|
|
26
|
-
```ts
|
|
27
|
-
import { createFayzClient } from '@fayz-ai/sdk'
|
|
28
|
-
|
|
29
|
-
const fayz = createFayzClient({
|
|
30
|
-
baseUrl: 'https://api.fayz.ai',
|
|
31
|
-
appId: 'app_123',
|
|
32
|
-
token: 'runtime-token',
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const user = await fayz.auth.me()
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Data/API Access
|
|
39
|
-
|
|
40
|
-
Generated apps should call Fayz through the SDK instead of importing provider clients directly.
|
|
41
29
|
|
|
42
|
-
|
|
43
|
-
import { fayz } from '@fayz-ai/sdk'
|
|
30
|
+
const me = await fayz.auth.me()
|
|
44
31
|
|
|
45
|
-
const
|
|
32
|
+
const { rows, total } = await fayz.data.listRows({
|
|
46
33
|
table: 'v_bookings',
|
|
47
|
-
filters: [
|
|
48
|
-
{ column: 'starts_at', operator: 'gte', value: dayStart },
|
|
49
|
-
{ column: 'starts_at', operator: 'lt', value: dayEnd },
|
|
50
|
-
{ column: 'status', operator: 'neq', value: 'cancelled' },
|
|
51
|
-
{ column: 'status', operator: 'neq', value: 'no_show' },
|
|
52
|
-
],
|
|
34
|
+
filters: [{ column: 'status', operator: 'neq', value: 'cancelled' }],
|
|
53
35
|
})
|
|
54
36
|
```
|
|
55
37
|
|
|
56
|
-
##
|
|
57
|
-
|
|
58
|
-
Provider OAuth secrets and refresh tokens stay server-side in Fayz. Generated projects should exchange a short-lived runtime token through Fayz and call brokered helpers.
|
|
59
|
-
|
|
60
|
-
```ts
|
|
61
|
-
import { createFayzRuntimeClient } from '@fayz-ai/sdk/runtime'
|
|
62
|
-
|
|
63
|
-
const runtime = createFayzRuntimeClient({
|
|
64
|
-
baseUrl: 'https://api.fayz.ai',
|
|
65
|
-
projectId: 'project_123',
|
|
66
|
-
runtimeToken: 'runtime-token',
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
const grant = await runtime.exchangePluginOAuth({
|
|
70
|
-
pluginId: 'agenda',
|
|
71
|
-
scopes: ['google.calendar.readonly'],
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
const calendars = await runtime.googleCalendar(grant.token).listCalendars()
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## Package Roles
|
|
78
|
-
|
|
79
|
-
- `@fayz-ai/sdk`: default SDK package for every generated project.
|
|
80
|
-
|
|
81
|
-
App runtime, shell, UI, and plugin modules are platform-bundled/internal while the Beauty manifest proof validates the right public boundary. Do not install or publish separate runtime/plugin packages for generated apps yet.
|
|
82
|
-
|
|
83
|
-
## Security Boundary
|
|
84
|
-
|
|
85
|
-
Do not put OAuth client secrets, provider refresh tokens, partner API keys, tenant authority decisions, or raw Fayz service secrets in SDK packages, generated repos, manifests, or browser code.
|
|
86
|
-
|
|
87
|
-
## License
|
|
38
|
+
## Part of the Fayz SDK
|
|
39
|
+
The foundation client beneath `@fayz-ai/core`, `@fayz-ai/saas`, and every Fayz plugin.
|
|
88
40
|
|
|
89
|
-
|
|
41
|
+
## Roadmap & contributing
|
|
42
|
+
Built and evolving in the open. See the [Fayz SDK roadmap](../../docs/ROADMAP.md#sdk) for current gaps, missing features, and good first issues.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVDWMKACF_cjs = require('./chunk-VDWMKACF.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "AI_BUILDER_REQUEST_CLASSES", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkVDWMKACF_cjs.AI_BUILDER_REQUEST_CLASSES; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "AI_BUILDER_REQUEST_CLASS_IDS", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkVDWMKACF_cjs.AI_BUILDER_REQUEST_CLASS_IDS; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "isAllowedRequestClass", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkVDWMKACF_cjs.isAllowedRequestClass; }
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=ai-builder.cjs.map
|
|
20
|
+
//# sourceMappingURL=ai-builder.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"ai-builder.cjs"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Ownership layer a request may modify. */
|
|
2
|
+
export type FayzLayer = 'app' | 'plugin-config' | 'private-extension' | 'platform' | 'none';
|
|
3
|
+
export type AiBuilderRequestClass = 'app-edit' | 'plugin-config' | 'private-extension' | 'platform-or-plugin-upgrade' | 'unsafe-blocked';
|
|
4
|
+
export interface AiBuilderRequestClassDef {
|
|
5
|
+
id: AiBuilderRequestClass;
|
|
6
|
+
label: string;
|
|
7
|
+
/** Which ownership layer this class is allowed to modify. */
|
|
8
|
+
layer: FayzLayer;
|
|
9
|
+
/** Who may perform it. */
|
|
10
|
+
editableBy: 'ai' | 'partner' | 'fayz' | 'none';
|
|
11
|
+
needsCode: boolean;
|
|
12
|
+
needsDeploy: boolean;
|
|
13
|
+
description: string;
|
|
14
|
+
examples: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare const AI_BUILDER_REQUEST_CLASSES: Record<AiBuilderRequestClass, AiBuilderRequestClassDef>;
|
|
17
|
+
export declare const AI_BUILDER_REQUEST_CLASS_IDS: AiBuilderRequestClass[];
|
|
18
|
+
/** True when a request class is permitted (anything but unsafe-blocked). */
|
|
19
|
+
export declare function isAllowedRequestClass(id: AiBuilderRequestClass): boolean;
|
|
20
|
+
//# sourceMappingURL=ai-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-builder.d.ts","sourceRoot":"","sources":["../src/ai-builder.ts"],"names":[],"mappings":"AAKA,4CAA4C;AAC5C,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,eAAe,GAAG,mBAAmB,GAAG,UAAU,GAAG,MAAM,CAAA;AAE3F,MAAM,MAAM,qBAAqB,GAC7B,UAAU,GACV,eAAe,GACf,mBAAmB,GACnB,4BAA4B,GAC5B,gBAAgB,CAAA;AAEpB,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,qBAAqB,CAAA;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,6DAA6D;IAC7D,KAAK,EAAE,SAAS,CAAA;IAChB,0BAA0B;IAC1B,UAAU,EAAE,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAA;IAC9C,SAAS,EAAE,OAAO,CAAA;IAClB,WAAW,EAAE,OAAO,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAAC,qBAAqB,EAAE,wBAAwB,CA6E9F,CAAA;AAED,eAAO,MAAM,4BAA4B,EAEpC,qBAAqB,EAAE,CAAA;AAE5B,4EAA4E;AAC5E,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAExE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"ai-builder.js"}
|
|
@@ -196,6 +196,12 @@ function updateOrderPayload(input) {
|
|
|
196
196
|
return updates;
|
|
197
197
|
}
|
|
198
198
|
function createFayzShopProvider(options) {
|
|
199
|
+
if (options.mode === "broker" || options.apiBaseUrl || options.projectId) {
|
|
200
|
+
return createBrokerShopProvider(options);
|
|
201
|
+
}
|
|
202
|
+
if (!options.supabaseUrl || !options.publishableKey || !options.storeId) {
|
|
203
|
+
throw new FayzShopError("Fayz Shop provider requires either broker apiBaseUrl/projectId or legacy supabaseUrl/publishableKey/storeId.", 400);
|
|
204
|
+
}
|
|
199
205
|
const baseUrl = `${normalizeBaseUrl(options.supabaseUrl)}/rest/v1`;
|
|
200
206
|
const fetcher = options.fetcher ?? fetch;
|
|
201
207
|
const key = options.publishableKey;
|
|
@@ -361,6 +367,46 @@ function createFayzShopProvider(options) {
|
|
|
361
367
|
});
|
|
362
368
|
return this.getOrder(id);
|
|
363
369
|
},
|
|
370
|
+
async placeOrder(input) {
|
|
371
|
+
const orderItems = [];
|
|
372
|
+
let subtotal = 0;
|
|
373
|
+
for (const line of input.items) {
|
|
374
|
+
const product = await this.getProduct(line.productId);
|
|
375
|
+
if (!product || product.status !== "active") throw new FayzShopError(`Product unavailable: ${line.productId}`, 409);
|
|
376
|
+
if (product.inventoryCount < line.quantity) throw new FayzShopError(`Insufficient stock for ${product.name}`, 409);
|
|
377
|
+
const name = line.optionsLabel ? `${product.name} (${line.optionsLabel})` : product.name;
|
|
378
|
+
subtotal += product.price * line.quantity;
|
|
379
|
+
orderItems.push({ productId: product.id, name, sku: product.sku ?? void 0, quantity: line.quantity, unitPrice: product.price, imageUrl: product.images[0]?.url });
|
|
380
|
+
}
|
|
381
|
+
subtotal = Math.round(subtotal * 100) / 100;
|
|
382
|
+
let shippingTotal = Math.max(input.shippingTotal ?? 0, 0);
|
|
383
|
+
let discountTotal = 0;
|
|
384
|
+
let appliedCode;
|
|
385
|
+
if (input.discountCode) {
|
|
386
|
+
const code = input.discountCode.trim().toLowerCase();
|
|
387
|
+
const discount = (await this.listDiscounts()).find((d) => (d.code ?? "").toLowerCase() === code);
|
|
388
|
+
const ts = nowIso();
|
|
389
|
+
const valid = !!discount && discount.status === "active" && discount.startsAt <= ts && (!discount.endsAt || discount.endsAt >= ts) && (discount.usageLimit == null || discount.timesUsed < discount.usageLimit);
|
|
390
|
+
if (valid && discount) {
|
|
391
|
+
appliedCode = discount.code ?? void 0;
|
|
392
|
+
if (discount.type === "percentage") discountTotal = Math.round(subtotal * discount.value) / 100;
|
|
393
|
+
else if (discount.type === "fixed_amount") discountTotal = Math.min(discount.value, subtotal);
|
|
394
|
+
else if (discount.type === "free_shipping") shippingTotal = 0;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
discountTotal = Math.round(Math.min(Math.max(discountTotal, 0), subtotal) * 100) / 100;
|
|
398
|
+
return this.createOrder({
|
|
399
|
+
customerId: input.customerId,
|
|
400
|
+
customerName: input.customer?.name,
|
|
401
|
+
customerEmail: input.customer?.email,
|
|
402
|
+
currency: input.currency,
|
|
403
|
+
notes: input.notes,
|
|
404
|
+
discountCode: appliedCode,
|
|
405
|
+
discountTotal,
|
|
406
|
+
shippingTotal,
|
|
407
|
+
items: orderItems
|
|
408
|
+
});
|
|
409
|
+
},
|
|
364
410
|
async listCustomers(options2) {
|
|
365
411
|
const query = tenantQuery();
|
|
366
412
|
query.set("select", "*");
|
|
@@ -433,7 +479,185 @@ function createFayzShopProvider(options) {
|
|
|
433
479
|
}
|
|
434
480
|
};
|
|
435
481
|
}
|
|
482
|
+
function appendQuery(url, values) {
|
|
483
|
+
const query = new URLSearchParams();
|
|
484
|
+
for (const [key, value] of Object.entries(values)) {
|
|
485
|
+
if (value !== void 0) query.set(key, String(value));
|
|
486
|
+
}
|
|
487
|
+
const serialized = query.toString();
|
|
488
|
+
return serialized ? `${url}?${serialized}` : url;
|
|
489
|
+
}
|
|
490
|
+
function normalizeBrokerProduct(product, overlay) {
|
|
491
|
+
const category = product.category && typeof product.category === "object" ? product.category : null;
|
|
492
|
+
const row = {
|
|
493
|
+
id: product.id,
|
|
494
|
+
tenant_id: product.tenantId,
|
|
495
|
+
name: product.name,
|
|
496
|
+
slug: product.slug,
|
|
497
|
+
description: product.description,
|
|
498
|
+
price: product.price,
|
|
499
|
+
compare_at_price: product.compareAtPrice,
|
|
500
|
+
currency: product.currency,
|
|
501
|
+
status: product.status,
|
|
502
|
+
inventory_count: product.inventoryCount,
|
|
503
|
+
sku: product.sku,
|
|
504
|
+
sort_order: product.sortOrder,
|
|
505
|
+
metadata: product.metadata,
|
|
506
|
+
images: Array.isArray(product.images) ? product.images.map((image) => {
|
|
507
|
+
const row2 = image;
|
|
508
|
+
return {
|
|
509
|
+
id: String(row2.id ?? ""),
|
|
510
|
+
product_id: String(row2.productId ?? product.id ?? ""),
|
|
511
|
+
url: String(row2.url ?? ""),
|
|
512
|
+
alt_text: row2.altText ?? null,
|
|
513
|
+
sort_order: row2.sortOrder ?? 0,
|
|
514
|
+
is_primary: row2.isPrimary ?? false,
|
|
515
|
+
created_at: row2.createdAt ?? null
|
|
516
|
+
};
|
|
517
|
+
}) : [],
|
|
518
|
+
category_id: product.categoryId ?? category?.id,
|
|
519
|
+
category: category ? { name: category.name } : null,
|
|
520
|
+
is_physical: product.isPhysical,
|
|
521
|
+
weight: product.weight,
|
|
522
|
+
weight_unit: product.weightUnit,
|
|
523
|
+
created_at: product.createdAt,
|
|
524
|
+
updated_at: product.updatedAt
|
|
525
|
+
};
|
|
526
|
+
return rowToProduct(row, overlay);
|
|
527
|
+
}
|
|
528
|
+
function normalizeBrokerCategory(category) {
|
|
529
|
+
return {
|
|
530
|
+
id: category.id,
|
|
531
|
+
tenantId: category.tenantId ?? "global",
|
|
532
|
+
name: category.name,
|
|
533
|
+
slug: category.slug ?? slugify(category.name),
|
|
534
|
+
description: category.description ?? null,
|
|
535
|
+
parentId: category.parentId ?? null,
|
|
536
|
+
sortOrder: category.sortOrder ?? 0,
|
|
537
|
+
imageUrl: category.imageUrl ?? null,
|
|
538
|
+
createdAt: category.createdAt ?? nowIso()
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function createBrokerShopProvider(options) {
|
|
542
|
+
if (!options.apiBaseUrl || !options.projectId) {
|
|
543
|
+
throw new FayzShopError("Fayz Shop broker mode requires apiBaseUrl and projectId.", 400);
|
|
544
|
+
}
|
|
545
|
+
const fetcher = options.fetcher ?? fetch;
|
|
546
|
+
const apiBaseUrl = normalizeBaseUrl(options.apiBaseUrl);
|
|
547
|
+
const projectId = encodeURIComponent(options.projectId);
|
|
548
|
+
const productMetadataOverlay = buildProductMetadataOverlay(options.productMetadata);
|
|
549
|
+
async function request(path, init = {}) {
|
|
550
|
+
const response = await fetcher(`${apiBaseUrl}/public/projects/${projectId}/shop${path}`, init);
|
|
551
|
+
const text = await response.text();
|
|
552
|
+
let body;
|
|
553
|
+
try {
|
|
554
|
+
body = text ? JSON.parse(text) : void 0;
|
|
555
|
+
} catch {
|
|
556
|
+
body = text;
|
|
557
|
+
}
|
|
558
|
+
if (!response.ok) {
|
|
559
|
+
const message = typeof body === "object" && body ? String(body.message ?? body.error ?? `Fayz Shop broker request failed with status ${response.status}`) : `Fayz Shop broker request failed with status ${response.status}`;
|
|
560
|
+
throw new FayzShopError(message, response.status, body);
|
|
561
|
+
}
|
|
562
|
+
return body;
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
async listProducts(options2) {
|
|
566
|
+
if (options2?.slug) {
|
|
567
|
+
const product = await this.getProduct(options2.slug);
|
|
568
|
+
return product ? [product] : [];
|
|
569
|
+
}
|
|
570
|
+
const response = await request(appendQuery("/products", {
|
|
571
|
+
status: options2?.status,
|
|
572
|
+
categoryId: options2?.categoryId,
|
|
573
|
+
search: options2?.search,
|
|
574
|
+
limit: options2?.limit,
|
|
575
|
+
offset: options2?.offset,
|
|
576
|
+
orderBy: options2?.orderBy,
|
|
577
|
+
order: options2?.order
|
|
578
|
+
}));
|
|
579
|
+
return (response.products ?? []).map((product) => normalizeBrokerProduct(product, productMetadataOverlay));
|
|
580
|
+
},
|
|
581
|
+
async getProduct(id) {
|
|
582
|
+
const response = await request(`/products/${encodeURIComponent(id)}`);
|
|
583
|
+
return response.product ? normalizeBrokerProduct(response.product, productMetadataOverlay) : null;
|
|
584
|
+
},
|
|
585
|
+
async createProduct() {
|
|
586
|
+
throw new FayzShopError("Product writes require the Fayz admin/broker API.", 501);
|
|
587
|
+
},
|
|
588
|
+
async updateProduct() {
|
|
589
|
+
throw new FayzShopError("Product writes require the Fayz admin/broker API.", 501);
|
|
590
|
+
},
|
|
591
|
+
async deleteProduct() {
|
|
592
|
+
throw new FayzShopError("Product writes require the Fayz admin/broker API.", 501);
|
|
593
|
+
},
|
|
594
|
+
async uploadProductImage() {
|
|
595
|
+
throw new FayzShopError("Product image uploads require the Fayz admin/broker API.", 501);
|
|
596
|
+
},
|
|
597
|
+
async deleteProductImage() {
|
|
598
|
+
throw new FayzShopError("Product image deletes require the Fayz admin/broker API.", 501);
|
|
599
|
+
},
|
|
600
|
+
async listCategories() {
|
|
601
|
+
const response = await request("/categories");
|
|
602
|
+
return (response.categories ?? []).map(normalizeBrokerCategory);
|
|
603
|
+
},
|
|
604
|
+
async createCategory() {
|
|
605
|
+
throw new FayzShopError("Category writes require the Fayz admin/broker API.", 501);
|
|
606
|
+
},
|
|
607
|
+
async updateCategory() {
|
|
608
|
+
throw new FayzShopError("Category writes require the Fayz admin/broker API.", 501);
|
|
609
|
+
},
|
|
610
|
+
async deleteCategory() {
|
|
611
|
+
throw new FayzShopError("Category deletes require the Fayz admin/broker API.", 501);
|
|
612
|
+
},
|
|
613
|
+
async listOrders() {
|
|
614
|
+
throw new FayzShopError("Order reads require the Fayz admin/broker API.", 501);
|
|
615
|
+
},
|
|
616
|
+
async getOrder() {
|
|
617
|
+
throw new FayzShopError("Order reads require the Fayz admin/broker API.", 501);
|
|
618
|
+
},
|
|
619
|
+
async createOrder() {
|
|
620
|
+
throw new FayzShopError("Order writes require the Fayz admin/broker API.", 501);
|
|
621
|
+
},
|
|
622
|
+
async updateOrder() {
|
|
623
|
+
throw new FayzShopError("Order writes require the Fayz admin/broker API.", 501);
|
|
624
|
+
},
|
|
625
|
+
async placeOrder() {
|
|
626
|
+
throw new FayzShopError("Order placement requires the Fayz admin/broker API.", 501);
|
|
627
|
+
},
|
|
628
|
+
async listCustomers() {
|
|
629
|
+
throw new FayzShopError("Customer reads require the Fayz admin/broker API.", 501);
|
|
630
|
+
},
|
|
631
|
+
async getCustomer() {
|
|
632
|
+
throw new FayzShopError("Customer reads require the Fayz admin/broker API.", 501);
|
|
633
|
+
},
|
|
634
|
+
async createCustomer() {
|
|
635
|
+
throw new FayzShopError("Customer writes require the Fayz admin/broker API.", 501);
|
|
636
|
+
},
|
|
637
|
+
async updateCustomer() {
|
|
638
|
+
throw new FayzShopError("Customer writes require the Fayz admin/broker API.", 501);
|
|
639
|
+
},
|
|
640
|
+
async deleteCustomer() {
|
|
641
|
+
throw new FayzShopError("Customer writes require the Fayz admin/broker API.", 501);
|
|
642
|
+
},
|
|
643
|
+
async listDiscounts() {
|
|
644
|
+
throw new FayzShopError("Discount reads require the Fayz admin/broker API.", 501);
|
|
645
|
+
},
|
|
646
|
+
async getDiscount() {
|
|
647
|
+
throw new FayzShopError("Discount reads require the Fayz admin/broker API.", 501);
|
|
648
|
+
},
|
|
649
|
+
async createDiscount() {
|
|
650
|
+
throw new FayzShopError("Discount writes require the Fayz admin/broker API.", 501);
|
|
651
|
+
},
|
|
652
|
+
async updateDiscount() {
|
|
653
|
+
throw new FayzShopError("Discount writes require the Fayz admin/broker API.", 501);
|
|
654
|
+
},
|
|
655
|
+
async deleteDiscount() {
|
|
656
|
+
throw new FayzShopError("Discount deletes require the Fayz admin/broker API.", 501);
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
}
|
|
436
660
|
|
|
437
661
|
export { FayzShopError, createFayzShopProvider };
|
|
438
|
-
//# sourceMappingURL=chunk-
|
|
439
|
-
//# sourceMappingURL=chunk-
|
|
662
|
+
//# sourceMappingURL=chunk-6JDIFOJG.js.map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AAA,MAAM,IAAI,aAAA,CAAc,oDAAA,EAAsD,GAAG,CAAA;AAAA,IACnF,CAAA;AAAA,IACA,MAAM,cAAA,GAAiB;AACrB,MAAA,MAAM,IAAI,aAAA,CAAc,qDAAA,EAAuD,GAAG,CAAA;AAAA,IACpF;AAAA,GACF;AACF","file":"chunk-6JDIFOJG.js","sourcesContent":["export interface FayzShopProviderOptions {\n supabaseUrl?: string\n publishableKey?: string\n storeId?: string\n apiBaseUrl?: string\n projectId?: string\n mode?: 'broker' | 'supabase'\n productMetadata?: FayzShopProductMetadataOverlay[]\n fetcher?: typeof fetch\n}\n\nexport interface FayzShopProductMetadataOverlay {\n sku?: string | null\n slug?: string | null\n metadata: Record<string, unknown>\n}\n\nexport type FayzShopProductStatus = 'draft' | 'active' | 'archived'\nexport type FayzShopOrderStatus = 'open' | 'archived' | 'cancelled'\nexport type FayzShopFinancialStatus = 'pending' | 'paid' | 'partially_paid' | 'refunded' | 'partially_refunded' | 'voided'\nexport type FayzShopFulfillmentStatus = 'unfulfilled' | 'partially_fulfilled' | 'fulfilled'\n\nexport interface FayzShopListProductsOptions {\n status?: FayzShopProductStatus\n categoryId?: string\n search?: string\n slug?: string\n limit?: number\n offset?: number\n orderBy?: 'name' | 'price' | 'created_at' | 'sort_order'\n order?: 'asc' | 'desc'\n}\n\nexport interface FayzShopListOrdersOptions {\n status?: FayzShopOrderStatus\n financialStatus?: FayzShopFinancialStatus\n fulfillmentStatus?: FayzShopFulfillmentStatus\n customerId?: string\n customerEmail?: string\n search?: string\n limit?: number\n offset?: number\n}\n\nexport interface FayzShopListCustomersOptions {\n search?: string\n limit?: number\n offset?: number\n}\n\nexport interface FayzShopListDiscountsOptions {\n status?: string\n type?: string\n search?: string\n limit?: number\n offset?: number\n}\n\ninterface ProductImageRow {\n id: string\n product_id: string\n url: string\n alt_text?: string | null\n sort_order?: number | null\n is_primary?: boolean | null\n created_at?: string | null\n}\n\ninterface ProductRow {\n id: string\n tenant_id: string\n name: string\n slug?: string | null\n description?: string | null\n price?: number | null\n compare_at_price?: number | null\n currency?: string | null\n status?: FayzShopProductStatus | null\n inventory_count?: number | null\n sku?: string | null\n sort_order?: number | null\n metadata?: Record<string, unknown> | null\n images?: ProductImageRow[] | null\n category_id?: string | null\n category?: { name?: string | null } | null\n is_physical?: boolean | null\n weight?: number | null\n weight_unit?: string | null\n created_at?: string | null\n updated_at?: string | null\n}\n\ninterface StoreCategoryMetadata {\n id?: string | null\n name?: string | null\n slug?: string | null\n description?: string | null\n imageUrl?: string | null\n sortOrder?: number | null\n}\n\ninterface CategoryRow {\n id: string\n tenant_id?: string | null\n name: string\n slug?: string | null\n description?: string | null\n parent_id?: string | null\n sort_order?: number | null\n image_url?: string | null\n created_at?: string | null\n}\n\ninterface OrderItemRow {\n id: string\n order_id: string\n product_id?: string | null\n name: string\n sku?: string | null\n quantity?: number | null\n unit_price?: number | null\n total?: number | null\n image_url?: string | null\n}\n\ninterface OrderRow {\n id: string\n tenant_id: string\n order_number?: number | null\n status?: FayzShopOrderStatus | null\n financial_status?: FayzShopFinancialStatus | null\n fulfillment_status?: FayzShopFulfillmentStatus | null\n currency?: string | null\n subtotal?: number | null\n tax_total?: number | null\n discount_total?: number | null\n shipping_total?: number | null\n total?: number | null\n customer_id?: string | null\n customer_name?: string | null\n customer_email?: string | null\n discount_code?: string | null\n notes?: string | null\n items?: OrderItemRow[] | null\n created_at?: string | null\n updated_at?: string | null\n}\n\ninterface CustomerRow {\n id: string\n tenant_id: string\n first_name: string\n last_name?: string | null\n email?: string | null\n phone?: string | null\n notes?: string | null\n orders_count?: number | null\n total_spent?: number | null\n created_at?: string | null\n updated_at?: string | null\n}\n\ninterface DiscountRow {\n id: string\n tenant_id: string\n title: string\n code?: string | null\n type: string\n method?: string | null\n value?: number | null\n usage_limit?: number | null\n once_per_customer?: boolean | null\n starts_at?: string | null\n ends_at?: string | null\n status?: string | null\n times_used?: number | null\n created_at?: string | null\n updated_at?: string | null\n}\n\nexport class FayzShopError extends Error {\n constructor(\n message: string,\n readonly status: number,\n readonly responseBody?: unknown,\n ) {\n super(message)\n this.name = 'FayzShopError'\n }\n}\n\nfunction normalizeBaseUrl(url: string): string {\n return url.replace(/\\/+$/, '')\n}\n\nfunction slugify(name: string): string {\n return name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')\n}\n\nfunction nowIso(): string {\n return new Date().toISOString()\n}\n\nfunction present<T>(value: T | null | undefined, fallback: T): T {\n return value == null ? fallback : value\n}\n\nfunction productMetadataKey(kind: 'sku' | 'slug', value: string): string {\n return `${kind}:${value.toLowerCase()}`\n}\n\nfunction buildProductMetadataOverlay(overlays: FayzShopProductMetadataOverlay[] | undefined) {\n const map = new Map<string, Record<string, unknown>>()\n for (const overlay of overlays ?? []) {\n if (overlay.sku) map.set(productMetadataKey('sku', overlay.sku), overlay.metadata)\n if (overlay.slug) map.set(productMetadataKey('slug', overlay.slug), overlay.metadata)\n }\n return map\n}\n\nfunction asUuid(value: string | null | undefined): string | null {\n if (!value) return null\n return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)\n ? value\n : null\n}\n\nfunction rowToImage(row: ProductImageRow) {\n return {\n id: row.id,\n productId: row.product_id,\n url: row.url,\n altText: row.alt_text ?? null,\n sortOrder: row.sort_order ?? 0,\n isPrimary: row.is_primary ?? false,\n createdAt: row.created_at ?? nowIso(),\n }\n}\n\nfunction getProductMetadata(row: ProductRow, overlay?: Map<string, Record<string, unknown>>): Record<string, unknown> {\n const metadata = row.metadata ?? {}\n const bySlug = overlay?.get(productMetadataKey('slug', row.slug ?? slugify(row.name)))\n const bySku = row.sku ? overlay?.get(productMetadataKey('sku', row.sku)) : undefined\n return { ...(bySlug ?? {}), ...(bySku ?? {}), ...metadata }\n}\n\nfunction getStoreCategory(row: ProductRow, overlay?: Map<string, Record<string, unknown>>): StoreCategoryMetadata | null {\n const raw = getProductMetadata(row, overlay).fayzStoreCategory\n return raw && typeof raw === 'object' ? raw as StoreCategoryMetadata : null\n}\n\nfunction rowToProduct(row: ProductRow, overlay?: Map<string, Record<string, unknown>>) {\n const metadata = getProductMetadata(row, overlay)\n const storeCategory = getStoreCategory(row, overlay)\n return {\n id: row.id,\n tenantId: row.tenant_id,\n name: row.name,\n slug: row.slug ?? slugify(row.name),\n description: row.description ?? null,\n price: row.price ?? 0,\n compareAtPrice: row.compare_at_price ?? null,\n currency: row.currency ?? 'BRL',\n status: row.status ?? 'active',\n inventoryCount: row.inventory_count ?? 0,\n sku: row.sku ?? null,\n sortOrder: row.sort_order ?? 0,\n metadata,\n images: Array.isArray(row.images) ? row.images.map(rowToImage) : [],\n categoryId: storeCategory?.id ?? row.category_id ?? null,\n categoryName: storeCategory?.name ?? row.category?.name ?? null,\n isPhysical: row.is_physical ?? true,\n weight: row.weight ?? null,\n weightUnit: row.weight_unit ?? 'kg',\n createdAt: row.created_at ?? nowIso(),\n updatedAt: row.updated_at ?? row.created_at ?? nowIso(),\n }\n}\n\nfunction rowToCategory(row: CategoryRow) {\n return {\n id: row.id,\n tenantId: row.tenant_id ?? 'global',\n name: row.name,\n slug: row.slug ?? slugify(row.name),\n description: row.description ?? null,\n parentId: row.parent_id ?? null,\n sortOrder: row.sort_order ?? 0,\n imageUrl: row.image_url ?? null,\n createdAt: row.created_at ?? nowIso(),\n }\n}\n\nfunction storeCategoryToCategory(category: StoreCategoryMetadata, tenantId: string) {\n const name = category.name ?? 'Category'\n return {\n id: category.id ?? slugify(name),\n tenantId,\n name,\n slug: category.slug ?? slugify(name),\n description: category.description ?? null,\n parentId: null,\n sortOrder: category.sortOrder ?? 0,\n imageUrl: category.imageUrl ?? null,\n createdAt: nowIso(),\n }\n}\n\nfunction deriveStoreCategories(products: ProductRow[], tenantId: string) {\n const categories = new Map<string, ReturnType<typeof storeCategoryToCategory>>()\n for (const product of products) {\n const category = getStoreCategory(product)\n if (!category?.name && !category?.id) continue\n const mapped = storeCategoryToCategory(category, tenantId)\n categories.set(mapped.id, mapped)\n }\n return [...categories.values()].sort((a, b) => a.sortOrder - b.sortOrder || a.name.localeCompare(b.name))\n}\n\nfunction rowToOrder(row: OrderRow) {\n return {\n id: row.id,\n tenantId: row.tenant_id,\n orderNumber: row.order_number ?? 0,\n status: row.status ?? 'open',\n financialStatus: row.financial_status ?? 'pending',\n fulfillmentStatus: row.fulfillment_status ?? 'unfulfilled',\n currency: row.currency ?? 'BRL',\n subtotal: row.subtotal ?? 0,\n taxTotal: row.tax_total ?? 0,\n discountTotal: row.discount_total ?? 0,\n shippingTotal: row.shipping_total ?? 0,\n total: row.total ?? 0,\n customerId: row.customer_id ?? null,\n customerName: row.customer_name ?? null,\n customerEmail: row.customer_email ?? null,\n discountCode: row.discount_code ?? null,\n notes: row.notes ?? null,\n items: Array.isArray(row.items) ? row.items.map(rowToOrderItem) : [],\n createdAt: row.created_at ?? nowIso(),\n updatedAt: row.updated_at ?? row.created_at ?? nowIso(),\n }\n}\n\nfunction rowToOrderItem(row: OrderItemRow) {\n return {\n id: row.id,\n orderId: row.order_id,\n productId: row.product_id ?? null,\n name: row.name,\n sku: row.sku ?? null,\n quantity: row.quantity ?? 0,\n unitPrice: row.unit_price ?? 0,\n total: row.total ?? 0,\n imageUrl: row.image_url ?? null,\n }\n}\n\nfunction rowToCustomer(row: CustomerRow) {\n return {\n id: row.id,\n tenantId: row.tenant_id,\n firstName: row.first_name,\n lastName: row.last_name ?? '',\n email: row.email ?? null,\n phone: row.phone ?? null,\n notes: row.notes ?? null,\n ordersCount: row.orders_count ?? 0,\n totalSpent: row.total_spent ?? 0,\n createdAt: row.created_at ?? nowIso(),\n updatedAt: row.updated_at ?? row.created_at ?? nowIso(),\n }\n}\n\nfunction rowToDiscount(row: DiscountRow) {\n return {\n id: row.id,\n tenantId: row.tenant_id,\n title: row.title,\n code: row.code ?? null,\n type: row.type,\n method: row.method ?? 'code',\n value: row.value ?? 0,\n usageLimit: row.usage_limit ?? null,\n oncePerCustomer: row.once_per_customer ?? false,\n startsAt: row.starts_at ?? nowIso(),\n endsAt: row.ends_at ?? null,\n status: row.status ?? 'active',\n timesUsed: row.times_used ?? 0,\n createdAt: row.created_at ?? nowIso(),\n updatedAt: row.updated_at ?? row.created_at ?? nowIso(),\n }\n}\n\nfunction updateOrderPayload(input: {\n status?: FayzShopOrderStatus\n financialStatus?: FayzShopFinancialStatus\n fulfillmentStatus?: FayzShopFulfillmentStatus\n notes?: string\n}) {\n const updates: Record<string, unknown> = {}\n if (input.status !== undefined) updates.status = input.status\n if (input.financialStatus !== undefined) updates.financial_status = input.financialStatus\n if (input.fulfillmentStatus !== undefined) updates.fulfillment_status = input.fulfillmentStatus\n if (input.notes !== undefined) updates.notes = input.notes\n return updates\n}\n\nexport function createFayzShopProvider(options: FayzShopProviderOptions) {\n if (options.mode === 'broker' || options.apiBaseUrl || options.projectId) {\n return createBrokerShopProvider(options)\n }\n\n if (!options.supabaseUrl || !options.publishableKey || !options.storeId) {\n throw new FayzShopError('Fayz Shop provider requires either broker apiBaseUrl/projectId or legacy supabaseUrl/publishableKey/storeId.', 400)\n }\n\n const baseUrl = `${normalizeBaseUrl(options.supabaseUrl)}/rest/v1`\n const fetcher = options.fetcher ?? fetch\n const key = options.publishableKey\n const storeId = options.storeId\n const productMetadataOverlay = buildProductMetadataOverlay(options.productMetadata)\n\n async function request<T>(table: string, init: RequestInit & { query?: URLSearchParams } = {}): Promise<T> {\n const query = init.query?.toString()\n const response = await fetcher(`${baseUrl}/${table}${query ? `?${query}` : ''}`, {\n ...init,\n headers: {\n apikey: key,\n Authorization: `Bearer ${key}`,\n ...(init.body ? { 'Content-Type': 'application/json', Prefer: 'return=representation' } : {}),\n ...init.headers,\n },\n })\n const text = await response.text()\n let body: unknown\n try {\n body = text ? JSON.parse(text) : undefined\n } catch {\n body = text\n }\n if (!response.ok) {\n const message = typeof body === 'object' && body\n ? String((body as { message?: unknown; error?: unknown }).message ?? (body as { error?: unknown }).error ?? `Fayz Shop request failed with status ${response.status}`)\n : `Fayz Shop request failed with status ${response.status}`\n throw new FayzShopError(message, response.status, body)\n }\n return body as T\n }\n\n const tenantQuery = () => {\n const query = new URLSearchParams()\n query.set('tenant_id', `eq.${storeId}`)\n return query\n }\n\n const singleById = (id: string) => {\n const query = tenantQuery()\n query.set('id', `eq.${id}`)\n query.set('limit', '1')\n return query\n }\n\n return {\n async listProducts(options?: FayzShopListProductsOptions) {\n const query = tenantQuery()\n query.set('select', '*,images:product_images(*),category:categories(name)')\n if (options?.status) query.set('status', `eq.${options.status}`)\n if (options?.slug) query.set('slug', `eq.${options.slug}`)\n if (options?.search) query.set('name', `ilike.*${options.search}*`)\n query.set('order', `${options?.orderBy ?? 'sort_order'}.${options?.order ?? 'asc'}`)\n if (options?.limit) query.set('limit', String(options.limit))\n if (options?.offset) query.set('offset', String(options.offset))\n const products = (await request<ProductRow[]>('products', { query })).map((row) => rowToProduct(row, productMetadataOverlay))\n return options?.categoryId ? products.filter((product) => product.categoryId === options.categoryId) : products\n },\n async getProduct(id: string) {\n const query = singleById(id)\n query.set('select', '*,images:product_images(*),category:categories(name)')\n const rows = await request<ProductRow[]>('products', { query })\n return rows[0] ? rowToProduct(rows[0], productMetadataOverlay) : null\n },\n async createProduct() {\n throw new FayzShopError('Product writes require the Fayz admin/broker API.', 501)\n },\n async updateProduct() {\n throw new FayzShopError('Product writes require the Fayz admin/broker API.', 501)\n },\n async deleteProduct() {\n throw new FayzShopError('Product writes require the Fayz admin/broker API.', 501)\n },\n async uploadProductImage() {\n throw new FayzShopError('Product image uploads require the Fayz admin/broker API.', 501)\n },\n async deleteProductImage() {\n throw new FayzShopError('Product image deletes require the Fayz admin/broker API.', 501)\n },\n async listCategories() {\n const productQuery = tenantQuery()\n productQuery.set('select', 'metadata')\n productQuery.set('order', 'sort_order.asc')\n const products = await request<ProductRow[]>('products', { query: productQuery })\n const storeCategories = deriveStoreCategories(products, storeId)\n if (storeCategories.length > 0) return storeCategories\n\n const query = new URLSearchParams()\n query.set('select', '*')\n query.set('order', 'sort_order.asc')\n return (await request<CategoryRow[]>('categories', { query })).map(rowToCategory)\n },\n async createCategory() {\n throw new FayzShopError('Category writes require the Fayz admin/broker API.', 501)\n },\n async updateCategory() {\n throw new FayzShopError('Category writes require the Fayz admin/broker API.', 501)\n },\n async deleteCategory() {\n throw new FayzShopError('Category deletes require the Fayz admin/broker API.', 501)\n },\n async listOrders(options?: FayzShopListOrdersOptions) {\n const query = tenantQuery()\n query.set('select', '*,items:order_items(*)')\n if (options?.status) query.set('status', `eq.${options.status}`)\n if (options?.financialStatus) query.set('financial_status', `eq.${options.financialStatus}`)\n if (options?.fulfillmentStatus) query.set('fulfillment_status', `eq.${options.fulfillmentStatus}`)\n if (options?.customerId) query.set('customer_id', `eq.${options.customerId}`)\n if (options?.customerEmail) query.set('customer_email', `eq.${options.customerEmail}`)\n if (options?.search) query.set('or', `(customer_name.ilike.*${options.search}*,customer_email.ilike.*${options.search}*)`)\n query.set('order', 'created_at.desc')\n if (options?.limit) query.set('limit', String(options.limit))\n if (options?.offset) query.set('offset', String(options.offset))\n return (await request<OrderRow[]>('orders', { query })).map(rowToOrder)\n },\n async getOrder(id: string) {\n const query = singleById(id)\n query.set('select', '*,items:order_items(*)')\n const rows = await request<OrderRow[]>('orders', { query })\n return rows[0] ? rowToOrder(rows[0]) : null\n },\n async createOrder(input: {\n customerId?: string\n customerName?: string\n customerEmail?: string\n currency?: string\n notes?: string\n discountCode?: string\n discountTotal?: number\n shippingTotal?: number\n items: Array<{ productId?: string; name: string; sku?: string; quantity: number; unitPrice: number; imageUrl?: string }>\n }) {\n const subtotal = input.items.reduce((sum, item) => sum + item.quantity * item.unitPrice, 0)\n const discountTotal = input.discountTotal ?? 0\n const shippingTotal = input.shippingTotal ?? 0\n const total = Math.round((subtotal - discountTotal + shippingTotal) * 100) / 100\n const [order] = await request<OrderRow[]>('orders', {\n method: 'POST',\n body: JSON.stringify({\n tenant_id: storeId,\n customer_id: input.customerId ?? null,\n customer_name: input.customerName ?? null,\n customer_email: input.customerEmail ?? null,\n currency: input.currency ?? 'BRL',\n notes: input.notes ?? null,\n subtotal,\n discount_total: discountTotal,\n shipping_total: shippingTotal,\n discount_code: input.discountCode ?? null,\n total,\n status: 'open',\n financial_status: 'pending',\n fulfillment_status: 'unfulfilled',\n }),\n })\n if (!order) throw new FayzShopError('Order insert did not return a row.', 500)\n if (input.items.length) {\n await request<OrderItemRow[]>('order_items', {\n method: 'POST',\n body: JSON.stringify(input.items.map((item) => ({\n order_id: order.id,\n product_id: asUuid(item.productId),\n name: item.name,\n sku: item.sku ?? null,\n quantity: item.quantity,\n unit_price: item.unitPrice,\n total: item.quantity * item.unitPrice,\n image_url: item.imageUrl ?? null,\n }))),\n })\n }\n return this.getOrder(order.id)\n },\n async updateOrder(id: string, input: Parameters<typeof updateOrderPayload>[0]) {\n await request<OrderRow[]>('orders', {\n method: 'PATCH',\n query: singleById(id),\n body: JSON.stringify(updateOrderPayload(input)),\n })\n return this.getOrder(id)\n },\n async placeOrder(input: {\n tenantId?: string\n customerId?: string\n customer?: { name?: string; email?: string }\n currency?: string\n notes?: string\n discountCode?: string\n shippingTotal?: number\n items: Array<{ productId: string; quantity: number; optionsLabel?: string }>\n }) {\n // Trusted placement over the legacy REST path: re-read prices from the\n // catalog so the browser can never set what it pays.\n const orderItems: Array<{ productId?: string; name: string; sku?: string; quantity: number; unitPrice: number; imageUrl?: string }> = []\n let subtotal = 0\n for (const line of input.items) {\n const product = await this.getProduct(line.productId)\n if (!product || product.status !== 'active') throw new FayzShopError(`Product unavailable: ${line.productId}`, 409)\n if (product.inventoryCount < line.quantity) throw new FayzShopError(`Insufficient stock for ${product.name}`, 409)\n const name = line.optionsLabel ? `${product.name} (${line.optionsLabel})` : product.name\n subtotal += product.price * line.quantity\n orderItems.push({ productId: product.id, name, sku: product.sku ?? undefined, quantity: line.quantity, unitPrice: product.price, imageUrl: product.images[0]?.url })\n }\n subtotal = Math.round(subtotal * 100) / 100\n\n let shippingTotal = Math.max(input.shippingTotal ?? 0, 0)\n let discountTotal = 0\n let appliedCode: string | undefined\n if (input.discountCode) {\n const code = input.discountCode.trim().toLowerCase()\n const discount = (await this.listDiscounts()).find((d) => (d.code ?? '').toLowerCase() === code)\n const ts = nowIso()\n const valid = !!discount && discount.status === 'active' && discount.startsAt <= ts\n && (!discount.endsAt || discount.endsAt >= ts)\n && (discount.usageLimit == null || discount.timesUsed < discount.usageLimit)\n if (valid && discount) {\n appliedCode = discount.code ?? undefined\n if (discount.type === 'percentage') discountTotal = Math.round(subtotal * discount.value) / 100\n else if (discount.type === 'fixed_amount') discountTotal = Math.min(discount.value, subtotal)\n else if (discount.type === 'free_shipping') shippingTotal = 0\n }\n }\n discountTotal = Math.round(Math.min(Math.max(discountTotal, 0), subtotal) * 100) / 100\n\n return this.createOrder({\n customerId: input.customerId,\n customerName: input.customer?.name,\n customerEmail: input.customer?.email,\n currency: input.currency,\n notes: input.notes,\n discountCode: appliedCode,\n discountTotal,\n shippingTotal,\n items: orderItems,\n })\n },\n async listCustomers(options?: FayzShopListCustomersOptions) {\n const query = tenantQuery()\n query.set('select', '*')\n query.set('order', 'first_name.asc')\n if (options?.search) query.set('or', `(first_name.ilike.*${options.search}*,last_name.ilike.*${options.search}*,email.ilike.*${options.search}*)`)\n if (options?.limit) query.set('limit', String(options.limit))\n if (options?.offset) query.set('offset', String(options.offset))\n return (await request<CustomerRow[]>('customers', { query })).map(rowToCustomer)\n },\n async getCustomer(id: string) {\n const rows = await request<CustomerRow[]>('customers', { query: singleById(id) })\n return rows[0] ? rowToCustomer(rows[0]) : null\n },\n async createCustomer(input: { firstName: string; lastName?: string; email?: string; phone?: string; notes?: string }) {\n const [customer] = await request<CustomerRow[]>('customers', {\n method: 'POST',\n body: JSON.stringify({\n tenant_id: storeId,\n first_name: input.firstName,\n last_name: input.lastName ?? '',\n email: input.email ?? null,\n phone: input.phone ?? null,\n notes: input.notes ?? null,\n }),\n })\n if (!customer) throw new FayzShopError('Customer insert did not return a row.', 500)\n return rowToCustomer(customer)\n },\n async updateCustomer(id: string, input: { firstName?: string; lastName?: string; email?: string | null; phone?: string | null; notes?: string | null }) {\n const updates: Record<string, unknown> = {}\n if (input.firstName !== undefined) updates.first_name = input.firstName\n if (input.lastName !== undefined) updates.last_name = input.lastName\n if (input.email !== undefined) updates.email = input.email\n if (input.phone !== undefined) updates.phone = input.phone\n if (input.notes !== undefined) updates.notes = input.notes\n const [customer] = await request<CustomerRow[]>('customers', {\n method: 'PATCH',\n query: singleById(id),\n body: JSON.stringify(updates),\n })\n if (!customer) throw new FayzShopError('Customer update did not return a row.', 500)\n return rowToCustomer(customer)\n },\n async deleteCustomer(id: string) {\n await request<unknown>('customers', { method: 'DELETE', query: singleById(id) })\n },\n async listDiscounts(options?: FayzShopListDiscountsOptions) {\n const query = tenantQuery()\n query.set('select', '*')\n query.set('order', 'created_at.desc')\n if (options?.status) query.set('status', `eq.${options.status}`)\n if (options?.type) query.set('type', `eq.${options.type}`)\n if (options?.search) query.set('title', `ilike.*${options.search}*`)\n if (options?.limit) query.set('limit', String(options.limit))\n if (options?.offset) query.set('offset', String(options.offset))\n return (await request<DiscountRow[]>('discounts', { query })).map(rowToDiscount)\n },\n async getDiscount(id: string) {\n const rows = await request<DiscountRow[]>('discounts', { query: singleById(id) })\n return rows[0] ? rowToDiscount(rows[0]) : null\n },\n async createDiscount() {\n throw new FayzShopError('Discount writes require the Fayz admin/broker API.', 501)\n },\n async updateDiscount() {\n throw new FayzShopError('Discount writes require the Fayz admin/broker API.', 501)\n },\n async deleteDiscount() {\n throw new FayzShopError('Discount deletes require the Fayz admin/broker API.', 501)\n },\n }\n}\n\nfunction appendQuery(url: string, values: Record<string, string | number | undefined>): string {\n const query = new URLSearchParams()\n for (const [key, value] of Object.entries(values)) {\n if (value !== undefined) query.set(key, String(value))\n }\n const serialized = query.toString()\n return serialized ? `${url}?${serialized}` : url\n}\n\nfunction normalizeBrokerProduct(product: Record<string, unknown>, overlay?: Map<string, Record<string, unknown>>) {\n const category = product.category && typeof product.category === 'object'\n ? product.category as Record<string, unknown>\n : null\n const row = {\n id: product.id as string,\n tenant_id: product.tenantId as string,\n name: product.name as string,\n slug: product.slug as string | undefined,\n description: product.description as string | null | undefined,\n price: product.price as number | null | undefined,\n compare_at_price: product.compareAtPrice as number | null | undefined,\n currency: product.currency as string | null | undefined,\n status: product.status as FayzShopProductStatus | null | undefined,\n inventory_count: product.inventoryCount as number | null | undefined,\n sku: product.sku as string | null | undefined,\n sort_order: product.sortOrder as number | null | undefined,\n metadata: product.metadata as Record<string, unknown> | null | undefined,\n images: Array.isArray(product.images)\n ? product.images.map((image): ProductImageRow => {\n const row = image as Record<string, unknown>\n return {\n id: String(row.id ?? ''),\n product_id: String(row.productId ?? product.id ?? ''),\n url: String(row.url ?? ''),\n alt_text: (row.altText as string | null | undefined) ?? null,\n sort_order: (row.sortOrder as number | null | undefined) ?? 0,\n is_primary: (row.isPrimary as boolean | null | undefined) ?? false,\n created_at: (row.createdAt as string | null | undefined) ?? null,\n }\n })\n : [],\n category_id: (product.categoryId ?? category?.id) as string | null | undefined,\n category: category ? { name: category.name as string | null | undefined } : null,\n is_physical: product.isPhysical as boolean | null | undefined,\n weight: product.weight as number | null | undefined,\n weight_unit: product.weightUnit as string | null | undefined,\n created_at: product.createdAt as string | null | undefined,\n updated_at: product.updatedAt as string | null | undefined,\n } satisfies ProductRow\n return rowToProduct(row, overlay)\n}\n\nfunction normalizeBrokerCategory(category: Record<string, unknown>) {\n return {\n id: category.id as string,\n tenantId: (category.tenantId as string | undefined) ?? 'global',\n name: category.name as string,\n slug: (category.slug as string | undefined) ?? slugify(category.name as string),\n description: (category.description as string | null | undefined) ?? null,\n parentId: (category.parentId as string | null | undefined) ?? null,\n sortOrder: (category.sortOrder as number | null | undefined) ?? 0,\n imageUrl: (category.imageUrl as string | null | undefined) ?? null,\n createdAt: (category.createdAt as string | null | undefined) ?? nowIso(),\n }\n}\n\nfunction createBrokerShopProvider(options: FayzShopProviderOptions) {\n if (!options.apiBaseUrl || !options.projectId) {\n throw new FayzShopError('Fayz Shop broker mode requires apiBaseUrl and projectId.', 400)\n }\n\n const fetcher = options.fetcher ?? fetch\n const apiBaseUrl = normalizeBaseUrl(options.apiBaseUrl)\n const projectId = encodeURIComponent(options.projectId)\n const productMetadataOverlay = buildProductMetadataOverlay(options.productMetadata)\n\n async function request<T>(path: string, init: RequestInit = {}): Promise<T> {\n const response = await fetcher(`${apiBaseUrl}/public/projects/${projectId}/shop${path}`, init)\n const text = await response.text()\n let body: unknown\n try {\n body = text ? JSON.parse(text) : undefined\n } catch {\n body = text\n }\n if (!response.ok) {\n const message = typeof body === 'object' && body\n ? String((body as { message?: unknown; error?: unknown }).message ?? (body as { error?: unknown }).error ?? `Fayz Shop broker request failed with status ${response.status}`)\n : `Fayz Shop broker request failed with status ${response.status}`\n throw new FayzShopError(message, response.status, body)\n }\n return body as T\n }\n\n return {\n async listProducts(options?: FayzShopListProductsOptions) {\n if (options?.slug) {\n const product = await this.getProduct(options.slug)\n return product ? [product] : []\n }\n\n const response = await request<{ products?: Array<Record<string, unknown>> }>(appendQuery('/products', {\n status: options?.status,\n categoryId: options?.categoryId,\n search: options?.search,\n limit: options?.limit,\n offset: options?.offset,\n orderBy: options?.orderBy,\n order: options?.order,\n }))\n return (response.products ?? []).map((product) => normalizeBrokerProduct(product, productMetadataOverlay))\n },\n async getProduct(id: string) {\n const response = await request<{ product?: Record<string, unknown> | null }>(`/products/${encodeURIComponent(id)}`)\n return response.product ? normalizeBrokerProduct(response.product, productMetadataOverlay) : null\n },\n async createProduct() {\n throw new FayzShopError('Product writes require the Fayz admin/broker API.', 501)\n },\n async updateProduct() {\n throw new FayzShopError('Product writes require the Fayz admin/broker API.', 501)\n },\n async deleteProduct() {\n throw new FayzShopError('Product writes require the Fayz admin/broker API.', 501)\n },\n async uploadProductImage() {\n throw new FayzShopError('Product image uploads require the Fayz admin/broker API.', 501)\n },\n async deleteProductImage() {\n throw new FayzShopError('Product image deletes require the Fayz admin/broker API.', 501)\n },\n async listCategories() {\n const response = await request<{ categories?: Array<Record<string, unknown>> }>('/categories')\n return (response.categories ?? []).map(normalizeBrokerCategory)\n },\n async createCategory() {\n throw new FayzShopError('Category writes require the Fayz admin/broker API.', 501)\n },\n async updateCategory() {\n throw new FayzShopError('Category writes require the Fayz admin/broker API.', 501)\n },\n async deleteCategory() {\n throw new FayzShopError('Category deletes require the Fayz admin/broker API.', 501)\n },\n async listOrders() {\n throw new FayzShopError('Order reads require the Fayz admin/broker API.', 501)\n },\n async getOrder() {\n throw new FayzShopError('Order reads require the Fayz admin/broker API.', 501)\n },\n async createOrder() {\n throw new FayzShopError('Order writes require the Fayz admin/broker API.', 501)\n },\n async updateOrder() {\n throw new FayzShopError('Order writes require the Fayz admin/broker API.', 501)\n },\n async placeOrder() {\n throw new FayzShopError('Order placement requires the Fayz admin/broker API.', 501)\n },\n async listCustomers() {\n throw new FayzShopError('Customer reads require the Fayz admin/broker API.', 501)\n },\n async getCustomer() {\n throw new FayzShopError('Customer reads require the Fayz admin/broker API.', 501)\n },\n async createCustomer() {\n throw new FayzShopError('Customer writes require the Fayz admin/broker API.', 501)\n },\n async updateCustomer() {\n throw new FayzShopError('Customer writes require the Fayz admin/broker API.', 501)\n },\n async deleteCustomer() {\n throw new FayzShopError('Customer writes require the Fayz admin/broker API.', 501)\n },\n async listDiscounts() {\n throw new FayzShopError('Discount reads require the Fayz admin/broker API.', 501)\n },\n async getDiscount() {\n throw new FayzShopError('Discount reads require the Fayz admin/broker API.', 501)\n },\n async createDiscount() {\n throw new FayzShopError('Discount writes require the Fayz admin/broker API.', 501)\n },\n async updateDiscount() {\n throw new FayzShopError('Discount writes require the Fayz admin/broker API.', 501)\n },\n async deleteDiscount() {\n throw new FayzShopError('Discount deletes require the Fayz admin/broker API.', 501)\n },\n }\n}\n"]}
|