@tosspayments/tosspayments-sdk 0.1.1-alpha.1.0 → 0.1.1-alpha.3.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/dist/index.cjs.js CHANGED
@@ -14,10 +14,153 @@ function clearTossPayments() {
14
14
  window.TossPayments = undefined;
15
15
  }
16
16
 
17
+ function _classCallCheck(instance, Constructor) {
18
+ if (!(instance instanceof Constructor)) {
19
+ throw new TypeError("Cannot call a class as a function");
20
+ }
21
+ }
22
+
23
+ function _inherits(subClass, superClass) {
24
+ if (typeof superClass !== "function" && superClass !== null) {
25
+ throw new TypeError("Super expression must either be null or a function");
26
+ }
27
+
28
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
29
+ constructor: {
30
+ value: subClass,
31
+ writable: true,
32
+ configurable: true
33
+ }
34
+ });
35
+ if (superClass) _setPrototypeOf(subClass, superClass);
36
+ }
37
+
38
+ function _getPrototypeOf(o) {
39
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
40
+ return o.__proto__ || Object.getPrototypeOf(o);
41
+ };
42
+ return _getPrototypeOf(o);
43
+ }
44
+
45
+ function _setPrototypeOf(o, p) {
46
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
47
+ o.__proto__ = p;
48
+ return o;
49
+ };
50
+
51
+ return _setPrototypeOf(o, p);
52
+ }
53
+
54
+ function _isNativeReflectConstruct() {
55
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
56
+ if (Reflect.construct.sham) return false;
57
+ if (typeof Proxy === "function") return true;
58
+
59
+ try {
60
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
61
+ return true;
62
+ } catch (e) {
63
+ return false;
64
+ }
65
+ }
66
+
67
+ function _construct(Parent, args, Class) {
68
+ if (_isNativeReflectConstruct()) {
69
+ _construct = Reflect.construct;
70
+ } else {
71
+ _construct = function _construct(Parent, args, Class) {
72
+ var a = [null];
73
+ a.push.apply(a, args);
74
+ var Constructor = Function.bind.apply(Parent, a);
75
+ var instance = new Constructor();
76
+ if (Class) _setPrototypeOf(instance, Class.prototype);
77
+ return instance;
78
+ };
79
+ }
80
+
81
+ return _construct.apply(null, arguments);
82
+ }
83
+
84
+ function _isNativeFunction(fn) {
85
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
86
+ }
87
+
88
+ function _wrapNativeSuper(Class) {
89
+ var _cache = typeof Map === "function" ? new Map() : undefined;
90
+
91
+ _wrapNativeSuper = function _wrapNativeSuper(Class) {
92
+ if (Class === null || !_isNativeFunction(Class)) return Class;
93
+
94
+ if (typeof Class !== "function") {
95
+ throw new TypeError("Super expression must either be null or a function");
96
+ }
97
+
98
+ if (typeof _cache !== "undefined") {
99
+ if (_cache.has(Class)) return _cache.get(Class);
100
+
101
+ _cache.set(Class, Wrapper);
102
+ }
103
+
104
+ function Wrapper() {
105
+ return _construct(Class, arguments, _getPrototypeOf(this).constructor);
106
+ }
107
+
108
+ Wrapper.prototype = Object.create(Class.prototype, {
109
+ constructor: {
110
+ value: Wrapper,
111
+ enumerable: false,
112
+ writable: true,
113
+ configurable: true
114
+ }
115
+ });
116
+ return _setPrototypeOf(Wrapper, Class);
117
+ };
118
+
119
+ return _wrapNativeSuper(Class);
120
+ }
121
+
122
+ function _assertThisInitialized(self) {
123
+ if (self === void 0) {
124
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
125
+ }
126
+
127
+ return self;
128
+ }
129
+
130
+ function _possibleConstructorReturn(self, call) {
131
+ if (call && (typeof call === "object" || typeof call === "function")) {
132
+ return call;
133
+ } else if (call !== void 0) {
134
+ throw new TypeError("Derived constructors may only return object or undefined");
135
+ }
136
+
137
+ return _assertThisInitialized(self);
138
+ }
139
+
140
+ function _createSuper(Derived) {
141
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
142
+
143
+ return function _createSuperInternal() {
144
+ var Super = _getPrototypeOf(Derived),
145
+ result;
146
+
147
+ if (hasNativeReflectConstruct) {
148
+ var NewTarget = _getPrototypeOf(this).constructor;
149
+
150
+ result = Reflect.construct(Super, arguments, NewTarget);
151
+ } else {
152
+ result = Super.apply(this, arguments);
153
+ }
154
+
155
+ return _possibleConstructorReturn(this, result);
156
+ };
157
+ }
158
+
17
159
  var cachedPromise = null;
18
160
  function loadScript(src, namespace) {
19
161
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
20
162
 
163
+ // Return the cached Promise if it exists
21
164
  if (cachedPromise != null) {
22
165
  return cachedPromise;
23
166
  }
@@ -28,21 +171,25 @@ function loadScript(src, namespace) {
28
171
  if (getNamespace(namespace) != null) {
29
172
  resolve(getNamespace(namespace));
30
173
  } else {
31
- reject(new Error("[TossPayments SDK] ".concat(namespace, " is not available")));
174
+ reject(new NamespaceNotAvailableError(namespace));
32
175
  }
33
176
  };
34
177
 
35
178
  var onError = function onError() {
36
- reject(new Error("[TossPayments SDK] Failed to load script: [".concat(src, "]")));
179
+ reject(new ScriptLoadFailedError(src));
37
180
  };
38
181
 
182
+ // Handle SSR
39
183
  if (typeof window === 'undefined' || typeof document === 'undefined') {
40
184
  return resolve(null);
41
- }
185
+ } // If the SDK instance already exists in the global namespace, resolve with it
186
+
42
187
 
43
188
  if (getNamespace(namespace) != null) {
44
189
  return resolve(getNamespace(namespace));
45
- }
190
+ } // if script exists, but we are reloading due to an error,
191
+ // reload script to trigger 'load' event
192
+
46
193
 
47
194
  var existingScript = document.querySelector("script[src=\"".concat(src, "\"]"));
48
195
 
@@ -68,7 +215,8 @@ function loadScript(src, namespace) {
68
215
  reject(error);
69
216
  return;
70
217
  }
71
- });
218
+ }); // Reset the cache if the Promise is rejected
219
+
72
220
  cachedPromise = promise["catch"](function (error) {
73
221
  cachedPromise = null;
74
222
  return Promise.reject(error);
@@ -78,7 +226,51 @@ function loadScript(src, namespace) {
78
226
 
79
227
  function getNamespace(name) {
80
228
  return window[name];
81
- } // Test용
229
+ } // TODO: test용 유틸을 export 하는 대신 다른 방식을 사용해야함
230
+ // Test용
231
+ // export function clearCache() {
232
+ // cachedPromise = null;
233
+ // }
234
+ // // Test용
235
+ // export function getCachedPromise() {
236
+ // return cachedPromise;
237
+ // }
238
+
239
+
240
+ var NamespaceNotAvailableError = /*#__PURE__*/function (_Error) {
241
+ _inherits(NamespaceNotAvailableError, _Error);
242
+
243
+ var _super = _createSuper(NamespaceNotAvailableError);
244
+
245
+ function NamespaceNotAvailableError(namespace) {
246
+ var _this;
247
+
248
+ _classCallCheck(this, NamespaceNotAvailableError);
249
+
250
+ _this = _super.call(this, "[TossPayments SDK] ".concat(namespace, " is not available"));
251
+ _this.name = 'NamespaceNotAvailableError';
252
+ return _this;
253
+ }
254
+
255
+ return NamespaceNotAvailableError;
256
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
257
+ var ScriptLoadFailedError = /*#__PURE__*/function (_Error2) {
258
+ _inherits(ScriptLoadFailedError, _Error2);
259
+
260
+ var _super2 = _createSuper(ScriptLoadFailedError);
261
+
262
+ function ScriptLoadFailedError(src) {
263
+ var _this2;
264
+
265
+ _classCallCheck(this, ScriptLoadFailedError);
266
+
267
+ _this2 = _super2.call(this, "[TossPayments SDK] Failed to load script: [".concat(src, "]"));
268
+ _this2.name = 'ScriptLoadFailedError';
269
+ return _this2;
270
+ }
271
+
272
+ return ScriptLoadFailedError;
273
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
82
274
 
83
275
  function loadTossPayments(clientKey) {
84
276
  var loadOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
package/dist/index.esm.js CHANGED
@@ -10,10 +10,153 @@ function clearTossPayments() {
10
10
  window.TossPayments = undefined;
11
11
  }
12
12
 
13
+ function _classCallCheck(instance, Constructor) {
14
+ if (!(instance instanceof Constructor)) {
15
+ throw new TypeError("Cannot call a class as a function");
16
+ }
17
+ }
18
+
19
+ function _inherits(subClass, superClass) {
20
+ if (typeof superClass !== "function" && superClass !== null) {
21
+ throw new TypeError("Super expression must either be null or a function");
22
+ }
23
+
24
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
25
+ constructor: {
26
+ value: subClass,
27
+ writable: true,
28
+ configurable: true
29
+ }
30
+ });
31
+ if (superClass) _setPrototypeOf(subClass, superClass);
32
+ }
33
+
34
+ function _getPrototypeOf(o) {
35
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
36
+ return o.__proto__ || Object.getPrototypeOf(o);
37
+ };
38
+ return _getPrototypeOf(o);
39
+ }
40
+
41
+ function _setPrototypeOf(o, p) {
42
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
43
+ o.__proto__ = p;
44
+ return o;
45
+ };
46
+
47
+ return _setPrototypeOf(o, p);
48
+ }
49
+
50
+ function _isNativeReflectConstruct() {
51
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
52
+ if (Reflect.construct.sham) return false;
53
+ if (typeof Proxy === "function") return true;
54
+
55
+ try {
56
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
57
+ return true;
58
+ } catch (e) {
59
+ return false;
60
+ }
61
+ }
62
+
63
+ function _construct(Parent, args, Class) {
64
+ if (_isNativeReflectConstruct()) {
65
+ _construct = Reflect.construct;
66
+ } else {
67
+ _construct = function _construct(Parent, args, Class) {
68
+ var a = [null];
69
+ a.push.apply(a, args);
70
+ var Constructor = Function.bind.apply(Parent, a);
71
+ var instance = new Constructor();
72
+ if (Class) _setPrototypeOf(instance, Class.prototype);
73
+ return instance;
74
+ };
75
+ }
76
+
77
+ return _construct.apply(null, arguments);
78
+ }
79
+
80
+ function _isNativeFunction(fn) {
81
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
82
+ }
83
+
84
+ function _wrapNativeSuper(Class) {
85
+ var _cache = typeof Map === "function" ? new Map() : undefined;
86
+
87
+ _wrapNativeSuper = function _wrapNativeSuper(Class) {
88
+ if (Class === null || !_isNativeFunction(Class)) return Class;
89
+
90
+ if (typeof Class !== "function") {
91
+ throw new TypeError("Super expression must either be null or a function");
92
+ }
93
+
94
+ if (typeof _cache !== "undefined") {
95
+ if (_cache.has(Class)) return _cache.get(Class);
96
+
97
+ _cache.set(Class, Wrapper);
98
+ }
99
+
100
+ function Wrapper() {
101
+ return _construct(Class, arguments, _getPrototypeOf(this).constructor);
102
+ }
103
+
104
+ Wrapper.prototype = Object.create(Class.prototype, {
105
+ constructor: {
106
+ value: Wrapper,
107
+ enumerable: false,
108
+ writable: true,
109
+ configurable: true
110
+ }
111
+ });
112
+ return _setPrototypeOf(Wrapper, Class);
113
+ };
114
+
115
+ return _wrapNativeSuper(Class);
116
+ }
117
+
118
+ function _assertThisInitialized(self) {
119
+ if (self === void 0) {
120
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
121
+ }
122
+
123
+ return self;
124
+ }
125
+
126
+ function _possibleConstructorReturn(self, call) {
127
+ if (call && (typeof call === "object" || typeof call === "function")) {
128
+ return call;
129
+ } else if (call !== void 0) {
130
+ throw new TypeError("Derived constructors may only return object or undefined");
131
+ }
132
+
133
+ return _assertThisInitialized(self);
134
+ }
135
+
136
+ function _createSuper(Derived) {
137
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
138
+
139
+ return function _createSuperInternal() {
140
+ var Super = _getPrototypeOf(Derived),
141
+ result;
142
+
143
+ if (hasNativeReflectConstruct) {
144
+ var NewTarget = _getPrototypeOf(this).constructor;
145
+
146
+ result = Reflect.construct(Super, arguments, NewTarget);
147
+ } else {
148
+ result = Super.apply(this, arguments);
149
+ }
150
+
151
+ return _possibleConstructorReturn(this, result);
152
+ };
153
+ }
154
+
13
155
  var cachedPromise = null;
14
156
  function loadScript(src, namespace) {
15
157
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16
158
 
159
+ // Return the cached Promise if it exists
17
160
  if (cachedPromise != null) {
18
161
  return cachedPromise;
19
162
  }
@@ -24,21 +167,25 @@ function loadScript(src, namespace) {
24
167
  if (getNamespace(namespace) != null) {
25
168
  resolve(getNamespace(namespace));
26
169
  } else {
27
- reject(new Error("[TossPayments SDK] ".concat(namespace, " is not available")));
170
+ reject(new NamespaceNotAvailableError(namespace));
28
171
  }
29
172
  };
30
173
 
31
174
  var onError = function onError() {
32
- reject(new Error("[TossPayments SDK] Failed to load script: [".concat(src, "]")));
175
+ reject(new ScriptLoadFailedError(src));
33
176
  };
34
177
 
178
+ // Handle SSR
35
179
  if (typeof window === 'undefined' || typeof document === 'undefined') {
36
180
  return resolve(null);
37
- }
181
+ } // If the SDK instance already exists in the global namespace, resolve with it
182
+
38
183
 
39
184
  if (getNamespace(namespace) != null) {
40
185
  return resolve(getNamespace(namespace));
41
- }
186
+ } // if script exists, but we are reloading due to an error,
187
+ // reload script to trigger 'load' event
188
+
42
189
 
43
190
  var existingScript = document.querySelector("script[src=\"".concat(src, "\"]"));
44
191
 
@@ -64,7 +211,8 @@ function loadScript(src, namespace) {
64
211
  reject(error);
65
212
  return;
66
213
  }
67
- });
214
+ }); // Reset the cache if the Promise is rejected
215
+
68
216
  cachedPromise = promise["catch"](function (error) {
69
217
  cachedPromise = null;
70
218
  return Promise.reject(error);
@@ -74,7 +222,51 @@ function loadScript(src, namespace) {
74
222
 
75
223
  function getNamespace(name) {
76
224
  return window[name];
77
- } // Test용
225
+ } // TODO: test용 유틸을 export 하는 대신 다른 방식을 사용해야함
226
+ // Test용
227
+ // export function clearCache() {
228
+ // cachedPromise = null;
229
+ // }
230
+ // // Test용
231
+ // export function getCachedPromise() {
232
+ // return cachedPromise;
233
+ // }
234
+
235
+
236
+ var NamespaceNotAvailableError = /*#__PURE__*/function (_Error) {
237
+ _inherits(NamespaceNotAvailableError, _Error);
238
+
239
+ var _super = _createSuper(NamespaceNotAvailableError);
240
+
241
+ function NamespaceNotAvailableError(namespace) {
242
+ var _this;
243
+
244
+ _classCallCheck(this, NamespaceNotAvailableError);
245
+
246
+ _this = _super.call(this, "[TossPayments SDK] ".concat(namespace, " is not available"));
247
+ _this.name = 'NamespaceNotAvailableError';
248
+ return _this;
249
+ }
250
+
251
+ return NamespaceNotAvailableError;
252
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
253
+ var ScriptLoadFailedError = /*#__PURE__*/function (_Error2) {
254
+ _inherits(ScriptLoadFailedError, _Error2);
255
+
256
+ var _super2 = _createSuper(ScriptLoadFailedError);
257
+
258
+ function ScriptLoadFailedError(src) {
259
+ var _this2;
260
+
261
+ _classCallCheck(this, ScriptLoadFailedError);
262
+
263
+ _this2 = _super2.call(this, "[TossPayments SDK] Failed to load script: [".concat(src, "]"));
264
+ _this2.name = 'ScriptLoadFailedError';
265
+ return _this2;
266
+ }
267
+
268
+ return ScriptLoadFailedError;
269
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
78
270
 
79
271
  function loadTossPayments(clientKey) {
80
272
  var loadOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
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.1.0",
4
+ "version": "0.1.1-alpha.3.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
7
7
  "types": "types/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "@rollup/plugin-babel": "^5.3.0",
21
21
  "@rollup/plugin-commonjs": "^21.0.1",
22
22
  "@rollup/plugin-typescript": "^8.3.0",
23
- "@tosspayments/sdk-loader": "1.2.1-alpha.1.0",
23
+ "@tosspayments/sdk-loader": "1.2.1-alpha.3.0",
24
24
  "@tosspayments/standard-public-interfaces": "2.0.0-next.24",
25
25
  "happy-dom": "^14.12.3",
26
26
  "prettier": "^2.0.2",
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "b50d0d5975b9d6e8dec619a72ab468d0059586c3"
40
+ "gitHead": "c558cf206d744750971a2323308b024ff120809a"
41
41
  }