@elizaos/plugin-shopify-ui 2.0.3-beta.6 → 2.0.3-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/CustomersPanel.d.ts +11 -0
  2. package/dist/CustomersPanel.d.ts.map +1 -0
  3. package/dist/CustomersPanel.js +86 -0
  4. package/dist/CustomersPanel.js.map +1 -0
  5. package/dist/InventoryLevelsPanel.d.ts +10 -0
  6. package/dist/InventoryLevelsPanel.d.ts.map +1 -0
  7. package/dist/InventoryLevelsPanel.js +190 -0
  8. package/dist/InventoryLevelsPanel.js.map +1 -0
  9. package/dist/OrdersPanel.d.ts +12 -0
  10. package/dist/OrdersPanel.d.ts.map +1 -0
  11. package/dist/OrdersPanel.js +170 -0
  12. package/dist/OrdersPanel.js.map +1 -0
  13. package/dist/ProductsPanel.d.ts +13 -0
  14. package/dist/ProductsPanel.d.ts.map +1 -0
  15. package/dist/ProductsPanel.js +419 -0
  16. package/dist/ProductsPanel.js.map +1 -0
  17. package/dist/ShopifyAppView.d.ts +3 -0
  18. package/dist/ShopifyAppView.d.ts.map +1 -0
  19. package/dist/ShopifyAppView.helpers.d.ts +11 -0
  20. package/dist/ShopifyAppView.helpers.d.ts.map +1 -0
  21. package/dist/ShopifyAppView.helpers.js +59 -0
  22. package/dist/ShopifyAppView.helpers.js.map +1 -0
  23. package/dist/ShopifyAppView.interact.d.ts +2 -0
  24. package/dist/ShopifyAppView.interact.d.ts.map +1 -0
  25. package/dist/ShopifyAppView.interact.js +93 -0
  26. package/dist/ShopifyAppView.interact.js.map +1 -0
  27. package/dist/ShopifyAppView.js +667 -0
  28. package/dist/ShopifyAppView.js.map +1 -0
  29. package/dist/ShopifyView.d.ts +18 -0
  30. package/dist/ShopifyView.d.ts.map +1 -0
  31. package/dist/ShopifyView.js +143 -0
  32. package/dist/ShopifyView.js.map +1 -0
  33. package/dist/StoreOverviewCard.d.ts +13 -0
  34. package/dist/StoreOverviewCard.d.ts.map +1 -0
  35. package/dist/StoreOverviewCard.js +23 -0
  36. package/dist/StoreOverviewCard.js.map +1 -0
  37. package/dist/components/ShopifySpatialView.d.ts +57 -0
  38. package/dist/components/ShopifySpatialView.d.ts.map +1 -0
  39. package/dist/components/ShopifySpatialView.js +419 -0
  40. package/dist/components/ShopifySpatialView.js.map +1 -0
  41. package/dist/index.d.ts +14 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +20 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/plugin.d.ts +14 -0
  46. package/dist/plugin.d.ts.map +1 -0
  47. package/dist/plugin.js +94 -0
  48. package/dist/plugin.js.map +1 -0
  49. package/dist/register-routes.d.ts +2 -0
  50. package/dist/register-routes.d.ts.map +1 -0
  51. package/dist/register-routes.js +6 -0
  52. package/dist/register-routes.js.map +1 -0
  53. package/dist/register-terminal-view.d.ts +15 -0
  54. package/dist/register-terminal-view.d.ts.map +1 -0
  55. package/dist/register-terminal-view.js +37 -0
  56. package/dist/register-terminal-view.js.map +1 -0
  57. package/dist/register.d.ts +2 -0
  58. package/dist/register.d.ts.map +1 -0
  59. package/dist/register.js +17 -0
  60. package/dist/register.js.map +1 -0
  61. package/dist/routes.d.ts +18 -0
  62. package/dist/routes.d.ts.map +1 -0
  63. package/dist/routes.js +518 -0
  64. package/dist/routes.js.map +1 -0
  65. package/dist/shopify-app.d.ts +11 -0
  66. package/dist/shopify-app.d.ts.map +1 -0
  67. package/dist/shopify-app.js +16 -0
  68. package/dist/shopify-app.js.map +1 -0
  69. package/dist/shopify-view-bundle.d.ts +3 -0
  70. package/dist/shopify-view-bundle.d.ts.map +1 -0
  71. package/dist/shopify-view-bundle.js +7 -0
  72. package/dist/shopify-view-bundle.js.map +1 -0
  73. package/dist/useShopifyDashboard.d.ts +118 -0
  74. package/dist/useShopifyDashboard.d.ts.map +1 -0
  75. package/dist/useShopifyDashboard.js +212 -0
  76. package/dist/useShopifyDashboard.js.map +1 -0
  77. package/dist/views/bundle.js +948 -0
  78. package/dist/views/bundle.js.map +1 -0
  79. package/package.json +5 -5
@@ -0,0 +1,948 @@
1
+ import { Button as e, Card as t, Divider as n, Field as r, HStack as i, List as a, SpatialSurface as o, Text as s, VStack as c } from "@elizaos/ui/spatial";
2
+ import { useCallback as l, useEffect as u, useRef as d, useState as f } from "react";
3
+ import { jsx as p, jsxs as m } from "react/jsx-runtime";
4
+ //#region src/ShopifyAppView.helpers.ts
5
+ async function h(e) {
6
+ let t = await fetch(e);
7
+ if (t.status === 404) return null;
8
+ let n = await t.json().catch(() => null);
9
+ if (!t.ok) {
10
+ let e = n && typeof n == "object" && "error" in n ? String(n.error) : `Shopify request failed with ${t.status}`;
11
+ throw Error(e);
12
+ }
13
+ return n;
14
+ }
15
+ async function g(e, t) {
16
+ let n = await fetch(e, {
17
+ method: "POST",
18
+ headers: { "Content-Type": "application/json" },
19
+ body: JSON.stringify(t)
20
+ }), r = await n.json().catch(() => ({}));
21
+ if (!n.ok) {
22
+ let e = r && typeof r == "object" && "error" in r ? String(r.error) : `Shopify request failed with ${n.status}`;
23
+ throw Error(e);
24
+ }
25
+ return r;
26
+ }
27
+ async function _() {
28
+ let e = await h("/api/shopify/status") ?? {
29
+ connected: !1,
30
+ shop: null
31
+ };
32
+ if (!e.connected) return {
33
+ status: e,
34
+ products: null,
35
+ orders: null,
36
+ inventory: null,
37
+ customers: null
38
+ };
39
+ let [t, n, r, i] = await Promise.all([
40
+ h("/api/shopify/products?page=1&limit=10&q="),
41
+ h("/api/shopify/orders?status=any&limit=10"),
42
+ h("/api/shopify/inventory"),
43
+ h("/api/shopify/customers?q=&limit=10")
44
+ ]);
45
+ return {
46
+ status: e,
47
+ products: t,
48
+ orders: n,
49
+ inventory: r,
50
+ customers: i
51
+ };
52
+ }
53
+ //#endregion
54
+ //#region src/ShopifyAppView.interact.ts
55
+ async function v(e, t) {
56
+ if (e === "terminal-shopify-state") return {
57
+ viewType: "tui",
58
+ ...await _()
59
+ };
60
+ if (e === "terminal-shopify-products") {
61
+ let e = typeof t?.query == "string" ? t.query.trim() : "", n = typeof t?.page == "number" ? t.page : 1, r = typeof t?.limit == "number" ? t.limit : 20;
62
+ return {
63
+ viewType: "tui",
64
+ products: await h(`/api/shopify/products?${new URLSearchParams({
65
+ page: String(n),
66
+ limit: String(r),
67
+ q: e
68
+ })}`)
69
+ };
70
+ }
71
+ if (e === "terminal-shopify-orders") {
72
+ let e = typeof t?.status == "string" ? t.status.trim() : "any", n = typeof t?.limit == "number" ? t.limit : 20;
73
+ return {
74
+ viewType: "tui",
75
+ orders: await h(`/api/shopify/orders?${new URLSearchParams({
76
+ status: e,
77
+ limit: String(n)
78
+ })}`)
79
+ };
80
+ }
81
+ if (e === "terminal-shopify-inventory") return {
82
+ viewType: "tui",
83
+ inventory: await h("/api/shopify/inventory")
84
+ };
85
+ if (e === "terminal-shopify-customers") {
86
+ let e = typeof t?.query == "string" ? t.query.trim() : "", n = typeof t?.limit == "number" ? t.limit : 20;
87
+ return {
88
+ viewType: "tui",
89
+ customers: await h(`/api/shopify/customers?${new URLSearchParams({
90
+ q: e,
91
+ limit: String(n)
92
+ })}`)
93
+ };
94
+ }
95
+ if (e === "terminal-shopify-create-product") {
96
+ let e = typeof t?.title == "string" ? t.title.trim() : "";
97
+ if (!e) throw Error("title is required");
98
+ return {
99
+ viewType: "tui",
100
+ product: await g("/api/shopify/products", {
101
+ title: e,
102
+ vendor: typeof t?.vendor == "string" ? t.vendor : void 0,
103
+ productType: typeof t?.productType == "string" ? t.productType : void 0,
104
+ price: typeof t?.price == "string" || typeof t?.price == "number" ? t.price : void 0
105
+ })
106
+ };
107
+ }
108
+ if (e === "terminal-shopify-adjust-inventory") {
109
+ let e = typeof t?.itemId == "string" ? t.itemId.trim() : "", n = typeof t?.delta == "number" ? t.delta : null;
110
+ if (!e) throw Error("itemId is required");
111
+ if (n === null) throw Error("delta is required");
112
+ return {
113
+ viewType: "tui",
114
+ inventory: await g(`/api/shopify/inventory/${encodeURIComponent(e)}/adjust`, {
115
+ delta: n,
116
+ locationId: typeof t?.locationId == "string" ? t.locationId : void 0
117
+ })
118
+ };
119
+ }
120
+ throw Error(`Unsupported capability "${e}"`);
121
+ }
122
+ //#endregion
123
+ //#region src/components/ShopifySpatialView.tsx
124
+ var y = [
125
+ {
126
+ id: "overview",
127
+ label: "Overview"
128
+ },
129
+ {
130
+ id: "products",
131
+ label: "Products"
132
+ },
133
+ {
134
+ id: "orders",
135
+ label: "Orders"
136
+ },
137
+ {
138
+ id: "inventory",
139
+ label: "Inventory"
140
+ },
141
+ {
142
+ id: "customers",
143
+ label: "Customers"
144
+ }
145
+ ];
146
+ function b(e) {
147
+ switch (e) {
148
+ case "PAID": return "success";
149
+ case "PENDING": return "warning";
150
+ case "REFUNDED":
151
+ case "PARTIALLY_REFUNDED": return "danger";
152
+ default: return "muted";
153
+ }
154
+ }
155
+ function x(e) {
156
+ switch (e) {
157
+ case "ACTIVE": return "success";
158
+ case "DRAFT": return "warning";
159
+ default: return "muted";
160
+ }
161
+ }
162
+ function S(e) {
163
+ return e === 0 ? "danger" : e <= 5 ? "warning" : "default";
164
+ }
165
+ function C({ label: t, value: n, tone: r, agent: i, onPress: a }) {
166
+ return /* @__PURE__ */ m(c, {
167
+ gap: 0,
168
+ grow: 1,
169
+ children: [/* @__PURE__ */ p(s, {
170
+ style: "subheading",
171
+ tone: r,
172
+ bold: !0,
173
+ children: n.toLocaleString()
174
+ }), /* @__PURE__ */ p(e, {
175
+ variant: "ghost",
176
+ tone: "default",
177
+ agent: i,
178
+ onPress: a,
179
+ children: t
180
+ })]
181
+ });
182
+ }
183
+ function w({ snapshot: e, onAction: t }) {
184
+ let r = e.inventoryItems.filter((e) => e.available <= 5), o = r.filter((e) => e.available === 0).length, l = (e) => () => t?.(`tab:${e}`);
185
+ return /* @__PURE__ */ m(c, {
186
+ gap: 1,
187
+ width: "100%",
188
+ children: [
189
+ /* @__PURE__ */ m(i, {
190
+ gap: 1,
191
+ wrap: !0,
192
+ width: "100%",
193
+ children: [
194
+ /* @__PURE__ */ p(C, {
195
+ label: "Products",
196
+ value: e.counts.productCount,
197
+ tone: "primary",
198
+ agent: "overview-products",
199
+ onPress: l("products")
200
+ }),
201
+ /* @__PURE__ */ p(C, {
202
+ label: "Orders",
203
+ value: e.counts.orderCount,
204
+ tone: "success",
205
+ agent: "overview-orders",
206
+ onPress: l("orders")
207
+ }),
208
+ /* @__PURE__ */ p(C, {
209
+ label: "Low stock",
210
+ value: r.length,
211
+ tone: o > 0 ? "danger" : "warning",
212
+ agent: "overview-inventory",
213
+ onPress: l("inventory")
214
+ }),
215
+ /* @__PURE__ */ p(C, {
216
+ label: "Customers",
217
+ value: e.counts.customerCount,
218
+ tone: "muted",
219
+ agent: "overview-customers",
220
+ onPress: l("customers")
221
+ })
222
+ ]
223
+ }),
224
+ /* @__PURE__ */ p(n, { label: "recent orders" }),
225
+ e.orders.length === 0 ? /* @__PURE__ */ p(s, {
226
+ tone: "muted",
227
+ align: "center",
228
+ style: "caption",
229
+ children: "None"
230
+ }) : /* @__PURE__ */ p(a, {
231
+ gap: 0,
232
+ width: "100%",
233
+ children: e.orders.slice(0, 3).map((e) => /* @__PURE__ */ m(i, {
234
+ gap: 1,
235
+ align: "center",
236
+ width: "100%",
237
+ children: [
238
+ /* @__PURE__ */ p(s, {
239
+ bold: !0,
240
+ wrap: !1,
241
+ width: 9,
242
+ children: e.name
243
+ }),
244
+ /* @__PURE__ */ p(s, {
245
+ style: "caption",
246
+ tone: "muted",
247
+ grow: 1,
248
+ wrap: !1,
249
+ children: e.email || "guest"
250
+ }),
251
+ /* @__PURE__ */ m(s, {
252
+ wrap: !1,
253
+ children: [
254
+ e.totalPrice,
255
+ " ",
256
+ e.currencyCode
257
+ ]
258
+ })
259
+ ]
260
+ }, e.id))
261
+ }),
262
+ /* @__PURE__ */ p(n, { label: "low inventory" }),
263
+ r.length === 0 ? /* @__PURE__ */ p(s, {
264
+ tone: "muted",
265
+ align: "center",
266
+ style: "caption",
267
+ children: "Stock levels look good"
268
+ }) : /* @__PURE__ */ p(a, {
269
+ gap: 0,
270
+ width: "100%",
271
+ children: r.slice(0, 3).map((e) => /* @__PURE__ */ m(i, {
272
+ gap: 1,
273
+ align: "center",
274
+ width: "100%",
275
+ children: [/* @__PURE__ */ m(s, {
276
+ grow: 1,
277
+ wrap: !1,
278
+ children: [e.productTitle, e.variantTitle ? ` / ${e.variantTitle}` : ""]
279
+ }), /* @__PURE__ */ p(s, {
280
+ tone: S(e.available),
281
+ bold: !0,
282
+ children: e.available
283
+ })]
284
+ }, `${e.id}:${e.locationName}`))
285
+ })
286
+ ]
287
+ });
288
+ }
289
+ var T = 20;
290
+ function E({ snapshot: t, onAction: n }) {
291
+ let o = Math.max(1, Math.ceil(t.productsTotal / T));
292
+ return /* @__PURE__ */ m(c, {
293
+ gap: 1,
294
+ width: "100%",
295
+ children: [
296
+ /* @__PURE__ */ p(r, {
297
+ label: "Search products",
298
+ placeholder: "filter by title",
299
+ value: t.productSearch,
300
+ agent: "products-search",
301
+ onChange: (e) => n?.(`products:search:${e}`)
302
+ }),
303
+ /* @__PURE__ */ m(i, {
304
+ gap: 1,
305
+ align: "center",
306
+ width: "100%",
307
+ children: [/* @__PURE__ */ p(r, {
308
+ label: "New product",
309
+ placeholder: "product title",
310
+ agent: "products-create-title",
311
+ grow: 1,
312
+ onChange: (e) => n?.(`products:create-title:${e}`)
313
+ }), /* @__PURE__ */ p(e, {
314
+ variant: "solid",
315
+ tone: "primary",
316
+ agent: "products-create",
317
+ onPress: () => n?.("products:create"),
318
+ children: "Create"
319
+ })]
320
+ }),
321
+ /* @__PURE__ */ m(s, {
322
+ style: "caption",
323
+ tone: "muted",
324
+ children: [
325
+ t.productSearch ? `search "${t.productSearch}"` : "all products",
326
+ " ",
327
+ "| page ",
328
+ t.productsPage,
329
+ " of ",
330
+ o,
331
+ " |",
332
+ " ",
333
+ t.productsTotal,
334
+ " total"
335
+ ]
336
+ }),
337
+ t.products.length === 0 ? /* @__PURE__ */ p(s, {
338
+ tone: "muted",
339
+ align: "center",
340
+ style: "caption",
341
+ children: "None"
342
+ }) : /* @__PURE__ */ p(a, {
343
+ gap: 0,
344
+ width: "100%",
345
+ children: t.products.slice(0, 6).map((e) => /* @__PURE__ */ m(i, {
346
+ gap: 1,
347
+ align: "center",
348
+ width: "100%",
349
+ children: [
350
+ /* @__PURE__ */ p(s, {
351
+ tone: x(e.status),
352
+ children: e.status === "ACTIVE" ? "+" : e.status === "DRAFT" ? "." : "x"
353
+ }),
354
+ /* @__PURE__ */ m(c, {
355
+ gap: 0,
356
+ grow: 1,
357
+ children: [/* @__PURE__ */ p(s, {
358
+ bold: !0,
359
+ wrap: !1,
360
+ children: e.title
361
+ }), /* @__PURE__ */ p(s, {
362
+ style: "caption",
363
+ tone: "muted",
364
+ wrap: !1,
365
+ children: e.vendor || e.productType || "uncategorized"
366
+ })]
367
+ }),
368
+ /* @__PURE__ */ p(s, {
369
+ wrap: !1,
370
+ children: e.priceRange.min === e.priceRange.max ? e.priceRange.min : `${e.priceRange.min}-${e.priceRange.max}`
371
+ })
372
+ ]
373
+ }, e.id))
374
+ }),
375
+ t.productsTotal > T ? /* @__PURE__ */ m(i, {
376
+ gap: 1,
377
+ align: "center",
378
+ width: "100%",
379
+ children: [/* @__PURE__ */ p(e, {
380
+ variant: "outline",
381
+ tone: "default",
382
+ agent: "products-prev-page",
383
+ disabled: t.productsPage <= 1,
384
+ onPress: () => n?.("products:prev-page"),
385
+ children: "Prev"
386
+ }), /* @__PURE__ */ p(e, {
387
+ variant: "outline",
388
+ tone: "default",
389
+ agent: "products-next-page",
390
+ disabled: t.productsPage >= o,
391
+ onPress: () => n?.("products:next-page"),
392
+ children: "Next"
393
+ })]
394
+ }) : null
395
+ ]
396
+ });
397
+ }
398
+ var D = [
399
+ {
400
+ id: "any",
401
+ label: "All"
402
+ },
403
+ {
404
+ id: "unfulfilled",
405
+ label: "Unfulfilled"
406
+ },
407
+ {
408
+ id: "fulfilled",
409
+ label: "Fulfilled"
410
+ }
411
+ ];
412
+ function O({ snapshot: t, onAction: n }) {
413
+ return /* @__PURE__ */ m(c, {
414
+ gap: 1,
415
+ width: "100%",
416
+ children: [
417
+ /* @__PURE__ */ p(i, {
418
+ gap: 1,
419
+ wrap: !0,
420
+ width: "100%",
421
+ children: D.map((r) => /* @__PURE__ */ p(e, {
422
+ variant: t.orderStatusFilter === r.id ? "solid" : "outline",
423
+ tone: t.orderStatusFilter === r.id ? "primary" : "default",
424
+ agent: `orders-filter-${r.id}`,
425
+ onPress: () => n?.(`orders:filter:${r.id}`),
426
+ children: r.label
427
+ }, r.id))
428
+ }),
429
+ /* @__PURE__ */ m(s, {
430
+ style: "caption",
431
+ tone: "muted",
432
+ children: [
433
+ "filter ",
434
+ t.orderStatusFilter,
435
+ " | ",
436
+ t.ordersTotal,
437
+ " total"
438
+ ]
439
+ }),
440
+ t.orders.length === 0 ? /* @__PURE__ */ p(s, {
441
+ tone: "muted",
442
+ align: "center",
443
+ style: "caption",
444
+ children: "None"
445
+ }) : /* @__PURE__ */ p(a, {
446
+ gap: 0,
447
+ width: "100%",
448
+ children: t.orders.slice(0, 6).map((e) => /* @__PURE__ */ m(i, {
449
+ gap: 1,
450
+ align: "center",
451
+ width: "100%",
452
+ children: [
453
+ /* @__PURE__ */ p(s, {
454
+ bold: !0,
455
+ wrap: !1,
456
+ width: 9,
457
+ children: e.name
458
+ }),
459
+ /* @__PURE__ */ p(s, {
460
+ style: "caption",
461
+ tone: b(e.financialStatus),
462
+ wrap: !1,
463
+ grow: 1,
464
+ children: e.financialStatus.toLowerCase()
465
+ }),
466
+ /* @__PURE__ */ m(s, {
467
+ wrap: !1,
468
+ children: [
469
+ e.totalPrice,
470
+ " ",
471
+ e.currencyCode
472
+ ]
473
+ })
474
+ ]
475
+ }, e.id))
476
+ })
477
+ ]
478
+ });
479
+ }
480
+ function k({ snapshot: e }) {
481
+ return /* @__PURE__ */ m(c, {
482
+ gap: 1,
483
+ width: "100%",
484
+ children: [/* @__PURE__ */ m(s, {
485
+ style: "caption",
486
+ tone: "muted",
487
+ children: [
488
+ e.inventoryItems.length,
489
+ " rows |",
490
+ " ",
491
+ e.inventoryLocations.length,
492
+ " locations"
493
+ ]
494
+ }), e.inventoryItems.length === 0 ? /* @__PURE__ */ p(s, {
495
+ tone: "muted",
496
+ align: "center",
497
+ style: "caption",
498
+ children: "None"
499
+ }) : /* @__PURE__ */ p(a, {
500
+ gap: 0,
501
+ width: "100%",
502
+ children: e.inventoryItems.slice(0, 6).map((e) => /* @__PURE__ */ m(i, {
503
+ gap: 1,
504
+ align: "center",
505
+ width: "100%",
506
+ children: [
507
+ /* @__PURE__ */ m(c, {
508
+ gap: 0,
509
+ grow: 1,
510
+ children: [/* @__PURE__ */ m(s, {
511
+ bold: !0,
512
+ wrap: !1,
513
+ children: [e.productTitle, e.variantTitle ? ` / ${e.variantTitle}` : ""]
514
+ }), /* @__PURE__ */ p(s, {
515
+ style: "caption",
516
+ tone: "muted",
517
+ wrap: !1,
518
+ children: e.locationName
519
+ })]
520
+ }),
521
+ /* @__PURE__ */ p(s, {
522
+ tone: S(e.available),
523
+ bold: !0,
524
+ children: e.available
525
+ }),
526
+ /* @__PURE__ */ m(s, {
527
+ style: "caption",
528
+ tone: "muted",
529
+ children: ["+", e.incoming]
530
+ })
531
+ ]
532
+ }, `${e.id}:${e.locationName}`))
533
+ })]
534
+ });
535
+ }
536
+ function A({ snapshot: e, onAction: t }) {
537
+ return /* @__PURE__ */ m(c, {
538
+ gap: 1,
539
+ width: "100%",
540
+ children: [
541
+ /* @__PURE__ */ p(r, {
542
+ label: "Search customers",
543
+ placeholder: "filter by name or email",
544
+ value: e.customerSearch,
545
+ agent: "customers-search",
546
+ onChange: (e) => t?.(`customers:search:${e}`)
547
+ }),
548
+ /* @__PURE__ */ m(s, {
549
+ style: "caption",
550
+ tone: "muted",
551
+ children: [
552
+ e.customerSearch ? `search "${e.customerSearch}"` : "all customers",
553
+ " ",
554
+ "| ",
555
+ e.customersTotal,
556
+ " total"
557
+ ]
558
+ }),
559
+ e.customers.length === 0 ? /* @__PURE__ */ p(s, {
560
+ tone: "muted",
561
+ align: "center",
562
+ style: "caption",
563
+ children: "None"
564
+ }) : /* @__PURE__ */ p(a, {
565
+ gap: 0,
566
+ width: "100%",
567
+ children: e.customers.slice(0, 6).map((e) => /* @__PURE__ */ m(i, {
568
+ gap: 1,
569
+ align: "center",
570
+ width: "100%",
571
+ children: [
572
+ /* @__PURE__ */ m(c, {
573
+ gap: 0,
574
+ grow: 1,
575
+ children: [/* @__PURE__ */ p(s, {
576
+ bold: !0,
577
+ wrap: !1,
578
+ children: `${e.firstName} ${e.lastName}`.trim() || e.email || "Customer"
579
+ }), /* @__PURE__ */ p(s, {
580
+ style: "caption",
581
+ tone: "muted",
582
+ wrap: !1,
583
+ children: e.email
584
+ })]
585
+ }),
586
+ /* @__PURE__ */ m(s, {
587
+ style: "caption",
588
+ tone: "muted",
589
+ wrap: !1,
590
+ children: [e.ordersCount, " orders"]
591
+ }),
592
+ /* @__PURE__ */ m(s, {
593
+ wrap: !1,
594
+ children: [
595
+ e.totalSpent,
596
+ " ",
597
+ e.currencyCode
598
+ ]
599
+ })
600
+ ]
601
+ }, e.id))
602
+ })
603
+ ]
604
+ });
605
+ }
606
+ function j({ snapshot: e, onAction: t }) {
607
+ switch (e.tab) {
608
+ case "products": return /* @__PURE__ */ p(E, {
609
+ snapshot: e,
610
+ onAction: t
611
+ });
612
+ case "orders": return /* @__PURE__ */ p(O, {
613
+ snapshot: e,
614
+ onAction: t
615
+ });
616
+ case "inventory": return /* @__PURE__ */ p(k, { snapshot: e });
617
+ case "customers": return /* @__PURE__ */ p(A, {
618
+ snapshot: e,
619
+ onAction: t
620
+ });
621
+ default: return /* @__PURE__ */ p(w, {
622
+ snapshot: e,
623
+ onAction: t
624
+ });
625
+ }
626
+ }
627
+ function M({ snapshot: r, onAction: a }) {
628
+ let o = (e) => () => a?.(e), c = r.status?.connected ?? !1, l = r.status?.shop ?? null;
629
+ return /* @__PURE__ */ m(t, {
630
+ gap: 1,
631
+ padding: 1,
632
+ children: [
633
+ /* @__PURE__ */ m(i, {
634
+ gap: 1,
635
+ align: "center",
636
+ width: "100%",
637
+ children: [/* @__PURE__ */ p(s, {
638
+ style: "caption",
639
+ tone: c ? "success" : "danger",
640
+ wrap: !1,
641
+ children: c ? "connected" : "offline"
642
+ }), /* @__PURE__ */ p(s, {
643
+ style: "caption",
644
+ tone: "muted",
645
+ grow: 1,
646
+ align: "end",
647
+ wrap: !1,
648
+ children: r.loading ? "loading" : l?.name ?? "no shop"
649
+ })]
650
+ }),
651
+ /* @__PURE__ */ p(s, {
652
+ style: "caption",
653
+ tone: "muted",
654
+ width: "100%",
655
+ wrap: !1,
656
+ children: l?.domain ?? "no domain"
657
+ }),
658
+ r.error ? /* @__PURE__ */ p(s, {
659
+ tone: "danger",
660
+ style: "caption",
661
+ children: r.error
662
+ }) : null,
663
+ !c && !r.loading ? /* @__PURE__ */ p(s, {
664
+ tone: "muted",
665
+ style: "caption",
666
+ children: "Set SHOPIFY_STORE_DOMAIN and SHOPIFY_ACCESS_TOKEN for live data."
667
+ }) : null,
668
+ /* @__PURE__ */ m(i, {
669
+ gap: 1,
670
+ wrap: !0,
671
+ width: "100%",
672
+ children: [y.map((t) => /* @__PURE__ */ p(e, {
673
+ variant: r.tab === t.id ? "solid" : "outline",
674
+ tone: r.tab === t.id ? "primary" : "default",
675
+ agent: `tab-${t.id}`,
676
+ onPress: o(`tab:${t.id}`),
677
+ children: t.label
678
+ }, t.id)), /* @__PURE__ */ p(e, {
679
+ variant: "ghost",
680
+ tone: "default",
681
+ agent: "refresh",
682
+ onPress: o("refresh"),
683
+ children: "Refresh"
684
+ })]
685
+ }),
686
+ /* @__PURE__ */ p(n, { label: r.tab }),
687
+ /* @__PURE__ */ p(j, {
688
+ snapshot: r,
689
+ onAction: a
690
+ })
691
+ ]
692
+ });
693
+ }
694
+ //#endregion
695
+ //#region src/useShopifyDashboard.ts
696
+ var N = 20, P = 3e4;
697
+ async function F(e) {
698
+ let t = await fetch(e);
699
+ if (t.status === 404) return null;
700
+ if (!t.ok) {
701
+ let e = await t.text().catch(() => "Unknown error");
702
+ throw Error(`${t.status}: ${e}`);
703
+ }
704
+ return t.json();
705
+ }
706
+ function I() {
707
+ let [e, t] = f(null), [n, r] = f(!0), [i, a] = f(null), [o, s] = f(null), [c, p] = f(!1), [m, h] = f(null), [g, _] = f(1), [v, y] = f(""), [b, x] = f(null), [S, C] = f(!1), [w, T] = f(null), [E, D] = f("any"), [O, k] = f(null), [A, j] = f(!1), [M, I] = f(null), [L, R] = f(null), [z, B] = f(!1), [V, H] = f(null), [U, W] = f(""), [G, K] = f(0), q = d(null), J = l(() => {
708
+ K((e) => e + 1);
709
+ }, []);
710
+ u(() => (q.current = setInterval(J, P), () => {
711
+ q.current !== null && clearInterval(q.current);
712
+ }), [J]), u(() => {
713
+ let e = !1;
714
+ return r(!0), a(null), F("/api/shopify/status").then((n) => {
715
+ e || t(n ?? {
716
+ connected: !1,
717
+ shop: null
718
+ });
719
+ }).catch((n) => {
720
+ e || (a(n instanceof Error ? n.message : "Failed to load Shopify status."), t({
721
+ connected: !1,
722
+ shop: null
723
+ }));
724
+ }).finally(() => {
725
+ e || r(!1);
726
+ }), () => {
727
+ e = !0;
728
+ };
729
+ }, [G]);
730
+ let Y = e?.connected ?? !1;
731
+ u(() => {
732
+ if (!Y) return;
733
+ let e = !1;
734
+ return p(!0), h(null), F(`/api/shopify/products?${new URLSearchParams({
735
+ page: String(g),
736
+ limit: String(N),
737
+ q: v
738
+ })}`).then((t) => {
739
+ e || s(t ?? {
740
+ products: [],
741
+ total: 0,
742
+ page: g,
743
+ pageSize: N
744
+ });
745
+ }).catch((t) => {
746
+ e || h(t instanceof Error ? t.message : "Failed to load products.");
747
+ }).finally(() => {
748
+ e || p(!1);
749
+ }), () => {
750
+ e = !0;
751
+ };
752
+ }, [
753
+ Y,
754
+ g,
755
+ v,
756
+ G
757
+ ]), u(() => {
758
+ if (!Y) return;
759
+ let e = !1;
760
+ return C(!0), T(null), F(`/api/shopify/orders?${new URLSearchParams({
761
+ status: E,
762
+ limit: String(N)
763
+ })}`).then((t) => {
764
+ e || x(t ?? {
765
+ orders: [],
766
+ total: 0
767
+ });
768
+ }).catch((t) => {
769
+ e || T(t instanceof Error ? t.message : "Failed to load orders.");
770
+ }).finally(() => {
771
+ e || C(!1);
772
+ }), () => {
773
+ e = !0;
774
+ };
775
+ }, [
776
+ Y,
777
+ E,
778
+ G
779
+ ]), u(() => {
780
+ if (!Y) return;
781
+ let e = !1;
782
+ return j(!0), I(null), F("/api/shopify/inventory").then((t) => {
783
+ e || k(t ?? {
784
+ items: [],
785
+ locations: []
786
+ });
787
+ }).catch((t) => {
788
+ e || I(t instanceof Error ? t.message : "Failed to load inventory.");
789
+ }).finally(() => {
790
+ e || j(!1);
791
+ }), () => {
792
+ e = !0;
793
+ };
794
+ }, [Y, G]), u(() => {
795
+ if (!Y) return;
796
+ let e = !1;
797
+ return B(!0), H(null), F(`/api/shopify/customers?${new URLSearchParams({
798
+ q: U,
799
+ limit: String(N)
800
+ })}`).then((t) => {
801
+ e || R(t ?? {
802
+ customers: [],
803
+ total: 0
804
+ });
805
+ }).catch((t) => {
806
+ e || H(t instanceof Error ? t.message : "Failed to load customers.");
807
+ }).finally(() => {
808
+ e || B(!1);
809
+ }), () => {
810
+ e = !0;
811
+ };
812
+ }, [
813
+ Y,
814
+ U,
815
+ G
816
+ ]);
817
+ let X = {
818
+ productCount: o?.total ?? 0,
819
+ orderCount: b?.total ?? 0,
820
+ customerCount: L?.total ?? 0
821
+ };
822
+ return {
823
+ status: e,
824
+ statusLoading: n,
825
+ statusError: i,
826
+ products: o?.products ?? [],
827
+ productsTotal: o?.total ?? 0,
828
+ productsPage: g,
829
+ productsLoading: c,
830
+ productsError: m,
831
+ productSearch: v,
832
+ setProductSearch: y,
833
+ setProductsPage: _,
834
+ orders: b?.orders ?? [],
835
+ ordersTotal: b?.total ?? 0,
836
+ ordersLoading: S,
837
+ ordersError: w,
838
+ orderStatusFilter: E,
839
+ setOrderStatusFilter: D,
840
+ inventoryItems: O?.items ?? [],
841
+ inventoryLocations: O?.locations ?? [],
842
+ inventoryLoading: A,
843
+ inventoryError: M,
844
+ customers: L?.customers ?? [],
845
+ customersTotal: L?.total ?? 0,
846
+ customersLoading: z,
847
+ customersError: V,
848
+ customerSearch: U,
849
+ setCustomerSearch: W,
850
+ counts: X,
851
+ refresh: J
852
+ };
853
+ }
854
+ //#endregion
855
+ //#region src/ShopifyView.tsx
856
+ function L() {
857
+ let [e, t] = f("overview"), [n, r] = f(""), [i, a] = f(null), { status: s, statusLoading: c, statusError: u, products: d, productsTotal: m, productsPage: h, productsLoading: g, productsError: _, productSearch: v, setProductSearch: y, setProductsPage: b, orders: x, ordersTotal: S, ordersLoading: C, ordersError: w, orderStatusFilter: T, setOrderStatusFilter: E, inventoryItems: D, inventoryLocations: O, inventoryLoading: k, inventoryError: A, customers: j, customersTotal: N, customersLoading: P, customersError: F, customerSearch: L, setCustomerSearch: R, counts: z, refresh: B } = I(), V = l(async () => {
858
+ let e = n.trim();
859
+ if (!e) {
860
+ a("Enter a product title.");
861
+ return;
862
+ }
863
+ a(null);
864
+ try {
865
+ let t = await fetch("/api/shopify/products", {
866
+ method: "POST",
867
+ headers: { "Content-Type": "application/json" },
868
+ body: JSON.stringify({ title: e })
869
+ });
870
+ if (!t.ok) {
871
+ let e = await t.text().catch(() => "Unknown error");
872
+ throw Error(e);
873
+ }
874
+ r(""), B();
875
+ } catch (e) {
876
+ a(e instanceof Error ? e.message : "Failed to create product.");
877
+ }
878
+ }, [n, B]), H = l((e) => {
879
+ if (e.startsWith("tab:")) {
880
+ t(e.slice(4));
881
+ return;
882
+ }
883
+ if (e.startsWith("products:search:")) {
884
+ b(1), y(e.slice(16));
885
+ return;
886
+ }
887
+ if (e.startsWith("products:create-title:")) {
888
+ a(null), r(e.slice(22));
889
+ return;
890
+ }
891
+ if (e.startsWith("orders:filter:")) {
892
+ E(e.slice(14));
893
+ return;
894
+ }
895
+ if (e.startsWith("customers:search:")) {
896
+ R(e.slice(17));
897
+ return;
898
+ }
899
+ switch (e) {
900
+ case "products:create":
901
+ V();
902
+ return;
903
+ case "products:prev-page":
904
+ b(Math.max(1, h - 1));
905
+ return;
906
+ case "products:next-page":
907
+ b(h + 1);
908
+ return;
909
+ case "refresh":
910
+ B();
911
+ return;
912
+ }
913
+ }, [
914
+ V,
915
+ h,
916
+ B,
917
+ R,
918
+ E,
919
+ y,
920
+ b
921
+ ]);
922
+ return /* @__PURE__ */ p(o, { children: /* @__PURE__ */ p(M, {
923
+ snapshot: {
924
+ status: s,
925
+ tab: e,
926
+ counts: z,
927
+ products: d,
928
+ productsTotal: m,
929
+ productsPage: h,
930
+ productSearch: v,
931
+ orders: x,
932
+ ordersTotal: S,
933
+ orderStatusFilter: T,
934
+ inventoryItems: D,
935
+ inventoryLocations: O,
936
+ customers: j,
937
+ customersTotal: N,
938
+ customerSearch: L,
939
+ loading: c || g || C || k || P,
940
+ error: i ?? u ?? _ ?? w ?? A ?? F
941
+ },
942
+ onAction: H
943
+ }) });
944
+ }
945
+ //#endregion
946
+ export { L as ShopifyView, v as interact };
947
+
948
+ //# sourceMappingURL=bundle.js.map