@facto-to/connect 0.0.1-beta.1 → 0.0.1-beta.5

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 CHANGED
@@ -8,19 +8,39 @@ Facto Connect SDK lets partners bind their users to Facto accounts and payment r
8
8
 
9
9
  ## Install
10
10
 
11
- `@facto-to/connect` is **not on the public npm registry yet** (publication is an
12
- operator gate), so `npm install @facto-to/connect` fails with a 404 today. Install
13
- the vendored tarball Facto ships with your credentials — it is self-contained
14
- (its `@facto-to/*` runtime dependencies are bundled into `dist/`), so the one file
15
- is the whole install:
11
+ The workspace version **0.0.1-beta.5** is a prepared candidate, not a publication
12
+ receipt. Install only a tarball delivered with its source revision and digest.
13
+ Its ESM `.d.ts` and CommonJS `.d.cts` declarations include the existing public
14
+ type dependencies; consumers do not install the private engine-wire package or
15
+ need `skipLibCheck` to hide a missing dependency.
16
+
17
+ When upgrading from beta.4, server-built Hosted Connect URLs require a
18
+ per-request `merchantOrigin`. Refresh exhaustive decline-reason handling and
19
+ payment-readiness types against the delivered declarations. The existing
20
+ server error wrapper remains `FACTO_ENGINE_REQUEST_FAILED` with the original
21
+ HTTP `status` and raw `details`: a 403 `permission_denied` and a 409 `conflict`
22
+ remain distinguishable and are not automatically retried. Request deadlines
23
+ and caller cancellation cover the response body as well as response headers.
24
+ These behaviors are checked with offline responses; they do not establish
25
+ Production eligibility or authorize a funds operation.
26
+
27
+ `@facto-to/connect` is published to npm with **restricted access**. If your npm
28
+ account is authorized on the `@facto-to` organization:
16
29
 
17
30
  ```sh
18
- npm install ./facto-connect-<version>.tgz
31
+ npm install @facto-to/connect
32
+ ```
33
+
34
+ Otherwise the registry answers 404 and you install the tarball Facto ships with
35
+ your credentials instead — it is self-contained (its `@facto-to/*` runtime
36
+ dependencies are bundled into `dist/`), so the one file is the whole install:
37
+
38
+ ```sh
39
+ npm install --ignore-scripts ./facto-to-connect-<version>.tgz
19
40
  ```
20
41
 
21
42
  Verify the tarball's SHA-256 against the digest Facto provides before
22
- installing. Once npm publication opens, `npm install @facto-to/connect` becomes
23
- the supported path.
43
+ installing.
24
44
 
25
45
  ## Browser
26
46
 
@@ -67,12 +87,16 @@ const facto = createFactoConnectServer({
67
87
  appId: process.env.FACTO_APP_ID!,
68
88
  clientId: process.env.FACTO_CLIENT_ID!,
69
89
  clientSecret: process.env.FACTO_CLIENT_SECRET!,
70
- environment: 'sandbox',
71
90
  })
72
91
 
73
92
  const linked = await facto.exchangeUserLinkCode({ code, state, nonce })
74
93
  ```
75
94
 
95
+ Credentials and endpoints are one decision, not three. The client id Facto issued
96
+ you already names its environment, so the SDK reads it and resolves both the API
97
+ base URL and the Hosted Connect origin from it — there is nothing else to
98
+ configure and no URL to paste.
99
+
76
100
  The server entrypoint wraps:
77
101
 
78
102
  - `POST /api/merchant/user-links/exchange`
@@ -86,29 +110,91 @@ The public GA operation names mirror the OpenAPI contract:
86
110
  `getAuthorizationSession`, `getPaymentAuthorization`, `createMerchantPayment`, and
87
111
  `getMerchantPayment`. The pre-GA names remain as deprecated source-compatible aliases.
88
112
 
89
- `environment` is required and accepts `sandbox`, `dev`, or `production`. Per ADR-0077
113
+ ### Hosted Connect URLs
114
+
115
+ `buildHostedConnectUrl` and `facto.createHostedConnectUrl` take a required
116
+ `merchantOrigin`: the origin of the browsing context that will open the
117
+ returned URL. **Breaking change** — this used to be implicit, resolved by the
118
+ Hosted Connect page from `document.referrer` alone, which `rel="noreferrer"`
119
+ links, a `Referrer-Policy: no-referrer` deployment, or a privacy-mode browser
120
+ all erase silently. The parameter is required so a
121
+ missing value fails your build instead of a shopper's session.
122
+
123
+ Pass the origin of *this specific request's* browsing context — never a
124
+ single static value pinned in server config, since one server can serve
125
+ several merchant origins (custom domains, preview deployments, staging
126
+ mirrors) that would otherwise all get stamped with whichever origin happened
127
+ to be configured last:
128
+
129
+ ```ts
130
+ // Express-style handler: derive merchantOrigin from the request that is
131
+ // actually asking, not from an environment variable.
132
+ app.get('/facto/connect-url', (req, res) => {
133
+ const merchantOrigin = req.get('origin') ?? new URL(req.get('referer')!).origin
134
+ const url = facto.createHostedConnectUrl({ state, nonce, merchantOrigin })
135
+ res.json({ url })
136
+ })
137
+ ```
138
+
139
+ `merchantOrigin` must be a bare `http(s)` origin — no path, query, fragment,
140
+ or credentials — and is written verbatim into the URL's `external_origin`
141
+ parameter. A value that fails that shape throws
142
+ `merchantOrigin must be an absolute http(s) origin`; omitting it throws
143
+ `merchantOrigin is required and has no implicit default`. Both are
144
+ `FactoConnectServerError` with code `FACTO_CONFIG_INVALID`.
145
+
146
+ This is the hosted (server-built) URL only. The browser popup leg
147
+ (`createFactoConnect`/`FactoConnectTransportOptions.origin`) already sets its
148
+ own `external_origin` from `window.location.origin` (or an explicit `origin`
149
+ override) and is unchanged by this release — see CHANGELOG for how the two
150
+ legs relate when they disagree.
151
+
152
+ ### Environment
153
+
154
+ `environment` is optional and accepts `sandbox`, `dev`, or `production`. Per ADR-0077
90
155
  (“sandbox naming, dev interface”), `sandbox` is the documented public name for the test
91
156
  environment and `dev` is the infrastructure name for the same environment: both resolve the
92
157
  same published dev endpoints (`https://dev-api.facto.to`, hosted Connect
93
- `https://dev.facto.to`) and the `/api/dev/*` route family. There is no implicit default:
94
- omitting `environment` throws at construction. The historical silent fallback — Production
95
- endpoints over the legacy `/api/external/*` routes — was removed before first publish, so a
96
- wrong environment fails loudly at construction instead of sending credentialed traffic to the
97
- wrong deployment at runtime. Exact published origins are matched fail-closed, and
98
- selector/origin or API/Hosted environment conflicts are rejected before any credential-bearing
99
- request. All operations, including the deprecated pre-GA aliases, use only the canonical
158
+ `https://dev.facto.to`) and the `/api/dev/*` route family.
159
+
160
+ > **Real-money warning (ADR-0078):** Sandbox is a product name, not a testnet.
161
+ > The environment behind `sandbox`/`dev` settles on mainnet chains with real
162
+ > value — a succeeded payment, refund, or faucet transfer moves real USDC. The
163
+ > only zero-money path is the offline fixture transport
164
+ > (`@facto-to/connect/testing`), which never performs network I/O.
165
+
166
+ Omit it and the environment is derived from `clientId`, in this order:
167
+
168
+ 1. the explicit `environment` value, when you pass one;
169
+ 2. the client id's keyspace — `dev_mcid_`/`dev_pspid_`/`dev_cpid_` resolve dev, bare
170
+ `mcid_`/`pspid_`/`cpid_` resolve production;
171
+ 3. an `apiBaseUrl` or `hostedConnectUrl` you pointed at a published Facto endpoint.
172
+
173
+ That is evidence, never a default. A client id carrying no published keyspace — internal
174
+ (`lab_`, `staging_`, `test_`), legacy (`sandbox_`), or unrecognized — derives nothing and
175
+ throws at construction. The historical silent fallback — Production endpoints over the
176
+ legacy `/api/external/*` routes — was removed before first publish, so a wrong environment
177
+ still fails loudly at construction instead of sending credentialed traffic to the wrong
178
+ deployment at runtime. An explicit `environment` that contradicts the credential is also
179
+ rejected there rather than silently preferring one of the two. Exact published origins are
180
+ matched fail-closed, and selector/origin or API/Hosted environment conflicts are rejected
181
+ before any credential-bearing request.
182
+
183
+ `factoConnectEnvironmentFromClientId(clientId)` is exported if you need the same reading
184
+ outside the client — for a config banner or a startup assertion, say. It returns `'dev'`,
185
+ `'production'`, or `undefined`. All operations, including the deprecated pre-GA aliases, use only the canonical
100
186
  `/api/connect` and `/api/merchant` families; the legacy `/api/external` aliases are gone. The
101
187
  published dev URL is a target endpoint and does not imply that a named dev deployment is
102
188
  currently available.
103
189
 
104
190
  `staging` and the former `custom` selector are retired. Local, private, and staging
105
- deployments keep any `environment` value and pass explicit `apiBaseUrl` and
106
- `hostedConnectUrl` overrides, which take precedence over the published endpoint tables:
191
+ deployments pass explicit `apiBaseUrl` and `hostedConnectUrl` overrides, which take
192
+ precedence over the published endpoint tables. A dev credential still names the environment
193
+ for the dev-only capability gates, so `environment` stays optional here too:
107
194
 
108
195
  ```ts
109
196
  createFactoConnectServer({
110
197
  ...credentials,
111
- environment: 'sandbox',
112
198
  apiBaseUrl: 'http://127.0.0.1:8080',
113
199
  hostedConnectUrl: 'http://127.0.0.1:5173',
114
200
  })
@@ -193,6 +279,28 @@ an `Idempotency-Key`, honoring `Retry-After`; it never retries other POST calls.
193
279
  and fixtures; callers must read the capability response rather than assuming a dev
194
280
  endpoint, faucet, simulation, or money loop is deployed or verified.
195
281
 
282
+ ## Link-code mint refusal errors
283
+
284
+ The two refusals below originate on the engine's link-code minting surface and
285
+ need different recovery actions. Their uppercase tokens are prefixes of the
286
+ engine's `error.message`, not SDK error codes. The identity refusal requires a
287
+ forced link reference, as used by the sandbox persona flow; the ordinary Hosted
288
+ Connect flow does not supply that reference.
289
+
290
+ | Message prefix | Engine `error.code` | HTTP | Meaning and recovery |
291
+ | --- | --- | --- | --- |
292
+ | `FACTO_LINK_IDENTITY_MISMATCH` | `conflict` | 409 | The forced link reference on a mint request differs from this user's active grant for the app. Unlink the existing association before reclaiming it. |
293
+ | `FACTO_LINK_MISMATCH` | `permission_denied` | 403 | The mint request's origin is not registered for the app. Register the intended origin; changing the shopper's identity does not fix this refusal. |
294
+
295
+ For non-success HTTP responses, `FactoConnectServerError.code` remains
296
+ `FACTO_ENGINE_REQUEST_FAILED`. Its `status` preserves the HTTP status and its
297
+ `details` preserves the engine error envelope, including `error.code` and
298
+ `error.message`. Both refusals are non-retryable: distinguish their status and
299
+ message prefix instead of treating every link refusal as an origin mismatch.
300
+ The SDK preserves these fields if a server returns such an envelope. This is
301
+ not a claim that the merchant link-code exchange endpoint produces either
302
+ minting refusal, or that the SDK exposes the minting surface.
303
+
196
304
  ## Offline Fixtures
197
305
 
198
306
  The testing entrypoint provides an in-memory transport that never performs network I/O:
@@ -1,4 +1,4 @@
1
- "use strict";var b=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var e1=Object.getOwnPropertyNames;var t1=Object.prototype.hasOwnProperty;var o1=(e,t)=>{for(var o in t)b(e,o,{get:t[o],enumerable:!0})},n1=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of e1(t))!t1.call(e,r)&&r!==o&&b(e,r,{get:()=>t[r],enumerable:!(n=J(t,r))||n.enumerable});return e};var s1=e=>n1(b({},"__esModule",{value:!0}),e);var N1={};o1(N1,{FACTO_LINK_CLOSE_REQUESTED:()=>O,FACTO_LINK_CONNECTED:()=>M,FACTO_LINK_FAILED:()=>T,FACTO_LINK_READY:()=>_,FactoConnect:()=>Z1,FactoConnectError:()=>m,createFactoConnect:()=>R,createFactoConnectTransport:()=>P,createFactoExpressCheckout:()=>X,default:()=>B1});module.exports=s1(N1);var D=`<svg xmlns:xodm="http://www.corel.com/coreldraw/odm/2003" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 2500 2500" style="enable-background:new 0 0 2500 2500;" xml:space="preserve"><div xmlns="" id="in-page-channel-node-id" data-channel-name="in_page_channel_fxgOrU"/>
1
+ "use strict";var E=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var e1=Object.getOwnPropertyNames;var t1=Object.prototype.hasOwnProperty;var o1=(e,t)=>{for(var n in t)E(e,n,{get:t[n],enumerable:!0})},n1=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of e1(t))!t1.call(e,a)&&a!==n&&E(e,a,{get:()=>t[a],enumerable:!(s=J(t,a))||s.enumerable});return e};var s1=e=>n1(E({},"__esModule",{value:!0}),e);var N1={};o1(N1,{FACTO_LINK_CLOSE_REQUESTED:()=>P,FACTO_LINK_CONNECTED:()=>_,FACTO_LINK_FAILED:()=>O,FACTO_LINK_READY:()=>T,FactoConnect:()=>Z1,FactoConnectError:()=>m,createFactoConnect:()=>A,createFactoConnectTransport:()=>R,createFactoExpressCheckout:()=>X,default:()=>B1});module.exports=s1(N1);var D=`<svg xmlns:xodm="http://www.corel.com/coreldraw/odm/2003" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 2500 2500" style="enable-background:new 0 0 2500 2500;" xml:space="preserve"><div xmlns="" id="in-page-channel-node-id" data-channel-name="in_page_channel_fxgOrU"/>
2
2
  <style type="text/css">
3
3
  .st0{fill:none;}
4
4
  .st1{fill:#213147;}
@@ -117,7 +117,7 @@
117
117
  transform="translate(70 66)"
118
118
  />
119
119
  </svg>
120
- `,f1='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill-opacity=".5" d="M17.82 14.342v4.672h1.275c.172 0 .312-.14.312-.311v-4.05a.31.31 0 0 0-.312-.312zm0-9.356v4.673h1.275c.172 0 .312-.14.312-.312v-4.05a.31.31 0 0 0-.312-.311z"/><path fill-opacity=".3" d="M20.209 4.986v4.673h.477c.172 0 .311-.14.311-.312v-4.05a.31.31 0 0 0-.311-.311zm.002 9.356v4.672h.477c.172 0 .312-.14.312-.311v-4.05a.31.31 0 0 0-.312-.312z"/><path d="M12.026 9.67h-4.03a.31.31 0 0 0-.31.307v4.002c0 .17.138.308.31.308h4.03a.31.31 0 0 0 .31-.308V9.977a.31.31 0 0 0-.31-.308M7.361 4.986h-4.05A.31.31 0 0 0 3 5.297v4.05c0 .172.14.312.312.312h4.05c.171 0 .31-.14.31-.312v-4.05a.31.31 0 0 0-.31-.311m9.343 0h-4.05a.31.31 0 0 0-.311.311v4.05c0 .172.14.312.311.312h4.05c.172 0 .312-.14.312-.312v-4.05a.31.31 0 0 0-.312-.311M7.361 14.33h-4.05a.31.31 0 0 0-.311.313v4.05c0 .171.14.31.312.31h4.05a.31.31 0 0 0 .31-.31v-4.05a.31.31 0 0 0-.31-.312m9.343-.001h-4.05a.31.31 0 0 0-.311.313v4.05c0 .171.14.31.311.31h4.05a.31.31 0 0 0 .312-.31v-4.05a.31.31 0 0 0-.312-.312"/></svg>',$=[{chainId:1,name:"Ethereum",gasSymbol:"ETH",explorerUrl:"https://etherscan.io",logo:r1,logoTheme:"normal",testnet:!1},{chainId:56,name:"BNB",gasSymbol:"BNB",explorerUrl:"https://bscscan.com",logo:a1,logoTheme:"normal",testnet:!1},{chainId:137,name:"Polygon",gasSymbol:"POL",explorerUrl:"https://polygonscan.com",logo:d1,logoTheme:"normal",testnet:!1},{chainId:143,name:"Monad",gasSymbol:"MON",explorerUrl:"https://monadscan.com",logo:c1,logoTheme:"normal",testnet:!1},{chainId:196,name:"X Layer",gasSymbol:"OKB",explorerUrl:"https://www.oklink.com/x-layer/evm",logo:f1,logoTheme:"invertOnDark",testnet:!1},{chainId:988,name:"Stable Mainnet",gasSymbol:"USDT0",explorerUrl:"https://stablescan.xyz",logo:u1,logoTheme:"invertOnLight",testnet:!1},{chainId:1329,name:"Sei",gasSymbol:"SEI",explorerUrl:"https://seiscan.io",logo:C1,logoTheme:"normal",testnet:!1},{chainId:4217,name:"Tempo",gasSymbol:"TMPO",explorerUrl:"https://explore.tempo.xyz",logo:V,logoTheme:"normal",testnet:!1},{chainId:4326,name:"MegaETH",gasSymbol:"ETH",explorerUrl:"https://mega.etherscan.io",logo:i1,logoTheme:"normal",testnet:!1},{chainId:8453,name:"Base",gasSymbol:"ETH",explorerUrl:"https://basescan.org",logo:z,logoTheme:"normal",testnet:!1},{chainId:9745,name:"Plasma",gasSymbol:"XPL",explorerUrl:"https://plasmascan.to",logo:l1,logoTheme:"normal",testnet:!1},{chainId:42161,name:"Arbitrum",gasSymbol:"ETH",explorerUrl:"https://arbiscan.io",logo:D,logoTheme:"normal",testnet:!1},{chainId:42431,name:"Tempo Moderato",gasSymbol:"SEI",explorerUrl:"https://explore.tempo.xyz",logo:V,logoTheme:"normal",testnet:!0},{chainId:46630,name:"Robinhood Testnet",gasSymbol:"ETH",explorerUrl:"https://explorer.testnet.chain.robinhood.com",logo:p1,logoTheme:"normal",testnet:!0},{chainId:84532,name:"Base Sepolia",gasSymbol:"ETH",explorerUrl:"https://sepolia.basescan.org",logo:z,logoTheme:"normal",testnet:!0},{chainId:421614,name:"Arbitrum Sepolia",gasSymbol:"ETH",explorerUrl:"https://sepolia.arbiscan.io",logo:D,logoTheme:"normal",testnet:!0}],E=Object.fromEntries($.map(e=>[e.chainId,e])),g1=`<svg width="100" height="100" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
120
+ `,f1='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill-opacity=".5" d="M17.82 14.342v4.672h1.275c.172 0 .312-.14.312-.311v-4.05a.31.31 0 0 0-.312-.312zm0-9.356v4.673h1.275c.172 0 .312-.14.312-.312v-4.05a.31.31 0 0 0-.312-.311z"/><path fill-opacity=".3" d="M20.209 4.986v4.673h.477c.172 0 .311-.14.311-.312v-4.05a.31.31 0 0 0-.311-.311zm.002 9.356v4.672h.477c.172 0 .312-.14.312-.311v-4.05a.31.31 0 0 0-.312-.312z"/><path d="M12.026 9.67h-4.03a.31.31 0 0 0-.31.307v4.002c0 .17.138.308.31.308h4.03a.31.31 0 0 0 .31-.308V9.977a.31.31 0 0 0-.31-.308M7.361 4.986h-4.05A.31.31 0 0 0 3 5.297v4.05c0 .172.14.312.312.312h4.05c.171 0 .31-.14.31-.312v-4.05a.31.31 0 0 0-.31-.311m9.343 0h-4.05a.31.31 0 0 0-.311.311v4.05c0 .172.14.312.311.312h4.05c.172 0 .312-.14.312-.312v-4.05a.31.31 0 0 0-.312-.311M7.361 14.33h-4.05a.31.31 0 0 0-.311.313v4.05c0 .171.14.31.312.31h4.05a.31.31 0 0 0 .31-.31v-4.05a.31.31 0 0 0-.31-.312m9.343-.001h-4.05a.31.31 0 0 0-.311.313v4.05c0 .171.14.31.311.31h4.05a.31.31 0 0 0 .312-.31v-4.05a.31.31 0 0 0-.312-.312"/></svg>',$=[{chainId:1,name:"Ethereum",gasSymbol:"ETH",explorerUrl:"https://etherscan.io",logo:r1,logoTheme:"normal",testnet:!1},{chainId:56,name:"BNB",gasSymbol:"BNB",explorerUrl:"https://bscscan.com",logo:a1,logoTheme:"normal",testnet:!1},{chainId:137,name:"Polygon",gasSymbol:"POL",explorerUrl:"https://polygonscan.com",logo:d1,logoTheme:"normal",testnet:!1},{chainId:143,name:"Monad",gasSymbol:"MON",explorerUrl:"https://monadscan.com",logo:c1,logoTheme:"normal",testnet:!1},{chainId:196,name:"X Layer",gasSymbol:"OKB",explorerUrl:"https://www.oklink.com/x-layer/evm",logo:f1,logoTheme:"invertOnDark",testnet:!1},{chainId:988,name:"Stable Mainnet",gasSymbol:"USDT0",explorerUrl:"https://stablescan.xyz",logo:u1,logoTheme:"invertOnLight",testnet:!1},{chainId:1329,name:"Sei",gasSymbol:"SEI",explorerUrl:"https://seiscan.io",logo:C1,logoTheme:"normal",testnet:!1},{chainId:4217,name:"Tempo",gasSymbol:"TMPO",explorerUrl:"https://explore.tempo.xyz",logo:V,logoTheme:"normal",testnet:!1},{chainId:4326,name:"MegaETH",gasSymbol:"ETH",explorerUrl:"https://mega.etherscan.io",logo:i1,logoTheme:"normal",testnet:!1},{chainId:8453,name:"Base",gasSymbol:"ETH",explorerUrl:"https://basescan.org",logo:z,logoTheme:"normal",testnet:!1},{chainId:9745,name:"Plasma",gasSymbol:"XPL",explorerUrl:"https://plasmascan.to",logo:l1,logoTheme:"normal",testnet:!1},{chainId:42161,name:"Arbitrum",gasSymbol:"ETH",explorerUrl:"https://arbiscan.io",logo:D,logoTheme:"normal",testnet:!1},{chainId:42431,name:"Tempo Moderato",gasSymbol:"SEI",explorerUrl:"https://explore.tempo.xyz",logo:V,logoTheme:"normal",testnet:!0},{chainId:46630,name:"Robinhood Testnet",gasSymbol:"ETH",explorerUrl:"https://explorer.testnet.chain.robinhood.com",logo:p1,logoTheme:"normal",testnet:!0},{chainId:84532,name:"Base Sepolia",gasSymbol:"ETH",explorerUrl:"https://sepolia.basescan.org",logo:z,logoTheme:"normal",testnet:!0},{chainId:421614,name:"Arbitrum Sepolia",gasSymbol:"ETH",explorerUrl:"https://sepolia.arbiscan.io",logo:D,logoTheme:"normal",testnet:!0}],k=Object.fromEntries($.map(e=>[e.chainId,e])),g1=`<svg width="100" height="100" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
121
121
  <!-- PLACEHOLDER \u2014 not final artwork. See src/assets/chains/README.md. -->
122
122
  <circle cx="50" cy="50" r="47" fill="#E5E7EB" stroke="#9CA3AF" stroke-width="2" stroke-dasharray="6 5"/>
123
123
  <text x="50" y="58" font-family="ui-sans-serif, system-ui, sans-serif" font-size="30" font-weight="600" fill="#6B7280" text-anchor="middle">AV3</text>
@@ -137,7 +137,7 @@
137
137
  <circle cx="50" cy="50" r="47" fill="#E5E7EB" stroke="#9CA3AF" stroke-width="2" stroke-dasharray="6 5"/>
138
138
  <text x="50" y="58" font-family="ui-sans-serif, system-ui, sans-serif" font-size="30" font-weight="600" fill="#6B7280" text-anchor="middle">MB</text>
139
139
  </svg>
140
- `,K=[{id:"aave-v3",name:"AAVE V3",logo:g1,logoTheme:"normal"},{id:"compound-v2",name:"Compound V2",logo:m1,logoTheme:"normal"},{id:"morpho",name:"Morpho Blue",logo:x1,logoTheme:"normal"},{id:"dolomite",name:"Dolomite",logo:h1,logoTheme:"normal"}],k=Object.fromEntries(K.map(e=>[e.id,e]));var j=!1;function X(e){let t=y1(e.container);k1();let o=e,n=S(void 0).setup,r={kind:"idle",message:""},l=!1,f=W("facto-express-root"),p=document.createElement("button");p.type="button",p.className="facto-express-button",p.addEventListener("click",()=>{L()});let C=document.createElement("span"),u=document.createElement("strong");p.append(C,u);let s=document.createElement("p");s.className="facto-express-inline-status",s.setAttribute("role","status"),s.setAttribute("aria-live","polite"),f.append(p,s),t.replaceChildren(f);let a=W("facto-express-overlay");a.setAttribute("aria-hidden","true"),a.innerHTML=L1(),document.body.append(a);let y=v(a,"[data-facto-close]"),g=v(a,"[data-facto-change]"),d=v(a,"[data-facto-pay]"),i=v(a,"[data-facto-result]");y.addEventListener("click",w),g.addEventListener("click",()=>{A()}),d.addEventListener("click",()=>{q()}),document.addEventListener("keydown",U),Z(),F();async function L(){if(!l){h({kind:"checking",message:"Checking saved Facto setup..."});try{let c=S(await o.getPaymentSetup());if(c.setup?.ready){n=c.setup,H();return}await A()}catch(c){h({kind:"error",message:I(c,"Facto checkout could not start.")})}}}async function A(){if(!l){h({kind:"setup",message:"Opening Facto secure checkout..."});try{let c=S(await o.startPaymentSetup());if(!c.setup?.ready){h({kind:"setup",message:c.state?.message??"Finish Facto setup"});return}n=c.setup,H()}catch(c){h({kind:"error",message:I(c,"Facto setup could not be completed.")})}}}async function q(){if(!(l||!n?.ready)){h({kind:"paying",message:"Submitting Facto payment..."}),d.disabled=!0;try{let c=await o.submitPayment(n);h({kind:"success",message:c?.message??"Payment authorized with Facto."})}catch(c){h({kind:"error",message:I(c,"Facto payment failed.")})}finally{d.disabled=!1}}}function H(){F(),a.dataset.open="true",a.setAttribute("aria-hidden","false"),h({kind:"ready",message:""}),d.focus()}function w(){a.dataset.open="false",a.setAttribute("aria-hidden","true"),p.focus()}function G(c){o={...o,...c},Z(),F()}function Q(){l=!0,document.removeEventListener("keydown",U),a.remove(),f.remove()}function U(c){c.key==="Escape"&&a.dataset.open==="true"&&w()}function h(c){r=c,o.onStatusChange?.(r),B()}function Z(){let c=o.buttonLabel??"Pay with",N=o.brandLabel??"Facto";C.textContent=c,u.textContent=N,p.setAttribute("aria-label",`${c} ${N}`)}function F(){let c=n;x(a,"[data-facto-brand]",o.brandLabel??"Facto"),x(a,"[data-facto-route]",c?.routeLabel??"Connect Facto to pay"),x(a,"[data-facto-address]",c?E1(c.walletAddress):""),x(a,"[data-facto-order-label]",o.order.label),x(a,"[data-facto-order-amount]",o.order.amountLabel),x(a,"[data-facto-shipping]",o.order.shippingLabel??"Included"),x(a,"[data-facto-total]",o.order.amountLabel),x(a,"[data-facto-pay-label]",`Pay ${o.order.amountLabel} with ${o.brandLabel??"Facto"}`),x(a,"[data-facto-env]",`Sandbox target: ${o.environmentLabel??"local"}`),B()}function B(){s.textContent=r.message,s.dataset.kind=r.kind,i.textContent=r.kind==="ready"?"":r.message,i.dataset.kind=r.kind}return{open:L,close:w,update:G,destroy:Q}}function L1(){return`
140
+ `,K=[{id:"aave-v3",name:"AAVE V3",logo:g1,logoTheme:"normal"},{id:"compound-v2",name:"Compound V2",logo:m1,logoTheme:"normal"},{id:"morpho",name:"Morpho Blue",logo:x1,logoTheme:"normal"},{id:"dolomite",name:"Dolomite",logo:h1,logoTheme:"normal"}],S=Object.fromEntries(K.map(e=>[e.id,e]));var j=!1;function X(e){let t=y1(e.container);k1();let n=e,s=I(void 0).setup,a={kind:"idle",message:""},c=!1,u=W("facto-express-root"),d=document.createElement("button");d.type="button",d.className="facto-express-button",d.addEventListener("click",()=>{r()});let p=document.createElement("span"),L=document.createElement("strong");d.append(p,L);let C=document.createElement("p");C.className="facto-express-inline-status",C.setAttribute("role","status"),C.setAttribute("aria-live","polite"),u.append(d,C),t.replaceChildren(u);let o=W("facto-express-overlay");o.setAttribute("aria-hidden","true"),o.innerHTML=L1(),document.body.append(o);let f=w(o,"[data-facto-close]"),g=w(o,"[data-facto-change]"),l=w(o,"[data-facto-pay]"),v=w(o,"[data-facto-result]");f.addEventListener("click",F),g.addEventListener("click",()=>{y()}),l.addEventListener("click",()=>{q()}),document.addEventListener("keydown",U),Z(),b();async function r(){if(!c){h({kind:"checking",message:"Checking saved Facto setup..."});try{let i=I(await n.getPaymentSetup());if(i.setup?.ready){s=i.setup,H();return}await y()}catch(i){h({kind:"error",message:M(i,"Facto checkout could not start.")})}}}async function y(){if(!c){h({kind:"setup",message:"Opening Facto secure checkout..."});try{let i=I(await n.startPaymentSetup());if(!i.setup?.ready){h({kind:"setup",message:i.state?.message??"Finish Facto setup"});return}s=i.setup,H()}catch(i){h({kind:"error",message:M(i,"Facto setup could not be completed.")})}}}async function q(){if(!(c||!s?.ready)){h({kind:"paying",message:"Submitting Facto payment..."}),l.disabled=!0;try{let i=await n.submitPayment(s);h({kind:"success",message:i?.message??"Payment authorized with Facto."})}catch(i){h({kind:"error",message:M(i,"Facto payment failed.")})}finally{l.disabled=!1}}}function H(){b(),o.dataset.open="true",o.setAttribute("aria-hidden","false"),h({kind:"ready",message:""}),l.focus()}function F(){o.dataset.open="false",o.setAttribute("aria-hidden","true"),d.focus()}function G(i){n={...n,...i},Z(),b()}function Q(){c=!0,document.removeEventListener("keydown",U),o.remove(),u.remove()}function U(i){i.key==="Escape"&&o.dataset.open==="true"&&F()}function h(i){a=i,n.onStatusChange?.(a),B()}function Z(){let i=n.buttonLabel??"Pay with",N=n.brandLabel??"Facto";p.textContent=i,L.textContent=N,d.setAttribute("aria-label",`${i} ${N}`)}function b(){let i=s;x(o,"[data-facto-brand]",n.brandLabel??"Facto"),x(o,"[data-facto-route]",i?.routeLabel??"Connect Facto to pay"),x(o,"[data-facto-address]",i?E1(i.walletAddress):""),x(o,"[data-facto-order-label]",n.order.label),x(o,"[data-facto-order-amount]",n.order.amountLabel),x(o,"[data-facto-shipping]",n.order.shippingLabel??"Included"),x(o,"[data-facto-total]",n.order.amountLabel),x(o,"[data-facto-pay-label]",`Pay ${n.order.amountLabel} with ${n.brandLabel??"Facto"}`),x(o,"[data-facto-env]",`Sandbox target: ${n.environmentLabel??"local"}`),B()}function B(){C.textContent=a.message,C.dataset.kind=a.kind,v.textContent=a.kind==="ready"?"":a.message,v.dataset.kind=a.kind}return{open:r,close:F,update:G,destroy:Q}}function L1(){return`
141
141
  <section class="facto-express-sheet" role="dialog" aria-modal="true" aria-labelledby="facto-express-title">
142
142
  <div class="facto-express-close-row">
143
143
  <button type="button" class="facto-express-secondary" data-facto-close>Close</button>
@@ -184,7 +184,7 @@
184
184
  <p class="facto-express-result" role="status" aria-live="polite" data-facto-result></p>
185
185
  </div>
186
186
  </section>
187
- `}function y1(e){if(typeof e!="string")return e;let t=document.querySelector(e);if(t instanceof HTMLElement)return t;throw new Error(`Facto checkout container was not found: ${e}`)}function S(e){return e?v1(e)?{setup:null,state:e}:"pipelineReady"in e?e.pipelineReady?e.factoServerWalletAddress?{setup:{walletAddress:e.factoServerWalletAddress,routeLabel:w1(e.pipeline),ready:!0},state:null}:{setup:null,state:null}:{setup:null,state:{buttonLabel:"Pay with Facto",setupStatus:"finish_facto_setup",message:"Finish Facto setup. We'll resume checkout here.",paymentReady:!1,mandateReady:!1,blockingReason:"payment_path_required"}}:e.ready?{setup:e,state:null}:{setup:null,state:null}:{setup:null,state:null}}function v1(e){return"setupStatus"in e&&"paymentReady"in e&&"mandateReady"in e}function w1(e){return e?[F1(e.chainId),b1(e.protocolId),e.assetSymbol].filter(Boolean).join(" \xB7 "):"Facto payment route"}function F1(e){return E[e]?.name??`Chain ${e}`}function b1(e){return k[e]?.name??e}function E1(e){return e.length>12?`${e.slice(0,6)}...${e.slice(-4)}`:e}function W(e){let t=document.createElement("div");return t.className=e,t}function v(e,t){let o=e.querySelector(t);if(!o)throw new Error(`Facto checkout element missing: ${t}`);return o}function x(e,t,o){v(e,t).textContent=o}function I(e,t){return e instanceof Error?e.message:t}function k1(){if(j)return;j=!0;let e=document.createElement("style");e.dataset.factoExpressCheckout="true",e.textContent=`
187
+ `}function y1(e){if(typeof e!="string")return e;let t=document.querySelector(e);if(t instanceof HTMLElement)return t;throw new Error(`Facto checkout container was not found: ${e}`)}function I(e){return e?v1(e)?{setup:null,state:e}:"pipelineReady"in e?e.pipelineReady?e.factoServerWalletAddress?{setup:{walletAddress:e.factoServerWalletAddress,routeLabel:w1(e.pipeline),ready:!0},state:null}:{setup:null,state:null}:{setup:null,state:{buttonLabel:"Pay with Facto",setupStatus:"finish_facto_setup",message:"Finish Facto setup. We'll resume checkout here.",paymentReady:!1,mandateReady:!1,blockingReason:"payment_path_required"}}:e.ready?{setup:e,state:null}:{setup:null,state:null}:{setup:null,state:null}}function v1(e){return"setupStatus"in e&&"paymentReady"in e&&"mandateReady"in e}function w1(e){return e?[F1(e.chainId),b1(e.protocolId),e.assetSymbol].filter(Boolean).join(" \xB7 "):"Facto payment route"}function F1(e){return k[e]?.name??`Chain ${e}`}function b1(e){return S[e]?.name??e}function E1(e){return e.length>12?`${e.slice(0,6)}...${e.slice(-4)}`:e}function W(e){let t=document.createElement("div");return t.className=e,t}function w(e,t){let n=e.querySelector(t);if(!n)throw new Error(`Facto checkout element missing: ${t}`);return n}function x(e,t,n){w(e,t).textContent=n}function M(e,t){return e instanceof Error?e.message:t}function k1(){if(j)return;j=!0;let e=document.createElement("style");e.dataset.factoExpressCheckout="true",e.textContent=`
188
188
  .facto-express-root { width: 100%; }
189
189
  .facto-express-button {
190
190
  width: min(352px, 100%);
@@ -375,5 +375,4 @@
375
375
  .facto-express-body { padding: 16px; }
376
376
  .facto-express-button { width: 100%; }
377
377
  }
378
- `,document.head.append(e)}var M="facto.externalLink.connected",_="facto.externalLink.ready",T="facto.externalLink.failed",O="facto.externalLink.closeRequested",m=class extends Error{code;retryable;status;details;constructor(t,o,n){super(o),this.name="FactoConnectError",this.code=t,this.retryable=n.retryable,this.status=n.status,this.details=n.details}},S1=460,I1=720;function Y(){let e=S1,t=I1,o=window.screenLeft??window.screenX??0,n=window.screenTop??window.screenY??0,r=window.outerWidth||e,l=window.outerHeight||t,f=Math.max(0,o+(r-e)/2),p=Math.max(0,n+(l-t)/2);return{width:e,height:t,left:Math.round(f),top:Math.round(p)}}function M1(){let{width:e,height:t,left:o,top:n}=Y();return["popup=yes",`width=${e}`,`height=${t}`,`innerWidth=${e}`,`innerHeight=${t}`,`left=${o}`,`top=${n}`,"resizable=yes","scrollbars=yes","toolbar=no","menubar=no","location=no","status=no"].join(",")}function _1(e){return`facto-connect-${e.replace(/[^a-zA-Z0-9_-]/g,"").slice(0,36)||"session"}`}function T1(e){let{width:t,height:o,left:n,top:r}=Y();try{typeof e.resizeTo=="function"&&e.resizeTo(t,o),typeof e.moveTo=="function"&&e.moveTo(n,r),typeof e.focus=="function"&&e.focus()}catch{}}function O1(e,t){let o=new URL(e);return!o.searchParams.has("external_origin")&&!o.searchParams.has("origin")&&o.searchParams.set("external_origin",t),o.toString()}function P1(e){if(typeof e!="object"||e===null)return null;let t=e,o=t.type,n=t.state;if(typeof o!="string"||typeof n!="string"||o!==M&&o!==_&&o!==T&&o!==O)return null;let r={type:o,state:n};return typeof t.code=="string"&&(r.code=t.code),typeof t.reason=="string"&&(r.reason=t.reason),r}function P(e){let t=new URL(e.connectUrl).origin,o=e.origin??window.location.origin,n=null,r=!1,l=!1,f=!1,p=!1,C=null,u=g=>{if(r||g.origin!==t||n&&g.source&&g.source!==n)return;let d=P1(g.data);if(!(!d||d.state!==e.state))switch(d.type){case M:typeof d.code=="string"&&e.onConnected?.({code:d.code,state:d.state,kind:"connected"});break;case _:typeof d.code=="string"&&e.onReady?.({code:d.code,state:d.state,kind:"ready"});break;case T:e.onFailed?.({state:d.state,reason:d.reason});break;case O:a();break}};function s(){l&&(window.removeEventListener("message",u),l=!1),C&&(clearInterval(C),C=null)}function a(){r||(r=!0,s(),n&&!n.closed&&n.close(),n=null,f&&e.onClose?.())}function y(){if(r||l)return;let g=O1(e.connectUrl,o);if(n=window.open(g,e.windowName??_1(e.state),e.windowFeatures??M1()),!n||n.closed){e.onFailed?.({state:e.state,reason:"popup_blocked"});return}e.windowFeatures||T1(n),window.addEventListener("message",u),l=!0,f=!0,p=!1,C=setInterval(()=>{if(n){if(!n.closed){p=!0;return}p&&a()}},500)}return{open:y,close:a}}function R1(e){return{...e.appId===void 0?{}:{appId:e.appId},...e.userLinkRef===void 0?{}:{userLinkRef:e.userLinkRef},...e.grantStatus===void 0?{}:{grantStatus:e.grantStatus},pipelineReady:e.pipelineReady,...e.scopes===void 0?{}:{scopes:e.scopes}}}function A1(e){let t=null,o=()=>{t?.close(),t=null},n=l=>{e.telemetry?.track(l)};return{connect:l=>(n({type:"connect_started",appId:e.appId}),new Promise((f,p)=>{let C=!1,u=null,s=null,a=i=>{C||(C=!0,u&&clearTimeout(u),o(),l.onError?.(i),p(i))},y=i=>{C||(C=!0,u&&clearTimeout(u),l.onError?.(i),p(i))},g=i=>{C||(C=!0,u&&clearTimeout(u),o(),f(i))},d=async i=>{if(!(C||!s)){i.kind==="connected"&&l.onConnected?.(i),i.kind==="ready"&&l.onReady?.(i),n({type:"code_received",appId:e.appId,sessionId:s.sessionId,state:s.state,details:{kind:i.kind}}),n({type:"link_complete_started",appId:e.appId,sessionId:s.sessionId,state:s.state});try{let L=await l.completeLink({sessionId:s.sessionId,state:s.state,nonce:s.nonce,code:i.code});n({type:"link_complete_succeeded",appId:e.appId,sessionId:s.sessionId,state:s.state}),g(R1(L))}catch(L){n({type:"link_complete_failed",appId:e.appId,sessionId:s.sessionId,state:s.state}),y(new m("LINK_COMPLETE_FAILED","Facto link completion failed",{retryable:!0,details:L}))}}};(async()=>{try{n({type:"link_session_requested",appId:e.appId}),s=H1(await l.fetchLinkSession()),n({type:"link_session_received",appId:e.appId,sessionId:s.sessionId,state:s.state})}catch(i){a(new m("INVALID_LINK_SESSION","Unable to create Facto link session",{retryable:!0,details:i}));return}if(new Date(s.expiresAt).getTime()<=Date.now()){a(new m("LINK_SESSION_EXPIRED","Facto link session expired",{retryable:!0,details:{expiresAt:s.expiresAt}}));return}u=setTimeout(()=>{l.onExit?.({reason:"timeout",state:s?.state}),n({type:"connect_timeout",appId:e.appId,sessionId:s?.sessionId,state:s?.state}),a(new m("TIMEOUT","Facto Connect timed out",{retryable:!0}))},e.timeoutMs??3e5),t=P({connectUrl:s.connectUrl,state:s.state,windowName:e.popupName,windowFeatures:e.popupFeatures,onReady:i=>{d(i)},onConnected:i=>{d(i)},onFailed:i=>{if(i.reason==="popup_blocked"){n({type:"popup_blocked",appId:e.appId,state:i.state}),a(new m("POPUP_BLOCKED","Facto Connect popup was blocked",{retryable:!0}));return}a(new m("CONNECT_APP_FAILED","Facto Connect failed",{retryable:!0,details:i}))},onClose:()=>{C||(l.onExit?.({reason:"user_exit",state:s?.state}),n({type:"journey_exit",appId:e.appId,sessionId:s?.sessionId,state:s?.state}),a(new m("USER_EXIT","Facto Connect was closed before completion",{retryable:!0})))}}),t.open(),n({type:"popup_opened",appId:e.appId,sessionId:s.sessionId,state:s.state})})()})),close:o}}function H1(e){let t=e.connectUrl??e.iframeUrl;if(!t||typeof t!="string")throw new Error("Facto link session is missing connectUrl");if(!e.state||typeof e.state!="string")throw new Error("Facto link session is missing state");if(!e.expiresAt||Number.isNaN(new Date(e.expiresAt).getTime()))throw new Error("Facto link session is missing a valid expiresAt");return{...e,connectUrl:t}}function U1(e){return"connectUrl"in e&&"state"in e}function R(e){return U1(e)?P(e):A1(e)}var Z1={create:R},B1=R;
379
- //# sourceMappingURL=index.cjs.map
378
+ `,document.head.append(e)}var _="facto.externalLink.connected",T="facto.externalLink.ready",O="facto.externalLink.failed",P="facto.externalLink.closeRequested",m=class extends Error{code;retryable;status;details;constructor(t,n,s){super(n),this.name="FactoConnectError",this.code=t,this.retryable=s.retryable,this.status=s.status,this.details=s.details}},S1=460,I1=720;function Y(){let e=S1,t=I1,n=window.screenLeft??window.screenX??0,s=window.screenTop??window.screenY??0,a=window.outerWidth||e,c=window.outerHeight||t,u=Math.max(0,n+(a-e)/2),d=Math.max(0,s+(c-t)/2);return{width:e,height:t,left:Math.round(u),top:Math.round(d)}}function M1(){let{width:e,height:t,left:n,top:s}=Y();return["popup=yes",`width=${e}`,`height=${t}`,`innerWidth=${e}`,`innerHeight=${t}`,`left=${n}`,`top=${s}`,"resizable=yes","scrollbars=yes","toolbar=no","menubar=no","location=no","status=no"].join(",")}function _1(e){return`facto-connect-${e.replace(/[^a-zA-Z0-9_-]/g,"").slice(0,36)||"session"}`}function T1(e){let{width:t,height:n,left:s,top:a}=Y();try{typeof e.resizeTo=="function"&&e.resizeTo(t,n),typeof e.moveTo=="function"&&e.moveTo(s,a),typeof e.focus=="function"&&e.focus()}catch{}}function O1(e,t){let n=new URL(e);return!n.searchParams.has("external_origin")&&!n.searchParams.has("origin")&&n.searchParams.set("external_origin",t),n.toString()}function P1(e){if(typeof e!="object"||e===null)return null;let t=e,n=t.type,s=t.state;if(typeof n!="string"||typeof s!="string"||n!==_&&n!==T&&n!==O&&n!==P)return null;let a={type:n,state:s};return typeof t.code=="string"&&(a.code=t.code),typeof t.reason=="string"&&(a.reason=t.reason),a}function R(e){let t=new URL(e.connectUrl).origin,n=e.origin??window.location.origin,s=null,a=!1,c=!1,u=!1,d=!1,p=null,L=g=>{if(a||g.origin!==t||s&&g.source&&g.source!==s)return;let l=P1(g.data);if(!(!l||l.state!==e.state))switch(l.type){case _:typeof l.code=="string"&&e.onConnected?.({code:l.code,state:l.state,kind:"connected"});break;case T:typeof l.code=="string"&&e.onReady?.({code:l.code,state:l.state,kind:"ready"});break;case O:e.onFailed?.({state:l.state,reason:l.reason});break;case P:o();break}};function C(){c&&(window.removeEventListener("message",L),c=!1),p&&(clearInterval(p),p=null)}function o(){a||(a=!0,C(),s&&!s.closed&&s.close(),s=null,u&&e.onClose?.())}function f(){if(a||c)return;let g=O1(e.connectUrl,n);if(s=window.open(g,e.windowName??_1(e.state),e.windowFeatures??M1()),!s||s.closed){e.onFailed?.({state:e.state,reason:"popup_blocked"});return}e.windowFeatures||T1(s),window.addEventListener("message",L),c=!0,u=!0,d=!1,p=setInterval(()=>{if(s){if(!s.closed){d=!0;return}d&&o()}},500)}return{open:f,close:o}}function R1(e){return{...e.appId===void 0?{}:{appId:e.appId},...e.userLinkRef===void 0?{}:{userLinkRef:e.userLinkRef},...e.grantStatus===void 0?{}:{grantStatus:e.grantStatus},pipelineReady:e.pipelineReady,...e.scopes===void 0?{}:{scopes:e.scopes}}}function A1(e){let t=null,n=()=>{t?.close(),t=null},s=c=>{e.telemetry?.track(c)};return{connect:c=>(s({type:"connect_started",appId:e.appId}),new Promise((u,d)=>{let p=!1,L=!1,C=null,o=null,f=r=>{p||(p=!0,C&&clearTimeout(C),n(),c.onError?.(r),d(r))},g=r=>{p||(p=!0,C&&clearTimeout(C),c.onError?.(r),d(r))},l=r=>{p||(p=!0,C&&clearTimeout(C),n(),u(r))},v=async r=>{if(!(p||L||!o)){L=!0,r.kind==="connected"&&c.onConnected?.(r),r.kind==="ready"&&c.onReady?.(r),s({type:"code_received",appId:e.appId,sessionId:o.sessionId,state:o.state,details:{kind:r.kind}}),s({type:"link_complete_started",appId:e.appId,sessionId:o.sessionId,state:o.state});try{let y=await c.completeLink({sessionId:o.sessionId,state:o.state,nonce:o.nonce,code:r.code});s({type:"link_complete_succeeded",appId:e.appId,sessionId:o.sessionId,state:o.state}),l(R1(y))}catch(y){s({type:"link_complete_failed",appId:e.appId,sessionId:o.sessionId,state:o.state}),g(new m("LINK_COMPLETE_FAILED","Facto link completion failed",{retryable:!0,details:y}))}}};(async()=>{try{s({type:"link_session_requested",appId:e.appId}),o=H1(await c.fetchLinkSession()),s({type:"link_session_received",appId:e.appId,sessionId:o.sessionId,state:o.state})}catch(r){f(new m("INVALID_LINK_SESSION","Unable to create Facto link session",{retryable:!0,details:r}));return}if(new Date(o.expiresAt).getTime()<=Date.now()){f(new m("LINK_SESSION_EXPIRED","Facto link session expired",{retryable:!0,details:{expiresAt:o.expiresAt}}));return}C=setTimeout(()=>{c.onExit?.({reason:"timeout",state:o?.state}),s({type:"connect_timeout",appId:e.appId,sessionId:o?.sessionId,state:o?.state}),f(new m("TIMEOUT","Facto Connect timed out",{retryable:!0}))},e.timeoutMs??3e5),t=R({connectUrl:o.connectUrl,state:o.state,windowName:e.popupName,windowFeatures:e.popupFeatures,onReady:r=>{v(r)},onConnected:r=>{v(r)},onFailed:r=>{if(r.reason==="popup_blocked"){s({type:"popup_blocked",appId:e.appId,state:r.state}),f(new m("POPUP_BLOCKED","Facto Connect popup was blocked",{retryable:!0}));return}f(new m("CONNECT_APP_FAILED","Facto Connect failed",{retryable:!0,details:r}))},onClose:()=>{p||(c.onExit?.({reason:"user_exit",state:o?.state}),s({type:"journey_exit",appId:e.appId,sessionId:o?.sessionId,state:o?.state}),f(new m("USER_EXIT","Facto Connect was closed before completion",{retryable:!0})))}}),t.open(),s({type:"popup_opened",appId:e.appId,sessionId:o.sessionId,state:o.state})})()})),close:n}}function H1(e){let t=e.connectUrl??e.iframeUrl;if(!t||typeof t!="string")throw new Error("Facto link session is missing connectUrl");if(!e.state||typeof e.state!="string")throw new Error("Facto link session is missing state");if(!e.expiresAt||Number.isNaN(new Date(e.expiresAt).getTime()))throw new Error("Facto link session is missing a valid expiresAt");return{...e,connectUrl:t}}function U1(e){return"connectUrl"in e&&"state"in e}function A(e){return U1(e)?R(e):A1(e)}var Z1={create:A},B1=A;
@@ -1,4 +1,4 @@
1
- import { ExchangeLinkCodeResponse } from '@facto-to/engine-wire';
1
+ import { E as ExchangeLinkCodeResponse } from '../index.d-DE9GmLfU.cjs';
2
2
 
3
3
  interface FactoExpressCheckoutOrder {
4
4
  label: string;
@@ -61,17 +61,6 @@ interface FactoExpressCheckoutHandle {
61
61
  }
62
62
  declare function createFactoExpressCheckout(options: FactoExpressCheckoutOptions): FactoExpressCheckoutHandle;
63
63
 
64
- /**
65
- * @facto-to/connect
66
- *
67
- * Browser SDK for merchant pages to launch the Facto-owned Connect Journey.
68
- * The public client hides popup and postMessage details behind
69
- * connect({ fetchLinkSession, completeLink }).
70
- *
71
- * The low-level popup transport remains exported for the current internal demo
72
- * and tests, but partner documentation should use the high-level client.
73
- */
74
-
75
64
  declare const FACTO_LINK_CONNECTED = "facto.externalLink.connected";
76
65
  declare const FACTO_LINK_READY = "facto.externalLink.ready";
77
66
  declare const FACTO_LINK_FAILED = "facto.externalLink.failed";
@@ -150,31 +139,12 @@ interface FactoLinkCompleteInput {
150
139
  nonce?: string;
151
140
  code: string;
152
141
  }
153
- /**
154
- * What the merchant's `completeLink` callback hands back: their own backend's
155
- * relay of the engine `ExchangeLinkCodeResponse`.
156
- *
157
- * Pre-GA engine deployments and older merchant backends relay partial bodies,
158
- * so every wire field except `pipelineReady` is tolerated as absent. Whatever
159
- * arrives here, `connect()` only ever resolves `FactoConnectResult`.
160
- */
161
142
  type FactoLinkCompleteResponse = Partial<ExchangeLinkCodeResponse> & Pick<ExchangeLinkCodeResponse, 'pipelineReady'> & {
162
- /** Legacy marker kept for source compatibility; not part of the wire. */
163
143
  linked?: true;
164
- /** Route summary consumed by the legacy express-checkout callback. */
165
144
  pipeline?: FactoPipelineSummary | null;
166
145
  };
167
- /**
168
- * Merchant-safe result of `createFactoConnect(...).connect(...)`.
169
- *
170
- * Exactly the wire-derived subset a browser caller is allowed to see. The
171
- * legacy identity fields `factoUserId`, `factoServerWalletAddress`, and
172
- * `cardRef` are server-side only and are stripped before this resolves — do not
173
- * widen this type to reintroduce them.
174
- */
175
146
  type FactoConnectResult = Pick<ExchangeLinkCodeResponse, 'pipelineReady'> & Partial<Pick<ExchangeLinkCodeResponse, 'appId' | 'userLinkRef' | 'grantStatus' | 'scopes'>>;
176
147
  interface FactoPipelineSummary {
177
- selectedPipelineId: string;
178
148
  chainId: number;
179
149
  protocolId: string;
180
150
  assetSymbol?: string;
@@ -1,4 +1,4 @@
1
- import { ExchangeLinkCodeResponse } from '@facto-to/engine-wire';
1
+ import { E as ExchangeLinkCodeResponse } from '../index.d-DE9GmLfU.js';
2
2
 
3
3
  interface FactoExpressCheckoutOrder {
4
4
  label: string;
@@ -61,17 +61,6 @@ interface FactoExpressCheckoutHandle {
61
61
  }
62
62
  declare function createFactoExpressCheckout(options: FactoExpressCheckoutOptions): FactoExpressCheckoutHandle;
63
63
 
64
- /**
65
- * @facto-to/connect
66
- *
67
- * Browser SDK for merchant pages to launch the Facto-owned Connect Journey.
68
- * The public client hides popup and postMessage details behind
69
- * connect({ fetchLinkSession, completeLink }).
70
- *
71
- * The low-level popup transport remains exported for the current internal demo
72
- * and tests, but partner documentation should use the high-level client.
73
- */
74
-
75
64
  declare const FACTO_LINK_CONNECTED = "facto.externalLink.connected";
76
65
  declare const FACTO_LINK_READY = "facto.externalLink.ready";
77
66
  declare const FACTO_LINK_FAILED = "facto.externalLink.failed";
@@ -150,31 +139,12 @@ interface FactoLinkCompleteInput {
150
139
  nonce?: string;
151
140
  code: string;
152
141
  }
153
- /**
154
- * What the merchant's `completeLink` callback hands back: their own backend's
155
- * relay of the engine `ExchangeLinkCodeResponse`.
156
- *
157
- * Pre-GA engine deployments and older merchant backends relay partial bodies,
158
- * so every wire field except `pipelineReady` is tolerated as absent. Whatever
159
- * arrives here, `connect()` only ever resolves `FactoConnectResult`.
160
- */
161
142
  type FactoLinkCompleteResponse = Partial<ExchangeLinkCodeResponse> & Pick<ExchangeLinkCodeResponse, 'pipelineReady'> & {
162
- /** Legacy marker kept for source compatibility; not part of the wire. */
163
143
  linked?: true;
164
- /** Route summary consumed by the legacy express-checkout callback. */
165
144
  pipeline?: FactoPipelineSummary | null;
166
145
  };
167
- /**
168
- * Merchant-safe result of `createFactoConnect(...).connect(...)`.
169
- *
170
- * Exactly the wire-derived subset a browser caller is allowed to see. The
171
- * legacy identity fields `factoUserId`, `factoServerWalletAddress`, and
172
- * `cardRef` are server-side only and are stripped before this resolves — do not
173
- * widen this type to reintroduce them.
174
- */
175
146
  type FactoConnectResult = Pick<ExchangeLinkCodeResponse, 'pipelineReady'> & Partial<Pick<ExchangeLinkCodeResponse, 'appId' | 'userLinkRef' | 'grantStatus' | 'scopes'>>;
176
147
  interface FactoPipelineSummary {
177
- selectedPipelineId: string;
178
148
  chainId: number;
179
149
  protocolId: string;
180
150
  assetSymbol?: string;
@@ -117,7 +117,7 @@ var R=`<svg xmlns:xodm="http://www.corel.com/coreldraw/odm/2003" xmlns="http://w
117
117
  transform="translate(70 66)"
118
118
  />
119
119
  </svg>
120
- `,r1='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill-opacity=".5" d="M17.82 14.342v4.672h1.275c.172 0 .312-.14.312-.311v-4.05a.31.31 0 0 0-.312-.312zm0-9.356v4.673h1.275c.172 0 .312-.14.312-.312v-4.05a.31.31 0 0 0-.312-.311z"/><path fill-opacity=".3" d="M20.209 4.986v4.673h.477c.172 0 .311-.14.311-.312v-4.05a.31.31 0 0 0-.311-.311zm.002 9.356v4.672h.477c.172 0 .312-.14.312-.311v-4.05a.31.31 0 0 0-.312-.312z"/><path d="M12.026 9.67h-4.03a.31.31 0 0 0-.31.307v4.002c0 .17.138.308.31.308h4.03a.31.31 0 0 0 .31-.308V9.977a.31.31 0 0 0-.31-.308M7.361 4.986h-4.05A.31.31 0 0 0 3 5.297v4.05c0 .172.14.312.312.312h4.05c.171 0 .31-.14.31-.312v-4.05a.31.31 0 0 0-.31-.311m9.343 0h-4.05a.31.31 0 0 0-.311.311v4.05c0 .172.14.312.311.312h4.05c.172 0 .312-.14.312-.312v-4.05a.31.31 0 0 0-.312-.311M7.361 14.33h-4.05a.31.31 0 0 0-.311.313v4.05c0 .171.14.31.312.31h4.05a.31.31 0 0 0 .31-.31v-4.05a.31.31 0 0 0-.31-.312m9.343-.001h-4.05a.31.31 0 0 0-.311.313v4.05c0 .171.14.31.311.31h4.05a.31.31 0 0 0 .312-.31v-4.05a.31.31 0 0 0-.312-.312"/></svg>',U=[{chainId:1,name:"Ethereum",gasSymbol:"ETH",explorerUrl:"https://etherscan.io",logo:Q,logoTheme:"normal",testnet:!1},{chainId:56,name:"BNB",gasSymbol:"BNB",explorerUrl:"https://bscscan.com",logo:G,logoTheme:"normal",testnet:!1},{chainId:137,name:"Polygon",gasSymbol:"POL",explorerUrl:"https://polygonscan.com",logo:o1,logoTheme:"normal",testnet:!1},{chainId:143,name:"Monad",gasSymbol:"MON",explorerUrl:"https://monadscan.com",logo:e1,logoTheme:"normal",testnet:!1},{chainId:196,name:"X Layer",gasSymbol:"OKB",explorerUrl:"https://www.oklink.com/x-layer/evm",logo:r1,logoTheme:"invertOnDark",testnet:!1},{chainId:988,name:"Stable Mainnet",gasSymbol:"USDT0",explorerUrl:"https://stablescan.xyz",logo:a1,logoTheme:"invertOnLight",testnet:!1},{chainId:1329,name:"Sei",gasSymbol:"SEI",explorerUrl:"https://seiscan.io",logo:s1,logoTheme:"normal",testnet:!1},{chainId:4217,name:"Tempo",gasSymbol:"TMPO",explorerUrl:"https://explore.tempo.xyz",logo:H,logoTheme:"normal",testnet:!1},{chainId:4326,name:"MegaETH",gasSymbol:"ETH",explorerUrl:"https://mega.etherscan.io",logo:J,logoTheme:"normal",testnet:!1},{chainId:8453,name:"Base",gasSymbol:"ETH",explorerUrl:"https://basescan.org",logo:A,logoTheme:"normal",testnet:!1},{chainId:9745,name:"Plasma",gasSymbol:"XPL",explorerUrl:"https://plasmascan.to",logo:t1,logoTheme:"normal",testnet:!1},{chainId:42161,name:"Arbitrum",gasSymbol:"ETH",explorerUrl:"https://arbiscan.io",logo:R,logoTheme:"normal",testnet:!1},{chainId:42431,name:"Tempo Moderato",gasSymbol:"SEI",explorerUrl:"https://explore.tempo.xyz",logo:H,logoTheme:"normal",testnet:!0},{chainId:46630,name:"Robinhood Testnet",gasSymbol:"ETH",explorerUrl:"https://explorer.testnet.chain.robinhood.com",logo:n1,logoTheme:"normal",testnet:!0},{chainId:84532,name:"Base Sepolia",gasSymbol:"ETH",explorerUrl:"https://sepolia.basescan.org",logo:A,logoTheme:"normal",testnet:!0},{chainId:421614,name:"Arbitrum Sepolia",gasSymbol:"ETH",explorerUrl:"https://sepolia.arbiscan.io",logo:R,logoTheme:"normal",testnet:!0}],b=Object.fromEntries(U.map(e=>[e.chainId,e])),i1=`<svg width="100" height="100" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
120
+ `,r1='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill-opacity=".5" d="M17.82 14.342v4.672h1.275c.172 0 .312-.14.312-.311v-4.05a.31.31 0 0 0-.312-.312zm0-9.356v4.673h1.275c.172 0 .312-.14.312-.312v-4.05a.31.31 0 0 0-.312-.311z"/><path fill-opacity=".3" d="M20.209 4.986v4.673h.477c.172 0 .311-.14.311-.312v-4.05a.31.31 0 0 0-.311-.311zm.002 9.356v4.672h.477c.172 0 .312-.14.312-.311v-4.05a.31.31 0 0 0-.312-.312z"/><path d="M12.026 9.67h-4.03a.31.31 0 0 0-.31.307v4.002c0 .17.138.308.31.308h4.03a.31.31 0 0 0 .31-.308V9.977a.31.31 0 0 0-.31-.308M7.361 4.986h-4.05A.31.31 0 0 0 3 5.297v4.05c0 .172.14.312.312.312h4.05c.171 0 .31-.14.31-.312v-4.05a.31.31 0 0 0-.31-.311m9.343 0h-4.05a.31.31 0 0 0-.311.311v4.05c0 .172.14.312.311.312h4.05c.172 0 .312-.14.312-.312v-4.05a.31.31 0 0 0-.312-.311M7.361 14.33h-4.05a.31.31 0 0 0-.311.313v4.05c0 .171.14.31.312.31h4.05a.31.31 0 0 0 .31-.31v-4.05a.31.31 0 0 0-.31-.312m9.343-.001h-4.05a.31.31 0 0 0-.311.313v4.05c0 .171.14.31.311.31h4.05a.31.31 0 0 0 .312-.31v-4.05a.31.31 0 0 0-.312-.312"/></svg>',U=[{chainId:1,name:"Ethereum",gasSymbol:"ETH",explorerUrl:"https://etherscan.io",logo:Q,logoTheme:"normal",testnet:!1},{chainId:56,name:"BNB",gasSymbol:"BNB",explorerUrl:"https://bscscan.com",logo:G,logoTheme:"normal",testnet:!1},{chainId:137,name:"Polygon",gasSymbol:"POL",explorerUrl:"https://polygonscan.com",logo:o1,logoTheme:"normal",testnet:!1},{chainId:143,name:"Monad",gasSymbol:"MON",explorerUrl:"https://monadscan.com",logo:e1,logoTheme:"normal",testnet:!1},{chainId:196,name:"X Layer",gasSymbol:"OKB",explorerUrl:"https://www.oklink.com/x-layer/evm",logo:r1,logoTheme:"invertOnDark",testnet:!1},{chainId:988,name:"Stable Mainnet",gasSymbol:"USDT0",explorerUrl:"https://stablescan.xyz",logo:a1,logoTheme:"invertOnLight",testnet:!1},{chainId:1329,name:"Sei",gasSymbol:"SEI",explorerUrl:"https://seiscan.io",logo:s1,logoTheme:"normal",testnet:!1},{chainId:4217,name:"Tempo",gasSymbol:"TMPO",explorerUrl:"https://explore.tempo.xyz",logo:H,logoTheme:"normal",testnet:!1},{chainId:4326,name:"MegaETH",gasSymbol:"ETH",explorerUrl:"https://mega.etherscan.io",logo:J,logoTheme:"normal",testnet:!1},{chainId:8453,name:"Base",gasSymbol:"ETH",explorerUrl:"https://basescan.org",logo:A,logoTheme:"normal",testnet:!1},{chainId:9745,name:"Plasma",gasSymbol:"XPL",explorerUrl:"https://plasmascan.to",logo:t1,logoTheme:"normal",testnet:!1},{chainId:42161,name:"Arbitrum",gasSymbol:"ETH",explorerUrl:"https://arbiscan.io",logo:R,logoTheme:"normal",testnet:!1},{chainId:42431,name:"Tempo Moderato",gasSymbol:"SEI",explorerUrl:"https://explore.tempo.xyz",logo:H,logoTheme:"normal",testnet:!0},{chainId:46630,name:"Robinhood Testnet",gasSymbol:"ETH",explorerUrl:"https://explorer.testnet.chain.robinhood.com",logo:n1,logoTheme:"normal",testnet:!0},{chainId:84532,name:"Base Sepolia",gasSymbol:"ETH",explorerUrl:"https://sepolia.basescan.org",logo:A,logoTheme:"normal",testnet:!0},{chainId:421614,name:"Arbitrum Sepolia",gasSymbol:"ETH",explorerUrl:"https://sepolia.arbiscan.io",logo:R,logoTheme:"normal",testnet:!0}],E=Object.fromEntries(U.map(e=>[e.chainId,e])),i1=`<svg width="100" height="100" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
121
121
  <!-- PLACEHOLDER \u2014 not final artwork. See src/assets/chains/README.md. -->
122
122
  <circle cx="50" cy="50" r="47" fill="#E5E7EB" stroke="#9CA3AF" stroke-width="2" stroke-dasharray="6 5"/>
123
123
  <text x="50" y="58" font-family="ui-sans-serif, system-ui, sans-serif" font-size="30" font-weight="600" fill="#6B7280" text-anchor="middle">AV3</text>
@@ -137,7 +137,7 @@ var R=`<svg xmlns:xodm="http://www.corel.com/coreldraw/odm/2003" xmlns="http://w
137
137
  <circle cx="50" cy="50" r="47" fill="#E5E7EB" stroke="#9CA3AF" stroke-width="2" stroke-dasharray="6 5"/>
138
138
  <text x="50" y="58" font-family="ui-sans-serif, system-ui, sans-serif" font-size="30" font-weight="600" fill="#6B7280" text-anchor="middle">MB</text>
139
139
  </svg>
140
- `,Z=[{id:"aave-v3",name:"AAVE V3",logo:i1,logoTheme:"normal"},{id:"compound-v2",name:"Compound V2",logo:c1,logoTheme:"normal"},{id:"morpho",name:"Morpho Blue",logo:d1,logoTheme:"normal"},{id:"dolomite",name:"Dolomite",logo:l1,logoTheme:"normal"}],E=Object.fromEntries(Z.map(e=>[e.id,e]));var B=!1;function p1(e){let o=u1(e.container);L1();let t=e,n=k(void 0).setup,l={kind:"idle",message:""},c=!1,f=N("facto-express-root"),p=document.createElement("button");p.type="button",p.className="facto-express-button",p.addEventListener("click",()=>{L()});let C=document.createElement("span"),u=document.createElement("strong");p.append(C,u);let s=document.createElement("p");s.className="facto-express-inline-status",s.setAttribute("role","status"),s.setAttribute("aria-live","polite"),f.append(p,s),o.replaceChildren(f);let a=N("facto-express-overlay");a.setAttribute("aria-hidden","true"),a.innerHTML=C1(),document.body.append(a);let y=v(a,"[data-facto-close]"),g=v(a,"[data-facto-change]"),d=v(a,"[data-facto-pay]"),r=v(a,"[data-facto-result]");y.addEventListener("click",w),g.addEventListener("click",()=>{I()}),d.addEventListener("click",()=>{X()}),document.addEventListener("keydown",_),T(),F();async function L(){if(!c){m({kind:"checking",message:"Checking saved Facto setup..."});try{let i=k(await t.getPaymentSetup());if(i.setup?.ready){n=i.setup,M();return}await I()}catch(i){m({kind:"error",message:S(i,"Facto checkout could not start.")})}}}async function I(){if(!c){m({kind:"setup",message:"Opening Facto secure checkout..."});try{let i=k(await t.startPaymentSetup());if(!i.setup?.ready){m({kind:"setup",message:i.state?.message??"Finish Facto setup"});return}n=i.setup,M()}catch(i){m({kind:"error",message:S(i,"Facto setup could not be completed.")})}}}async function X(){if(!(c||!n?.ready)){m({kind:"paying",message:"Submitting Facto payment..."}),d.disabled=!0;try{let i=await t.submitPayment(n);m({kind:"success",message:i?.message??"Payment authorized with Facto."})}catch(i){m({kind:"error",message:S(i,"Facto payment failed.")})}finally{d.disabled=!1}}}function M(){F(),a.dataset.open="true",a.setAttribute("aria-hidden","false"),m({kind:"ready",message:""}),d.focus()}function w(){a.dataset.open="false",a.setAttribute("aria-hidden","true"),p.focus()}function Y(i){t={...t,...i},T(),F()}function q(){c=!0,document.removeEventListener("keydown",_),a.remove(),f.remove()}function _(i){i.key==="Escape"&&a.dataset.open==="true"&&w()}function m(i){l=i,t.onStatusChange?.(l),O()}function T(){let i=t.buttonLabel??"Pay with",P=t.brandLabel??"Facto";C.textContent=i,u.textContent=P,p.setAttribute("aria-label",`${i} ${P}`)}function F(){let i=n;h(a,"[data-facto-brand]",t.brandLabel??"Facto"),h(a,"[data-facto-route]",i?.routeLabel??"Connect Facto to pay"),h(a,"[data-facto-address]",i?x1(i.walletAddress):""),h(a,"[data-facto-order-label]",t.order.label),h(a,"[data-facto-order-amount]",t.order.amountLabel),h(a,"[data-facto-shipping]",t.order.shippingLabel??"Included"),h(a,"[data-facto-total]",t.order.amountLabel),h(a,"[data-facto-pay-label]",`Pay ${t.order.amountLabel} with ${t.brandLabel??"Facto"}`),h(a,"[data-facto-env]",`Sandbox target: ${t.environmentLabel??"local"}`),O()}function O(){s.textContent=l.message,s.dataset.kind=l.kind,r.textContent=l.kind==="ready"?"":l.message,r.dataset.kind=l.kind}return{open:L,close:w,update:Y,destroy:q}}function C1(){return`
140
+ `,Z=[{id:"aave-v3",name:"AAVE V3",logo:i1,logoTheme:"normal"},{id:"compound-v2",name:"Compound V2",logo:c1,logoTheme:"normal"},{id:"morpho",name:"Morpho Blue",logo:d1,logoTheme:"normal"},{id:"dolomite",name:"Dolomite",logo:l1,logoTheme:"normal"}],k=Object.fromEntries(Z.map(e=>[e.id,e]));var B=!1;function p1(e){let n=u1(e.container);L1();let o=e,s=S(void 0).setup,c={kind:"idle",message:""},i=!1,u=N("facto-express-root"),d=document.createElement("button");d.type="button",d.className="facto-express-button",d.addEventListener("click",()=>{a()});let p=document.createElement("span"),L=document.createElement("strong");d.append(p,L);let C=document.createElement("p");C.className="facto-express-inline-status",C.setAttribute("role","status"),C.setAttribute("aria-live","polite"),u.append(d,C),n.replaceChildren(u);let t=N("facto-express-overlay");t.setAttribute("aria-hidden","true"),t.innerHTML=C1(),document.body.append(t);let f=w(t,"[data-facto-close]"),g=w(t,"[data-facto-change]"),l=w(t,"[data-facto-pay]"),v=w(t,"[data-facto-result]");f.addEventListener("click",F),g.addEventListener("click",()=>{y()}),l.addEventListener("click",()=>{X()}),document.addEventListener("keydown",_),T(),b();async function a(){if(!i){m({kind:"checking",message:"Checking saved Facto setup..."});try{let r=S(await o.getPaymentSetup());if(r.setup?.ready){s=r.setup,M();return}await y()}catch(r){m({kind:"error",message:I(r,"Facto checkout could not start.")})}}}async function y(){if(!i){m({kind:"setup",message:"Opening Facto secure checkout..."});try{let r=S(await o.startPaymentSetup());if(!r.setup?.ready){m({kind:"setup",message:r.state?.message??"Finish Facto setup"});return}s=r.setup,M()}catch(r){m({kind:"error",message:I(r,"Facto setup could not be completed.")})}}}async function X(){if(!(i||!s?.ready)){m({kind:"paying",message:"Submitting Facto payment..."}),l.disabled=!0;try{let r=await o.submitPayment(s);m({kind:"success",message:r?.message??"Payment authorized with Facto."})}catch(r){m({kind:"error",message:I(r,"Facto payment failed.")})}finally{l.disabled=!1}}}function M(){b(),t.dataset.open="true",t.setAttribute("aria-hidden","false"),m({kind:"ready",message:""}),l.focus()}function F(){t.dataset.open="false",t.setAttribute("aria-hidden","true"),d.focus()}function Y(r){o={...o,...r},T(),b()}function q(){i=!0,document.removeEventListener("keydown",_),t.remove(),u.remove()}function _(r){r.key==="Escape"&&t.dataset.open==="true"&&F()}function m(r){c=r,o.onStatusChange?.(c),O()}function T(){let r=o.buttonLabel??"Pay with",P=o.brandLabel??"Facto";p.textContent=r,L.textContent=P,d.setAttribute("aria-label",`${r} ${P}`)}function b(){let r=s;h(t,"[data-facto-brand]",o.brandLabel??"Facto"),h(t,"[data-facto-route]",r?.routeLabel??"Connect Facto to pay"),h(t,"[data-facto-address]",r?x1(r.walletAddress):""),h(t,"[data-facto-order-label]",o.order.label),h(t,"[data-facto-order-amount]",o.order.amountLabel),h(t,"[data-facto-shipping]",o.order.shippingLabel??"Included"),h(t,"[data-facto-total]",o.order.amountLabel),h(t,"[data-facto-pay-label]",`Pay ${o.order.amountLabel} with ${o.brandLabel??"Facto"}`),h(t,"[data-facto-env]",`Sandbox target: ${o.environmentLabel??"local"}`),O()}function O(){C.textContent=c.message,C.dataset.kind=c.kind,v.textContent=c.kind==="ready"?"":c.message,v.dataset.kind=c.kind}return{open:a,close:F,update:Y,destroy:q}}function C1(){return`
141
141
  <section class="facto-express-sheet" role="dialog" aria-modal="true" aria-labelledby="facto-express-title">
142
142
  <div class="facto-express-close-row">
143
143
  <button type="button" class="facto-express-secondary" data-facto-close>Close</button>
@@ -184,7 +184,7 @@ var R=`<svg xmlns:xodm="http://www.corel.com/coreldraw/odm/2003" xmlns="http://w
184
184
  <p class="facto-express-result" role="status" aria-live="polite" data-facto-result></p>
185
185
  </div>
186
186
  </section>
187
- `}function u1(e){if(typeof e!="string")return e;let o=document.querySelector(e);if(o instanceof HTMLElement)return o;throw new Error(`Facto checkout container was not found: ${e}`)}function k(e){return e?f1(e)?{setup:null,state:e}:"pipelineReady"in e?e.pipelineReady?e.factoServerWalletAddress?{setup:{walletAddress:e.factoServerWalletAddress,routeLabel:g1(e.pipeline),ready:!0},state:null}:{setup:null,state:null}:{setup:null,state:{buttonLabel:"Pay with Facto",setupStatus:"finish_facto_setup",message:"Finish Facto setup. We'll resume checkout here.",paymentReady:!1,mandateReady:!1,blockingReason:"payment_path_required"}}:e.ready?{setup:e,state:null}:{setup:null,state:null}:{setup:null,state:null}}function f1(e){return"setupStatus"in e&&"paymentReady"in e&&"mandateReady"in e}function g1(e){return e?[m1(e.chainId),h1(e.protocolId),e.assetSymbol].filter(Boolean).join(" \xB7 "):"Facto payment route"}function m1(e){return b[e]?.name??`Chain ${e}`}function h1(e){return E[e]?.name??e}function x1(e){return e.length>12?`${e.slice(0,6)}...${e.slice(-4)}`:e}function N(e){let o=document.createElement("div");return o.className=e,o}function v(e,o){let t=e.querySelector(o);if(!t)throw new Error(`Facto checkout element missing: ${o}`);return t}function h(e,o,t){v(e,o).textContent=t}function S(e,o){return e instanceof Error?e.message:o}function L1(){if(B)return;B=!0;let e=document.createElement("style");e.dataset.factoExpressCheckout="true",e.textContent=`
187
+ `}function u1(e){if(typeof e!="string")return e;let n=document.querySelector(e);if(n instanceof HTMLElement)return n;throw new Error(`Facto checkout container was not found: ${e}`)}function S(e){return e?f1(e)?{setup:null,state:e}:"pipelineReady"in e?e.pipelineReady?e.factoServerWalletAddress?{setup:{walletAddress:e.factoServerWalletAddress,routeLabel:g1(e.pipeline),ready:!0},state:null}:{setup:null,state:null}:{setup:null,state:{buttonLabel:"Pay with Facto",setupStatus:"finish_facto_setup",message:"Finish Facto setup. We'll resume checkout here.",paymentReady:!1,mandateReady:!1,blockingReason:"payment_path_required"}}:e.ready?{setup:e,state:null}:{setup:null,state:null}:{setup:null,state:null}}function f1(e){return"setupStatus"in e&&"paymentReady"in e&&"mandateReady"in e}function g1(e){return e?[m1(e.chainId),h1(e.protocolId),e.assetSymbol].filter(Boolean).join(" \xB7 "):"Facto payment route"}function m1(e){return E[e]?.name??`Chain ${e}`}function h1(e){return k[e]?.name??e}function x1(e){return e.length>12?`${e.slice(0,6)}...${e.slice(-4)}`:e}function N(e){let n=document.createElement("div");return n.className=e,n}function w(e,n){let o=e.querySelector(n);if(!o)throw new Error(`Facto checkout element missing: ${n}`);return o}function h(e,n,o){w(e,n).textContent=o}function I(e,n){return e instanceof Error?e.message:n}function L1(){if(B)return;B=!0;let e=document.createElement("style");e.dataset.factoExpressCheckout="true",e.textContent=`
188
188
  .facto-express-root { width: 100%; }
189
189
  .facto-express-button {
190
190
  width: min(352px, 100%);
@@ -375,5 +375,4 @@ var R=`<svg xmlns:xodm="http://www.corel.com/coreldraw/odm/2003" xmlns="http://w
375
375
  .facto-express-body { padding: 16px; }
376
376
  .facto-express-button { width: 100%; }
377
377
  }
378
- `,document.head.append(e)}var D="facto.externalLink.connected",z="facto.externalLink.ready",V="facto.externalLink.failed",$="facto.externalLink.closeRequested",x=class extends Error{code;retryable;status;details;constructor(o,t,n){super(t),this.name="FactoConnectError",this.code=o,this.retryable=n.retryable,this.status=n.status,this.details=n.details}},y1=460,v1=720;function K(){let e=y1,o=v1,t=window.screenLeft??window.screenX??0,n=window.screenTop??window.screenY??0,l=window.outerWidth||e,c=window.outerHeight||o,f=Math.max(0,t+(l-e)/2),p=Math.max(0,n+(c-o)/2);return{width:e,height:o,left:Math.round(f),top:Math.round(p)}}function w1(){let{width:e,height:o,left:t,top:n}=K();return["popup=yes",`width=${e}`,`height=${o}`,`innerWidth=${e}`,`innerHeight=${o}`,`left=${t}`,`top=${n}`,"resizable=yes","scrollbars=yes","toolbar=no","menubar=no","location=no","status=no"].join(",")}function F1(e){return`facto-connect-${e.replace(/[^a-zA-Z0-9_-]/g,"").slice(0,36)||"session"}`}function b1(e){let{width:o,height:t,left:n,top:l}=K();try{typeof e.resizeTo=="function"&&e.resizeTo(o,t),typeof e.moveTo=="function"&&e.moveTo(n,l),typeof e.focus=="function"&&e.focus()}catch{}}function E1(e,o){let t=new URL(e);return!t.searchParams.has("external_origin")&&!t.searchParams.has("origin")&&t.searchParams.set("external_origin",o),t.toString()}function k1(e){if(typeof e!="object"||e===null)return null;let o=e,t=o.type,n=o.state;if(typeof t!="string"||typeof n!="string"||t!==D&&t!==z&&t!==V&&t!==$)return null;let l={type:t,state:n};return typeof o.code=="string"&&(l.code=o.code),typeof o.reason=="string"&&(l.reason=o.reason),l}function j(e){let o=new URL(e.connectUrl).origin,t=e.origin??window.location.origin,n=null,l=!1,c=!1,f=!1,p=!1,C=null,u=g=>{if(l||g.origin!==o||n&&g.source&&g.source!==n)return;let d=k1(g.data);if(!(!d||d.state!==e.state))switch(d.type){case D:typeof d.code=="string"&&e.onConnected?.({code:d.code,state:d.state,kind:"connected"});break;case z:typeof d.code=="string"&&e.onReady?.({code:d.code,state:d.state,kind:"ready"});break;case V:e.onFailed?.({state:d.state,reason:d.reason});break;case $:a();break}};function s(){c&&(window.removeEventListener("message",u),c=!1),C&&(clearInterval(C),C=null)}function a(){l||(l=!0,s(),n&&!n.closed&&n.close(),n=null,f&&e.onClose?.())}function y(){if(l||c)return;let g=E1(e.connectUrl,t);if(n=window.open(g,e.windowName??F1(e.state),e.windowFeatures??w1()),!n||n.closed){e.onFailed?.({state:e.state,reason:"popup_blocked"});return}e.windowFeatures||b1(n),window.addEventListener("message",u),c=!0,f=!0,p=!1,C=setInterval(()=>{if(n){if(!n.closed){p=!0;return}p&&a()}},500)}return{open:y,close:a}}function S1(e){return{...e.appId===void 0?{}:{appId:e.appId},...e.userLinkRef===void 0?{}:{userLinkRef:e.userLinkRef},...e.grantStatus===void 0?{}:{grantStatus:e.grantStatus},pipelineReady:e.pipelineReady,...e.scopes===void 0?{}:{scopes:e.scopes}}}function I1(e){let o=null,t=()=>{o?.close(),o=null},n=c=>{e.telemetry?.track(c)};return{connect:c=>(n({type:"connect_started",appId:e.appId}),new Promise((f,p)=>{let C=!1,u=null,s=null,a=r=>{C||(C=!0,u&&clearTimeout(u),t(),c.onError?.(r),p(r))},y=r=>{C||(C=!0,u&&clearTimeout(u),c.onError?.(r),p(r))},g=r=>{C||(C=!0,u&&clearTimeout(u),t(),f(r))},d=async r=>{if(!(C||!s)){r.kind==="connected"&&c.onConnected?.(r),r.kind==="ready"&&c.onReady?.(r),n({type:"code_received",appId:e.appId,sessionId:s.sessionId,state:s.state,details:{kind:r.kind}}),n({type:"link_complete_started",appId:e.appId,sessionId:s.sessionId,state:s.state});try{let L=await c.completeLink({sessionId:s.sessionId,state:s.state,nonce:s.nonce,code:r.code});n({type:"link_complete_succeeded",appId:e.appId,sessionId:s.sessionId,state:s.state}),g(S1(L))}catch(L){n({type:"link_complete_failed",appId:e.appId,sessionId:s.sessionId,state:s.state}),y(new x("LINK_COMPLETE_FAILED","Facto link completion failed",{retryable:!0,details:L}))}}};(async()=>{try{n({type:"link_session_requested",appId:e.appId}),s=M1(await c.fetchLinkSession()),n({type:"link_session_received",appId:e.appId,sessionId:s.sessionId,state:s.state})}catch(r){a(new x("INVALID_LINK_SESSION","Unable to create Facto link session",{retryable:!0,details:r}));return}if(new Date(s.expiresAt).getTime()<=Date.now()){a(new x("LINK_SESSION_EXPIRED","Facto link session expired",{retryable:!0,details:{expiresAt:s.expiresAt}}));return}u=setTimeout(()=>{c.onExit?.({reason:"timeout",state:s?.state}),n({type:"connect_timeout",appId:e.appId,sessionId:s?.sessionId,state:s?.state}),a(new x("TIMEOUT","Facto Connect timed out",{retryable:!0}))},e.timeoutMs??3e5),o=j({connectUrl:s.connectUrl,state:s.state,windowName:e.popupName,windowFeatures:e.popupFeatures,onReady:r=>{d(r)},onConnected:r=>{d(r)},onFailed:r=>{if(r.reason==="popup_blocked"){n({type:"popup_blocked",appId:e.appId,state:r.state}),a(new x("POPUP_BLOCKED","Facto Connect popup was blocked",{retryable:!0}));return}a(new x("CONNECT_APP_FAILED","Facto Connect failed",{retryable:!0,details:r}))},onClose:()=>{C||(c.onExit?.({reason:"user_exit",state:s?.state}),n({type:"journey_exit",appId:e.appId,sessionId:s?.sessionId,state:s?.state}),a(new x("USER_EXIT","Facto Connect was closed before completion",{retryable:!0})))}}),o.open(),n({type:"popup_opened",appId:e.appId,sessionId:s.sessionId,state:s.state})})()})),close:t}}function M1(e){let o=e.connectUrl??e.iframeUrl;if(!o||typeof o!="string")throw new Error("Facto link session is missing connectUrl");if(!e.state||typeof e.state!="string")throw new Error("Facto link session is missing state");if(!e.expiresAt||Number.isNaN(new Date(e.expiresAt).getTime()))throw new Error("Facto link session is missing a valid expiresAt");return{...e,connectUrl:o}}function _1(e){return"connectUrl"in e&&"state"in e}function W(e){return _1(e)?j(e):I1(e)}var H1={create:W},U1=W;export{$ as FACTO_LINK_CLOSE_REQUESTED,D as FACTO_LINK_CONNECTED,V as FACTO_LINK_FAILED,z as FACTO_LINK_READY,H1 as FactoConnect,x as FactoConnectError,W as createFactoConnect,j as createFactoConnectTransport,p1 as createFactoExpressCheckout,U1 as default};
379
- //# sourceMappingURL=index.js.map
378
+ `,document.head.append(e)}var D="facto.externalLink.connected",z="facto.externalLink.ready",V="facto.externalLink.failed",$="facto.externalLink.closeRequested",x=class extends Error{code;retryable;status;details;constructor(n,o,s){super(o),this.name="FactoConnectError",this.code=n,this.retryable=s.retryable,this.status=s.status,this.details=s.details}},y1=460,v1=720;function K(){let e=y1,n=v1,o=window.screenLeft??window.screenX??0,s=window.screenTop??window.screenY??0,c=window.outerWidth||e,i=window.outerHeight||n,u=Math.max(0,o+(c-e)/2),d=Math.max(0,s+(i-n)/2);return{width:e,height:n,left:Math.round(u),top:Math.round(d)}}function w1(){let{width:e,height:n,left:o,top:s}=K();return["popup=yes",`width=${e}`,`height=${n}`,`innerWidth=${e}`,`innerHeight=${n}`,`left=${o}`,`top=${s}`,"resizable=yes","scrollbars=yes","toolbar=no","menubar=no","location=no","status=no"].join(",")}function F1(e){return`facto-connect-${e.replace(/[^a-zA-Z0-9_-]/g,"").slice(0,36)||"session"}`}function b1(e){let{width:n,height:o,left:s,top:c}=K();try{typeof e.resizeTo=="function"&&e.resizeTo(n,o),typeof e.moveTo=="function"&&e.moveTo(s,c),typeof e.focus=="function"&&e.focus()}catch{}}function E1(e,n){let o=new URL(e);return!o.searchParams.has("external_origin")&&!o.searchParams.has("origin")&&o.searchParams.set("external_origin",n),o.toString()}function k1(e){if(typeof e!="object"||e===null)return null;let n=e,o=n.type,s=n.state;if(typeof o!="string"||typeof s!="string"||o!==D&&o!==z&&o!==V&&o!==$)return null;let c={type:o,state:s};return typeof n.code=="string"&&(c.code=n.code),typeof n.reason=="string"&&(c.reason=n.reason),c}function j(e){let n=new URL(e.connectUrl).origin,o=e.origin??window.location.origin,s=null,c=!1,i=!1,u=!1,d=!1,p=null,L=g=>{if(c||g.origin!==n||s&&g.source&&g.source!==s)return;let l=k1(g.data);if(!(!l||l.state!==e.state))switch(l.type){case D:typeof l.code=="string"&&e.onConnected?.({code:l.code,state:l.state,kind:"connected"});break;case z:typeof l.code=="string"&&e.onReady?.({code:l.code,state:l.state,kind:"ready"});break;case V:e.onFailed?.({state:l.state,reason:l.reason});break;case $:t();break}};function C(){i&&(window.removeEventListener("message",L),i=!1),p&&(clearInterval(p),p=null)}function t(){c||(c=!0,C(),s&&!s.closed&&s.close(),s=null,u&&e.onClose?.())}function f(){if(c||i)return;let g=E1(e.connectUrl,o);if(s=window.open(g,e.windowName??F1(e.state),e.windowFeatures??w1()),!s||s.closed){e.onFailed?.({state:e.state,reason:"popup_blocked"});return}e.windowFeatures||b1(s),window.addEventListener("message",L),i=!0,u=!0,d=!1,p=setInterval(()=>{if(s){if(!s.closed){d=!0;return}d&&t()}},500)}return{open:f,close:t}}function S1(e){return{...e.appId===void 0?{}:{appId:e.appId},...e.userLinkRef===void 0?{}:{userLinkRef:e.userLinkRef},...e.grantStatus===void 0?{}:{grantStatus:e.grantStatus},pipelineReady:e.pipelineReady,...e.scopes===void 0?{}:{scopes:e.scopes}}}function I1(e){let n=null,o=()=>{n?.close(),n=null},s=i=>{e.telemetry?.track(i)};return{connect:i=>(s({type:"connect_started",appId:e.appId}),new Promise((u,d)=>{let p=!1,L=!1,C=null,t=null,f=a=>{p||(p=!0,C&&clearTimeout(C),o(),i.onError?.(a),d(a))},g=a=>{p||(p=!0,C&&clearTimeout(C),i.onError?.(a),d(a))},l=a=>{p||(p=!0,C&&clearTimeout(C),o(),u(a))},v=async a=>{if(!(p||L||!t)){L=!0,a.kind==="connected"&&i.onConnected?.(a),a.kind==="ready"&&i.onReady?.(a),s({type:"code_received",appId:e.appId,sessionId:t.sessionId,state:t.state,details:{kind:a.kind}}),s({type:"link_complete_started",appId:e.appId,sessionId:t.sessionId,state:t.state});try{let y=await i.completeLink({sessionId:t.sessionId,state:t.state,nonce:t.nonce,code:a.code});s({type:"link_complete_succeeded",appId:e.appId,sessionId:t.sessionId,state:t.state}),l(S1(y))}catch(y){s({type:"link_complete_failed",appId:e.appId,sessionId:t.sessionId,state:t.state}),g(new x("LINK_COMPLETE_FAILED","Facto link completion failed",{retryable:!0,details:y}))}}};(async()=>{try{s({type:"link_session_requested",appId:e.appId}),t=M1(await i.fetchLinkSession()),s({type:"link_session_received",appId:e.appId,sessionId:t.sessionId,state:t.state})}catch(a){f(new x("INVALID_LINK_SESSION","Unable to create Facto link session",{retryable:!0,details:a}));return}if(new Date(t.expiresAt).getTime()<=Date.now()){f(new x("LINK_SESSION_EXPIRED","Facto link session expired",{retryable:!0,details:{expiresAt:t.expiresAt}}));return}C=setTimeout(()=>{i.onExit?.({reason:"timeout",state:t?.state}),s({type:"connect_timeout",appId:e.appId,sessionId:t?.sessionId,state:t?.state}),f(new x("TIMEOUT","Facto Connect timed out",{retryable:!0}))},e.timeoutMs??3e5),n=j({connectUrl:t.connectUrl,state:t.state,windowName:e.popupName,windowFeatures:e.popupFeatures,onReady:a=>{v(a)},onConnected:a=>{v(a)},onFailed:a=>{if(a.reason==="popup_blocked"){s({type:"popup_blocked",appId:e.appId,state:a.state}),f(new x("POPUP_BLOCKED","Facto Connect popup was blocked",{retryable:!0}));return}f(new x("CONNECT_APP_FAILED","Facto Connect failed",{retryable:!0,details:a}))},onClose:()=>{p||(i.onExit?.({reason:"user_exit",state:t?.state}),s({type:"journey_exit",appId:e.appId,sessionId:t?.sessionId,state:t?.state}),f(new x("USER_EXIT","Facto Connect was closed before completion",{retryable:!0})))}}),n.open(),s({type:"popup_opened",appId:e.appId,sessionId:t.sessionId,state:t.state})})()})),close:o}}function M1(e){let n=e.connectUrl??e.iframeUrl;if(!n||typeof n!="string")throw new Error("Facto link session is missing connectUrl");if(!e.state||typeof e.state!="string")throw new Error("Facto link session is missing state");if(!e.expiresAt||Number.isNaN(new Date(e.expiresAt).getTime()))throw new Error("Facto link session is missing a valid expiresAt");return{...e,connectUrl:n}}function _1(e){return"connectUrl"in e&&"state"in e}function W(e){return _1(e)?j(e):I1(e)}var H1={create:W},U1=W;export{$ as FACTO_LINK_CLOSE_REQUESTED,D as FACTO_LINK_CONNECTED,V as FACTO_LINK_FAILED,z as FACTO_LINK_READY,H1 as FactoConnect,x as FactoConnectError,W as createFactoConnect,j as createFactoConnectTransport,p1 as createFactoExpressCheckout,U1 as default};