@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.
@@ -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 p } from "./basket.js";
2
- import { applyKivaCredit as s, applyPromoCredit as m, removeKivaCredit as c, removePromoCredit as u } from "./basketCredits.js";
3
- import { setTipDonation as k } from "./basketItems.js";
4
- import { basketTotalsQuery as x, watchBasketTotals as h } from "./basketTotals.js";
5
- import { VerificationState as d, isBasketVerified as C } from "./basketVerification.js";
6
- import { getCheckoutStatus as g, pollForFinishedCheckout as T } from "./checkoutStatus.js";
7
- import { getPromoFromBasket as B } from "./managedAccount.js";
8
- import { executeOneTimeCheckout as P } from "./oneTimeCheckout.js";
9
- import { getCheckoutTrackingData as F, getFTDStatus as I, getReceiptItems as b, getReceiptTotals as w } from "./receipt.js";
10
- import { ShopError as K, parseShopError as Q } from "./shopError.js";
11
- import { callShopMutation as R, callShopQuery as V, watchShopQuery as N } from "./shopQueries.js";
12
- import { checkSubscriptionStatus as j, executeNewSubscriptionCheckout as q } from "./subscriptionCheckout.js";
13
- import { defaultPaymentTypes as A, getClientToken as G, default as H } from "./useBraintreeDropIn.js";
14
- import { validatePreCheckout as L, validatePreCheckoutMutation as U } from "./validatePreCheckout.js";
15
- import { default as X } from "./components/KvPaymentSelect.js";
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
- X as KvPaymentSelect,
18
- K as ShopError,
19
- d as VerificationState,
20
- s as applyKivaCredit,
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
- x as basketTotalsQuery,
23
- R as callShopMutation,
24
- V as callShopQuery,
25
- j as checkSubscriptionStatus,
25
+ d as basketTotalsQuery,
26
+ N as callShopMutation,
27
+ j as callShopQuery,
28
+ A as checkSubscriptionStatus,
26
29
  o as createBasket,
27
- A as defaultPaymentTypes,
28
- q as executeNewSubscriptionCheckout,
29
- P as executeOneTimeCheckout,
30
+ L as defaultPaymentTypes,
31
+ H as executeNewSubscriptionCheckout,
32
+ I as executeOneTimeCheckout,
33
+ b as executeOneTimeCheckoutForGivingFund,
30
34
  r as getBasketID,
31
- g as getCheckoutStatus,
32
- F as getCheckoutTrackingData,
33
- G as getClientToken,
34
- I as getFTDStatus,
35
- B as getPromoFromBasket,
36
- b as getReceiptItems,
37
- w as getReceiptTotals,
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
- Q as parseShopError,
41
- T as pollForFinishedCheckout,
42
- c as removeKivaCredit,
43
- u as removePromoCredit,
44
- p as setBasketID,
45
- k as setTipDonation,
46
- H as useBraintreeDropIn,
47
- L as validatePreCheckout,
48
- U as validatePreCheckoutMutation,
49
- h as watchBasketTotals,
50
- N as watchShopQuery
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
  };
@@ -1,18 +1,20 @@
1
- import { gql as s } from "@apollo/client/core";
2
- import { trackTransaction as C } from "@kiva/kv-analytics";
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 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`
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 = (e = (r = o == null ? void 0 : o.shop) == null ? void 0 : r.basket) == null ? void 0 : e.totals) == null ? void 0 : i.creditAmountNeeded;
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 R = s`
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
- `, _ = s`
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 x(t) {
64
- return b(t, {
65
- mutation: R,
65
+ function R(e) {
66
+ return q(e, {
67
+ mutation: Q,
66
68
  variables: {
67
- visitorId: v()
69
+ visitorId: N()
68
70
  }
69
71
  }, 0);
70
72
  }
71
- async function B({
72
- apollo: t,
73
- braintree: o,
73
+ async function l({
74
+ apollo: e,
75
+ braintree: t,
74
76
  amount: r
75
77
  }) {
76
78
  try {
77
- const e = await o.requestPaymentMethod();
78
- if (!e)
79
- throw new g(
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: d, type: n } = e;
85
+ const { nonce: i, deviceData: s, type: a } = o;
84
86
  return {
85
- paymentType: n,
86
- mutation: b(t, {
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: d,
94
- visitorId: v()
95
+ deviceData: s,
96
+ visitorId: N()
95
97
  }
96
98
  }, 0)
97
99
  };
98
- } catch (e) {
99
- throw S(e);
100
+ } catch (o) {
101
+ throw S(o);
100
102
  }
101
103
  }
102
- async function F(t, o, r) {
104
+ async function A(e, t, r) {
103
105
  try {
104
- const e = await T(
106
+ const o = await _(
107
+ e,
105
108
  t,
106
- o,
107
109
  r
108
110
  );
109
- C(e), await q(800);
110
- } catch (e) {
111
- console.error("Error tracking transaction", e);
111
+ F(o), await B(800);
112
+ } catch (o) {
113
+ console.error("Error tracking transaction", o);
112
114
  }
113
115
  }
114
- async function W({
115
- apollo: t,
116
- braintree: o,
116
+ async function ot({
117
+ apollo: e,
118
+ braintree: t,
117
119
  emailAddress: r,
118
- emailOptIn: e,
120
+ emailOptIn: o,
119
121
  valetInviter: i,
120
- deactivateRedirect: d
122
+ deactivateRedirect: s
121
123
  }) {
122
- var k, y, f, I, w;
123
- await N({
124
- apollo: t,
124
+ var d, I, h, p, k;
125
+ await D({
126
+ apollo: e,
125
127
  emailAddress: r,
126
- emailOptIn: e,
128
+ emailOptIn: o,
127
129
  valetInviter: i
128
130
  });
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({
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: o,
137
- amount: n
190
+ braintree: r,
191
+ amount: u
138
192
  });
139
- m = $.paymentType, a = await $.mutation;
193
+ m = C.paymentType, n = await C.mutation;
140
194
  } else
141
- a = await x(t);
142
- const l = (k = a == null ? void 0 : a.shop) == null ? void 0 : k.transactionId, c = await P({
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: l,
198
+ transactionSagaId: w,
145
199
  timeout: 3e5
146
200
  // five minutes
147
201
  });
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);
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
- W as executeOneTimeCheckout
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.73",
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.0",
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": "664b7df4d6a1ac8608eefcbf5e3b2387ea84052b"
58
+ "gitHead": "4c7bdf26569f83523e54f30f447957b8a832b8b0"
59
59
  }