@juo/blocks 1.20.1 → 1.22.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/dist/core.js +120 -44
- package/dist/services/login/adapter.d.ts +8 -1
- package/dist/services/login/adapter.d.ts.map +1 -1
- package/dist/services/login/errors.d.ts +6 -0
- package/dist/services/login/errors.d.ts.map +1 -1
- package/dist/services/login/index.d.ts +2 -2
- package/dist/services/login/index.d.ts.map +1 -1
- package/dist/services/login/loginService.d.ts.map +1 -1
- package/dist/services/orders/adapter.d.ts +10 -0
- package/dist/services/orders/adapter.d.ts.map +1 -1
- package/dist/services/orders/adapter.test.d.ts +2 -0
- package/dist/services/orders/adapter.test.d.ts.map +1 -0
- package/dist/services/orders/index.d.ts +3 -3
- package/dist/services/orders/index.d.ts.map +1 -1
- package/dist/services/orders/ordersService.d.ts.map +1 -1
- package/dist/services/orders/types.d.ts +31 -1
- package/dist/services/orders/types.d.ts.map +1 -1
- package/dist/services/schedules/adapter.d.ts.map +1 -1
- package/dist/services/simulateLatency.d.ts +7 -0
- package/dist/services/simulateLatency.d.ts.map +1 -0
- package/dist/services/subscription/adapter.d.ts.map +1 -1
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/vue/main.d.ts +1 -0
- package/dist/vue/main.d.ts.map +1 -1
- package/dist/vue/useLoginCooldown.d.ts +7 -0
- package/dist/vue/useLoginCooldown.d.ts.map +1 -0
- package/dist/vue/useLoginCooldown.test.d.ts +2 -0
- package/dist/vue/useLoginCooldown.test.d.ts.map +1 -0
- package/dist/vue.js +34 -0
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -234,6 +234,7 @@ function uuid() {
|
|
|
234
234
|
);
|
|
235
235
|
}
|
|
236
236
|
var AuthenticationErrorReason = /* @__PURE__ */ ((AuthenticationErrorReason2) => {
|
|
237
|
+
AuthenticationErrorReason2["RateLimited"] = "rate-limited";
|
|
237
238
|
AuthenticationErrorReason2["Expired"] = "expired";
|
|
238
239
|
AuthenticationErrorReason2["IncorrectCode"] = "wrong-code";
|
|
239
240
|
AuthenticationErrorReason2["TooManyTries"] = "too-many-tries";
|
|
@@ -251,6 +252,17 @@ class AuthenticationError extends Error {
|
|
|
251
252
|
this.data = data ?? {};
|
|
252
253
|
}
|
|
253
254
|
}
|
|
255
|
+
class RateLimitedError extends AuthenticationError {
|
|
256
|
+
constructor(retryAt) {
|
|
257
|
+
super(
|
|
258
|
+
"rate-limited"
|
|
259
|
+
/* RateLimited */
|
|
260
|
+
);
|
|
261
|
+
/** Epoch milliseconds before which the backend will refuse another login request. */
|
|
262
|
+
__publicField(this, "retryAt");
|
|
263
|
+
this.retryAt = retryAt;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
254
266
|
const OTP_ERROR_REASONS = {
|
|
255
267
|
INCORRECT_CODE: AuthenticationErrorReason.IncorrectCode,
|
|
256
268
|
TOO_MANY_TRIES: AuthenticationErrorReason.TooManyTries,
|
|
@@ -272,6 +284,15 @@ function authenticationErrorFromBody(data) {
|
|
|
272
284
|
const reason = OTP_ERROR_REASONS[code];
|
|
273
285
|
return reason == null ? void 0 : new AuthenticationError(reason);
|
|
274
286
|
}
|
|
287
|
+
function rateLimitErrorFromResponse(res) {
|
|
288
|
+
var _a;
|
|
289
|
+
if (res.status !== 429) {
|
|
290
|
+
return void 0;
|
|
291
|
+
}
|
|
292
|
+
const seconds = (_a = res.headers.get("Retry-After")) == null ? void 0 : _a.trim();
|
|
293
|
+
const delay2 = seconds && /^\d+$/.test(seconds) ? Number(seconds) * 1e3 : 6e4;
|
|
294
|
+
return new RateLimitedError(Date.now() + delay2);
|
|
295
|
+
}
|
|
275
296
|
function createMockLoginAdapter(opts = {}) {
|
|
276
297
|
const appUrl = opts.appUrl ?? "https://admin.juo.io";
|
|
277
298
|
return {
|
|
@@ -310,6 +331,8 @@ function createApiLoginAdapter(fetcher, opts) {
|
|
|
310
331
|
},
|
|
311
332
|
body: JSON.stringify(body)
|
|
312
333
|
});
|
|
334
|
+
const limited = rateLimitErrorFromResponse(res);
|
|
335
|
+
if (limited) throw limited;
|
|
313
336
|
if (res.status === 403) {
|
|
314
337
|
const error = authenticationErrorFromBody(await res.json());
|
|
315
338
|
if (error != null) {
|
|
@@ -345,6 +368,8 @@ function createApiLoginAdapter(fetcher, opts) {
|
|
|
345
368
|
},
|
|
346
369
|
body: JSON.stringify(params)
|
|
347
370
|
});
|
|
371
|
+
const limited = rateLimitErrorFromResponse(res);
|
|
372
|
+
if (limited) throw limited;
|
|
348
373
|
if (res.status === 403) {
|
|
349
374
|
const error = authenticationErrorFromBody(await res.json());
|
|
350
375
|
if (error != null) {
|
|
@@ -417,6 +442,12 @@ function loginService(deps) {
|
|
|
417
442
|
}
|
|
418
443
|
function createLoginService(init) {
|
|
419
444
|
const { adapter, formatError, router, shop, onLoginSuccess } = init;
|
|
445
|
+
function failure(error) {
|
|
446
|
+
return {
|
|
447
|
+
_tag: "Failure",
|
|
448
|
+
error: error instanceof RateLimitedError ? { ...formatError(error), retryAt: error.retryAt } : formatError(error)
|
|
449
|
+
};
|
|
450
|
+
}
|
|
420
451
|
const accessToken = d(null);
|
|
421
452
|
const delegatedToken = d(storage(STORAGE_DELEGATED_TOKEN));
|
|
422
453
|
const refreshToken = d(storage(STORAGE_REFRESH_TOKEN_KEY));
|
|
@@ -489,11 +520,11 @@ function createLoginService(init) {
|
|
|
489
520
|
lang
|
|
490
521
|
});
|
|
491
522
|
if (result._tag === "Failure") {
|
|
492
|
-
return
|
|
523
|
+
return failure(result.error);
|
|
493
524
|
}
|
|
494
525
|
return { _tag: "Success", data: void 0 };
|
|
495
526
|
} catch (error) {
|
|
496
|
-
return
|
|
527
|
+
return failure(error);
|
|
497
528
|
}
|
|
498
529
|
},
|
|
499
530
|
async verify(email, code) {
|
|
@@ -509,13 +540,13 @@ function createLoginService(init) {
|
|
|
509
540
|
code
|
|
510
541
|
});
|
|
511
542
|
if (result._tag === "Failure") {
|
|
512
|
-
return
|
|
543
|
+
return failure(result.error);
|
|
513
544
|
}
|
|
514
545
|
storeTokens(result.data);
|
|
515
546
|
await onSuccess();
|
|
516
547
|
return { _tag: "Success", data: void 0 };
|
|
517
548
|
} catch (error) {
|
|
518
|
-
return
|
|
549
|
+
return failure(error);
|
|
519
550
|
}
|
|
520
551
|
}
|
|
521
552
|
}
|
|
@@ -535,13 +566,13 @@ function createLoginService(init) {
|
|
|
535
566
|
try {
|
|
536
567
|
const result = await adapter.authenticate({ code });
|
|
537
568
|
if (result._tag === "Failure") {
|
|
538
|
-
return
|
|
569
|
+
return failure(result.error);
|
|
539
570
|
}
|
|
540
571
|
storeTokens(result.data);
|
|
541
572
|
await onSuccess();
|
|
542
573
|
return { _tag: "Success", data: void 0 };
|
|
543
574
|
} catch (error) {
|
|
544
|
-
return
|
|
575
|
+
return failure(error);
|
|
545
576
|
}
|
|
546
577
|
}
|
|
547
578
|
},
|
|
@@ -604,6 +635,14 @@ function createLoginService(init) {
|
|
|
604
635
|
return service;
|
|
605
636
|
}
|
|
606
637
|
const LoginServiceContext = createContext("services/login");
|
|
638
|
+
class OrderPayError extends Error {
|
|
639
|
+
constructor(status) {
|
|
640
|
+
super(`HTTP ${status}`);
|
|
641
|
+
__publicField(this, "status");
|
|
642
|
+
this.name = "OrderPayError";
|
|
643
|
+
this.status = status;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
607
646
|
function createMockOrdersAdapter() {
|
|
608
647
|
const mockOrders = [
|
|
609
648
|
{
|
|
@@ -637,7 +676,7 @@ function createMockOrdersAdapter() {
|
|
|
637
676
|
placedAt: "2024-09-20T14:15:00Z",
|
|
638
677
|
currencyCode: "USD",
|
|
639
678
|
totalPrice: 45.99,
|
|
640
|
-
financialStatus: "
|
|
679
|
+
financialStatus: "PENDING",
|
|
641
680
|
fulfillmentStatus: "PARTIALLY_FULFILLED",
|
|
642
681
|
lines: [
|
|
643
682
|
{
|
|
@@ -648,7 +687,14 @@ function createMockOrdersAdapter() {
|
|
|
648
687
|
customAttributes: []
|
|
649
688
|
}
|
|
650
689
|
],
|
|
651
|
-
customAttributes: []
|
|
690
|
+
customAttributes: [],
|
|
691
|
+
// Postpaid invoice between auto-charge attempts — theme preview shows
|
|
692
|
+
// the "Pay now" button and the "Next attempt on ..." line.
|
|
693
|
+
payment: {
|
|
694
|
+
state: "retry_scheduled",
|
|
695
|
+
nextAttemptAt: "2024-09-27T14:15:00Z",
|
|
696
|
+
actions: ["pay"]
|
|
697
|
+
}
|
|
652
698
|
}
|
|
653
699
|
];
|
|
654
700
|
return {
|
|
@@ -662,6 +708,9 @@ function createMockOrdersAdapter() {
|
|
|
662
708
|
endCursor: null
|
|
663
709
|
}
|
|
664
710
|
};
|
|
711
|
+
},
|
|
712
|
+
async payOrder(orderId) {
|
|
713
|
+
return { url: `https://example.com/mock-pay/${orderId}` };
|
|
665
714
|
}
|
|
666
715
|
};
|
|
667
716
|
}
|
|
@@ -671,7 +720,10 @@ function mapOrderLine(item) {
|
|
|
671
720
|
id: item.id,
|
|
672
721
|
title: item.title,
|
|
673
722
|
quantity: item.quantity,
|
|
674
|
-
variantImage: ((_a = item.variantImage) == null ? void 0 : _a.url) ? {
|
|
723
|
+
variantImage: ((_a = item.variantImage) == null ? void 0 : _a.url) ? {
|
|
724
|
+
url: item.variantImage.url,
|
|
725
|
+
altText: item.variantImage.altText ?? void 0
|
|
726
|
+
} : null,
|
|
675
727
|
customAttributes: item.customAttributes
|
|
676
728
|
};
|
|
677
729
|
}
|
|
@@ -685,7 +737,8 @@ function mapOrder(order) {
|
|
|
685
737
|
financialStatus: order.financialStatus,
|
|
686
738
|
fulfillmentStatus: order.fulfillmentStatus,
|
|
687
739
|
lines: order.items.map(mapOrderLine),
|
|
688
|
-
customAttributes: order.customAttributes
|
|
740
|
+
customAttributes: order.customAttributes,
|
|
741
|
+
payment: order.payment ?? null
|
|
689
742
|
};
|
|
690
743
|
}
|
|
691
744
|
function createApiOrdersAdapter(fetcher) {
|
|
@@ -696,7 +749,8 @@ function createApiOrdersAdapter(fetcher) {
|
|
|
696
749
|
if ((params == null ? void 0 : params.after) != null) query.set("after", params.after);
|
|
697
750
|
if ((params == null ? void 0 : params.before) != null) query.set("before", params.before);
|
|
698
751
|
if ((params == null ? void 0 : params.query) != null) query.set("query", params.query);
|
|
699
|
-
if ((params == null ? void 0 : params.includeOneTime) != null)
|
|
752
|
+
if ((params == null ? void 0 : params.includeOneTime) != null)
|
|
753
|
+
query.set("includeOneTime", String(params.includeOneTime));
|
|
700
754
|
if ((params == null ? void 0 : params.sort) != null) query.set("sort", params.sort);
|
|
701
755
|
const qs = query.toString();
|
|
702
756
|
const res = await fetcher(`/customer/v1/orders${qs ? `?${qs}` : ""}`);
|
|
@@ -711,6 +765,14 @@ function createApiOrdersAdapter(fetcher) {
|
|
|
711
765
|
endCursor: body.endCursor
|
|
712
766
|
}
|
|
713
767
|
};
|
|
768
|
+
},
|
|
769
|
+
async payOrder(orderId) {
|
|
770
|
+
const res = await fetcher(
|
|
771
|
+
`/customer/v1/orders/${encodeURIComponent(orderId)}/pay`,
|
|
772
|
+
{ method: "POST" }
|
|
773
|
+
);
|
|
774
|
+
if (!res.ok) throw new OrderPayError(res.status);
|
|
775
|
+
return await res.json();
|
|
714
776
|
}
|
|
715
777
|
};
|
|
716
778
|
}
|
|
@@ -723,6 +785,14 @@ function createOrdersService(adapter) {
|
|
|
723
785
|
} catch (error) {
|
|
724
786
|
return { _tag: "Failure", error };
|
|
725
787
|
}
|
|
788
|
+
},
|
|
789
|
+
async payOrder(orderId) {
|
|
790
|
+
try {
|
|
791
|
+
const data = await adapter.payOrder(orderId);
|
|
792
|
+
return { _tag: "Success", data };
|
|
793
|
+
} catch (error) {
|
|
794
|
+
return { _tag: "Failure", error };
|
|
795
|
+
}
|
|
726
796
|
}
|
|
727
797
|
};
|
|
728
798
|
}
|
|
@@ -1229,6 +1299,9 @@ const DISCOUNT_REJECTION_REASONS = [
|
|
|
1229
1299
|
"INVALID_COMBINATION",
|
|
1230
1300
|
"QUANTITY_REQUIREMENT_NOT_MET"
|
|
1231
1301
|
];
|
|
1302
|
+
function simulateLatency(ms) {
|
|
1303
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1304
|
+
}
|
|
1232
1305
|
function toAttributeArray(next) {
|
|
1233
1306
|
return Object.entries(next).map(([key, value]) => ({ key, value }));
|
|
1234
1307
|
}
|
|
@@ -1442,7 +1515,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1442
1515
|
];
|
|
1443
1516
|
return {
|
|
1444
1517
|
async getById(id) {
|
|
1445
|
-
await
|
|
1518
|
+
await simulateLatency(300);
|
|
1446
1519
|
const subscription = mockSubscriptions.find((sub) => sub.id === id);
|
|
1447
1520
|
return {
|
|
1448
1521
|
_tag: "Success",
|
|
@@ -1454,7 +1527,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1454
1527
|
};
|
|
1455
1528
|
},
|
|
1456
1529
|
async search(options2 = {}) {
|
|
1457
|
-
await
|
|
1530
|
+
await simulateLatency(300);
|
|
1458
1531
|
const pageSize = 2;
|
|
1459
1532
|
const allItems = mockSubscriptions;
|
|
1460
1533
|
let startIndex = 0;
|
|
@@ -1490,7 +1563,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1490
1563
|
},
|
|
1491
1564
|
async addItem({ subscriptionId, item }) {
|
|
1492
1565
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1493
|
-
await
|
|
1566
|
+
await simulateLatency(300);
|
|
1494
1567
|
const subscription = mockSubscriptions.find((sub) => sub.id === subscriptionId);
|
|
1495
1568
|
if (!subscription) {
|
|
1496
1569
|
return { _tag: "Failure", error: "Subscription not found" };
|
|
@@ -1517,7 +1590,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1517
1590
|
return { _tag: "Success", data: void 0 };
|
|
1518
1591
|
},
|
|
1519
1592
|
async removeItem({ subscriptionId, itemId }) {
|
|
1520
|
-
await
|
|
1593
|
+
await simulateLatency(300);
|
|
1521
1594
|
const subscription = mockSubscriptions.find((sub) => sub.id === subscriptionId);
|
|
1522
1595
|
if (!subscription) {
|
|
1523
1596
|
return { _tag: "Failure", error: "Subscription not found" };
|
|
@@ -1527,7 +1600,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1527
1600
|
return { _tag: "Success", data: void 0 };
|
|
1528
1601
|
},
|
|
1529
1602
|
async updateItem({ subscriptionId, lineId, update }) {
|
|
1530
|
-
await
|
|
1603
|
+
await simulateLatency(300);
|
|
1531
1604
|
const subscription = mockSubscriptions.find((sub) => sub.id === subscriptionId);
|
|
1532
1605
|
if (!subscription) {
|
|
1533
1606
|
return { _tag: "Failure", error: "Subscription not found" };
|
|
@@ -1543,7 +1616,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1543
1616
|
return { _tag: "Success", data: void 0 };
|
|
1544
1617
|
},
|
|
1545
1618
|
async updateItemAttributes({ subscriptionId, lineId, customAttributes }) {
|
|
1546
|
-
await
|
|
1619
|
+
await simulateLatency(300);
|
|
1547
1620
|
const subscription = mockSubscriptions.find((sub) => sub.id === subscriptionId);
|
|
1548
1621
|
if (!subscription) {
|
|
1549
1622
|
return { _tag: "Failure", error: "Subscription not found" };
|
|
@@ -1557,7 +1630,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1557
1630
|
return { _tag: "Success", data: void 0 };
|
|
1558
1631
|
},
|
|
1559
1632
|
async updateAttributes({ subscriptionId, customAttributes }) {
|
|
1560
|
-
await
|
|
1633
|
+
await simulateLatency(300);
|
|
1561
1634
|
const subscription = mockSubscriptions.find((sub) => sub.id === subscriptionId);
|
|
1562
1635
|
if (!subscription) {
|
|
1563
1636
|
return { _tag: "Failure", error: "Subscription not found" };
|
|
@@ -1567,14 +1640,14 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1567
1640
|
return { _tag: "Success", data: void 0 };
|
|
1568
1641
|
},
|
|
1569
1642
|
async skipLineItem() {
|
|
1570
|
-
await
|
|
1643
|
+
await simulateLatency(300);
|
|
1571
1644
|
return { _tag: "Success", data: void 0 };
|
|
1572
1645
|
},
|
|
1573
1646
|
async updateBoxItems() {
|
|
1574
1647
|
return { _tag: "Success", data: void 0 };
|
|
1575
1648
|
},
|
|
1576
1649
|
async addDiscount() {
|
|
1577
|
-
await
|
|
1650
|
+
await simulateLatency(300);
|
|
1578
1651
|
const behavior = options.addDiscountBehavior ?? { kind: "success" };
|
|
1579
1652
|
if (behavior.kind === "success") {
|
|
1580
1653
|
return { _tag: "Success", data: void 0 };
|
|
@@ -1588,7 +1661,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1588
1661
|
return { _tag: "Failure", error: { kind: behavior.error } };
|
|
1589
1662
|
},
|
|
1590
1663
|
async removeDiscount() {
|
|
1591
|
-
await
|
|
1664
|
+
await simulateLatency(300);
|
|
1592
1665
|
const behavior = options.removeDiscountBehavior ?? { kind: "success" };
|
|
1593
1666
|
if (behavior.kind === "success") {
|
|
1594
1667
|
return { _tag: "Success", data: void 0 };
|
|
@@ -1596,7 +1669,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1596
1669
|
return { _tag: "Failure", error: { kind: behavior.error } };
|
|
1597
1670
|
},
|
|
1598
1671
|
async reschedule(params) {
|
|
1599
|
-
await
|
|
1672
|
+
await simulateLatency(300);
|
|
1600
1673
|
const subscription = mockSubscriptions.find(
|
|
1601
1674
|
(sub) => sub.id === params.subscriptionId
|
|
1602
1675
|
);
|
|
@@ -1608,7 +1681,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1608
1681
|
return { _tag: "Success", data: { ...subscription } };
|
|
1609
1682
|
},
|
|
1610
1683
|
async updateCustomAttributes(params) {
|
|
1611
|
-
await
|
|
1684
|
+
await simulateLatency(300);
|
|
1612
1685
|
const subscription = mockSubscriptions.find(
|
|
1613
1686
|
(sub) => sub.id === params.subscriptionId
|
|
1614
1687
|
);
|
|
@@ -1626,7 +1699,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1626
1699
|
return { _tag: "Success", data: { ...subscription } };
|
|
1627
1700
|
},
|
|
1628
1701
|
async resume(params) {
|
|
1629
|
-
await
|
|
1702
|
+
await simulateLatency(300);
|
|
1630
1703
|
const subscription = mockSubscriptions.find(
|
|
1631
1704
|
(sub) => sub.id === params.subscriptionId
|
|
1632
1705
|
);
|
|
@@ -1638,7 +1711,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1638
1711
|
return { _tag: "Success", data: { ...subscription } };
|
|
1639
1712
|
},
|
|
1640
1713
|
async pause(params) {
|
|
1641
|
-
await
|
|
1714
|
+
await simulateLatency(300);
|
|
1642
1715
|
const subscription = mockSubscriptions.find(
|
|
1643
1716
|
(sub) => sub.id === params.subscriptionId
|
|
1644
1717
|
);
|
|
@@ -1650,7 +1723,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1650
1723
|
return { _tag: "Success", data: { ...subscription } };
|
|
1651
1724
|
},
|
|
1652
1725
|
async reactivate(params) {
|
|
1653
|
-
await
|
|
1726
|
+
await simulateLatency(300);
|
|
1654
1727
|
const subscription = mockSubscriptions.find(
|
|
1655
1728
|
(sub) => sub.id === params.subscriptionId
|
|
1656
1729
|
);
|
|
@@ -1662,7 +1735,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1662
1735
|
return { _tag: "Success", data: { ...subscription } };
|
|
1663
1736
|
},
|
|
1664
1737
|
async cancel(params) {
|
|
1665
|
-
await
|
|
1738
|
+
await simulateLatency(300);
|
|
1666
1739
|
const subscription = mockSubscriptions.find(
|
|
1667
1740
|
(sub) => sub.id === params.subscriptionId
|
|
1668
1741
|
);
|
|
@@ -1674,7 +1747,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1674
1747
|
return { _tag: "Success", data: { ...subscription } };
|
|
1675
1748
|
},
|
|
1676
1749
|
async getAvailablePlans() {
|
|
1677
|
-
await
|
|
1750
|
+
await simulateLatency(300);
|
|
1678
1751
|
return {
|
|
1679
1752
|
_tag: "Success",
|
|
1680
1753
|
data: [
|
|
@@ -1700,7 +1773,7 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1700
1773
|
};
|
|
1701
1774
|
},
|
|
1702
1775
|
async getLastOrder(params) {
|
|
1703
|
-
await
|
|
1776
|
+
await simulateLatency(200);
|
|
1704
1777
|
const subscription = mockSubscriptions.find((sub) => sub.id === params.subscriptionId);
|
|
1705
1778
|
if (!subscription) return { _tag: "Success", data: null };
|
|
1706
1779
|
return {
|
|
@@ -1712,11 +1785,11 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1712
1785
|
};
|
|
1713
1786
|
},
|
|
1714
1787
|
async renewNow(_params) {
|
|
1715
|
-
await
|
|
1788
|
+
await simulateLatency(300);
|
|
1716
1789
|
return { _tag: "Success", data: { result: "success" } };
|
|
1717
1790
|
},
|
|
1718
1791
|
async changeFrequency(params) {
|
|
1719
|
-
await
|
|
1792
|
+
await simulateLatency(300);
|
|
1720
1793
|
const subscription = mockSubscriptions.find((sub) => sub.id === params.subscriptionId);
|
|
1721
1794
|
if (!subscription) {
|
|
1722
1795
|
return { _tag: "Failure", error: "Subscription not found" };
|
|
@@ -1744,15 +1817,15 @@ function createMockSubscriptionAdapter(options = {}) {
|
|
|
1744
1817
|
},
|
|
1745
1818
|
async getDefaultSubscriptionId() {
|
|
1746
1819
|
var _a;
|
|
1747
|
-
await
|
|
1820
|
+
await simulateLatency(300);
|
|
1748
1821
|
return { _tag: "Success", data: ((_a = mockSubscriptions[0]) == null ? void 0 : _a.id) ?? null };
|
|
1749
1822
|
},
|
|
1750
1823
|
async getUpsellProducts() {
|
|
1751
|
-
await
|
|
1824
|
+
await simulateLatency(300);
|
|
1752
1825
|
return { _tag: "Success", data: [...mockUpsellProducts] };
|
|
1753
1826
|
},
|
|
1754
1827
|
async addUpsellProduct() {
|
|
1755
|
-
await
|
|
1828
|
+
await simulateLatency(400);
|
|
1756
1829
|
return { _tag: "Success", data: void 0 };
|
|
1757
1830
|
}
|
|
1758
1831
|
};
|
|
@@ -2576,7 +2649,7 @@ function createMockSchedulesAdapter(subscriptions = createMockSubscriptionAdapte
|
|
|
2576
2649
|
}
|
|
2577
2650
|
return {
|
|
2578
2651
|
async getUpcomingOrders({ count, subscriptionId, excludeSkipped = true }) {
|
|
2579
|
-
await
|
|
2652
|
+
await simulateLatency(200);
|
|
2580
2653
|
const subs = await subscriptionsToProject(subscriptionId);
|
|
2581
2654
|
const skipCount = new Set(
|
|
2582
2655
|
stored.filter(
|
|
@@ -2597,18 +2670,18 @@ function createMockSchedulesAdapter(subscriptions = createMockSubscriptionAdapte
|
|
|
2597
2670
|
return { _tag: "Success", data: orders.slice(0, count) };
|
|
2598
2671
|
},
|
|
2599
2672
|
async getAdjustments() {
|
|
2600
|
-
await
|
|
2673
|
+
await simulateLatency(200);
|
|
2601
2674
|
return { _tag: "Success", data: stored.map((s) => s.adjustment) };
|
|
2602
2675
|
},
|
|
2603
2676
|
async skipOrder({ subscriptionId, cycle, date }) {
|
|
2604
|
-
await
|
|
2677
|
+
await simulateLatency(300);
|
|
2605
2678
|
return recordAdjustment(subscriptionId, { cycle, date }, () => ({
|
|
2606
2679
|
type: "SKIP_ORDER",
|
|
2607
2680
|
input: { reason: "" }
|
|
2608
2681
|
}));
|
|
2609
2682
|
},
|
|
2610
2683
|
async skipItem({ subscriptionId, lineId, cycle, date, reason }) {
|
|
2611
|
-
await
|
|
2684
|
+
await simulateLatency(300);
|
|
2612
2685
|
const built = buildSkipItemMatcher({ cycle, date });
|
|
2613
2686
|
if (!built.ok) return { _tag: "Failure", error: built.error };
|
|
2614
2687
|
return recordAdjustment(
|
|
@@ -2622,7 +2695,7 @@ function createMockSchedulesAdapter(subscriptions = createMockSubscriptionAdapte
|
|
|
2622
2695
|
);
|
|
2623
2696
|
},
|
|
2624
2697
|
async changeDateAdjustment({ subscriptionId, newDate, cycle, currentDate }) {
|
|
2625
|
-
await
|
|
2698
|
+
await simulateLatency(300);
|
|
2626
2699
|
const newIso = toIsoOrNull(newDate);
|
|
2627
2700
|
if (newIso == null) {
|
|
2628
2701
|
return { _tag: "Failure", error: "newDate must be a valid date" };
|
|
@@ -2637,7 +2710,7 @@ function createMockSchedulesAdapter(subscriptions = createMockSubscriptionAdapte
|
|
|
2637
2710
|
);
|
|
2638
2711
|
},
|
|
2639
2712
|
async updateShippingAdjustment({ subscriptionId, address, cycle, date }) {
|
|
2640
|
-
await
|
|
2713
|
+
await simulateLatency(300);
|
|
2641
2714
|
return recordAdjustment(subscriptionId, { cycle, date }, () => ({
|
|
2642
2715
|
type: "UPDATE_SHIPPING",
|
|
2643
2716
|
input: { address }
|
|
@@ -2649,28 +2722,28 @@ function createMockSchedulesAdapter(subscriptions = createMockSubscriptionAdapte
|
|
|
2649
2722
|
cycle,
|
|
2650
2723
|
date
|
|
2651
2724
|
}) {
|
|
2652
|
-
await
|
|
2725
|
+
await simulateLatency(300);
|
|
2653
2726
|
return recordAdjustment(subscriptionId, { cycle, date }, () => ({
|
|
2654
2727
|
type: "UPDATE_PAYMENT_METHOD",
|
|
2655
2728
|
input: { paymentMethodId }
|
|
2656
2729
|
}));
|
|
2657
2730
|
},
|
|
2658
2731
|
async updateProductsAdjustment({ subscriptionId, lines, cycle, date }) {
|
|
2659
|
-
await
|
|
2732
|
+
await simulateLatency(300);
|
|
2660
2733
|
return recordAdjustment(subscriptionId, { cycle, date }, () => ({
|
|
2661
2734
|
type: "UPDATE_PRODUCTS",
|
|
2662
2735
|
input: { lines }
|
|
2663
2736
|
}));
|
|
2664
2737
|
},
|
|
2665
2738
|
async applyDiscountAdjustment({ subscriptionId, discountCode, cycle }) {
|
|
2666
|
-
await
|
|
2739
|
+
await simulateLatency(300);
|
|
2667
2740
|
return recordAdjustment(subscriptionId, { cycle }, () => ({
|
|
2668
2741
|
type: "APPLY_DISCOUNT",
|
|
2669
2742
|
input: { discountSource: "code", discountCode }
|
|
2670
2743
|
}));
|
|
2671
2744
|
},
|
|
2672
2745
|
async removeAdjustment({ adjustmentId }) {
|
|
2673
|
-
await
|
|
2746
|
+
await simulateLatency(200);
|
|
2674
2747
|
stored = stored.filter((s) => s.adjustment.id !== adjustmentId);
|
|
2675
2748
|
return { _tag: "Success", data: void 0 };
|
|
2676
2749
|
}
|
|
@@ -4153,9 +4226,11 @@ export {
|
|
|
4153
4226
|
GRID_V1_ENGINE_ID,
|
|
4154
4227
|
L as LAYOUT_SCOPE_ATTR,
|
|
4155
4228
|
LoginServiceContext,
|
|
4229
|
+
OrderPayError,
|
|
4156
4230
|
OrdersServiceContext,
|
|
4157
4231
|
P as PAGE_ROOT_SLOT,
|
|
4158
4232
|
ProductServiceContext,
|
|
4233
|
+
RateLimitedError,
|
|
4159
4234
|
RouterServiceContext,
|
|
4160
4235
|
SUPPORTED_UI_LANGUAGES,
|
|
4161
4236
|
SUPPORTED_UI_LANGUAGE_OPTIONS,
|
|
@@ -4245,6 +4320,7 @@ export {
|
|
|
4245
4320
|
a1 as projectToCss,
|
|
4246
4321
|
p as projectToGridStack,
|
|
4247
4322
|
a2 as provideContext,
|
|
4323
|
+
rateLimitErrorFromResponse,
|
|
4248
4324
|
a3 as readingOrder,
|
|
4249
4325
|
e as reconcileLayout,
|
|
4250
4326
|
a4 as rectsOverlap,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiFetcher, Result } from '../../utils';
|
|
2
|
-
import { AuthenticationError } from './errors';
|
|
2
|
+
import { AuthenticationError, RateLimitedError } from './errors';
|
|
3
3
|
export type AuthTokens = {
|
|
4
4
|
access_token: string;
|
|
5
5
|
refresh_token: string;
|
|
@@ -33,6 +33,13 @@ export interface LoginAdapter {
|
|
|
33
33
|
* and translating it to a code is the backend's job.
|
|
34
34
|
*/
|
|
35
35
|
export declare function authenticationErrorFromBody(data: unknown): AuthenticationError | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Turn a `429` from the auth endpoints into a `RateLimitedError`, or
|
|
38
|
+
* `undefined` for any other status. `Retry-After` is read as delay-seconds; a
|
|
39
|
+
* missing or unparseable header falls back to a minute so the form can't stay
|
|
40
|
+
* blocked forever.
|
|
41
|
+
*/
|
|
42
|
+
export declare function rateLimitErrorFromResponse(res: Pick<Response, "status" | "headers">): RateLimitedError | undefined;
|
|
36
43
|
export declare function createMockLoginAdapter(opts?: {
|
|
37
44
|
appUrl?: string;
|
|
38
45
|
}): LoginAdapter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/services/login/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/services/login/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,mBAAmB,EAEnB,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,UAAU,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,iBAAiB,CAAC,MAAM,EAAE;QACxB,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAE1B,YAAY,CACV,MAAM,EACF;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC/B;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAChB;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,GAC3B,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IAE/B,eAAe,CAAC,MAAM,EAAE;QACtB,UAAU,EAAE,UAAU,GAAG,eAAe,CAAC;QACzC,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,MAAM,CAAC;CACZ;AAQD;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,OAAO,GACZ,mBAAmB,GAAG,SAAS,CAoBjC;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,GAAG,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC,GACxC,gBAAgB,GAAG,SAAS,CAU9B;AAED,wBAAgB,sBAAsB,CACpC,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAC7B,YAAY,CAwBd;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC3C,YAAY,CA0Gd"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* which is what lets the adapter's code lookup be a plain table.
|
|
7
7
|
*/
|
|
8
8
|
export declare enum AuthenticationErrorReason {
|
|
9
|
+
RateLimited = "rate-limited",
|
|
9
10
|
Expired = "expired",
|
|
10
11
|
IncorrectCode = "wrong-code",
|
|
11
12
|
TooManyTries = "too-many-tries",
|
|
@@ -18,4 +19,9 @@ export declare class AuthenticationError extends Error {
|
|
|
18
19
|
data: Record<string, unknown>;
|
|
19
20
|
constructor(reason: AuthenticationErrorReason, data?: Record<string, unknown>);
|
|
20
21
|
}
|
|
22
|
+
export declare class RateLimitedError extends AuthenticationError {
|
|
23
|
+
/** Epoch milliseconds before which the backend will refuse another login request. */
|
|
24
|
+
readonly retryAt: number;
|
|
25
|
+
constructor(retryAt: number);
|
|
26
|
+
}
|
|
21
27
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/services/login/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,oBAAY,yBAAyB;IACnC,OAAO,YAAY;IACnB,aAAa,eAAe;IAC5B,YAAY,mBAAmB;IAC/B,OAAO,aAAa;IACpB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,MAAM,EAAE,yBAAyB,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAG5B,MAAM,EAAE,yBAAyB,EACjC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMjC"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/services/login/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,oBAAY,yBAAyB;IACnC,WAAW,iBAAiB;IAC5B,OAAO,YAAY;IACnB,aAAa,eAAe;IAC5B,YAAY,mBAAmB;IAC/B,OAAO,aAAa;IACpB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,MAAM,EAAE,yBAAyB,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAG5B,MAAM,EAAE,yBAAyB,EACjC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMjC;AAED,qBAAa,gBAAiB,SAAQ,mBAAmB;IACvD,qFAAqF;IACrF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -21,6 +21,6 @@ export declare const LoginServiceContext: {
|
|
|
21
21
|
__context__: LoginService;
|
|
22
22
|
};
|
|
23
23
|
export { loginService, createLoginService, type LoginServiceDependencies, type ErrorFormatter, } from './loginService';
|
|
24
|
-
export { AuthenticationError, AuthenticationErrorReason } from './errors';
|
|
25
|
-
export { type LoginAdapter, type AuthTokens, authenticationErrorFromBody, createApiLoginAdapter, createMockLoginAdapter, } from './adapter';
|
|
24
|
+
export { AuthenticationError, AuthenticationErrorReason, RateLimitedError, } from './errors';
|
|
25
|
+
export { type LoginAdapter, type AuthTokens, authenticationErrorFromBody, rateLimitErrorFromResponse, createApiLoginAdapter, createMockLoginAdapter, } from './adapter';
|
|
26
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/login/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,KAAK,YAAY,GAAG;IAClB,YAAY,EAAE;QACZ,KAAK,EAAE;YACL,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;YAC1D,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;SAC1E,CAAC;KACH,CAAC;IAEF,MAAM,EAAE;QACN,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;QAC5E,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;KAC3D,CAAC;IAEF,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAEjC,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAEnC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EA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c,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAElD,iBAAiB,CACf,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;IAEvC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3B,CAAC;AAEF,eAAO,MAAM,mBAAmB;;CACe,CAAC;AAEhD,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,GACpB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,2BAA2B,EAC3B,0BAA0B,EAC1B,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loginService.d.ts","sourceRoot":"","sources":["../../../src/services/login/loginService.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAKxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,
|
|
1
|
+
{"version":3,"file":"loginService.d.ts","sourceRoot":"","sources":["../../../src/services/login/loginService.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAKxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EAE1B,MAAM,UAAU,CAAC;AAElB,UAAU,aAAa;IACrB,IAAI,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GAAG,IAAI,CAAC;IACtE,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,UAAU,WAAW;IACnB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC;CAChB;AA0BD,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,KAAK;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,yBAAyB,CAAC;CACpC,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,YAAY,CAAC;IACtB,WAAW,EAAE,cAAc,CAAC;IAC5B,MAAM,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE;IACjC,WAAW,EAAE,cAAc,CAAC;IAC5B,SAAS,EAAE,MAAM,MAAM,CAAC;IACxB,MAAM,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;;;;;;;;;;;;;;;;EAmBA;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,wBAAwB;;;;;;;;;;;;;;;;EAkOhE"}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { ApiFetcher } from '../../utils';
|
|
2
2
|
import { OrdersAdapter } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Thrown by `createApiOrdersAdapter`'s `payOrder` on a non-ok response.
|
|
5
|
+
* Carries the HTTP `status` so callers can cheaply distinguish a 409
|
|
6
|
+
* (charge in flight / nothing payable here right now) from other failures
|
|
7
|
+
* without parsing the message.
|
|
8
|
+
*/
|
|
9
|
+
export declare class OrderPayError extends Error {
|
|
10
|
+
status: number;
|
|
11
|
+
constructor(status: number);
|
|
12
|
+
}
|
|
3
13
|
/**
|
|
4
14
|
* Returns a mock `OrdersAdapter` with sample orders including customAttributes.
|
|
5
15
|
* Hosts can override the methods to seed real fixtures.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/services/orders/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/services/orders/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAIV,aAAa,EAEd,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MAAM;CAK3B;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,aAAa,CAuEvD;AA6DD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,UAAU,GAAG,aAAa,CAsCzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.test.d.ts","sourceRoot":"","sources":["../../../src/services/orders/adapter.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { GetOrdersParams, Order, OrderLine, OrdersAdapter, OrdersService, } from './types';
|
|
2
|
-
export { createMockOrdersAdapter, createApiOrdersAdapter } from './adapter';
|
|
3
|
-
export { createOrdersService, OrdersServiceContext
|
|
1
|
+
export type { GetOrdersParams, Order, OrderLine, OrderPayment, OrderPaymentAction, OrderPaymentState, OrdersAdapter, OrdersService, } from './types';
|
|
2
|
+
export { createMockOrdersAdapter, createApiOrdersAdapter, OrderPayError, } from './adapter';
|
|
3
|
+
export { createOrdersService, OrdersServiceContext } from './ordersService';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/orders/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,KAAK,EACL,SAAS,EACT,aAAa,EACb,aAAa,GACd,MAAM,SAAS,CAAC;AAEjB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/orders/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,KAAK,EACL,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,aAAa,GACd,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,aAAa,GACd,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ordersService.d.ts","sourceRoot":"","sources":["../../../src/services/orders/ordersService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE5D,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"ordersService.d.ts","sourceRoot":"","sources":["../../../src/services/orders/ordersService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE5D,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAmBzE;AAED,eAAO,MAAM,oBAAoB;;CACgB,CAAC"}
|
|
@@ -9,8 +9,22 @@ export interface OrderLine {
|
|
|
9
9
|
value: string;
|
|
10
10
|
}>;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Self-service action a customer can take on an order's payment right now.
|
|
14
|
+
* `update-payment-method` / `add-payment-method` are reported by the backend
|
|
15
|
+
* but not acted on by any block yet — no route exists for a subscription
|
|
16
|
+
* payment-methods panel here, so blocks only ever look for `"pay"`.
|
|
17
|
+
*/
|
|
18
|
+
export type OrderPaymentAction = "pay" | "update-payment-method" | "add-payment-method";
|
|
19
|
+
export type OrderPaymentState = "charging" | "retry_scheduled" | "awaiting_customer" | "awaiting_payment_method" | "overdue";
|
|
20
|
+
export interface OrderPayment {
|
|
21
|
+
state: OrderPaymentState;
|
|
22
|
+
/** ISO date-time of the next auto-charge attempt. Only set for `retry_scheduled`. */
|
|
23
|
+
nextAttemptAt: string | null;
|
|
24
|
+
actions: OrderPaymentAction[];
|
|
25
|
+
}
|
|
12
26
|
export interface Order {
|
|
13
|
-
/**
|
|
27
|
+
/** Local invoice id (UUID) for an open postpaid invoice, or the numeric Shopify order id (the trailing segment of the order GID) otherwise. The block prepends `#` for display. */
|
|
14
28
|
id: string;
|
|
15
29
|
createdAt: string;
|
|
16
30
|
placedAt: string | null;
|
|
@@ -25,6 +39,8 @@ export interface Order {
|
|
|
25
39
|
key: string;
|
|
26
40
|
value: string;
|
|
27
41
|
}>;
|
|
42
|
+
/** Where this order's payment stands from the customer's side, and what they can do about it. `null` when nothing is outstanding. */
|
|
43
|
+
payment?: OrderPayment | null;
|
|
28
44
|
}
|
|
29
45
|
export interface GetOrdersParams {
|
|
30
46
|
limit?: number;
|
|
@@ -53,8 +69,22 @@ export interface GetOrdersParams {
|
|
|
53
69
|
/** Adapter consumed by `createOrdersService`. Hosts (customer portal, theme, storybook) implement this. */
|
|
54
70
|
export interface OrdersAdapter {
|
|
55
71
|
getOrders(params?: GetOrdersParams): Promise<PaginatedList<Order>>;
|
|
72
|
+
/**
|
|
73
|
+
* Pay an outstanding postpaid invoice right now. Resolves the stable
|
|
74
|
+
* customer-facing pay link (a Shopify Checkout, or the Juo pay page) —
|
|
75
|
+
* callers should redirect the customer there. Throws on failure; a 409
|
|
76
|
+
* (charge already in flight, or nothing payable here) should be thrown as
|
|
77
|
+
* an error carrying a `status` property so callers can distinguish it
|
|
78
|
+
* cheaply from other failures.
|
|
79
|
+
*/
|
|
80
|
+
payOrder(orderId: string): Promise<{
|
|
81
|
+
url: string;
|
|
82
|
+
}>;
|
|
56
83
|
}
|
|
57
84
|
export interface OrdersService {
|
|
58
85
|
getOrders(params?: GetOrdersParams): Promise<Result<PaginatedList<Order>>>;
|
|
86
|
+
payOrder(orderId: string): Promise<Result<{
|
|
87
|
+
url: string;
|
|
88
|
+
}>>;
|
|
59
89
|
}
|
|
60
90
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,KAAK,GAAG,IAAI,CAAC;IAC3B,gBAAgB,CAAC,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC1D;AAED,MAAM,WAAW,KAAK;IACpB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAA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CAAC;IAChB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,2GAA2G;AAC3G,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IACnE;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrD;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3E,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CAC7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/services/schedules/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAiC,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAClG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EACV,kBAAkB,EAElB,aAAa,EAEb,4BAA4B,EAC5B,0BAA0B,EAC3B,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/services/schedules/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,a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@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock adapters stand in for the API in Storybook and devtools, where a
|
|
3
|
+
* realistic delay shows loading states. Under Vitest (mode "test") the delay
|
|
4
|
+
* only makes tests wait: it was most of this package's test time.
|
|
5
|
+
*/
|
|
6
|
+
export declare function simulateLatency(ms: number): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=simulateLatency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulateLatency.d.ts","sourceRoot":"","sources":["../../src/services/simulateLatency.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/services/subscription/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,wBAAwB,EACxB,sBAAsB,EACtB,aAAa,EACb,SAAS,EACT,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EACV,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/services/subscription/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,MAA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,UAAU,CAAC;QAAC,MAAM,EAAE,uBAAuB,CAAA;KAAE,GACrD;QACE,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,wBAAwB,CAAC;KACzD,CAAC;IACN,sBAAsB,CAAC,EACnB;QAAE,IAAI,EAAE,SAAS,CAAA;KAAE,GACnB;QACE,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EACD,SAAS,GACT,SAAS,GACT,wBAAwB,GACxB,oBAAoB,CAAC;KAC1B,CAAC;IACN;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,gBAAgB,GAAG,SAAS,CAAC,CAAC;CACrE;AAcD,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,8BAAmC,GAC3C,mBAAmB,CA8lBrB;AA6HD,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,UAAU,GAClB,mBAAmB,CA2frB"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -27,6 +27,11 @@ export type ErrorDetails = {
|
|
|
27
27
|
* Values are `AuthenticationErrorReason` members.
|
|
28
28
|
*/
|
|
29
29
|
reason?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Epoch milliseconds before which the backend will refuse another login
|
|
32
|
+
* request. Present when `reason` is rate-limited.
|
|
33
|
+
*/
|
|
34
|
+
retryAt?: number;
|
|
30
35
|
};
|
|
31
36
|
export type Image = {
|
|
32
37
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,OAAO,IAAI;IACjC,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,IAAI,IAAI;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,CAAC,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AED,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjF,cAAc,UAAU,CAAC"}
|
package/dist/vue/main.d.ts
CHANGED
package/dist/vue/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/vue/main.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/vue/main.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
export declare function useLoginCooldown(deadline: MaybeRefOrGetter<number | null>): {
|
|
3
|
+
remainingSeconds: import('vue').ComputedRef<number>;
|
|
4
|
+
remainingTime: import('vue').ComputedRef<string>;
|
|
5
|
+
isBlocked: import('vue').ComputedRef<boolean>;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=useLoginCooldown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLoginCooldown.d.ts","sourceRoot":"","sources":["../../src/vue/useLoginCooldown.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,KAAK,CAAC;AAEb,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC;;;;EAsCzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLoginCooldown.test.d.ts","sourceRoot":"","sources":["../../src/vue/useLoginCooldown.test.ts"],"names":[],"mappings":""}
|
package/dist/vue.js
CHANGED
|
@@ -346,6 +346,39 @@ function useBridge(options) {
|
|
|
346
346
|
});
|
|
347
347
|
return { isEditorMode: isEditorMode.value };
|
|
348
348
|
}
|
|
349
|
+
function useLoginCooldown(deadline) {
|
|
350
|
+
const retryAt = computed(() => toValue(deadline) ?? 0);
|
|
351
|
+
const now = ref(Date.now());
|
|
352
|
+
const remainingSeconds = computed(
|
|
353
|
+
() => Math.max(0, Math.ceil((retryAt.value - now.value) / 1e3))
|
|
354
|
+
);
|
|
355
|
+
const remainingTime = computed(() => {
|
|
356
|
+
const minutes = Math.floor(remainingSeconds.value / 60);
|
|
357
|
+
const seconds = remainingSeconds.value % 60;
|
|
358
|
+
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
|
359
|
+
});
|
|
360
|
+
const isBlocked = computed(() => remainingSeconds.value > 0);
|
|
361
|
+
let timer;
|
|
362
|
+
function stop() {
|
|
363
|
+
clearInterval(timer);
|
|
364
|
+
timer = void 0;
|
|
365
|
+
}
|
|
366
|
+
watch(
|
|
367
|
+
retryAt,
|
|
368
|
+
(value) => {
|
|
369
|
+
stop();
|
|
370
|
+
now.value = Date.now();
|
|
371
|
+
if (value <= now.value) return;
|
|
372
|
+
timer = setInterval(() => {
|
|
373
|
+
now.value = Date.now();
|
|
374
|
+
if (!isBlocked.value) stop();
|
|
375
|
+
}, 250);
|
|
376
|
+
},
|
|
377
|
+
{ immediate: true, flush: "sync" }
|
|
378
|
+
);
|
|
379
|
+
onScopeDispose(stop);
|
|
380
|
+
return { remainingSeconds, remainingTime, isBlocked };
|
|
381
|
+
}
|
|
349
382
|
export {
|
|
350
383
|
ContextProvider,
|
|
351
384
|
createVueCeRenderer,
|
|
@@ -357,6 +390,7 @@ export {
|
|
|
357
390
|
useBlockType,
|
|
358
391
|
useBridge,
|
|
359
392
|
useContext,
|
|
393
|
+
useLoginCooldown,
|
|
360
394
|
useProvideContext,
|
|
361
395
|
useProvideContextProvider,
|
|
362
396
|
useRegisterTranslationKeys,
|