@tosspayments/tosspayments-sdk 0.1.1-alpha.1 → 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/README.md +2 -2
- package/dist/index.cjs.js +241 -25
- package/dist/index.esm.js +241 -25
- package/package.json +7 -8
- package/types/clearTossPayments.d.ts +0 -10
package/README.md
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -8,53 +8,269 @@ function clearTossPayments() {
|
|
|
8
8
|
var _script$parentElement;
|
|
9
9
|
|
|
10
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);
|
|
11
|
+
script === null || script === void 0 ? void 0 : (_script$parentElement = script.parentElement) === null || _script$parentElement === void 0 ? void 0 : _script$parentElement.removeChild(script); // TODO: public interface에서 TossPayments의 global declaration 추가한 뒤 제거 예정입니다
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
|
|
12
14
|
window.TossPayments = undefined;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
|
|
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
|
+
|
|
159
|
+
var cachedPromise = null;
|
|
16
160
|
function loadScript(src, namespace) {
|
|
17
161
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
18
|
-
var existingElement = document.querySelector("[src=\"".concat(src, "\"]"));
|
|
19
162
|
|
|
20
|
-
|
|
163
|
+
// Return the cached Promise if it exists
|
|
164
|
+
if (cachedPromise != null) {
|
|
21
165
|
return cachedPromise;
|
|
22
166
|
}
|
|
23
167
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
168
|
+
var promise = new Promise(function (resolve, reject) {
|
|
169
|
+
try {
|
|
170
|
+
var onLoad = function onLoad() {
|
|
171
|
+
if (getNamespace(namespace) != null) {
|
|
172
|
+
resolve(getNamespace(namespace));
|
|
173
|
+
} else {
|
|
174
|
+
reject(new NamespaceNotAvailableError(namespace));
|
|
175
|
+
}
|
|
176
|
+
};
|
|
27
177
|
|
|
28
|
-
|
|
29
|
-
|
|
178
|
+
var onError = function onError() {
|
|
179
|
+
reject(new ScriptLoadFailedError(src));
|
|
180
|
+
};
|
|
30
181
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
182
|
+
// Handle SSR
|
|
183
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
184
|
+
return resolve(null);
|
|
185
|
+
} // If the SDK instance already exists in the global namespace, resolve with it
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
if (getNamespace(namespace) != null) {
|
|
189
|
+
return resolve(getNamespace(namespace));
|
|
190
|
+
} // if script exists, but we are reloading due to an error,
|
|
191
|
+
// reload script to trigger 'load' event
|
|
34
192
|
|
|
35
|
-
cachedPromise = new Promise(function (resolve, reject) {
|
|
36
|
-
script.onload = function () {
|
|
37
|
-
var loadedNamespace = getNamespace(namespace);
|
|
38
193
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
194
|
+
var existingScript = document.querySelector("script[src=\"".concat(src, "\"]"));
|
|
195
|
+
|
|
196
|
+
if (existingScript != null) {
|
|
197
|
+
var _existingScript$paren;
|
|
198
|
+
|
|
199
|
+
existingScript.removeEventListener('load', onLoad);
|
|
200
|
+
existingScript.removeEventListener('error', onError);
|
|
201
|
+
(_existingScript$paren = existingScript.parentElement) === null || _existingScript$paren === void 0 ? void 0 : _existingScript$paren.removeChild(existingScript);
|
|
43
202
|
}
|
|
44
|
-
};
|
|
45
203
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
204
|
+
var script = document.createElement('script');
|
|
205
|
+
script.src = src;
|
|
206
|
+
script.addEventListener('load', onLoad);
|
|
207
|
+
script.addEventListener('error', onError);
|
|
49
208
|
|
|
50
|
-
|
|
209
|
+
if (options.priority != null) {
|
|
210
|
+
script.fetchPriority = options.priority;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
document.head.appendChild(script);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
reject(error);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
}); // Reset the cache if the Promise is rejected
|
|
219
|
+
|
|
220
|
+
cachedPromise = promise["catch"](function (error) {
|
|
221
|
+
cachedPromise = null;
|
|
222
|
+
return Promise.reject(error);
|
|
51
223
|
});
|
|
52
224
|
return cachedPromise;
|
|
53
225
|
}
|
|
54
226
|
|
|
55
227
|
function getNamespace(name) {
|
|
56
228
|
return window[name];
|
|
57
|
-
}
|
|
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));
|
|
58
274
|
|
|
59
275
|
function loadTossPayments(clientKey) {
|
|
60
276
|
var loadOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
package/dist/index.esm.js
CHANGED
|
@@ -4,53 +4,269 @@ function clearTossPayments() {
|
|
|
4
4
|
var _script$parentElement;
|
|
5
5
|
|
|
6
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);
|
|
7
|
+
script === null || script === void 0 ? void 0 : (_script$parentElement = script.parentElement) === null || _script$parentElement === void 0 ? void 0 : _script$parentElement.removeChild(script); // TODO: public interface에서 TossPayments의 global declaration 추가한 뒤 제거 예정입니다
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
|
|
8
10
|
window.TossPayments = undefined;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
|
|
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
|
+
|
|
155
|
+
var cachedPromise = null;
|
|
12
156
|
function loadScript(src, namespace) {
|
|
13
157
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
14
|
-
var existingElement = document.querySelector("[src=\"".concat(src, "\"]"));
|
|
15
158
|
|
|
16
|
-
|
|
159
|
+
// Return the cached Promise if it exists
|
|
160
|
+
if (cachedPromise != null) {
|
|
17
161
|
return cachedPromise;
|
|
18
162
|
}
|
|
19
163
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
164
|
+
var promise = new Promise(function (resolve, reject) {
|
|
165
|
+
try {
|
|
166
|
+
var onLoad = function onLoad() {
|
|
167
|
+
if (getNamespace(namespace) != null) {
|
|
168
|
+
resolve(getNamespace(namespace));
|
|
169
|
+
} else {
|
|
170
|
+
reject(new NamespaceNotAvailableError(namespace));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
23
173
|
|
|
24
|
-
|
|
25
|
-
|
|
174
|
+
var onError = function onError() {
|
|
175
|
+
reject(new ScriptLoadFailedError(src));
|
|
176
|
+
};
|
|
26
177
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
178
|
+
// Handle SSR
|
|
179
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
180
|
+
return resolve(null);
|
|
181
|
+
} // If the SDK instance already exists in the global namespace, resolve with it
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
if (getNamespace(namespace) != null) {
|
|
185
|
+
return resolve(getNamespace(namespace));
|
|
186
|
+
} // if script exists, but we are reloading due to an error,
|
|
187
|
+
// reload script to trigger 'load' event
|
|
30
188
|
|
|
31
|
-
cachedPromise = new Promise(function (resolve, reject) {
|
|
32
|
-
script.onload = function () {
|
|
33
|
-
var loadedNamespace = getNamespace(namespace);
|
|
34
189
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
190
|
+
var existingScript = document.querySelector("script[src=\"".concat(src, "\"]"));
|
|
191
|
+
|
|
192
|
+
if (existingScript != null) {
|
|
193
|
+
var _existingScript$paren;
|
|
194
|
+
|
|
195
|
+
existingScript.removeEventListener('load', onLoad);
|
|
196
|
+
existingScript.removeEventListener('error', onError);
|
|
197
|
+
(_existingScript$paren = existingScript.parentElement) === null || _existingScript$paren === void 0 ? void 0 : _existingScript$paren.removeChild(existingScript);
|
|
39
198
|
}
|
|
40
|
-
};
|
|
41
199
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
200
|
+
var script = document.createElement('script');
|
|
201
|
+
script.src = src;
|
|
202
|
+
script.addEventListener('load', onLoad);
|
|
203
|
+
script.addEventListener('error', onError);
|
|
45
204
|
|
|
46
|
-
|
|
205
|
+
if (options.priority != null) {
|
|
206
|
+
script.fetchPriority = options.priority;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
document.head.appendChild(script);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
reject(error);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
}); // Reset the cache if the Promise is rejected
|
|
215
|
+
|
|
216
|
+
cachedPromise = promise["catch"](function (error) {
|
|
217
|
+
cachedPromise = null;
|
|
218
|
+
return Promise.reject(error);
|
|
47
219
|
});
|
|
48
220
|
return cachedPromise;
|
|
49
221
|
}
|
|
50
222
|
|
|
51
223
|
function getNamespace(name) {
|
|
52
224
|
return window[name];
|
|
53
|
-
}
|
|
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));
|
|
54
270
|
|
|
55
271
|
function loadTossPayments(clientKey) {
|
|
56
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.
|
|
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",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "rm -rf dist && rollup -c && tsc --emitDeclarationOnly --declaration --declarationDir types",
|
|
11
11
|
"prepack": "yarn build",
|
|
12
|
-
"test": "
|
|
12
|
+
"test": "vitest",
|
|
13
13
|
"typecheck": "tsc --noEmit"
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
@@ -20,16 +20,15 @@
|
|
|
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.0",
|
|
23
|
+
"@tosspayments/sdk-loader": "1.2.1-alpha.3.0",
|
|
24
24
|
"@tosspayments/standard-public-interfaces": "2.0.0-next.24",
|
|
25
|
-
"
|
|
26
|
-
"jest": "^27.0.7",
|
|
25
|
+
"happy-dom": "^14.12.3",
|
|
27
26
|
"prettier": "^2.0.2",
|
|
28
27
|
"rollup": "^2.60.0",
|
|
29
28
|
"rollup-plugin-babel": "^4.4.0",
|
|
30
|
-
"ts-jest": "^27.0.7",
|
|
31
29
|
"tslib": "^1.11.1",
|
|
32
|
-
"typescript": "5.2.2"
|
|
30
|
+
"typescript": "5.2.2",
|
|
31
|
+
"vitest": "^1.6.0"
|
|
33
32
|
},
|
|
34
33
|
"files": [
|
|
35
34
|
"dist",
|
|
@@ -38,5 +37,5 @@
|
|
|
38
37
|
"publishConfig": {
|
|
39
38
|
"access": "public"
|
|
40
39
|
},
|
|
41
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "c558cf206d744750971a2323308b024ff120809a"
|
|
42
41
|
}
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import type { TossPayments } from '@tosspayments/standard-public-interfaces';
|
|
2
|
-
declare global {
|
|
3
|
-
interface Window {
|
|
4
|
-
TossPayments?: TossPayments & {
|
|
5
|
-
version: string;
|
|
6
|
-
isV2: boolean;
|
|
7
|
-
ANONYMOUS: string;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
1
|
export declare function clearTossPayments(): void;
|