@compose-market/sdk 0.8.0 → 0.8.2
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/.speakeasy/a2a.arazzo.yaml +1 -1
- package/.speakeasy/memory.arazzo.yaml +1 -1
- package/.speakeasy/tests.arazzo.yaml +1 -1
- package/generated/inference/esm/lib/config.d.ts +3 -3
- package/generated/inference/esm/lib/config.js +3 -3
- package/generated/inference/package.json +1 -1
- package/generated/inference/src/lib/config.ts +3 -3
- package/generated/manowar/esm/lib/config.d.ts +3 -3
- package/generated/manowar/esm/lib/config.js +3 -3
- package/generated/manowar/package.json +1 -1
- package/generated/manowar/src/lib/config.ts +3 -3
- package/generated/memory/esm/lib/config.d.ts +3 -3
- package/generated/memory/esm/lib/config.js +3 -3
- package/generated/memory/package.json +1 -1
- package/generated/memory/src/lib/config.ts +3 -3
- package/generated/x402/esm/lib/config.d.ts +3 -3
- package/generated/x402/esm/lib/config.js +3 -3
- package/generated/x402/package.json +1 -1
- package/generated/x402/src/lib/config.ts +3 -3
- package/package.json +4 -4
- package/specs/inference.openapi.yaml +1 -1
- package/specs/manowar.openapi.yaml +1 -1
- package/specs/memory.openapi.yaml +1 -1
- package/specs/x402.openapi.yaml +1 -1
- package/dist/errors.d.ts +0 -2
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -2
- package/dist/errors.js.map +0 -1
- package/dist/events.d.ts +0 -202
- package/dist/events.d.ts.map +0 -1
- package/dist/events.js +0 -70
- package/dist/events.js.map +0 -1
- package/dist/index.d.ts +0 -277
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -551
- package/dist/index.js.map +0 -1
- package/dist/resources/accounts.d.ts +0 -32
- package/dist/resources/accounts.d.ts.map +0 -1
- package/dist/resources/accounts.js +0 -128
- package/dist/resources/accounts.js.map +0 -1
- package/dist/resources/agent.d.ts +0 -58
- package/dist/resources/agent.d.ts.map +0 -1
- package/dist/resources/agent.js +0 -770
- package/dist/resources/agent.js.map +0 -1
- package/dist/resources/channels.d.ts +0 -24
- package/dist/resources/channels.d.ts.map +0 -1
- package/dist/resources/channels.js +0 -74
- package/dist/resources/channels.js.map +0 -1
- package/dist/resources/directory.d.ts +0 -43
- package/dist/resources/directory.d.ts.map +0 -1
- package/dist/resources/directory.js +0 -97
- package/dist/resources/directory.js.map +0 -1
- package/dist/resources/dispenser.d.ts +0 -25
- package/dist/resources/dispenser.d.ts.map +0 -1
- package/dist/resources/dispenser.js +0 -56
- package/dist/resources/dispenser.js.map +0 -1
- package/dist/resources/feedback.d.ts +0 -35
- package/dist/resources/feedback.d.ts.map +0 -1
- package/dist/resources/feedback.js +0 -127
- package/dist/resources/feedback.js.map +0 -1
- package/dist/resources/inference.d.ts +0 -206
- package/dist/resources/inference.d.ts.map +0 -1
- package/dist/resources/inference.js +0 -1046
- package/dist/resources/inference.js.map +0 -1
- package/dist/resources/instrumentation.d.ts +0 -29
- package/dist/resources/instrumentation.d.ts.map +0 -1
- package/dist/resources/instrumentation.js +0 -43
- package/dist/resources/instrumentation.js.map +0 -1
- package/dist/resources/keys.d.ts +0 -56
- package/dist/resources/keys.d.ts.map +0 -1
- package/dist/resources/keys.js +0 -186
- package/dist/resources/keys.js.map +0 -1
- package/dist/resources/local.d.ts +0 -56
- package/dist/resources/local.d.ts.map +0 -1
- package/dist/resources/local.js +0 -163
- package/dist/resources/local.js.map +0 -1
- package/dist/resources/memory.d.ts +0 -249
- package/dist/resources/memory.d.ts.map +0 -1
- package/dist/resources/memory.js +0 -217
- package/dist/resources/memory.js.map +0 -1
- package/dist/resources/models.d.ts +0 -45
- package/dist/resources/models.d.ts.map +0 -1
- package/dist/resources/models.js +0 -101
- package/dist/resources/models.js.map +0 -1
- package/dist/resources/permissions.d.ts +0 -23
- package/dist/resources/permissions.d.ts.map +0 -1
- package/dist/resources/permissions.js +0 -69
- package/dist/resources/permissions.js.map +0 -1
- package/dist/resources/receipts.d.ts +0 -23
- package/dist/resources/receipts.d.ts.map +0 -1
- package/dist/resources/receipts.js +0 -48
- package/dist/resources/receipts.js.map +0 -1
- package/dist/resources/session-events.d.ts +0 -51
- package/dist/resources/session-events.d.ts.map +0 -1
- package/dist/resources/session-events.js +0 -404
- package/dist/resources/session-events.js.map +0 -1
- package/dist/resources/settlement.d.ts +0 -21
- package/dist/resources/settlement.d.ts.map +0 -1
- package/dist/resources/settlement.js +0 -30
- package/dist/resources/settlement.js.map +0 -1
- package/dist/resources/system.d.ts +0 -9
- package/dist/resources/system.d.ts.map +0 -1
- package/dist/resources/system.js +0 -19
- package/dist/resources/system.js.map +0 -1
- package/dist/resources/webhooks.d.ts +0 -27
- package/dist/resources/webhooks.d.ts.map +0 -1
- package/dist/resources/webhooks.js +0 -78
- package/dist/resources/webhooks.js.map +0 -1
- package/dist/resources/workflow.d.ts +0 -49
- package/dist/resources/workflow.d.ts.map +0 -1
- package/dist/resources/workflow.js +0 -361
- package/dist/resources/workflow.js.map +0 -1
- package/dist/resources/x402.d.ts +0 -113
- package/dist/resources/x402.d.ts.map +0 -1
- package/dist/resources/x402.js +0 -231
- package/dist/resources/x402.js.map +0 -1
- package/dist/tools/index.d.ts +0 -55
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -51
- package/dist/tools/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -1857
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -14
- package/dist/types/index.js.map +0 -1
- package/dist/version.d.ts +0 -9
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js +0 -9
- package/dist/version.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/resources/models.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO,uBAAuB;IACH;IAA7B,YAA6B,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAEnD;;;OAGG;IACH,IAAI;QACA,OAAO,IAAI,CAAC,MAAM,CAAC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AI,EAAE,gBAAgB;SACzB,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,QAA0B,EAAE;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAsB;YAC5C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,mBAAmB;YACzB,IAAI,EAAE,KAAK;SACd,CAAC,CAAC;IACP,CAAC;IAED,GAAG,CAAC,OAAe;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAQ;YAC9B,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,cAAc,kBAAkB,CAAC,OAAO,CAAC,EAAE;SACpD,CAAC,CAAC;IACP,CAAC;IAED,SAAS,CAAC,OAAe;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAsB;YAC5C,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,cAAc,kBAAkB,CAAC,OAAO,CAAC,SAAS;SAC3D,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACH,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAkB;YACxC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,cAAc;SACvB,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { APIPromise, HttpClient } from "@compose-market/core/http";
|
|
2
|
-
import type { PermissionGrantInput, PermissionListInput, PermissionListResponse, PermissionRevokeInput, PermissionWriteResponse } from "../types/index.js";
|
|
3
|
-
interface Context {
|
|
4
|
-
getWalletMaybe(): {
|
|
5
|
-
address: string | null;
|
|
6
|
-
chainId: number | null;
|
|
7
|
-
};
|
|
8
|
-
getTokenMaybe(): string | null;
|
|
9
|
-
}
|
|
10
|
-
interface Options {
|
|
11
|
-
signal?: AbortSignal;
|
|
12
|
-
timeoutMs?: number;
|
|
13
|
-
}
|
|
14
|
-
export declare class PermissionsResource {
|
|
15
|
-
private readonly client;
|
|
16
|
-
private readonly ctx;
|
|
17
|
-
constructor(client: HttpClient, ctx: Context);
|
|
18
|
-
list(input: PermissionListInput, options?: Options): APIPromise<PermissionListResponse>;
|
|
19
|
-
grant(input: PermissionGrantInput, options?: Options): APIPromise<PermissionWriteResponse>;
|
|
20
|
-
revoke(input: PermissionRevokeInput, options?: Options): APIPromise<PermissionWriteResponse>;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../src/resources/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAExE,OAAO,KAAK,EACR,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EAC1B,MAAM,mBAAmB,CAAC;AAE3B,UAAU,OAAO;IACb,cAAc,IAAI;QAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACrE,aAAa,IAAI,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,UAAU,OAAO;IACb,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AA0BD,qBAAa,mBAAmB;IAExB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBADH,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,OAAO;IAGjC,IAAI,CAAC,KAAK,EAAE,mBAAmB,EAAE,OAAO,GAAE,OAAY,GAAG,UAAU,CAAC,sBAAsB,CAAC;IAa3F,KAAK,CAAC,KAAK,EAAE,oBAAoB,EAAE,OAAO,GAAE,OAAY,GAAG,UAAU,CAAC,uBAAuB,CAAC;IAc9F,MAAM,CAAC,KAAK,EAAE,qBAAqB,EAAE,OAAO,GAAE,OAAY,GAAG,UAAU,CAAC,uBAAuB,CAAC;CAanG"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { BadRequestError } from "../errors.js";
|
|
2
|
-
function user(input, fallback) {
|
|
3
|
-
const resolved = input.userAddress ?? fallback;
|
|
4
|
-
if (!resolved) {
|
|
5
|
-
throw new BadRequestError({ message: "userAddress is required. Attach a wallet or pass userAddress." });
|
|
6
|
-
}
|
|
7
|
-
return resolved;
|
|
8
|
-
}
|
|
9
|
-
function agent(input) {
|
|
10
|
-
if (!input.agentWallet) {
|
|
11
|
-
throw new BadRequestError({ message: "agentWallet is required." });
|
|
12
|
-
}
|
|
13
|
-
return input.agentWallet;
|
|
14
|
-
}
|
|
15
|
-
function headers(ctx, userAddress) {
|
|
16
|
-
const wallet = ctx.getWalletMaybe();
|
|
17
|
-
return {
|
|
18
|
-
key: ctx.getTokenMaybe() ?? undefined,
|
|
19
|
-
userAddress,
|
|
20
|
-
chainId: wallet.chainId ?? undefined,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export class PermissionsResource {
|
|
24
|
-
client;
|
|
25
|
-
ctx;
|
|
26
|
-
constructor(client, ctx) {
|
|
27
|
-
this.client = client;
|
|
28
|
-
this.ctx = ctx;
|
|
29
|
-
}
|
|
30
|
-
list(input, options = {}) {
|
|
31
|
-
const userAddress = user(input, this.ctx.getWalletMaybe().address);
|
|
32
|
-
const agentWallet = agent(input);
|
|
33
|
-
return this.client.request({
|
|
34
|
-
method: "GET",
|
|
35
|
-
path: "/permissions",
|
|
36
|
-
query: { userAddress, agentWallet },
|
|
37
|
-
headers: headers(this.ctx, userAddress),
|
|
38
|
-
signal: options.signal,
|
|
39
|
-
timeoutMs: options.timeoutMs,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
grant(input, options = {}) {
|
|
43
|
-
const userAddress = user(input, this.ctx.getWalletMaybe().address);
|
|
44
|
-
const agentWallet = agent(input);
|
|
45
|
-
return this.client.request({
|
|
46
|
-
method: "POST",
|
|
47
|
-
path: "/permissions",
|
|
48
|
-
body: { ...input, userAddress, agentWallet },
|
|
49
|
-
headers: headers(this.ctx, userAddress),
|
|
50
|
-
signal: options.signal,
|
|
51
|
-
timeoutMs: options.timeoutMs,
|
|
52
|
-
doNotRetry: true,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
revoke(input, options = {}) {
|
|
56
|
-
const userAddress = user(input, this.ctx.getWalletMaybe().address);
|
|
57
|
-
const agentWallet = agent(input);
|
|
58
|
-
return this.client.request({
|
|
59
|
-
method: "DELETE",
|
|
60
|
-
path: "/permissions",
|
|
61
|
-
body: { ...input, userAddress, agentWallet },
|
|
62
|
-
headers: headers(this.ctx, userAddress),
|
|
63
|
-
signal: options.signal,
|
|
64
|
-
timeoutMs: options.timeoutMs,
|
|
65
|
-
doNotRetry: true,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=permissions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../src/resources/permissions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAmB/C,SAAS,IAAI,CAAC,KAA+B,EAAE,QAAuB;IAClE,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,IAAI,QAAQ,CAAC;IAC/C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,MAAM,IAAI,eAAe,CAAC,EAAE,OAAO,EAAE,+DAA+D,EAAE,CAAC,CAAC;IAC5G,CAAC;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,SAAS,KAAK,CAAC,KAA+B;IAC1C,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QACrB,MAAM,IAAI,eAAe,CAAC,EAAE,OAAO,EAAE,0BAA0B,EAAE,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,KAAK,CAAC,WAAW,CAA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AAI,EAAE,EAAE,GAAG,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE;YAC5C,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC;YACvC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,UAAU,EAAE,IAAI;SACnB,CAAC,CAAC;IACP,CAAC;IAED,MAAM,CAAC,KAA4B,EAAE,UAAmB,EAAE;QACtD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,CAAC;QACnE,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAA0B;YAChD,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,cAAc;YACpB,IAAI,EAAE,EAAE,GAAG,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE;YAC5C,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC;YACvC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,UAAU,EAAE,IAAI;SACnB,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { APIPromise, HttpClient } from "@compose-market/core/http";
|
|
2
|
-
import type { ReceiptListResponse } from "../types/index.js";
|
|
3
|
-
interface ReceiptsContext {
|
|
4
|
-
getWalletMaybe(): {
|
|
5
|
-
address: string | null;
|
|
6
|
-
chainId: number | null;
|
|
7
|
-
};
|
|
8
|
-
getTokenMaybe(): string | null;
|
|
9
|
-
}
|
|
10
|
-
export interface ReceiptListOptions {
|
|
11
|
-
chainId?: number;
|
|
12
|
-
limit?: number;
|
|
13
|
-
signal?: AbortSignal;
|
|
14
|
-
timeoutMs?: number;
|
|
15
|
-
}
|
|
16
|
-
export declare class ReceiptsResource {
|
|
17
|
-
private readonly client;
|
|
18
|
-
private readonly ctx;
|
|
19
|
-
constructor(client: HttpClient, ctx: ReceiptsContext);
|
|
20
|
-
list(input?: ReceiptListOptions): APIPromise<ReceiptListResponse>;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=receipts.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"receipts.d.ts","sourceRoot":"","sources":["../../src/resources/receipts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAExE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,UAAU,eAAe;IACrB,cAAc,IAAI;QAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACrE,aAAa,IAAI,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,kBAAkB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAUD,qBAAa,gBAAgB;IAErB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBADH,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,eAAe;IAGzC,IAAI,CAAC,KAAK,GAAE,kBAAuB,GAAG,UAAU,CAAC,mBAAmB,CAAC;CAgCxE"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { BadRequestError } from "../errors.js";
|
|
2
|
-
function normalizeLimit(value) {
|
|
3
|
-
if (value === undefined)
|
|
4
|
-
return undefined;
|
|
5
|
-
if (!Number.isInteger(value) || value <= 0) {
|
|
6
|
-
throw new BadRequestError({ message: "limit must be a positive integer" });
|
|
7
|
-
}
|
|
8
|
-
return Math.min(value, 100);
|
|
9
|
-
}
|
|
10
|
-
export class ReceiptsResource {
|
|
11
|
-
client;
|
|
12
|
-
ctx;
|
|
13
|
-
constructor(client, ctx) {
|
|
14
|
-
this.client = client;
|
|
15
|
-
this.ctx = ctx;
|
|
16
|
-
}
|
|
17
|
-
list(input = {}) {
|
|
18
|
-
const token = this.ctx.getTokenMaybe();
|
|
19
|
-
if (!token) {
|
|
20
|
-
throw new BadRequestError({
|
|
21
|
-
message: "receipts.list() requires a Compose Key token. Call keys.use(token), keys.create(...), or pass key via options.",
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
const wallet = this.ctx.getWalletMaybe();
|
|
25
|
-
const chainId = input.chainId ?? wallet.chainId;
|
|
26
|
-
if (!chainId) {
|
|
27
|
-
throw new BadRequestError({
|
|
28
|
-
message: "receipts.list() needs a chainId, either in options or via sdk.wallets.attach(...).",
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return this.client.request({
|
|
32
|
-
method: "GET",
|
|
33
|
-
path: "/api/receipts",
|
|
34
|
-
query: {
|
|
35
|
-
chainId,
|
|
36
|
-
limit: normalizeLimit(input.limit),
|
|
37
|
-
},
|
|
38
|
-
headers: {
|
|
39
|
-
key: token,
|
|
40
|
-
userAddress: wallet.address ?? undefined,
|
|
41
|
-
chainId,
|
|
42
|
-
},
|
|
43
|
-
signal: input.signal,
|
|
44
|
-
timeoutMs: input.timeoutMs,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=receipts.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"receipts.js","sourceRoot":"","sources":["../../src/resources/receipts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAe/C,SAAS,cAAc,CAAC,KAAyB;IAC7C,IAAI,KAAK,KAAK,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,MAAM;YACpB,SAAS,EAAE,KAAK,CAAC,SAAS;SAC7B,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session-events SSE resource.
|
|
3
|
-
*
|
|
4
|
-
* Subscribes to `/api/session/events?userAddress=<address>&chainId=<chainId>`
|
|
5
|
-
* and yields typed `session-active` / `session-expired` events as they arrive.
|
|
6
|
-
*
|
|
7
|
-
* Each event is additionally dispatched to the SDK event bus so application
|
|
8
|
-
* code can centralise listeners on `sdk.events.on("sessionActive", ...)` and
|
|
9
|
-
* `sdk.events.on("sessionExpired", ...)` without plumbing the iterator
|
|
10
|
-
* manually.
|
|
11
|
-
*
|
|
12
|
-
* The iterator auto-reconnects transparently on network errors using the
|
|
13
|
-
* retry policy configured on the HTTP client; callers cancel via the
|
|
14
|
-
* provided `AbortSignal`.
|
|
15
|
-
*/
|
|
16
|
-
import type { EventBus } from "../events.js";
|
|
17
|
-
import type { HttpClient } from "@compose-market/core/http";
|
|
18
|
-
import type { SessionEvent } from "../types/index.js";
|
|
19
|
-
export interface SessionEventsOptions {
|
|
20
|
-
userAddress: string;
|
|
21
|
-
chainId: number;
|
|
22
|
-
signal?: AbortSignal;
|
|
23
|
-
/** Max delay between reconnect attempts, in milliseconds. Default 10_000. */
|
|
24
|
-
reconnectMaxDelayMs?: number;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Drive a raw SSE subscription to `/api/session/events` and yield one event
|
|
28
|
-
* at a time. The generator terminates only when the caller aborts the signal
|
|
29
|
-
* or when a terminal `session-expired` event is emitted for the requested
|
|
30
|
-
* `(userAddress, chainId)` tuple (a terminal signal from the server side).
|
|
31
|
-
*/
|
|
32
|
-
export declare class SessionEventsResource {
|
|
33
|
-
private readonly client;
|
|
34
|
-
private readonly events;
|
|
35
|
-
private readonly hubs;
|
|
36
|
-
constructor(client: HttpClient, events: EventBus);
|
|
37
|
-
subscribe(opts: SessionEventsOptions): AsyncIterable<SessionEvent>;
|
|
38
|
-
private createIterator;
|
|
39
|
-
private key;
|
|
40
|
-
private start;
|
|
41
|
-
private run;
|
|
42
|
-
private publish;
|
|
43
|
-
private close;
|
|
44
|
-
private fail;
|
|
45
|
-
private drop;
|
|
46
|
-
private finish;
|
|
47
|
-
private next;
|
|
48
|
-
private stream;
|
|
49
|
-
private consumeStream;
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=session-events.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-events.d.ts","sourceRoot":"","sources":["../../src/resources/session-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAGR,YAAY,EAGf,MAAM,mBAAmB,CAAC;AAI3B,MAAM,WAAW,oBAAoB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,6EAA6E;IAC7E,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAChC;AA0BD;;;;;GAKG;AACH,qBAAa,qBAAqB;IAI1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJ3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA0B;gBAG1B,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,QAAQ;IAGrC,SAAS,CAAC,IAAI,EAAE,oBAAoB,GAAG,aAAa,CAAC,YAAY,CAAC;IASlE,OAAO,CAAC,cAAc;IA+CtB,OAAO,CAAC,GAAG;IAIX,OAAO,CAAC,KAAK;YAeC,GAAG;IAmBjB,OAAO,CAAC,OAAO;IAaf,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,IAAI;IAeZ,OAAO,CAAC,IAAI;IAUZ,OAAO,CAAC,MAAM;YAYA,IAAI;YAgBH,MAAM;YAqEN,aAAa;CAsC/B"}
|
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session-events SSE resource.
|
|
3
|
-
*
|
|
4
|
-
* Subscribes to `/api/session/events?userAddress=<address>&chainId=<chainId>`
|
|
5
|
-
* and yields typed `session-active` / `session-expired` events as they arrive.
|
|
6
|
-
*
|
|
7
|
-
* Each event is additionally dispatched to the SDK event bus so application
|
|
8
|
-
* code can centralise listeners on `sdk.events.on("sessionActive", ...)` and
|
|
9
|
-
* `sdk.events.on("sessionExpired", ...)` without plumbing the iterator
|
|
10
|
-
* manually.
|
|
11
|
-
*
|
|
12
|
-
* The iterator auto-reconnects transparently on network errors using the
|
|
13
|
-
* retry policy configured on the HTTP client; callers cancel via the
|
|
14
|
-
* provided `AbortSignal`.
|
|
15
|
-
*/
|
|
16
|
-
import { Error } from "../errors.js";
|
|
17
|
-
import { parseSSEStream } from "@compose-market/core/transport";
|
|
18
|
-
/**
|
|
19
|
-
* Drive a raw SSE subscription to `/api/session/events` and yield one event
|
|
20
|
-
* at a time. The generator terminates only when the caller aborts the signal
|
|
21
|
-
* or when a terminal `session-expired` event is emitted for the requested
|
|
22
|
-
* `(userAddress, chainId)` tuple (a terminal signal from the server side).
|
|
23
|
-
*/
|
|
24
|
-
export class SessionEventsResource {
|
|
25
|
-
client;
|
|
26
|
-
events;
|
|
27
|
-
hubs = new Map();
|
|
28
|
-
constructor(client, events) {
|
|
29
|
-
this.client = client;
|
|
30
|
-
this.events = events;
|
|
31
|
-
}
|
|
32
|
-
subscribe(opts) {
|
|
33
|
-
const self = this;
|
|
34
|
-
return {
|
|
35
|
-
[Symbol.asyncIterator]() {
|
|
36
|
-
return self.createIterator(opts);
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
createIterator(opts) {
|
|
41
|
-
if (opts.signal?.aborted) {
|
|
42
|
-
return {
|
|
43
|
-
next: async () => ({ done: true, value: undefined }),
|
|
44
|
-
return: async () => ({ done: true, value: undefined }),
|
|
45
|
-
throw: async (err) => { throw err; },
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const key = this.key(opts);
|
|
49
|
-
const hub = this.hubs.get(key) ?? this.start(key, opts);
|
|
50
|
-
const sink = {
|
|
51
|
-
queue: [],
|
|
52
|
-
waiter: null,
|
|
53
|
-
closed: false,
|
|
54
|
-
error: null,
|
|
55
|
-
abort: null,
|
|
56
|
-
};
|
|
57
|
-
const cleanup = () => {
|
|
58
|
-
if (sink.abort) {
|
|
59
|
-
opts.signal?.removeEventListener("abort", sink.abort);
|
|
60
|
-
sink.abort = null;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const drop = () => {
|
|
64
|
-
cleanup();
|
|
65
|
-
this.drop(hub, sink);
|
|
66
|
-
};
|
|
67
|
-
sink.abort = drop;
|
|
68
|
-
opts.signal?.addEventListener("abort", drop, { once: true });
|
|
69
|
-
hub.sinks.add(sink);
|
|
70
|
-
return {
|
|
71
|
-
next: async () => this.next(sink),
|
|
72
|
-
return: async () => {
|
|
73
|
-
drop();
|
|
74
|
-
return { done: true, value: undefined };
|
|
75
|
-
},
|
|
76
|
-
throw: async (err) => {
|
|
77
|
-
drop();
|
|
78
|
-
throw err;
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
key(opts) {
|
|
83
|
-
return `${opts.userAddress.toLowerCase()}:${opts.chainId}`;
|
|
84
|
-
}
|
|
85
|
-
start(key, opts) {
|
|
86
|
-
const hub = {
|
|
87
|
-
key,
|
|
88
|
-
controller: new AbortController(),
|
|
89
|
-
sinks: new Set(),
|
|
90
|
-
};
|
|
91
|
-
this.hubs.set(key, hub);
|
|
92
|
-
queueMicrotask(() => {
|
|
93
|
-
void this.run(hub, opts);
|
|
94
|
-
});
|
|
95
|
-
return hub;
|
|
96
|
-
}
|
|
97
|
-
async run(hub, opts) {
|
|
98
|
-
try {
|
|
99
|
-
for await (const event of this.stream({ ...opts, signal: hub.controller.signal })) {
|
|
100
|
-
this.publish(hub, event);
|
|
101
|
-
}
|
|
102
|
-
this.close(hub);
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
if (hub.controller.signal.aborted) {
|
|
106
|
-
this.close(hub);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
this.fail(hub, err);
|
|
110
|
-
}
|
|
111
|
-
finally {
|
|
112
|
-
if (this.hubs.get(hub.key) === hub) {
|
|
113
|
-
this.hubs.delete(hub.key);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
publish(hub, event) {
|
|
118
|
-
for (const sink of Array.from(hub.sinks)) {
|
|
119
|
-
if (sink.closed)
|
|
120
|
-
continue;
|
|
121
|
-
if (sink.waiter) {
|
|
122
|
-
const waiter = sink.waiter;
|
|
123
|
-
sink.waiter = null;
|
|
124
|
-
waiter.resolve({ done: false, value: event });
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
sink.queue.push(event);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
close(hub) {
|
|
132
|
-
for (const sink of Array.from(hub.sinks)) {
|
|
133
|
-
this.finish(hub, sink);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
fail(hub, err) {
|
|
137
|
-
for (const sink of Array.from(hub.sinks)) {
|
|
138
|
-
sink.error = err;
|
|
139
|
-
if (sink.waiter) {
|
|
140
|
-
const waiter = sink.waiter;
|
|
141
|
-
sink.waiter = null;
|
|
142
|
-
waiter.reject(err);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
hub.sinks.clear();
|
|
146
|
-
if (this.hubs.get(hub.key) === hub) {
|
|
147
|
-
this.hubs.delete(hub.key);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
drop(hub, sink) {
|
|
151
|
-
this.finish(hub, sink);
|
|
152
|
-
if (hub.sinks.size === 0) {
|
|
153
|
-
hub.controller.abort();
|
|
154
|
-
if (this.hubs.get(hub.key) === hub) {
|
|
155
|
-
this.hubs.delete(hub.key);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
finish(hub, sink) {
|
|
160
|
-
if (sink.closed)
|
|
161
|
-
return;
|
|
162
|
-
sink.closed = true;
|
|
163
|
-
sink.queue = [];
|
|
164
|
-
hub.sinks.delete(sink);
|
|
165
|
-
if (sink.waiter) {
|
|
166
|
-
const waiter = sink.waiter;
|
|
167
|
-
sink.waiter = null;
|
|
168
|
-
waiter.resolve({ done: true, value: undefined });
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
async next(sink) {
|
|
172
|
-
if (sink.queue.length > 0) {
|
|
173
|
-
return { done: false, value: sink.queue.shift() };
|
|
174
|
-
}
|
|
175
|
-
if (sink.error) {
|
|
176
|
-
throw sink.error;
|
|
177
|
-
}
|
|
178
|
-
if (sink.closed) {
|
|
179
|
-
return { done: true, value: undefined };
|
|
180
|
-
}
|
|
181
|
-
return new Promise((resolve, reject) => {
|
|
182
|
-
sink.waiter = { resolve, reject };
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
async *stream(opts) {
|
|
186
|
-
const reconnectMaxDelayMs = Math.max(500, opts.reconnectMaxDelayMs ?? 10_000);
|
|
187
|
-
let attempt = 0;
|
|
188
|
-
while (!opts.signal?.aborted) {
|
|
189
|
-
try {
|
|
190
|
-
const request = new AbortController();
|
|
191
|
-
const abortRequest = () => request.abort();
|
|
192
|
-
opts.signal?.addEventListener("abort", abortRequest, { once: true });
|
|
193
|
-
let response;
|
|
194
|
-
try {
|
|
195
|
-
response = await this.client.request({
|
|
196
|
-
method: "GET",
|
|
197
|
-
path: "/api/session/events",
|
|
198
|
-
query: {
|
|
199
|
-
userAddress: opts.userAddress,
|
|
200
|
-
chainId: opts.chainId,
|
|
201
|
-
},
|
|
202
|
-
signal: request.signal,
|
|
203
|
-
expectStream: true,
|
|
204
|
-
doNotRetry: true,
|
|
205
|
-
headers: {
|
|
206
|
-
extra: { Accept: "text/event-stream" },
|
|
207
|
-
},
|
|
208
|
-
}).asResponse();
|
|
209
|
-
}
|
|
210
|
-
finally {
|
|
211
|
-
opts.signal?.removeEventListener("abort", abortRequest);
|
|
212
|
-
}
|
|
213
|
-
if (response.status === 204) {
|
|
214
|
-
await wait(retryDelayFrom(response) ?? reconnectMaxDelayMs, opts.signal);
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
if (!response.body) {
|
|
218
|
-
throw new Error({
|
|
219
|
-
code: "upstream_error",
|
|
220
|
-
message: "session events stream had no body",
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
if (opts.signal?.aborted) {
|
|
224
|
-
try {
|
|
225
|
-
response.body.cancel();
|
|
226
|
-
}
|
|
227
|
-
catch { /* best-effort */ }
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
attempt = 0;
|
|
231
|
-
const result = yield* this.consumeStream(response.body, opts);
|
|
232
|
-
if (result.kind === "terminal" || opts.signal?.aborted) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
if (result.kind === "rotate") {
|
|
236
|
-
await wait(result.retryAfterMs ?? retryDelayFrom(response) ?? reconnectMaxDelayMs, opts.signal);
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
throw new Error({
|
|
240
|
-
code: "upstream_error",
|
|
241
|
-
message: "session events stream closed before session-expired",
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
catch (err) {
|
|
245
|
-
if (opts.signal?.aborted)
|
|
246
|
-
return;
|
|
247
|
-
attempt += 1;
|
|
248
|
-
const delay = Math.min(500 * (2 ** (attempt - 1)), reconnectMaxDelayMs);
|
|
249
|
-
await wait(delay, opts.signal);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
async *consumeStream(body, opts) {
|
|
254
|
-
const parser = parseSSEStream(body, { signal: opts.signal });
|
|
255
|
-
try {
|
|
256
|
-
for await (const frame of parser) {
|
|
257
|
-
const alert = parseAlertFrame(frame);
|
|
258
|
-
if (alert) {
|
|
259
|
-
this.events.emit("alert", alert);
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
const parsed = parseSessionEventFrame(frame);
|
|
263
|
-
if (!parsed)
|
|
264
|
-
continue;
|
|
265
|
-
if (parsed.type === "session-active") {
|
|
266
|
-
this.events.emit("sessionActive", parsed);
|
|
267
|
-
}
|
|
268
|
-
else if (parsed.type === "session-expired") {
|
|
269
|
-
this.events.emit("sessionExpired", parsed);
|
|
270
|
-
}
|
|
271
|
-
yield parsed;
|
|
272
|
-
if (parsed.type === "session-expired") {
|
|
273
|
-
return { kind: "terminal" };
|
|
274
|
-
}
|
|
275
|
-
if (parsed.type === "session-lease") {
|
|
276
|
-
return { kind: "rotate", retryAfterMs: parsed.retryAfterMs };
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
finally {
|
|
281
|
-
try {
|
|
282
|
-
body.cancel();
|
|
283
|
-
}
|
|
284
|
-
catch { /* best-effort */ }
|
|
285
|
-
}
|
|
286
|
-
return { kind: "closed" };
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
function wait(ms, signal) {
|
|
290
|
-
if (signal?.aborted)
|
|
291
|
-
return Promise.resolve();
|
|
292
|
-
return new Promise((resolve) => {
|
|
293
|
-
const finish = () => {
|
|
294
|
-
signal?.removeEventListener("abort", finish);
|
|
295
|
-
clearTimeout(timer);
|
|
296
|
-
resolve();
|
|
297
|
-
};
|
|
298
|
-
const timer = setTimeout(finish, ms);
|
|
299
|
-
signal?.addEventListener("abort", finish, { once: true });
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
function retryDelayFrom(response) {
|
|
303
|
-
const value = response.headers.get("retry-after");
|
|
304
|
-
if (!value)
|
|
305
|
-
return null;
|
|
306
|
-
const seconds = Number.parseInt(value, 10);
|
|
307
|
-
return Number.isFinite(seconds) && seconds > 0 ? seconds * 1000 : null;
|
|
308
|
-
}
|
|
309
|
-
function parseSessionEventFrame(frame) {
|
|
310
|
-
if (frame.event === "session-active") {
|
|
311
|
-
try {
|
|
312
|
-
const data = JSON.parse(frame.data);
|
|
313
|
-
return {
|
|
314
|
-
type: "session-active",
|
|
315
|
-
userAddress: String(data.userAddress ?? ""),
|
|
316
|
-
chainId: Number(data.chainId ?? 0),
|
|
317
|
-
expiresAt: typeof data.expiresAt === "number" ? data.expiresAt : undefined,
|
|
318
|
-
budgetLimit: coerceWeiString(data.budgetLimit),
|
|
319
|
-
budgetUsed: coerceWeiString(data.budgetUsed),
|
|
320
|
-
budgetLocked: coerceWeiString(data.budgetLocked),
|
|
321
|
-
budgetRemaining: coerceWeiString(data.budgetRemaining),
|
|
322
|
-
timestamp: typeof data.timestamp === "number" ? data.timestamp : undefined,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
catch {
|
|
326
|
-
return null;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
if (frame.event === "session-expired") {
|
|
330
|
-
try {
|
|
331
|
-
const data = JSON.parse(frame.data);
|
|
332
|
-
return {
|
|
333
|
-
type: "session-expired",
|
|
334
|
-
userAddress: String(data.userAddress ?? ""),
|
|
335
|
-
chainId: Number(data.chainId ?? 0),
|
|
336
|
-
reason: typeof data.reason === "string" ? data.reason : undefined,
|
|
337
|
-
message: typeof data.message === "string" ? data.message : undefined,
|
|
338
|
-
action: typeof data.action === "string" ? data.action : undefined,
|
|
339
|
-
expiresAt: typeof data.expiresAt === "number" ? data.expiresAt : undefined,
|
|
340
|
-
timestamp: typeof data.timestamp === "number" ? data.timestamp : undefined,
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
catch {
|
|
344
|
-
return null;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
if (frame.event === "session-lease") {
|
|
348
|
-
try {
|
|
349
|
-
const data = JSON.parse(frame.data);
|
|
350
|
-
return {
|
|
351
|
-
type: "session-lease",
|
|
352
|
-
userAddress: String(data.userAddress ?? ""),
|
|
353
|
-
chainId: Number(data.chainId ?? 0),
|
|
354
|
-
reason: typeof data.reason === "string" ? data.reason : undefined,
|
|
355
|
-
message: typeof data.message === "string" ? data.message : undefined,
|
|
356
|
-
leaseMs: typeof data.leaseMs === "number" ? data.leaseMs : undefined,
|
|
357
|
-
retryAfterMs: typeof data.retryAfterMs === "number" ? data.retryAfterMs : undefined,
|
|
358
|
-
timestamp: typeof data.timestamp === "number" ? data.timestamp : undefined,
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
catch {
|
|
362
|
-
return null;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
|
-
function parseAlertFrame(frame) {
|
|
368
|
-
if (frame.event !== "compose.alert")
|
|
369
|
-
return null;
|
|
370
|
-
try {
|
|
371
|
-
const data = JSON.parse(frame.data);
|
|
372
|
-
const message = typeof data.message === "string" ? data.message : "";
|
|
373
|
-
const severity = data.severity === "warning" || data.severity === "error" ? data.severity : "info";
|
|
374
|
-
return {
|
|
375
|
-
type: "compose.alert",
|
|
376
|
-
code: typeof data.code === "string" ? data.code : "compose_alert",
|
|
377
|
-
severity,
|
|
378
|
-
source: typeof data.source === "string" ? data.source : "api",
|
|
379
|
-
scope: typeof data.scope === "string" ? data.scope : "api",
|
|
380
|
-
title: typeof data.title === "string" ? data.title : undefined,
|
|
381
|
-
message,
|
|
382
|
-
userAddress: typeof data.userAddress === "string" ? data.userAddress : undefined,
|
|
383
|
-
chainId: typeof data.chainId === "number" ? data.chainId : undefined,
|
|
384
|
-
timestamp: typeof data.timestamp === "number" ? data.timestamp : undefined,
|
|
385
|
-
metadata: isRecord(data.metadata) ? data.metadata : undefined,
|
|
386
|
-
leaseMs: typeof data.leaseMs === "number" ? data.leaseMs : undefined,
|
|
387
|
-
retryAfterMs: typeof data.retryAfterMs === "number" ? data.retryAfterMs : undefined,
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
catch {
|
|
391
|
-
return null;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
function isRecord(value) {
|
|
395
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
396
|
-
}
|
|
397
|
-
function coerceWeiString(value) {
|
|
398
|
-
if (typeof value === "string" && value.length > 0)
|
|
399
|
-
return value;
|
|
400
|
-
if (typeof value === "number" && Number.isFinite(value))
|
|
401
|
-
return String(value);
|
|
402
|
-
return undefined;
|
|
403
|
-
}
|
|
404
|
-
//# sourceMappingURL=session-events.js.map
|