@tosspayments/tosspayments-sdk 0.1.1-alpha.0 → 0.1.1-alpha.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/dist/index.cjs.js CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var SCRIPT_URL = 'https://js.tosspayments.com/v2/standard';
6
+
7
+ function clearTossPayments() {
8
+ var _script$parentElement;
9
+
10
+ var script = document.querySelector("script[src=\"".concat(SCRIPT_URL, "\"]"));
11
+ script === null || script === void 0 ? void 0 : (_script$parentElement = script.parentElement) === null || _script$parentElement === void 0 ? void 0 : _script$parentElement.removeChild(script);
12
+ window.TossPayments = undefined;
13
+ }
14
+
5
15
  var cachedPromise;
6
16
  function loadScript(src, namespace) {
7
17
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -23,14 +33,21 @@ function loadScript(src, namespace) {
23
33
  }
24
34
 
25
35
  cachedPromise = new Promise(function (resolve, reject) {
26
- document.head.appendChild(script);
27
- window.addEventListener("TossPayments:initialize:".concat(namespace), function () {
28
- if (getNamespace(namespace) !== undefined) {
29
- resolve(getNamespace(namespace));
36
+ script.onload = function () {
37
+ var loadedNamespace = getNamespace(namespace);
38
+
39
+ if (loadedNamespace !== undefined) {
40
+ resolve(loadedNamespace);
30
41
  } else {
31
42
  reject(new Error("[TossPayments SDK] Failed to load script: [".concat(src, "]")));
32
43
  }
33
- });
44
+ };
45
+
46
+ script.onerror = function () {
47
+ reject(new Error("[TossPayments SDK] Failed to load script: [".concat(src, "]")));
48
+ };
49
+
50
+ document.head.appendChild(script);
34
51
  });
35
52
  return cachedPromise;
36
53
  }
@@ -39,8 +56,6 @@ function getNamespace(name) {
39
56
  return window[name];
40
57
  }
41
58
 
42
- var SCRIPT_URL = 'https://js.tosspayments.com/v2/standard';
43
-
44
59
  function loadTossPayments(clientKey) {
45
60
  var loadOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
46
61
  var _loadOptions$src = loadOptions.src,
@@ -57,16 +72,5 @@ function loadTossPayments(clientKey) {
57
72
  });
58
73
  }
59
74
 
60
- function clearPaymentWidget() {
61
- var _script$parentElement;
62
-
63
- var script = document.querySelector("script[src=\"".concat(SCRIPT_URL, "\"]"));
64
- script === null || script === void 0 ? void 0 : (_script$parentElement = script.parentElement) === null || _script$parentElement === void 0 ? void 0 : _script$parentElement.removeChild(script);
65
- window.TossPayments = undefined;
66
- }
67
-
68
- var ANONYMOUS = '@@ANONYMOUS';
69
-
70
- exports.ANONYMOUS = ANONYMOUS;
71
- exports.clearPaymentWidget = clearPaymentWidget;
75
+ exports.clearTossPayments = clearTossPayments;
72
76
  exports.loadTossPayments = loadTossPayments;
package/dist/index.esm.js CHANGED
@@ -1,3 +1,13 @@
1
+ var SCRIPT_URL = 'https://js.tosspayments.com/v2/standard';
2
+
3
+ function clearTossPayments() {
4
+ var _script$parentElement;
5
+
6
+ var script = document.querySelector("script[src=\"".concat(SCRIPT_URL, "\"]"));
7
+ script === null || script === void 0 ? void 0 : (_script$parentElement = script.parentElement) === null || _script$parentElement === void 0 ? void 0 : _script$parentElement.removeChild(script);
8
+ window.TossPayments = undefined;
9
+ }
10
+
1
11
  var cachedPromise;
2
12
  function loadScript(src, namespace) {
3
13
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -19,14 +29,21 @@ function loadScript(src, namespace) {
19
29
  }
20
30
 
21
31
  cachedPromise = new Promise(function (resolve, reject) {
22
- document.head.appendChild(script);
23
- window.addEventListener("TossPayments:initialize:".concat(namespace), function () {
24
- if (getNamespace(namespace) !== undefined) {
25
- resolve(getNamespace(namespace));
32
+ script.onload = function () {
33
+ var loadedNamespace = getNamespace(namespace);
34
+
35
+ if (loadedNamespace !== undefined) {
36
+ resolve(loadedNamespace);
26
37
  } else {
27
38
  reject(new Error("[TossPayments SDK] Failed to load script: [".concat(src, "]")));
28
39
  }
29
- });
40
+ };
41
+
42
+ script.onerror = function () {
43
+ reject(new Error("[TossPayments SDK] Failed to load script: [".concat(src, "]")));
44
+ };
45
+
46
+ document.head.appendChild(script);
30
47
  });
31
48
  return cachedPromise;
32
49
  }
@@ -35,8 +52,6 @@ function getNamespace(name) {
35
52
  return window[name];
36
53
  }
37
54
 
38
- var SCRIPT_URL = 'https://js.tosspayments.com/v2/standard';
39
-
40
55
  function loadTossPayments(clientKey) {
41
56
  var loadOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
42
57
  var _loadOptions$src = loadOptions.src,
@@ -53,14 +68,4 @@ function loadTossPayments(clientKey) {
53
68
  });
54
69
  }
55
70
 
56
- function clearPaymentWidget() {
57
- var _script$parentElement;
58
-
59
- var script = document.querySelector("script[src=\"".concat(SCRIPT_URL, "\"]"));
60
- script === null || script === void 0 ? void 0 : (_script$parentElement = script.parentElement) === null || _script$parentElement === void 0 ? void 0 : _script$parentElement.removeChild(script);
61
- window.TossPayments = undefined;
62
- }
63
-
64
- var ANONYMOUS = '@@ANONYMOUS';
65
-
66
- export { ANONYMOUS, clearPaymentWidget, loadTossPayments };
71
+ export { clearTossPayments, loadTossPayments };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tosspayments/tosspayments-sdk",
3
3
  "description": "TossPayments.js Tosspayments SDK.",
4
- "version": "0.1.1-alpha.0",
4
+ "version": "0.1.1-alpha.1",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
7
7
  "types": "types/index.d.ts",
@@ -13,9 +13,6 @@
13
13
  "typecheck": "tsc --noEmit"
14
14
  },
15
15
  "license": "MIT",
16
- "dependencies": {
17
- "@tosspayments/standard-public-interfaces": "2.0.0-next.24"
18
- },
19
16
  "devDependencies": {
20
17
  "@babel/core": "^7.11.6",
21
18
  "@babel/preset-env": "^7.11.5",
@@ -23,7 +20,8 @@
23
20
  "@rollup/plugin-babel": "^5.3.0",
24
21
  "@rollup/plugin-commonjs": "^21.0.1",
25
22
  "@rollup/plugin-typescript": "^8.3.0",
26
- "@tosspayments/sdk-loader": "1.2.0",
23
+ "@tosspayments/sdk-loader": "1.2.1-alpha.0",
24
+ "@tosspayments/standard-public-interfaces": "2.0.0-next.24",
27
25
  "@types/jest": "^27.0.0",
28
26
  "jest": "^27.0.7",
29
27
  "prettier": "^2.0.2",
@@ -40,5 +38,5 @@
40
38
  "publishConfig": {
41
39
  "access": "public"
42
40
  },
43
- "gitHead": "cb83fbd8511cf435548ccf01d7a9038ffa7c3d7b"
41
+ "gitHead": "61a4736909d1d7df660bb2af567ed46567961e9c"
44
42
  }
@@ -1,4 +1,4 @@
1
- import { TossPayments } from '@tosspayments/standard-public-interfaces';
1
+ import type { TossPayments } from '@tosspayments/standard-public-interfaces';
2
2
  declare global {
3
3
  interface Window {
4
4
  TossPayments?: TossPayments & {
@@ -8,4 +8,4 @@ declare global {
8
8
  };
9
9
  }
10
10
  }
11
- export declare function clearPaymentWidget(): void;
11
+ export declare function clearTossPayments(): void;
@@ -0,0 +1 @@
1
+ export {};
package/types/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export { loadTossPayments } from './loadTossPayment';
2
- export { clearPaymentWidget } from './clearPaymentWidget';
3
- export declare const ANONYMOUS = "@@ANONYMOUS";
1
+ export { clearTossPayments } from './clearTossPayments';
2
+ export { loadTossPayments } from './loadTossPayments';
@@ -0,0 +1 @@
1
+ export {};