arky-sdk 0.9.13 → 0.9.17

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 (40) hide show
  1. package/README.md +16 -12
  2. package/dist/admin-6xpHuyKc.d.cts +1544 -0
  3. package/dist/admin-DVFAgnHm.d.ts +1544 -0
  4. package/dist/admin.cjs +982 -425
  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 +982 -425
  9. package/dist/admin.js.map +1 -1
  10. package/dist/{api-DvsFdOaF.d.cts → api-DJrUdQ1C.d.cts} +1425 -657
  11. package/dist/{api-DvsFdOaF.d.ts → api-DJrUdQ1C.d.ts} +1425 -657
  12. package/dist/index.cjs +1317 -539
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +3 -3
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +1317 -539
  17. package/dist/index.js.map +1 -1
  18. package/dist/{index-CQd9b_7n.d.ts → inventory-DOwNF3D-.d.cts} +6 -4
  19. package/dist/{index-BC06yiuv.d.cts → inventory-GpWTZ2oe.d.ts} +6 -4
  20. package/dist/storefront.cjs +1210 -658
  21. package/dist/storefront.cjs.map +1 -1
  22. package/dist/storefront.d.cts +88 -285
  23. package/dist/storefront.d.ts +88 -285
  24. package/dist/storefront.js +1207 -659
  25. package/dist/storefront.js.map +1 -1
  26. package/dist/types.cjs.map +1 -1
  27. package/dist/types.d.cts +1 -1
  28. package/dist/types.d.ts +1 -1
  29. package/dist/types.js.map +1 -1
  30. package/dist/utils.cjs +198 -16
  31. package/dist/utils.cjs.map +1 -1
  32. package/dist/utils.d.cts +18 -2
  33. package/dist/utils.d.ts +18 -2
  34. package/dist/utils.js +191 -17
  35. package/dist/utils.js.map +1 -1
  36. package/package.json +4 -5
  37. package/dist/admin-Q9MBFwCb.d.cts +0 -1496
  38. package/dist/admin-ZLXD4_en.d.ts +0 -1496
  39. package/scripts/contract-admin.mjs +0 -120
  40. package/scripts/contract-storefront.mjs +0 -296
@@ -1,120 +0,0 @@
1
- #!/usr/bin/env node
2
- import assert from "node:assert/strict";
3
- import { createAdmin } from "../dist/admin.js";
4
-
5
- const arky = createAdmin({
6
- baseUrl: "http://127.0.0.1:1",
7
- storeId: "contract-store",
8
- apiToken: "contract-token",
9
- });
10
-
11
- assert.equal(typeof arky.account.auth.code, "function");
12
- assert.equal(typeof arky.account.auth.verify, "function");
13
- assert.equal(typeof arky.account.auth.refresh, "function");
14
- assert.equal(typeof arky.account.update, "function");
15
- assert.equal(typeof arky.account.delete, "function");
16
- assert.equal(typeof arky.account.getMe, "function");
17
- assert.equal(typeof arky.account.search, "function");
18
-
19
- assert.equal(typeof arky.store.create, "function");
20
- assert.equal(typeof arky.store.update, "function");
21
- assert.equal(typeof arky.store.delete, "function");
22
- assert.equal(typeof arky.store.get, "function");
23
- assert.equal(typeof arky.store.find, "function");
24
- assert.equal(typeof arky.store.subscription.getPlans, "function");
25
- assert.equal(typeof arky.store.subscription.subscribe, "function");
26
- assert.equal(typeof arky.store.subscription.createPortalSession, "function");
27
- assert.equal(typeof arky.store.member.add, "function");
28
- assert.equal(typeof arky.store.member.invite, "function");
29
- assert.equal(typeof arky.store.member.remove, "function");
30
- assert.equal(typeof arky.store.buildHook.list, "function");
31
- assert.equal(typeof arky.store.webhook.list, "function");
32
- assert.equal(typeof arky.store.config.get, "function");
33
- assert.equal(typeof arky.store.media.find, "function");
34
- assert.equal(typeof arky.store.paymentProvider.list, "function");
35
- assert.equal(typeof arky.store.paymentProvider.refresh, "function");
36
- assert.equal(typeof arky.store.paymentProvider.connectStripe, "function");
37
- assert.equal(typeof arky.store.paymentProvider.delete, "function");
38
-
39
- assert.equal(typeof arky.social.account.list, "function");
40
- assert.equal(typeof arky.social.account.connect, "function");
41
- assert.equal(typeof arky.social.account.getOAuthAttempt, "function");
42
- assert.equal(typeof arky.social.account.selectDestination, "function");
43
- assert.equal(typeof arky.social.account.delete, "function");
44
- assert.equal(typeof arky.social.publication.getComments, "function");
45
- assert.equal(typeof arky.social.publication.syncComments, "function");
46
- assert.equal(typeof arky.social.publication.getCommentThread, "function");
47
- assert.equal(typeof arky.social.publication.syncCommentThread, "function");
48
- assert.equal(typeof arky.social.publication.getMetrics, "function");
49
- assert.equal(typeof arky.social.publication.syncMetrics, "function");
50
-
51
- assert.equal(typeof arky.automation.workflow.listAccounts, "function");
52
- assert.equal(typeof arky.automation.workflow.getAccountConnectUrl, "function");
53
- assert.equal("connectAccount" in arky.automation.workflow, false);
54
- assert.equal(typeof arky.automation.workflow.deleteAccount, "function");
55
-
56
- const workflowFetchCalls = [];
57
- const originalFetch = globalThis.fetch;
58
- globalThis.fetch = async (url, init = {}) => {
59
- workflowFetchCalls.push({
60
- url: String(url),
61
- method: init.method,
62
- body: init.body,
63
- });
64
- return new Response(JSON.stringify({ authorization_url: "https://oauth.test", state: "state" }), {
65
- status: 200,
66
- headers: { "content-type": "application/json" },
67
- });
68
- };
69
-
70
- try {
71
- await arky.automation.workflow.getAccountConnectUrl({
72
- type: "google_drive",
73
- });
74
- } finally {
75
- globalThis.fetch = originalFetch;
76
- }
77
-
78
- assert.equal(workflowFetchCalls[0].method, "POST");
79
- assert.equal(
80
- workflowFetchCalls[0].url,
81
- "http://127.0.0.1:1/v1/stores/contract-store/workflow-accounts/connect-url",
82
- );
83
- assert.deepEqual(JSON.parse(workflowFetchCalls[0].body), {
84
- type: "google_drive",
85
- store_id: "contract-store",
86
- });
87
- assert.equal(workflowFetchCalls.length, 1);
88
-
89
- assert.equal(typeof arky.automation.support.createAgent, "function");
90
- assert.equal(typeof arky.automation.support.findAgents, "function");
91
- assert.equal(typeof arky.automation.support.findConversations, "function");
92
- assert.equal(typeof arky.automation.support.replyToConversation, "function");
93
- assert.equal("agent" in arky.automation.support, false);
94
- assert.equal("conversation" in arky.automation.support, false);
95
-
96
- assert.equal(typeof arky.notification.mailbox.find, "function");
97
- assert.equal(typeof arky.notification.email.trackOpen, "function");
98
- assert.equal(typeof arky.notification.trigger.send, "function");
99
- assert.equal("mailbox" in arky.crm, false);
100
-
101
- assert.equal(typeof arky.outreach.campaign.find, "function");
102
- assert.equal(typeof arky.outreach.campaignEnrollment.find, "function");
103
- assert.equal(typeof arky.outreach.campaignMessage.find, "function");
104
- assert.equal(typeof arky.outreach.suppression.find, "function");
105
- assert.equal(typeof arky.outreach.leadResearch.createRun, "function");
106
- assert.equal("campaign" in arky.crm, false);
107
- assert.equal("leadResearch" in arky.crm, false);
108
- assert.equal("leadResearch" in arky, false);
109
-
110
- assert.equal(typeof arky.crm.contactList.addMember, "function");
111
- assert.equal(typeof arky.crm.contactList.findMembers, "function");
112
- assert.equal("members" in arky.crm.contactList, false);
113
- assert.equal("contacts" in arky.crm.contactList, false);
114
-
115
- assert.equal(typeof arky.eshop.order.getShippingRates, "function");
116
- assert.equal(typeof arky.eshop.order.ship, "function");
117
- assert.equal("shipping" in arky, false);
118
- assert.equal("promoCode" in arky, false);
119
-
120
- console.log("Admin SDK contract test passed.");
@@ -1,296 +0,0 @@
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.");