@integralscope/command-transfer-checkout-js 0.1.6 → 0.1.7-dev.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 +40 -1
- package/dist/commandtransfer-checkout.js +50 -53
- package/dist/commandtransfer-checkout.umd.cjs +1 -1
- package/dist/constants.d.ts +7 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/url.d.ts +13 -1
- package/dist/url.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -104,6 +104,19 @@ const session = await fetch("/api/checkout", { method: "POST" }).then((r) =>
|
|
|
104
104
|
npm install @integralscope/command-transfer-checkout-js
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
+
### Release channels
|
|
108
|
+
|
|
109
|
+
| Channel | Install | What it is |
|
|
110
|
+
| -------- | ------- | ---------- |
|
|
111
|
+
| `latest` | `npm i @integralscope/command-transfer-checkout-js` | Released versions. What merchants should use. |
|
|
112
|
+
| `dev` | `npm i @integralscope/command-transfer-checkout-js@dev` | Every push to `main`, published as `X.Y.Z-dev.N`. Internal testing only. |
|
|
113
|
+
|
|
114
|
+
A prerelease version never satisfies a `^` or `~` range, so a plain install can
|
|
115
|
+
never resolve to a `dev` build — you have to ask for it by name.
|
|
116
|
+
|
|
117
|
+
There is one branch, `main`, and work on it is not a release. **Tagging `v*` is
|
|
118
|
+
what promotes a commit to production** and the only thing that moves `latest`.
|
|
119
|
+
|
|
107
120
|
Or a script tag:
|
|
108
121
|
|
|
109
122
|
```html
|
|
@@ -263,6 +276,7 @@ Do not call `/v1/checkout/.../client` or card-attempt routes from the merchant p
|
|
|
263
276
|
| `mode` | no | `inline` (default), `modal`, or `redirect` |
|
|
264
277
|
| `container` | no | Used by `start()` when `mode` is `inline` |
|
|
265
278
|
| `returnUrl` | no | Redirect return URL. Ignored for inline/modal. |
|
|
279
|
+
| `checkoutOrigin` | no | Override the hosted checkout origin. Defaults to production — see below. |
|
|
266
280
|
|
|
267
281
|
## Events
|
|
268
282
|
|
|
@@ -275,7 +289,9 @@ Do not call `/v1/checkout/.../client` or card-attempt routes from the merchant p
|
|
|
275
289
|
|
|
276
290
|
## Checkout origin
|
|
277
291
|
|
|
278
|
-
Merchants do not pass a checkout URL.
|
|
292
|
+
Merchants do not pass a checkout URL. Every published build of this SDK — stable
|
|
293
|
+
and prerelease alike — bakes in Command Transfer’s **production** Checkout Web
|
|
294
|
+
origin, so the normal case needs no configuration:
|
|
279
295
|
|
|
280
296
|
```js
|
|
281
297
|
new Checkout({
|
|
@@ -286,6 +302,29 @@ new Checkout({
|
|
|
286
302
|
|
|
287
303
|
If you set a Content-Security-Policy on your site, allow Command Transfer’s checkout origin in `frame-src`.
|
|
288
304
|
|
|
305
|
+
### Pointing a non-production app elsewhere
|
|
306
|
+
|
|
307
|
+
Internal and staging apps override the origin at runtime, rather than installing
|
|
308
|
+
a differently-built package:
|
|
309
|
+
|
|
310
|
+
```js
|
|
311
|
+
new Checkout({
|
|
312
|
+
intentId: session.intentId,
|
|
313
|
+
clientToken: session.clientToken,
|
|
314
|
+
checkoutOrigin: "https://ct-dev-checkout.web.app", // non-production only
|
|
315
|
+
});
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
The override is validated exactly like the baked value: it must be `https` and
|
|
319
|
+
carry no credentials, and only loopback (`http://localhost:5173`) may use plain
|
|
320
|
+
`http`, for a checkout app running on your machine. Anything else throws before
|
|
321
|
+
a frame is created.
|
|
322
|
+
|
|
323
|
+
This is why there is no separate “development build” of the package: the channel
|
|
324
|
+
you install decides which **code** you get, and `checkoutOrigin` decides which
|
|
325
|
+
**backend** it talks to. The two are independent on purpose — it means no build
|
|
326
|
+
wired to a non-production backend can ever reach a merchant.
|
|
327
|
+
|
|
289
328
|
## Rules
|
|
290
329
|
|
|
291
330
|
- Secret API keys (`sk_…`) stay on your server. This package must not receive them.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class d {
|
|
2
2
|
constructor() {
|
|
3
3
|
this.listeners = /* @__PURE__ */ new Map();
|
|
4
4
|
}
|
|
@@ -10,11 +10,11 @@ class f {
|
|
|
10
10
|
}
|
|
11
11
|
emit(e, t) {
|
|
12
12
|
const n = this.listeners.get(e);
|
|
13
|
-
n && [...n].forEach((
|
|
13
|
+
n && [...n].forEach((i) => {
|
|
14
14
|
try {
|
|
15
|
-
|
|
16
|
-
} catch (
|
|
17
|
-
console.error(`Checkout "${String(e)}" handler failed.`,
|
|
15
|
+
i(t);
|
|
16
|
+
} catch (o) {
|
|
17
|
+
console.error(`Checkout "${String(e)}" handler failed.`, o);
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -26,16 +26,16 @@ const s = "commandtransfer.checkout", u = "ctc_";
|
|
|
26
26
|
function m(r) {
|
|
27
27
|
return r?.trim() || "";
|
|
28
28
|
}
|
|
29
|
-
const
|
|
29
|
+
const f = m(
|
|
30
30
|
"https://ct-dev-checkout.web.app"
|
|
31
|
-
),
|
|
31
|
+
), g = /* @__PURE__ */ new Set([
|
|
32
32
|
"checkout.ready",
|
|
33
33
|
"checkout.success",
|
|
34
34
|
"checkout.cancel",
|
|
35
35
|
"checkout.error",
|
|
36
36
|
"checkout.resize"
|
|
37
37
|
]);
|
|
38
|
-
function
|
|
38
|
+
function w(r) {
|
|
39
39
|
return !!r && typeof r == "object" && !Array.isArray(r);
|
|
40
40
|
}
|
|
41
41
|
function c(r, e) {
|
|
@@ -44,10 +44,10 @@ function c(r, e) {
|
|
|
44
44
|
return !t || t.length > e || /[\u0000-\u001f\u007f]/.test(t) ? null : t;
|
|
45
45
|
}
|
|
46
46
|
function k(r, e) {
|
|
47
|
-
if (!
|
|
47
|
+
if (!w(r) || r.source !== s)
|
|
48
48
|
return null;
|
|
49
49
|
const t = c(r.type, 64);
|
|
50
|
-
if (!t || !
|
|
50
|
+
if (!t || !g.has(t))
|
|
51
51
|
return null;
|
|
52
52
|
const n = c(r.checkoutId, 128);
|
|
53
53
|
if (n !== e)
|
|
@@ -60,12 +60,12 @@ function k(r, e) {
|
|
|
60
60
|
checkoutId: n
|
|
61
61
|
};
|
|
62
62
|
case "checkout.success": {
|
|
63
|
-
const
|
|
64
|
-
return
|
|
63
|
+
const i = c(r.reference, 128);
|
|
64
|
+
return i ? {
|
|
65
65
|
source: s,
|
|
66
66
|
type: t,
|
|
67
67
|
checkoutId: n,
|
|
68
|
-
reference:
|
|
68
|
+
reference: i
|
|
69
69
|
} : null;
|
|
70
70
|
}
|
|
71
71
|
case "checkout.cancel":
|
|
@@ -75,22 +75,22 @@ function k(r, e) {
|
|
|
75
75
|
checkoutId: n
|
|
76
76
|
};
|
|
77
77
|
case "checkout.error": {
|
|
78
|
-
const
|
|
79
|
-
return !
|
|
78
|
+
const i = c(r.code, 64), o = c(r.message, 280);
|
|
79
|
+
return !i || !o ? null : {
|
|
80
80
|
source: s,
|
|
81
81
|
type: t,
|
|
82
82
|
checkoutId: n,
|
|
83
|
-
code:
|
|
84
|
-
message:
|
|
83
|
+
code: i,
|
|
84
|
+
message: o
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
case "checkout.resize": {
|
|
88
|
-
const
|
|
89
|
-
return !Number.isFinite(
|
|
88
|
+
const i = typeof r.height == "number" ? r.height : Number(r.height);
|
|
89
|
+
return !Number.isFinite(i) || i < 200 || i > 4e3 ? null : {
|
|
90
90
|
source: s,
|
|
91
91
|
type: t,
|
|
92
92
|
checkoutId: n,
|
|
93
|
-
height: Math.round(
|
|
93
|
+
height: Math.round(i)
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
default:
|
|
@@ -174,8 +174,8 @@ class y {
|
|
|
174
174
|
"border-radius:16px",
|
|
175
175
|
"box-shadow:0 24px 64px rgba(15,12,41,0.28)"
|
|
176
176
|
].join(";");
|
|
177
|
-
const
|
|
178
|
-
|
|
177
|
+
const i = document.createElement("button");
|
|
178
|
+
i.type = "button", i.setAttribute("aria-label", "Close checkout"), i.textContent = "×", i.style.cssText = [
|
|
179
179
|
"position:absolute",
|
|
180
180
|
"top:8px",
|
|
181
181
|
"right:8px",
|
|
@@ -190,11 +190,11 @@ class y {
|
|
|
190
190
|
"line-height:1",
|
|
191
191
|
"cursor:pointer",
|
|
192
192
|
"box-shadow:0 2px 8px rgba(15,12,41,0.16)"
|
|
193
|
-
].join(";"),
|
|
194
|
-
|
|
195
|
-
}), this.escapeListener = (
|
|
196
|
-
|
|
197
|
-
}, window.addEventListener("keydown", this.escapeListener), this.previousBodyOverflow = document.body.style.overflow, document.body.style.overflow = "hidden", n.append(
|
|
193
|
+
].join(";"), i.addEventListener("click", this.onCloseRequest), t.addEventListener("click", (o) => {
|
|
194
|
+
o.target === t && this.onCloseRequest();
|
|
195
|
+
}), this.escapeListener = (o) => {
|
|
196
|
+
o.key === "Escape" && this.onCloseRequest();
|
|
197
|
+
}, window.addEventListener("keydown", this.escapeListener), this.previousBodyOverflow = document.body.style.overflow, document.body.style.overflow = "hidden", n.append(i, e), t.appendChild(n), document.body.appendChild(t), this.overlay = t, i.focus();
|
|
198
198
|
}
|
|
199
199
|
teardownModal() {
|
|
200
200
|
this.escapeListener && (window.removeEventListener("keydown", this.escapeListener), this.escapeListener = null), this.overlay?.remove(), this.overlay = null, this.previousBodyOverflow !== null && (document.body.style.overflow = this.previousBodyOverflow, this.previousBodyOverflow = null);
|
|
@@ -207,25 +207,25 @@ function b(r) {
|
|
|
207
207
|
return e ? e.startsWith("#") || e.startsWith(".") || e.startsWith("[") ? document.querySelector(e) : document.getElementById(e) ?? document.querySelector(e) : null;
|
|
208
208
|
}
|
|
209
209
|
const v = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
210
|
-
function
|
|
210
|
+
function a(r) {
|
|
211
211
|
return r.replace(/^\[|\]$/g, "").toLowerCase();
|
|
212
212
|
}
|
|
213
|
-
function
|
|
214
|
-
const e =
|
|
213
|
+
function h(r) {
|
|
214
|
+
const e = a(r);
|
|
215
215
|
return e === "localhost" || e === "127.0.0.1" || e === "::1";
|
|
216
216
|
}
|
|
217
217
|
function E(r) {
|
|
218
218
|
const e = r.split(".");
|
|
219
219
|
if (e.length !== 4) return !1;
|
|
220
|
-
const t = e.map((
|
|
221
|
-
if (t.some((
|
|
220
|
+
const t = e.map((o) => Number(o));
|
|
221
|
+
if (t.some((o) => !Number.isInteger(o) || o < 0 || o > 255))
|
|
222
222
|
return !1;
|
|
223
|
-
const [n,
|
|
224
|
-
return n === 10 || n === 127 || n === 192 &&
|
|
223
|
+
const [n, i] = t;
|
|
224
|
+
return n === 10 || n === 127 || n === 192 && i === 168 || n === 172 && i >= 16 && i <= 31;
|
|
225
225
|
}
|
|
226
226
|
function I(r) {
|
|
227
|
-
const e =
|
|
228
|
-
return
|
|
227
|
+
const e = a(r);
|
|
228
|
+
return h(e) || E(e) ? !0 : e.endsWith(".local") || e.endsWith(".test") || e.endsWith(".localhost");
|
|
229
229
|
}
|
|
230
230
|
function C(r) {
|
|
231
231
|
const e = r.trim();
|
|
@@ -243,7 +243,7 @@ function x(r) {
|
|
|
243
243
|
throw new Error("clientToken is invalid.");
|
|
244
244
|
return t;
|
|
245
245
|
}
|
|
246
|
-
function
|
|
246
|
+
function l(r, e, t) {
|
|
247
247
|
let n;
|
|
248
248
|
try {
|
|
249
249
|
n = new URL(r);
|
|
@@ -256,17 +256,14 @@ function d(r, e, t) {
|
|
|
256
256
|
return n;
|
|
257
257
|
throw new Error(`${e} must be an https URL.`);
|
|
258
258
|
}
|
|
259
|
-
function M() {
|
|
260
|
-
|
|
259
|
+
function M(r) {
|
|
260
|
+
const e = r?.trim() || f;
|
|
261
|
+
if (!e)
|
|
261
262
|
throw new Error("checkout origin is not configured.");
|
|
262
|
-
return
|
|
263
|
-
a,
|
|
264
|
-
"checkout origin",
|
|
265
|
-
l
|
|
266
|
-
).origin;
|
|
263
|
+
return l(e, "checkout origin", h).origin;
|
|
267
264
|
}
|
|
268
265
|
function O(r, e) {
|
|
269
|
-
return
|
|
266
|
+
return l(r, e, I).toString();
|
|
270
267
|
}
|
|
271
268
|
function U(r) {
|
|
272
269
|
const e = encodeURIComponent(r.intentId), t = new URL(`/pay/${e}`, r.checkoutOrigin);
|
|
@@ -277,21 +274,21 @@ function L(r) {
|
|
|
277
274
|
throw new Error("Checkout config is required.");
|
|
278
275
|
if (!r.intentId?.trim())
|
|
279
276
|
throw new Error("intentId is required.");
|
|
280
|
-
const e = C(r.intentId), t = x(r.clientToken ?? ""), n = M(),
|
|
281
|
-
if (
|
|
277
|
+
const e = C(r.intentId), t = x(r.clientToken ?? ""), n = M(r.checkoutOrigin), i = r.mode ?? "inline";
|
|
278
|
+
if (i !== "inline" && i !== "modal" && i !== "redirect")
|
|
282
279
|
throw new Error('mode must be "inline", "modal", or "redirect".');
|
|
283
|
-
const
|
|
280
|
+
const o = r.returnUrl ? O(r.returnUrl, "returnUrl") : void 0;
|
|
284
281
|
return {
|
|
285
282
|
intentId: e,
|
|
286
283
|
clientToken: t,
|
|
287
284
|
checkoutOrigin: n,
|
|
288
|
-
mode:
|
|
289
|
-
returnUrl:
|
|
285
|
+
mode: i,
|
|
286
|
+
returnUrl: o
|
|
290
287
|
};
|
|
291
288
|
}
|
|
292
289
|
class T {
|
|
293
290
|
constructor(e) {
|
|
294
|
-
this.events = new
|
|
291
|
+
this.events = new d(), this.iframeManager = null, this.mounted = !1, this.settled = !1, this.handleMessage = (t) => {
|
|
295
292
|
switch (t.type) {
|
|
296
293
|
case "checkout.ready":
|
|
297
294
|
this.events.emit("ready", { intentId: t.checkoutId });
|
|
@@ -369,10 +366,10 @@ class T {
|
|
|
369
366
|
const n = e === "modal" ? document.body : b(t);
|
|
370
367
|
if (!n)
|
|
371
368
|
throw new Error("Checkout container was not found.");
|
|
372
|
-
const
|
|
369
|
+
const i = this.getCheckoutUrl(e);
|
|
373
370
|
this.iframeManager = new y({
|
|
374
371
|
checkoutId: this.config.intentId,
|
|
375
|
-
checkoutUrl:
|
|
372
|
+
checkoutUrl: i,
|
|
376
373
|
checkoutOrigin: this.config.checkoutOrigin,
|
|
377
374
|
presentation: e,
|
|
378
375
|
onMessage: this.handleMessage,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.CommandTransferCheckout={}))})(this,(function(s){"use strict";class u{constructor(){this.listeners=new Map}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>{n?.delete(t)}}emit(e,t){const n=this.listeners.get(e);n&&[...n].forEach(o=>{try{o(t)}catch(i){console.error(`Checkout "${String(e)}" handler failed.`,i)}})}removeAllListeners(){this.listeners.clear()}}const c="commandtransfer.checkout",h="ctc_";function
|
|
1
|
+
(function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.CommandTransferCheckout={}))})(this,(function(s){"use strict";class u{constructor(){this.listeners=new Map}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>{n?.delete(t)}}emit(e,t){const n=this.listeners.get(e);n&&[...n].forEach(o=>{try{o(t)}catch(i){console.error(`Checkout "${String(e)}" handler failed.`,i)}})}removeAllListeners(){this.listeners.clear()}}const c="commandtransfer.checkout",h="ctc_";function m(r){return r?.trim()||""}const g=m("https://ct-dev-checkout.web.app"),w=new Set(["checkout.ready","checkout.success","checkout.cancel","checkout.error","checkout.resize"]);function k(r){return!!r&&typeof r=="object"&&!Array.isArray(r)}function a(r,e){if(typeof r!="string")return null;const t=r.trim();return!t||t.length>e||/[\u0000-\u001f\u007f]/.test(t)?null:t}function p(r,e){if(!k(r)||r.source!==c)return null;const t=a(r.type,64);if(!t||!w.has(t))return null;const n=a(r.checkoutId,128);if(n!==e)return null;switch(t){case"checkout.ready":return{source:c,type:t,checkoutId:n};case"checkout.success":{const o=a(r.reference,128);return o?{source:c,type:t,checkoutId:n,reference:o}:null}case"checkout.cancel":return{source:c,type:t,checkoutId:n};case"checkout.error":{const o=a(r.code,64),i=a(r.message,280);return!o||!i?null:{source:c,type:t,checkoutId:n,code:o,message:i}}case"checkout.resize":{const o=typeof r.height=="number"?r.height:Number(r.height);return!Number.isFinite(o)||o<200||o>4e3?null:{source:c,type:t,checkoutId:n,height:Math.round(o)}}default:return null}}class y{constructor(e){this.sourceWindow=null,this.handleMessage=t=>{if(t.origin!==this.checkoutOrigin||!this.sourceWindow||t.source!==this.sourceWindow)return;const n=p(t.data,this.checkoutId);n&&this.onMessage(n)},this.checkoutId=e.checkoutId,this.checkoutOrigin=e.checkoutOrigin,this.onMessage=e.onMessage,window.addEventListener("message",this.handleMessage)}setSourceWindow(e){this.sourceWindow=e}destroy(){window.removeEventListener("message",this.handleMessage),this.sourceWindow=null}}class b{constructor(e){this.iframe=null,this.overlay=null,this.previousBodyOverflow=null,this.escapeListener=null,this.checkoutUrl=e.checkoutUrl,this.presentation=e.presentation,this.onCloseRequest=e.onCloseRequest,this.bridge=new y({checkoutId:e.checkoutId,checkoutOrigin:e.checkoutOrigin,onMessage:e.onMessage})}mount(e){if(this.iframe)throw new Error("Checkout iframe is already mounted.");const t=this.createIframe();this.presentation==="modal"?this.mountModal(t):e.appendChild(t),this.iframe=t,this.bridge.setSourceWindow(t.contentWindow),t.addEventListener("load",()=>{this.bridge.setSourceWindow(t.contentWindow)})}setHeight(e){this.iframe&&(this.iframe.style.height=`${Math.round(e)}px`)}destroy(){this.bridge.destroy(),this.iframe?.remove(),this.iframe=null,this.teardownModal()}createIframe(){const e=document.createElement("iframe");return e.src=this.checkoutUrl,e.title="Command Transfer checkout",e.setAttribute("allow","payment; clipboard-write; publickey-credentials-get"),e.setAttribute("referrerpolicy","no-referrer"),e.setAttribute("sandbox",["allow-scripts","allow-same-origin","allow-forms","allow-popups","allow-popups-to-escape-sandbox","allow-modals","allow-top-navigation-by-user-activation"].join(" ")),e.style.width="100%",e.style.height="720px",e.style.border="0",e.style.display="block",e.style.background="#f3f0ff",e.style.borderRadius=this.presentation==="modal"?"16px":"0",e}mountModal(e){const t=document.createElement("div");t.setAttribute("data-ct-checkout","overlay"),t.setAttribute("role","dialog"),t.setAttribute("aria-modal","true"),t.setAttribute("aria-label","Payment checkout"),t.style.cssText=["position:fixed","inset:0","z-index:2147483647","display:flex","align-items:center","justify-content:center","padding:24px 16px","background:rgba(15,12,41,0.55)"].join(";");const n=document.createElement("div");n.style.cssText=["position:relative","width:min(420px,100%)","max-height:calc(100vh - 48px)","overflow:auto","border-radius:16px","box-shadow:0 24px 64px rgba(15,12,41,0.28)"].join(";");const o=document.createElement("button");o.type="button",o.setAttribute("aria-label","Close checkout"),o.textContent="×",o.style.cssText=["position:absolute","top:8px","right:8px","z-index:1","width:32px","height:32px","border:0","border-radius:999px","background:#ffffff","color:#1e1654","font-size:22px","line-height:1","cursor:pointer","box-shadow:0 2px 8px rgba(15,12,41,0.16)"].join(";"),o.addEventListener("click",this.onCloseRequest),t.addEventListener("click",i=>{i.target===t&&this.onCloseRequest()}),this.escapeListener=i=>{i.key==="Escape"&&this.onCloseRequest()},window.addEventListener("keydown",this.escapeListener),this.previousBodyOverflow=document.body.style.overflow,document.body.style.overflow="hidden",n.append(o,e),t.appendChild(n),document.body.appendChild(t),this.overlay=t,o.focus()}teardownModal(){this.escapeListener&&(window.removeEventListener("keydown",this.escapeListener),this.escapeListener=null),this.overlay?.remove(),this.overlay=null,this.previousBodyOverflow!==null&&(document.body.style.overflow=this.previousBodyOverflow,this.previousBodyOverflow=null)}}function v(r){if(typeof r!="string")return r;const e=r.trim();return e?e.startsWith("#")||e.startsWith(".")||e.startsWith("[")?document.querySelector(e):document.getElementById(e)??document.querySelector(e):null}const C=/^[A-Za-z0-9._:-]{1,128}$/;function l(r){return r.replace(/^\[|\]$/g,"").toLowerCase()}function d(r){const e=l(r);return e==="localhost"||e==="127.0.0.1"||e==="::1"}function E(r){const e=r.split(".");if(e.length!==4)return!1;const t=e.map(i=>Number(i));if(t.some(i=>!Number.isInteger(i)||i<0||i>255))return!1;const[n,o]=t;return n===10||n===127||n===192&&o===168||n===172&&o>=16&&o<=31}function I(r){const e=l(r);return d(e)||E(e)?!0:e.endsWith(".local")||e.endsWith(".test")||e.endsWith(".localhost")}function x(r){const e=r.trim();if(!C.test(e))throw new Error("intentId is invalid.");return e}function M(r){const e=r.trim(),t=e.toLowerCase().startsWith("bearer ")?e.slice(7).trim():e;if(!t.toLowerCase().startsWith(h))throw new Error(`clientToken is invalid. Expected a token starting with ${h}.`);if(t.length>512||/\s/.test(t))throw new Error("clientToken is invalid.");return t}function f(r,e,t){let n;try{n=new URL(r)}catch{throw new Error(`${e} is not a valid URL.`)}if(n.username||n.password)throw new Error(`${e} must not include credentials.`);if(n.protocol==="https:"||n.protocol==="http:"&&t(n.hostname))return n;throw new Error(`${e} must be an https URL.`)}function O(r){const e=r?.trim()||g;if(!e)throw new Error("checkout origin is not configured.");return f(e,"checkout origin",d).origin}function U(r,e){return f(r,e,I).toString()}function T(r){const e=encodeURIComponent(r.intentId),t=new URL(`/pay/${e}`,r.checkoutOrigin);return r.mode==="redirect"?r.returnUrl&&t.searchParams.set("return_url",r.returnUrl):(t.searchParams.set("embed","1"),r.parentOrigin&&t.searchParams.set("origin",r.parentOrigin)),t.hash=`token=${encodeURIComponent(r.clientToken)}`,t.toString()}function L(r){if(!r||typeof r!="object")throw new Error("Checkout config is required.");if(!r.intentId?.trim())throw new Error("intentId is required.");const e=x(r.intentId),t=M(r.clientToken??""),n=O(r.checkoutOrigin),o=r.mode??"inline";if(o!=="inline"&&o!=="modal"&&o!=="redirect")throw new Error('mode must be "inline", "modal", or "redirect".');const i=r.returnUrl?U(r.returnUrl,"returnUrl"):void 0;return{intentId:e,clientToken:t,checkoutOrigin:n,mode:o,returnUrl:i}}class S{constructor(e){this.events=new u,this.iframeManager=null,this.mounted=!1,this.settled=!1,this.handleMessage=t=>{switch(t.type){case"checkout.ready":this.events.emit("ready",{intentId:t.checkoutId});break;case"checkout.success":this.settled=!0,this.events.emit("success",{intentId:t.checkoutId,reference:t.reference}),this.teardownFrame();break;case"checkout.cancel":this.settled=!0,this.events.emit("cancel",void 0),this.teardownFrame();break;case"checkout.error":this.settled=!0,this.events.emit("error",{code:t.code,message:t.message}),this.teardownFrame();break;case"checkout.resize":this.iframeManager?.setHeight(t.height);break}},this.config=L(e),this.containerOption=e.container}start(e){if(this.config.mode==="redirect"){this.redirect();return}if(this.config.mode==="modal"){this.open();return}this.mount(e??this.containerOption)}mount(e){this.mountFrame("inline",e??this.containerOption)}open(){this.mountFrame("modal",document.body)}redirect(){window.location.assign(this.getCheckoutUrl("redirect"))}on(e,t){return this.events.on(e,t)}close(){const e=this.mounted;this.teardownFrame(),e&&!this.settled&&(this.settled=!0,this.events.emit("cancel",void 0))}getCheckoutUrl(e){return T({intentId:this.config.intentId,clientToken:this.config.clientToken,checkoutOrigin:this.config.checkoutOrigin,mode:e,returnUrl:this.config.returnUrl,parentOrigin:e==="redirect"?void 0:window.location.origin})}mountFrame(e,t){if(this.mounted)throw new Error("Checkout is already mounted.");if(!t)throw new Error("Checkout container was not found.");const n=e==="modal"?document.body:v(t);if(!n)throw new Error("Checkout container was not found.");const o=this.getCheckoutUrl(e);this.iframeManager=new b({checkoutId:this.config.intentId,checkoutUrl:o,checkoutOrigin:this.config.checkoutOrigin,presentation:e,onMessage:this.handleMessage,onCloseRequest:()=>this.close()}),this.iframeManager.mount(n),this.mounted=!0}teardownFrame(){this.iframeManager?.destroy(),this.iframeManager=null,this.mounted=!1}}s.Checkout=S,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export declare const CHECKOUT_MESSAGE_SOURCE = "commandtransfer.checkout";
|
|
2
2
|
export declare const CLIENT_TOKEN_PREFIX = "ctc_";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Default hosted Checkout Web origin, baked in at build time from
|
|
5
|
+
* `VITE_CHECKOUT_ORIGIN`.
|
|
6
|
+
*
|
|
7
|
+
* Every published build — stable and prerelease alike — is built against
|
|
8
|
+
* PRODUCTION. Callers that need another environment pass
|
|
9
|
+
* `checkoutOrigin` to `new Checkout({ ... })` rather than installing a
|
|
10
|
+
* separately-built package.
|
|
6
11
|
*/
|
|
7
12
|
export declare const CHECKOUT_ORIGIN: string;
|
|
8
13
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAElE,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAM1C
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAElE,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAM1C;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,QAE3B,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -16,6 +16,18 @@ export interface CheckoutConfig {
|
|
|
16
16
|
* Ignored for inline/modal — handle `success` / `cancel` events instead.
|
|
17
17
|
*/
|
|
18
18
|
returnUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Hosted checkout origin to talk to. Defaults to the origin this package was
|
|
21
|
+
* built against, which is always production.
|
|
22
|
+
*
|
|
23
|
+
* Merchants should leave this unset. Set it only to point a non-production
|
|
24
|
+
* app at a non-production checkout, e.g.
|
|
25
|
+
* `checkoutOrigin: "https://ct-dev-checkout.web.app"`.
|
|
26
|
+
*
|
|
27
|
+
* Must be https; http is accepted only on loopback, for a checkout app
|
|
28
|
+
* running locally.
|
|
29
|
+
*/
|
|
30
|
+
checkoutOrigin?: string;
|
|
19
31
|
}
|
|
20
32
|
export interface CheckoutReady {
|
|
21
33
|
intentId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;AAE3D,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IAEjB,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;IAEpB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAEjC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;AAE3D,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IAEjB,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;IAEpB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAEjC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;;;;;OAUG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,eAAe,CAAC;IACzB,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAC3B,gBAAgB,GAChB,kBAAkB,GAClB,iBAAiB,GACjB,gBAAgB,GAChB,iBAAiB,CAAC;AAEtB,MAAM,MAAM,eAAe,GACvB;IACE,MAAM,EAAE,0BAA0B,CAAC;IACnC,IAAI,EAAE,gBAAgB,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,GACD;IACE,MAAM,EAAE,0BAA0B,CAAC;IACnC,IAAI,EAAE,kBAAkB,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,MAAM,EAAE,0BAA0B,CAAC;IACnC,IAAI,EAAE,iBAAiB,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;CACpB,GACD;IACE,MAAM,EAAE,0BAA0B,CAAC;IACnC,IAAI,EAAE,gBAAgB,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,MAAM,EAAE,0BAA0B,CAAC;IACnC,IAAI,EAAE,iBAAiB,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
package/dist/url.d.ts
CHANGED
|
@@ -5,7 +5,19 @@ export declare function isLocalHostname(hostname: string): boolean;
|
|
|
5
5
|
export declare function isMerchantDevHostname(hostname: string): boolean;
|
|
6
6
|
export declare function normalizeIntentId(value: string): string;
|
|
7
7
|
export declare function normalizeClientToken(value: string): string;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the hosted checkout origin.
|
|
10
|
+
*
|
|
11
|
+
* `override` (from `CheckoutConfig.checkoutOrigin`) wins; otherwise the origin
|
|
12
|
+
* baked in at build time is used. Keeping this overridable is what lets ONE
|
|
13
|
+
* published package serve production and non-production: the package is always
|
|
14
|
+
* built against production, and a staging app points itself elsewhere at
|
|
15
|
+
* runtime instead of installing a differently-built build.
|
|
16
|
+
*
|
|
17
|
+
* The override goes through the same validation as the baked value, so it must
|
|
18
|
+
* be https (http is allowed only on loopback, for a locally running checkout).
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveCheckoutOrigin(override?: string): string;
|
|
9
21
|
/** Merchant return / parent URLs — any https site, or http on local/LAN. */
|
|
10
22
|
export declare function assertSafeHttpUrl(value: string, field: string): string;
|
|
11
23
|
export declare function buildCheckoutUrl(options: {
|
package/dist/url.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAQ5D,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGzD;AAkBD,0DAA0D;AAC1D,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAQ/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMvD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiB1D;AA6BD,wBAAgB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAQ5D,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGzD;AAkBD,0DAA0D;AAC1D,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAQ/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMvD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiB1D;AA6BD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ/D;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,UAAU,CAAC;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,MAAM,CAiBT;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CA6BA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@integralscope/command-transfer-checkout-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7-dev.1",
|
|
4
4
|
"description": "Command Transfer Checkout Web SDK",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,4 +37,4 @@
|
|
|
37
37
|
"registry": "https://registry.npmjs.org",
|
|
38
38
|
"access": "public"
|
|
39
39
|
}
|
|
40
|
-
}
|
|
40
|
+
}
|