@terrawallet/pay-js 0.0.0-stage → 0.1.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 +202 -0
- package/NOTICE +15 -0
- package/README.md +77 -2
- package/dist/cdn/manifest.json +20 -0
- package/dist/cdn/sbom.cdx.json +50 -0
- package/dist/cdn/terra-pay.esm.js +52 -0
- package/dist/cdn/terra-pay.iife.js +52 -0
- package/dist/cdn-esm.d.ts +2 -0
- package/dist/cdn.d.ts +1 -0
- package/dist/checkout.d.ts +56 -0
- package/dist/dom.d.ts +21 -0
- package/dist/errors.d.ts +14 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +491 -0
- package/dist/protocol.d.ts +43 -0
- package/dist/sbom.cdx.json +26 -0
- package/dist/styles.d.ts +6 -0
- package/package.json +57 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Terra Wallet SDK
|
|
2
|
+
Copyright 2026 Terra Wallet (https://terrawallet.us)
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Terra Wallet.
|
|
5
|
+
Official source: https://github.com/theterrawallet/terra-sdk
|
|
6
|
+
Developers: https://developers.terrawallet.us
|
|
7
|
+
|
|
8
|
+
"Terra Wallet", "Terra Pay", "Terra Connect", "Terra Escrow" and the Terra Wallet
|
|
9
|
+
logo are trademarks of Terra Wallet. The Apache License 2.0 grants no permission
|
|
10
|
+
to use them (section 6), except as needed to describe the origin of the software.
|
|
11
|
+
A modified copy must not be presented as the official Terra Wallet SDK.
|
|
12
|
+
|
|
13
|
+
Third-party software: the optional WalletConnect add-on (terra-walletconnect.*)
|
|
14
|
+
bundles @walletconnect/sign-client and its dependencies, which are distributed
|
|
15
|
+
under their own licenses, not under this one. See each bundle's sbom.cdx.json.
|
package/README.md
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @terrawallet/pay-js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Open Terra Pay hosted checkout (`https://pay.terrawallet.us`) from any page.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { TerraPay } from "@terrawallet/pay-js";
|
|
7
|
+
|
|
8
|
+
// paymentIntentId / checkoutUrl come from YOUR server (it creates the payment intent with the secret key).
|
|
9
|
+
TerraPay.open({
|
|
10
|
+
checkoutUrl, // or paymentIntentId: "pi_...", or planId: "plan_..."
|
|
11
|
+
publishableKey: "tw_test_pk_...",
|
|
12
|
+
onSuccess: (r) => showThankYou(r), // UI only: fulfil from the webhook
|
|
13
|
+
onCancel: () => {},
|
|
14
|
+
onExpire: () => {},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
TerraPay.mountSubscribeButton(document.querySelector("#subscribe")!, { planId: "plan_...", publishableKey: "tw_test_pk_..." });
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Script tag: `dist/cdn/terra-pay.iife.js` (SRI hash in `dist/cdn/manifest.json`) exposes `window.TerraPay`.
|
|
21
|
+
|
|
22
|
+
## Modes
|
|
23
|
+
|
|
24
|
+
- `auto` (default): the modal on phones, a popup on desktops (browser wallet extensions, Terra Wallet included, do
|
|
25
|
+
not inject into iframes, so a desktop checkout needs its own window). A blocked popup falls back to the modal.
|
|
26
|
+
- `modal`: `<iframe sandbox="allow-scripts allow-same-origin allow-popups allow-forms">` inside a closed shadow root
|
|
27
|
+
and a native `<dialog>`, with a fixed "Secure checkout, pay.terrawallet.us" header. The checkout lets a page frame
|
|
28
|
+
it only after a server-side check: the publishable key must belong to the checkout's organization and your exact
|
|
29
|
+
https origin must be on its project's allowed origins (dashboard, project settings). Then it sends
|
|
30
|
+
`frame-ancestors <your origin>`; for anyone else it stays `frame-ancestors 'none'`. Inside the frame the checkout
|
|
31
|
+
shows "Paying on <your site>" and accepts pay actions only from real taps or clicks.
|
|
32
|
+
- `popup`: a centred window (a new tab on phones), with an overlay on your page to bring it back or cancel.
|
|
33
|
+
|
|
34
|
+
If the checkout does not report `ready` within `readyTimeoutMs` (default 20 s), `onError` receives a
|
|
35
|
+
`CHECKOUT_ERROR` that says why: the frame was refused (your origin is not an allowed origin of the publishable key)
|
|
36
|
+
or your page is not https. A modal then offers the shopper "Continue in a new window", which opens the same session
|
|
37
|
+
in a popup (from the shopper's tap, because browsers block popups opened from a timer); `handle.mode` reports
|
|
38
|
+
`popup` from then on. Messages go only to https pages, and localhost origins work only with test-mode keys.
|
|
39
|
+
|
|
40
|
+
Your own page must not send `Cross-Origin-Opener-Policy: same-origin` (use `same-origin-allow-popups`), otherwise
|
|
41
|
+
the browser cuts the link to the popup and the SDK sees an immediate cancel.
|
|
42
|
+
|
|
43
|
+
## Security
|
|
44
|
+
|
|
45
|
+
- Publishable keys only (`tw_test_pk_` / `tw_live_pk_` plus base64url). Anything containing `_sk_` (or starting
|
|
46
|
+
with `sk_`) or `whsec_`, in any case, throws `SECRET_KEY_REFUSED` before anything is shown.
|
|
47
|
+
- `checkoutUrl` must be exactly on `https://pay.terrawallet.us` with a known path (`/c/pi_`, `/l/plink_`,
|
|
48
|
+
`/i/inv_`, `/s/plan_`).
|
|
49
|
+
- A message is accepted only when `event.origin === "https://pay.terrawallet.us"`, `event.source` is the window or
|
|
50
|
+
iframe this call opened, and `data.sid` is this call's random 128-bit session id. Fields are type-checked and
|
|
51
|
+
copied; anything else is dropped. Once the checkout closes, the listener is gone.
|
|
52
|
+
- The iframe sandbox is the smallest set the checkout needs (scripts, its own origin for its API and Turnstile,
|
|
53
|
+
popups for wallet and explorer links, forms for its transaction-hash form). It never gets
|
|
54
|
+
`allow-top-navigation*`, `allow-popups-to-escape-sandbox` or `allow-modals`.
|
|
55
|
+
- The popup keeps `window.opener` (the checkout posts there, to your exact origin only). Its window name is random
|
|
56
|
+
and unrelated to the session id.
|
|
57
|
+
|
|
58
|
+
## Checkout page contract (what pay.terrawallet.us implements)
|
|
59
|
+
|
|
60
|
+
The checkout page receives `?embed=modal|popup&pk=<publishable key>&sid=<session id>&origin=<merchant origin>`
|
|
61
|
+
(`theme=light|dark` optional), each parameter exactly once. For `embed=modal` the checkout's Worker asks the API
|
|
62
|
+
(`GET /api/v1/checkout/:id/embed?origin=...`, the key in the Authorization header) and sends
|
|
63
|
+
`frame-ancestors <origin>` only when it says yes (`frame-ancestors 'none'` and `X-Frame-Options: DENY` otherwise).
|
|
64
|
+
The page checks `origin` the same way before posting, then posts to `window.parent` (modal) or `window.opener`
|
|
65
|
+
(popup) with `targetOrigin` set to that origin:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
{ terraPay: 1, sid, type: "ready" }
|
|
69
|
+
{ terraPay: 1, sid, type: "resize", height: 640 }
|
|
70
|
+
{ terraPay: 1, sid, type: "success", status: "succeeded" | "processing", paymentIntentId, txHash, chain }
|
|
71
|
+
{ terraPay: 1, sid, type: "expire", paymentIntentId }
|
|
72
|
+
{ terraPay: 1, sid, type: "error", errorCode: "QUOTE_FAILED", errorMessage: "..." }
|
|
73
|
+
{ terraPay: 1, sid, type: "cancel" } // the shopper cancelled
|
|
74
|
+
{ terraPay: 1, sid, type: "close" } // the shopper pressed Done
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The popup must not send `Cross-Origin-Opener-Policy: same-origin` (use `same-origin-allow-popups` or none),
|
|
78
|
+
otherwise the merchant page loses the window reference and sees an immediate cancel.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"package": "@terrawallet/pay-js",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"generated": "build",
|
|
5
|
+
"note": "Pin the exact versioned URL and add integrity + crossorigin=\"anonymous\" to the script tag.",
|
|
6
|
+
"files": {
|
|
7
|
+
"terra-pay.iife.js": {
|
|
8
|
+
"integrity": "sha384-F7k26iGNzk2yxlZq8VOTopxgVTDGfc2e65HD/frd7UE/zzASeycEFrFfk2PwUTjy",
|
|
9
|
+
"bytes": 17109,
|
|
10
|
+
"gzipBytes": 6506,
|
|
11
|
+
"format": "iife"
|
|
12
|
+
},
|
|
13
|
+
"terra-pay.esm.js": {
|
|
14
|
+
"integrity": "sha384-ioMf4BB51CjeYTkU4KIP5Ql9nFMTmAY2dIM/duRgB9jwlL4owv7kHUv1mCwThsAO",
|
|
15
|
+
"bytes": 17339,
|
|
16
|
+
"gzipBytes": 6604,
|
|
17
|
+
"format": "esm"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bomFormat": "CycloneDX",
|
|
3
|
+
"specVersion": "1.5",
|
|
4
|
+
"serialNumber": "urn:uuid:7b2b544c-bf79-4fa2-adcd-ae2ea2cb3d01",
|
|
5
|
+
"version": 1,
|
|
6
|
+
"metadata": {
|
|
7
|
+
"timestamp": "2026-11-27T23:02:28.749Z",
|
|
8
|
+
"tools": {
|
|
9
|
+
"components": [
|
|
10
|
+
{
|
|
11
|
+
"type": "application",
|
|
12
|
+
"name": "terra-sdk-sbom",
|
|
13
|
+
"version": "1"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"component": {
|
|
18
|
+
"type": "library",
|
|
19
|
+
"name": "@terrawallet/pay-js (CDN bundles)",
|
|
20
|
+
"version": "0.1.0",
|
|
21
|
+
"bom-ref": "terra-sdk:@terrawallet/pay-js (CDN bundles)@0.1.0"
|
|
22
|
+
},
|
|
23
|
+
"properties": [
|
|
24
|
+
{
|
|
25
|
+
"name": "terra:cdnFile:terra-pay.iife.js",
|
|
26
|
+
"value": "sha384-F7k26iGNzk2yxlZq8VOTopxgVTDGfc2e65HD/frd7UE/zzASeycEFrFfk2PwUTjy"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "terra:cdnFile:terra-pay.esm.js",
|
|
30
|
+
"value": "sha384-ioMf4BB51CjeYTkU4KIP5Ql9nFMTmAY2dIM/duRgB9jwlL4owv7kHUv1mCwThsAO"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
"components": [
|
|
35
|
+
{
|
|
36
|
+
"type": "library",
|
|
37
|
+
"bom-ref": "pkg:npm/%40terrawallet/pay-js@0.1.0",
|
|
38
|
+
"name": "@terrawallet/pay-js",
|
|
39
|
+
"version": "0.1.0",
|
|
40
|
+
"purl": "pkg:npm/%40terrawallet/pay-js@0.1.0",
|
|
41
|
+
"licenses": [
|
|
42
|
+
{
|
|
43
|
+
"license": {
|
|
44
|
+
"id": "Apache-2.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var pe=Object.defineProperty;var he=(e,n,t)=>n in e?pe(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var A=(e,n,t)=>he(e,typeof n!="symbol"?n+"":n,t);var Q=`
|
|
2
|
+
:host{all:initial}
|
|
3
|
+
*{box-sizing:border-box}
|
|
4
|
+
.t{--canvas:#060912;--l1:#0C1322;--l2:#111A2E;--l3:#18233C;--line:rgba(255,255,255,.08);--line2:rgba(255,255,255,.14);--fg:#F5F7FF;--muted:#93A0B8;--brand:#0A5BFF;--brand2:#5B8BFF;--ok:#2ECC71;--shadow:0 16px 48px rgba(0,0,0,.55);color-scheme:dark}
|
|
5
|
+
.t[data-theme=light]{--canvas:#F7F9FC;--l1:#fff;--l2:#F1F4F9;--l3:#E6EBF4;--line:rgba(11,18,33,.08);--line2:rgba(11,18,33,.14);--fg:#0B1221;--muted:#5B6577;--brand2:#0A5BFF;--ok:#13703D;--shadow:0 16px 48px rgba(11,18,33,.18);color-scheme:light}
|
|
6
|
+
@media (prefers-color-scheme:light){.t[data-theme=auto]{--canvas:#F7F9FC;--l1:#fff;--l2:#F1F4F9;--l3:#E6EBF4;--line:rgba(11,18,33,.08);--line2:rgba(11,18,33,.14);--fg:#0B1221;--muted:#5B6577;--brand2:#0A5BFF;--ok:#13703D;--shadow:0 16px 48px rgba(11,18,33,.18);color-scheme:light}}
|
|
7
|
+
dialog{position:fixed;inset:0;margin:0;padding:0;border:0;background:transparent;max-width:none;max-height:none;width:100%;height:100%;overflow:hidden;font:14px/20px Inter,ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;-webkit-font-smoothing:antialiased}
|
|
8
|
+
dialog::backdrop{background:rgba(3,6,14,.62)}
|
|
9
|
+
dialog:not([open]){display:none}
|
|
10
|
+
.scrim{position:absolute;inset:0}
|
|
11
|
+
.panel{position:absolute;left:0;right:0;bottom:0;display:flex;flex-direction:column;height:min(92dvh,92vh);background:var(--l1);color:var(--fg);border-top:1px solid var(--line2);border-radius:24px 24px 0 0;box-shadow:var(--shadow);overflow:hidden;animation:sheet .24s cubic-bezier(.32,.72,0,1)}
|
|
12
|
+
.card{position:absolute;left:16px;right:16px;bottom:16px;padding:20px;background:var(--l1);color:var(--fg);border:1px solid var(--line2);border-radius:24px;box-shadow:var(--shadow);animation:sheet .24s cubic-bezier(.32,.72,0,1)}
|
|
13
|
+
@media (min-width:641px){
|
|
14
|
+
.panel{left:50%;top:50%;bottom:auto;width:440px;height:min(720px,calc(100vh - 48px));border:1px solid var(--line2);border-radius:24px;transform:translate(-50%,-50%);animation:pop .16s ease-out}
|
|
15
|
+
.card{left:50%;top:50%;bottom:auto;right:auto;width:380px;transform:translate(-50%,-50%);animation:pop .16s ease-out}
|
|
16
|
+
}
|
|
17
|
+
.bar{display:flex;align-items:center;gap:10px;padding:12px 12px 12px 16px;border-bottom:1px solid var(--line);background:var(--l1)}
|
|
18
|
+
.lock{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:10px;background:rgba(46,204,113,.12);color:var(--ok);flex:none}
|
|
19
|
+
.who{display:flex;flex-direction:column;min-width:0;flex:1}
|
|
20
|
+
.who strong{font-size:14px;line-height:18px;font-weight:600}
|
|
21
|
+
.origin{font-size:12px;line-height:16px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
22
|
+
.x{all:unset;display:flex;align-items:center;justify-content:center;width:36px;height:36px;border-radius:12px;color:var(--muted);cursor:pointer;flex:none}
|
|
23
|
+
.x:hover{background:var(--l2);color:var(--fg)}
|
|
24
|
+
.x:focus-visible,.btn:focus-visible{outline:none;box-shadow:0 0 0 3px rgba(91,139,255,.45)}
|
|
25
|
+
.frame{position:relative;flex:1;background:var(--canvas)}
|
|
26
|
+
iframe{position:absolute;inset:0;width:100%;height:100%;border:0;background:transparent;color-scheme:normal}
|
|
27
|
+
.loading{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;color:var(--muted);font-size:13px}
|
|
28
|
+
.loading[hidden]{display:none}
|
|
29
|
+
.spin{width:28px;height:28px;border-radius:50%;border:2.5px solid var(--line2);border-top-color:var(--brand2);animation:spin .8s linear infinite}
|
|
30
|
+
h2{margin:12px 0 4px;font-size:18px;line-height:24px;font-weight:700;letter-spacing:-.01em}
|
|
31
|
+
p{margin:0;color:var(--muted)}
|
|
32
|
+
.row{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:20px}
|
|
33
|
+
.btn{all:unset;box-sizing:border-box;display:flex;align-items:center;justify-content:center;gap:8px;height:44px;padding:0 16px;border-radius:14px;font-weight:600;font-size:14px;cursor:pointer;text-align:center;transition:transform .15s ease-out,filter .15s ease-out}
|
|
34
|
+
.btn:active{transform:scale(.98)}
|
|
35
|
+
.primary{background:linear-gradient(135deg,#0A5BFF 0%,#5B8BFF 100%);color:#fff;box-shadow:0 8px 22px rgba(10,91,255,.38)}
|
|
36
|
+
.primary:hover{filter:brightness(1.1)}
|
|
37
|
+
.secondary{background:var(--l2);color:var(--fg);border:1px solid var(--line2)}
|
|
38
|
+
.secondary:hover{background:var(--l3)}
|
|
39
|
+
@keyframes sheet{from{transform:translateY(100%)}to{transform:translateY(0)}}
|
|
40
|
+
@keyframes pop{from{opacity:0;transform:translate(-50%,-50%) scale(.96)}to{opacity:1;transform:translate(-50%,-50%) scale(1)}}
|
|
41
|
+
@keyframes spin{to{transform:rotate(360deg)}}
|
|
42
|
+
@media (prefers-reduced-motion:reduce){*{animation-duration:1ms!important;transition-duration:1ms!important}}
|
|
43
|
+
`,ee=`
|
|
44
|
+
:host{all:initial;display:inline-block;vertical-align:middle}
|
|
45
|
+
*{box-sizing:border-box}
|
|
46
|
+
button{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:44px;padding:0 20px;border-radius:var(--terra-radius,14px);font:600 15px/20px Inter,ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;color:#fff;background:linear-gradient(135deg,#0A5BFF 0%,#5B8BFF 100%);box-shadow:0 8px 22px rgba(10,91,255,.32);cursor:pointer;transition:transform .15s ease-out,filter .15s ease-out;-webkit-font-smoothing:antialiased}
|
|
47
|
+
button:hover{filter:brightness(1.1)}
|
|
48
|
+
button:active{transform:scale(.98)}
|
|
49
|
+
button:focus-visible{outline:none;box-shadow:0 0 0 3px rgba(91,139,255,.45)}
|
|
50
|
+
button[disabled]{opacity:.5;cursor:default}
|
|
51
|
+
@media (prefers-reduced-motion:reduce){button{transition:none}}
|
|
52
|
+
`;function a(e,n={},...t){let o=document.createElement(e);for(let[i,s]of Object.entries(n))s!==void 0&&o.setAttribute(i,s);for(let i of t)i!=null&&i!==!1&&o.append(i);return o}var te="http://www.w3.org/2000/svg";function g(e,n=20,t={}){let o=document.createElementNS(te,"svg");o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("width",String(n)),o.setAttribute("height",String(n)),o.setAttribute("aria-hidden","true"),o.setAttribute("focusable","false"),t.cls&&o.setAttribute("class",t.cls),o.setAttribute("fill",t.fill?"currentColor":"none"),t.fill||(o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","2"),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"));for(let i of e){let s=document.createElementNS(te,"path");s.setAttribute("d",i),o.append(s)}return o}var y={lock:["M7 11V8a5 5 0 0 1 10 0v3","M5 11h14v10H5z"],close:["M18 6 6 18","M6 6l12 12"],external:["M14 4h6v6","M20 4 10 14","M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"]};function U(e,n){try{let o=new CSSStyleSheet;o.replaceSync(n),e.adoptedStyleSheets=[...e.adoptedStyleSheets,o];return}catch{}let t=document.createElement("style");t.textContent=n,e.prepend(t)}var B=()=>typeof matchMedia=="function"&&matchMedia("(max-width: 640px), (pointer: coarse) and (max-width: 900px)").matches;var fe="https://developers.terrawallet.us/docs/errors",me={SECRET_KEY_REFUSED:"A secret key was passed to browser code and was refused. Use your publishable key (tw_test_pk_ or tw_live_pk_) here, and rotate that secret key in the Terra dashboard now: anything shipped to a browser is public.",INVALID_PUBLISHABLE_KEY:"Use a publishable key that starts with tw_test_pk_ or tw_live_pk_.",INVALID_CHECKOUT:"Pass a checkout URL on https://pay.terrawallet.us, a payment intent id (pi_...), or a plan id (plan_...).",POPUP_BLOCKED:"The browser blocked the checkout window. Open checkout from a click.",UNSUPPORTED_ENVIRONMENT:"Terra Pay checkout needs a browser.",CHECKOUT_ERROR:"Checkout reported an error."},d=class extends Error{constructor(t,o){super(o||me[t]);A(this,"name","TerraPayError");A(this,"code");A(this,"docUrl");this.code=t,this.docUrl=`${fe}#${t.toLowerCase()}`}};function P(e){if(typeof e=="string"&&/(^|_)sk_|whsec_/i.test(e))throw new d("SECRET_KEY_REFUSED");if(typeof e!="string"||!/^tw_(test|live)_pk_[A-Za-z0-9_-]{8,128}$/.test(e))throw new d("INVALID_PUBLISHABLE_KEY")}var k="https://pay.terrawallet.us",w={pi:/^pi_[A-Za-z0-9]{6,64}$/,plink:/^plink_[A-Za-z0-9]{6,64}$/,inv:/^inv_[A-Za-z0-9]{6,64}$/,plan:/^plan_[A-Za-z0-9]{6,64}$/,sub:/^sub_[A-Za-z0-9]{6,64}$/},ge={c:"pi",l:"plink",i:"inv",s:"plan"};function D(){let e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,n=>n.toString(16).padStart(2,"0")).join("")}function oe(e){if([e.checkoutUrl,e.paymentIntentId,e.planId].filter(s=>s!==void 0).length!==1)throw new d("INVALID_CHECKOUT");if(e.paymentIntentId!==void 0){if(!w.pi.test(e.paymentIntentId))throw new d("INVALID_CHECKOUT","paymentIntentId must look like pi_...");return`/c/${e.paymentIntentId}`}if(e.planId!==void 0){if(!w.plan.test(e.planId))throw new d("INVALID_CHECKOUT","planId must look like plan_...");return`/s/${e.planId}`}let t;try{t=new URL(String(e.checkoutUrl))}catch{throw new d("INVALID_CHECKOUT")}if(t.origin!==k||t.username||t.password)throw new d("INVALID_CHECKOUT","checkoutUrl must be on https://pay.terrawallet.us.");let o=/^\/([clis])\/([A-Za-z0-9_]+)\/?$/.exec(t.pathname),i=o?ge[o[1]]:void 0;if(!o||!i||!w[i].test(o[2]))throw new d("INVALID_CHECKOUT","Unrecognised checkout URL path.");return`/${o[1]}/${o[2]}`}function V(e,n){let t=new URL(oe(e),k);return t.searchParams.set("embed",n.mode),t.searchParams.set("pk",n.publishableKey),t.searchParams.set("sid",n.sid),t.searchParams.set("origin",n.parentOrigin),(n.theme==="light"||n.theme==="dark")&&t.searchParams.set("theme",n.theme),t.toString()}var be=new Set(["ready","resize","success","cancel","expire","error","close"]),x=(e,n)=>typeof e=="string"&&n.test(e)?e:void 0;function $(e,n){if(e.origin!==k||!n.source||e.source!==n.source)return null;let t=e.data;if(!t||typeof t!="object"||Array.isArray(t)||t.terraPay!==1||t.sid!==n.sid||typeof t.type!="string"||!be.has(t.type))return null;let o={type:t.type};(t.status==="succeeded"||t.status==="processing")&&(o.status=t.status);let i=x(t.paymentIntentId,w.pi);i&&(o.paymentIntentId=i);let s=x(t.subscriptionId,w.sub);s&&(o.subscriptionId=s);let c=x(t.invoiceId,w.inv);c&&(o.invoiceId=c);let C=x(t.txHash,/^(0x)?[A-Za-z0-9]{16,128}$/);C&&(o.txHash=C);let E=x(t.chain,/^[a-z0-9-]{2,32}$/);E&&(o.chain=E),typeof t.height=="number"&&Number.isFinite(t.height)&&(o.height=Math.min(4e3,Math.max(120,Math.round(t.height))));let _=x(t.errorCode,/^[A-Z][A-Z0-9_]{1,63}$/);return _&&(o.errorCode=_),typeof t.errorMessage=="string"&&(o.errorMessage=t.errorMessage.replace(/[\u0000-\u001f\u007f]/g," ").slice(0,300)),o.type==="success"&&!o.status&&(o.status="succeeded"),o}var ne="allow-scripts allow-same-origin allow-popups allow-forms",re=2e4,T=null;function L(e){if(typeof window>"u"||typeof document>"u")throw new d("UNSUPPORTED_ENVIRONMENT");if(P(e.publishableKey),T)return T.focus(),T;let n=D(),t=e.theme??"auto",o=e.mode??"auto",i=r=>V(e,{publishableKey:e.publishableKey,mode:r,sid:n,parentOrigin:location.origin,theme:t});i("modal");let s=o==="auto"?B()?"modal":"popup":o,c=null,C=()=>{let p=Math.max(0,Math.round((window.screenX??0)+((window.outerWidth??460)-460)/2)),u=Math.max(0,Math.round((window.screenY??0)+((window.outerHeight??760)-760)/2));return window.open(i("popup"),`terra_pay_${D().slice(0,12)}`,`popup=yes,width=460,height=760,left=${p},top=${u}`)};if(s==="popup"&&(c=C(),!c)){if(o==="popup")throw new d("POPUP_BLOCKED");s="modal"}let E,_=new Promise(r=>E=r),h=null,S=!1,H=document.activeElement,K=document.createElement("terra-pay-checkout"),M=K.attachShadow({mode:"closed"});U(M,Q);let f=a("dialog",{"aria-labelledby":"t","aria-describedby":"d"}),v=a("div",{class:"t","data-theme":t}),O=a("button",{class:"x",type:"button","aria-label":"Close checkout"},g(y.close,20)),m=null,I=null,z=a("div",{class:"scrim"});function ae(){return I=a("div",{class:"loading",role:"status"},a("span",{class:"spin"}),"Loading secure checkout"),m=a("iframe",{title:"Terra Pay checkout",sandbox:ne,allow:"clipboard-write",referrerpolicy:"strict-origin-when-cross-origin"}),m.src=i("modal"),a("div",{class:"panel"},a("header",{class:"bar"},a("span",{class:"lock"},g(y.lock,18)),a("div",{class:"who"},a("strong",{id:"t"},"Secure checkout"),a("span",{class:"origin",id:"d"},"pay.terrawallet.us")),O),a("div",{class:"frame"},I,m))}function j(){let r=a("button",{class:"btn primary",type:"button"},g(y.external,18),"Show window"),l=a("button",{class:"btn secondary",type:"button"},"Cancel payment");return r.addEventListener("click",()=>c?.focus()),l.addEventListener("click",()=>b({status:"canceled"},!0)),a("div",{class:"card",role:"document"},a("span",{class:"lock"},g(y.lock,18)),a("h2",{id:"t"},"Finish paying in the Terra Pay window"),a("p",{id:"d"},"Secure checkout opened on pay.terrawallet.us. Your payment continues there."),a("div",{class:"row"},l,r))}v.append(z,s==="modal"?ae():j()),f.append(v),M.append(f),document.body.append(K);let Y=document.documentElement.style.getPropertyValue("overflow");if(document.documentElement.style.setProperty("overflow","hidden"),typeof f.showModal=="function")try{f.showModal()}catch{f.setAttribute("open","")}else f.setAttribute("open","");(s==="modal"?O:v.querySelector(".primary"))?.focus(),O.addEventListener("click",()=>b(h??{status:"canceled"},!0)),v.querySelector(".scrim")?.addEventListener("click",()=>c&&!c.closed?c.focus():void 0),f.addEventListener("cancel",r=>{r.preventDefault(),b(h??{status:"canceled"},!0)}),f.addEventListener("keydown",r=>{if(r.key!=="Tab")return;let l=[...M.querySelectorAll("button, iframe")],p=l[0],u=l[l.length-1],N=M.activeElement;!p||!u||(r.shiftKey&&(N===p||!N)?(r.preventDefault(),u.focus()):!r.shiftKey&&N===u&&(r.preventDefault(),p.focus()))});let ie=()=>s==="modal"?m?.contentWindow??null:c,Z=r=>{let l=$(r,{source:ie(),sid:n});l&&ue(l)};window.addEventListener("message",Z);let F,G=()=>{F=setInterval(()=>c?.closed&&b(h??{status:"canceled"},!1),400)};s==="popup"&&G();let W=!1,ce=typeof e.readyTimeoutMs=="number"&&Number.isFinite(e.readyTimeoutMs)&&e.readyTimeoutMs>0?e.readyTimeoutMs:re,R,q=()=>{clearTimeout(R),R=setTimeout(le,ce)};function le(){if(S||W)return;let r=location.protocol==="https:";if(s==="modal"){let p=r?"The checkout could not load in a frame on this page: check that this site is an allowed origin of the publishable key (dashboard, project settings).":"The checkout sends its messages only to https pages.";e.onError?.(new d("CHECKOUT_ERROR",`The checkout did not connect to this page. ${p} The shopper can continue in a new window.`));let u=a("button",{class:"btn primary",type:"button"},g(y.external,18),"Continue in a new window");u.addEventListener("click",()=>de(u)),I?.replaceChildren(a("p",{},"The secure checkout could not open here."),u),u.focus();return}let l=r?"Check that this site is an allowed origin of the publishable key (dashboard, project settings).":"The checkout sends its messages only to https pages.";e.onError?.(new d("CHECKOUT_ERROR",`The checkout did not connect to this page. ${l}`))}q();function de(r){if(S||s!=="modal")return;let l=C();if(!l){e.onError?.(new d("POPUP_BLOCKED")),r.focus();return}c=l,s="popup",m?.remove(),m=null,I=null;let p=j();v.replaceChildren(z,p),p.querySelector(".primary")?.focus(),G(),q()}function X(r,l){let p={status:l};for(let u of["paymentIntentId","subscriptionId","invoiceId","txHash","chain"])r[u]&&(p[u]=r[u]);return p}function ue(r){switch(r.type){case"ready":W=!0,clearTimeout(R),I?.setAttribute("hidden",""),e.onReady?.();break;case"resize":m&&r.height&&!B()&&m.style.setProperty("min-height",`${Math.min(r.height,window.innerHeight-120)}px`);break;case"success":h=X(r,r.status??"succeeded"),e.onSuccess?.(h);break;case"expire":h=X(r,"expired"),e.onExpire?.(h);break;case"error":e.onError?.(new d("CHECKOUT_ERROR",r.errorMessage?`Checkout: ${r.errorMessage}`:void 0));break;case"cancel":b({status:"canceled"},!0);break;case"close":b(h??{status:"canceled"},!0);break}}function b(r,l){if(!S){S=!0,window.removeEventListener("message",Z),F&&clearInterval(F),clearTimeout(R),l&&c&&!c.closed&&c.close();try{f.close()}catch{}K.remove(),Y?document.documentElement.style.setProperty("overflow",Y):document.documentElement.style.removeProperty("overflow"),H&&document.contains(H)&&H.focus({preventScroll:!0}),T=null,r.status==="canceled"&&e.onCancel?.(),e.onClose?.(r),E(r)}}let J={get mode(){return s},closed:_,close:()=>b(h??{status:"canceled"},!0),focus:()=>c&&!c.closed?c.focus():O.focus()};return T=J,J}var ye="0.1.0";function xe(e){return L(e)}function se(e,n){P(n.publishableKey);let t=document.createElement("terra-pay-js-button"),o=t.attachShadow({mode:"closed"});U(o,ee),typeof n.radius=="number"&&t.style.setProperty("--terra-radius",`${Math.min(24,Math.max(0,n.radius))}px`);let i=(n.label??(n.planId?"Subscribe with Terra":"Pay with Terra")).slice(0,60),s=a("button",{type:"button"},g(["M7 11V8a5 5 0 0 1 10 0v3","M5 11h14v10H5z"],18),i);return s.addEventListener("click",()=>{s.disabled=!0,L(n).closed.finally(()=>s.disabled=!1)}),o.append(s),e.append(t),()=>t.remove()}function we(e,n){return se(e,n)}var Fe=Object.freeze({open:L,subscribe:xe,mountButton:se,mountSubscribeButton:we,CHECKOUT_ORIGIN:k,VERSION:ye});export{k as CHECKOUT_ORIGIN,re as DEFAULT_READY_TIMEOUT_MS,ne as IFRAME_SANDBOX,Fe as TerraPay,d as TerraPayError,ye as VERSION,P as assertPublishableKey,V as buildCheckoutUrl,oe as checkoutPath,se as mountButton,we as mountSubscribeButton,L as openCheckout,$ as parseCheckoutMessage,xe as subscribe};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";(()=>{var ue=Object.defineProperty;var pe=(e,n,t)=>n in e?ue(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var P=(e,n,t)=>pe(e,typeof n!="symbol"?n+"":n,t);var X=`
|
|
2
|
+
:host{all:initial}
|
|
3
|
+
*{box-sizing:border-box}
|
|
4
|
+
.t{--canvas:#060912;--l1:#0C1322;--l2:#111A2E;--l3:#18233C;--line:rgba(255,255,255,.08);--line2:rgba(255,255,255,.14);--fg:#F5F7FF;--muted:#93A0B8;--brand:#0A5BFF;--brand2:#5B8BFF;--ok:#2ECC71;--shadow:0 16px 48px rgba(0,0,0,.55);color-scheme:dark}
|
|
5
|
+
.t[data-theme=light]{--canvas:#F7F9FC;--l1:#fff;--l2:#F1F4F9;--l3:#E6EBF4;--line:rgba(11,18,33,.08);--line2:rgba(11,18,33,.14);--fg:#0B1221;--muted:#5B6577;--brand2:#0A5BFF;--ok:#13703D;--shadow:0 16px 48px rgba(11,18,33,.18);color-scheme:light}
|
|
6
|
+
@media (prefers-color-scheme:light){.t[data-theme=auto]{--canvas:#F7F9FC;--l1:#fff;--l2:#F1F4F9;--l3:#E6EBF4;--line:rgba(11,18,33,.08);--line2:rgba(11,18,33,.14);--fg:#0B1221;--muted:#5B6577;--brand2:#0A5BFF;--ok:#13703D;--shadow:0 16px 48px rgba(11,18,33,.18);color-scheme:light}}
|
|
7
|
+
dialog{position:fixed;inset:0;margin:0;padding:0;border:0;background:transparent;max-width:none;max-height:none;width:100%;height:100%;overflow:hidden;font:14px/20px Inter,ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;-webkit-font-smoothing:antialiased}
|
|
8
|
+
dialog::backdrop{background:rgba(3,6,14,.62)}
|
|
9
|
+
dialog:not([open]){display:none}
|
|
10
|
+
.scrim{position:absolute;inset:0}
|
|
11
|
+
.panel{position:absolute;left:0;right:0;bottom:0;display:flex;flex-direction:column;height:min(92dvh,92vh);background:var(--l1);color:var(--fg);border-top:1px solid var(--line2);border-radius:24px 24px 0 0;box-shadow:var(--shadow);overflow:hidden;animation:sheet .24s cubic-bezier(.32,.72,0,1)}
|
|
12
|
+
.card{position:absolute;left:16px;right:16px;bottom:16px;padding:20px;background:var(--l1);color:var(--fg);border:1px solid var(--line2);border-radius:24px;box-shadow:var(--shadow);animation:sheet .24s cubic-bezier(.32,.72,0,1)}
|
|
13
|
+
@media (min-width:641px){
|
|
14
|
+
.panel{left:50%;top:50%;bottom:auto;width:440px;height:min(720px,calc(100vh - 48px));border:1px solid var(--line2);border-radius:24px;transform:translate(-50%,-50%);animation:pop .16s ease-out}
|
|
15
|
+
.card{left:50%;top:50%;bottom:auto;right:auto;width:380px;transform:translate(-50%,-50%);animation:pop .16s ease-out}
|
|
16
|
+
}
|
|
17
|
+
.bar{display:flex;align-items:center;gap:10px;padding:12px 12px 12px 16px;border-bottom:1px solid var(--line);background:var(--l1)}
|
|
18
|
+
.lock{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:10px;background:rgba(46,204,113,.12);color:var(--ok);flex:none}
|
|
19
|
+
.who{display:flex;flex-direction:column;min-width:0;flex:1}
|
|
20
|
+
.who strong{font-size:14px;line-height:18px;font-weight:600}
|
|
21
|
+
.origin{font-size:12px;line-height:16px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
22
|
+
.x{all:unset;display:flex;align-items:center;justify-content:center;width:36px;height:36px;border-radius:12px;color:var(--muted);cursor:pointer;flex:none}
|
|
23
|
+
.x:hover{background:var(--l2);color:var(--fg)}
|
|
24
|
+
.x:focus-visible,.btn:focus-visible{outline:none;box-shadow:0 0 0 3px rgba(91,139,255,.45)}
|
|
25
|
+
.frame{position:relative;flex:1;background:var(--canvas)}
|
|
26
|
+
iframe{position:absolute;inset:0;width:100%;height:100%;border:0;background:transparent;color-scheme:normal}
|
|
27
|
+
.loading{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;color:var(--muted);font-size:13px}
|
|
28
|
+
.loading[hidden]{display:none}
|
|
29
|
+
.spin{width:28px;height:28px;border-radius:50%;border:2.5px solid var(--line2);border-top-color:var(--brand2);animation:spin .8s linear infinite}
|
|
30
|
+
h2{margin:12px 0 4px;font-size:18px;line-height:24px;font-weight:700;letter-spacing:-.01em}
|
|
31
|
+
p{margin:0;color:var(--muted)}
|
|
32
|
+
.row{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:20px}
|
|
33
|
+
.btn{all:unset;box-sizing:border-box;display:flex;align-items:center;justify-content:center;gap:8px;height:44px;padding:0 16px;border-radius:14px;font-weight:600;font-size:14px;cursor:pointer;text-align:center;transition:transform .15s ease-out,filter .15s ease-out}
|
|
34
|
+
.btn:active{transform:scale(.98)}
|
|
35
|
+
.primary{background:linear-gradient(135deg,#0A5BFF 0%,#5B8BFF 100%);color:#fff;box-shadow:0 8px 22px rgba(10,91,255,.38)}
|
|
36
|
+
.primary:hover{filter:brightness(1.1)}
|
|
37
|
+
.secondary{background:var(--l2);color:var(--fg);border:1px solid var(--line2)}
|
|
38
|
+
.secondary:hover{background:var(--l3)}
|
|
39
|
+
@keyframes sheet{from{transform:translateY(100%)}to{transform:translateY(0)}}
|
|
40
|
+
@keyframes pop{from{opacity:0;transform:translate(-50%,-50%) scale(.96)}to{opacity:1;transform:translate(-50%,-50%) scale(1)}}
|
|
41
|
+
@keyframes spin{to{transform:rotate(360deg)}}
|
|
42
|
+
@media (prefers-reduced-motion:reduce){*{animation-duration:1ms!important;transition-duration:1ms!important}}
|
|
43
|
+
`,J=`
|
|
44
|
+
:host{all:initial;display:inline-block;vertical-align:middle}
|
|
45
|
+
*{box-sizing:border-box}
|
|
46
|
+
button{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:44px;padding:0 20px;border-radius:var(--terra-radius,14px);font:600 15px/20px Inter,ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;color:#fff;background:linear-gradient(135deg,#0A5BFF 0%,#5B8BFF 100%);box-shadow:0 8px 22px rgba(10,91,255,.32);cursor:pointer;transition:transform .15s ease-out,filter .15s ease-out;-webkit-font-smoothing:antialiased}
|
|
47
|
+
button:hover{filter:brightness(1.1)}
|
|
48
|
+
button:active{transform:scale(.98)}
|
|
49
|
+
button:focus-visible{outline:none;box-shadow:0 0 0 3px rgba(91,139,255,.45)}
|
|
50
|
+
button[disabled]{opacity:.5;cursor:default}
|
|
51
|
+
@media (prefers-reduced-motion:reduce){button{transition:none}}
|
|
52
|
+
`;function a(e,n={},...t){let o=document.createElement(e);for(let[i,s]of Object.entries(n))s!==void 0&&o.setAttribute(i,s);for(let i of t)i!=null&&i!==!1&&o.append(i);return o}var Q="http://www.w3.org/2000/svg";function g(e,n=20,t={}){let o=document.createElementNS(Q,"svg");o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("width",String(n)),o.setAttribute("height",String(n)),o.setAttribute("aria-hidden","true"),o.setAttribute("focusable","false"),t.cls&&o.setAttribute("class",t.cls),o.setAttribute("fill",t.fill?"currentColor":"none"),t.fill||(o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","2"),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"));for(let i of e){let s=document.createElementNS(Q,"path");s.setAttribute("d",i),o.append(s)}return o}var y={lock:["M7 11V8a5 5 0 0 1 10 0v3","M5 11h14v10H5z"],close:["M18 6 6 18","M6 6l12 12"],external:["M14 4h6v6","M20 4 10 14","M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"]};function A(e,n){try{let o=new CSSStyleSheet;o.replaceSync(n),e.adoptedStyleSheets=[...e.adoptedStyleSheets,o];return}catch{}let t=document.createElement("style");t.textContent=n,e.prepend(t)}var B=()=>typeof matchMedia=="function"&&matchMedia("(max-width: 640px), (pointer: coarse) and (max-width: 900px)").matches;var he="https://developers.terrawallet.us/docs/errors",fe={SECRET_KEY_REFUSED:"A secret key was passed to browser code and was refused. Use your publishable key (tw_test_pk_ or tw_live_pk_) here, and rotate that secret key in the Terra dashboard now: anything shipped to a browser is public.",INVALID_PUBLISHABLE_KEY:"Use a publishable key that starts with tw_test_pk_ or tw_live_pk_.",INVALID_CHECKOUT:"Pass a checkout URL on https://pay.terrawallet.us, a payment intent id (pi_...), or a plan id (plan_...).",POPUP_BLOCKED:"The browser blocked the checkout window. Open checkout from a click.",UNSUPPORTED_ENVIRONMENT:"Terra Pay checkout needs a browser.",CHECKOUT_ERROR:"Checkout reported an error."},d=class extends Error{constructor(t,o){super(o||fe[t]);P(this,"name","TerraPayError");P(this,"code");P(this,"docUrl");this.code=t,this.docUrl=`${he}#${t.toLowerCase()}`}};function U(e){if(typeof e=="string"&&/(^|_)sk_|whsec_/i.test(e))throw new d("SECRET_KEY_REFUSED");if(typeof e!="string"||!/^tw_(test|live)_pk_[A-Za-z0-9_-]{8,128}$/.test(e))throw new d("INVALID_PUBLISHABLE_KEY")}var k="https://pay.terrawallet.us",w={pi:/^pi_[A-Za-z0-9]{6,64}$/,plink:/^plink_[A-Za-z0-9]{6,64}$/,inv:/^inv_[A-Za-z0-9]{6,64}$/,plan:/^plan_[A-Za-z0-9]{6,64}$/,sub:/^sub_[A-Za-z0-9]{6,64}$/},me={c:"pi",l:"plink",i:"inv",s:"plan"};function D(){let e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,n=>n.toString(16).padStart(2,"0")).join("")}function ge(e){if([e.checkoutUrl,e.paymentIntentId,e.planId].filter(s=>s!==void 0).length!==1)throw new d("INVALID_CHECKOUT");if(e.paymentIntentId!==void 0){if(!w.pi.test(e.paymentIntentId))throw new d("INVALID_CHECKOUT","paymentIntentId must look like pi_...");return`/c/${e.paymentIntentId}`}if(e.planId!==void 0){if(!w.plan.test(e.planId))throw new d("INVALID_CHECKOUT","planId must look like plan_...");return`/s/${e.planId}`}let t;try{t=new URL(String(e.checkoutUrl))}catch{throw new d("INVALID_CHECKOUT")}if(t.origin!==k||t.username||t.password)throw new d("INVALID_CHECKOUT","checkoutUrl must be on https://pay.terrawallet.us.");let o=/^\/([clis])\/([A-Za-z0-9_]+)\/?$/.exec(t.pathname),i=o?me[o[1]]:void 0;if(!o||!i||!w[i].test(o[2]))throw new d("INVALID_CHECKOUT","Unrecognised checkout URL path.");return`/${o[1]}/${o[2]}`}function ee(e,n){let t=new URL(ge(e),k);return t.searchParams.set("embed",n.mode),t.searchParams.set("pk",n.publishableKey),t.searchParams.set("sid",n.sid),t.searchParams.set("origin",n.parentOrigin),(n.theme==="light"||n.theme==="dark")&&t.searchParams.set("theme",n.theme),t.toString()}var be=new Set(["ready","resize","success","cancel","expire","error","close"]),x=(e,n)=>typeof e=="string"&&n.test(e)?e:void 0;function te(e,n){if(e.origin!==k||!n.source||e.source!==n.source)return null;let t=e.data;if(!t||typeof t!="object"||Array.isArray(t)||t.terraPay!==1||t.sid!==n.sid||typeof t.type!="string"||!be.has(t.type))return null;let o={type:t.type};(t.status==="succeeded"||t.status==="processing")&&(o.status=t.status);let i=x(t.paymentIntentId,w.pi);i&&(o.paymentIntentId=i);let s=x(t.subscriptionId,w.sub);s&&(o.subscriptionId=s);let c=x(t.invoiceId,w.inv);c&&(o.invoiceId=c);let C=x(t.txHash,/^(0x)?[A-Za-z0-9]{16,128}$/);C&&(o.txHash=C);let E=x(t.chain,/^[a-z0-9-]{2,32}$/);E&&(o.chain=E),typeof t.height=="number"&&Number.isFinite(t.height)&&(o.height=Math.min(4e3,Math.max(120,Math.round(t.height))));let _=x(t.errorCode,/^[A-Z][A-Z0-9_]{1,63}$/);return _&&(o.errorCode=_),typeof t.errorMessage=="string"&&(o.errorMessage=t.errorMessage.replace(/[\u0000-\u001f\u007f]/g," ").slice(0,300)),o.type==="success"&&!o.status&&(o.status="succeeded"),o}var ye="allow-scripts allow-same-origin allow-popups allow-forms",xe=2e4,I=null;function L(e){if(typeof window>"u"||typeof document>"u")throw new d("UNSUPPORTED_ENVIRONMENT");if(U(e.publishableKey),I)return I.focus(),I;let n=D(),t=e.theme??"auto",o=e.mode??"auto",i=r=>ee(e,{publishableKey:e.publishableKey,mode:r,sid:n,parentOrigin:location.origin,theme:t});i("modal");let s=o==="auto"?B()?"modal":"popup":o,c=null,C=()=>{let p=Math.max(0,Math.round((window.screenX??0)+((window.outerWidth??460)-460)/2)),u=Math.max(0,Math.round((window.screenY??0)+((window.outerHeight??760)-760)/2));return window.open(i("popup"),`terra_pay_${D().slice(0,12)}`,`popup=yes,width=460,height=760,left=${p},top=${u}`)};if(s==="popup"&&(c=C(),!c)){if(o==="popup")throw new d("POPUP_BLOCKED");s="modal"}let E,_=new Promise(r=>E=r),h=null,S=!1,H=document.activeElement,K=document.createElement("terra-pay-checkout"),M=K.attachShadow({mode:"closed"});A(M,X);let f=a("dialog",{"aria-labelledby":"t","aria-describedby":"d"}),v=a("div",{class:"t","data-theme":t}),O=a("button",{class:"x",type:"button","aria-label":"Close checkout"},g(y.close,20)),m=null,T=null,V=a("div",{class:"scrim"});function se(){return T=a("div",{class:"loading",role:"status"},a("span",{class:"spin"}),"Loading secure checkout"),m=a("iframe",{title:"Terra Pay checkout",sandbox:ye,allow:"clipboard-write",referrerpolicy:"strict-origin-when-cross-origin"}),m.src=i("modal"),a("div",{class:"panel"},a("header",{class:"bar"},a("span",{class:"lock"},g(y.lock,18)),a("div",{class:"who"},a("strong",{id:"t"},"Secure checkout"),a("span",{class:"origin",id:"d"},"pay.terrawallet.us")),O),a("div",{class:"frame"},T,m))}function $(){let r=a("button",{class:"btn primary",type:"button"},g(y.external,18),"Show window"),l=a("button",{class:"btn secondary",type:"button"},"Cancel payment");return r.addEventListener("click",()=>c?.focus()),l.addEventListener("click",()=>b({status:"canceled"},!0)),a("div",{class:"card",role:"document"},a("span",{class:"lock"},g(y.lock,18)),a("h2",{id:"t"},"Finish paying in the Terra Pay window"),a("p",{id:"d"},"Secure checkout opened on pay.terrawallet.us. Your payment continues there."),a("div",{class:"row"},l,r))}v.append(V,s==="modal"?se():$()),f.append(v),M.append(f),document.body.append(K);let z=document.documentElement.style.getPropertyValue("overflow");if(document.documentElement.style.setProperty("overflow","hidden"),typeof f.showModal=="function")try{f.showModal()}catch{f.setAttribute("open","")}else f.setAttribute("open","");(s==="modal"?O:v.querySelector(".primary"))?.focus(),O.addEventListener("click",()=>b(h??{status:"canceled"},!0)),v.querySelector(".scrim")?.addEventListener("click",()=>c&&!c.closed?c.focus():void 0),f.addEventListener("cancel",r=>{r.preventDefault(),b(h??{status:"canceled"},!0)}),f.addEventListener("keydown",r=>{if(r.key!=="Tab")return;let l=[...M.querySelectorAll("button, iframe")],p=l[0],u=l[l.length-1],N=M.activeElement;!p||!u||(r.shiftKey&&(N===p||!N)?(r.preventDefault(),u.focus()):!r.shiftKey&&N===u&&(r.preventDefault(),p.focus()))});let ae=()=>s==="modal"?m?.contentWindow??null:c,j=r=>{let l=te(r,{source:ae(),sid:n});l&&de(l)};window.addEventListener("message",j);let F,Y=()=>{F=setInterval(()=>c?.closed&&b(h??{status:"canceled"},!1),400)};s==="popup"&&Y();let Z=!1,ie=typeof e.readyTimeoutMs=="number"&&Number.isFinite(e.readyTimeoutMs)&&e.readyTimeoutMs>0?e.readyTimeoutMs:xe,R,G=()=>{clearTimeout(R),R=setTimeout(ce,ie)};function ce(){if(S||Z)return;let r=location.protocol==="https:";if(s==="modal"){let p=r?"The checkout could not load in a frame on this page: check that this site is an allowed origin of the publishable key (dashboard, project settings).":"The checkout sends its messages only to https pages.";e.onError?.(new d("CHECKOUT_ERROR",`The checkout did not connect to this page. ${p} The shopper can continue in a new window.`));let u=a("button",{class:"btn primary",type:"button"},g(y.external,18),"Continue in a new window");u.addEventListener("click",()=>le(u)),T?.replaceChildren(a("p",{},"The secure checkout could not open here."),u),u.focus();return}let l=r?"Check that this site is an allowed origin of the publishable key (dashboard, project settings).":"The checkout sends its messages only to https pages.";e.onError?.(new d("CHECKOUT_ERROR",`The checkout did not connect to this page. ${l}`))}G();function le(r){if(S||s!=="modal")return;let l=C();if(!l){e.onError?.(new d("POPUP_BLOCKED")),r.focus();return}c=l,s="popup",m?.remove(),m=null,T=null;let p=$();v.replaceChildren(V,p),p.querySelector(".primary")?.focus(),Y(),G()}function W(r,l){let p={status:l};for(let u of["paymentIntentId","subscriptionId","invoiceId","txHash","chain"])r[u]&&(p[u]=r[u]);return p}function de(r){switch(r.type){case"ready":Z=!0,clearTimeout(R),T?.setAttribute("hidden",""),e.onReady?.();break;case"resize":m&&r.height&&!B()&&m.style.setProperty("min-height",`${Math.min(r.height,window.innerHeight-120)}px`);break;case"success":h=W(r,r.status??"succeeded"),e.onSuccess?.(h);break;case"expire":h=W(r,"expired"),e.onExpire?.(h);break;case"error":e.onError?.(new d("CHECKOUT_ERROR",r.errorMessage?`Checkout: ${r.errorMessage}`:void 0));break;case"cancel":b({status:"canceled"},!0);break;case"close":b(h??{status:"canceled"},!0);break}}function b(r,l){if(!S){S=!0,window.removeEventListener("message",j),F&&clearInterval(F),clearTimeout(R),l&&c&&!c.closed&&c.close();try{f.close()}catch{}K.remove(),z?document.documentElement.style.setProperty("overflow",z):document.documentElement.style.removeProperty("overflow"),H&&document.contains(H)&&H.focus({preventScroll:!0}),I=null,r.status==="canceled"&&e.onCancel?.(),e.onClose?.(r),E(r)}}let q={get mode(){return s},closed:_,close:()=>b(h??{status:"canceled"},!0),focus:()=>c&&!c.closed?c.focus():O.focus()};return I=q,q}var we="0.1.0";function ke(e){return L(e)}function oe(e,n){U(n.publishableKey);let t=document.createElement("terra-pay-js-button"),o=t.attachShadow({mode:"closed"});A(o,J),typeof n.radius=="number"&&t.style.setProperty("--terra-radius",`${Math.min(24,Math.max(0,n.radius))}px`);let i=(n.label??(n.planId?"Subscribe with Terra":"Pay with Terra")).slice(0,60),s=a("button",{type:"button"},g(["M7 11V8a5 5 0 0 1 10 0v3","M5 11h14v10H5z"],18),i);return s.addEventListener("click",()=>{s.disabled=!0,L(n).closed.finally(()=>s.disabled=!1)}),o.append(s),e.append(t),()=>t.remove()}function Ce(e,n){return oe(e,n)}var ne=Object.freeze({open:L,subscribe:ke,mountButton:oe,mountSubscribeButton:Ce,CHECKOUT_ORIGIN:k,VERSION:we});var re=globalThis;re.TerraPay||(re.TerraPay=ne);})();
|
package/dist/cdn.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { TerraPayError } from "./errors.js";
|
|
2
|
+
import { CHECKOUT_ORIGIN, type CheckoutMode, type CheckoutTarget } from "./protocol.js";
|
|
3
|
+
export type CheckoutStatus = "succeeded" | "processing" | "canceled" | "expired" | "error";
|
|
4
|
+
export interface CheckoutResult {
|
|
5
|
+
status: CheckoutStatus;
|
|
6
|
+
paymentIntentId?: string;
|
|
7
|
+
subscriptionId?: string;
|
|
8
|
+
invoiceId?: string;
|
|
9
|
+
txHash?: string;
|
|
10
|
+
chain?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface OpenOptions extends CheckoutTarget {
|
|
13
|
+
/** Your publishable key (tw_test_pk_... or tw_live_pk_...). Secret keys are refused. */
|
|
14
|
+
publishableKey: string;
|
|
15
|
+
mode?: "auto" | CheckoutMode;
|
|
16
|
+
theme?: "light" | "dark" | "auto";
|
|
17
|
+
/**
|
|
18
|
+
* The payment went through on the checkout page. This is a UI signal only: fulfil orders from the
|
|
19
|
+
* payment_intent.succeeded webhook (or by fetching the payment intent on your server), never from this callback.
|
|
20
|
+
*/
|
|
21
|
+
onSuccess?(result: CheckoutResult): void;
|
|
22
|
+
onCancel?(): void;
|
|
23
|
+
onExpire?(result: CheckoutResult): void;
|
|
24
|
+
onError?(error: TerraPayError): void;
|
|
25
|
+
onReady?(): void;
|
|
26
|
+
/** Always called last, once the checkout UI is gone. */
|
|
27
|
+
onClose?(result: CheckoutResult): void;
|
|
28
|
+
/**
|
|
29
|
+
* How long to wait for the checkout's "ready" message before calling onError (the frame was refused, this page
|
|
30
|
+
* is not an allowed origin of the publishable key, or the page is not https). A modal then offers to continue in
|
|
31
|
+
* a popup window. Default 20000 ms.
|
|
32
|
+
*/
|
|
33
|
+
readyTimeoutMs?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface CheckoutHandle {
|
|
36
|
+
/** The current mode: a modal that fell back to a popup reports "popup" from then on. */
|
|
37
|
+
readonly mode: CheckoutMode;
|
|
38
|
+
/** Resolves with the final result when the checkout closes. */
|
|
39
|
+
readonly closed: Promise<CheckoutResult>;
|
|
40
|
+
close(): void;
|
|
41
|
+
focus(): void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The sandbox for the embedded checkout, the smallest set the hosted checkout needs:
|
|
45
|
+
* - allow-scripts: the checkout is an app;
|
|
46
|
+
* - allow-same-origin: it calls its own same-origin API and runs Turnstile (an opaque origin would break both);
|
|
47
|
+
* - allow-popups: explorer links and wallet app links open outside the frame (popups stay sandboxed: there is no
|
|
48
|
+
* allow-popups-to-escape-sandbox);
|
|
49
|
+
* - allow-forms: its "I already paid" transaction-hash form (without it the submit event never fires).
|
|
50
|
+
* Never granted: allow-top-navigation*, allow-modals, allow-downloads, allow-popups-to-escape-sandbox, so the
|
|
51
|
+
* frame can never navigate or cover the merchant page.
|
|
52
|
+
*/
|
|
53
|
+
export declare const IFRAME_SANDBOX = "allow-scripts allow-same-origin allow-popups allow-forms";
|
|
54
|
+
export declare const DEFAULT_READY_TIMEOUT_MS = 20000;
|
|
55
|
+
export declare function openCheckout(opts: OpenOptions): CheckoutHandle;
|
|
56
|
+
export { CHECKOUT_ORIGIN };
|
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM helpers. Every node is built with createElement / textContent: no innerHTML, no HTML strings from data, so
|
|
3
|
+
* merchant or checkout text can never become markup. Styles go through constructable stylesheets (CSP friendly).
|
|
4
|
+
*/
|
|
5
|
+
type Child = Node | string | null | undefined | false;
|
|
6
|
+
export declare function h<K extends keyof HTMLElementTagNameMap>(tag: K, attrs?: Record<string, string | undefined>, ...children: Child[]): HTMLElementTagNameMap[K];
|
|
7
|
+
/** An inline SVG icon from static path data (24x24 grid, stroke style like the extension's icons). */
|
|
8
|
+
export declare function icon(paths: readonly string[], size?: number, opts?: {
|
|
9
|
+
fill?: boolean;
|
|
10
|
+
cls?: string;
|
|
11
|
+
}): SVGSVGElement;
|
|
12
|
+
export declare const ICONS: {
|
|
13
|
+
readonly lock: readonly ["M7 11V8a5 5 0 0 1 10 0v3", "M5 11h14v10H5z"];
|
|
14
|
+
readonly close: readonly ["M18 6 6 18", "M6 6l12 12"];
|
|
15
|
+
readonly external: readonly ["M14 4h6v6", "M20 4 10 14", "M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"];
|
|
16
|
+
};
|
|
17
|
+
/** Attaches styles to a shadow root: a constructable stylesheet when supported, a <style> element otherwise. */
|
|
18
|
+
export declare function adoptStyles(root: ShadowRoot, css: string): void;
|
|
19
|
+
export declare const prefersReducedMotion: () => boolean;
|
|
20
|
+
export declare const isPhone: () => boolean;
|
|
21
|
+
export {};
|