@guestyorg/tokenization-js 1.0.4 → 1.1.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.
package/README.md CHANGED
@@ -41,6 +41,7 @@ Import the `loadScript` function for asynchronously loading the Guesty Tokenizat
41
41
  #### options
42
42
 
43
43
  - `sandbox` - load the SDK in a sandbox mode
44
+ - `version` - SDK version to load (default: `v1`)
44
45
 
45
46
  ```js
46
47
  loadScript({ sandbox: true });
@@ -17,14 +17,16 @@ var injectScriptElement = function (_a) {
17
17
  };
18
18
 
19
19
  var NAMESPACE = 'guestyTokenization';
20
- var SCRIPT_URL = 'https://pay.guesty.com/tokenization/v1/init.js';
21
20
 
22
21
  var loadScript = function (options) {
22
+ var _a;
23
23
  if (options === void 0) { options = {}; }
24
24
  if (typeof window === 'undefined') {
25
25
  return Promise.resolve(null);
26
26
  }
27
- var existingScript = findScriptElement(SCRIPT_URL);
27
+ var version = (_a = options.version) !== null && _a !== void 0 ? _a : 'v1';
28
+ var scriptUrl = "https://pay.guesty.com/tokenization/".concat(version, "/init.js");
29
+ var existingScript = findScriptElement(scriptUrl);
28
30
  var existingNamespace = window[NAMESPACE];
29
31
  if (existingScript) {
30
32
  if (existingNamespace) {
@@ -35,7 +37,7 @@ var loadScript = function (options) {
35
37
  return new Promise(function (resolve, reject) {
36
38
  var _a;
37
39
  injectScriptElement({
38
- url: SCRIPT_URL,
40
+ url: scriptUrl,
39
41
  sandbox: (_a = options.sandbox) !== null && _a !== void 0 ? _a : false,
40
42
  onSuccess: function () {
41
43
  var newNamespace = window[NAMESPACE];
@@ -47,7 +49,7 @@ var loadScript = function (options) {
47
49
  }
48
50
  },
49
51
  onError: function () {
50
- reject(new Error("The script ".concat(SCRIPT_URL, " failed to load")));
52
+ reject(new Error("The script ".concat(scriptUrl, " failed to load")));
51
53
  },
52
54
  });
53
55
  });
@@ -1 +1 @@
1
- "use strict";var e="guestyTokenization",o="https://pay.guesty.com/tokenization/v1/init.js";exports.loadScript=function(n){if(void 0===n&&(n={}),"undefined"==typeof window)return Promise.resolve(null);var r,t=(r=o,document.querySelector('script[src="'.concat(r,'"]'))),i=window[e];if(t){if(i)return Promise.resolve(i);t.remove()}return new Promise((function(r,t){var i;!function(e){var o=e.url,n=e.sandbox,r=e.onSuccess,t=e.onError,i=document.createElement("script");i.src=o,i.async=!0,i.onerror=t,i.onload=r,n&&i.setAttribute("data-env","sandbox"),document.head.insertBefore(i,document.head.firstElementChild)}({url:o,sandbox:null!==(i=n.sandbox)&&void 0!==i&&i,onSuccess:function(){var o=window[e];o?r(o):t(new Error("Guesty Tokenization is not available"))},onError:function(){t(new Error("The script ".concat(o," failed to load")))}})}))};
1
+ "use strict";var o="guestyTokenization";exports.loadScript=function(n){var e;if(void 0===n&&(n={}),"undefined"==typeof window)return Promise.resolve(null);var r,t=null!==(e=n.version)&&void 0!==e?e:"v1",i="https://pay.guesty.com/tokenization/".concat(t,"/init.js"),s=(r=i,document.querySelector('script[src="'.concat(r,'"]'))),a=window[o];if(s){if(a)return Promise.resolve(a);s.remove()}return new Promise((function(e,r){var t;!function(o){var n=o.url,e=o.sandbox,r=o.onSuccess,t=o.onError,i=document.createElement("script");i.src=n,i.async=!0,i.onerror=t,i.onload=r,e&&i.setAttribute("data-env","sandbox"),document.head.insertBefore(i,document.head.firstElementChild)}({url:i,sandbox:null!==(t=n.sandbox)&&void 0!==t&&t,onSuccess:function(){var n=window[o];n?e(n):r(new Error("Guesty Tokenization is not available"))},onError:function(){r(new Error("The script ".concat(i," failed to load")))}})}))};
@@ -1,3 +1,2 @@
1
1
  export declare const NAMESPACE = "guestyTokenization";
2
- export declare const SCRIPT_URL = "https://pay.guesty.com/tokenization/v1/init.js";
3
2
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,uBAAuB,CAAC;AAC9C,eAAO,MAAM,UAAU,mDAAmD,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,uBAAuB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/loadScript.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,eAAO,MAAM,UAAU,aAAa,iBAAiB,qBAgCpD,CAAC"}
1
+ {"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/loadScript.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,eAAO,MAAM,UAAU,aAAa,iBAAiB,qBAmCpD,CAAC"}
@@ -15,14 +15,16 @@ var injectScriptElement = function (_a) {
15
15
  };
16
16
 
17
17
  var NAMESPACE = 'guestyTokenization';
18
- var SCRIPT_URL = 'https://pay.guesty.com/tokenization/v1/init.js';
19
18
 
20
19
  var loadScript = function (options) {
20
+ var _a;
21
21
  if (options === void 0) { options = {}; }
22
22
  if (typeof window === 'undefined') {
23
23
  return Promise.resolve(null);
24
24
  }
25
- var existingScript = findScriptElement(SCRIPT_URL);
25
+ var version = (_a = options.version) !== null && _a !== void 0 ? _a : 'v1';
26
+ var scriptUrl = "https://pay.guesty.com/tokenization/".concat(version, "/init.js");
27
+ var existingScript = findScriptElement(scriptUrl);
26
28
  var existingNamespace = window[NAMESPACE];
27
29
  if (existingScript) {
28
30
  if (existingNamespace) {
@@ -33,7 +35,7 @@ var loadScript = function (options) {
33
35
  return new Promise(function (resolve, reject) {
34
36
  var _a;
35
37
  injectScriptElement({
36
- url: SCRIPT_URL,
38
+ url: scriptUrl,
37
39
  sandbox: (_a = options.sandbox) !== null && _a !== void 0 ? _a : false,
38
40
  onSuccess: function () {
39
41
  var newNamespace = window[NAMESPACE];
@@ -45,7 +47,7 @@ var loadScript = function (options) {
45
47
  }
46
48
  },
47
49
  onError: function () {
48
- reject(new Error("The script ".concat(SCRIPT_URL, " failed to load")));
50
+ reject(new Error("The script ".concat(scriptUrl, " failed to load")));
49
51
  },
50
52
  });
51
53
  });
@@ -1 +1 @@
1
- var e="guestyTokenization",n="https://pay.guesty.com/tokenization/v1/init.js",o=function(o){if(void 0===o&&(o={}),"undefined"==typeof window)return Promise.resolve(null);var r,t=(r=n,document.querySelector('script[src="'.concat(r,'"]'))),i=window[e];if(t){if(i)return Promise.resolve(i);t.remove()}return new Promise((function(r,t){var i;!function(e){var n=e.url,o=e.sandbox,r=e.onSuccess,t=e.onError,i=document.createElement("script");i.src=n,i.async=!0,i.onerror=t,i.onload=r,o&&i.setAttribute("data-env","sandbox"),document.head.insertBefore(i,document.head.firstElementChild)}({url:n,sandbox:null!==(i=o.sandbox)&&void 0!==i&&i,onSuccess:function(){var n=window[e];n?r(n):t(new Error("Guesty Tokenization is not available"))},onError:function(){t(new Error("The script ".concat(n," failed to load")))}})}))};export{o as loadScript};
1
+ var n="guestyTokenization",o=function(o){var e;if(void 0===o&&(o={}),"undefined"==typeof window)return Promise.resolve(null);var r,t=null!==(e=o.version)&&void 0!==e?e:"v1",i="https://pay.guesty.com/tokenization/".concat(t,"/init.js"),a=(r=i,document.querySelector('script[src="'.concat(r,'"]'))),s=window[n];if(a){if(s)return Promise.resolve(s);a.remove()}return new Promise((function(e,r){var t;!function(n){var o=n.url,e=n.sandbox,r=n.onSuccess,t=n.onError,i=document.createElement("script");i.src=o,i.async=!0,i.onerror=t,i.onload=r,e&&i.setAttribute("data-env","sandbox"),document.head.insertBefore(i,document.head.firstElementChild)}({url:i,sandbox:null!==(t=o.sandbox)&&void 0!==t&&t,onSuccess:function(){var o=window[n];o?e(o):r(new Error("Guesty Tokenization is not available"))},onError:function(){r(new Error("The script ".concat(i," failed to load")))}})}))};export{o as loadScript};
@@ -1,3 +1,2 @@
1
1
  export declare const NAMESPACE = "guestyTokenization";
2
- export declare const SCRIPT_URL = "https://pay.guesty.com/tokenization/v1/init.js";
3
2
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,uBAAuB,CAAC;AAC9C,eAAO,MAAM,UAAU,mDAAmD,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,uBAAuB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/loadScript.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,eAAO,MAAM,UAAU,aAAa,iBAAiB,qBAgCpD,CAAC"}
1
+ {"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/loadScript.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,eAAO,MAAM,UAAU,aAAa,iBAAiB,qBAmCpD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guestyorg/tokenization-js",
3
- "version": "1.0.4",
3
+ "version": "1.1.1",
4
4
  "description": "Guesty Tokenization SDK loading utility and types",
5
5
  "main": "index.js",
6
6
  "module": "lib/esm/guesty-tokenization-js.js",
package/types/index.d.ts CHANGED
@@ -30,7 +30,7 @@ type TInput =
30
30
  | TBillingAddressInput
31
31
  | TPaymentDetailsInput;
32
32
 
33
- export interface GuestyTokenizationRenderOptions {
33
+ export interface GuestyTokenizationV1RenderOptions {
34
34
  containerId: string;
35
35
  providerId: string;
36
36
  amount: number;
@@ -54,27 +54,103 @@ export interface GuestyTokenizationRenderOptions {
54
54
  };
55
55
  }
56
56
 
57
+ export interface GuestyTokenizationV2RenderOptions {
58
+ containerId: string;
59
+ providerId: string;
60
+ onStatusChange?: (status: boolean) => void;
61
+ styles?: GuestyTokenizationStyles;
62
+ lang?: string;
63
+ initialValues?: {
64
+ firstName?: string;
65
+ lastName?: string;
66
+ street?: string;
67
+ city?: string;
68
+ state?: string;
69
+ zipCode?: string;
70
+ country?: string;
71
+ };
72
+ showInitialValuesToggle?: boolean;
73
+ initialValuesToggleLabel?: string;
74
+ sections?: Section[];
75
+ showSupportedCards?: boolean;
76
+ showPciCompliantLink?: boolean;
77
+ }
78
+
79
+ export interface GuestyTokenizationV2ApiV2SubmitPayload {
80
+ amount: number;
81
+ currency: string;
82
+ apiVersion: 'v2';
83
+ }
84
+
85
+ type ReservationOrQuote =
86
+ | {
87
+ reservationId: string;
88
+ quoteId?: never;
89
+ guest?: never;
90
+ }
91
+ | {
92
+ quoteId: string;
93
+ guest: {
94
+ firstName: string;
95
+ lastName: string;
96
+ email?: string;
97
+ phone?: string;
98
+ };
99
+ reservationId?: never;
100
+ };
101
+
102
+ export type GuestyTokenizationV2ApiV3SubmitPayload = {
103
+ listingId: string;
104
+ amount: number;
105
+ currency: string;
106
+ apiVersion?: 'v3';
107
+ } & ReservationOrQuote;
108
+
109
+ export type GuestyTokenizationV2SubmitPayload =
110
+ | GuestyTokenizationV2ApiV2SubmitPayload
111
+ | GuestyTokenizationV2ApiV3SubmitPayload;
112
+
57
113
  export interface PaymentMethod {
58
114
  _id: string;
59
115
  }
60
116
 
61
- export interface GuestyTokenizationNamespace {
62
- render: (options: GuestyTokenizationRenderOptions) => Promise<void>;
117
+ export interface GuestyTokenizationV1Namespace {
118
+ render: (options: GuestyTokenizationV1RenderOptions) => Promise<void>;
63
119
  destroy: () => Promise<void>;
64
120
  submit: () => Promise<PaymentMethod>;
65
121
  validate: () => void;
66
122
  }
67
123
 
124
+ export interface GuestyTokenizationV2Namespace {
125
+ render: (options: GuestyTokenizationV2RenderOptions) => Promise<void>;
126
+ destroy: () => Promise<void>;
127
+ submit: (
128
+ payload: GuestyTokenizationV2SubmitPayload
129
+ ) => Promise<PaymentMethod>;
130
+ validate: () => void;
131
+ }
132
+
68
133
  export interface LoadScriptOptions {
69
134
  sandbox?: boolean;
135
+ version?: 'v1' | 'v2';
70
136
  }
71
137
 
72
- export function loadScript(
73
- options?: LoadScriptOptions
74
- ): Promise<GuestyTokenizationNamespace | null>;
138
+ type NamespaceBasedOnVersion<T extends LoadScriptOptions['version']> =
139
+ T extends 'v1'
140
+ ? GuestyTokenizationV1Namespace
141
+ : T extends 'v2'
142
+ ? GuestyTokenizationV2Namespace
143
+ : never;
144
+
145
+ export function loadScript<T extends LoadScriptOptions['version']>(
146
+ options?: LoadScriptOptions & { version: T }
147
+ ): Promise<NamespaceBasedOnVersion<T> | null>;
75
148
 
76
149
  declare global {
77
150
  interface Window {
78
- guestyTokenization?: GuestyTokenizationNamespace | null;
151
+ guestyTokenization?:
152
+ | GuestyTokenizationV1Namespace
153
+ | GuestyTokenizationV2Namespace
154
+ | null;
79
155
  }
80
156
  }