@kiva/kv-shop 2.1.1 → 3.0.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/_virtual/_commonjs-dynamic-modules.js +6 -0
- package/dist/_virtual/_commonjsHelpers.js +8 -0
- package/dist/_virtual/_plugin-vue_export-helper.js +9 -0
- package/dist/_virtual/dropin.js +11 -0
- package/dist/_virtual/dropin2.js +4 -0
- package/dist/basket.js +35 -12
- package/dist/basketCredits.js +78 -14
- package/dist/basketItems.js +27 -8
- package/dist/basketTotals.js +38 -10
- package/dist/basketVerification.js +6 -6
- package/dist/checkoutStatus.js +52 -8
- package/dist/components/KvPaymentSelect.css +1 -0
- package/dist/components/KvPaymentSelect.js +23 -0
- package/dist/components/KvPaymentSelect2.js +110 -0
- package/dist/index.d.ts +321 -20
- package/dist/index.js +49 -96
- package/dist/managedAccount.js +62 -8
- package/dist/oneTimeCheckout.js +156 -12
- package/dist/receipt.js +143 -12
- package/dist/shopError.js +41 -6
- package/dist/shopQueries.js +82 -11
- package/dist/subscriptionCheckout.js +88 -7
- package/dist/useBraintreeDropIn.js +145 -9
- package/dist/util/cookie.js +11 -0
- package/dist/util/poll.js +17 -0
- package/dist/util/redirect.js +8 -0
- package/dist/util/visitorId.js +7 -0
- package/dist/validatePreCheckout.js +44 -11
- package/dist/vendor/braintree-web-drop-in/dist/browser/dropin.js +12223 -0
- package/package.json +28 -26
- package/dist/basket.cjs +0 -141
- package/dist/basket.d.ts +0 -8
- package/dist/basketCredits.cjs +0 -250
- package/dist/basketCredits.d.ts +0 -32
- package/dist/basketItems.cjs +0 -205
- package/dist/basketItems.d.ts +0 -26
- package/dist/basketTotals.cjs +0 -228
- package/dist/basketTotals.d.ts +0 -37
- package/dist/basketVerification.cjs +0 -41
- package/dist/basketVerification.d.ts +0 -10
- package/dist/checkoutStatus.cjs +0 -111
- package/dist/checkoutStatus.d.ts +0 -20
- package/dist/chunk-4ODZGLWK.js +0 -64
- package/dist/chunk-ASZJVUQ7.js +0 -72
- package/dist/chunk-FBF4WMN6.js +0 -49
- package/dist/chunk-FC4QW6QA.js +0 -106
- package/dist/chunk-FCAOCO7O.js +0 -17
- package/dist/chunk-GVVI7X2R.js +0 -196
- package/dist/chunk-IIN37LC7.js +0 -45
- package/dist/chunk-IOZ5ERDX.js +0 -121
- package/dist/chunk-KCUOMCSN.js +0 -58
- package/dist/chunk-LZ4UMRCV.js +0 -16
- package/dist/chunk-RQNRQ2E5.js +0 -155
- package/dist/chunk-SRGYGDAX.js +0 -80
- package/dist/chunk-TPJPGUO7.js +0 -12
- package/dist/chunk-UJXHTR43.js +0 -86
- package/dist/chunk-VZ3VDRRP.js +0 -167
- package/dist/chunk-Z7JRY3QE.js +0 -34
- package/dist/components/KvPaymentSelect.vue +0 -380
- package/dist/index.cjs +0 -1227
- package/dist/managedAccount.cjs +0 -231
- package/dist/managedAccount.d.ts +0 -59
- package/dist/oneTimeCheckout.cjs +0 -636
- package/dist/oneTimeCheckout.d.ts +0 -21
- package/dist/receipt.cjs +0 -191
- package/dist/receipt.d.ts +0 -16
- package/dist/shopError.cjs +0 -88
- package/dist/shopError.d.ts +0 -14
- package/dist/shopQueries.cjs +0 -248
- package/dist/shopQueries.d.ts +0 -8
- package/dist/subscriptionCheckout.cjs +0 -187
- package/dist/subscriptionCheckout.d.ts +0 -13
- package/dist/useBraintreeDropIn.cjs +0 -258
- package/dist/useBraintreeDropIn.d.ts +0 -25
- package/dist/validatePreCheckout.cjs +0 -218
- package/dist/validatePreCheckout.d.ts +0 -28
package/dist/oneTimeCheckout.js
CHANGED
|
@@ -1,14 +1,158 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import "./
|
|
5
|
-
import "./
|
|
6
|
-
import "./
|
|
7
|
-
import "./
|
|
8
|
-
import "./
|
|
9
|
-
import "./
|
|
10
|
-
import "./
|
|
11
|
-
import "./
|
|
1
|
+
import { gql as s } from "@apollo/client";
|
|
2
|
+
import { trackTransaction as C } from "@kiva/kv-analytics";
|
|
3
|
+
import M from "numeral";
|
|
4
|
+
import { pollForFinishedCheckout as P } from "./checkoutStatus.js";
|
|
5
|
+
import { ShopError as g, parseShopError as S } from "./shopError.js";
|
|
6
|
+
import { callShopQuery as D, callShopMutation as b } from "./shopQueries.js";
|
|
7
|
+
import { validatePreCheckout as N } from "./validatePreCheckout.js";
|
|
8
|
+
import { wait as q } from "./util/poll.js";
|
|
9
|
+
import { getVisitorID as v } from "./util/visitorId.js";
|
|
10
|
+
import { redirectTo as A } from "./util/redirect.js";
|
|
11
|
+
import { getCheckoutTrackingData as T } from "./receipt.js";
|
|
12
|
+
async function E(t) {
|
|
13
|
+
var r, e, i;
|
|
14
|
+
const o = await D(t, {
|
|
15
|
+
query: s`
|
|
16
|
+
query creditAmountNeeded($basketId: String) {
|
|
17
|
+
shop (basketId: $basketId) {
|
|
18
|
+
id
|
|
19
|
+
basket {
|
|
20
|
+
id
|
|
21
|
+
totals {
|
|
22
|
+
creditAmountNeeded
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
`,
|
|
28
|
+
fetchPolicy: "network-only"
|
|
29
|
+
}, 0);
|
|
30
|
+
return (i = (e = (r = o == null ? void 0 : o.shop) == null ? void 0 : r.basket) == null ? void 0 : e.totals) == null ? void 0 : i.creditAmountNeeded;
|
|
31
|
+
}
|
|
32
|
+
const R = s`
|
|
33
|
+
mutation creditCheckout(
|
|
34
|
+
$basketId: String,
|
|
35
|
+
$visitorId: String
|
|
36
|
+
) {
|
|
37
|
+
shop (basketId: $basketId) {
|
|
38
|
+
id
|
|
39
|
+
transactionId: checkoutAsync (visitorId: $visitorId)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`, _ = s`
|
|
43
|
+
mutation depositCheckout(
|
|
44
|
+
$basketId: String,
|
|
45
|
+
$amount: Money!,
|
|
46
|
+
$nonce: String!,
|
|
47
|
+
$savePaymentMethod: Boolean,
|
|
48
|
+
$deviceData: String,
|
|
49
|
+
$visitorId: String
|
|
50
|
+
) {
|
|
51
|
+
shop (basketId: $basketId) {
|
|
52
|
+
id
|
|
53
|
+
transactionId: doNoncePaymentDepositAndCheckoutAsync(
|
|
54
|
+
amount: $amount,
|
|
55
|
+
nonce: $nonce,
|
|
56
|
+
savePaymentMethod: $savePaymentMethod,
|
|
57
|
+
deviceData: $deviceData,
|
|
58
|
+
visitorId: $visitorId
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
function x(t) {
|
|
64
|
+
return b(t, {
|
|
65
|
+
mutation: R,
|
|
66
|
+
variables: {
|
|
67
|
+
visitorId: v()
|
|
68
|
+
}
|
|
69
|
+
}, 0);
|
|
70
|
+
}
|
|
71
|
+
async function B({
|
|
72
|
+
apollo: t,
|
|
73
|
+
braintree: o,
|
|
74
|
+
amount: r
|
|
75
|
+
}) {
|
|
76
|
+
try {
|
|
77
|
+
const e = await o.requestPaymentMethod();
|
|
78
|
+
if (!e)
|
|
79
|
+
throw new g(
|
|
80
|
+
{ code: "shop.dropinNoPaymentMethod" },
|
|
81
|
+
"No payment method returned from braintree dropin"
|
|
82
|
+
);
|
|
83
|
+
const { nonce: i, deviceData: d, type: n } = e;
|
|
84
|
+
return {
|
|
85
|
+
paymentType: n,
|
|
86
|
+
mutation: b(t, {
|
|
87
|
+
mutation: _,
|
|
88
|
+
variables: {
|
|
89
|
+
nonce: i,
|
|
90
|
+
amount: r,
|
|
91
|
+
savePaymentMethod: !1,
|
|
92
|
+
// save payment methods handled by braintree drop in UI
|
|
93
|
+
deviceData: d,
|
|
94
|
+
visitorId: v()
|
|
95
|
+
}
|
|
96
|
+
}, 0)
|
|
97
|
+
};
|
|
98
|
+
} catch (e) {
|
|
99
|
+
throw S(e);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function F(t, o, r) {
|
|
103
|
+
try {
|
|
104
|
+
const e = await T(
|
|
105
|
+
t,
|
|
106
|
+
o,
|
|
107
|
+
r
|
|
108
|
+
);
|
|
109
|
+
C(e), await q(800);
|
|
110
|
+
} catch (e) {
|
|
111
|
+
console.error("Error tracking transaction", e);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function W({
|
|
115
|
+
apollo: t,
|
|
116
|
+
braintree: o,
|
|
117
|
+
emailAddress: r,
|
|
118
|
+
emailOptIn: e,
|
|
119
|
+
valetInviter: i,
|
|
120
|
+
deactivateRedirect: d
|
|
121
|
+
}) {
|
|
122
|
+
var k, y, f, I, w;
|
|
123
|
+
await N({
|
|
124
|
+
apollo: t,
|
|
125
|
+
emailAddress: r,
|
|
126
|
+
emailOptIn: e,
|
|
127
|
+
valetInviter: i
|
|
128
|
+
});
|
|
129
|
+
const n = await E(t), u = M(n).value() > 0;
|
|
130
|
+
if (u && !o)
|
|
131
|
+
throw new g({ code: "shop.dropinRequired" }, "Braintree dropin required for credit deposit checkout");
|
|
132
|
+
let a, m = "";
|
|
133
|
+
if (u) {
|
|
134
|
+
const $ = await B({
|
|
135
|
+
apollo: t,
|
|
136
|
+
braintree: o,
|
|
137
|
+
amount: n
|
|
138
|
+
});
|
|
139
|
+
m = $.paymentType, a = await $.mutation;
|
|
140
|
+
} else
|
|
141
|
+
a = await x(t);
|
|
142
|
+
const l = (k = a == null ? void 0 : a.shop) == null ? void 0 : k.transactionId, c = await P({
|
|
143
|
+
apollo: t,
|
|
144
|
+
transactionSagaId: l,
|
|
145
|
+
timeout: 3e5
|
|
146
|
+
// five minutes
|
|
147
|
+
});
|
|
148
|
+
if ((y = c.errors) != null && y.length)
|
|
149
|
+
throw S(c.errors[0]);
|
|
150
|
+
const h = (w = (I = (f = c.data) == null ? void 0 : f.checkoutStatus) == null ? void 0 : I.receipt) == null ? void 0 : w.checkoutId;
|
|
151
|
+
if (await F(t, h, m), d)
|
|
152
|
+
return c;
|
|
153
|
+
let p = `/checkout/post-purchase?kiva_transaction_id=${h}`;
|
|
154
|
+
i != null && i.inviterId && (p += `&valet_inviter=${i.inviterId}`), await A(p);
|
|
155
|
+
}
|
|
12
156
|
export {
|
|
13
|
-
executeOneTimeCheckout
|
|
157
|
+
W as executeOneTimeCheckout
|
|
14
158
|
};
|
package/dist/receipt.js
CHANGED
|
@@ -1,14 +1,145 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { gql as T } from "@apollo/client";
|
|
2
|
+
import { getVisitorID as k } from "./util/visitorId.js";
|
|
3
|
+
async function g(o) {
|
|
4
|
+
var n, i, s;
|
|
5
|
+
return ((s = (i = (n = (await o.query({
|
|
6
|
+
query: T`
|
|
7
|
+
query ftdStatus {
|
|
8
|
+
my {
|
|
9
|
+
id
|
|
10
|
+
userAccount {
|
|
11
|
+
id
|
|
12
|
+
isFirstTimeDepositor
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`
|
|
17
|
+
})).data) == null ? void 0 : n.my) == null ? void 0 : i.userAccount) == null ? void 0 : s.isFirstTimeDepositor) ?? !1;
|
|
18
|
+
}
|
|
19
|
+
async function q(o, r) {
|
|
20
|
+
return new Promise((n, i) => {
|
|
21
|
+
let e = 0;
|
|
22
|
+
const a = o.watchQuery({
|
|
23
|
+
query: T`
|
|
24
|
+
query receiptItems($checkoutId: Int, $visitorId: String, $limit: Int, $offset: Int) {
|
|
25
|
+
shop {
|
|
26
|
+
id
|
|
27
|
+
receipt(checkoutId: $checkoutId, visitorId: $visitorId) {
|
|
28
|
+
id
|
|
29
|
+
items(limit: $limit, offset: $offset) {
|
|
30
|
+
totalCount
|
|
31
|
+
values {
|
|
32
|
+
id
|
|
33
|
+
price
|
|
34
|
+
__typename
|
|
35
|
+
|
|
36
|
+
... on Donation {
|
|
37
|
+
id
|
|
38
|
+
isTip
|
|
39
|
+
isUserEdited
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
`,
|
|
47
|
+
variables: {
|
|
48
|
+
checkoutId: r,
|
|
49
|
+
visitorId: k(),
|
|
50
|
+
limit: 100,
|
|
51
|
+
offset: e
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
let d = [];
|
|
55
|
+
const c = async (l) => {
|
|
56
|
+
var t, p, m, v, I, y, f, h;
|
|
57
|
+
const u = (v = (m = (p = (t = l.data) == null ? void 0 : t.shop) == null ? void 0 : p.receipt) == null ? void 0 : m.items) == null ? void 0 : v.totalCount;
|
|
58
|
+
if (d = d.concat((h = (f = (y = (I = l.data) == null ? void 0 : I.shop) == null ? void 0 : y.receipt) == null ? void 0 : f.items) == null ? void 0 : h.values), u > e + 100) {
|
|
59
|
+
e += 100;
|
|
60
|
+
const C = await a.fetchMore({
|
|
61
|
+
variables: {
|
|
62
|
+
offset: e
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
try {
|
|
66
|
+
c(C);
|
|
67
|
+
} catch ($) {
|
|
68
|
+
i($);
|
|
69
|
+
}
|
|
70
|
+
} else
|
|
71
|
+
n(d);
|
|
72
|
+
};
|
|
73
|
+
a.subscribe({
|
|
74
|
+
next: c,
|
|
75
|
+
error: (l) => {
|
|
76
|
+
i(l);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async function D(o, r) {
|
|
82
|
+
var i, s, e;
|
|
83
|
+
return (e = (s = (i = (await o.query({
|
|
84
|
+
query: T`
|
|
85
|
+
query receiptTotals($checkoutId: Int, $visitorId: String) {
|
|
86
|
+
shop {
|
|
87
|
+
id
|
|
88
|
+
receipt(checkoutId: $checkoutId, visitorId: $visitorId) {
|
|
89
|
+
id
|
|
90
|
+
totals {
|
|
91
|
+
loanReservationTotal
|
|
92
|
+
donationTotal
|
|
93
|
+
kivaCardTotal
|
|
94
|
+
itemTotal
|
|
95
|
+
kivaCreditAppliedTotal
|
|
96
|
+
depositTotals {
|
|
97
|
+
depositTotal
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
`,
|
|
104
|
+
variables: {
|
|
105
|
+
checkoutId: r,
|
|
106
|
+
visitorId: k()
|
|
107
|
+
}
|
|
108
|
+
})).data) == null ? void 0 : i.shop) == null ? void 0 : s.receipt) == null ? void 0 : e.totals;
|
|
109
|
+
}
|
|
110
|
+
async function b(o, r, n) {
|
|
111
|
+
var u;
|
|
112
|
+
const i = parseInt(r, 10), [s, e, a] = await Promise.all([
|
|
113
|
+
g(o),
|
|
114
|
+
q(o, i),
|
|
115
|
+
D(o, i)
|
|
116
|
+
]), d = e.filter((t) => t.__typename === "LoanReservation"), c = e.filter((t) => t.__typename === "Donation"), l = e.filter((t) => t.__typename === "KivaCard");
|
|
117
|
+
return {
|
|
118
|
+
transactionId: r,
|
|
119
|
+
itemTotal: a.itemTotal,
|
|
120
|
+
// Loan reservations
|
|
121
|
+
loans: d,
|
|
122
|
+
loanCount: d.length,
|
|
123
|
+
loanTotal: a.loanReservationTotal,
|
|
124
|
+
// Donations
|
|
125
|
+
donations: c.map(({ id: t, price: p, __typename: m }) => ({ id: t, price: p, __typename: m })),
|
|
126
|
+
donationTotal: a.donationTotal,
|
|
127
|
+
isTip: c.every((t) => t.isTip),
|
|
128
|
+
isUserEdited: c.some((t) => t.isUserEdited),
|
|
129
|
+
// Kiva Cards
|
|
130
|
+
kivaCards: l,
|
|
131
|
+
kivaCardCount: l.length,
|
|
132
|
+
kivaCardTotal: a.kivaCardTotal,
|
|
133
|
+
// Credit & deposit
|
|
134
|
+
kivaCreditAppliedTotal: a.kivaCreditAppliedTotal,
|
|
135
|
+
depositTotal: ((u = a.depositTotals) == null ? void 0 : u.depositTotal) ?? "0.00",
|
|
136
|
+
paymentType: n,
|
|
137
|
+
isFTD: s
|
|
138
|
+
};
|
|
139
|
+
}
|
|
9
140
|
export {
|
|
10
|
-
getCheckoutTrackingData,
|
|
11
|
-
getFTDStatus,
|
|
12
|
-
getReceiptItems,
|
|
13
|
-
getReceiptTotals
|
|
141
|
+
b as getCheckoutTrackingData,
|
|
142
|
+
g as getFTDStatus,
|
|
143
|
+
q as getReceiptItems,
|
|
144
|
+
D as getReceiptTotals
|
|
14
145
|
};
|
package/dist/shopError.js
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
class t extends Error {
|
|
2
|
+
constructor({ code: n, original: a }, ...i) {
|
|
3
|
+
super(...i), Error.captureStackTrace && Error.captureStackTrace(this, t), this.name = "ShopError", this.code = n, this.original = a;
|
|
4
|
+
}
|
|
5
|
+
aggregateErrors(n) {
|
|
6
|
+
this.errors = n;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function l(e) {
|
|
10
|
+
var i;
|
|
11
|
+
if (e instanceof t)
|
|
12
|
+
return e;
|
|
13
|
+
const n = (e == null ? void 0 : e.code) ?? ((i = e == null ? void 0 : e.extensions) == null ? void 0 : i.code) ?? (e == null ? void 0 : e.name) ?? "", a = typeof e == "string" ? e : (e == null ? void 0 : e.message) ?? "";
|
|
14
|
+
if (n === "invalidMethodParameter" && a.includes("paymentMethod.create"))
|
|
15
|
+
return new t({
|
|
16
|
+
code: "paymentMethod.create.invalidMethodParameter",
|
|
17
|
+
original: e
|
|
18
|
+
}, "There was a problem validating your payment information. Please double-check the details and try again.");
|
|
19
|
+
if (a.includes("Invalid request: ")) {
|
|
20
|
+
const s = a.split("Invalid request: ")[1].split("., ").map((d) => d.matchAll(/[A-Z_]+: (.*)/g))[0], o = s[1], c = s[2];
|
|
21
|
+
return new t({
|
|
22
|
+
code: `paymentMethod.${o}`,
|
|
23
|
+
original: e
|
|
24
|
+
}, c);
|
|
25
|
+
}
|
|
26
|
+
return n === "insufficientFunds" || a.includes("There is not enough credit") ? new t({
|
|
27
|
+
code: "shop.insufficientFunds",
|
|
28
|
+
original: e
|
|
29
|
+
}, "There is not enough money to complete the checkout. Please double-check the details and try again.") : n === "shop.invalidBasketId" || n === "shop.basketRequired" || n === "shop.alreadyCheckedOut" ? new t({
|
|
30
|
+
code: n,
|
|
31
|
+
original: e
|
|
32
|
+
}, "There was a problem with your basket. Please, refresh the page and try again.") : n === "donationAmountTooLarge" ? new t({
|
|
33
|
+
code: n,
|
|
34
|
+
original: e
|
|
35
|
+
}, a) : new t({
|
|
36
|
+
code: "shop.unknown",
|
|
37
|
+
original: e
|
|
38
|
+
}, "An unknown error occurred.");
|
|
39
|
+
}
|
|
5
40
|
export {
|
|
6
|
-
ShopError,
|
|
7
|
-
parseShopError
|
|
41
|
+
t as ShopError,
|
|
42
|
+
l as parseShopError
|
|
8
43
|
};
|
package/dist/shopQueries.js
CHANGED
|
@@ -1,13 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { getBasketID as b, hasBasketExpired as k, createBasket as E } from "./basket.js";
|
|
2
|
+
import { parseShopError as f } from "./shopError.js";
|
|
3
|
+
const v = /* @__PURE__ */ new Set();
|
|
4
|
+
async function S(i, e, c = 2) {
|
|
5
|
+
var o, t;
|
|
6
|
+
try {
|
|
7
|
+
const r = await i.mutate({
|
|
8
|
+
...e,
|
|
9
|
+
variables: {
|
|
10
|
+
...e.variables,
|
|
11
|
+
basketId: b()
|
|
12
|
+
},
|
|
13
|
+
refetchQueries: e.awaitRefetchQueries ? Array.from(v) : []
|
|
14
|
+
});
|
|
15
|
+
if ((o = r == null ? void 0 : r.errors) != null && o.length) {
|
|
16
|
+
const a = r == null ? void 0 : r.errors.filter((h) => k(h));
|
|
17
|
+
if (a.length) {
|
|
18
|
+
if (c > 0)
|
|
19
|
+
return await E(i), S(i, e, c - 1);
|
|
20
|
+
throw a[0];
|
|
21
|
+
}
|
|
22
|
+
if ((t = r == null ? void 0 : r.errors) != null && t.length)
|
|
23
|
+
throw r.errors[0];
|
|
24
|
+
}
|
|
25
|
+
return r == null ? void 0 : r.data;
|
|
26
|
+
} catch (r) {
|
|
27
|
+
throw f(r);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function F(i, e, c = 2) {
|
|
31
|
+
var o, t;
|
|
32
|
+
try {
|
|
33
|
+
const r = await i.query({
|
|
34
|
+
...e,
|
|
35
|
+
variables: {
|
|
36
|
+
...e.variables,
|
|
37
|
+
basketId: b()
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if ((o = r == null ? void 0 : r.errors) != null && o.length) {
|
|
41
|
+
const a = r == null ? void 0 : r.errors.filter((h) => k(h));
|
|
42
|
+
if (a.length) {
|
|
43
|
+
if (c > 0)
|
|
44
|
+
return await E(i), F(i, e, c - 1);
|
|
45
|
+
throw a[0];
|
|
46
|
+
}
|
|
47
|
+
if ((t = r == null ? void 0 : r.errors) != null && t.length)
|
|
48
|
+
throw r.errors[0];
|
|
49
|
+
}
|
|
50
|
+
return r == null ? void 0 : r.data;
|
|
51
|
+
} catch (r) {
|
|
52
|
+
throw f(r);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function L(i, e, c = 2) {
|
|
56
|
+
let o = 0;
|
|
57
|
+
v.add(e.query);
|
|
58
|
+
const t = i.watchQuery({
|
|
59
|
+
...e,
|
|
60
|
+
variables: {
|
|
61
|
+
...e.variables,
|
|
62
|
+
basketId: b()
|
|
63
|
+
}
|
|
64
|
+
}), r = t.subscribe.bind(t);
|
|
65
|
+
return t.subscribe = (...a) => {
|
|
66
|
+
var d, y, l;
|
|
67
|
+
let h, s, w;
|
|
68
|
+
return typeof a[0] == "function" ? [h, s, w] = a : (h = (d = a[0]) == null ? void 0 : d.next, s = (y = a[0]) == null ? void 0 : y.error, w = (l = a[0]) == null ? void 0 : l.complete), r(h, (n) => {
|
|
69
|
+
var Q, g;
|
|
70
|
+
const u = (Q = n == null ? void 0 : n.graphQLErrors) == null ? void 0 : Q.filter((m) => k(m));
|
|
71
|
+
u.length ? o < c ? E(i).then(() => {
|
|
72
|
+
o += 1, t.refetch({
|
|
73
|
+
...t.variables,
|
|
74
|
+
basketId: b()
|
|
75
|
+
});
|
|
76
|
+
}) : s(f(u[0])) : ((g = n == null ? void 0 : n.graphQLErrors) != null && g.length && s(f(n.graphQLErrors[0])), n != null && n.networkError && s(f(n.networkError)));
|
|
77
|
+
}, w);
|
|
78
|
+
}, t;
|
|
79
|
+
}
|
|
9
80
|
export {
|
|
10
|
-
callShopMutation,
|
|
11
|
-
callShopQuery,
|
|
12
|
-
watchShopQuery
|
|
81
|
+
S as callShopMutation,
|
|
82
|
+
F as callShopQuery,
|
|
83
|
+
L as watchShopQuery
|
|
13
84
|
};
|
|
@@ -1,9 +1,90 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { gql as g } from "@apollo/client";
|
|
2
|
+
import { ShopError as r, parseShopError as w } from "./shopError.js";
|
|
3
|
+
async function f(a) {
|
|
4
|
+
var c, n, s, i, u, d, e;
|
|
5
|
+
const { data: o } = await a.query({
|
|
6
|
+
query: g`query subscriptionStatus{
|
|
7
|
+
my {
|
|
8
|
+
id
|
|
9
|
+
subscriptions {
|
|
10
|
+
totalCount
|
|
11
|
+
}
|
|
12
|
+
autoDeposit {
|
|
13
|
+
id
|
|
14
|
+
isSubscriber
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}`
|
|
18
|
+
});
|
|
19
|
+
if (!((c = o == null ? void 0 : o.my) != null && c.id))
|
|
20
|
+
throw new r({ code: "api.authenticationRequired" }, "You must be logged in to continue.");
|
|
21
|
+
if ((((s = (n = o == null ? void 0 : o.my) == null ? void 0 : n.subscriptions) == null ? void 0 : s.totalCount) ?? 0) > 0 || (u = (i = o == null ? void 0 : o.my) == null ? void 0 : i.autoDeposit) != null && u.isSubscriber)
|
|
22
|
+
throw new r({ code: "shop.subscriptionExists" }, "You already have an existing Monthly Good subscription. Changes can be made in your subscription settings.");
|
|
23
|
+
if ((e = (d = o == null ? void 0 : o.my) == null ? void 0 : d.autoDeposit) != null && e.id)
|
|
24
|
+
throw new r({ code: "shop.autoDepositExists" }, "You already have existing Auto Deposit settings. Changes can be made in your subscription settings.");
|
|
25
|
+
return !0;
|
|
26
|
+
}
|
|
27
|
+
async function $({
|
|
28
|
+
amount: a,
|
|
29
|
+
apollo: o,
|
|
30
|
+
dayOfMonth: c = (/* @__PURE__ */ new Date()).getDate(),
|
|
31
|
+
donateAmount: n,
|
|
32
|
+
paymentMethod: s
|
|
33
|
+
}) {
|
|
34
|
+
var h, m, y;
|
|
35
|
+
const i = new RegExp(/^\d+\.\d{2}$/);
|
|
36
|
+
if (!i.test(a) || !i.test(n))
|
|
37
|
+
throw new r({
|
|
38
|
+
code: "api.invalidMethodParameter"
|
|
39
|
+
}, "Please check that the amount is correct and try again.");
|
|
40
|
+
await f(o);
|
|
41
|
+
const { deviceData: u, nonce: d } = s;
|
|
42
|
+
let e, p;
|
|
43
|
+
try {
|
|
44
|
+
const t = await o.mutate({
|
|
45
|
+
variables: {
|
|
46
|
+
nonce: d,
|
|
47
|
+
deviceData: u,
|
|
48
|
+
amount: a,
|
|
49
|
+
donateAmount: n,
|
|
50
|
+
dayOfMonth: c
|
|
51
|
+
},
|
|
52
|
+
mutation: g`mutation createAutoDepositSubscription(
|
|
53
|
+
$nonce: String!,
|
|
54
|
+
$deviceData: String,
|
|
55
|
+
$amount: Money!,
|
|
56
|
+
$donateAmount: Money!,
|
|
57
|
+
$dayOfMonth: Int!
|
|
58
|
+
) {
|
|
59
|
+
my {
|
|
60
|
+
createAutoDeposit (
|
|
61
|
+
autoDeposit: {
|
|
62
|
+
amount: $amount,
|
|
63
|
+
donateAmount: $donateAmount,
|
|
64
|
+
dayOfMonth: $dayOfMonth,
|
|
65
|
+
},
|
|
66
|
+
deviceData: $deviceData,
|
|
67
|
+
paymentMethodNonce: $nonce
|
|
68
|
+
) {
|
|
69
|
+
id amount donateAmount dayOfMonth status
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}`
|
|
73
|
+
});
|
|
74
|
+
t != null && t.error || (h = t == null ? void 0 : t.errors) != null && h.length ? p = (t == null ? void 0 : t.error) ?? ((m = t == null ? void 0 : t.errors) == null ? void 0 : m[0]) : e = t == null ? void 0 : t.data;
|
|
75
|
+
} catch (t) {
|
|
76
|
+
p = t;
|
|
77
|
+
}
|
|
78
|
+
if (p) {
|
|
79
|
+
const t = w(p);
|
|
80
|
+
throw (t == null ? void 0 : t.code) === "shop.unknown" ? new r({
|
|
81
|
+
code: "shop.createAutoDepositError",
|
|
82
|
+
original: t
|
|
83
|
+
}, "There was a problem trying to setup your monthly deposit.") : t;
|
|
84
|
+
}
|
|
85
|
+
return (y = e == null ? void 0 : e.my) == null ? void 0 : y.createAutoDeposit;
|
|
86
|
+
}
|
|
6
87
|
export {
|
|
7
|
-
checkSubscriptionStatus,
|
|
8
|
-
executeNewSubscriptionCheckout
|
|
88
|
+
f as checkSubscriptionStatus,
|
|
89
|
+
$ as executeNewSubscriptionCheckout
|
|
9
90
|
};
|