@juo/blocks 1.1.0-alpha.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ExtensionRoot-unXhHjxE.js → ExtensionRoot-BixerQDc.js} +5 -2
- package/dist/{bridge-DQsM97cH.js → bridge-CIUKbSJR.js} +17 -17
- package/dist/core.js +36 -912
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor.js +22 -20
- package/dist/{juo-workflow-RSrOuKUH.js → juo-workflow-BvTgGZQj.js} +4 -4
- package/dist/preact.js +2 -2
- package/dist/react.js +2 -2
- package/dist/services/customer/customerService.d.ts +3 -6
- package/dist/services/customer/customerService.d.ts.map +1 -1
- package/dist/services/customer/index.d.ts +2 -4
- package/dist/services/customer/index.d.ts.map +1 -1
- package/dist/services/customer/types.d.ts +8 -12
- package/dist/services/customer/types.d.ts.map +1 -1
- package/dist/services/index.d.ts +0 -3
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/login/index.d.ts +0 -1
- package/dist/services/login/index.d.ts.map +1 -1
- package/dist/services/login/loginService.d.ts +0 -2
- package/dist/services/login/loginService.d.ts.map +1 -1
- package/dist/services/product/types.d.ts +0 -2
- package/dist/services/product/types.d.ts.map +1 -1
- package/dist/services/subscription/adapter.d.ts +2 -19
- package/dist/services/subscription/adapter.d.ts.map +1 -1
- package/dist/services/subscription/index.d.ts +1 -1
- package/dist/services/subscription/index.d.ts.map +1 -1
- package/dist/services/subscription/subscriptionService.d.ts +2 -1
- package/dist/services/subscription/subscriptionService.d.ts.map +1 -1
- package/dist/services/subscription/types.d.ts +7 -28
- package/dist/services/subscription/types.d.ts.map +1 -1
- package/dist/{theme-state-BZplRS92.js → theme-state-DMyDKxtl.js} +16 -16
- package/dist/utils/index.d.ts +0 -6
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/vue/block.d.ts.map +1 -1
- package/dist/vue.js +8 -4
- package/dist/web-components/ExtensionRoot.d.ts.map +1 -1
- package/dist/web-components-editor.js +4 -4
- package/dist/web-components-runtime.js +3 -3
- package/package.json +1 -1
- package/dist/services/customer/adapter.d.ts +0 -13
- package/dist/services/customer/adapter.d.ts.map +0 -1
- package/dist/services/order/adapter.d.ts +0 -12
- package/dist/services/order/adapter.d.ts.map +0 -1
- package/dist/services/order/index.d.ts +0 -5
- package/dist/services/order/index.d.ts.map +0 -1
- package/dist/services/order/orderService.d.ts +0 -7
- package/dist/services/order/orderService.d.ts.map +0 -1
- package/dist/services/order/types.d.ts +0 -25
- package/dist/services/order/types.d.ts.map +0 -1
- package/dist/services/router/index.d.ts +0 -3
- package/dist/services/router/index.d.ts.map +0 -1
- package/dist/services/router/routerService.d.ts +0 -5
- package/dist/services/router/routerService.d.ts.map +0 -1
- package/dist/services/router/types.d.ts +0 -16
- package/dist/services/router/types.d.ts.map +0 -1
- package/dist/services/schedules/adapter.d.ts +0 -20
- package/dist/services/schedules/adapter.d.ts.map +0 -1
- package/dist/services/schedules/index.d.ts +0 -5
- package/dist/services/schedules/index.d.ts.map +0 -1
- package/dist/services/schedules/schedulesService.d.ts +0 -10
- package/dist/services/schedules/schedulesService.d.ts.map +0 -1
- package/dist/services/schedules/types.d.ts +0 -45
- package/dist/services/schedules/types.d.ts.map +0 -1
package/dist/core.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { c as createContext, d, w, E, u } from "./theme-state-
|
|
5
|
-
import { B,
|
|
6
|
-
import { T as T2, W, c,
|
|
4
|
+
import { c as createContext, d, w, E, u } from "./theme-state-DMyDKxtl.js";
|
|
5
|
+
import { B, C, a, D, S, T, b, e, f, g, h, i, j, k, l, m, n, o, p, r, s, q, t, v } from "./theme-state-DMyDKxtl.js";
|
|
6
|
+
import { T as T2, W, c, a as a2, b as b2, g as g2, h as h2 } from "./juo-workflow-BvTgGZQj.js";
|
|
7
7
|
function createState() {
|
|
8
8
|
const discountCode = d(null);
|
|
9
9
|
const products = d([]);
|
|
@@ -415,18 +415,7 @@ function createLoginService(init) {
|
|
|
415
415
|
return { _tag: "Success", data: void 0 };
|
|
416
416
|
},
|
|
417
417
|
isAuthenticated: auth.isAuthenticated,
|
|
418
|
-
getToken: () => auth.getToken()
|
|
419
|
-
async getAuthHeaders() {
|
|
420
|
-
const delegated = auth.getDelegatedToken();
|
|
421
|
-
if (delegated) {
|
|
422
|
-
return { "X-Delegated-Token": delegated };
|
|
423
|
-
}
|
|
424
|
-
const token = await auth.getToken();
|
|
425
|
-
if (token) {
|
|
426
|
-
return { Authorization: `Bearer ${token}` };
|
|
427
|
-
}
|
|
428
|
-
return {};
|
|
429
|
-
}
|
|
418
|
+
getToken: () => auth.getToken()
|
|
430
419
|
};
|
|
431
420
|
return service;
|
|
432
421
|
}
|
|
@@ -676,32 +665,6 @@ function createMockSubscriptionAdapter() {
|
|
|
676
665
|
updatedAt: "2024-10-10T00:00:00Z"
|
|
677
666
|
}
|
|
678
667
|
];
|
|
679
|
-
const mockUpsellProducts = [
|
|
680
|
-
{
|
|
681
|
-
id: "upsell-1",
|
|
682
|
-
variantId: "upsell-v-1",
|
|
683
|
-
title: "Retinol Night Cream",
|
|
684
|
-
imageUrl: "https://images.unsplash.com/photo-1617897903246-719242758050?w=200",
|
|
685
|
-
price: { amount: "38.00", currencyCode: "USD" },
|
|
686
|
-
description: "Anti-aging night treatment"
|
|
687
|
-
},
|
|
688
|
-
{
|
|
689
|
-
id: "upsell-2",
|
|
690
|
-
variantId: "upsell-v-2",
|
|
691
|
-
title: "SPF 50 Day Shield",
|
|
692
|
-
imageUrl: "https://images.unsplash.com/photo-1556228578-8c89e6adf883?w=200",
|
|
693
|
-
price: { amount: "24.00", currencyCode: "USD" },
|
|
694
|
-
description: "Lightweight daily sun protection"
|
|
695
|
-
},
|
|
696
|
-
{
|
|
697
|
-
id: "upsell-3",
|
|
698
|
-
variantId: "upsell-v-3",
|
|
699
|
-
title: "Collagen Eye Patches",
|
|
700
|
-
imageUrl: "https://images.unsplash.com/photo-1512290923902-8a9f81dc236c?w=200",
|
|
701
|
-
price: { amount: "18.00", currencyCode: "USD" },
|
|
702
|
-
description: "Depuffing under-eye treatment"
|
|
703
|
-
}
|
|
704
|
-
];
|
|
705
668
|
return {
|
|
706
669
|
async getById(id) {
|
|
707
670
|
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
@@ -778,9 +741,7 @@ function createMockSubscriptionAdapter() {
|
|
|
778
741
|
data: {
|
|
779
742
|
...subscription,
|
|
780
743
|
items: subscription.items.map((item) => ({ ...item })),
|
|
781
|
-
discounts: subscription.discounts.map((discount) => ({
|
|
782
|
-
...discount
|
|
783
|
-
}))
|
|
744
|
+
discounts: subscription.discounts.map((discount) => ({ ...discount }))
|
|
784
745
|
}
|
|
785
746
|
};
|
|
786
747
|
},
|
|
@@ -802,9 +763,7 @@ function createMockSubscriptionAdapter() {
|
|
|
802
763
|
data: {
|
|
803
764
|
...subscription,
|
|
804
765
|
items: subscription.items.map((item) => ({ ...item })),
|
|
805
|
-
discounts: subscription.discounts.map((discount) => ({
|
|
806
|
-
...discount
|
|
807
|
-
}))
|
|
766
|
+
discounts: subscription.discounts.map((discount) => ({ ...discount }))
|
|
808
767
|
}
|
|
809
768
|
};
|
|
810
769
|
},
|
|
@@ -826,9 +785,7 @@ function createMockSubscriptionAdapter() {
|
|
|
826
785
|
data: {
|
|
827
786
|
...subscription,
|
|
828
787
|
items: subscription.items.map((item) => ({ ...item })),
|
|
829
|
-
discounts: subscription.discounts.map((discount) => ({
|
|
830
|
-
...discount
|
|
831
|
-
}))
|
|
788
|
+
discounts: subscription.discounts.map((discount) => ({ ...discount }))
|
|
832
789
|
}
|
|
833
790
|
};
|
|
834
791
|
},
|
|
@@ -850,9 +807,7 @@ function createMockSubscriptionAdapter() {
|
|
|
850
807
|
data: {
|
|
851
808
|
...subscription,
|
|
852
809
|
items: subscription.items.map((item) => ({ ...item })),
|
|
853
|
-
discounts: subscription.discounts.map((discount) => ({
|
|
854
|
-
...discount
|
|
855
|
-
}))
|
|
810
|
+
discounts: subscription.discounts.map((discount) => ({ ...discount }))
|
|
856
811
|
}
|
|
857
812
|
};
|
|
858
813
|
},
|
|
@@ -874,9 +829,7 @@ function createMockSubscriptionAdapter() {
|
|
|
874
829
|
data: {
|
|
875
830
|
...subscription,
|
|
876
831
|
items: subscription.items.map((item) => ({ ...item })),
|
|
877
|
-
discounts: subscription.discounts.map((discount) => ({
|
|
878
|
-
...discount
|
|
879
|
-
}))
|
|
832
|
+
discounts: subscription.discounts.map((discount) => ({ ...discount }))
|
|
880
833
|
}
|
|
881
834
|
};
|
|
882
835
|
},
|
|
@@ -910,316 +863,6 @@ function createMockSubscriptionAdapter() {
|
|
|
910
863
|
var _a;
|
|
911
864
|
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
912
865
|
return { _tag: "Success", data: ((_a = mockSubscriptions[0]) == null ? void 0 : _a.id) ?? null };
|
|
913
|
-
},
|
|
914
|
-
async getDeliveryFrequencies() {
|
|
915
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
916
|
-
return {
|
|
917
|
-
_tag: "Success",
|
|
918
|
-
data: [
|
|
919
|
-
{
|
|
920
|
-
id: "plan_1",
|
|
921
|
-
name: "Monthly",
|
|
922
|
-
billingPolicy: { intervalCount: 1, interval: "MONTH" },
|
|
923
|
-
deliveryPolicy: { intervalCount: 1, interval: "MONTH" }
|
|
924
|
-
},
|
|
925
|
-
{
|
|
926
|
-
id: "plan_2",
|
|
927
|
-
name: "Every 2 months",
|
|
928
|
-
billingPolicy: { intervalCount: 2, interval: "MONTH" },
|
|
929
|
-
deliveryPolicy: { intervalCount: 2, interval: "MONTH" }
|
|
930
|
-
}
|
|
931
|
-
]
|
|
932
|
-
};
|
|
933
|
-
},
|
|
934
|
-
async getUpsellProducts() {
|
|
935
|
-
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
936
|
-
return { _tag: "Success", data: [...mockUpsellProducts] };
|
|
937
|
-
},
|
|
938
|
-
async addUpsellProduct() {
|
|
939
|
-
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
940
|
-
return { _tag: "Success", data: void 0 };
|
|
941
|
-
},
|
|
942
|
-
async changeFrequency(params) {
|
|
943
|
-
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
944
|
-
const subscription = mockSubscriptions.find(
|
|
945
|
-
(sub) => sub.id === params.subscriptionId
|
|
946
|
-
);
|
|
947
|
-
if (!subscription) {
|
|
948
|
-
return { _tag: "Failure", error: "Subscription not found" };
|
|
949
|
-
}
|
|
950
|
-
subscription.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
951
|
-
return {
|
|
952
|
-
_tag: "Success",
|
|
953
|
-
data: { ...subscription }
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
};
|
|
957
|
-
}
|
|
958
|
-
function createApiSubscriptionAdapter(fetcher) {
|
|
959
|
-
return {
|
|
960
|
-
async search(options) {
|
|
961
|
-
try {
|
|
962
|
-
const params = new URLSearchParams();
|
|
963
|
-
if (options == null ? void 0 : options.filters) {
|
|
964
|
-
params.set("filters", JSON.stringify(options.filters));
|
|
965
|
-
}
|
|
966
|
-
if (options == null ? void 0 : options.pagination) {
|
|
967
|
-
if ("after" in options.pagination) {
|
|
968
|
-
params.set("after", options.pagination.after);
|
|
969
|
-
} else if ("before" in options.pagination) {
|
|
970
|
-
params.set("before", options.pagination.before);
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
const query = params.toString() ? `?${params.toString()}` : "";
|
|
974
|
-
const res = await fetcher(`/customer/v1/subscriptions${query}`);
|
|
975
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
976
|
-
const body = await res.json();
|
|
977
|
-
body.data.forEach((sub) => {
|
|
978
|
-
if (sub.nextDeliveryDate) {
|
|
979
|
-
sub.nextDeliveryDate = new Date(sub.nextDeliveryDate);
|
|
980
|
-
}
|
|
981
|
-
sub.items.forEach((item) => {
|
|
982
|
-
if (item.nextDeliveryDate) {
|
|
983
|
-
item.nextDeliveryDate = new Date(item.nextDeliveryDate);
|
|
984
|
-
}
|
|
985
|
-
});
|
|
986
|
-
});
|
|
987
|
-
const data = {
|
|
988
|
-
items: body.data,
|
|
989
|
-
pageInfo: {
|
|
990
|
-
hasNextPage: body.hasNextPage,
|
|
991
|
-
hasPrevPage: body.hasPrevPage,
|
|
992
|
-
startCursor: body.startCursor,
|
|
993
|
-
endCursor: body.endCursor
|
|
994
|
-
}
|
|
995
|
-
};
|
|
996
|
-
return { _tag: "Success", data };
|
|
997
|
-
} catch (e2) {
|
|
998
|
-
return { _tag: "Failure", error: e2 };
|
|
999
|
-
}
|
|
1000
|
-
},
|
|
1001
|
-
async getById(id) {
|
|
1002
|
-
try {
|
|
1003
|
-
const res = await fetcher(`/customer/v1/subscriptions/${id}`);
|
|
1004
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1005
|
-
const data = await res.json();
|
|
1006
|
-
if (data.nextDeliveryDate)
|
|
1007
|
-
data.nextDeliveryDate = new Date(data.nextDeliveryDate);
|
|
1008
|
-
return { _tag: "Success", data };
|
|
1009
|
-
} catch (e2) {
|
|
1010
|
-
return { _tag: "Failure", error: e2 };
|
|
1011
|
-
}
|
|
1012
|
-
},
|
|
1013
|
-
async addItem({ subscriptionId, item }) {
|
|
1014
|
-
try {
|
|
1015
|
-
const res = await fetcher(
|
|
1016
|
-
`/customer/v1/subscriptions/${subscriptionId}/items`,
|
|
1017
|
-
{
|
|
1018
|
-
method: "POST",
|
|
1019
|
-
headers: { "Content-Type": "application/json" },
|
|
1020
|
-
body: JSON.stringify(item)
|
|
1021
|
-
}
|
|
1022
|
-
);
|
|
1023
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1024
|
-
return { _tag: "Success", data: void 0 };
|
|
1025
|
-
} catch (e2) {
|
|
1026
|
-
return { _tag: "Failure", error: e2 };
|
|
1027
|
-
}
|
|
1028
|
-
},
|
|
1029
|
-
async removeItem({ subscriptionId, itemId }) {
|
|
1030
|
-
try {
|
|
1031
|
-
const res = await fetcher(
|
|
1032
|
-
`/customer/v1/subscriptions/${subscriptionId}/items/${itemId}`,
|
|
1033
|
-
{ method: "DELETE" }
|
|
1034
|
-
);
|
|
1035
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1036
|
-
return { _tag: "Success", data: void 0 };
|
|
1037
|
-
} catch (e2) {
|
|
1038
|
-
return { _tag: "Failure", error: e2 };
|
|
1039
|
-
}
|
|
1040
|
-
},
|
|
1041
|
-
async addDiscount({ subscriptionId, code }) {
|
|
1042
|
-
try {
|
|
1043
|
-
const res = await fetcher(
|
|
1044
|
-
`/customer/v1/subscriptions/${subscriptionId}/discounts`,
|
|
1045
|
-
{
|
|
1046
|
-
method: "POST",
|
|
1047
|
-
headers: { "Content-Type": "application/json" },
|
|
1048
|
-
body: JSON.stringify({ code })
|
|
1049
|
-
}
|
|
1050
|
-
);
|
|
1051
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1052
|
-
return { _tag: "Success", data: void 0 };
|
|
1053
|
-
} catch (e2) {
|
|
1054
|
-
return { _tag: "Failure", error: e2 };
|
|
1055
|
-
}
|
|
1056
|
-
},
|
|
1057
|
-
async removeDiscount({ subscriptionId, discountId }) {
|
|
1058
|
-
try {
|
|
1059
|
-
const res = await fetcher(
|
|
1060
|
-
`/customer/v1/subscriptions/${subscriptionId}/discounts/${discountId}`,
|
|
1061
|
-
{ method: "DELETE" }
|
|
1062
|
-
);
|
|
1063
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1064
|
-
return { _tag: "Success", data: void 0 };
|
|
1065
|
-
} catch (e2) {
|
|
1066
|
-
return { _tag: "Failure", error: e2 };
|
|
1067
|
-
}
|
|
1068
|
-
},
|
|
1069
|
-
async reschedule({ subscriptionId, newDate }) {
|
|
1070
|
-
try {
|
|
1071
|
-
const res = await fetcher(
|
|
1072
|
-
`/customer/v1/subscriptions/${subscriptionId}/reschedule`,
|
|
1073
|
-
{
|
|
1074
|
-
method: "POST",
|
|
1075
|
-
headers: { "Content-Type": "application/json" },
|
|
1076
|
-
body: JSON.stringify({ newDate })
|
|
1077
|
-
}
|
|
1078
|
-
);
|
|
1079
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1080
|
-
const data = await res.json();
|
|
1081
|
-
if (data.nextDeliveryDate)
|
|
1082
|
-
data.nextDeliveryDate = new Date(data.nextDeliveryDate);
|
|
1083
|
-
return { _tag: "Success", data };
|
|
1084
|
-
} catch (e2) {
|
|
1085
|
-
return { _tag: "Failure", error: e2 };
|
|
1086
|
-
}
|
|
1087
|
-
},
|
|
1088
|
-
async resume({ subscriptionId }) {
|
|
1089
|
-
try {
|
|
1090
|
-
const res = await fetcher(
|
|
1091
|
-
`/customer/v1/subscriptions/${subscriptionId}/resume`,
|
|
1092
|
-
{ method: "POST" }
|
|
1093
|
-
);
|
|
1094
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1095
|
-
const data = await res.json();
|
|
1096
|
-
return { _tag: "Success", data };
|
|
1097
|
-
} catch (e2) {
|
|
1098
|
-
return { _tag: "Failure", error: e2 };
|
|
1099
|
-
}
|
|
1100
|
-
},
|
|
1101
|
-
async pause({ subscriptionId }) {
|
|
1102
|
-
try {
|
|
1103
|
-
const res = await fetcher(
|
|
1104
|
-
`/customer/v1/subscriptions/${subscriptionId}/pause`,
|
|
1105
|
-
{ method: "POST" }
|
|
1106
|
-
);
|
|
1107
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1108
|
-
const data = await res.json();
|
|
1109
|
-
return { _tag: "Success", data };
|
|
1110
|
-
} catch (e2) {
|
|
1111
|
-
return { _tag: "Failure", error: e2 };
|
|
1112
|
-
}
|
|
1113
|
-
},
|
|
1114
|
-
async reactivate({ subscriptionId }) {
|
|
1115
|
-
try {
|
|
1116
|
-
const res = await fetcher(
|
|
1117
|
-
`/customer/v1/subscriptions/${subscriptionId}/reactivate`,
|
|
1118
|
-
{ method: "POST" }
|
|
1119
|
-
);
|
|
1120
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1121
|
-
const data = await res.json();
|
|
1122
|
-
return { _tag: "Success", data };
|
|
1123
|
-
} catch (e2) {
|
|
1124
|
-
return { _tag: "Failure", error: e2 };
|
|
1125
|
-
}
|
|
1126
|
-
},
|
|
1127
|
-
async cancel({ subscriptionId, reason }) {
|
|
1128
|
-
try {
|
|
1129
|
-
const res = await fetcher(
|
|
1130
|
-
`/customer/v1/subscriptions/${subscriptionId}/cancel`,
|
|
1131
|
-
{
|
|
1132
|
-
method: "POST",
|
|
1133
|
-
headers: { "Content-Type": "application/json" },
|
|
1134
|
-
body: JSON.stringify({ reason })
|
|
1135
|
-
}
|
|
1136
|
-
);
|
|
1137
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1138
|
-
const data = await res.json();
|
|
1139
|
-
return { _tag: "Success", data };
|
|
1140
|
-
} catch (e2) {
|
|
1141
|
-
return { _tag: "Failure", error: e2 };
|
|
1142
|
-
}
|
|
1143
|
-
},
|
|
1144
|
-
async getAvailablePlans({ subscriptionId }) {
|
|
1145
|
-
try {
|
|
1146
|
-
const res = await fetcher(
|
|
1147
|
-
`/customer/v1/subscriptions/${subscriptionId}/plans`
|
|
1148
|
-
);
|
|
1149
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1150
|
-
const data = await res.json();
|
|
1151
|
-
return { _tag: "Success", data: data.items };
|
|
1152
|
-
} catch (e2) {
|
|
1153
|
-
return { _tag: "Failure", error: e2 };
|
|
1154
|
-
}
|
|
1155
|
-
},
|
|
1156
|
-
async getDefaultSubscriptionId() {
|
|
1157
|
-
var _a;
|
|
1158
|
-
try {
|
|
1159
|
-
const res = await fetcher(`/customer/v1/subscriptions?limit=1`);
|
|
1160
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1161
|
-
const body = await res.json();
|
|
1162
|
-
return { _tag: "Success", data: ((_a = body.data[0]) == null ? void 0 : _a.id) ?? null };
|
|
1163
|
-
} catch (e2) {
|
|
1164
|
-
return { _tag: "Failure", error: e2 };
|
|
1165
|
-
}
|
|
1166
|
-
},
|
|
1167
|
-
async getDeliveryFrequencies({ subscriptionId }) {
|
|
1168
|
-
try {
|
|
1169
|
-
const res = await fetcher(
|
|
1170
|
-
`/customer/v1/subscriptions/${subscriptionId}/frequencies`
|
|
1171
|
-
);
|
|
1172
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1173
|
-
const data = await res.json();
|
|
1174
|
-
return { _tag: "Success", data: data.items };
|
|
1175
|
-
} catch (e2) {
|
|
1176
|
-
return { _tag: "Failure", error: e2 };
|
|
1177
|
-
}
|
|
1178
|
-
},
|
|
1179
|
-
async getUpsellProducts({ subscriptionId }) {
|
|
1180
|
-
try {
|
|
1181
|
-
const res = await fetcher(
|
|
1182
|
-
`/customer/v1/subscriptions/${subscriptionId}/upsells`
|
|
1183
|
-
);
|
|
1184
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1185
|
-
const data = await res.json();
|
|
1186
|
-
return { _tag: "Success", data: data.items };
|
|
1187
|
-
} catch (e2) {
|
|
1188
|
-
return { _tag: "Failure", error: e2 };
|
|
1189
|
-
}
|
|
1190
|
-
},
|
|
1191
|
-
async addUpsellProduct({ subscriptionId, variantId, quantity, oneTime }) {
|
|
1192
|
-
try {
|
|
1193
|
-
const res = await fetcher(
|
|
1194
|
-
`/customer/v1/subscriptions/${subscriptionId}/upsells`,
|
|
1195
|
-
{
|
|
1196
|
-
method: "POST",
|
|
1197
|
-
headers: { "Content-Type": "application/json" },
|
|
1198
|
-
body: JSON.stringify({ variantId, quantity, oneTime })
|
|
1199
|
-
}
|
|
1200
|
-
);
|
|
1201
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1202
|
-
return { _tag: "Success", data: void 0 };
|
|
1203
|
-
} catch (e2) {
|
|
1204
|
-
return { _tag: "Failure", error: e2 };
|
|
1205
|
-
}
|
|
1206
|
-
},
|
|
1207
|
-
async changeFrequency({ subscriptionId, sellingPlanId }) {
|
|
1208
|
-
try {
|
|
1209
|
-
const res = await fetcher(
|
|
1210
|
-
`/customer/v1/subscriptions/${subscriptionId}/frequency`,
|
|
1211
|
-
{
|
|
1212
|
-
method: "POST",
|
|
1213
|
-
headers: { "Content-Type": "application/json" },
|
|
1214
|
-
body: JSON.stringify({ sellingPlanId })
|
|
1215
|
-
}
|
|
1216
|
-
);
|
|
1217
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1218
|
-
const data = await res.json();
|
|
1219
|
-
return { _tag: "Success", data };
|
|
1220
|
-
} catch (e2) {
|
|
1221
|
-
return { _tag: "Failure", error: e2 };
|
|
1222
|
-
}
|
|
1223
866
|
}
|
|
1224
867
|
};
|
|
1225
868
|
}
|
|
@@ -1245,24 +888,9 @@ function getCurrentSubscriptionId() {
|
|
|
1245
888
|
}
|
|
1246
889
|
function createSubscriptionService(adapter) {
|
|
1247
890
|
const current = d(null);
|
|
1248
|
-
const
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
hasPendingBilling,
|
|
1252
|
-
async search(options) {
|
|
1253
|
-
const result = await adapter.search(options);
|
|
1254
|
-
if (result._tag === "Success") {
|
|
1255
|
-
current.value = result.data.items[0] ?? null;
|
|
1256
|
-
}
|
|
1257
|
-
return result;
|
|
1258
|
-
},
|
|
1259
|
-
async getById(id) {
|
|
1260
|
-
const result = await adapter.getById(id);
|
|
1261
|
-
if (result._tag === "Success" && result.data) {
|
|
1262
|
-
current.value = result.data;
|
|
1263
|
-
}
|
|
1264
|
-
return result;
|
|
1265
|
-
},
|
|
891
|
+
const service = {
|
|
892
|
+
search: adapter.search,
|
|
893
|
+
getById: adapter.getById,
|
|
1266
894
|
getCurrentSubscriptionId,
|
|
1267
895
|
addItem: (subscriptionId, item) => adapter.addItem({ subscriptionId, item }),
|
|
1268
896
|
removeItem: (subscriptionId, itemId) => adapter.removeItem({ subscriptionId, itemId }),
|
|
@@ -1275,508 +903,16 @@ function createSubscriptionService(adapter) {
|
|
|
1275
903
|
cancel: (subscriptionId, reason) => adapter.cancel({ subscriptionId, reason }),
|
|
1276
904
|
getAvailablePlans: (subscriptionId) => adapter.getAvailablePlans({ subscriptionId }),
|
|
1277
905
|
getDefaultSubscriptionId: () => adapter.getDefaultSubscriptionId(),
|
|
1278
|
-
|
|
1279
|
-
getUpsellProducts: (params) => adapter.getUpsellProducts ? adapter.getUpsellProducts(params) : Promise.resolve({ _tag: "Success", data: [] }),
|
|
1280
|
-
addUpsellProduct: (params) => adapter.addUpsellProduct ? adapter.addUpsellProduct(params) : Promise.resolve({ _tag: "Success", data: void 0 }),
|
|
1281
|
-
changeFrequency: (params) => adapter.changeFrequency ? adapter.changeFrequency(params) : Promise.resolve({ _tag: "Failure", error: "Not implemented" })
|
|
1282
|
-
};
|
|
1283
|
-
}
|
|
1284
|
-
function createMockCustomerAdapter() {
|
|
1285
|
-
let customers = [
|
|
1286
|
-
{
|
|
1287
|
-
id: "customer-1",
|
|
1288
|
-
name: "Customer 1",
|
|
1289
|
-
metadata: { mealCount: 3 }
|
|
1290
|
-
},
|
|
1291
|
-
{
|
|
1292
|
-
id: "customer-2",
|
|
1293
|
-
name: "Customer 2",
|
|
1294
|
-
metadata: { mealCount: 4 }
|
|
1295
|
-
}
|
|
1296
|
-
];
|
|
1297
|
-
return {
|
|
1298
|
-
async getCurrent() {
|
|
1299
|
-
return { _tag: "Success", data: customers[0] ?? null };
|
|
1300
|
-
},
|
|
1301
|
-
async getAll() {
|
|
1302
|
-
return { _tag: "Success", data: [...customers] };
|
|
1303
|
-
},
|
|
1304
|
-
async getById(id) {
|
|
1305
|
-
return {
|
|
1306
|
-
_tag: "Success",
|
|
1307
|
-
data: customers.find((c2) => c2.id === id) ?? null
|
|
1308
|
-
};
|
|
1309
|
-
},
|
|
1310
|
-
async create(data) {
|
|
1311
|
-
const customer = { id: `customer-${Date.now()}`, ...data };
|
|
1312
|
-
customers = [...customers, customer];
|
|
1313
|
-
return { _tag: "Success", data: customer };
|
|
1314
|
-
},
|
|
1315
|
-
async update(id, data) {
|
|
1316
|
-
const existing = customers.find((c2) => c2.id === id);
|
|
1317
|
-
if (!existing) return { _tag: "Failure", error: "Customer not found" };
|
|
1318
|
-
const updated = { ...existing, ...data };
|
|
1319
|
-
customers = customers.map((c2) => c2.id === id ? updated : c2);
|
|
1320
|
-
return { _tag: "Success", data: updated };
|
|
1321
|
-
},
|
|
1322
|
-
async remove(id) {
|
|
1323
|
-
customers = customers.filter((c2) => c2.id !== id);
|
|
1324
|
-
return { _tag: "Success", data: void 0 };
|
|
1325
|
-
}
|
|
1326
|
-
};
|
|
1327
|
-
}
|
|
1328
|
-
function createApiCustomerAdapter(fetcher) {
|
|
1329
|
-
return {
|
|
1330
|
-
async getCurrent() {
|
|
1331
|
-
try {
|
|
1332
|
-
const res = await fetcher("/customer/v1/customer");
|
|
1333
|
-
if (!res.ok) return { _tag: "Failure", error: await res.text() };
|
|
1334
|
-
const data = await res.json();
|
|
1335
|
-
return { _tag: "Success", data };
|
|
1336
|
-
} catch (e2) {
|
|
1337
|
-
return { _tag: "Failure", error: e2 };
|
|
1338
|
-
}
|
|
1339
|
-
},
|
|
1340
|
-
async getAll() {
|
|
1341
|
-
try {
|
|
1342
|
-
const res = await fetcher("/customer/v1/customers");
|
|
1343
|
-
if (!res.ok) return { _tag: "Failure", error: await res.text() };
|
|
1344
|
-
const data = await res.json();
|
|
1345
|
-
return { _tag: "Success", data };
|
|
1346
|
-
} catch (e2) {
|
|
1347
|
-
return { _tag: "Failure", error: e2 };
|
|
1348
|
-
}
|
|
1349
|
-
},
|
|
1350
|
-
async getById(id) {
|
|
1351
|
-
try {
|
|
1352
|
-
const res = await fetcher(`/customer/v1/customers/${id}`);
|
|
1353
|
-
if (!res.ok) return { _tag: "Failure", error: await res.text() };
|
|
1354
|
-
const data = await res.json();
|
|
1355
|
-
return { _tag: "Success", data };
|
|
1356
|
-
} catch (e2) {
|
|
1357
|
-
return { _tag: "Failure", error: e2 };
|
|
1358
|
-
}
|
|
1359
|
-
},
|
|
1360
|
-
async create(data) {
|
|
1361
|
-
try {
|
|
1362
|
-
const res = await fetcher("/customer/v1/customers", {
|
|
1363
|
-
method: "POST",
|
|
1364
|
-
headers: { "Content-Type": "application/json" },
|
|
1365
|
-
body: JSON.stringify(data)
|
|
1366
|
-
});
|
|
1367
|
-
if (!res.ok) return { _tag: "Failure", error: await res.text() };
|
|
1368
|
-
const created = await res.json();
|
|
1369
|
-
return { _tag: "Success", data: created };
|
|
1370
|
-
} catch (e2) {
|
|
1371
|
-
return { _tag: "Failure", error: e2 };
|
|
1372
|
-
}
|
|
1373
|
-
},
|
|
1374
|
-
async update(id, data) {
|
|
1375
|
-
try {
|
|
1376
|
-
const res = await fetcher(`/customer/v1/customers/${id}`, {
|
|
1377
|
-
method: "PATCH",
|
|
1378
|
-
headers: { "Content-Type": "application/json" },
|
|
1379
|
-
body: JSON.stringify(data)
|
|
1380
|
-
});
|
|
1381
|
-
if (!res.ok) return { _tag: "Failure", error: await res.text() };
|
|
1382
|
-
const updated = await res.json();
|
|
1383
|
-
return { _tag: "Success", data: updated };
|
|
1384
|
-
} catch (e2) {
|
|
1385
|
-
return { _tag: "Failure", error: e2 };
|
|
1386
|
-
}
|
|
1387
|
-
},
|
|
1388
|
-
async remove(id) {
|
|
1389
|
-
try {
|
|
1390
|
-
const res = await fetcher(`/customer/v1/customers/${id}`, {
|
|
1391
|
-
method: "DELETE"
|
|
1392
|
-
});
|
|
1393
|
-
if (!res.ok) return { _tag: "Failure", error: await res.text() };
|
|
1394
|
-
return { _tag: "Success", data: void 0 };
|
|
1395
|
-
} catch (e2) {
|
|
1396
|
-
return { _tag: "Failure", error: e2 };
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
906
|
+
current
|
|
1399
907
|
};
|
|
908
|
+
return service;
|
|
1400
909
|
}
|
|
1401
910
|
const CustomerServiceContext = createContext("services/customer");
|
|
1402
|
-
function createCustomerService(
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
getById: (id) => adapter.getById(id),
|
|
1407
|
-
create: (data) => adapter.create(data),
|
|
1408
|
-
update: (id, data) => adapter.update(id, data),
|
|
1409
|
-
remove: (id) => adapter.remove(id)
|
|
1410
|
-
};
|
|
1411
|
-
}
|
|
1412
|
-
function createMockOrderAdapter() {
|
|
1413
|
-
let orders = [
|
|
1414
|
-
{
|
|
1415
|
-
id: "order-1",
|
|
1416
|
-
customerId: "customer-1",
|
|
1417
|
-
items: [],
|
|
1418
|
-
deliveryDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3).toISOString().split("T")[0] ?? null,
|
|
1419
|
-
status: "pending"
|
|
1420
|
-
},
|
|
1421
|
-
{
|
|
1422
|
-
id: "order-2",
|
|
1423
|
-
customerId: "customer-1",
|
|
1424
|
-
items: [
|
|
1425
|
-
{ id: "item-1", productId: "p1", variantId: "v1", quantity: 1 },
|
|
1426
|
-
{ id: "item-2", productId: "p2", variantId: "v2", quantity: 2 }
|
|
1427
|
-
],
|
|
1428
|
-
deliveryDate: new Date(Date.now() - 30 * 24 * 60 * 60 * 1e3).toISOString().split("T")[0] ?? null,
|
|
1429
|
-
status: "delivered"
|
|
1430
|
-
},
|
|
1431
|
-
{
|
|
1432
|
-
id: "order-3",
|
|
1433
|
-
customerId: "customer-1",
|
|
1434
|
-
items: [
|
|
1435
|
-
{ id: "item-3", productId: "p1", variantId: "v1", quantity: 1 }
|
|
1436
|
-
],
|
|
1437
|
-
deliveryDate: new Date(Date.now() - 60 * 24 * 60 * 60 * 1e3).toISOString().split("T")[0] ?? null,
|
|
1438
|
-
status: "delivered"
|
|
1439
|
-
},
|
|
1440
|
-
{
|
|
1441
|
-
id: "order-4",
|
|
1442
|
-
customerId: "customer-1",
|
|
1443
|
-
items: [],
|
|
1444
|
-
deliveryDate: new Date(Date.now() - 90 * 24 * 60 * 60 * 1e3).toISOString().split("T")[0] ?? null,
|
|
1445
|
-
status: "skipped"
|
|
1446
|
-
}
|
|
1447
|
-
];
|
|
1448
|
-
return {
|
|
1449
|
-
async getUpcoming() {
|
|
1450
|
-
return {
|
|
1451
|
-
_tag: "Success",
|
|
1452
|
-
data: orders.filter((o2) => o2.status === "pending")
|
|
1453
|
-
};
|
|
1454
|
-
},
|
|
1455
|
-
async getHistory() {
|
|
1456
|
-
return {
|
|
1457
|
-
_tag: "Success",
|
|
1458
|
-
data: orders.filter((o2) => o2.status === "delivered" || o2.status === "skipped").sort((a3, b3) => (b3.deliveryDate ?? "").localeCompare(a3.deliveryDate ?? ""))
|
|
1459
|
-
};
|
|
1460
|
-
},
|
|
1461
|
-
async getById(id) {
|
|
1462
|
-
return {
|
|
1463
|
-
_tag: "Success",
|
|
1464
|
-
data: orders.find((o2) => o2.id === id) ?? null
|
|
1465
|
-
};
|
|
1466
|
-
},
|
|
1467
|
-
async updateItems(orderId, items) {
|
|
1468
|
-
const order = orders.find((o2) => o2.id === orderId);
|
|
1469
|
-
if (!order) return { _tag: "Failure", error: "Order not found" };
|
|
1470
|
-
const updated = {
|
|
1471
|
-
...order,
|
|
1472
|
-
items: items.map((item, i2) => ({
|
|
1473
|
-
id: `item-${Date.now()}-${i2}`,
|
|
1474
|
-
...item
|
|
1475
|
-
}))
|
|
1476
|
-
};
|
|
1477
|
-
orders = orders.map((o2) => o2.id === orderId ? updated : o2);
|
|
1478
|
-
return { _tag: "Success", data: updated };
|
|
1479
|
-
},
|
|
1480
|
-
async skip(orderId) {
|
|
1481
|
-
const order = orders.find((o2) => o2.id === orderId);
|
|
1482
|
-
if (!order) return { _tag: "Failure", error: "Order not found" };
|
|
1483
|
-
const updated = { ...order, status: "skipped" };
|
|
1484
|
-
orders = orders.map((o2) => o2.id === orderId ? updated : o2);
|
|
1485
|
-
return { _tag: "Success", data: updated };
|
|
1486
|
-
}
|
|
1487
|
-
};
|
|
1488
|
-
}
|
|
1489
|
-
function createApiOrderAdapter(fetcher) {
|
|
1490
|
-
return {
|
|
1491
|
-
async getUpcoming() {
|
|
1492
|
-
try {
|
|
1493
|
-
const res = await fetcher("/customer/v1/orders?status=pending");
|
|
1494
|
-
if (!res.ok) return { _tag: "Failure", error: await res.text() };
|
|
1495
|
-
const body = await res.json();
|
|
1496
|
-
return { _tag: "Success", data: body.orders };
|
|
1497
|
-
} catch (e2) {
|
|
1498
|
-
return { _tag: "Failure", error: e2 };
|
|
1499
|
-
}
|
|
1500
|
-
},
|
|
1501
|
-
async getHistory() {
|
|
1502
|
-
try {
|
|
1503
|
-
const res = await fetcher("/customer/v1/orders?status=delivered,skipped");
|
|
1504
|
-
if (!res.ok) return { _tag: "Failure", error: await res.text() };
|
|
1505
|
-
const body = await res.json();
|
|
1506
|
-
return { _tag: "Success", data: body.orders };
|
|
1507
|
-
} catch (e2) {
|
|
1508
|
-
return { _tag: "Failure", error: e2 };
|
|
1509
|
-
}
|
|
1510
|
-
},
|
|
1511
|
-
async getById(id) {
|
|
1512
|
-
try {
|
|
1513
|
-
const res = await fetcher(`/customer/v1/orders/${id}`);
|
|
1514
|
-
if (!res.ok) return { _tag: "Failure", error: await res.text() };
|
|
1515
|
-
const data = await res.json();
|
|
1516
|
-
return { _tag: "Success", data };
|
|
1517
|
-
} catch (e2) {
|
|
1518
|
-
return { _tag: "Failure", error: e2 };
|
|
1519
|
-
}
|
|
1520
|
-
},
|
|
1521
|
-
async updateItems(orderId, items) {
|
|
1522
|
-
try {
|
|
1523
|
-
const res = await fetcher(`/customer/v1/orders/${orderId}/items`, {
|
|
1524
|
-
method: "PUT",
|
|
1525
|
-
headers: { "Content-Type": "application/json" },
|
|
1526
|
-
body: JSON.stringify({ items })
|
|
1527
|
-
});
|
|
1528
|
-
if (!res.ok) return { _tag: "Failure", error: await res.text() };
|
|
1529
|
-
const data = await res.json();
|
|
1530
|
-
return { _tag: "Success", data };
|
|
1531
|
-
} catch (e2) {
|
|
1532
|
-
return { _tag: "Failure", error: e2 };
|
|
1533
|
-
}
|
|
1534
|
-
},
|
|
1535
|
-
async skip(orderId) {
|
|
1536
|
-
try {
|
|
1537
|
-
const res = await fetcher(`/customer/v1/orders/${orderId}/skip`, {
|
|
1538
|
-
method: "POST"
|
|
1539
|
-
});
|
|
1540
|
-
if (!res.ok) return { _tag: "Failure", error: await res.text() };
|
|
1541
|
-
const data = await res.json();
|
|
1542
|
-
return { _tag: "Success", data };
|
|
1543
|
-
} catch (e2) {
|
|
1544
|
-
return { _tag: "Failure", error: e2 };
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1547
|
-
};
|
|
1548
|
-
}
|
|
1549
|
-
const OrderServiceContext = createContext("services/order");
|
|
1550
|
-
function createOrderService(adapter) {
|
|
1551
|
-
return {
|
|
1552
|
-
getUpcoming: () => adapter.getUpcoming(),
|
|
1553
|
-
getHistory: () => adapter.getHistory(),
|
|
1554
|
-
getById: (id) => adapter.getById(id),
|
|
1555
|
-
updateItems: (orderId, items) => adapter.updateItems(orderId, items),
|
|
1556
|
-
skip: (orderId) => adapter.skip(orderId)
|
|
1557
|
-
};
|
|
1558
|
-
}
|
|
1559
|
-
function futureDateStr(daysFromNow) {
|
|
1560
|
-
const d2 = /* @__PURE__ */ new Date();
|
|
1561
|
-
d2.setDate(d2.getDate() + daysFromNow);
|
|
1562
|
-
return d2.toISOString().split("T")[0] ?? "";
|
|
1563
|
-
}
|
|
1564
|
-
function createMockSchedulesAdapter() {
|
|
1565
|
-
let orders = [
|
|
1566
|
-
{
|
|
1567
|
-
id: "schedule-order-1",
|
|
1568
|
-
subscriptionId: "sub_1",
|
|
1569
|
-
deliveryDate: futureDateStr(7),
|
|
1570
|
-
items: [
|
|
1571
|
-
{
|
|
1572
|
-
id: "si-1",
|
|
1573
|
-
productId: "p-beauty-1",
|
|
1574
|
-
variantId: "v-beauty-1",
|
|
1575
|
-
quantity: 1,
|
|
1576
|
-
title: "Rose Face Serum",
|
|
1577
|
-
imageUrl: "https://images.unsplash.com/photo-1611930022073-b7a4ba5fcccd?w=200"
|
|
1578
|
-
},
|
|
1579
|
-
{
|
|
1580
|
-
id: "si-2",
|
|
1581
|
-
productId: "p-beauty-2",
|
|
1582
|
-
variantId: "v-beauty-2",
|
|
1583
|
-
quantity: 1,
|
|
1584
|
-
title: "Vitamin C Moisturizer",
|
|
1585
|
-
imageUrl: "https://images.unsplash.com/photo-1556228578-8c89e6adf883?w=200"
|
|
1586
|
-
}
|
|
1587
|
-
],
|
|
1588
|
-
status: "scheduled"
|
|
1589
|
-
},
|
|
1590
|
-
{
|
|
1591
|
-
id: "schedule-order-2",
|
|
1592
|
-
subscriptionId: "sub_1",
|
|
1593
|
-
deliveryDate: futureDateStr(35),
|
|
1594
|
-
items: [
|
|
1595
|
-
{
|
|
1596
|
-
id: "si-3",
|
|
1597
|
-
productId: "p-beauty-1",
|
|
1598
|
-
variantId: "v-beauty-1",
|
|
1599
|
-
quantity: 1,
|
|
1600
|
-
title: "Rose Face Serum",
|
|
1601
|
-
imageUrl: "https://images.unsplash.com/photo-1611930022073-b7a4ba5fcccd?w=200"
|
|
1602
|
-
},
|
|
1603
|
-
{
|
|
1604
|
-
id: "si-4",
|
|
1605
|
-
productId: "p-beauty-3",
|
|
1606
|
-
variantId: "v-beauty-3",
|
|
1607
|
-
quantity: 1,
|
|
1608
|
-
title: "Hyaluronic Acid Serum",
|
|
1609
|
-
imageUrl: "https://images.unsplash.com/photo-1621232201696-ba6c9db10a97?w=200"
|
|
1610
|
-
}
|
|
1611
|
-
],
|
|
1612
|
-
status: "scheduled"
|
|
1613
|
-
}
|
|
1614
|
-
];
|
|
1615
|
-
let adjustments = [];
|
|
1616
|
-
return {
|
|
1617
|
-
async getUpcomingOrders(count) {
|
|
1618
|
-
await new Promise((r2) => setTimeout(r2, 200));
|
|
1619
|
-
return { _tag: "Success", data: orders.slice(0, count) };
|
|
1620
|
-
},
|
|
1621
|
-
async getAdjustments() {
|
|
1622
|
-
await new Promise((r2) => setTimeout(r2, 200));
|
|
1623
|
-
return { _tag: "Success", data: [...adjustments] };
|
|
1624
|
-
},
|
|
1625
|
-
async skipOrder({ subscriptionId }) {
|
|
1626
|
-
await new Promise((r2) => setTimeout(r2, 300));
|
|
1627
|
-
const order = orders.find(
|
|
1628
|
-
(o2) => o2.subscriptionId === subscriptionId && o2.status === "scheduled"
|
|
1629
|
-
);
|
|
1630
|
-
if (!order) return { _tag: "Failure", error: "No scheduled order found" };
|
|
1631
|
-
orders = orders.map(
|
|
1632
|
-
(o2) => o2.id === order.id ? { ...o2, status: "skipped" } : o2
|
|
1633
|
-
);
|
|
1634
|
-
const adj = {
|
|
1635
|
-
id: `adj-${Date.now()}`,
|
|
1636
|
-
subscriptionId,
|
|
1637
|
-
type: "skip"
|
|
1638
|
-
};
|
|
1639
|
-
adjustments = [...adjustments, adj];
|
|
1640
|
-
return { _tag: "Success", data: void 0 };
|
|
1641
|
-
},
|
|
1642
|
-
async changeDateAdjustment({ subscriptionId, newDate }) {
|
|
1643
|
-
await new Promise((r2) => setTimeout(r2, 300));
|
|
1644
|
-
const order = orders.find(
|
|
1645
|
-
(o2) => o2.subscriptionId === subscriptionId && o2.status === "scheduled"
|
|
1646
|
-
);
|
|
1647
|
-
if (!order) return { _tag: "Failure", error: "No scheduled order found" };
|
|
1648
|
-
orders = orders.map(
|
|
1649
|
-
(o2) => o2.id === order.id ? { ...o2, deliveryDate: newDate } : o2
|
|
1650
|
-
);
|
|
1651
|
-
const adj = {
|
|
1652
|
-
id: `adj-${Date.now()}`,
|
|
1653
|
-
subscriptionId,
|
|
1654
|
-
type: "date_change",
|
|
1655
|
-
newDate
|
|
1656
|
-
};
|
|
1657
|
-
adjustments = [...adjustments, adj];
|
|
1658
|
-
return { _tag: "Success", data: void 0 };
|
|
1659
|
-
},
|
|
1660
|
-
async removeAdjustment({ adjustmentId }) {
|
|
1661
|
-
await new Promise((r2) => setTimeout(r2, 200));
|
|
1662
|
-
adjustments = adjustments.filter((a3) => a3.id !== adjustmentId);
|
|
1663
|
-
return { _tag: "Success", data: void 0 };
|
|
1664
|
-
}
|
|
1665
|
-
};
|
|
1666
|
-
}
|
|
1667
|
-
function createApiSchedulesAdapter(fetcher) {
|
|
1668
|
-
return {
|
|
1669
|
-
async getUpcomingOrders(count) {
|
|
1670
|
-
try {
|
|
1671
|
-
const res = await fetcher(
|
|
1672
|
-
`/customer/v1/schedules?count=${count}`
|
|
1673
|
-
);
|
|
1674
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1675
|
-
const data = await res.json();
|
|
1676
|
-
return { _tag: "Success", data: data.orders };
|
|
1677
|
-
} catch (e2) {
|
|
1678
|
-
return { _tag: "Failure", error: e2 };
|
|
1679
|
-
}
|
|
1680
|
-
},
|
|
1681
|
-
async getAdjustments() {
|
|
1682
|
-
try {
|
|
1683
|
-
const res = await fetcher(`/customer/v1/schedules/adjustments`);
|
|
1684
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1685
|
-
const data = await res.json();
|
|
1686
|
-
return { _tag: "Success", data: data.items };
|
|
1687
|
-
} catch (e2) {
|
|
1688
|
-
return { _tag: "Failure", error: e2 };
|
|
1689
|
-
}
|
|
1690
|
-
},
|
|
1691
|
-
async skipOrder(params) {
|
|
1692
|
-
try {
|
|
1693
|
-
const res = await fetcher(`/customer/v1/schedules/adjustments`, {
|
|
1694
|
-
method: "POST",
|
|
1695
|
-
headers: { "Content-Type": "application/json" },
|
|
1696
|
-
body: JSON.stringify({ action: "skip", ...params })
|
|
1697
|
-
});
|
|
1698
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1699
|
-
return { _tag: "Success", data: void 0 };
|
|
1700
|
-
} catch (e2) {
|
|
1701
|
-
return { _tag: "Failure", error: e2 };
|
|
1702
|
-
}
|
|
1703
|
-
},
|
|
1704
|
-
async changeDateAdjustment(params) {
|
|
1705
|
-
try {
|
|
1706
|
-
const res = await fetcher(`/customer/v1/schedules/adjustments`, {
|
|
1707
|
-
method: "POST",
|
|
1708
|
-
headers: { "Content-Type": "application/json" },
|
|
1709
|
-
body: JSON.stringify({ action: "date_change", ...params })
|
|
1710
|
-
});
|
|
1711
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1712
|
-
return { _tag: "Success", data: void 0 };
|
|
1713
|
-
} catch (e2) {
|
|
1714
|
-
return { _tag: "Failure", error: e2 };
|
|
1715
|
-
}
|
|
1716
|
-
},
|
|
1717
|
-
async removeAdjustment({ adjustmentId }) {
|
|
1718
|
-
try {
|
|
1719
|
-
const res = await fetcher(
|
|
1720
|
-
`/customer/v1/schedules/adjustments/${adjustmentId}`,
|
|
1721
|
-
{ method: "DELETE" }
|
|
1722
|
-
);
|
|
1723
|
-
if (!res.ok) return { _tag: "Failure", error: `HTTP ${res.status}` };
|
|
1724
|
-
return { _tag: "Success", data: void 0 };
|
|
1725
|
-
} catch (e2) {
|
|
1726
|
-
return { _tag: "Failure", error: e2 };
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
};
|
|
1730
|
-
}
|
|
1731
|
-
const SchedulesServiceContext = createContext("services/schedules");
|
|
1732
|
-
function createSchedulesService(adapter, opts) {
|
|
1733
|
-
const upcoming = d([]);
|
|
1734
|
-
async function refreshUpcoming() {
|
|
1735
|
-
const count = Math.max(upcoming.value.length, 3);
|
|
1736
|
-
const result = await adapter.getUpcomingOrders(count);
|
|
1737
|
-
if (result._tag === "Success") {
|
|
1738
|
-
upcoming.value = result.data;
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
return {
|
|
1742
|
-
upcoming,
|
|
1743
|
-
hasPendingBilling: opts.hasPendingBilling,
|
|
1744
|
-
async getUpcomingOrder() {
|
|
1745
|
-
const result = await adapter.getUpcomingOrders(1);
|
|
1746
|
-
if (result._tag === "Failure") return result;
|
|
1747
|
-
upcoming.value = result.data;
|
|
1748
|
-
return { _tag: "Success", data: result.data[0] ?? null };
|
|
1749
|
-
},
|
|
1750
|
-
async getUpcomingOrders(count) {
|
|
1751
|
-
const result = await adapter.getUpcomingOrders(count);
|
|
1752
|
-
if (result._tag === "Success") {
|
|
1753
|
-
upcoming.value = result.data;
|
|
1754
|
-
}
|
|
1755
|
-
return result;
|
|
1756
|
-
},
|
|
1757
|
-
async getAdjustments() {
|
|
1758
|
-
return adapter.getAdjustments();
|
|
1759
|
-
},
|
|
1760
|
-
async skipOrder(params) {
|
|
1761
|
-
const result = await adapter.skipOrder(params);
|
|
1762
|
-
if (result._tag === "Success") {
|
|
1763
|
-
await refreshUpcoming();
|
|
1764
|
-
}
|
|
1765
|
-
return result;
|
|
1766
|
-
},
|
|
1767
|
-
async changeDateAdjustment(params) {
|
|
1768
|
-
const result = await adapter.changeDateAdjustment(params);
|
|
1769
|
-
if (result._tag === "Success") {
|
|
1770
|
-
await refreshUpcoming();
|
|
1771
|
-
}
|
|
1772
|
-
return result;
|
|
1773
|
-
},
|
|
1774
|
-
async removeAdjustment(params) {
|
|
1775
|
-
return adapter.removeAdjustment(params);
|
|
1776
|
-
}
|
|
1777
|
-
};
|
|
911
|
+
function createCustomerService() {
|
|
912
|
+
const current = d(null);
|
|
913
|
+
const service = { current };
|
|
914
|
+
return service;
|
|
1778
915
|
}
|
|
1779
|
-
const RouterServiceContext = createContext("services/router");
|
|
1780
916
|
const MOCK_FLOWS = {
|
|
1781
917
|
cancellation: [
|
|
1782
918
|
{
|
|
@@ -2031,15 +1167,12 @@ export {
|
|
|
2031
1167
|
AuthenticationError,
|
|
2032
1168
|
AuthenticationErrorReason,
|
|
2033
1169
|
B as BlockWrapperEvent,
|
|
2034
|
-
|
|
2035
|
-
|
|
1170
|
+
C as ContextProvideEvent,
|
|
1171
|
+
a as ContextRequestEvent,
|
|
2036
1172
|
CustomerServiceContext,
|
|
2037
1173
|
D as DEFAULT_GLOBAL_STYLES,
|
|
2038
1174
|
LoginServiceContext,
|
|
2039
|
-
OrderServiceContext,
|
|
2040
1175
|
ProductServiceContext,
|
|
2041
|
-
RouterServiceContext,
|
|
2042
|
-
SchedulesServiceContext,
|
|
2043
1176
|
S as SelectedBlockContext,
|
|
2044
1177
|
u as Signal,
|
|
2045
1178
|
StateContext,
|
|
@@ -2048,47 +1181,38 @@ export {
|
|
|
2048
1181
|
T2 as TranslationContext,
|
|
2049
1182
|
W as WorkflowServiceContext,
|
|
2050
1183
|
w as computed,
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
a as createBlockInstance,
|
|
2056
|
-
b as createBlockInstanceFromJSON,
|
|
2057
|
-
e as createBlockInstanceFromObject,
|
|
2058
|
-
f as createCeRenderer,
|
|
1184
|
+
b as createBlockInstance,
|
|
1185
|
+
e as createBlockInstanceFromJSON,
|
|
1186
|
+
f as createBlockInstanceFromObject,
|
|
1187
|
+
g as createCeRenderer,
|
|
2059
1188
|
createContext,
|
|
2060
1189
|
createCustomerService,
|
|
2061
|
-
createMockCustomerAdapter,
|
|
2062
|
-
createMockOrderAdapter,
|
|
2063
1190
|
createMockProductAdapter,
|
|
2064
|
-
createMockSchedulesAdapter,
|
|
2065
1191
|
createMockSubscriptionAdapter,
|
|
2066
1192
|
createMockWorkflowApiAdapter,
|
|
2067
|
-
createOrderService,
|
|
2068
1193
|
createProductService,
|
|
2069
|
-
|
|
2070
|
-
k as createSelectedBlock,
|
|
1194
|
+
h as createSelectedBlock,
|
|
2071
1195
|
createState,
|
|
2072
1196
|
createSubscriptionService,
|
|
2073
|
-
|
|
1197
|
+
i as createThemeState,
|
|
2074
1198
|
c as createTranslationService,
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
1199
|
+
a2 as createWorkflowApiAdapter,
|
|
1200
|
+
b2 as createWorkflowService,
|
|
1201
|
+
j as defineBlock,
|
|
1202
|
+
k as defineBlockRuntime,
|
|
2079
1203
|
E as effect,
|
|
2080
1204
|
g2 as getDefaultBlockForAction,
|
|
2081
|
-
|
|
1205
|
+
l as getDefinedBlocks,
|
|
2082
1206
|
h2 as hasDefaultBlockForAction,
|
|
2083
1207
|
m as indexOverrides,
|
|
2084
|
-
|
|
1208
|
+
n as injectContext,
|
|
2085
1209
|
loginService,
|
|
2086
1210
|
o as onRegisterBlock,
|
|
2087
|
-
|
|
1211
|
+
p as provideContext,
|
|
2088
1212
|
r as registerBlock,
|
|
2089
1213
|
s as serializeBlocks,
|
|
2090
1214
|
d as signal,
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
1215
|
+
q as subscribeContext,
|
|
1216
|
+
t as untracked,
|
|
1217
|
+
v as withWrapper
|
|
2094
1218
|
};
|