@xyo-network/xl1-react-client-sdk 5.0.12 → 5.0.14
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 +5 -1
- package/dist/browser/client/context/in-page/Provider.d.ts +14 -12
- package/dist/browser/client/context/in-page/Provider.d.ts.map +1 -1
- package/dist/browser/client/context/in-page/lib/index.d.ts +1 -0
- package/dist/browser/client/context/in-page/lib/index.d.ts.map +1 -1
- package/dist/browser/client/context/in-page/lib/launchInPageGatewaySystem.d.ts +10 -0
- package/dist/browser/client/context/in-page/lib/launchInPageGatewaySystem.d.ts.map +1 -0
- package/dist/browser/client/index.mjs +75 -3
- package/dist/browser/client/index.mjs.map +4 -4
- package/dist/browser/index.mjs +75 -3
- package/dist/browser/index.mjs.map +4 -4
- package/package.json +13 -5
package/README.md
CHANGED
|
@@ -72,7 +72,11 @@ export const App = () => (
|
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
For read-only dApps that should work before wallet connection, mount
|
|
75
|
-
`InPageGatewaysProvider` and `GatewayProvider` around the app shell.
|
|
75
|
+
`InPageGatewaysProvider` and `GatewayProvider` around the app shell. With
|
|
76
|
+
`transport="rest"`, the in-page provider launches one page-owned
|
|
77
|
+
`@xyo-network/xl1-browser-system` session per network and stops those sessions
|
|
78
|
+
on React cleanup or `pagehide`; wallet gateways still take precedence when
|
|
79
|
+
connected.
|
|
76
80
|
|
|
77
81
|
## Documentation
|
|
78
82
|
|
|
@@ -2,7 +2,7 @@ import type { AccountInstance } from '@xyo-network/sdk';
|
|
|
2
2
|
import type { CreatableProviderFactory, RpcTransport, XyoSignerRpcSchemas } from '@xyo-network/xl1-sdk';
|
|
3
3
|
import type { PropsWithChildren } from 'react';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import type
|
|
5
|
+
import { type GatewayTransport } from './lib/index.ts';
|
|
6
6
|
/** Props accepted by the In Page Gateways Provider component. */
|
|
7
7
|
export interface InPageGatewaysProviderProps extends PropsWithChildren {
|
|
8
8
|
/** Static REST/S3 root used for the local network; defaults to the Aries local-chain endpoint. */
|
|
@@ -30,25 +30,27 @@ export interface InPageGatewaysProviderProps extends PropsWithChildren {
|
|
|
30
30
|
* once, while many `GatewayProvider` instances deeper in the tree each
|
|
31
31
|
* expose whichever gateway their subtree cares about.
|
|
32
32
|
*
|
|
33
|
-
* Unlike `WalletGatewayProvider`, gateways here are
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
33
|
+
* Unlike `WalletGatewayProvider`, gateways here are owned by the page — no
|
|
34
|
+
* browser wallet extension is required. Read-only REST gateways launch one
|
|
35
|
+
* config-resolved XL1 browser system per network. RPC gateways and REST
|
|
36
|
+
* gateways with an in-page signing capability retain the direct
|
|
37
|
+
* `buildGateway` compatibility path.
|
|
38
38
|
*
|
|
39
39
|
* `transport` selects how each gateway reads chain data: `'rpc'` (the
|
|
40
40
|
* default viewer/runner locator, reads over RPC) or `'rest'` (the
|
|
41
|
-
* REST/S3-backed implementation, reads from the static CDN layout).
|
|
42
|
-
* forwarded to `buildGateway`.
|
|
41
|
+
* REST/S3-backed implementation, reads from the static CDN layout).
|
|
43
42
|
*
|
|
44
43
|
* Behavior:
|
|
45
|
-
* - On mount, and whenever
|
|
46
|
-
*
|
|
44
|
+
* - On mount, and whenever a launch dependency changes, every network in
|
|
45
|
+
* `DefaultNetworks` is launched in parallel via
|
|
47
46
|
* `Promise.allSettled`. Networks that resolve populate `gateways[id]`;
|
|
48
47
|
* networks that reject populate `errors[id]`. One failed network does
|
|
49
48
|
* not block the others.
|
|
50
|
-
* -
|
|
51
|
-
*
|
|
49
|
+
* - Read-only REST gateways are resolved once through browser-kit and share
|
|
50
|
+
* one immutable provider graph with their XL1 system actor. The page owns
|
|
51
|
+
* each session until React cleanup or `pagehide`.
|
|
52
|
+
* - If a signing capability is provided, gateways are built through the
|
|
53
|
+
* existing *runner* compatibility path.
|
|
52
54
|
* - When `signerTransport` changes identity mid-life, the provider clears
|
|
53
55
|
* all cached gateways and errors synchronously during render (via
|
|
54
56
|
* `previousSignerTransport` state) so consumers never see gateways
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../../src/client/context/in-page/Provider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../../src/client/context/in-page/Provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EACV,wBAAwB,EACX,YAAY,EAAE,mBAAmB,EAC/C,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,KAGN,MAAM,OAAO,CAAA;AAKd,OAAO,EAEL,KAAK,gBAAgB,EAGtB,MAAM,gBAAgB,CAAA;AAKvB,iEAAiE;AACjE,MAAM,WAAW,2BAA4B,SAAQ,iBAAiB;IAEpE,kGAAkG;IAClG,aAAa,CAAC,EAAE,MAAM,CAAA;IAEtB,4FAA4F;IAC5F,aAAa,CAAC,EAAE,eAAe,CAAA;IAE/B,mEAAmE;IACnE,aAAa,CAAC,EAAE,wBAAwB,CAAA;IAExC,4DAA4D;IAC5D,eAAe,CAAC,EAAE,YAAY,CAAC,mBAAmB,CAAC,CAAA;IAEnD,qFAAqF;IACrF,SAAS,CAAC,EAAE,gBAAgB,CAAA;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAqGxE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/client/context/in-page/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/client/context/in-page/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,gCAAgC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GatewayName } from '@xyo-network/xl1-sdk';
|
|
2
|
+
import type { ContextGatewayType } from '../../../types/index.ts';
|
|
3
|
+
/** Page-owned browser-system session exposing the gateway expected by the React context. */
|
|
4
|
+
export interface InPageGatewaySystem {
|
|
5
|
+
readonly gateway: ContextGatewayType;
|
|
6
|
+
stop(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/** Launches one read-only REST browser system for a configured XL1 network. */
|
|
9
|
+
export declare function launchInPageGatewaySystem(gatewayName: GatewayName, localEndpoint: string): Promise<InPageGatewaySystem>;
|
|
10
|
+
//# sourceMappingURL=launchInPageGatewaySystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launchInPageGatewaySystem.d.ts","sourceRoot":"","sources":["../../../../../../src/client/context/in-page/lib/launchInPageGatewaySystem.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAMvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAIjE,4FAA4F;AAC5F,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAA;IACpC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,+EAA+E;AAC/E,wBAAsB,yBAAyB,CAC7C,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC,CAkC9B"}
|
|
@@ -2203,8 +2203,56 @@ var buildGateway = async (gatewayName, localEndpoint, signerTransport, signerFac
|
|
|
2203
2203
|
return await getRestGateway({ ...config, name: gatewayName });
|
|
2204
2204
|
};
|
|
2205
2205
|
|
|
2206
|
+
// src/client/context/in-page/lib/launchInPageGatewaySystem.ts
|
|
2207
|
+
import { assertEx as assertEx4 } from "@ariestools/sdk";
|
|
2208
|
+
import {
|
|
2209
|
+
createXl1RestBrowserSystemConfig,
|
|
2210
|
+
launchXl1BrowserSystem,
|
|
2211
|
+
Xl1BrowserSystemActor
|
|
2212
|
+
} from "@xyo-network/xl1-browser-system";
|
|
2213
|
+
import {
|
|
2214
|
+
DefaultNetworks as DefaultNetworks2,
|
|
2215
|
+
LocalNetwork as LocalNetwork3
|
|
2216
|
+
} from "@xyo-network/xl1-sdk";
|
|
2217
|
+
var PAGE_HOST = "page";
|
|
2218
|
+
async function launchInPageGatewaySystem(gatewayName, localEndpoint) {
|
|
2219
|
+
const network = DefaultNetworks2.find((network2) => network2.id === gatewayName);
|
|
2220
|
+
const resolvedNetwork = assertEx4(network, () => `No network found for id ${gatewayName}`);
|
|
2221
|
+
const isLocal = resolvedNetwork.id === LocalNetwork3.id;
|
|
2222
|
+
const endpoint = isLocal ? localEndpoint : `https://${resolvedNetwork.id}.xyo.space`;
|
|
2223
|
+
const config = createXl1RestBrowserSystemConfig({
|
|
2224
|
+
endpoint,
|
|
2225
|
+
host: PAGE_HOST,
|
|
2226
|
+
layout: isLocal ? "path" : "subdomain"
|
|
2227
|
+
});
|
|
2228
|
+
const session = await launchXl1BrowserSystem({
|
|
2229
|
+
config,
|
|
2230
|
+
host: PAGE_HOST
|
|
2231
|
+
});
|
|
2232
|
+
try {
|
|
2233
|
+
const actor = session.actors.find((actor2) => actor2 instanceof Xl1BrowserSystemActor);
|
|
2234
|
+
const resolvedActor = assertEx4(actor, () => `XL1 browser system actor was not created for ${gatewayName}`);
|
|
2235
|
+
const gateway = await resolvedActor.getGateway();
|
|
2236
|
+
return {
|
|
2237
|
+
gateway,
|
|
2238
|
+
stop: async () => await session.stop()
|
|
2239
|
+
};
|
|
2240
|
+
} catch (launchError) {
|
|
2241
|
+
const [stopResult] = await Promise.allSettled([session.stop()]);
|
|
2242
|
+
if (stopResult.status === "rejected") {
|
|
2243
|
+
throw new AggregateError(
|
|
2244
|
+
[launchError, stopResult.reason],
|
|
2245
|
+
`XL1 browser system for ${gatewayName} failed to expose a gateway and stop cleanly`,
|
|
2246
|
+
{ cause: launchError }
|
|
2247
|
+
);
|
|
2248
|
+
}
|
|
2249
|
+
throw launchError;
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2206
2253
|
// src/client/context/in-page/Provider.tsx
|
|
2207
|
-
import {
|
|
2254
|
+
import { bindPageLifecycle } from "@ariestools/browser-kit-page";
|
|
2255
|
+
import { DefaultNetworks as DefaultNetworks3 } from "@xyo-network/xl1-sdk";
|
|
2208
2256
|
import {
|
|
2209
2257
|
startTransition,
|
|
2210
2258
|
useCallback as useCallback6,
|
|
@@ -2235,10 +2283,31 @@ var InPageGatewaysProvider = ({
|
|
|
2235
2283
|
}
|
|
2236
2284
|
useEffect5(() => {
|
|
2237
2285
|
let cancelled = false;
|
|
2286
|
+
const ownedSystems = [];
|
|
2238
2287
|
const buildAll = async () => {
|
|
2239
2288
|
if (cancelled) return;
|
|
2240
2289
|
const results = await Promise.allSettled(
|
|
2241
|
-
|
|
2290
|
+
DefaultNetworks3.map(async (network) => {
|
|
2291
|
+
if (transport === "rest" && signerAccount === void 0 && signerFactory === void 0 && signerTransport === void 0) {
|
|
2292
|
+
const system = await launchInPageGatewaySystem(network.id, localEndpoint);
|
|
2293
|
+
if (cancelled) {
|
|
2294
|
+
await Promise.allSettled([system.stop()]);
|
|
2295
|
+
return { id: network.id, gateway: system.gateway };
|
|
2296
|
+
}
|
|
2297
|
+
const disposePageLifecycle = bindPageLifecycle(system, {
|
|
2298
|
+
onStopError: (error) => {
|
|
2299
|
+
if (cancelled) return;
|
|
2300
|
+
startTransition(() => {
|
|
2301
|
+
setErrors((previous) => ({
|
|
2302
|
+
...previous,
|
|
2303
|
+
[network.id]: error instanceof Error ? error : new Error(String(error))
|
|
2304
|
+
}));
|
|
2305
|
+
});
|
|
2306
|
+
}
|
|
2307
|
+
});
|
|
2308
|
+
ownedSystems.push({ disposePageLifecycle, system });
|
|
2309
|
+
return { id: network.id, gateway: system.gateway };
|
|
2310
|
+
}
|
|
2242
2311
|
const gateway = await buildGateway(network.id, localEndpoint, signerTransport, signerFactory, transport, signerAccount);
|
|
2243
2312
|
return { id: network.id, gateway };
|
|
2244
2313
|
})
|
|
@@ -2247,7 +2316,7 @@ var InPageGatewaysProvider = ({
|
|
|
2247
2316
|
const nextGateways = {};
|
|
2248
2317
|
const nextErrors = {};
|
|
2249
2318
|
for (const [index, result] of results.entries()) {
|
|
2250
|
-
const networkId =
|
|
2319
|
+
const networkId = DefaultNetworks3[index].id;
|
|
2251
2320
|
if (result.status === "fulfilled") {
|
|
2252
2321
|
nextGateways[networkId] = result.value.gateway;
|
|
2253
2322
|
} else {
|
|
@@ -2263,6 +2332,8 @@ var InPageGatewaysProvider = ({
|
|
|
2263
2332
|
void buildAll();
|
|
2264
2333
|
return () => {
|
|
2265
2334
|
cancelled = true;
|
|
2335
|
+
for (const owned of ownedSystems) owned.disposePageLifecycle();
|
|
2336
|
+
void Promise.allSettled(ownedSystems.map(async (owned) => await owned.system.stop()));
|
|
2266
2337
|
};
|
|
2267
2338
|
}, [localEndpoint, signerAccount, signerFactory, signerTransport, transport]);
|
|
2268
2339
|
const value = useMemo6(() => {
|
|
@@ -2410,6 +2481,7 @@ export {
|
|
|
2410
2481
|
buildGateway,
|
|
2411
2482
|
findCaveat,
|
|
2412
2483
|
getXyoClient,
|
|
2484
|
+
launchInPageGatewaySystem,
|
|
2413
2485
|
listenForClientInjection,
|
|
2414
2486
|
useAccountPermissions,
|
|
2415
2487
|
useClient,
|