threeu-sdk 0.1.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/README.md +176 -0
- package/dist/admin/index.d.ts +22 -0
- package/dist/admin/index.js +17 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/chunk-2TGBSV6L.js +197 -0
- package/dist/chunk-2TGBSV6L.js.map +1 -0
- package/dist/chunk-6S7OFN23.js +81 -0
- package/dist/chunk-6S7OFN23.js.map +1 -0
- package/dist/chunk-6ZCBDWWQ.js +140 -0
- package/dist/chunk-6ZCBDWWQ.js.map +1 -0
- package/dist/chunk-BCUODRZW.js +78 -0
- package/dist/chunk-BCUODRZW.js.map +1 -0
- package/dist/chunk-H3XILKGI.js +70 -0
- package/dist/chunk-H3XILKGI.js.map +1 -0
- package/dist/chunk-HYSJ6YPN.js +425 -0
- package/dist/chunk-HYSJ6YPN.js.map +1 -0
- package/dist/chunk-LFF5LPWT.js +122 -0
- package/dist/chunk-LFF5LPWT.js.map +1 -0
- package/dist/chunk-OXAQGEMQ.js +3 -0
- package/dist/chunk-OXAQGEMQ.js.map +1 -0
- package/dist/chunk-USFJIM5K.js +195 -0
- package/dist/chunk-USFJIM5K.js.map +1 -0
- package/dist/chunk-ZWLFJIAM.js +69 -0
- package/dist/chunk-ZWLFJIAM.js.map +1 -0
- package/dist/define-B6ZJMWDI.d.ts +24 -0
- package/dist/developer/index.d.ts +120 -0
- package/dist/developer/index.js +106 -0
- package/dist/developer/index.js.map +1 -0
- package/dist/errors/index.d.ts +83 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index-ksmDFDZc.d.ts +90 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/index.d.ts +13 -0
- package/dist/plugin/index.js +27 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/server/index.d.ts +70 -0
- package/dist/plugin/server/index.js +105 -0
- package/dist/plugin/server/index.js.map +1 -0
- package/dist/pos/index.d.ts +26 -0
- package/dist/pos/index.js +24 -0
- package/dist/pos/index.js.map +1 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.js +7 -0
- package/dist/react/index.js.map +1 -0
- package/dist/session-BFDRm-KJ.d.ts +94 -0
- package/dist/storefront/index.d.ts +76 -0
- package/dist/storefront/index.js +6 -0
- package/dist/storefront/index.js.map +1 -0
- package/dist/testing/index.d.ts +82 -0
- package/dist/testing/index.js +106 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/theme/index.d.ts +109 -0
- package/dist/theme/index.js +152 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/threeu-BesFjXdw.d.ts +143 -0
- package/dist/types-BoGD3IXz.d.ts +173 -0
- package/dist/types-DfyYnoLn.d.ts +248 -0
- package/dist/webhooks/index.d.ts +36 -0
- package/dist/webhooks/index.js +4 -0
- package/dist/webhooks/index.js.map +1 -0
- package/package.json +110 -0
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# threeu-sdk
|
|
2
|
+
|
|
3
|
+
Official ThreeU developer SDK — a typed, tree-shakeable, fetch-based layer over the
|
|
4
|
+
ThreeU platform for **admin**, **POS**, **storefront**, **theme**, **plugin**, and
|
|
5
|
+
**developer** integrations.
|
|
6
|
+
|
|
7
|
+
> Status: **v0.1.0 (pre-release).** Built against ThreeU's live API. Backend-dependent
|
|
8
|
+
> features (developer manifest writes, telemetry ingestion, plugin health/delivery logs)
|
|
9
|
+
> are typed but ship as clearly-marked planned/experimental stubs that throw
|
|
10
|
+
> `ThreeuNotImplementedError` until the backend lands them — see
|
|
11
|
+
> [`docs/M8_BACKEND_PROPOSAL.md`](docs/M8_BACKEND_PROPOSAL.md). The original product brief
|
|
12
|
+
> is preserved in [`docs/BRIEF.md`](docs/BRIEF.md); build progress in
|
|
13
|
+
> [`docs/BUILD_LEDGER.md`](docs/BUILD_LEDGER.md); backend recon in
|
|
14
|
+
> [`docs/ARCHITECTURE_MAP.md`](docs/ARCHITECTURE_MAP.md).
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install threeu-sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
ESM-only, zero runtime dependencies. Node 18+, modern browsers, and edge runtimes.
|
|
23
|
+
`react` is an optional peer (only needed for `threeu-sdk/theme` and `/react`).
|
|
24
|
+
|
|
25
|
+
## Entry points
|
|
26
|
+
|
|
27
|
+
| Import | Use |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| `threeu-sdk` | core `Threeu` client + transport, errors, telemetry |
|
|
30
|
+
| `threeu-sdk/admin` | `ThreeuAdmin` — secret-token admin (server-side) |
|
|
31
|
+
| `threeu-sdk/pos` | `ThreeuPOS` — POS sessions/carts/checkout |
|
|
32
|
+
| `threeu-sdk/storefront` | `ThreeuStorefront` — public-token, browser-safe |
|
|
33
|
+
| `threeu-sdk/developer` | `ThreeuDeveloper` — developer.threeu.app API |
|
|
34
|
+
| `threeu-sdk/theme` | `createTheme`, `T*` components, hooks |
|
|
35
|
+
| `threeu-sdk/react` | React providers & hooks (no components) |
|
|
36
|
+
| `threeu-sdk/plugin` | `definePlugin`, `defineApp`, manifest types |
|
|
37
|
+
| `threeu-sdk/plugin/server` | remote plugin server helper (experimental) |
|
|
38
|
+
| `threeu-sdk/webhooks` | sign/verify webhook signatures |
|
|
39
|
+
| `threeu-sdk/errors` | typed error classes |
|
|
40
|
+
| `threeu-sdk/testing` | mock fetch + fixtures |
|
|
41
|
+
|
|
42
|
+
## Core usage
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { Threeu } from "threeu-sdk";
|
|
46
|
+
|
|
47
|
+
const threeu = new Threeu(process.env.THREEU_SECRET_KEY!);
|
|
48
|
+
const brand = threeu.brand("my-store");
|
|
49
|
+
|
|
50
|
+
await brand.products.create({ name: "Black Abaya", price: 350, currency: "QAR" });
|
|
51
|
+
const orders = await brand.orders.list({ status: "pending" });
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`brand(...)` returns a scoped object with `products`, `orders`, `customers`, `inventory`,
|
|
55
|
+
`collections`, `discounts`, `payments`, `shipping`, `locations`, `analytics`, `marketing`,
|
|
56
|
+
`theme`, and `pos`. Every call is scoped to the brand via the `platform-id` header.
|
|
57
|
+
|
|
58
|
+
### Admin / POS / storefront
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { ThreeuAdmin } from "threeu-sdk/admin";
|
|
62
|
+
import { ThreeuPOS } from "threeu-sdk/pos";
|
|
63
|
+
import { ThreeuStorefront } from "threeu-sdk/storefront";
|
|
64
|
+
|
|
65
|
+
const admin = new ThreeuAdmin(process.env.THREEU_SECRET_KEY!);
|
|
66
|
+
const pos = new ThreeuPOS(process.env.THREEU_POS_TOKEN!, { brand: "my-store" });
|
|
67
|
+
const storefront = new ThreeuStorefront({ publicToken: PUBLIC_KEY, brand: "my-store" });
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
See [`examples/`](examples) for end-to-end snippets of each.
|
|
71
|
+
|
|
72
|
+
## Themes (React)
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { createTheme, TSection, THeading, TColor } from "threeu-sdk/theme";
|
|
76
|
+
|
|
77
|
+
function HomePage() {
|
|
78
|
+
return (
|
|
79
|
+
<TSection name="home.hero">
|
|
80
|
+
<THeading name="home.hero.title">Welcome to our store</THeading>
|
|
81
|
+
<button style={{ backgroundColor: TColor("home.hero.buttonColor", "#000") }}>Shop now</button>
|
|
82
|
+
</TSection>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
export default createTheme({ name: "Modern Luxury", slug: "modern-luxury", pages: { home: HomePage } });
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Data/customization hooks (`useProducts`, `useCart`, `useTheme`, ...) require a
|
|
89
|
+
`<ThreeuThemeProvider>` / `<ThemeProvider>` ancestor.
|
|
90
|
+
|
|
91
|
+
## Plugins
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { definePlugin } from "threeu-sdk/plugin";
|
|
95
|
+
|
|
96
|
+
export default definePlugin({
|
|
97
|
+
name: "FastShip",
|
|
98
|
+
slug: "fastship",
|
|
99
|
+
category: "shipping",
|
|
100
|
+
permissions: ["orders:read", "shipping:write"],
|
|
101
|
+
provider: {
|
|
102
|
+
type: "remote_http",
|
|
103
|
+
baseUrl: "https://api.fastship.com/threeu",
|
|
104
|
+
healthPath: "/health",
|
|
105
|
+
actions: { "shipping.get_rates": { method: "POST", path: "/rates" } },
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`definePlugin` validates the definition and emits the normalized manifest JSON
|
|
111
|
+
(`.manifest`). Community developers declare `provider.type` only — the SDK never sets
|
|
112
|
+
the internal `provider_class`. Implement the hosted side with
|
|
113
|
+
`createThreeuPluginServer` (see `examples/plugin-server-fastship.ts`).
|
|
114
|
+
|
|
115
|
+
## Webhook verification
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { verifyWebhookSignature, verifyLegacyWebhook } from "threeu-sdk/webhooks";
|
|
119
|
+
|
|
120
|
+
// Target scheme: raw body + X-Plugin-Timestamp, with replay protection.
|
|
121
|
+
const ok = await verifyWebhookSignature({ secret, rawBody, timestamp, signature, toleranceSeconds: 300 });
|
|
122
|
+
// Compatible with the backend's current json_encode signing:
|
|
123
|
+
const okLegacy = await verifyLegacyWebhook(secret, JSON.parse(rawBody), signature);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Always verify against the **raw** request body.
|
|
127
|
+
|
|
128
|
+
## Logging & telemetry
|
|
129
|
+
|
|
130
|
+
Pass a `logger` and/or `telemetry` config. The SDK redacts tokens, secrets, credentials,
|
|
131
|
+
signatures, and PII before any event is logged or transmitted, and templatizes ids out of
|
|
132
|
+
paths.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
const threeu = new Threeu(token, {
|
|
136
|
+
logger: { error: (e) => console.error(e.type, e.errorCode) },
|
|
137
|
+
telemetry: { enabled: true, endpoint: "https://api.threeu.app/api/sdk/events", sampleRate: 1 },
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Browser safety
|
|
142
|
+
|
|
143
|
+
- Never construct `ThreeuAdmin` / a secret-token client in browser code — the SDK warns
|
|
144
|
+
in development when it detects this.
|
|
145
|
+
- Use `ThreeuStorefront` (public token, `platform-id` only) in the browser.
|
|
146
|
+
|
|
147
|
+
## Errors
|
|
148
|
+
|
|
149
|
+
All failures normalize to typed errors with `code`, `status`, `requestId`, `details`,
|
|
150
|
+
`cause`, and `retryable`: `ThreeuApiError`, `ThreeuAuthError`, `ThreeuPermissionError`,
|
|
151
|
+
`ThreeuValidationError` (with `.fields`), `ThreeuNotFoundError`, `ThreeuConflictError`,
|
|
152
|
+
`ThreeuRateLimitError`, `ThreeuTimeoutError`, `ThreeuNetworkError`,
|
|
153
|
+
`ThreeuWebhookSignatureError`, `ThreeuManifestError`, `ThreeuProviderError`,
|
|
154
|
+
`ThreeuNotImplementedError`.
|
|
155
|
+
|
|
156
|
+
## Scripts
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npm run build # tsup → ESM + .d.ts + sourcemaps for every entry
|
|
160
|
+
npm run typecheck # tsc --noEmit
|
|
161
|
+
npm test # vitest
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Publishing
|
|
165
|
+
|
|
166
|
+
Published to npm as the unscoped package **`threeu-sdk`** (MIT). Release flow:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
npm login # any npm account
|
|
170
|
+
npm version patch|minor # bump version + git tag
|
|
171
|
+
# update src/version.ts SDK_VERSION to match
|
|
172
|
+
npm publish # prepublishOnly runs typecheck + tests + build first
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Standalone in `local-code/threeu_npm_sdk`, designed to migrate into a
|
|
176
|
+
`packages/threeu-sdk` workspace later without import changes.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { T as Threeu, a as ThreeuOptions } from '../threeu-BesFjXdw.js';
|
|
2
|
+
export { B as BrandClient } from '../threeu-BesFjXdw.js';
|
|
3
|
+
export { B as BaseRecord, C as Collection, a as Customer, D as Discount, I as Id, b as InventoryItem, L as ListParams, c as Location, M as Money, O as Order, P as Payment, d as Product, e as ProductInput, S as ShippingRate } from '../types-DfyYnoLn.js';
|
|
4
|
+
import '../session-BFDRm-KJ.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @threeu/threeu/admin — secret-token admin client.
|
|
8
|
+
*
|
|
9
|
+
* const threeu = new ThreeuAdmin(process.env.THREEU_SECRET_KEY!);
|
|
10
|
+
* const brand = await threeu.brand("brand-slug");
|
|
11
|
+
* await brand.products.create({ name: "Black Abaya", price: 350, currency: "QAR", stock: 20 });
|
|
12
|
+
* const orders = await brand.orders.list({ status: "pending" });
|
|
13
|
+
*
|
|
14
|
+
* Identical capability to the root `Threeu` client; named export for clarity in
|
|
15
|
+
* server-side admin code. Never instantiate with a secret token in a browser.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
declare class ThreeuAdmin extends Threeu {
|
|
19
|
+
constructor(token: string, options?: ThreeuOptions);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { Threeu, ThreeuAdmin, ThreeuOptions };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Threeu } from '../chunk-2TGBSV6L.js';
|
|
2
|
+
export { BrandClient, Threeu } from '../chunk-2TGBSV6L.js';
|
|
3
|
+
import '../chunk-BCUODRZW.js';
|
|
4
|
+
import '../chunk-HYSJ6YPN.js';
|
|
5
|
+
import '../chunk-H3XILKGI.js';
|
|
6
|
+
import '../chunk-LFF5LPWT.js';
|
|
7
|
+
|
|
8
|
+
// src/admin/index.ts
|
|
9
|
+
var ThreeuAdmin = class extends Threeu {
|
|
10
|
+
constructor(token, options = {}) {
|
|
11
|
+
super(token, options, "secret_admin");
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { ThreeuAdmin };
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/admin/index.ts"],"names":[],"mappings":";;;;;;;;AAaO,IAAM,WAAA,GAAN,cAA0B,MAAA,CAAO;AAAA,EACtC,WAAA,CAAY,KAAA,EAAe,OAAA,GAAyB,EAAC,EAAG;AACtD,IAAA,KAAA,CAAM,KAAA,EAAO,SAAS,cAAc,CAAA;AAAA,EACtC;AACF","file":"index.js","sourcesContent":["/**\n * @threeu/threeu/admin — secret-token admin client.\n *\n * const threeu = new ThreeuAdmin(process.env.THREEU_SECRET_KEY!);\n * const brand = await threeu.brand(\"brand-slug\");\n * await brand.products.create({ name: \"Black Abaya\", price: 350, currency: \"QAR\", stock: 20 });\n * const orders = await brand.orders.list({ status: \"pending\" });\n *\n * Identical capability to the root `Threeu` client; named export for clarity in\n * server-side admin code. Never instantiate with a secret token in a browser.\n */\nimport { Threeu, type ThreeuOptions } from \"../clients/threeu\";\n\nexport class ThreeuAdmin extends Threeu {\n constructor(token: string, options: ThreeuOptions = {}) {\n super(token, options, \"secret_admin\");\n }\n}\n\nexport { Threeu } from \"../clients/threeu\";\nexport { BrandClient } from \"../clients/brand\";\nexport type { ThreeuOptions } from \"../clients/threeu\";\nexport * from \"../resources/types\";\n"]}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { PosNamespace } from './chunk-BCUODRZW.js';
|
|
2
|
+
import { ThreeuHttpClient } from './chunk-HYSJ6YPN.js';
|
|
3
|
+
|
|
4
|
+
// src/resources/resource.ts
|
|
5
|
+
var CrudResource = class {
|
|
6
|
+
constructor(ctx, path) {
|
|
7
|
+
this.ctx = ctx;
|
|
8
|
+
this.path = path;
|
|
9
|
+
}
|
|
10
|
+
opts(extra) {
|
|
11
|
+
return this.ctx.brand !== void 0 ? { brand: this.ctx.brand, ...extra } : { ...extra };
|
|
12
|
+
}
|
|
13
|
+
list(params) {
|
|
14
|
+
return this.ctx.http.list(this.path, this.opts({ query: params }));
|
|
15
|
+
}
|
|
16
|
+
iterate(params) {
|
|
17
|
+
return this.ctx.http.iterate(this.path, this.opts({ query: params }));
|
|
18
|
+
}
|
|
19
|
+
get(id) {
|
|
20
|
+
return this.ctx.http.get(`${this.path}/${id}`, this.opts());
|
|
21
|
+
}
|
|
22
|
+
create(input, options) {
|
|
23
|
+
return this.ctx.http.post(
|
|
24
|
+
this.path,
|
|
25
|
+
this.opts({ body: input, idempotent: true, idempotencyKey: options?.idempotencyKey })
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
update(id, input) {
|
|
29
|
+
return this.ctx.http.put(`${this.path}/${id}`, this.opts({ body: input }));
|
|
30
|
+
}
|
|
31
|
+
delete(id) {
|
|
32
|
+
return this.ctx.http.delete(`${this.path}/${id}`, this.opts());
|
|
33
|
+
}
|
|
34
|
+
/** POST a custom sub-action, e.g. `action(id, "fulfill", {...})`. */
|
|
35
|
+
action(id, verb, body) {
|
|
36
|
+
return this.ctx.http.post(`${this.path}/${id}/${verb}`, this.opts({ body, idempotent: true }));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/resources/index.ts
|
|
41
|
+
var ProductsResource = class extends CrudResource {
|
|
42
|
+
constructor(ctx) {
|
|
43
|
+
super(ctx, "products");
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var OrdersResource = class extends CrudResource {
|
|
47
|
+
constructor(ctx) {
|
|
48
|
+
super(ctx, "orders");
|
|
49
|
+
}
|
|
50
|
+
fulfill(id, body) {
|
|
51
|
+
return this.action(id, "fulfill", body);
|
|
52
|
+
}
|
|
53
|
+
cancel(id, body) {
|
|
54
|
+
return this.action(id, "cancel", body);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var CustomersResource = class extends CrudResource {
|
|
58
|
+
constructor(ctx) {
|
|
59
|
+
super(ctx, "customers");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var CollectionsResource = class extends CrudResource {
|
|
63
|
+
constructor(ctx) {
|
|
64
|
+
super(ctx, "collections");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var DiscountsResource = class extends CrudResource {
|
|
68
|
+
constructor(ctx) {
|
|
69
|
+
super(ctx, "discounts");
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var LocationsResource = class extends CrudResource {
|
|
73
|
+
constructor(ctx) {
|
|
74
|
+
super(ctx, "locations");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var InventoryResource = class extends CrudResource {
|
|
78
|
+
constructor(ctx) {
|
|
79
|
+
super(ctx, "inventory");
|
|
80
|
+
}
|
|
81
|
+
adjust(body) {
|
|
82
|
+
return this.ctx.http.post("inventory/adjust", this.opts({ body, idempotent: true }));
|
|
83
|
+
}
|
|
84
|
+
transfer(body) {
|
|
85
|
+
return this.ctx.http.post("inventory/transfer", this.opts({ body, idempotent: true }));
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var PaymentsResource = class extends CrudResource {
|
|
89
|
+
constructor(ctx) {
|
|
90
|
+
super(ctx, "payments");
|
|
91
|
+
}
|
|
92
|
+
refund(id, body) {
|
|
93
|
+
return this.action(id, "refund", body);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var ShippingResource = class {
|
|
97
|
+
constructor(ctx) {
|
|
98
|
+
this.ctx = ctx;
|
|
99
|
+
}
|
|
100
|
+
opts(extra) {
|
|
101
|
+
return this.ctx.brand !== void 0 ? { brand: this.ctx.brand, ...extra } : { ...extra };
|
|
102
|
+
}
|
|
103
|
+
rates(body) {
|
|
104
|
+
return this.ctx.http.post("shipping/rates", this.opts({ body }));
|
|
105
|
+
}
|
|
106
|
+
createShipment(body) {
|
|
107
|
+
return this.ctx.http.post("shipping/shipments", { ...this.opts({ body }), idempotent: true });
|
|
108
|
+
}
|
|
109
|
+
trackShipment(trackingNumber) {
|
|
110
|
+
return this.ctx.http.get(`shipping/shipments/${trackingNumber}/track`, this.opts());
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var AnalyticsResource = class {
|
|
114
|
+
constructor(ctx) {
|
|
115
|
+
this.ctx = ctx;
|
|
116
|
+
}
|
|
117
|
+
opts(query) {
|
|
118
|
+
return this.ctx.brand !== void 0 ? { brand: this.ctx.brand, query } : { query };
|
|
119
|
+
}
|
|
120
|
+
summary(params) {
|
|
121
|
+
return this.ctx.http.get("analytics/summary", this.opts(params));
|
|
122
|
+
}
|
|
123
|
+
sales(params) {
|
|
124
|
+
return this.ctx.http.get("analytics/sales", this.opts(params));
|
|
125
|
+
}
|
|
126
|
+
products(params) {
|
|
127
|
+
return this.ctx.http.get("analytics/products", this.opts(params));
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var CampaignsResource = class extends CrudResource {
|
|
131
|
+
constructor(ctx) {
|
|
132
|
+
super(ctx, "marketing/campaigns");
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var MarketingResource = class {
|
|
136
|
+
constructor(ctx) {
|
|
137
|
+
this.campaigns = new CampaignsResource(ctx);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var ThemeResource = class {
|
|
141
|
+
constructor(ctx) {
|
|
142
|
+
this.ctx = ctx;
|
|
143
|
+
}
|
|
144
|
+
opts(extra) {
|
|
145
|
+
return this.ctx.brand !== void 0 ? { brand: this.ctx.brand, ...extra } : { ...extra };
|
|
146
|
+
}
|
|
147
|
+
get() {
|
|
148
|
+
return this.ctx.http.get("theme", this.opts());
|
|
149
|
+
}
|
|
150
|
+
update(body) {
|
|
151
|
+
return this.ctx.http.put("theme", this.opts({ body }));
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// src/clients/brand.ts
|
|
156
|
+
var BrandClient = class {
|
|
157
|
+
constructor(http, brand) {
|
|
158
|
+
this.id = brand;
|
|
159
|
+
const ctx = { http, brand };
|
|
160
|
+
this.products = new ProductsResource(ctx);
|
|
161
|
+
this.orders = new OrdersResource(ctx);
|
|
162
|
+
this.customers = new CustomersResource(ctx);
|
|
163
|
+
this.inventory = new InventoryResource(ctx);
|
|
164
|
+
this.collections = new CollectionsResource(ctx);
|
|
165
|
+
this.discounts = new DiscountsResource(ctx);
|
|
166
|
+
this.payments = new PaymentsResource(ctx);
|
|
167
|
+
this.shipping = new ShippingResource(ctx);
|
|
168
|
+
this.locations = new LocationsResource(ctx);
|
|
169
|
+
this.analytics = new AnalyticsResource(ctx);
|
|
170
|
+
this.marketing = new MarketingResource(ctx);
|
|
171
|
+
this.theme = new ThemeResource(ctx);
|
|
172
|
+
this.pos = new PosNamespace(ctx);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// src/clients/threeu.ts
|
|
177
|
+
var Threeu = class {
|
|
178
|
+
constructor(token, options = {}, tokenType = "secret_admin") {
|
|
179
|
+
this.tokenType = tokenType;
|
|
180
|
+
this.http = new ThreeuHttpClient({ ...options, token, tokenType });
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Return a brand-scoped client. Synchronous, but returns a value safe to
|
|
184
|
+
* `await` so both `threeu.brand(x)` and `await threeu.brand(x)` work.
|
|
185
|
+
*/
|
|
186
|
+
brand(brand) {
|
|
187
|
+
return new BrandClient(this.http, brand);
|
|
188
|
+
}
|
|
189
|
+
/** Flush telemetry and release timers. */
|
|
190
|
+
close() {
|
|
191
|
+
return this.http.close();
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export { BrandClient, Threeu };
|
|
196
|
+
//# sourceMappingURL=chunk-2TGBSV6L.js.map
|
|
197
|
+
//# sourceMappingURL=chunk-2TGBSV6L.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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AiB,GAAG,CAAA;AACxC,IAAA,IAAA,CAAK,SAAA,GAAY,IAAI,iBAAA,CAAkB,GAAG,CAAA;AAC1C,IAAA,IAAA,CAAK,SAAA,GAAY,IAAI,iBAAA,CAAkB,GAAG,CAAA;AAC1C,IAAA,IAAA,CAAK,SAAA,GAAY,IAAI,iBAAA,CAAkB,GAAG,CAAA;AAC1C,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,aAAA,CAAc,GAAG,CAAA;AAClC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,YAAA,CAAa,GAAG,CAAA;AAAA,EACjC;AACF;;;AC1CO,IAAM,SAAN,MAAa;AAAA,EAIlB,YAAY,KAAA,EAAe,OAAA,GAAyB,EAAC,EAAG,YAAuB,cAAA,EAAgB;AAC7F,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AACjB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAAS,KAAA,EAAO,WAAW,CAAA;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,KAAA,EAAwB;AAC5B,IAAA,OAAO,IAAI,WAAA,CAAY,IAAA,CAAK,IAAA,EAAM,KAAK,CAAA;AAAA,EACzC;AAAA;AAAA,EAGA,KAAA,GAAuB;AACrB,IAAA,OAAO,IAAA,CAAK,KAAK,KAAA,EAAM;AAAA,EACzB;AACF","file":"chunk-2TGBSV6L.js","sourcesContent":["/**\n * Generic CRUD resource bound to a base path and a brand scope. Each high-level\n * resource (products, orders, ...) is a thin subclass that adds domain-specific\n * actions. Paths are centralized so they're trivial to adjust as backend routes\n * are confirmed.\n */\nimport type { ThreeuHttpClient } from \"../core/http-client\";\nimport type { Page } from \"../core/pagination\";\nimport type { RequestOptions } from \"../core/types\";\nimport type { BaseRecord, Id, ListParams } from \"./types\";\n\nexport interface ResourceContext {\n http: ThreeuHttpClient;\n /** Brand scope applied as `platform-id` on every call (undefined = client default). */\n brand?: Id;\n}\n\nexport class CrudResource<T extends BaseRecord = BaseRecord, TInput = Partial<T>> {\n constructor(\n protected readonly ctx: ResourceContext,\n protected readonly path: string,\n ) {}\n\n protected opts(extra?: RequestOptions): RequestOptions {\n return this.ctx.brand !== undefined ? { brand: this.ctx.brand, ...extra } : { ...extra };\n }\n\n list(params?: ListParams): Promise<Page<T>> {\n return this.ctx.http.list<T>(this.path, this.opts({ query: params }));\n }\n\n iterate(params?: ListParams): AsyncGenerator<T, void, void> {\n return this.ctx.http.iterate<T>(this.path, this.opts({ query: params }));\n }\n\n get(id: Id): Promise<T> {\n return this.ctx.http.get(`${this.path}/${id}`, this.opts()) as Promise<T>;\n }\n\n create(input: TInput, options?: { idempotencyKey?: string }): Promise<T> {\n return this.ctx.http.post(\n this.path,\n this.opts({ body: input, idempotent: true, idempotencyKey: options?.idempotencyKey }),\n ) as Promise<T>;\n }\n\n update(id: Id, input: Partial<TInput>): Promise<T> {\n return this.ctx.http.put(`${this.path}/${id}`, this.opts({ body: input })) as Promise<T>;\n }\n\n delete(id: Id): Promise<void> {\n return this.ctx.http.delete(`${this.path}/${id}`, this.opts()) as Promise<void>;\n }\n\n /** POST a custom sub-action, e.g. `action(id, \"fulfill\", {...})`. */\n protected action<R = unknown>(id: Id, verb: string, body?: unknown): Promise<R> {\n return this.ctx.http.post(`${this.path}/${id}/${verb}`, this.opts({ body, idempotent: true })) as Promise<R>;\n }\n}\n","/**\n * Concrete brand resources. Each adds domain actions on top of `CrudResource`.\n * Resource path constants live here so backend route changes are a one-line edit.\n */\nimport type { Page } from \"../core/pagination\";\nimport { CrudResource, type ResourceContext } from \"./resource\";\nimport type {\n Collection,\n Customer,\n Discount,\n Id,\n InventoryItem,\n ListParams,\n Location,\n Order,\n Payment,\n Product,\n ProductInput,\n ShippingRate,\n} from \"./types\";\n\nexport class ProductsResource extends CrudResource<Product, ProductInput> {\n constructor(ctx: ResourceContext) {\n super(ctx, \"products\");\n }\n}\n\nexport class OrdersResource extends CrudResource<Order> {\n constructor(ctx: ResourceContext) {\n super(ctx, \"orders\");\n }\n fulfill(id: Id, body?: Record<string, unknown>): Promise<Order> {\n return this.action<Order>(id, \"fulfill\", body);\n }\n cancel(id: Id, body?: Record<string, unknown>): Promise<Order> {\n return this.action<Order>(id, \"cancel\", body);\n }\n}\n\nexport class CustomersResource extends CrudResource<Customer> {\n constructor(ctx: ResourceContext) {\n super(ctx, \"customers\");\n }\n}\n\nexport class CollectionsResource extends CrudResource<Collection> {\n constructor(ctx: ResourceContext) {\n super(ctx, \"collections\");\n }\n}\n\nexport class DiscountsResource extends CrudResource<Discount> {\n constructor(ctx: ResourceContext) {\n super(ctx, \"discounts\");\n }\n}\n\nexport class LocationsResource extends CrudResource<Location> {\n constructor(ctx: ResourceContext) {\n super(ctx, \"locations\");\n }\n}\n\nexport class InventoryResource extends CrudResource<InventoryItem> {\n constructor(ctx: ResourceContext) {\n super(ctx, \"inventory\");\n }\n adjust(body: { product_id: Id; location_id?: Id; delta: number; reason?: string }): Promise<InventoryItem> {\n return this.ctx.http.post(\"inventory/adjust\", this.opts({ body, idempotent: true })) as Promise<InventoryItem>;\n }\n transfer(body: { product_id: Id; from_location_id: Id; to_location_id: Id; quantity: number }): Promise<InventoryItem> {\n return this.ctx.http.post(\"inventory/transfer\", this.opts({ body, idempotent: true })) as Promise<InventoryItem>;\n }\n}\n\nexport class PaymentsResource extends CrudResource<Payment> {\n constructor(ctx: ResourceContext) {\n super(ctx, \"payments\");\n }\n refund(id: Id, body?: { amount?: number; reason?: string }): Promise<Payment> {\n return this.action<Payment>(id, \"refund\", body);\n }\n}\n\nexport class ShippingResource {\n constructor(private readonly ctx: ResourceContext) {}\n private opts(extra?: { body?: unknown; query?: Record<string, unknown> }) {\n return this.ctx.brand !== undefined ? { brand: this.ctx.brand, ...extra } : { ...extra };\n }\n rates(body: { destination: string; items: unknown[] }): Promise<ShippingRate[]> {\n return this.ctx.http.post(\"shipping/rates\", this.opts({ body })) as Promise<ShippingRate[]>;\n }\n createShipment(body: Record<string, unknown>): Promise<Record<string, unknown>> {\n return this.ctx.http.post(\"shipping/shipments\", { ...this.opts({ body }), idempotent: true }) as Promise<\n Record<string, unknown>\n >;\n }\n trackShipment(trackingNumber: string): Promise<Record<string, unknown>> {\n return this.ctx.http.get(`shipping/shipments/${trackingNumber}/track`, this.opts()) as Promise<\n Record<string, unknown>\n >;\n }\n}\n\nexport class AnalyticsResource {\n constructor(private readonly ctx: ResourceContext) {}\n private opts(query?: Record<string, unknown>) {\n return this.ctx.brand !== undefined ? { brand: this.ctx.brand, query } : { query };\n }\n summary(params?: { from?: string; to?: string }): Promise<Record<string, unknown>> {\n return this.ctx.http.get(\"analytics/summary\", this.opts(params)) as Promise<Record<string, unknown>>;\n }\n sales(params?: { from?: string; to?: string; interval?: string }): Promise<Record<string, unknown>> {\n return this.ctx.http.get(\"analytics/sales\", this.opts(params)) as Promise<Record<string, unknown>>;\n }\n products(params?: { from?: string; to?: string; limit?: number }): Promise<Record<string, unknown>> {\n return this.ctx.http.get(\"analytics/products\", this.opts(params)) as Promise<Record<string, unknown>>;\n }\n}\n\nexport class CampaignsResource extends CrudResource {\n constructor(ctx: ResourceContext) {\n super(ctx, \"marketing/campaigns\");\n }\n}\n\nexport class MarketingResource {\n readonly campaigns: CampaignsResource;\n constructor(ctx: ResourceContext) {\n this.campaigns = new CampaignsResource(ctx);\n }\n}\n\nexport class ThemeResource {\n constructor(private readonly ctx: ResourceContext) {}\n private opts(extra?: { body?: unknown }) {\n return this.ctx.brand !== undefined ? { brand: this.ctx.brand, ...extra } : { ...extra };\n }\n get(): Promise<Record<string, unknown>> {\n return this.ctx.http.get(\"theme\", this.opts()) as Promise<Record<string, unknown>>;\n }\n update(body: Record<string, unknown>): Promise<Record<string, unknown>> {\n return this.ctx.http.put(\"theme\", this.opts({ body })) as Promise<Record<string, unknown>>;\n }\n}\n\nexport type { Page, ListParams };\n","/**\n * Scoped brand object returned by `client.brand(slug)`. Every resource call is\n * automatically scoped to this brand via the `platform-id` header. This is the\n * SDK object the brief's core DX revolves around (`brand.products.create(...)`).\n */\nimport type { ThreeuHttpClient } from \"../core/http-client\";\nimport type { Id } from \"../resources/types\";\nimport type { ResourceContext } from \"../resources/resource\";\nimport {\n AnalyticsResource,\n CollectionsResource,\n CustomersResource,\n DiscountsResource,\n InventoryResource,\n LocationsResource,\n MarketingResource,\n OrdersResource,\n PaymentsResource,\n ProductsResource,\n ShippingResource,\n ThemeResource,\n} from \"../resources\";\nimport { PosNamespace } from \"../pos/session\";\n\nexport class BrandClient {\n readonly id: Id;\n readonly products: ProductsResource;\n readonly orders: OrdersResource;\n readonly customers: CustomersResource;\n readonly inventory: InventoryResource;\n readonly collections: CollectionsResource;\n readonly discounts: DiscountsResource;\n readonly payments: PaymentsResource;\n readonly shipping: ShippingResource;\n readonly locations: LocationsResource;\n readonly analytics: AnalyticsResource;\n readonly marketing: MarketingResource;\n readonly theme: ThemeResource;\n readonly pos: PosNamespace;\n\n constructor(http: ThreeuHttpClient, brand: Id) {\n this.id = brand;\n const ctx: ResourceContext = { http, brand };\n this.products = new ProductsResource(ctx);\n this.orders = new OrdersResource(ctx);\n this.customers = new CustomersResource(ctx);\n this.inventory = new InventoryResource(ctx);\n this.collections = new CollectionsResource(ctx);\n this.discounts = new DiscountsResource(ctx);\n this.payments = new PaymentsResource(ctx);\n this.shipping = new ShippingResource(ctx);\n this.locations = new LocationsResource(ctx);\n this.analytics = new AnalyticsResource(ctx);\n this.marketing = new MarketingResource(ctx);\n this.theme = new ThemeResource(ctx);\n this.pos = new PosNamespace(ctx);\n }\n}\n","/**\n * `Threeu` — the high-level entry client. Constructed with a secret key, it\n * yields brand-scoped objects:\n *\n * const threeu = new Threeu(process.env.THREEU_SECRET_KEY!);\n * const brand = await threeu.brand(\"my-store\");\n * await brand.products.create({ name: \"Black Abaya\", price: 350, currency: \"QAR\" });\n */\nimport { ThreeuHttpClient } from \"../core/http-client\";\nimport type { ThreeuClientOptions, TokenType } from \"../core/types\";\nimport type { Id } from \"../resources/types\";\nimport { BrandClient } from \"./brand\";\n\nexport type ThreeuOptions = Omit<ThreeuClientOptions, \"token\" | \"tokenType\">;\n\nexport class Threeu {\n readonly http: ThreeuHttpClient;\n protected readonly tokenType: TokenType;\n\n constructor(token: string, options: ThreeuOptions = {}, tokenType: TokenType = \"secret_admin\") {\n this.tokenType = tokenType;\n this.http = new ThreeuHttpClient({ ...options, token, tokenType });\n }\n\n /**\n * Return a brand-scoped client. Synchronous, but returns a value safe to\n * `await` so both `threeu.brand(x)` and `await threeu.brand(x)` work.\n */\n brand(brand: Id): BrandClient {\n return new BrandClient(this.http, brand);\n }\n\n /** Flush telemetry and release timers. */\n close(): Promise<void> {\n return this.http.close();\n }\n}\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ThreeuHttpClient } from './chunk-HYSJ6YPN.js';
|
|
2
|
+
|
|
3
|
+
// src/storefront/index.ts
|
|
4
|
+
var STOREFRONT_BASE = "/api/marketplace/storefront";
|
|
5
|
+
function normalizeStorefrontBase(baseUrl) {
|
|
6
|
+
if (!baseUrl) return STOREFRONT_BASE;
|
|
7
|
+
let base = baseUrl.replace(/\/+$/, "");
|
|
8
|
+
if (base.includes("/api/marketplace/storefront")) return base;
|
|
9
|
+
if (base.endsWith("/api/marketplace")) return `${base}/storefront`;
|
|
10
|
+
if (base.endsWith("/api")) return `${base}/marketplace/storefront`;
|
|
11
|
+
return `${base}${STOREFRONT_BASE}`;
|
|
12
|
+
}
|
|
13
|
+
var StorefrontProducts = class {
|
|
14
|
+
constructor(http, brand) {
|
|
15
|
+
this.http = http;
|
|
16
|
+
this.brand = brand;
|
|
17
|
+
}
|
|
18
|
+
list(params) {
|
|
19
|
+
return this.http.list("products", { brand: this.brand, query: params });
|
|
20
|
+
}
|
|
21
|
+
get(id) {
|
|
22
|
+
return this.http.get(`products/${id}`, { brand: this.brand });
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var StorefrontCollections = class {
|
|
26
|
+
constructor(http, brand) {
|
|
27
|
+
this.http = http;
|
|
28
|
+
this.brand = brand;
|
|
29
|
+
}
|
|
30
|
+
list(params) {
|
|
31
|
+
return this.http.list("collections", { brand: this.brand, query: params });
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var StorefrontCart = class {
|
|
35
|
+
constructor(http, brand) {
|
|
36
|
+
this.http = http;
|
|
37
|
+
this.brand = brand;
|
|
38
|
+
}
|
|
39
|
+
create() {
|
|
40
|
+
return this.http.post("cart", { brand: this.brand, idempotent: true });
|
|
41
|
+
}
|
|
42
|
+
get(id) {
|
|
43
|
+
return this.http.get(`cart/${id}`, { brand: this.brand });
|
|
44
|
+
}
|
|
45
|
+
addItem(id, item) {
|
|
46
|
+
return this.http.post(`cart/${id}/items`, {
|
|
47
|
+
brand: this.brand,
|
|
48
|
+
body: { product_id: item.productId, quantity: item.quantity },
|
|
49
|
+
idempotent: true
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var ThreeuStorefront = class {
|
|
54
|
+
constructor(options) {
|
|
55
|
+
this.brand = options.brand;
|
|
56
|
+
this.http = new ThreeuHttpClient({
|
|
57
|
+
baseUrl: normalizeStorefrontBase(options.baseUrl),
|
|
58
|
+
token: options.publicToken,
|
|
59
|
+
tokenType: "public_storefront",
|
|
60
|
+
brand: options.brand,
|
|
61
|
+
fetch: options.fetch,
|
|
62
|
+
logger: options.logger,
|
|
63
|
+
telemetry: options.telemetry,
|
|
64
|
+
timeoutMs: options.timeoutMs
|
|
65
|
+
});
|
|
66
|
+
this.products = new StorefrontProducts(this.http, this.brand);
|
|
67
|
+
this.collections = new StorefrontCollections(this.http, this.brand);
|
|
68
|
+
this.cart = new StorefrontCart(this.http, this.brand);
|
|
69
|
+
}
|
|
70
|
+
/** Fetch the unified storefront config (delivery, payments, theme tokens). */
|
|
71
|
+
getConfig(params) {
|
|
72
|
+
return this.http.get("config", { brand: this.brand, query: params });
|
|
73
|
+
}
|
|
74
|
+
close() {
|
|
75
|
+
return this.http.close();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export { ThreeuStorefront };
|
|
80
|
+
//# sourceMappingURL=chunk-6S7OFN23.js.map
|
|
81
|
+
//# sourceMappingURL=chunk-6S7OFN23.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/storefront/index.ts"],"names":[],"mappings":";;;AAmBA,IAAM,eAAA,GAAkB,6BAAA;AAoBxB,SAAS,wBAAwB,OAAA,EAA0B;AACzD,EAAA,IAAI,CAAC,SAAS,OAAO,eAAA;AACrB,EAAA,IAAI,IAAA,GAAO,OAAA,CAAQ,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AACrC,EAAA,IAAI,IAAA,CAAK,QAAA,CAAS,6BAA6B,CAAA,EAAG,OAAO,IAAA;AACzD,EAAA,IAAI,KAAK,QAAA,CAAS,kBAAkB,CAAA,EAAG,OAAO,GAAG,IAAI,CAAA,WAAA,CAAA;AACrD,EAAA,IAAI,KAAK,QAAA,CAAS,MAAM,CAAA,EAAG,OAAO,GAAG,IAAI,CAAA,uBAAA,CAAA;AACzC,EAAA,OAAO,CAAA,EAAG,IAAI,CAAA,EAAG,eAAe,CAAA,CAAA;AAClC;AAEA,IAAM,qBAAN,MAAyB;AAAA,EACvB,WAAA,CACmB,MACA,KAAA,EACjB;AAFiB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAAA,EAChB;AAAA,EACH,KAAK,MAAA,EAA0D;AAC7D,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAc,UAAA,EAAY,EAAE,OAAO,IAAA,CAAK,KAAA,EAAO,KAAA,EAAO,MAAA,EAAQ,CAAA;AAAA,EACjF;AAAA,EACA,IAAI,EAAA,EAA0B;AAC5B,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,CAAA,SAAA,EAA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D,UAAA,EAAY;AAAA,KACb,CAAA;AAAA,EACH;AACF,CAAA;AAEO,IAAM,mBAAN,MAAuB;AAAA,EAO5B,YAAY,OAAA,EAAkC;AAC5C,IAAA,IAAA,CAAK,QAAQ,OAAA,CAAQ,KAAA;AACrB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAI,gBAAA,CAAiB;AAAA,MAC/B,OAAA,EAAS,uBAAA,CAAwB,OAAA,CAAQ,OAAO,CAAA;AAAA,MAChD,OAAO,OAAA,CAAQ,WAAA;AAAA,MACf,SAAA,EAAW,mBAAA;AAAA,MACX,OAAO,OAAA,CAAQ,KAAA;AAAA,MACf,OAAO,OAAA,CAAQ,KAAA;AAAA,MACf,QAAQ,OAAA,CAAQ,MAAA;AAAA,MAChB,WAAW,OAAA,CAAQ,SAAA;AAAA,MACnB,WAAW,OAAA,CAAQ;AAAA,KACpB,CAAA;AACD,IAAA,IAAA,CAAK,WAAW,IAAI,kBAAA,CAAmB,IAAA,CAAK,IAAA,EAAM,KAAK,KAAK,CAAA;AAC5D,IAAA,IAAA,CAAK,cAAc,IAAI,qBAAA,CAAsB,IAAA,CAAK,IAAA,EAAM,KAAK,KAAK,CAAA;AAClE,IAAA,IAAA,CAAK,OAAO,IAAI,cAAA,CAAe,IAAA,CAAK,IAAA,EAAM,KAAK,KAAK,CAAA;AAAA,EACtD;AAAA;AAAA,EAGA,UAAU,MAAA,EAAiF;AACzF,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,QAAA,EAAU,EAAE,OAAO,IAAA,CAAK,KAAA,EAAO,KAAA,EAAO,MAAA,EAAQ,CAAA;AAAA,EACrE;AAAA,EAEA,KAAA,GAAuB;AACrB,IAAA,OAAO,IAAA,CAAK,KAAK,KAAA,EAAM;AAAA,EACzB;AACF","file":"chunk-6S7OFN23.js","sourcesContent":["/**\n * @threeu/threeu/storefront — public-token storefront client.\n *\n * const storefront = new ThreeuStorefront({\n * publicToken: import.meta.env.VITE_THREEU_PUBLIC_KEY,\n * brand: \"my-store\",\n * });\n * const products = await storefront.products.list({ collection: \"featured\", limit: 8 });\n * const cart = await storefront.cart.create();\n *\n * Public surface lives under `/api/marketplace/storefront/*` and resolves the\n * brand purely from the `platform-id` header (docs/ARCHITECTURE_MAP.md §14).\n * Safe to use in the browser — it never carries a secret token.\n */\nimport { ThreeuHttpClient } from \"../core/http-client\";\nimport type { Page } from \"../core/pagination\";\nimport type { ThreeuLogger, ThreeuTelemetryOptions } from \"../core/types\";\nimport type { Collection, Id, Product } from \"../resources/types\";\n\nconst STOREFRONT_BASE = \"/api/marketplace/storefront\";\n\nexport interface ThreeuStorefrontOptions {\n brand: Id;\n publicToken?: string;\n baseUrl?: string;\n fetch?: typeof fetch;\n logger?: ThreeuLogger;\n telemetry?: ThreeuTelemetryOptions;\n timeoutMs?: number;\n}\n\nexport interface StorefrontProductParams {\n collection?: string;\n limit?: number;\n page?: number;\n search?: string;\n [key: string]: unknown;\n}\n\nfunction normalizeStorefrontBase(baseUrl?: string): string {\n if (!baseUrl) return STOREFRONT_BASE;\n let base = baseUrl.replace(/\\/+$/, \"\");\n if (base.includes(\"/api/marketplace/storefront\")) return base;\n if (base.endsWith(\"/api/marketplace\")) return `${base}/storefront`;\n if (base.endsWith(\"/api\")) return `${base}/marketplace/storefront`;\n return `${base}${STOREFRONT_BASE}`;\n}\n\nclass StorefrontProducts {\n constructor(\n private readonly http: ThreeuHttpClient,\n private readonly brand: Id,\n ) {}\n list(params?: StorefrontProductParams): Promise<Page<Product>> {\n return this.http.list<Product>(\"products\", { brand: this.brand, query: params });\n }\n get(id: Id): Promise<Product> {\n return this.http.get(`products/${id}`, { brand: this.brand }) as Promise<Product>;\n }\n}\n\nclass StorefrontCollections {\n constructor(\n private readonly http: ThreeuHttpClient,\n private readonly brand: Id,\n ) {}\n list(params?: { limit?: number; page?: number }): Promise<Page<Collection>> {\n return this.http.list<Collection>(\"collections\", { brand: this.brand, query: params });\n }\n}\n\nclass StorefrontCart {\n constructor(\n private readonly http: ThreeuHttpClient,\n private readonly brand: Id,\n ) {}\n create(): Promise<Record<string, unknown>> {\n return this.http.post(\"cart\", { brand: this.brand, idempotent: true }) as Promise<Record<string, unknown>>;\n }\n get(id: Id): Promise<Record<string, unknown>> {\n return this.http.get(`cart/${id}`, { brand: this.brand }) as Promise<Record<string, unknown>>;\n }\n addItem(id: Id, item: { productId: Id; quantity: number }): Promise<Record<string, unknown>> {\n return this.http.post(`cart/${id}/items`, {\n brand: this.brand,\n body: { product_id: item.productId, quantity: item.quantity },\n idempotent: true,\n }) as Promise<Record<string, unknown>>;\n }\n}\n\nexport class ThreeuStorefront {\n readonly http: ThreeuHttpClient;\n readonly products: StorefrontProducts;\n readonly collections: StorefrontCollections;\n readonly cart: StorefrontCart;\n private readonly brand: Id;\n\n constructor(options: ThreeuStorefrontOptions) {\n this.brand = options.brand;\n this.http = new ThreeuHttpClient({\n baseUrl: normalizeStorefrontBase(options.baseUrl),\n token: options.publicToken,\n tokenType: \"public_storefront\",\n brand: options.brand,\n fetch: options.fetch,\n logger: options.logger,\n telemetry: options.telemetry,\n timeoutMs: options.timeoutMs,\n });\n this.products = new StorefrontProducts(this.http, this.brand);\n this.collections = new StorefrontCollections(this.http, this.brand);\n this.cart = new StorefrontCart(this.http, this.brand);\n }\n\n /** Fetch the unified storefront config (delivery, payments, theme tokens). */\n getConfig(params?: { website?: boolean; pos?: boolean }): Promise<Record<string, unknown>> {\n return this.http.get(\"config\", { brand: this.brand, query: params }) as Promise<Record<string, unknown>>;\n }\n\n close(): Promise<void> {\n return this.http.close();\n }\n}\n"]}
|