@parity/product-sdk-signer 0.8.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +37 -66
- package/dist/index.js +38 -42
- package/dist/index.js.map +1 -1
- package/package.json +3 -7
- package/src/errors.ts +2 -1
- package/src/providers/host.ts +198 -365
- package/src/signer-manager.ts +30 -1
- package/src/types.ts +10 -8
package/src/signer-manager.ts
CHANGED
|
@@ -671,7 +671,14 @@ export class SignerManager {
|
|
|
671
671
|
|
|
672
672
|
const ctx: ConnectContext = {
|
|
673
673
|
signal: controller.signal,
|
|
674
|
-
requestResourceAllocation
|
|
674
|
+
// Bridge host's `Result`-returning `requestResourceAllocation` back to
|
|
675
|
+
// the `ConnectContext` contract (`Promise<AllocationOutcome[]>`, throws
|
|
676
|
+
// on failure) by unwrapping the typed error on the `err` channel.
|
|
677
|
+
requestResourceAllocation: async (resources) => {
|
|
678
|
+
const result = await requestResourceAllocation(resources);
|
|
679
|
+
if (!result.ok) throw result.error;
|
|
680
|
+
return result.value;
|
|
681
|
+
},
|
|
675
682
|
};
|
|
676
683
|
|
|
677
684
|
// Defer so connect()/attemptReconnect() return before the callback fires —
|
|
@@ -890,6 +897,28 @@ if (import.meta.vitest) {
|
|
|
890
897
|
manager.destroy();
|
|
891
898
|
});
|
|
892
899
|
|
|
900
|
+
test("ctx.requestResourceAllocation unwraps host errors by throwing", async () => {
|
|
901
|
+
// The ctx helper adapts host's `Result`-returning
|
|
902
|
+
// `requestResourceAllocation` to the throwing `ConnectContext`
|
|
903
|
+
// contract. Outside a container the host call returns `err`, so the
|
|
904
|
+
// adapter must throw (not return a `Result` object).
|
|
905
|
+
let captured: ConnectContext | undefined;
|
|
906
|
+
const onConnect = vi.fn().mockImplementation((_account, ctx: ConnectContext) => {
|
|
907
|
+
captured = ctx;
|
|
908
|
+
});
|
|
909
|
+
const manager = new SignerManager({
|
|
910
|
+
createProvider: () => mockProvider(),
|
|
911
|
+
onConnect,
|
|
912
|
+
});
|
|
913
|
+
await manager.connect("dev");
|
|
914
|
+
await flush();
|
|
915
|
+
expect(captured).toBeDefined();
|
|
916
|
+
await expect(
|
|
917
|
+
captured?.requestResourceAllocation([{ tag: "AutoSigning", value: undefined }]),
|
|
918
|
+
).rejects.toThrow();
|
|
919
|
+
manager.destroy();
|
|
920
|
+
});
|
|
921
|
+
|
|
893
922
|
test("re-connecting cancels in-flight onConnect from the prior session", async () => {
|
|
894
923
|
const signals: AbortSignal[] = [];
|
|
895
924
|
const onConnect = vi.fn().mockImplementation((_, ctx) => {
|
package/src/types.ts
CHANGED
|
@@ -119,10 +119,11 @@ export interface SignerManagerOptions {
|
|
|
119
119
|
* plus an `AbortSignal` that fires if the user disconnects or
|
|
120
120
|
* destroys the manager mid-flight.
|
|
121
121
|
*
|
|
122
|
-
* `requestResourceAllocation` throws on failure (
|
|
123
|
-
* `@parity/product-sdk-host` export of the same name
|
|
124
|
-
*
|
|
125
|
-
* the
|
|
122
|
+
* `requestResourceAllocation` throws on failure (it adapts the
|
|
123
|
+
* `Result`-returning `@parity/product-sdk-host` export of the same name,
|
|
124
|
+
* re-throwing the typed error on the `err` channel); errors thrown from
|
|
125
|
+
* `onConnect` are logged but do not affect the connected state — the next
|
|
126
|
+
* reconnect retries.
|
|
126
127
|
*
|
|
127
128
|
* @example
|
|
128
129
|
* ```ts
|
|
@@ -133,7 +134,7 @@ export interface SignerManagerOptions {
|
|
|
133
134
|
* { tag: "AutoSigning", value: undefined },
|
|
134
135
|
* ]);
|
|
135
136
|
* if (signal.aborted) return;
|
|
136
|
-
* if (outcomes.some((o) => o
|
|
137
|
+
* if (outcomes.some((o) => o !== "Allocated")) {
|
|
137
138
|
* logWarning("partial permissions", outcomes);
|
|
138
139
|
* }
|
|
139
140
|
* } catch (cause) {
|
|
@@ -155,9 +156,10 @@ export interface ConnectContext {
|
|
|
155
156
|
*/
|
|
156
157
|
signal: AbortSignal;
|
|
157
158
|
/**
|
|
158
|
-
* Request a batch of host resource allocations.
|
|
159
|
-
* `requestResourceAllocation` from `@parity/product-sdk-host`
|
|
160
|
-
*
|
|
159
|
+
* Request a batch of host resource allocations. Adapts
|
|
160
|
+
* `requestResourceAllocation` from `@parity/product-sdk-host` (which returns
|
|
161
|
+
* a `Result`) to this throwing contract — returns the unwrapped outcomes on
|
|
162
|
+
* success, throws the typed host error on failure.
|
|
161
163
|
*/
|
|
162
164
|
requestResourceAllocation: (resources: AllocatableResource[]) => Promise<AllocationOutcome[]>;
|
|
163
165
|
}
|