@kiva/kv-shop 2.1.2 → 3.0.1

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.
Files changed (76) hide show
  1. package/dist/_virtual/_commonjs-dynamic-modules.js +6 -0
  2. package/dist/_virtual/_commonjsHelpers.js +8 -0
  3. package/dist/_virtual/_plugin-vue_export-helper.js +9 -0
  4. package/dist/_virtual/dropin.js +11 -0
  5. package/dist/_virtual/dropin2.js +4 -0
  6. package/dist/basket.js +35 -12
  7. package/dist/basketCredits.js +78 -14
  8. package/dist/basketItems.js +27 -8
  9. package/dist/basketTotals.js +38 -10
  10. package/dist/basketVerification.js +6 -6
  11. package/dist/checkoutStatus.js +52 -8
  12. package/dist/components/KvPaymentSelect.css +1 -0
  13. package/dist/components/KvPaymentSelect.js +23 -0
  14. package/dist/components/KvPaymentSelect2.js +110 -0
  15. package/dist/index.d.ts +321 -20
  16. package/dist/index.js +49 -96
  17. package/dist/managedAccount.js +62 -8
  18. package/dist/oneTimeCheckout.js +156 -12
  19. package/dist/receipt.js +143 -12
  20. package/dist/shopError.js +41 -6
  21. package/dist/shopQueries.js +82 -11
  22. package/dist/subscriptionCheckout.js +88 -7
  23. package/dist/useBraintreeDropIn.js +145 -9
  24. package/dist/util/cookie.js +11 -0
  25. package/dist/util/poll.js +17 -0
  26. package/dist/util/redirect.js +8 -0
  27. package/dist/util/visitorId.js +7 -0
  28. package/dist/validatePreCheckout.js +44 -11
  29. package/dist/vendor/braintree-web-drop-in/dist/browser/dropin.js +12223 -0
  30. package/package.json +28 -26
  31. package/dist/basket.cjs +0 -141
  32. package/dist/basket.d.ts +0 -8
  33. package/dist/basketCredits.cjs +0 -250
  34. package/dist/basketCredits.d.ts +0 -32
  35. package/dist/basketItems.cjs +0 -205
  36. package/dist/basketItems.d.ts +0 -26
  37. package/dist/basketTotals.cjs +0 -228
  38. package/dist/basketTotals.d.ts +0 -37
  39. package/dist/basketVerification.cjs +0 -41
  40. package/dist/basketVerification.d.ts +0 -10
  41. package/dist/checkoutStatus.cjs +0 -111
  42. package/dist/checkoutStatus.d.ts +0 -20
  43. package/dist/chunk-4ODZGLWK.js +0 -64
  44. package/dist/chunk-ASZJVUQ7.js +0 -72
  45. package/dist/chunk-FBF4WMN6.js +0 -49
  46. package/dist/chunk-FC4QW6QA.js +0 -106
  47. package/dist/chunk-FCAOCO7O.js +0 -17
  48. package/dist/chunk-GVVI7X2R.js +0 -196
  49. package/dist/chunk-IIN37LC7.js +0 -45
  50. package/dist/chunk-IOZ5ERDX.js +0 -121
  51. package/dist/chunk-KCUOMCSN.js +0 -58
  52. package/dist/chunk-LZ4UMRCV.js +0 -16
  53. package/dist/chunk-RQNRQ2E5.js +0 -155
  54. package/dist/chunk-SRGYGDAX.js +0 -80
  55. package/dist/chunk-TPJPGUO7.js +0 -12
  56. package/dist/chunk-UJXHTR43.js +0 -86
  57. package/dist/chunk-VZ3VDRRP.js +0 -167
  58. package/dist/chunk-Z7JRY3QE.js +0 -34
  59. package/dist/components/KvPaymentSelect.vue +0 -380
  60. package/dist/index.cjs +0 -1227
  61. package/dist/managedAccount.cjs +0 -231
  62. package/dist/managedAccount.d.ts +0 -59
  63. package/dist/oneTimeCheckout.cjs +0 -636
  64. package/dist/oneTimeCheckout.d.ts +0 -21
  65. package/dist/receipt.cjs +0 -191
  66. package/dist/receipt.d.ts +0 -16
  67. package/dist/shopError.cjs +0 -88
  68. package/dist/shopError.d.ts +0 -14
  69. package/dist/shopQueries.cjs +0 -248
  70. package/dist/shopQueries.d.ts +0 -8
  71. package/dist/subscriptionCheckout.cjs +0 -187
  72. package/dist/subscriptionCheckout.d.ts +0 -13
  73. package/dist/useBraintreeDropIn.cjs +0 -258
  74. package/dist/useBraintreeDropIn.d.ts +0 -25
  75. package/dist/validatePreCheckout.cjs +0 -218
  76. package/dist/validatePreCheckout.d.ts +0 -28
@@ -1,58 +0,0 @@
1
- import {
2
- getVisitorID
3
- } from "./chunk-TPJPGUO7.js";
4
- import {
5
- callShopMutation
6
- } from "./chunk-IOZ5ERDX.js";
7
- import {
8
- ShopError,
9
- parseShopError
10
- } from "./chunk-4ODZGLWK.js";
11
-
12
- // src/validatePreCheckout.ts
13
- import { gql } from "@apollo/client/core/core.cjs";
14
- var validatePreCheckoutMutation = gql`
15
- mutation validatePreCheckout(
16
- $basketId: String,
17
- $email: String,
18
- $visitorId: String,
19
- $emailOptIn: Boolean,
20
- $inviter: InviterInput
21
- ) {
22
- shop (basketId: $basketId) {
23
- id
24
- validatePreCheckout (email: $email, visitorId: $visitorId, emailOptIn: $emailOptIn, inviter: $inviter) {
25
- error
26
- success
27
- value
28
- }
29
- }
30
- }`;
31
- async function validatePreCheckout({
32
- apollo,
33
- emailAddress,
34
- emailOptIn,
35
- valetInviter
36
- }) {
37
- const data = await callShopMutation(apollo, {
38
- mutation: validatePreCheckoutMutation,
39
- variables: {
40
- visitorId: getVisitorID(),
41
- email: emailAddress,
42
- emailOptIn,
43
- inviter: valetInviter
44
- }
45
- }, 0);
46
- const results = data?.shop?.validatePreCheckout;
47
- const errors = results.filter(({ success }) => !success).map((result) => parseShopError(result));
48
- if (errors.length) {
49
- const aggregate = new ShopError({ code: "shop.failedCheckoutValidation" });
50
- aggregate.aggregateErrors(errors);
51
- throw aggregate;
52
- }
53
- }
54
-
55
- export {
56
- validatePreCheckoutMutation,
57
- validatePreCheckout
58
- };
@@ -1,16 +0,0 @@
1
- // src/util/cookie.ts
2
- var getCookieValue = (name) => {
3
- if (typeof document !== void 0) {
4
- return decodeURIComponent(document.cookie.match(`(^|;)\\s*${name}\\s*=\\s*([^;]+)`)?.pop() || "");
5
- }
6
- };
7
- var setCookieValue = (name, value, options = "") => {
8
- if (typeof document !== void 0) {
9
- document.cookie = `${name}=${encodeURIComponent(value)};${options}`;
10
- }
11
- };
12
-
13
- export {
14
- getCookieValue,
15
- setCookieValue
16
- };
@@ -1,155 +0,0 @@
1
- import {
2
- getVisitorID
3
- } from "./chunk-TPJPGUO7.js";
4
-
5
- // src/receipt.ts
6
- import { gql } from "@apollo/client/core/core.cjs";
7
- async function getFTDStatus(apollo) {
8
- const result = await apollo.query({
9
- query: gql`
10
- query ftdStatus {
11
- my {
12
- id
13
- userAccount {
14
- id
15
- isFirstTimeDepositor
16
- }
17
- }
18
- }
19
- `
20
- });
21
- return result.data?.my?.userAccount?.isFirstTimeDepositor ?? false;
22
- }
23
- async function getReceiptItems(apollo, checkoutId) {
24
- return new Promise((resolve, reject) => {
25
- const limit = 100;
26
- let offset = 0;
27
- const observer = apollo.watchQuery({
28
- query: gql`
29
- query receiptItems($checkoutId: Int, $visitorId: String, $limit: Int, $offset: Int) {
30
- shop {
31
- id
32
- receipt(checkoutId: $checkoutId, visitorId: $visitorId) {
33
- id
34
- items(limit: $limit, offset: $offset) {
35
- totalCount
36
- values {
37
- id
38
- price
39
- __typename
40
-
41
- ... on Donation {
42
- id
43
- isTip
44
- isUserEdited
45
- }
46
- }
47
- }
48
- }
49
- }
50
- }
51
- `,
52
- variables: {
53
- checkoutId,
54
- visitorId: getVisitorID(),
55
- limit,
56
- offset
57
- }
58
- });
59
- let items = [];
60
- const handleResult = async (result) => {
61
- const total = result.data?.shop?.receipt?.items?.totalCount;
62
- items = items.concat(result.data?.shop?.receipt?.items?.values);
63
- if (total > offset + limit) {
64
- offset += limit;
65
- const nextResult = await observer.fetchMore({
66
- variables: {
67
- offset
68
- }
69
- });
70
- try {
71
- handleResult(nextResult);
72
- } catch (e) {
73
- reject(e);
74
- }
75
- } else {
76
- resolve(items);
77
- }
78
- };
79
- observer.subscribe({
80
- next: handleResult,
81
- error: (error) => {
82
- reject(error);
83
- }
84
- });
85
- });
86
- }
87
- async function getReceiptTotals(apollo, checkoutId) {
88
- const result = await apollo.query({
89
- query: gql`
90
- query receiptTotals($checkoutId: Int, $visitorId: String) {
91
- shop {
92
- id
93
- receipt(checkoutId: $checkoutId, visitorId: $visitorId) {
94
- id
95
- totals {
96
- loanReservationTotal
97
- donationTotal
98
- kivaCardTotal
99
- itemTotal
100
- kivaCreditAppliedTotal
101
- depositTotals {
102
- depositTotal
103
- }
104
- }
105
- }
106
- }
107
- }
108
- `,
109
- variables: {
110
- checkoutId,
111
- visitorId: getVisitorID()
112
- }
113
- });
114
- return result.data?.shop?.receipt?.totals;
115
- }
116
- async function getCheckoutTrackingData(apollo, checkoutId, paymentType) {
117
- const checkoutIdInt = parseInt(checkoutId, 10);
118
- const [isFTD, items, totals] = await Promise.all([
119
- getFTDStatus(apollo),
120
- getReceiptItems(apollo, checkoutIdInt),
121
- getReceiptTotals(apollo, checkoutIdInt)
122
- ]);
123
- const loans = items.filter((item) => item.__typename === "LoanReservation");
124
- const donations = items.filter((item) => item.__typename === "Donation");
125
- const kivaCards = items.filter((item) => item.__typename === "KivaCard");
126
- return {
127
- transactionId: checkoutId,
128
- itemTotal: totals.itemTotal,
129
- // Loan reservations
130
- loans,
131
- loanCount: loans.length,
132
- loanTotal: totals.loanReservationTotal,
133
- // Donations
134
- donations: donations.map(({ id, price, __typename }) => ({ id, price, __typename })),
135
- donationTotal: totals.donationTotal,
136
- isTip: donations.every((donation) => donation.isTip),
137
- isUserEdited: donations.some((donation) => donation.isUserEdited),
138
- // Kiva Cards
139
- kivaCards,
140
- kivaCardCount: kivaCards.length,
141
- kivaCardTotal: totals.kivaCardTotal,
142
- // Credit & deposit
143
- kivaCreditAppliedTotal: totals.kivaCreditAppliedTotal,
144
- depositTotal: totals.depositTotals?.depositTotal ?? "0.00",
145
- paymentType,
146
- isFTD
147
- };
148
- }
149
-
150
- export {
151
- getFTDStatus,
152
- getReceiptItems,
153
- getReceiptTotals,
154
- getCheckoutTrackingData
155
- };
@@ -1,80 +0,0 @@
1
- import {
2
- getVisitorID
3
- } from "./chunk-TPJPGUO7.js";
4
-
5
- // src/checkoutStatus.ts
6
- import { gql } from "@apollo/client/core/core.cjs";
7
-
8
- // src/util/poll.ts
9
- function wait(ms) {
10
- return new Promise((resolve) => setTimeout(resolve, ms));
11
- }
12
- async function poll(fn, fnCondition, interval, timeout) {
13
- const endTime = Date.now() + timeout;
14
- let result = await fn();
15
- while (!fnCondition(result)) {
16
- if (Date.now() > endTime) {
17
- throw new Error("Polling timed out");
18
- }
19
- await wait(interval);
20
- result = await fn();
21
- }
22
- return result;
23
- }
24
-
25
- // src/checkoutStatus.ts
26
- async function getCheckoutStatus({ apollo, transactionSagaId }) {
27
- return apollo.query({
28
- query: gql`
29
- query checkoutStatus($transactionId: String!, $visitorId: String) {
30
- checkoutStatus(transactionId: $transactionId, visitorId: $visitorId) {
31
- basketId
32
- errorCode
33
- errorMessage
34
- receipt {
35
- checkoutId
36
- }
37
- requestedAt
38
- status
39
- transactionId
40
- updatedAt
41
- }
42
- }
43
- `,
44
- variables: {
45
- transactionId: transactionSagaId,
46
- visitorId: getVisitorID()
47
- },
48
- fetchPolicy: "network-only"
49
- });
50
- }
51
- async function pollForFinishedCheckout({
52
- apollo,
53
- transactionSagaId,
54
- interval = 1e3,
55
- timeout = 6e4
56
- }) {
57
- return poll(
58
- // function to poll
59
- () => getCheckoutStatus({
60
- apollo,
61
- transactionSagaId
62
- }),
63
- // function to check for completed status
64
- (result) => {
65
- const { status, errorCode, errorMessage } = result?.data?.checkoutStatus;
66
- if (status === "COMPLETED" || errorCode || errorMessage) {
67
- return true;
68
- }
69
- return false;
70
- },
71
- interval,
72
- timeout
73
- );
74
- }
75
-
76
- export {
77
- wait,
78
- getCheckoutStatus,
79
- pollForFinishedCheckout
80
- };
@@ -1,12 +0,0 @@
1
- import {
2
- getCookieValue
3
- } from "./chunk-LZ4UMRCV.js";
4
-
5
- // src/util/visitorId.ts
6
- function getVisitorID() {
7
- return getCookieValue("uiv");
8
- }
9
-
10
- export {
11
- getVisitorID
12
- };
@@ -1,86 +0,0 @@
1
- import {
2
- callShopMutation
3
- } from "./chunk-IOZ5ERDX.js";
4
-
5
- // src/basketCredits.ts
6
- import { gql } from "@apollo/client/core/core.cjs";
7
- async function applyKivaCredit(apollo) {
8
- const data = await callShopMutation(apollo, {
9
- awaitRefetchQueries: true,
10
- mutation: gql`mutation applyKivaCredit($basketId: String) {
11
- shop (basketId: $basketId) {
12
- id
13
- addCreditByType(creditType: kiva_credit)
14
- }
15
- }`
16
- });
17
- return !!data?.shop?.addCreditByType;
18
- }
19
- async function removeKivaCredit(apollo) {
20
- const data = await callShopMutation(apollo, {
21
- awaitRefetchQueries: true,
22
- mutation: gql`mutation removeKivaCredit($basketId: String) {
23
- shop (basketId: $basketId) {
24
- id
25
- removeCreditByType(creditType: kiva_credit)
26
- }
27
- }`
28
- });
29
- return !!data?.shop?.removeCreditByType;
30
- }
31
- async function applyPromoCredit(apollo, options) {
32
- if (!options?.variables?.creditType || !options?.variables?.redemptionCode) {
33
- return Promise.resolve({
34
- errors: [
35
- {
36
- message: "Missing required parameter.",
37
- extensions: { code: "upc.missing_parameter" }
38
- }
39
- ]
40
- });
41
- }
42
- const data = await callShopMutation(apollo, {
43
- awaitRefetchQueries: true,
44
- fetchPolicy: options?.fetchPolicy ?? "network-only",
45
- mutation: gql`mutation applyPromoCredit(
46
- $basketId: String,
47
- $creditType: CreditTypeEnum!,
48
- $redemptionCode: String
49
- ) {
50
- shop (basketId: $basketId) {
51
- id
52
- addCreditByType(creditType: $creditType, redemptionCode: $redemptionCode)
53
- }
54
- }`,
55
- variables: { ...options?.variables }
56
- });
57
- return data;
58
- }
59
- async function removePromoCredit(apollo, options) {
60
- if (!options?.variables?.creditType && !options?.variables?.redemptionCode) {
61
- return Promise.resolve(false);
62
- }
63
- const data = await callShopMutation(apollo, {
64
- awaitRefetchQueries: true,
65
- fetchPolicy: options?.fetchPolicy ?? "network-only",
66
- mutation: gql`mutation removePromoCredit(
67
- $basketId: String,
68
- $creditType: CreditTypeEnum!,
69
- $redemptionCode: String
70
- ) {
71
- shop (basketId: $basketId) {
72
- id
73
- removeCreditByType(creditType: $creditType, redemptionCode: $redemptionCode)
74
- }
75
- }`,
76
- variables: { ...options?.variables }
77
- });
78
- return !!data?.shop?.removeCreditByType;
79
- }
80
-
81
- export {
82
- applyKivaCredit,
83
- removeKivaCredit,
84
- applyPromoCredit,
85
- removePromoCredit
86
- };
@@ -1,167 +0,0 @@
1
- import {
2
- ShopError,
3
- parseShopError
4
- } from "./chunk-4ODZGLWK.js";
5
-
6
- // src/useBraintreeDropIn.ts
7
- import { gql } from "@apollo/client/core/core.cjs";
8
- import numeral from "numeral";
9
- import { ref } from "vue-demi";
10
- var defaultPaymentTypes = ["paypal", "card", "applePay", "googlePay"];
11
- async function getClientToken(apollo) {
12
- const { data, error, errors } = await apollo.query({
13
- query: gql`query getClientToken {
14
- shop {
15
- id
16
- getClientToken(useCustomerId: true)
17
- }
18
- }`
19
- });
20
- if (error || errors?.length) {
21
- throw parseShopError(error ?? errors?.[0]);
22
- }
23
- return data?.shop?.getClientToken;
24
- }
25
- function initBraintreeDropin() {
26
- let instance;
27
- let formattedAmount = "";
28
- const paymentMethodRequestable = ref(false);
29
- function getApplePaymentRequest(amount) {
30
- return {
31
- countryCode: "US",
32
- currencyCode: "USD",
33
- // merchantCapabilities: ['supports3DS'], // TODO: confirm/update
34
- requiredBillingContactFields: ["postalAddress"],
35
- // supportedNetworks: ['amex', 'discover', 'interac', 'jcb', 'masterCard', 'visa'], // TODO: confirm/update
36
- total: {
37
- label: "Kiva",
38
- amount
39
- }
40
- };
41
- }
42
- function getGoogleTransactionInfo(amount) {
43
- return {
44
- totalPriceStatus: "FINAL",
45
- totalPrice: amount,
46
- currencyCode: "USD",
47
- countryCode: "US"
48
- };
49
- }
50
- function initDropInActions() {
51
- if (instance.isPaymentMethodRequestable()) {
52
- paymentMethodRequestable.value = true;
53
- }
54
- instance.on("paymentMethodRequestable", (event) => {
55
- paymentMethodRequestable.value = true;
56
- });
57
- instance.on("noPaymentMethodRequestable", () => {
58
- paymentMethodRequestable.value = false;
59
- });
60
- }
61
- async function initDropIn({
62
- amount,
63
- authToken,
64
- container,
65
- googlePayMerchantId,
66
- paymentTypes = [...defaultPaymentTypes],
67
- preselectVaultedPaymentMethod = true,
68
- paypalFlow = "checkout"
69
- }) {
70
- formattedAmount = numeral(amount).format("0.00");
71
- const { default: DropIn } = await import("braintree-web-drop-in");
72
- try {
73
- instance = await DropIn.create({
74
- authorization: authToken,
75
- container,
76
- dataCollector: {
77
- kount: true
78
- // Required if Kount fraud data collection is enabled
79
- },
80
- // vaultManager: true, - Useful for testing and removing payment methods easily.
81
- paymentOptionPriority: paymentTypes,
82
- preselectVaultedPaymentMethod,
83
- card: {
84
- vault: {
85
- allowVaultCardOverride: true
86
- }
87
- },
88
- paypal: {
89
- flow: paypalFlow,
90
- amount: formattedAmount,
91
- currency: "USD",
92
- buttonStyle: {
93
- // @ts-ignore
94
- color: "gold",
95
- // @ts-ignore
96
- shape: "rect",
97
- // @ts-ignore
98
- size: "responsive"
99
- }
100
- },
101
- googlePay: {
102
- googlePayVersion: 2,
103
- merchantId: googlePayMerchantId,
104
- transactionInfo: getGoogleTransactionInfo(formattedAmount),
105
- button: {
106
- allowedPaymentMethods: [{
107
- type: "CARD",
108
- // @ts-ignore
109
- parameters: {
110
- // allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'], // TODO: confirm/update
111
- // allowedCardNetworks: ['AMEX', 'DISCOVER', 'INTERAC', 'JCB', 'MASTERCARD', 'VISA'], // TODO: confirm/update
112
- billingAddressRequired: true,
113
- billingAddressParameters: {
114
- format: "FULL"
115
- }
116
- }
117
- }]
118
- }
119
- },
120
- applePay: {
121
- displayName: "Kiva",
122
- paymentRequest: getApplePaymentRequest(formattedAmount)
123
- }
124
- });
125
- initDropInActions();
126
- } catch (e) {
127
- throw new ShopError({
128
- code: "shop.braintreeDropinInitError",
129
- original: e
130
- }, "An Error has occured. Please refresh the page and try again.");
131
- }
132
- return instance;
133
- }
134
- async function requestPaymentMethod() {
135
- if (instance.isPaymentMethodRequestable()) {
136
- return instance.requestPaymentMethod();
137
- }
138
- }
139
- function updateAmount(amount) {
140
- const newAmount = numeral(amount).format("0.00");
141
- if (newAmount !== formattedAmount) {
142
- formattedAmount = newAmount;
143
- instance?.updateConfiguration("paypal", "amount", formattedAmount);
144
- instance?.updateConfiguration("googlePay", "transactionInfo", getGoogleTransactionInfo(formattedAmount));
145
- instance?.updateConfiguration?.("applePay", "paymentRequest", getApplePaymentRequest(formattedAmount));
146
- }
147
- }
148
- return {
149
- initDropIn,
150
- paymentMethodRequestable,
151
- requestPaymentMethod,
152
- updateAmount
153
- };
154
- }
155
- var instances = {};
156
- function useBraintreeDropIn(key = "default") {
157
- if (!instances[key]) {
158
- instances[key] = initBraintreeDropin();
159
- }
160
- return instances[key];
161
- }
162
-
163
- export {
164
- defaultPaymentTypes,
165
- getClientToken,
166
- useBraintreeDropIn
167
- };
@@ -1,34 +0,0 @@
1
- import {
2
- callShopMutation
3
- } from "./chunk-IOZ5ERDX.js";
4
-
5
- // src/basketItems.ts
6
- import { gql } from "@apollo/client/core/core.cjs";
7
- import numeral from "numeral";
8
- async function setTipDonation({ amount, apollo, metadata }) {
9
- const donationAmount = numeral(amount).format("0.00");
10
- const data = await callShopMutation(apollo, {
11
- awaitRefetchQueries: true,
12
- mutation: gql`mutation setTipDonation($price: Money!, $basketId: String, $metadata: String) {
13
- shop (basketId: $basketId) {
14
- id
15
- updateDonation (donation: {
16
- price: $price,
17
- isTip: true,
18
- metadata: $metadata,
19
- })
20
- {
21
- id
22
- price
23
- isTip
24
- }
25
- }
26
- }`,
27
- variables: { price: donationAmount, metadata }
28
- });
29
- return data?.shop?.updateDonation;
30
- }
31
-
32
- export {
33
- setTipDonation
34
- };