@guestyorg/tokenization-js 1.0.0-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/LICENSE.md ADDED
@@ -0,0 +1,35 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Guesty Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
11
+ Disclaimer Regarding Non-Compliance with Assimilation Instructions
12
+
13
+ In accordance with the terms of the MIT License, users and advertisers are granted permission to use, modify, and distribute this software. However, the following disclaimer shall apply:
14
+
15
+ - The original authors and copyright holders of this software are not responsible for any non-compliance with the assimilation instructions provided in the documentation or any associated materials. Users, advertisers, and third parties who choose to use, modify, or distribute this software are solely responsible for ensuring compliance with any assimilation, attribution, or other requirements outlined in the documentation.
16
+
17
+ - By using, modifying, or distributing this software, you acknowledge and agree that the responsibility for adhering to any assimilation instructions lies with the user, advertiser, or third party, and any consequences resulting from non-compliance are the sole responsibility of those parties.
18
+
19
+ This disclaimer is in addition to, and does not supersede the terms and conditions outlined in the MIT License, which governs the use, modification, and distribution of this Software.
20
+
21
+ User Responsibility Regarding Data Collection
22
+
23
+ This Software may collect and process data. By using, modifying, or distributing the Software, you agree to the following:
24
+
25
+ 1. Data Handling: You are solely responsible for understanding and complying with any data collection, storage, and processing practices outlined in the documentation or associated materials. This includes but is not limited to ensuring that any data collected complies with applicable data protection and privacy laws and regulations.
26
+
27
+ 2. Data Security: You are responsible for implementing appropriate security measures to protect any data collected through the use of this Software. This includes safeguarding data against unauthorized access, disclosure, or modification.
28
+
29
+ 3. Data Consent: If this Software collects personally identifiable information or sensitive data, you must obtain appropriate consent from individuals whose data is collected, and you must adhere to any applicable consent requirements and data subject rights.
30
+
31
+ 4. Data Ownership: Any data collected and processed by this software remains the property of the individuals or entities to whom it pertains. You do not acquire ownership rights to the data by using this Software.
32
+
33
+ 5. No Liability: The original authors and copyright holders of this software are not liable for any issues, damages, or legal obligations related to the data collected or processed through the use of this software. You assume full responsibility for any data-related matters.
34
+
35
+ This clause is in addition to, and does not supersede, the terms and conditions outlined in the MIT License, which govern the use, modification, and distribution of this Software.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # [Guesty Tokenization JS SDK](https://github.com/guestyorg/tokenization-js/wiki)
2
+
3
+ There are two ways to integrate the SDK:
4
+
5
+ ### Manually include a script tag
6
+
7
+ Add a script tag to your application `head` or `body`.
8
+ This loads `guestyTokenization` object to the global `window` scope of the browser
9
+
10
+ ```html
11
+ <script src="https://pay.guesty.com/tokenization/v1/init.js"></script>
12
+ ```
13
+
14
+ #### Note: To be PCI-compliant, you must load the SDK directly from https://pay.guesty.com. You cannot include it in a bundle or host it yourself
15
+
16
+ ### Use it as an ES module
17
+
18
+ Advantages of loading the SDK as a module:
19
+
20
+ - loads script asynchronously to ensure page rendering isn't blocked
21
+ - returns a Promise to know when script loading is complete
22
+ - resolves to `null` if called in a server environment
23
+
24
+ ## Installation
25
+
26
+ Use `npm` to install the Guesty Tokenization JS module:
27
+
28
+ ```sh
29
+ npm install @guestyorg/tokenization-js
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ Import the `loadScript` function for asynchronously loading the Guesty Tokenization JS SDK
35
+
36
+ ### loadScript(options?)
37
+
38
+ - accepts an `options` object to configure script URL and attributes
39
+ - returns a Promise that resolves with `window.guestyTokenization` after the SDK is finished loading
40
+
41
+ #### options
42
+
43
+ - `sandbox` - load the SDK in a sandbox mode
44
+
45
+ ```js
46
+ loadScript({ sandbox: true });
47
+ ```
48
+
49
+ This is equivalent to the following script:
50
+
51
+ ```html
52
+ <script
53
+ src="https://pay.guesty.com/tokenization/v1/init.js"
54
+ data-env="sandbox"
55
+ ></script>
56
+ ```
57
+
58
+ #### Async/Await
59
+
60
+ ```js
61
+ import { loadScript } from '@guesty/tokenization-js';
62
+
63
+ try {
64
+ const guestyTokenization = await loadScript();
65
+ // Guesty Tokenization JS SDK is loaded and ready to use
66
+ } catch (error) {
67
+ console.error('Failed to load the Guesty Tokenization JS SDK script', error);
68
+ }
69
+ ```
70
+
71
+ #### Promises
72
+
73
+ ```js
74
+ import { loadScript } from '@guesty/tokenization-js';
75
+
76
+ loadScript()
77
+ .then((guestyTokenization) => {
78
+ // Guesty Tokenization JS SDK is loaded and ready to use
79
+ })
80
+ .catch((error) => {
81
+ console.error(
82
+ 'Failed to load the Guesty Tokenization JS SDK script',
83
+ error
84
+ );
85
+ });
86
+ ```
87
+
88
+ ## TypeScript Support
89
+
90
+ This package includes TypeScript type definitions for the Guesty Tokenization JS SDK. This includes types for the `window.guestyTokenization` namespace. We support projects using TypeScript versions >= 3.8.
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ if (process.env.NODE_ENV === 'production') {
2
+ module.exports = require('./lib/cjs/guesty-tokenization-js.min.js');
3
+ } else {
4
+ module.exports = require('./lib/cjs/guesty-tokenization-js.js');
5
+ }
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ var findScriptElement = function (url) {
4
+ return document.querySelector("script[src=\"".concat(url, "\"]"));
5
+ };
6
+ var injectScriptElement = function (_a) {
7
+ var url = _a.url, sandbox = _a.sandbox, onSuccess = _a.onSuccess, onError = _a.onError;
8
+ var script = document.createElement('script');
9
+ script.src = url;
10
+ script.async = true;
11
+ script.onerror = onError;
12
+ script.onload = onSuccess;
13
+ if (sandbox) {
14
+ script.setAttribute('data-env', 'sandbox');
15
+ }
16
+ document.head.insertBefore(script, document.head.firstElementChild);
17
+ };
18
+
19
+ var NAMESPACE = 'guestyTokenization';
20
+ var SCRIPT_URL = 'https://pay.guesty.com/tokenization/v1/init.js';
21
+
22
+ var loadScript = function (options) {
23
+ if (options === void 0) { options = {}; }
24
+ if (typeof window === 'undefined') {
25
+ return Promise.resolve(null);
26
+ }
27
+ var existingScript = findScriptElement(SCRIPT_URL);
28
+ var existingNamespace = window[NAMESPACE];
29
+ if (existingScript) {
30
+ if (existingNamespace) {
31
+ return Promise.resolve(existingNamespace);
32
+ }
33
+ existingScript.remove();
34
+ }
35
+ return new Promise(function (resolve, reject) {
36
+ var _a;
37
+ injectScriptElement({
38
+ url: SCRIPT_URL,
39
+ sandbox: (_a = options.sandbox) !== null && _a !== void 0 ? _a : false,
40
+ onSuccess: function () {
41
+ var newNamespace = window[NAMESPACE];
42
+ if (newNamespace) {
43
+ resolve(newNamespace);
44
+ }
45
+ else {
46
+ reject(new Error('Guesty Tokenization is not available'));
47
+ }
48
+ },
49
+ onError: function () {
50
+ reject(new Error("The script ".concat(SCRIPT_URL, " failed to load")));
51
+ },
52
+ });
53
+ });
54
+ };
55
+
56
+ exports.loadScript = loadScript;
@@ -0,0 +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")))}})}))};
@@ -0,0 +1,3 @@
1
+ export declare const NAMESPACE = "guestyTokenization";
2
+ export declare const SCRIPT_URL = "https://pay.guesty.com/tokenization/v1/init.js";
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ export * from './loadScript';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { LoadScriptOptions } from '../types';
2
+ export declare const loadScript: (options?: LoadScriptOptions) => Promise<unknown>;
3
+ //# sourceMappingURL=loadScript.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,9 @@
1
+ export declare const findScriptElement: (url: string) => Element | null;
2
+ export interface InjectScriptElementOptions {
3
+ url: string;
4
+ sandbox: boolean;
5
+ onSuccess: () => void;
6
+ onError: () => void;
7
+ }
8
+ export declare const injectScriptElement: ({ url, sandbox, onSuccess, onError, }: InjectScriptElementOptions) => void;
9
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,QAAS,MAAM,mBAE5C,CAAC;AAEF,MAAM,WAAW,0BAA0B;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,mBAAmB,0CAK7B,0BAA0B,SAY5B,CAAC"}
@@ -0,0 +1,54 @@
1
+ var findScriptElement = function (url) {
2
+ return document.querySelector("script[src=\"".concat(url, "\"]"));
3
+ };
4
+ var injectScriptElement = function (_a) {
5
+ var url = _a.url, sandbox = _a.sandbox, onSuccess = _a.onSuccess, onError = _a.onError;
6
+ var script = document.createElement('script');
7
+ script.src = url;
8
+ script.async = true;
9
+ script.onerror = onError;
10
+ script.onload = onSuccess;
11
+ if (sandbox) {
12
+ script.setAttribute('data-env', 'sandbox');
13
+ }
14
+ document.head.insertBefore(script, document.head.firstElementChild);
15
+ };
16
+
17
+ var NAMESPACE = 'guestyTokenization';
18
+ var SCRIPT_URL = 'https://pay.guesty.com/tokenization/v1/init.js';
19
+
20
+ var loadScript = function (options) {
21
+ if (options === void 0) { options = {}; }
22
+ if (typeof window === 'undefined') {
23
+ return Promise.resolve(null);
24
+ }
25
+ var existingScript = findScriptElement(SCRIPT_URL);
26
+ var existingNamespace = window[NAMESPACE];
27
+ if (existingScript) {
28
+ if (existingNamespace) {
29
+ return Promise.resolve(existingNamespace);
30
+ }
31
+ existingScript.remove();
32
+ }
33
+ return new Promise(function (resolve, reject) {
34
+ var _a;
35
+ injectScriptElement({
36
+ url: SCRIPT_URL,
37
+ sandbox: (_a = options.sandbox) !== null && _a !== void 0 ? _a : false,
38
+ onSuccess: function () {
39
+ var newNamespace = window[NAMESPACE];
40
+ if (newNamespace) {
41
+ resolve(newNamespace);
42
+ }
43
+ else {
44
+ reject(new Error('Guesty Tokenization is not available'));
45
+ }
46
+ },
47
+ onError: function () {
48
+ reject(new Error("The script ".concat(SCRIPT_URL, " failed to load")));
49
+ },
50
+ });
51
+ });
52
+ };
53
+
54
+ export { loadScript };
@@ -0,0 +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};
@@ -0,0 +1,3 @@
1
+ export declare const NAMESPACE = "guestyTokenization";
2
+ export declare const SCRIPT_URL = "https://pay.guesty.com/tokenization/v1/init.js";
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ export * from './loadScript';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { LoadScriptOptions } from '../types';
2
+ export declare const loadScript: (options?: LoadScriptOptions) => Promise<unknown>;
3
+ //# sourceMappingURL=loadScript.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,9 @@
1
+ export declare const findScriptElement: (url: string) => Element | null;
2
+ export interface InjectScriptElementOptions {
3
+ url: string;
4
+ sandbox: boolean;
5
+ onSuccess: () => void;
6
+ onError: () => void;
7
+ }
8
+ export declare const injectScriptElement: ({ url, sandbox, onSuccess, onError, }: InjectScriptElementOptions) => void;
9
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,QAAS,MAAM,mBAE5C,CAAC;AAEF,MAAM,WAAW,0BAA0B;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,mBAAmB,0CAK7B,0BAA0B,SAY5B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@guestyorg/tokenization-js",
3
+ "version": "1.0.0-0",
4
+ "description": "Guesty Tokenization SDK loading utility and types",
5
+ "main": "index.js",
6
+ "module": "lib/esm/guesty-tokenization-js.js",
7
+ "types": "types/index.d.ts",
8
+ "files": [
9
+ "lib",
10
+ "types"
11
+ ],
12
+ "scripts": {
13
+ "test": "jest --coverage --color",
14
+ "clean": "rm -rf ./lib",
15
+ "build": "yarn clean && rollup --config --bundleConfigAsCjs",
16
+ "lint": "eslint . --fix",
17
+ "prettier": "prettier **/*.{js|ts}",
18
+ "release": "np --no-publish"
19
+ },
20
+ "devDependencies": {
21
+ "@rollup/plugin-terser": "^0.4.3",
22
+ "@rollup/plugin-typescript": "^11.1.2",
23
+ "@types/jest": "^29.2.4",
24
+ "@typescript-eslint/eslint-plugin": "^5.45.1",
25
+ "@typescript-eslint/parser": "^5.45.1",
26
+ "eslint": "^8.29.0",
27
+ "eslint-config-airbnb-base": "^14.0.0",
28
+ "eslint-config-prettier": "^6.0.0",
29
+ "husky": "^4.2.3",
30
+ "jest": "^29.3.1",
31
+ "jest-environment-jsdom": "^29.3.1",
32
+ "lint-staged": "^10.0.7",
33
+ "prettier": "^2.8.0",
34
+ "rollup": "^3.28.1",
35
+ "ts-jest": "^29.0.3",
36
+ "typescript": "^4.9.3"
37
+ },
38
+ "husky": {
39
+ "hooks": {
40
+ "pre-push": "yarn lint",
41
+ "pre-commit": "lint-staged"
42
+ }
43
+ },
44
+ "lint-staged": {
45
+ "*.{js,ts,css,json,md}": [
46
+ "prettier --write",
47
+ "git add"
48
+ ],
49
+ "*.{jsx,js,ts}": [
50
+ "eslint --fix",
51
+ "git add"
52
+ ]
53
+ },
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/guestyorg/tokenization-js.git"
57
+ },
58
+ "keywords": [],
59
+ "author": "Guesty Inc.",
60
+ "license": "MIT",
61
+ "bugs": {
62
+ "url": "https://github.com/guestyorg/tokenization-js/issues"
63
+ },
64
+ "homepage": "https://github.com/guestyorg/tokenization-js/wiki",
65
+ "private": false,
66
+ "publishConfig": {
67
+ "access": "public"
68
+ }
69
+ }
@@ -0,0 +1,51 @@
1
+ export interface GuestyTokenizationStyles {
2
+ mobileBreakpoint?: number;
3
+ fontFamily?: string;
4
+ fontSizeMd?: number;
5
+ fontSizeLg?: number;
6
+ fontWeightRegular?: number;
7
+ fontWeightBold?: number;
8
+ colorText?: string;
9
+ colorTextError?: string;
10
+ colorBorder?: string;
11
+ colorBorderError?: string;
12
+ colorBorderHover?: string;
13
+ colorPlaceholder?: string;
14
+ colorBackgroundError?: string;
15
+ colorBackgroundDisabled?: string;
16
+ }
17
+
18
+ export interface GuestyTokenizationRenderOptions {
19
+ containerId: string;
20
+ providerId: string;
21
+ amount: number;
22
+ currency: string;
23
+ onStatusChange?: (status: boolean) => void;
24
+ styles?: GuestyTokenizationStyles;
25
+ lang?: string;
26
+ }
27
+
28
+ export interface PaymentMethod {
29
+ _id: string;
30
+ }
31
+
32
+ export interface GuestyTokenizationNamespace {
33
+ render: (options: GuestyTokenizationRenderOptions) => Promise<void>;
34
+ destroy: () => Promise<void>;
35
+ submit: () => Promise<PaymentMethod>;
36
+ validate: () => void;
37
+ }
38
+
39
+ export interface LoadScriptOptions {
40
+ sandbox?: boolean;
41
+ }
42
+
43
+ export function loadScript(
44
+ options?: LoadScriptOptions
45
+ ): Promise<GuestyTokenizationNamespace | null>;
46
+
47
+ declare global {
48
+ interface Window {
49
+ guestyTokenization?: GuestyTokenizationNamespace | null;
50
+ }
51
+ }