arky-sdk 0.9.0 → 0.9.11

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 (43) hide show
  1. package/README.md +113 -194
  2. package/dist/admin-BKXmDIVk.d.ts +1396 -0
  3. package/dist/admin-CAwQrMOX.d.cts +1396 -0
  4. package/dist/admin.cjs +1239 -455
  5. package/dist/admin.cjs.map +1 -1
  6. package/dist/admin.d.cts +3 -3
  7. package/dist/admin.d.ts +3 -3
  8. package/dist/admin.js +1239 -455
  9. package/dist/admin.js.map +1 -1
  10. package/dist/api-DJI3S6XA.d.cts +4204 -0
  11. package/dist/api-DJI3S6XA.d.ts +4204 -0
  12. package/dist/{index-C5gikdBg.d.cts → index-BaSBPLdF.d.ts} +1 -1
  13. package/dist/{index-MFMjlIfS.d.ts → index-u-gjHnKs.d.cts} +1 -1
  14. package/dist/index.cjs +1360 -610
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +3 -3
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.js +1360 -610
  19. package/dist/index.js.map +1 -1
  20. package/dist/storefront.cjs +590 -382
  21. package/dist/storefront.cjs.map +1 -1
  22. package/dist/storefront.d.cts +182 -156
  23. package/dist/storefront.d.ts +182 -156
  24. package/dist/storefront.js +588 -381
  25. package/dist/storefront.js.map +1 -1
  26. package/dist/types.cjs.map +1 -1
  27. package/dist/types.d.cts +1 -2666
  28. package/dist/types.d.ts +1 -2666
  29. package/dist/types.js.map +1 -1
  30. package/dist/utils.d.cts +2 -2
  31. package/dist/utils.d.ts +2 -2
  32. package/package.json +9 -11
  33. package/scripts/contract-admin.mjs +137 -0
  34. package/scripts/contract-storefront.mjs +296 -0
  35. package/dist/admin-CfHen7c5.d.cts +0 -1036
  36. package/dist/admin-ru7pX5bd.d.ts +0 -1036
  37. package/dist/storefront-store.cjs +0 -2794
  38. package/dist/storefront-store.cjs.map +0 -1
  39. package/dist/storefront-store.d.cts +0 -5
  40. package/dist/storefront-store.d.ts +0 -5
  41. package/dist/storefront-store.js +0 -2792
  42. package/dist/storefront-store.js.map +0 -1
  43. package/scripts/smoke-store.mjs +0 -41
@@ -0,0 +1,296 @@
1
+ #!/usr/bin/env node
2
+ import assert from "node:assert/strict";
3
+ import { initialize } from "../dist/storefront.js";
4
+
5
+ const store = initialize({
6
+ baseUrl: "http://127.0.0.1:1",
7
+ storeId: "contract-store",
8
+ market: "us",
9
+ locale: "en",
10
+ });
11
+
12
+ assert.equal(typeof store.cart.load, "function");
13
+ assert.equal(store.cart, store.eshop.cart);
14
+ assert.equal(typeof store.cart.refresh, "function");
15
+ assert.equal(typeof store.setContext, "function");
16
+ assert.equal(typeof store.me, "function");
17
+ assert.equal(typeof store.onAuthStateChanged, "function");
18
+ assert.equal(store.session.get(), null);
19
+ assert.equal(store.isAuthenticated, false);
20
+ store.setContext({ locale: "en", market: "us" });
21
+ assert.equal(store.getLocale(), "en");
22
+ assert.equal(store.getMarket(), "us");
23
+ assert.equal(typeof store.cms.entry.get, "function");
24
+ assert.equal(typeof store.cms.entry.find, "function");
25
+ assert.equal(typeof store.action.pageView, "function");
26
+ assert.equal(typeof store.eshop.cart.load, "function");
27
+ assert.equal(typeof store.eshop.cart.checkout, "function");
28
+ assert.equal(typeof store.eshop.cart.payment, "object");
29
+ assert.equal(typeof store.eshop.cart.payment.setController, "function");
30
+ assert.equal(typeof store.eshop.cart.payment.getController, "function");
31
+ assert.equal(typeof store.eshop.cart.payment.mountStripe, "function");
32
+ assert.equal(typeof store.eshop.cart.payment.update, "function");
33
+ assert.equal(typeof store.eshop.cart.payment.destroy, "function");
34
+ assert.equal(typeof store.eshop.product.list, "function");
35
+ assert.equal(typeof store.eshop.product.loadDetail, "function");
36
+ assert.equal(typeof store.eshop.service.listProviders, "function");
37
+ assert.equal(typeof store.eshop.service.initialize, "function");
38
+ assert.equal(typeof store.eshop.service.select, "function");
39
+ const removedServiceModuleName = "service" + "Order";
40
+ assert.equal(removedServiceModuleName in store.eshop, false, "scheduled service controls belong under eshop.service");
41
+ assert.equal(store.eshop.cart.product_items.get().length, 0);
42
+ assert.equal(store.eshop.service.state.get().cart.length, 0);
43
+
44
+ const fetchCalls = [];
45
+ const originalFetch = globalThis.fetch;
46
+ globalThis.fetch = async (url, init = {}) => {
47
+ fetchCalls.push({
48
+ url: String(url),
49
+ method: init.method,
50
+ body: init.body,
51
+ });
52
+ return new Response(JSON.stringify({ success: true }), {
53
+ status: 200,
54
+ headers: { "content-type": "application/json" },
55
+ });
56
+ };
57
+
58
+ try {
59
+ const unsubscribe = await store.crm.contactList.unsubscribe("unsubscribe-token");
60
+ const confirm = await store.crm.contactList.confirm("confirm-token");
61
+ assert.deepEqual(unsubscribe, { success: true });
62
+ assert.deepEqual(confirm, { success: true });
63
+ } finally {
64
+ globalThis.fetch = originalFetch;
65
+ }
66
+
67
+ assert.equal(fetchCalls[0].method, "POST");
68
+ assert.equal(
69
+ fetchCalls[0].url,
70
+ "http://127.0.0.1:1/v1/storefront/contract-store/contact-lists/unsubscribe",
71
+ );
72
+ assert.deepEqual(JSON.parse(fetchCalls[0].body), { token: "unsubscribe-token" });
73
+ assert.equal(fetchCalls[1].method, "POST");
74
+ assert.equal(
75
+ fetchCalls[1].url,
76
+ "http://127.0.0.1:1/v1/storefront/contract-store/contact-lists/confirm",
77
+ );
78
+ assert.deepEqual(JSON.parse(fetchCalls[1].body), { token: "confirm-token" });
79
+
80
+ const checkoutFetchCalls = [];
81
+ const paymentCalls = [];
82
+ const storedController = {
83
+ mount() {
84
+ paymentCalls.push(["mount"]);
85
+ },
86
+ update(input) {
87
+ paymentCalls.push(["update", input]);
88
+ },
89
+ async createConfirmationToken(options) {
90
+ paymentCalls.push(["token", options]);
91
+ return {
92
+ confirmation_token_id: "ct_store_owned",
93
+ return_url: options?.return_url,
94
+ };
95
+ },
96
+ async handleNextAction(clientSecret) {
97
+ paymentCalls.push(["next_action", clientSecret]);
98
+ },
99
+ destroy() {
100
+ paymentCalls.push(["destroy"]);
101
+ },
102
+ };
103
+
104
+ const quoteSnapshot = {
105
+ market: "us",
106
+ zone: null,
107
+ items: [],
108
+ shipping_lines: [],
109
+ subtotal: 1000,
110
+ shipping: 0,
111
+ discount: 0,
112
+ tax: 0,
113
+ total: 1000,
114
+ shipping_method: null,
115
+ payment_method: null,
116
+ payment_methods: [{ id: "pm_card", key: "credit_card", type: "credit_card", name: "Card" }],
117
+ promo_code: null,
118
+ payment: {
119
+ id: "payment_quote",
120
+ status: "pending",
121
+ total: 1000,
122
+ currency: "usd",
123
+ payment_method_key: "credit_card",
124
+ method_type: "credit_card",
125
+ },
126
+ charge_amount: 1000,
127
+ };
128
+
129
+ const cartSnapshot = {
130
+ id: "cart_contract",
131
+ store_id: "contract-store",
132
+ contact_id: "contact_contract",
133
+ token: "cart-token",
134
+ status: "active",
135
+ origin: "storefront",
136
+ market: "us",
137
+ items: [],
138
+ shipping_address: null,
139
+ billing_address: null,
140
+ forms: [],
141
+ promo_code: null,
142
+ payment_method_key: "credit_card",
143
+ shipping_method_id: null,
144
+ quote_snapshot: quoteSnapshot,
145
+ converted_order_id: null,
146
+ item_count: 1,
147
+ last_action_at: 1,
148
+ created_at: 1,
149
+ updated_at: 1,
150
+ };
151
+
152
+ store.eshop.cart.cart.set(cartSnapshot);
153
+
154
+ globalThis.fetch = async (url, init = {}) => {
155
+ checkoutFetchCalls.push({
156
+ url: String(url),
157
+ method: init.method,
158
+ body: init.body,
159
+ });
160
+ if (String(url).endsWith("/actions/track")) {
161
+ throw new Error("commerce cart helpers must not call generic action tracking");
162
+ }
163
+ if (String(url).endsWith("/carts/cart_contract/items")) {
164
+ return new Response(JSON.stringify(cartSnapshot), {
165
+ status: 200,
166
+ headers: { "content-type": "application/json" },
167
+ });
168
+ }
169
+ if (String(url).endsWith("/carts/cart_contract/items/remove")) {
170
+ return new Response(JSON.stringify(cartSnapshot), {
171
+ status: 200,
172
+ headers: { "content-type": "application/json" },
173
+ });
174
+ }
175
+ throw new Error(`Unexpected cart mutation contract request: ${url}`);
176
+ };
177
+
178
+ try {
179
+ await store.eshop.cart.addProduct(
180
+ { id: "product_contract" },
181
+ { id: "variant_contract" },
182
+ 1,
183
+ );
184
+ store.eshop.cart.product_items.set([
185
+ {
186
+ id: "line_contract",
187
+ product_id: "product_contract",
188
+ variant_id: "variant_contract",
189
+ product_name: "Contract product",
190
+ product_slug: "contract-product",
191
+ variant_attributes: {},
192
+ requires_shipping: false,
193
+ price: { amount: 1000, currency: "usd", market: "us" },
194
+ quantity: 1,
195
+ added_at: 1,
196
+ },
197
+ ]);
198
+ await store.eshop.cart.removeProduct("line_contract");
199
+ } finally {
200
+ globalThis.fetch = originalFetch;
201
+ }
202
+ assert.deepEqual(
203
+ checkoutFetchCalls
204
+ .filter((call) => call.url.endsWith("/actions/track"))
205
+ .map((call) => call.url),
206
+ [],
207
+ "cart mutations should rely on backend commerce actions instead of generic action tracking",
208
+ );
209
+ checkoutFetchCalls.length = 0;
210
+
211
+ store.eshop.cart.product_items.set([
212
+ {
213
+ id: "line_contract",
214
+ product_id: "product_contract",
215
+ variant_id: "variant_contract",
216
+ product_name: "Contract product",
217
+ product_slug: "contract-product",
218
+ variant_attributes: {},
219
+ requires_shipping: false,
220
+ price: { amount: 1000, currency: "usd", market: "us" },
221
+ quantity: 1,
222
+ added_at: 1,
223
+ },
224
+ ]);
225
+ store.eshop.cart.payment.setController(storedController);
226
+ assert.equal(store.eshop.cart.payment.getController(), storedController);
227
+
228
+ globalThis.fetch = async (url, init = {}) => {
229
+ checkoutFetchCalls.push({
230
+ url: String(url),
231
+ method: init.method,
232
+ body: init.body,
233
+ });
234
+ if (String(url).endsWith("/actions/track")) {
235
+ throw new Error("checkout must not call generic action tracking");
236
+ }
237
+ if (String(url).endsWith("/carts/cart_contract")) {
238
+ return new Response(JSON.stringify(cartSnapshot), {
239
+ status: 200,
240
+ headers: { "content-type": "application/json" },
241
+ });
242
+ }
243
+ if (String(url).endsWith("/carts/cart_contract/checkout")) {
244
+ const body = JSON.parse(init.body);
245
+ assert.equal(body.payment_method_key, "credit_card");
246
+ assert.equal(body.confirmation_token_id, "ct_store_owned");
247
+ return new Response(JSON.stringify({
248
+ order_id: "order_contract",
249
+ number: "1001",
250
+ payment_action: { type: "handle_next_action", client_secret: "pi_secret_contract" },
251
+ payment: {
252
+ id: "payment_contract",
253
+ status: "pending",
254
+ total: 1000,
255
+ currency: "usd",
256
+ payment_method_key: "credit_card",
257
+ method_type: "credit_card",
258
+ },
259
+ }), {
260
+ status: 200,
261
+ headers: { "content-type": "application/json" },
262
+ });
263
+ }
264
+ throw new Error(`Unexpected checkout contract request: ${url}`);
265
+ };
266
+
267
+ try {
268
+ const result = await store.eshop.cart.checkout({
269
+ billing_details: { email: "checkout@example.com" },
270
+ });
271
+ assert.equal(result.order_id, "order_contract");
272
+ } finally {
273
+ globalThis.fetch = originalFetch;
274
+ }
275
+
276
+ assert.deepEqual(paymentCalls[0], [
277
+ "token",
278
+ {
279
+ return_url: undefined,
280
+ billing_details: { email: "checkout@example.com" },
281
+ },
282
+ ]);
283
+ assert.deepEqual(paymentCalls[1], ["next_action", "pi_secret_contract"]);
284
+ assert.equal(
285
+ checkoutFetchCalls.some((call) => call.url.endsWith("/carts/cart_contract/checkout")),
286
+ true,
287
+ );
288
+ assert.deepEqual(
289
+ checkoutFetchCalls
290
+ .filter((call) => call.url.endsWith("/actions/track"))
291
+ .map((call) => call.url),
292
+ [],
293
+ "checkout should rely on backend commerce actions instead of generic action tracking",
294
+ );
295
+
296
+ console.log("Storefront SDK contract test passed.");