swell-js 5.9.3 → 5.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swell-js",
3
- "version": "5.9.3",
3
+ "version": "5.10.0",
4
4
  "description": "Swell JS library for client-side stores",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -0,0 +1,17 @@
1
+ import type { ConvertSnakeToCamelCase } from '../index.js';
2
+ import type { Replace } from '../utils.js';
3
+
4
+ import type { Consent, ConsentEffective, ConsentInput } from './snake.js';
5
+
6
+ export type ConsentInputCamel = ConvertSnakeToCamelCase<ConsentInput>;
7
+
8
+ export type ConsentEffectiveCamel = ConvertSnakeToCamelCase<ConsentEffective>;
9
+
10
+ export type ConsentCamel = ConvertSnakeToCamelCase<
11
+ Replace<
12
+ Consent,
13
+ {
14
+ effective: ConsentEffectiveCamel;
15
+ }
16
+ >
17
+ >;
@@ -0,0 +1,21 @@
1
+ import type { MakeCase } from '../utils.js';
2
+
3
+ import type { Consent, ConsentEffective, ConsentInput } from './snake.js';
4
+ import type {
5
+ ConsentCamel,
6
+ ConsentEffectiveCamel,
7
+ ConsentInputCamel,
8
+ } from './camel.js';
9
+
10
+ export type ConsentCase = MakeCase<Consent, ConsentCamel>;
11
+
12
+ export type ConsentInputCase = MakeCase<ConsentInput, ConsentInputCamel>;
13
+
14
+ export type {
15
+ Consent,
16
+ ConsentEffective,
17
+ ConsentInput,
18
+ ConsentCamel,
19
+ ConsentEffectiveCamel,
20
+ ConsentInputCamel,
21
+ };
@@ -0,0 +1,22 @@
1
+ /** The shopper's answers; purposes left out stay as they are */
2
+ export interface ConsentInput {
3
+ analytics?: boolean;
4
+ marketing?: boolean;
5
+ sale_of_data?: boolean;
6
+ }
7
+
8
+ /** What the answers allow, after the region's rule and GPC */
9
+ export interface ConsentEffective {
10
+ analytics: boolean;
11
+ marketing: boolean;
12
+ sale_of_data: boolean;
13
+ }
14
+
15
+ export interface Consent {
16
+ analytics: boolean | null;
17
+ marketing: boolean | null;
18
+ sale_of_data: boolean | null;
19
+ gpc: boolean;
20
+ rule: 'opt_in' | 'opt_out' | null;
21
+ effective: ConsentEffective;
22
+ }
package/types/index.d.cts CHANGED
@@ -82,6 +82,14 @@ declare namespace swell {
82
82
  export type CategoryCase = import('./index.js', { with: { 'resolution-mode': 'import' } }).CategoryCase;
83
83
  export type Category = import('./index.js', { with: { 'resolution-mode': 'import' } }).Category;
84
84
  export type CategoryCamel = import('./index.js', { with: { 'resolution-mode': 'import' } }).CategoryCamel;
85
+ export type ConsentCase = import('./index.js', { with: { 'resolution-mode': 'import' } }).ConsentCase;
86
+ export type ConsentInputCase = import('./index.js', { with: { 'resolution-mode': 'import' } }).ConsentInputCase;
87
+ export type Consent = import('./index.js', { with: { 'resolution-mode': 'import' } }).Consent;
88
+ export type ConsentEffective = import('./index.js', { with: { 'resolution-mode': 'import' } }).ConsentEffective;
89
+ export type ConsentInput = import('./index.js', { with: { 'resolution-mode': 'import' } }).ConsentInput;
90
+ export type ConsentCamel = import('./index.js', { with: { 'resolution-mode': 'import' } }).ConsentCamel;
91
+ export type ConsentEffectiveCamel = import('./index.js', { with: { 'resolution-mode': 'import' } }).ConsentEffectiveCamel;
92
+ export type ConsentInputCamel = import('./index.js', { with: { 'resolution-mode': 'import' } }).ConsentInputCamel;
85
93
  export type ContentCase = import('./index.js', { with: { 'resolution-mode': 'import' } }).ContentCase;
86
94
  export type ContentSectionCase = import('./index.js', { with: { 'resolution-mode': 'import' } }).ContentSectionCase;
87
95
  export type ContentPageCase = import('./index.js', { with: { 'resolution-mode': 'import' } }).ContentPageCase;
@@ -139,12 +147,14 @@ declare namespace swell {
139
147
  export type OrderShippingCamel = import('./index.js', { with: { 'resolution-mode': 'import' } }).OrderShippingCamel;
140
148
  export type PaymentCase = import('./index.js', { with: { 'resolution-mode': 'import' } }).PaymentCase;
141
149
  export type InputPaymentElementBase = import('./index.js', { with: { 'resolution-mode': 'import' } }).InputPaymentElementBase;
150
+ export type InputPaymentStripePaymentElement = import('./index.js', { with: { 'resolution-mode': 'import' } }).InputPaymentStripePaymentElement;
142
151
  export type InputPaymentElementCard = import('./index.js', { with: { 'resolution-mode': 'import' } }).InputPaymentElementCard;
143
152
  export type InputPaymentElementIdeal = import('./index.js', { with: { 'resolution-mode': 'import' } }).InputPaymentElementIdeal;
144
153
  export type InputPaymentElementPaypal = import('./index.js', { with: { 'resolution-mode': 'import' } }).InputPaymentElementPaypal;
145
154
  export type InputPaymentElementApple = import('./index.js', { with: { 'resolution-mode': 'import' } }).InputPaymentElementApple;
146
155
  export type InputPaymentElementGoogle = import('./index.js', { with: { 'resolution-mode': 'import' } }).InputPaymentElementGoogle;
147
156
  export type InputPaymentElementSezzle = import('./index.js', { with: { 'resolution-mode': 'import' } }).InputPaymentElementSezzle;
157
+ export type InputPaymentTokenizeCard = import('./index.js', { with: { 'resolution-mode': 'import' } }).InputPaymentTokenizeCard;
148
158
  export type InputPaymentRedirect = import('./index.js', { with: { 'resolution-mode': 'import' } }).InputPaymentRedirect;
149
159
  export type Payment = import('./index.js', { with: { 'resolution-mode': 'import' } }).Payment;
150
160
  export type PaymentCamel = import('./index.js', { with: { 'resolution-mode': 'import' } }).PaymentCamel;
package/types/index.d.ts CHANGED
@@ -17,6 +17,7 @@ import type {
17
17
  } from './card/index.js';
18
18
  import type { CartCase, CartItemCase } from './cart/index.js';
19
19
  import type { CategoryCase } from './category/index.js';
20
+ import type { ConsentCase, ConsentInputCase } from './consent/index.js';
20
21
  import type { ContentCase } from './content/index.js';
21
22
  import type {
22
23
  SelectCurrencyReturnCase,
@@ -40,6 +41,7 @@ import type {
40
41
  InputPaymentElementApple,
41
42
  InputPaymentElementSezzle,
42
43
  InputPaymentRedirect,
44
+ InputPaymentTokenizeCard,
43
45
  PaymentCase,
44
46
  } from './payment/index.js';
45
47
 
@@ -53,6 +55,7 @@ export type * from './billing/index.js';
53
55
  export type * from './card/index.js';
54
56
  export type * from './cart/index.js';
55
57
  export type * from './category/index.js';
58
+ export type * from './consent/index.js';
56
59
  export type * from './content/index.js';
57
60
  export type * from './coupon/index.js';
58
61
  export type * from './currency/index.js';
@@ -374,24 +377,36 @@ export interface SwellClient<C extends 'snake' | 'camel' = 'snake'> {
374
377
  }): Promise<void>;
375
378
 
376
379
  tokenize(input?: {
377
- card?: object;
380
+ card?: InputPaymentTokenizeCard;
381
+ /** Without `createElements` iDEAL needs no element: the shopper picks the bank on the iDEAL page */
378
382
  ideal?: object;
379
383
  klarna?: object;
380
384
  bancontact?: object;
381
385
  paysafecard?: object;
382
386
  amazon?: object;
387
+ /** Saferpay payment page; has no element, `tokenize` redirects */
388
+ twint?: InputPaymentRedirect;
383
389
  }): Promise<void>;
384
390
 
385
391
  handleRedirect(input?: {
386
392
  card?: InputPaymentRedirect;
393
+ ideal?: InputPaymentRedirect;
387
394
  paysafecard?: InputPaymentRedirect;
388
395
  klarna?: InputPaymentRedirect;
389
396
  bancontact?: InputPaymentRedirect;
397
+ amazon?: InputPaymentRedirect;
398
+ twint?: InputPaymentRedirect;
390
399
  }): Promise<void>;
391
400
 
392
401
  authenticate(id: string): Promise<object | { error: Error }>;
393
402
  resetAsyncPayment(id: string): Promise<object>;
394
403
 
404
+ /**
405
+ * Redirects to the gateway when a submitted order waits for an
406
+ * asynchronous payment; resolves `true` after starting the redirect
407
+ */
408
+ handleAsyncRedirect(order: object): Promise<boolean>;
409
+
395
410
  createIntent(input: { gateway: string; intent: object }): Promise<object>;
396
411
 
397
412
  updateIntent(input: { gateway: string; intent: object }): Promise<object>;
@@ -499,6 +514,15 @@ export interface SwellClient<C extends 'snake' | 'camel' = 'snake'> {
499
514
  setCookie(value: string): void;
500
515
  };
501
516
 
517
+ consent: {
518
+ /**
519
+ * Records the shopper's consent for attribution. Call it from the
520
+ * storefront's consent banner; purposes left out stay as they are.
521
+ * Browser only: it calls the storefront's own origin.
522
+ */
523
+ set(consent?: ConsentInputCase[C]): Promise<ConsentCase[C]>;
524
+ };
525
+
502
526
  functions: {
503
527
  request<T>(
504
528
  method: string,
@@ -27,8 +27,28 @@ export interface InputPaymentElementBase {
27
27
  onError?: (error: Error) => void;
28
28
  }
29
29
 
30
- export interface InputPaymentElementCard extends InputPaymentElementBase {
31
- /** @see {@link https://docs.stripe.com/js/elements_object/create_element?type=card#elements_create-options} */
30
+ /**
31
+ * Stripe: draw the form with the Payment Element instead of the split elements.
32
+ * The element mounts into `#payment-element` unless `elementId` is set.
33
+ */
34
+ export interface InputPaymentStripePaymentElement {
35
+ paymentElement?: boolean;
36
+ /**
37
+ * Payment Element only: Stripe Appearance API object (`theme`, `variables`, `rules`, `labels`).
38
+ *
39
+ * @see {@link https://docs.stripe.com/elements/appearance-api}
40
+ */
41
+ appearance?: Record<string, unknown>;
42
+ }
43
+
44
+ export interface InputPaymentElementCard
45
+ extends InputPaymentElementBase,
46
+ InputPaymentStripePaymentElement {
47
+ /**
48
+ * Split elements: {@link https://docs.stripe.com/js/elements_object/create_element?type=card#elements_create-options}.
49
+ * Payment Element: {@link https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options},
50
+ * merged over `{ layout: 'tabs', fields: { billingDetails: 'never' }, wallets: { applePay: 'never', googlePay: 'never' } }`.
51
+ */
32
52
  options?: object;
33
53
  separateElements?: boolean;
34
54
  cardNumber?: {
@@ -47,9 +67,13 @@ export interface InputPaymentElementCard extends InputPaymentElementBase {
47
67
  };
48
68
  }
49
69
 
50
- export interface InputPaymentElementIdeal extends InputPaymentElementBase {
70
+ export interface InputPaymentElementIdeal
71
+ extends InputPaymentElementBase,
72
+ InputPaymentStripePaymentElement {
73
+ /** Payment Element: the same options and defaults as the card one */
51
74
  options?: {
52
75
  style?: unknown;
76
+ [key: string]: unknown;
53
77
  };
54
78
  }
55
79
 
@@ -127,6 +151,21 @@ export interface InputPaymentElementSezzle extends InputPaymentElementBase {
127
151
  };
128
152
  }
129
153
 
154
+ export interface InputPaymentTokenizeCard
155
+ extends InputPaymentRedirect,
156
+ Pick<InputPaymentStripePaymentElement, 'paymentElement'> {
157
+ /** Stripe: `false` stores the card without a payment intent (default `true`) */
158
+ createIntent?: boolean;
159
+ /**
160
+ * Stripe: the `pm_` id of a card the shopper already has (a saved card, a
161
+ * wallet's payment method), authorized with an intent and 3-D Secure instead
162
+ * of an element's card
163
+ */
164
+ paymentMethod?: string;
165
+ /** Saferpay: register a new card even when the cart already has one */
166
+ replace?: boolean;
167
+ }
168
+
130
169
  export interface InputPaymentRedirect {
131
170
  /** @optional called on card payment success */
132
171
  onSuccess?: (event: unknown) => void;