@kiva/kv-shop 3.2.9 → 3.3.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/basketItems.js +12 -7
- package/dist/index.d.ts +12 -1
- package/dist/oneTimeCheckout.js +90 -76
- package/package.json +2 -2
package/dist/basketItems.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { gql as r } from "@apollo/client/core";
|
|
2
2
|
import p from "numeral";
|
|
3
3
|
import { callShopMutation as m } from "./shopQueries.js";
|
|
4
|
-
async function
|
|
5
|
-
var
|
|
6
|
-
const n = p(
|
|
4
|
+
async function u({ amount: i, apollo: e, metadata: o }) {
|
|
5
|
+
var a;
|
|
6
|
+
const n = p(i).format("0.00"), t = await m(e, {
|
|
7
7
|
awaitRefetchQueries: !0,
|
|
8
8
|
mutation: r`mutation setTipDonation($price: Money!, $basketId: String, $metadata: String) {
|
|
9
9
|
shop (basketId: $basketId) {
|
|
@@ -14,16 +14,21 @@ async function d({ amount: a, apollo: o, metadata: e }) {
|
|
|
14
14
|
metadata: $metadata,
|
|
15
15
|
})
|
|
16
16
|
{
|
|
17
|
+
basketItemType
|
|
17
18
|
id
|
|
18
|
-
price
|
|
19
19
|
isTip
|
|
20
|
+
isUserEdited
|
|
21
|
+
metadata {
|
|
22
|
+
campaignId
|
|
23
|
+
}
|
|
24
|
+
price
|
|
20
25
|
}
|
|
21
26
|
}
|
|
22
27
|
}`,
|
|
23
|
-
variables: { price: n, metadata:
|
|
28
|
+
variables: { price: n, metadata: o }
|
|
24
29
|
});
|
|
25
|
-
return (
|
|
30
|
+
return (a = t == null ? void 0 : t.shop) == null ? void 0 : a.updateDonation;
|
|
26
31
|
}
|
|
27
32
|
export {
|
|
28
|
-
|
|
33
|
+
u as setTipDonation
|
|
29
34
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -114,7 +114,7 @@ export declare function executeNewSubscriptionCheckout({ amount, apollo, dayOfMo
|
|
|
114
114
|
|
|
115
115
|
export declare function executeOneTimeCheckout({ apollo, braintree, emailAddress, emailOptIn, valetInviter, deactivateRedirect, }: OneTimeCheckoutOptions): Promise<CheckoutStatusQueryResult>;
|
|
116
116
|
|
|
117
|
-
export declare function executeOneTimeCheckoutForGivingFund({ amount, apollo, braintree, emailAddress, emailOptIn, fundTarget, userId, useKivaCredit, }: OneTimeCheckoutForGivingFundOptions): Promise<
|
|
117
|
+
export declare function executeOneTimeCheckoutForGivingFund({ amount, apollo, braintree, emailAddress, emailOptIn, fundTarget, userId, useKivaCredit, }: OneTimeCheckoutForGivingFundOptions): Promise<OneTimeCheckoutForGivingFundResult>;
|
|
118
118
|
|
|
119
119
|
export declare function getBasketID(): string;
|
|
120
120
|
|
|
@@ -154,6 +154,17 @@ export declare interface OneTimeCheckoutForGivingFundOptions {
|
|
|
154
154
|
useKivaCredit?: boolean;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
export declare interface OneTimeCheckoutForGivingFundResult {
|
|
158
|
+
data: {
|
|
159
|
+
checkoutStatus: any;
|
|
160
|
+
donation: any;
|
|
161
|
+
givingFund: {
|
|
162
|
+
id: string;
|
|
163
|
+
};
|
|
164
|
+
} | null;
|
|
165
|
+
errors?: any;
|
|
166
|
+
}
|
|
167
|
+
|
|
157
168
|
export declare interface OneTimeCheckoutOptions {
|
|
158
169
|
apollo: ApolloClient<any>;
|
|
159
170
|
braintree?: DropInWrapper;
|
package/dist/oneTimeCheckout.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { gql as $ } from "@apollo/client/core";
|
|
2
|
-
import { trackTransaction as
|
|
3
|
-
import
|
|
4
|
-
import { pollForFinishedCheckout as
|
|
2
|
+
import { trackTransaction as E } from "@kiva/kv-analytics";
|
|
3
|
+
import R from "numeral";
|
|
4
|
+
import { pollForFinishedCheckout as D } from "./checkoutStatus.js";
|
|
5
5
|
import { ShopError as v, parseShopError as S } from "./shopError.js";
|
|
6
|
-
import { callShopQuery as
|
|
7
|
-
import { validatePreCheckout as
|
|
8
|
-
import { wait as
|
|
9
|
-
import { getVisitorID as
|
|
10
|
-
import { redirectTo as
|
|
11
|
-
import { getCheckoutTrackingData as
|
|
12
|
-
import { addGivingFund as
|
|
13
|
-
import { setTipDonation as
|
|
14
|
-
import { removeKivaCredit as
|
|
15
|
-
async function
|
|
6
|
+
import { callShopQuery as _, callShopMutation as N } from "./shopQueries.js";
|
|
7
|
+
import { validatePreCheckout as P } from "./validatePreCheckout.js";
|
|
8
|
+
import { wait as G } from "./util/poll.js";
|
|
9
|
+
import { getVisitorID as l } from "./util/visitorId.js";
|
|
10
|
+
import { redirectTo as O } from "./util/redirect.js";
|
|
11
|
+
import { getCheckoutTrackingData as K } from "./receipt.js";
|
|
12
|
+
import { addGivingFund as Q } from "./givingFunds.js";
|
|
13
|
+
import { setTipDonation as U } from "./basketItems.js";
|
|
14
|
+
import { removeKivaCredit as V } from "./basketCredits.js";
|
|
15
|
+
async function A(e) {
|
|
16
16
|
var r, o, i;
|
|
17
|
-
const t = await
|
|
17
|
+
const t = await _(e, {
|
|
18
18
|
query: $`
|
|
19
19
|
query creditAmountNeeded($basketId: String) {
|
|
20
20
|
shop (basketId: $basketId) {
|
|
@@ -32,7 +32,7 @@ async function R(e) {
|
|
|
32
32
|
}, 0);
|
|
33
33
|
return (i = (o = (r = t == null ? void 0 : t.shop) == null ? void 0 : r.basket) == null ? void 0 : o.totals) == null ? void 0 : i.creditAmountNeeded;
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const j = $`
|
|
36
36
|
mutation creditCheckout(
|
|
37
37
|
$basketId: String,
|
|
38
38
|
$visitorId: String
|
|
@@ -42,7 +42,7 @@ const U = $`
|
|
|
42
42
|
transactionId: checkoutAsync (visitorId: $visitorId)
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
`,
|
|
45
|
+
`, z = $`
|
|
46
46
|
mutation depositCheckout(
|
|
47
47
|
$basketId: String,
|
|
48
48
|
$amount: Money!,
|
|
@@ -63,15 +63,15 @@ const U = $`
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
`;
|
|
66
|
-
function
|
|
67
|
-
return
|
|
68
|
-
mutation:
|
|
66
|
+
function F(e) {
|
|
67
|
+
return N(e, {
|
|
68
|
+
mutation: j,
|
|
69
69
|
variables: {
|
|
70
|
-
visitorId:
|
|
70
|
+
visitorId: l()
|
|
71
71
|
}
|
|
72
72
|
}, 0);
|
|
73
73
|
}
|
|
74
|
-
async function
|
|
74
|
+
async function x({
|
|
75
75
|
apollo: e,
|
|
76
76
|
braintree: t,
|
|
77
77
|
amount: r
|
|
@@ -83,18 +83,18 @@ async function F({
|
|
|
83
83
|
{ code: "shop.dropinNoPaymentMethod" },
|
|
84
84
|
"No payment method returned from braintree dropin"
|
|
85
85
|
);
|
|
86
|
-
const { nonce: i, deviceData: u, type:
|
|
86
|
+
const { nonce: i, deviceData: u, type: d } = o;
|
|
87
87
|
return {
|
|
88
|
-
paymentType:
|
|
89
|
-
mutation:
|
|
90
|
-
mutation:
|
|
88
|
+
paymentType: d,
|
|
89
|
+
mutation: N(e, {
|
|
90
|
+
mutation: z,
|
|
91
91
|
variables: {
|
|
92
92
|
nonce: i,
|
|
93
93
|
amount: r,
|
|
94
94
|
savePaymentMethod: !1,
|
|
95
95
|
// save payment methods handled by braintree drop in UI
|
|
96
96
|
deviceData: u,
|
|
97
|
-
visitorId:
|
|
97
|
+
visitorId: l()
|
|
98
98
|
}
|
|
99
99
|
}, 0)
|
|
100
100
|
};
|
|
@@ -102,19 +102,19 @@ async function F({
|
|
|
102
102
|
throw S(o);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
async function
|
|
105
|
+
async function B(e, t, r) {
|
|
106
106
|
try {
|
|
107
|
-
const o = await
|
|
107
|
+
const o = await K(
|
|
108
108
|
e,
|
|
109
109
|
t,
|
|
110
110
|
r
|
|
111
111
|
);
|
|
112
|
-
|
|
112
|
+
E(o), await G(800);
|
|
113
113
|
} catch (o) {
|
|
114
114
|
console.error("Error tracking transaction", o);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
async function
|
|
117
|
+
async function ct({
|
|
118
118
|
apollo: e,
|
|
119
119
|
braintree: t,
|
|
120
120
|
emailAddress: r,
|
|
@@ -122,91 +122,105 @@ async function nt({
|
|
|
122
122
|
valetInviter: i,
|
|
123
123
|
deactivateRedirect: u
|
|
124
124
|
}) {
|
|
125
|
-
var
|
|
126
|
-
await
|
|
125
|
+
var h, y, a, w, g;
|
|
126
|
+
await P({
|
|
127
127
|
apollo: e,
|
|
128
128
|
emailAddress: r,
|
|
129
129
|
emailOptIn: o,
|
|
130
130
|
valetInviter: i
|
|
131
131
|
});
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
132
|
+
const d = await A(e), k = R(d).value() > 0;
|
|
133
|
+
if (k && !t)
|
|
134
134
|
throw new v({ code: "shop.dropinRequired" }, "Braintree dropin required for credit deposit checkout");
|
|
135
|
-
let
|
|
136
|
-
if (
|
|
137
|
-
const
|
|
135
|
+
let n, f = "";
|
|
136
|
+
if (k) {
|
|
137
|
+
const p = await x({
|
|
138
138
|
apollo: e,
|
|
139
139
|
braintree: t,
|
|
140
|
-
amount:
|
|
140
|
+
amount: d
|
|
141
141
|
});
|
|
142
|
-
|
|
142
|
+
f = p.paymentType, n = await p.mutation;
|
|
143
143
|
} else
|
|
144
|
-
|
|
145
|
-
const
|
|
144
|
+
n = await F(e);
|
|
145
|
+
const I = (h = n == null ? void 0 : n.shop) == null ? void 0 : h.transactionId, s = await D({
|
|
146
146
|
apollo: e,
|
|
147
|
-
transactionSagaId:
|
|
147
|
+
transactionSagaId: I,
|
|
148
148
|
timeout: 3e5
|
|
149
149
|
// five minutes
|
|
150
150
|
});
|
|
151
|
-
if ((
|
|
152
|
-
throw S(
|
|
153
|
-
const
|
|
154
|
-
if (await
|
|
155
|
-
return
|
|
156
|
-
let
|
|
157
|
-
i != null && i.inviterId && (
|
|
151
|
+
if ((y = s.errors) != null && y.length)
|
|
152
|
+
throw S(s.errors[0]);
|
|
153
|
+
const m = (g = (w = (a = s.data) == null ? void 0 : a.checkoutStatus) == null ? void 0 : w.receipt) == null ? void 0 : g.checkoutId;
|
|
154
|
+
if (await B(e, m, f), u)
|
|
155
|
+
return s;
|
|
156
|
+
let c = `/checkout/post-purchase?kiva_transaction_id=${m}`;
|
|
157
|
+
i != null && i.inviterId && (c += `&valet_inviter=${i.inviterId}`), await O(c);
|
|
158
158
|
}
|
|
159
|
-
async function
|
|
159
|
+
async function dt({
|
|
160
160
|
amount: e,
|
|
161
161
|
apollo: t,
|
|
162
162
|
braintree: r,
|
|
163
163
|
emailAddress: o,
|
|
164
164
|
emailOptIn: i,
|
|
165
165
|
fundTarget: u,
|
|
166
|
-
userId:
|
|
167
|
-
useKivaCredit:
|
|
166
|
+
userId: d,
|
|
167
|
+
useKivaCredit: k = !0
|
|
168
168
|
}) {
|
|
169
|
-
var
|
|
170
|
-
await
|
|
169
|
+
var p, b, C, M, T;
|
|
170
|
+
await P({
|
|
171
171
|
apollo: t,
|
|
172
172
|
emailAddress: o,
|
|
173
173
|
emailOptIn: i
|
|
174
174
|
});
|
|
175
|
-
const
|
|
175
|
+
const n = await Q({
|
|
176
176
|
apollo: t,
|
|
177
177
|
fundTarget: u,
|
|
178
|
-
userId:
|
|
179
|
-
})
|
|
180
|
-
await K({
|
|
178
|
+
userId: d ? `${d}` : void 0
|
|
179
|
+
}), f = `campaignId: ${n.id}`, I = await U({
|
|
181
180
|
amount: e,
|
|
182
|
-
metadata:
|
|
181
|
+
metadata: f,
|
|
183
182
|
apollo: t
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
});
|
|
184
|
+
k || await V(t);
|
|
185
|
+
const s = await A(t), m = R(s).value() > 0;
|
|
186
|
+
if (m && !r)
|
|
187
187
|
throw new v({ code: "shop.dropinRequired" }, "Braintree dropin required for credit deposit checkout");
|
|
188
|
-
let
|
|
189
|
-
if (
|
|
190
|
-
const
|
|
188
|
+
let c, h = "";
|
|
189
|
+
if (m) {
|
|
190
|
+
const q = await x({
|
|
191
191
|
apollo: t,
|
|
192
192
|
braintree: r,
|
|
193
|
-
amount:
|
|
193
|
+
amount: s
|
|
194
194
|
});
|
|
195
|
-
|
|
195
|
+
h = q.paymentType, c = await q.mutation;
|
|
196
196
|
} else
|
|
197
|
-
|
|
198
|
-
const
|
|
197
|
+
c = await F(t);
|
|
198
|
+
const y = (p = c == null ? void 0 : c.shop) == null ? void 0 : p.transactionId, a = await D({
|
|
199
199
|
apollo: t,
|
|
200
|
-
transactionSagaId:
|
|
200
|
+
transactionSagaId: y,
|
|
201
201
|
timeout: 3e5
|
|
202
202
|
// five minutes
|
|
203
203
|
});
|
|
204
|
-
if ((
|
|
205
|
-
throw S(
|
|
206
|
-
const
|
|
207
|
-
return await
|
|
204
|
+
if ((b = a.errors) != null && b.length)
|
|
205
|
+
throw S(a.errors[0]);
|
|
206
|
+
const w = (T = (M = (C = a.data) == null ? void 0 : C.checkoutStatus) == null ? void 0 : M.receipt) == null ? void 0 : T.checkoutId;
|
|
207
|
+
return await B(t, w, h), {
|
|
208
|
+
data: {
|
|
209
|
+
...a.data,
|
|
210
|
+
checkoutStatus: {
|
|
211
|
+
...a.data.checkoutStatus
|
|
212
|
+
},
|
|
213
|
+
donation: {
|
|
214
|
+
...I
|
|
215
|
+
},
|
|
216
|
+
givingFund: {
|
|
217
|
+
id: n.id
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
errors: a.errors ?? []
|
|
221
|
+
};
|
|
208
222
|
}
|
|
209
223
|
export {
|
|
210
|
-
|
|
211
|
-
|
|
224
|
+
ct as executeOneTimeCheckout,
|
|
225
|
+
dt as executeOneTimeCheckoutForGivingFund
|
|
212
226
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiva/kv-shop",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"numeral": "2.x",
|
|
56
56
|
"vue": "3.x"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "66f2edef6330f52bb77fd6acb06b70cced0b883f"
|
|
59
59
|
}
|