@kiva/kv-shop 3.0.73 → 3.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/givingFunds.js +36 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +48 -44
- package/dist/oneTimeCheckout.js +122 -70
- package/package.json +3 -3
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { gql as e } from "@apollo/client/core";
|
|
2
|
+
import { getVisitorID as g } from "./util/visitorId.js";
|
|
3
|
+
import { parseShopError as s, ShopError as f } from "./shopError.js";
|
|
4
|
+
const m = e`
|
|
5
|
+
mutation AddGivingFund($fund: GivingFundInput!) {
|
|
6
|
+
addGivingFund(fund: $fund) {
|
|
7
|
+
id
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
async function F({
|
|
12
|
+
apollo: t,
|
|
13
|
+
fundTarget: d,
|
|
14
|
+
userId: o
|
|
15
|
+
}) {
|
|
16
|
+
var n;
|
|
17
|
+
const r = await t.mutate({
|
|
18
|
+
mutation: m,
|
|
19
|
+
variables: {
|
|
20
|
+
fund: {
|
|
21
|
+
userId: o,
|
|
22
|
+
target: d,
|
|
23
|
+
visitorId: g()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
if (r.errors) {
|
|
28
|
+
const a = r.errors.map((u) => s(u)), i = new f({ code: "shop.failedAddGivingFund" });
|
|
29
|
+
throw i.aggregateErrors(a), i;
|
|
30
|
+
}
|
|
31
|
+
return (n = r.data) == null ? void 0 : n.addGivingFund;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
F as addGivingFund,
|
|
35
|
+
m as addGivingFundMutation
|
|
36
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,22 @@ import { Ref } from 'vue';
|
|
|
10
10
|
import { TransactionData } from '@kiva/kv-analytics';
|
|
11
11
|
import { WatchQueryOptions } from '@apollo/client/core';
|
|
12
12
|
|
|
13
|
+
export declare function addGivingFund({ apollo, fundTarget, userId, }: AddGivingFundOptions): Promise<any>;
|
|
14
|
+
|
|
15
|
+
export declare interface AddGivingFundData {
|
|
16
|
+
addGivingFund: {
|
|
17
|
+
id: string;
|
|
18
|
+
} | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export declare const addGivingFundMutation: DocumentNode;
|
|
22
|
+
|
|
23
|
+
export declare interface AddGivingFundOptions {
|
|
24
|
+
apollo: ApolloClient<any>;
|
|
25
|
+
userId?: string;
|
|
26
|
+
fundTarget: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
13
29
|
export declare function applyKivaCredit(apollo: ApolloClient<any>): Promise<boolean>;
|
|
14
30
|
|
|
15
31
|
export declare interface ApplyKivaCreditData {
|
|
@@ -98,6 +114,8 @@ export declare function executeNewSubscriptionCheckout({ amount, apollo, dayOfMo
|
|
|
98
114
|
|
|
99
115
|
export declare function executeOneTimeCheckout({ apollo, braintree, emailAddress, emailOptIn, valetInviter, deactivateRedirect, }: OneTimeCheckoutOptions): Promise<CheckoutStatusQueryResult>;
|
|
100
116
|
|
|
117
|
+
export declare function executeOneTimeCheckoutForGivingFund({ amount, apollo, braintree, emailAddress, emailOptIn, fundTarget, userId, }: OneTimeCheckoutForGivingFundOptions): Promise<CheckoutStatusQueryResult>;
|
|
118
|
+
|
|
101
119
|
export declare function getBasketID(): string;
|
|
102
120
|
|
|
103
121
|
export declare function getCheckoutStatus({ apollo, transactionSagaId }: GetCheckoutStatusOptions): Promise<CheckoutStatusQueryResult>;
|
|
@@ -125,6 +143,17 @@ export declare function isBasketVerified(state: VerificationState): boolean;
|
|
|
125
143
|
|
|
126
144
|
export { KvPaymentSelect }
|
|
127
145
|
|
|
146
|
+
export declare interface OneTimeCheckoutForGivingFundOptions {
|
|
147
|
+
apollo: ApolloClient<any>;
|
|
148
|
+
braintree?: DropInWrapper;
|
|
149
|
+
emailAddress?: string;
|
|
150
|
+
emailOptIn?: boolean;
|
|
151
|
+
userId?: string;
|
|
152
|
+
fundTarget: string;
|
|
153
|
+
amount: string;
|
|
154
|
+
visitorId?: string;
|
|
155
|
+
}
|
|
156
|
+
|
|
128
157
|
export declare interface OneTimeCheckoutOptions {
|
|
129
158
|
apollo: ApolloClient<any>;
|
|
130
159
|
braintree?: DropInWrapper;
|
package/dist/index.js
CHANGED
|
@@ -1,51 +1,55 @@
|
|
|
1
|
-
import { createBasket as o, getBasketID as r, hasBasketExpired as a, setBasketID as
|
|
2
|
-
import { applyKivaCredit as
|
|
3
|
-
import { setTipDonation as
|
|
4
|
-
import { basketTotalsQuery as
|
|
5
|
-
import { VerificationState as
|
|
6
|
-
import { getCheckoutStatus as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
1
|
+
import { createBasket as o, getBasketID as r, hasBasketExpired as a, setBasketID as i } from "./basket.js";
|
|
2
|
+
import { applyKivaCredit as u, applyPromoCredit as m, removeKivaCredit as s, removePromoCredit as c } from "./basketCredits.js";
|
|
3
|
+
import { setTipDonation as f } from "./basketItems.js";
|
|
4
|
+
import { basketTotalsQuery as d, watchBasketTotals as k } from "./basketTotals.js";
|
|
5
|
+
import { VerificationState as l, isBasketVerified as C } from "./basketVerification.js";
|
|
6
|
+
import { getCheckoutStatus as S, pollForFinishedCheckout as v } from "./checkoutStatus.js";
|
|
7
|
+
import { addGivingFund as y, addGivingFundMutation as B } from "./givingFunds.js";
|
|
8
|
+
import { getPromoFromBasket as P } from "./managedAccount.js";
|
|
9
|
+
import { executeOneTimeCheckout as I, executeOneTimeCheckoutForGivingFund as b } from "./oneTimeCheckout.js";
|
|
10
|
+
import { getCheckoutTrackingData as E, getFTDStatus as G, getReceiptItems as K, getReceiptTotals as M } from "./receipt.js";
|
|
11
|
+
import { ShopError as O, parseShopError as R } from "./shopError.js";
|
|
12
|
+
import { callShopMutation as N, callShopQuery as j, watchShopQuery as q } from "./shopQueries.js";
|
|
13
|
+
import { checkSubscriptionStatus as A, executeNewSubscriptionCheckout as H } from "./subscriptionCheckout.js";
|
|
14
|
+
import { defaultPaymentTypes as L, getClientToken as U, default as W } from "./useBraintreeDropIn.js";
|
|
15
|
+
import { validatePreCheckout as Y, validatePreCheckoutMutation as Z } from "./validatePreCheckout.js";
|
|
16
|
+
import { default as $ } from "./components/KvPaymentSelect.js";
|
|
16
17
|
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
$ as KvPaymentSelect,
|
|
19
|
+
O as ShopError,
|
|
20
|
+
l as VerificationState,
|
|
21
|
+
y as addGivingFund,
|
|
22
|
+
B as addGivingFundMutation,
|
|
23
|
+
u as applyKivaCredit,
|
|
21
24
|
m as applyPromoCredit,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
d as basketTotalsQuery,
|
|
26
|
+
N as callShopMutation,
|
|
27
|
+
j as callShopQuery,
|
|
28
|
+
A as checkSubscriptionStatus,
|
|
26
29
|
o as createBasket,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
L as defaultPaymentTypes,
|
|
31
|
+
H as executeNewSubscriptionCheckout,
|
|
32
|
+
I as executeOneTimeCheckout,
|
|
33
|
+
b as executeOneTimeCheckoutForGivingFund,
|
|
30
34
|
r as getBasketID,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
S as getCheckoutStatus,
|
|
36
|
+
E as getCheckoutTrackingData,
|
|
37
|
+
U as getClientToken,
|
|
38
|
+
G as getFTDStatus,
|
|
39
|
+
P as getPromoFromBasket,
|
|
40
|
+
K as getReceiptItems,
|
|
41
|
+
M as getReceiptTotals,
|
|
38
42
|
a as hasBasketExpired,
|
|
39
43
|
C as isBasketVerified,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
R as parseShopError,
|
|
45
|
+
v as pollForFinishedCheckout,
|
|
46
|
+
s as removeKivaCredit,
|
|
47
|
+
c as removePromoCredit,
|
|
48
|
+
i as setBasketID,
|
|
49
|
+
f as setTipDonation,
|
|
50
|
+
W as useBraintreeDropIn,
|
|
51
|
+
Y as validatePreCheckout,
|
|
52
|
+
Z as validatePreCheckoutMutation,
|
|
53
|
+
k as watchBasketTotals,
|
|
54
|
+
q as watchShopQuery
|
|
51
55
|
};
|
package/dist/oneTimeCheckout.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { gql as
|
|
2
|
-
import { trackTransaction as
|
|
1
|
+
import { gql as $ } from "@apollo/client/core";
|
|
2
|
+
import { trackTransaction as F } from "@kiva/kv-analytics";
|
|
3
3
|
import M from "numeral";
|
|
4
|
-
import { pollForFinishedCheckout as
|
|
5
|
-
import { ShopError as
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
import { pollForFinishedCheckout as T } from "./checkoutStatus.js";
|
|
5
|
+
import { ShopError as v, parseShopError as S } from "./shopError.js";
|
|
6
|
+
import { callShopQuery as x, callShopMutation as q } from "./shopQueries.js";
|
|
7
|
+
import { validatePreCheckout as D } from "./validatePreCheckout.js";
|
|
8
|
+
import { wait as B } from "./util/poll.js";
|
|
9
|
+
import { getVisitorID as N } from "./util/visitorId.js";
|
|
10
|
+
import { redirectTo as E } from "./util/redirect.js";
|
|
11
|
+
import { getCheckoutTrackingData as _ } from "./receipt.js";
|
|
12
|
+
import { addGivingFund as G } from "./givingFunds.js";
|
|
13
|
+
import { setTipDonation as O } from "./basketItems.js";
|
|
14
|
+
async function P(e) {
|
|
15
|
+
var r, o, i;
|
|
16
|
+
const t = await x(e, {
|
|
17
|
+
query: $`
|
|
16
18
|
query creditAmountNeeded($basketId: String) {
|
|
17
19
|
shop (basketId: $basketId) {
|
|
18
20
|
id
|
|
@@ -27,9 +29,9 @@ async function E(t) {
|
|
|
27
29
|
`,
|
|
28
30
|
fetchPolicy: "network-only"
|
|
29
31
|
}, 0);
|
|
30
|
-
return (i = (
|
|
32
|
+
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;
|
|
31
33
|
}
|
|
32
|
-
const
|
|
34
|
+
const Q = $`
|
|
33
35
|
mutation creditCheckout(
|
|
34
36
|
$basketId: String,
|
|
35
37
|
$visitorId: String
|
|
@@ -39,7 +41,7 @@ const R = s`
|
|
|
39
41
|
transactionId: checkoutAsync (visitorId: $visitorId)
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
|
-
`,
|
|
44
|
+
`, U = $`
|
|
43
45
|
mutation depositCheckout(
|
|
44
46
|
$basketId: String,
|
|
45
47
|
$amount: Money!,
|
|
@@ -60,99 +62,149 @@ const R = s`
|
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
`;
|
|
63
|
-
function
|
|
64
|
-
return
|
|
65
|
-
mutation:
|
|
65
|
+
function R(e) {
|
|
66
|
+
return q(e, {
|
|
67
|
+
mutation: Q,
|
|
66
68
|
variables: {
|
|
67
|
-
visitorId:
|
|
69
|
+
visitorId: N()
|
|
68
70
|
}
|
|
69
71
|
}, 0);
|
|
70
72
|
}
|
|
71
|
-
async function
|
|
72
|
-
apollo:
|
|
73
|
-
braintree:
|
|
73
|
+
async function l({
|
|
74
|
+
apollo: e,
|
|
75
|
+
braintree: t,
|
|
74
76
|
amount: r
|
|
75
77
|
}) {
|
|
76
78
|
try {
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
79
|
-
throw new
|
|
79
|
+
const o = await t.requestPaymentMethod();
|
|
80
|
+
if (!o)
|
|
81
|
+
throw new v(
|
|
80
82
|
{ code: "shop.dropinNoPaymentMethod" },
|
|
81
83
|
"No payment method returned from braintree dropin"
|
|
82
84
|
);
|
|
83
|
-
const { nonce: i, deviceData:
|
|
85
|
+
const { nonce: i, deviceData: s, type: a } = o;
|
|
84
86
|
return {
|
|
85
|
-
paymentType:
|
|
86
|
-
mutation:
|
|
87
|
-
mutation:
|
|
87
|
+
paymentType: a,
|
|
88
|
+
mutation: q(e, {
|
|
89
|
+
mutation: U,
|
|
88
90
|
variables: {
|
|
89
91
|
nonce: i,
|
|
90
92
|
amount: r,
|
|
91
93
|
savePaymentMethod: !1,
|
|
92
94
|
// save payment methods handled by braintree drop in UI
|
|
93
|
-
deviceData:
|
|
94
|
-
visitorId:
|
|
95
|
+
deviceData: s,
|
|
96
|
+
visitorId: N()
|
|
95
97
|
}
|
|
96
98
|
}, 0)
|
|
97
99
|
};
|
|
98
|
-
} catch (
|
|
99
|
-
throw S(
|
|
100
|
+
} catch (o) {
|
|
101
|
+
throw S(o);
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
|
-
async function
|
|
104
|
+
async function A(e, t, r) {
|
|
103
105
|
try {
|
|
104
|
-
const
|
|
106
|
+
const o = await _(
|
|
107
|
+
e,
|
|
105
108
|
t,
|
|
106
|
-
o,
|
|
107
109
|
r
|
|
108
110
|
);
|
|
109
|
-
|
|
110
|
-
} catch (
|
|
111
|
-
console.error("Error tracking transaction",
|
|
111
|
+
F(o), await B(800);
|
|
112
|
+
} catch (o) {
|
|
113
|
+
console.error("Error tracking transaction", o);
|
|
112
114
|
}
|
|
113
115
|
}
|
|
114
|
-
async function
|
|
115
|
-
apollo:
|
|
116
|
-
braintree:
|
|
116
|
+
async function ot({
|
|
117
|
+
apollo: e,
|
|
118
|
+
braintree: t,
|
|
117
119
|
emailAddress: r,
|
|
118
|
-
emailOptIn:
|
|
120
|
+
emailOptIn: o,
|
|
119
121
|
valetInviter: i,
|
|
120
|
-
deactivateRedirect:
|
|
122
|
+
deactivateRedirect: s
|
|
121
123
|
}) {
|
|
122
|
-
var
|
|
123
|
-
await
|
|
124
|
-
apollo:
|
|
124
|
+
var d, I, h, p, k;
|
|
125
|
+
await D({
|
|
126
|
+
apollo: e,
|
|
125
127
|
emailAddress: r,
|
|
126
|
-
emailOptIn:
|
|
128
|
+
emailOptIn: o,
|
|
127
129
|
valetInviter: i
|
|
128
130
|
});
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
131
|
-
throw new
|
|
132
|
-
let
|
|
133
|
-
if (
|
|
134
|
-
const
|
|
131
|
+
const a = await P(e), g = M(a).value() > 0;
|
|
132
|
+
if (g && !t)
|
|
133
|
+
throw new v({ code: "shop.dropinRequired" }, "Braintree dropin required for credit deposit checkout");
|
|
134
|
+
let c, u = "";
|
|
135
|
+
if (g) {
|
|
136
|
+
const y = await l({
|
|
137
|
+
apollo: e,
|
|
138
|
+
braintree: t,
|
|
139
|
+
amount: a
|
|
140
|
+
});
|
|
141
|
+
u = y.paymentType, c = await y.mutation;
|
|
142
|
+
} else
|
|
143
|
+
c = await R(e);
|
|
144
|
+
const f = (d = c == null ? void 0 : c.shop) == null ? void 0 : d.transactionId, n = await T({
|
|
145
|
+
apollo: e,
|
|
146
|
+
transactionSagaId: f,
|
|
147
|
+
timeout: 3e5
|
|
148
|
+
// five minutes
|
|
149
|
+
});
|
|
150
|
+
if ((I = n.errors) != null && I.length)
|
|
151
|
+
throw S(n.errors[0]);
|
|
152
|
+
const m = (k = (p = (h = n.data) == null ? void 0 : h.checkoutStatus) == null ? void 0 : p.receipt) == null ? void 0 : k.checkoutId;
|
|
153
|
+
if (await A(e, m, u), s)
|
|
154
|
+
return n;
|
|
155
|
+
let w = `/checkout/post-purchase?kiva_transaction_id=${m}`;
|
|
156
|
+
i != null && i.inviterId && (w += `&valet_inviter=${i.inviterId}`), await E(w);
|
|
157
|
+
}
|
|
158
|
+
async function it({
|
|
159
|
+
amount: e,
|
|
160
|
+
apollo: t,
|
|
161
|
+
braintree: r,
|
|
162
|
+
emailAddress: o,
|
|
163
|
+
emailOptIn: i,
|
|
164
|
+
fundTarget: s,
|
|
165
|
+
userId: a
|
|
166
|
+
}) {
|
|
167
|
+
var h, p, k, y, b;
|
|
168
|
+
await D({
|
|
169
|
+
apollo: t,
|
|
170
|
+
emailAddress: o,
|
|
171
|
+
emailOptIn: i
|
|
172
|
+
});
|
|
173
|
+
const c = `campaignId: ${(await G({
|
|
174
|
+
apollo: t,
|
|
175
|
+
fundTarget: s,
|
|
176
|
+
userId: a ? `${a}` : void 0
|
|
177
|
+
})).id}`;
|
|
178
|
+
await O({
|
|
179
|
+
amount: e,
|
|
180
|
+
metadata: c,
|
|
181
|
+
apollo: t
|
|
182
|
+
});
|
|
183
|
+
const u = await P(t), f = M(u).value() > 0;
|
|
184
|
+
if (f && !r)
|
|
185
|
+
throw new v({ code: "shop.dropinRequired" }, "Braintree dropin required for credit deposit checkout");
|
|
186
|
+
let n, m = "";
|
|
187
|
+
if (f) {
|
|
188
|
+
const C = await l({
|
|
135
189
|
apollo: t,
|
|
136
|
-
braintree:
|
|
137
|
-
amount:
|
|
190
|
+
braintree: r,
|
|
191
|
+
amount: u
|
|
138
192
|
});
|
|
139
|
-
m =
|
|
193
|
+
m = C.paymentType, n = await C.mutation;
|
|
140
194
|
} else
|
|
141
|
-
|
|
142
|
-
const
|
|
195
|
+
n = await R(t);
|
|
196
|
+
const w = (h = n == null ? void 0 : n.shop) == null ? void 0 : h.transactionId, d = await T({
|
|
143
197
|
apollo: t,
|
|
144
|
-
transactionSagaId:
|
|
198
|
+
transactionSagaId: w,
|
|
145
199
|
timeout: 3e5
|
|
146
200
|
// five minutes
|
|
147
201
|
});
|
|
148
|
-
if ((
|
|
149
|
-
throw S(
|
|
150
|
-
const
|
|
151
|
-
|
|
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);
|
|
202
|
+
if ((p = d.errors) != null && p.length)
|
|
203
|
+
throw S(d.errors[0]);
|
|
204
|
+
const I = (b = (y = (k = d.data) == null ? void 0 : k.checkoutStatus) == null ? void 0 : y.receipt) == null ? void 0 : b.checkoutId;
|
|
205
|
+
return await A(t, I, m), d;
|
|
155
206
|
}
|
|
156
207
|
export {
|
|
157
|
-
|
|
208
|
+
ot as executeOneTimeCheckout,
|
|
209
|
+
it as executeOneTimeCheckoutForGivingFund
|
|
158
210
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiva/kv-shop",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@apollo/client": "^3.13.1",
|
|
28
28
|
"@kiva/kv-analytics": "^1.3.0",
|
|
29
|
-
"@kiva/kv-components": "^6.38.
|
|
29
|
+
"@kiva/kv-components": "^6.38.1",
|
|
30
30
|
"@kiva/vite-plugin-vue-lib-css": "^2.0.0",
|
|
31
31
|
"@types/braintree-web-drop-in": "^1.39.3",
|
|
32
32
|
"@types/jest": "^29.5.14",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"numeral": "2.x",
|
|
56
56
|
"vue": "3.x"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "4c7bdf26569f83523e54f30f447957b8a832b8b0"
|
|
59
59
|
}
|