@canton-network/core-asyncapi-client 2.3.0 → 2.4.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.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/websocket-client.d.ts +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _canton_network_core_ledger_client_types = require("@canton-network/core-ledger-client-types");
|
|
3
3
|
let _logtape_logtape = require("@logtape/logtape");
|
|
4
|
-
// \0@oxc-project+runtime@0.
|
|
4
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
5
5
|
function _typeof(o) {
|
|
6
6
|
"@babel/helpers - typeof";
|
|
7
7
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -10,23 +10,23 @@ function _typeof(o) {
|
|
|
10
10
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
11
11
|
}, _typeof(o);
|
|
12
12
|
}
|
|
13
|
-
// \0@oxc-project+runtime@0.
|
|
14
|
-
function toPrimitive(t,
|
|
13
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
14
|
+
function toPrimitive(t, e) {
|
|
15
15
|
if ("object" != _typeof(t) || !t) return t;
|
|
16
|
-
var
|
|
17
|
-
if (void 0 !==
|
|
18
|
-
var i =
|
|
16
|
+
var r;
|
|
17
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
18
|
+
var i = r.call(t, e || "default");
|
|
19
19
|
if ("object" != _typeof(i)) return i;
|
|
20
20
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
21
21
|
}
|
|
22
|
-
return ("string" ===
|
|
22
|
+
return ("string" === e ? String : Number)(t);
|
|
23
23
|
}
|
|
24
|
-
// \0@oxc-project+runtime@0.
|
|
24
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
25
25
|
function toPropertyKey(t) {
|
|
26
26
|
var i = toPrimitive(t, "string");
|
|
27
27
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
28
28
|
}
|
|
29
|
-
// \0@oxc-project+runtime@0.
|
|
29
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
30
30
|
function _defineProperty(e, r, t) {
|
|
31
31
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
32
32
|
value: t,
|
|
@@ -48,7 +48,7 @@ var WebSocketClient = class {
|
|
|
48
48
|
_defineProperty(this, "token", "");
|
|
49
49
|
_defineProperty(this, "protocol", []);
|
|
50
50
|
_defineProperty(this, "channelsByVersion", void 0);
|
|
51
|
-
_defineProperty(this, "version", "3.
|
|
51
|
+
_defineProperty(this, "version", "3.6");
|
|
52
52
|
_defineProperty(this, "accessTokenProvider", void 0);
|
|
53
53
|
this.baseUrl = baseUrl;
|
|
54
54
|
this.accessTokenProvider = accessTokenProvider;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["supportedAsyncApiVersions","getLogger","asyncApiByVersion","EventFilterBySetup"],"sources":["../src/websocket-client.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { PartyId } from '@canton-network/core-types'\nimport {\n asyncApiByVersion,\n supportedAsyncApiVersions,\n EventFilterBySetup,\n type AsyncChannelsByVersion,\n type AsyncApiVersion,\n type AsyncCommonChannels,\n type LedgerCommonSchemas,\n} from '@canton-network/core-ledger-client-types'\nimport type { AccessTokenProvider } from '@canton-network/core-wallet-auth'\nimport { getLogger } from '@logtape/logtape'\n\nexport const supportedVersions = supportedAsyncApiVersions\n\nexport type SupportedVersions = AsyncApiVersion\n\ntype ChannelsByVersion = AsyncChannelsByVersion\n\ntype ChannelsMap = {\n [V in SupportedVersions]: ChannelsByVersion[V]\n}\n\nexport type CompletionStreamRequest =\n LedgerCommonSchemas['CompletionStreamRequest']\n\nexport type GetUpdatesRequest = LedgerCommonSchemas['GetUpdatesRequest']\n\nexport type JsGetUpdatesResponse = LedgerCommonSchemas['JsGetUpdatesResponse']\nexport type CompletionsResponse =\n LedgerCommonSchemas['CompletionStreamResponse']\n\ntype UpdateSubscriptionOptions = {\n beginExclusive: number\n endInclusive?: number\n partyId?: PartyId\n verbose?: boolean\n} & (\n | { interfaceIds: string[]; templateIds?: never }\n | { interfaceIds?: never; templateIds: string[] }\n)\n\ntype CommandsCompletionsOptions = {\n beginExclusive: number\n userId: string\n parties: PartyId[]\n}\n\nexport class WebSocketClient {\n private logger = getLogger(['core', 'asyncapi-client', 'WebSocketClient'])\n private baseUrl: string\n private token: string = ''\n private protocol: string[] = []\n private readonly channelsByVersion: ChannelsMap\n private version: SupportedVersions = '3.
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["supportedAsyncApiVersions","getLogger","asyncApiByVersion","EventFilterBySetup"],"sources":["../src/websocket-client.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { PartyId } from '@canton-network/core-types'\nimport {\n asyncApiByVersion,\n supportedAsyncApiVersions,\n EventFilterBySetup,\n type AsyncChannelsByVersion,\n type AsyncApiVersion,\n type AsyncCommonChannels,\n type LedgerCommonSchemas,\n} from '@canton-network/core-ledger-client-types'\nimport type { AccessTokenProvider } from '@canton-network/core-wallet-auth'\nimport { getLogger } from '@logtape/logtape'\n\nexport const supportedVersions = supportedAsyncApiVersions\n\nexport type SupportedVersions = AsyncApiVersion\n\ntype ChannelsByVersion = AsyncChannelsByVersion\n\ntype ChannelsMap = {\n [V in SupportedVersions]: ChannelsByVersion[V]\n}\n\nexport type CompletionStreamRequest =\n LedgerCommonSchemas['CompletionStreamRequest']\n\nexport type GetUpdatesRequest = LedgerCommonSchemas['GetUpdatesRequest']\n\nexport type JsGetUpdatesResponse = LedgerCommonSchemas['JsGetUpdatesResponse']\nexport type CompletionsResponse =\n LedgerCommonSchemas['CompletionStreamResponse']\n\ntype UpdateSubscriptionOptions = {\n beginExclusive: number\n endInclusive?: number\n partyId?: PartyId\n verbose?: boolean\n} & (\n | { interfaceIds: string[]; templateIds?: never }\n | { interfaceIds?: never; templateIds: string[] }\n)\n\ntype CommandsCompletionsOptions = {\n beginExclusive: number\n userId: string\n parties: PartyId[]\n}\n\nexport class WebSocketClient {\n private logger = getLogger(['core', 'asyncapi-client', 'WebSocketClient'])\n private baseUrl: string\n private token: string = ''\n private protocol: string[] = []\n private readonly channelsByVersion: ChannelsMap\n private version: SupportedVersions = '3.6'\n private accessTokenProvider: AccessTokenProvider\n\n constructor({\n baseUrl,\n accessTokenProvider,\n version,\n }: {\n baseUrl: string\n accessTokenProvider: AccessTokenProvider\n version?: SupportedVersions\n }) {\n this.baseUrl = baseUrl\n this.accessTokenProvider = accessTokenProvider\n this.channelsByVersion = Object.fromEntries(\n supportedVersions.map((v) => [v, asyncApiByVersion[v].CHANNELS])\n ) as ChannelsMap\n this.version = version ?? this.version\n }\n\n private get channels(): AsyncCommonChannels {\n return this.channelsByVersion[this.version] as AsyncCommonChannels\n }\n\n async init() {\n this.token = await this.accessTokenProvider.getAccessToken()\n this.protocol = [`jwt.token.${this.token}`, 'daml.ws.auth']\n\n this.logger.info(\n `initializing websocket client with {length} protocols`,\n {\n length: this.protocol.length,\n }\n )\n }\n\n private generate<T extends JsGetUpdatesResponse | CompletionsResponse>(\n wsUrl: string,\n request: GetUpdatesRequest | CompletionStreamRequest\n ): AsyncIterableIterator<T> {\n const messageQueue: T[] = []\n let resolveNext: (() => void) | null = null\n let isClosed = false\n let streamError: Error | null = null\n\n const generator = async function* (this: WebSocketClient) {\n await this.init()\n\n this.logger.debug({ request })\n\n const ws = new WebSocket(wsUrl, this.protocol)\n\n ws.onopen = () => {\n ws.send(JSON.stringify(request))\n }\n ws.onmessage = (event) => {\n messageQueue.push(JSON.parse(event.data as string) as T)\n this.logger.debug(event.data, `Received event`)\n resolveNext?.()\n }\n ws.onerror = () => {\n streamError = new Error('WebSocket Handshake/Connection failed')\n this.logger.error(`Encountered ws.onError`)\n isClosed = true\n resolveNext?.()\n }\n ws.onclose = (event: CloseEvent) => {\n this.logger.debug(\n `CLOSING WEBSOCKET CONNECTION code: ${event.code}, reason: ${event.reason}`\n )\n isClosed = true\n resolveNext?.()\n }\n\n try {\n while (true) {\n if (messageQueue.length === 0) {\n if (isClosed) break\n await new Promise<void>((r) => (resolveNext = r))\n }\n\n if (streamError) throw streamError\n\n while (messageQueue.length > 0) {\n yield messageQueue.shift()!\n }\n\n if (isClosed && messageQueue.length === 0) break\n }\n } finally {\n if (ws.readyState === WebSocket.OPEN) ws.close()\n this.logger.info('Generator cleanup: WebSocket closed.')\n }\n }\n\n return generator.call(this)\n }\n\n streamUpdates(\n options: UpdateSubscriptionOptions\n ): AsyncIterableIterator<JsGetUpdatesResponse> {\n const wsUpdatesUrl = `${this.baseUrl}${this.channels.v2_updates}`\n\n const eventFormat = options.templateIds\n ? EventFilterBySetup({\n templateIds: options.templateIds,\n partyId: options.partyId,\n verbose: options.verbose ?? true,\n })\n : EventFilterBySetup({\n interfaceIds: options.interfaceIds!,\n partyId: options.partyId,\n verbose: options.verbose ?? true,\n })\n\n const request = {\n beginExclusive: options.beginExclusive,\n updateFormat: {\n includeTransactions: {\n eventFormat,\n transactionShape: 'TRANSACTION_SHAPE_ACS_DELTA',\n },\n includeReassignments: eventFormat,\n includeTopologyEvents: {\n includeParticipantAuthorizationEvents: {\n parties: options.partyId ? [options.partyId] : [],\n },\n },\n },\n ...(options.endInclusive !== undefined\n ? { endInclusive: options.endInclusive }\n : {}),\n } satisfies GetUpdatesRequest\n\n return this.generate<JsGetUpdatesResponse>(wsUpdatesUrl, request)\n }\n\n streamCompletions(\n options: CommandsCompletionsOptions\n ): AsyncIterableIterator<CompletionsResponse> {\n const wsCompletionsUrl = `${this.baseUrl}${this.channels.v2_commands_completions}`\n\n const request = {\n beginExclusive: options.beginExclusive,\n userId: options.userId,\n parties: options.parties,\n }\n\n return this.generate<CompletionsResponse>(wsCompletionsUrl, request)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAa,oBAAoBA,yCAAAA;AAmCjC,IAAa,kBAAb,MAA6B;CASzB,YAAY,EACR,SACA,qBACA,WAKD;EAhBK,gBAAA,MAAA,WAAA,GAASC,iBAAAA,UAAAA,CAAU;GAAC;GAAQ;GAAmB;EAAiB,CAAC,CAAA;EACjE,gBAAA,MAAA,WAAA,KAAA,CAAA;EACA,gBAAA,MAAA,SAAgB,EAAA;EAChB,gBAAA,MAAA,YAAqB,CAAC,CAAA;EACb,gBAAA,MAAA,qBAAA,KAAA,CAAA;EACT,gBAAA,MAAA,WAA6B,KAAA;EAC7B,gBAAA,MAAA,uBAAA,KAAA,CAAA;EAWJ,KAAK,UAAU;EACf,KAAK,sBAAsB;EAC3B,KAAK,oBAAoB,OAAO,YAC5B,kBAAkB,KAAK,MAAM,CAAC,GAAGC,yCAAAA,kBAAkB,EAAE,CAAC,QAAQ,CAAC,CACnE;EACA,KAAK,UAAU,WAAW,KAAK;CACnC;CAEA,IAAY,WAAgC;EACxC,OAAO,KAAK,kBAAkB,KAAK;CACvC;CAEA,MAAM,OAAO;EACT,KAAK,QAAQ,MAAM,KAAK,oBAAoB,eAAe;EAC3D,KAAK,WAAW,CAAC,aAAa,KAAK,SAAS,cAAc;EAE1D,KAAK,OAAO,KACR,yDACA,EACI,QAAQ,KAAK,SAAS,OAC1B,CACJ;CACJ;CAEA,SACI,OACA,SACwB;EACxB,MAAM,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AC,KAAA,GACDA,yCAAAA,mBAAAA,CAAmB;GACf,cAAc,QAAQ;GACtB,SAAS,QAAQ;GACjB,SAAS,QAAQ,WAAW;EAChC,CAAC;EAEP,MAAM,UAAU;GACZ,gBAAgB,QAAQ;GACxB,cAAc;IACV,qBAAqB;KACjB;KACA,kBAAkB;IACtB;IACA,sBAAsB;IACtB,uBAAuB,EACnB,uCAAuC,EACnC,SAAS,QAAQ,UAAU,CAAC,QAAQ,OAAO,IAAI,CAAC,EACpD,EACJ;GACJ;GACA,GAAI,QAAQ,iBAAiB,KAAA,IACvB,EAAE,cAAc,QAAQ,aAAa,IACrC,CAAC;EACX;EAEA,OAAO,KAAK,SAA+B,cAAc,OAAO;CACpE;CAEA,kBACI,SAC0C;EAC1C,MAAM,mBAAmB,GAAG,KAAK,UAAU,KAAK,SAAS;EAEzD,MAAM,UAAU;GACZ,gBAAgB,QAAQ;GACxB,QAAQ,QAAQ;GAChB,SAAS,QAAQ;EACrB;EAEA,OAAO,KAAK,SAA8B,kBAAkB,OAAO;CACvE;AACJ"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventFilterBySetup, asyncApiByVersion, supportedAsyncApiVersions } from "@canton-network/core-ledger-client-types";
|
|
2
2
|
import { getLogger } from "@logtape/logtape";
|
|
3
|
-
// \0@oxc-project+runtime@0.
|
|
3
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
4
4
|
function _typeof(o) {
|
|
5
5
|
"@babel/helpers - typeof";
|
|
6
6
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -9,23 +9,23 @@ function _typeof(o) {
|
|
|
9
9
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
10
10
|
}, _typeof(o);
|
|
11
11
|
}
|
|
12
|
-
// \0@oxc-project+runtime@0.
|
|
13
|
-
function toPrimitive(t,
|
|
12
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
13
|
+
function toPrimitive(t, e) {
|
|
14
14
|
if ("object" != _typeof(t) || !t) return t;
|
|
15
|
-
var
|
|
16
|
-
if (void 0 !==
|
|
17
|
-
var i =
|
|
15
|
+
var r;
|
|
16
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
17
|
+
var i = r.call(t, e || "default");
|
|
18
18
|
if ("object" != _typeof(i)) return i;
|
|
19
19
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
20
20
|
}
|
|
21
|
-
return ("string" ===
|
|
21
|
+
return ("string" === e ? String : Number)(t);
|
|
22
22
|
}
|
|
23
|
-
// \0@oxc-project+runtime@0.
|
|
23
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
24
24
|
function toPropertyKey(t) {
|
|
25
25
|
var i = toPrimitive(t, "string");
|
|
26
26
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
27
27
|
}
|
|
28
|
-
// \0@oxc-project+runtime@0.
|
|
28
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
29
29
|
function _defineProperty(e, r, t) {
|
|
30
30
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
31
31
|
value: t,
|
|
@@ -47,7 +47,7 @@ var WebSocketClient = class {
|
|
|
47
47
|
_defineProperty(this, "token", "");
|
|
48
48
|
_defineProperty(this, "protocol", []);
|
|
49
49
|
_defineProperty(this, "channelsByVersion", void 0);
|
|
50
|
-
_defineProperty(this, "version", "3.
|
|
50
|
+
_defineProperty(this, "version", "3.6");
|
|
51
51
|
_defineProperty(this, "accessTokenProvider", void 0);
|
|
52
52
|
this.baseUrl = baseUrl;
|
|
53
53
|
this.accessTokenProvider = accessTokenProvider;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/websocket-client.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { PartyId } from '@canton-network/core-types'\nimport {\n asyncApiByVersion,\n supportedAsyncApiVersions,\n EventFilterBySetup,\n type AsyncChannelsByVersion,\n type AsyncApiVersion,\n type AsyncCommonChannels,\n type LedgerCommonSchemas,\n} from '@canton-network/core-ledger-client-types'\nimport type { AccessTokenProvider } from '@canton-network/core-wallet-auth'\nimport { getLogger } from '@logtape/logtape'\n\nexport const supportedVersions = supportedAsyncApiVersions\n\nexport type SupportedVersions = AsyncApiVersion\n\ntype ChannelsByVersion = AsyncChannelsByVersion\n\ntype ChannelsMap = {\n [V in SupportedVersions]: ChannelsByVersion[V]\n}\n\nexport type CompletionStreamRequest =\n LedgerCommonSchemas['CompletionStreamRequest']\n\nexport type GetUpdatesRequest = LedgerCommonSchemas['GetUpdatesRequest']\n\nexport type JsGetUpdatesResponse = LedgerCommonSchemas['JsGetUpdatesResponse']\nexport type CompletionsResponse =\n LedgerCommonSchemas['CompletionStreamResponse']\n\ntype UpdateSubscriptionOptions = {\n beginExclusive: number\n endInclusive?: number\n partyId?: PartyId\n verbose?: boolean\n} & (\n | { interfaceIds: string[]; templateIds?: never }\n | { interfaceIds?: never; templateIds: string[] }\n)\n\ntype CommandsCompletionsOptions = {\n beginExclusive: number\n userId: string\n parties: PartyId[]\n}\n\nexport class WebSocketClient {\n private logger = getLogger(['core', 'asyncapi-client', 'WebSocketClient'])\n private baseUrl: string\n private token: string = ''\n private protocol: string[] = []\n private readonly channelsByVersion: ChannelsMap\n private version: SupportedVersions = '3.
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/websocket-client.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { PartyId } from '@canton-network/core-types'\nimport {\n asyncApiByVersion,\n supportedAsyncApiVersions,\n EventFilterBySetup,\n type AsyncChannelsByVersion,\n type AsyncApiVersion,\n type AsyncCommonChannels,\n type LedgerCommonSchemas,\n} from '@canton-network/core-ledger-client-types'\nimport type { AccessTokenProvider } from '@canton-network/core-wallet-auth'\nimport { getLogger } from '@logtape/logtape'\n\nexport const supportedVersions = supportedAsyncApiVersions\n\nexport type SupportedVersions = AsyncApiVersion\n\ntype ChannelsByVersion = AsyncChannelsByVersion\n\ntype ChannelsMap = {\n [V in SupportedVersions]: ChannelsByVersion[V]\n}\n\nexport type CompletionStreamRequest =\n LedgerCommonSchemas['CompletionStreamRequest']\n\nexport type GetUpdatesRequest = LedgerCommonSchemas['GetUpdatesRequest']\n\nexport type JsGetUpdatesResponse = LedgerCommonSchemas['JsGetUpdatesResponse']\nexport type CompletionsResponse =\n LedgerCommonSchemas['CompletionStreamResponse']\n\ntype UpdateSubscriptionOptions = {\n beginExclusive: number\n endInclusive?: number\n partyId?: PartyId\n verbose?: boolean\n} & (\n | { interfaceIds: string[]; templateIds?: never }\n | { interfaceIds?: never; templateIds: string[] }\n)\n\ntype CommandsCompletionsOptions = {\n beginExclusive: number\n userId: string\n parties: PartyId[]\n}\n\nexport class WebSocketClient {\n private logger = getLogger(['core', 'asyncapi-client', 'WebSocketClient'])\n private baseUrl: string\n private token: string = ''\n private protocol: string[] = []\n private readonly channelsByVersion: ChannelsMap\n private version: SupportedVersions = '3.6'\n private accessTokenProvider: AccessTokenProvider\n\n constructor({\n baseUrl,\n accessTokenProvider,\n version,\n }: {\n baseUrl: string\n accessTokenProvider: AccessTokenProvider\n version?: SupportedVersions\n }) {\n this.baseUrl = baseUrl\n this.accessTokenProvider = accessTokenProvider\n this.channelsByVersion = Object.fromEntries(\n supportedVersions.map((v) => [v, asyncApiByVersion[v].CHANNELS])\n ) as ChannelsMap\n this.version = version ?? this.version\n }\n\n private get channels(): AsyncCommonChannels {\n return this.channelsByVersion[this.version] as AsyncCommonChannels\n }\n\n async init() {\n this.token = await this.accessTokenProvider.getAccessToken()\n this.protocol = [`jwt.token.${this.token}`, 'daml.ws.auth']\n\n this.logger.info(\n `initializing websocket client with {length} protocols`,\n {\n length: this.protocol.length,\n }\n )\n }\n\n private generate<T extends JsGetUpdatesResponse | CompletionsResponse>(\n wsUrl: string,\n request: GetUpdatesRequest | CompletionStreamRequest\n ): AsyncIterableIterator<T> {\n const messageQueue: T[] = []\n let resolveNext: (() => void) | null = null\n let isClosed = false\n let streamError: Error | null = null\n\n const generator = async function* (this: WebSocketClient) {\n await this.init()\n\n this.logger.debug({ request })\n\n const ws = new WebSocket(wsUrl, this.protocol)\n\n ws.onopen = () => {\n ws.send(JSON.stringify(request))\n }\n ws.onmessage = (event) => {\n messageQueue.push(JSON.parse(event.data as string) as T)\n this.logger.debug(event.data, `Received event`)\n resolveNext?.()\n }\n ws.onerror = () => {\n streamError = new Error('WebSocket Handshake/Connection failed')\n this.logger.error(`Encountered ws.onError`)\n isClosed = true\n resolveNext?.()\n }\n ws.onclose = (event: CloseEvent) => {\n this.logger.debug(\n `CLOSING WEBSOCKET CONNECTION code: ${event.code}, reason: ${event.reason}`\n )\n isClosed = true\n resolveNext?.()\n }\n\n try {\n while (true) {\n if (messageQueue.length === 0) {\n if (isClosed) break\n await new Promise<void>((r) => (resolveNext = r))\n }\n\n if (streamError) throw streamError\n\n while (messageQueue.length > 0) {\n yield messageQueue.shift()!\n }\n\n if (isClosed && messageQueue.length === 0) break\n }\n } finally {\n if (ws.readyState === WebSocket.OPEN) ws.close()\n this.logger.info('Generator cleanup: WebSocket closed.')\n }\n }\n\n return generator.call(this)\n }\n\n streamUpdates(\n options: UpdateSubscriptionOptions\n ): AsyncIterableIterator<JsGetUpdatesResponse> {\n const wsUpdatesUrl = `${this.baseUrl}${this.channels.v2_updates}`\n\n const eventFormat = options.templateIds\n ? EventFilterBySetup({\n templateIds: options.templateIds,\n partyId: options.partyId,\n verbose: options.verbose ?? true,\n })\n : EventFilterBySetup({\n interfaceIds: options.interfaceIds!,\n partyId: options.partyId,\n verbose: options.verbose ?? true,\n })\n\n const request = {\n beginExclusive: options.beginExclusive,\n updateFormat: {\n includeTransactions: {\n eventFormat,\n transactionShape: 'TRANSACTION_SHAPE_ACS_DELTA',\n },\n includeReassignments: eventFormat,\n includeTopologyEvents: {\n includeParticipantAuthorizationEvents: {\n parties: options.partyId ? [options.partyId] : [],\n },\n },\n },\n ...(options.endInclusive !== undefined\n ? { endInclusive: options.endInclusive }\n : {}),\n } satisfies GetUpdatesRequest\n\n return this.generate<JsGetUpdatesResponse>(wsUpdatesUrl, request)\n }\n\n streamCompletions(\n options: CommandsCompletionsOptions\n ): AsyncIterableIterator<CompletionsResponse> {\n const wsCompletionsUrl = `${this.baseUrl}${this.channels.v2_commands_completions}`\n\n const request = {\n beginExclusive: options.beginExclusive,\n userId: options.userId,\n parties: options.parties,\n }\n\n return this.generate<CompletionsResponse>(wsCompletionsUrl, request)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAa,oBAAoB;AAmCjC,IAAa,kBAAb,MAA6B;CASzB,YAAY,EACR,SACA,qBACA,WAKD;EAhBK,gBAAA,MAAA,UAAS,UAAU;GAAC;GAAQ;GAAmB;EAAiB,CAAC,CAAA;EACjE,gBAAA,MAAA,WAAA,KAAA,CAAA;EACA,gBAAA,MAAA,SAAgB,EAAA;EAChB,gBAAA,MAAA,YAAqB,CAAC,CAAA;EACb,gBAAA,MAAA,qBAAA,KAAA,CAAA;EACT,gBAAA,MAAA,WAA6B,KAAA;EAC7B,gBAAA,MAAA,uBAAA,KAAA,CAAA;EAWJ,KAAK,UAAU;EACf,KAAK,sBAAsB;EAC3B,KAAK,oBAAoB,OAAO,YAC5B,kBAAkB,KAAK,MAAM,CAAC,GAAG,kBAAkB,EAAE,CAAC,QAAQ,CAAC,CACnE;EACA,KAAK,UAAU,WAAW,KAAK;CACnC;CAEA,IAAY,WAAgC;EACxC,OAAO,KAA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J;EAEA,OAAO,UAAU,KAAK,IAAI;CAC9B;CAEA,cACI,SAC2C;EAC3C,MAAM,eAAe,GAAG,KAAK,UAAU,KAAK,SAAS;EAErD,MAAM,cAAc,QAAQ,cACtB,mBAAmB;GACf,aAAa,QAAQ;GACrB,SAAS,QAAQ;GACjB,SAAS,QAAQ,WAAW;EAChC,CAAC,IACD,mBAAmB;GACf,cAAc,QAAQ;GACtB,SAAS,QAAQ;GACjB,SAAS,QAAQ,WAAW;EAChC,CAAC;EAEP,MAAM,UAAU;GACZ,gBAAgB,QAAQ;GACxB,cAAc;IACV,qBAAqB;KACjB;KACA,kBAAkB;IACtB;IACA,sBAAsB;IACtB,uBAAuB,EACnB,uCAAuC,EACnC,SAAS,QAAQ,UAAU,CAAC,QAAQ,OAAO,IAAI,CAAC,EACpD,EACJ;GACJ;GACA,GAAI,QAAQ,iBAAiB,KAAA,IACvB,EAAE,cAAc,QAAQ,aAAa,IACrC,CAAC;EACX;EAEA,OAAO,KAAK,SAA+B,cAAc,OAAO;CACpE;CAEA,kBACI,SAC0C;EAC1C,MAAM,mBAAmB,GAAG,KAAK,UAAU,KAAK,SAAS;EAEzD,MAAM,UAAU;GACZ,gBAAgB,QAAQ;GACxB,QAAQ,QAAQ;GAChB,SAAS,QAAQ;EACrB;EAEA,OAAO,KAAK,SAA8B,kBAAkB,OAAO;CACvE;AACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PartyId } from '@canton-network/core-types';
|
|
2
2
|
import { type AsyncApiVersion, type LedgerCommonSchemas } from '@canton-network/core-ledger-client-types';
|
|
3
3
|
import type { AccessTokenProvider } from '@canton-network/core-wallet-auth';
|
|
4
|
-
export declare const supportedVersions: readonly ["3.
|
|
4
|
+
export declare const supportedVersions: readonly ["3.6", "3.7"];
|
|
5
5
|
export type SupportedVersions = AsyncApiVersion;
|
|
6
6
|
export type CompletionStreamRequest = LedgerCommonSchemas['CompletionStreamRequest'];
|
|
7
7
|
export type GetUpdatesRequest = LedgerCommonSchemas['GetUpdatesRequest'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canton-network/core-asyncapi-client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Provides a TypeScript asyncapi ledger client, generated by the OpenAPI spec",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"@types/node": "^25.9.9",
|
|
22
22
|
"@vitest/browser-playwright": "^5.0.5",
|
|
23
23
|
"@vitest/coverage-v8": "^5.0.5",
|
|
24
|
-
"playwright": "^1.
|
|
25
|
-
"tsdown": "^0.23.
|
|
24
|
+
"playwright": "^1.65.0",
|
|
25
|
+
"tsdown": "^0.23.7",
|
|
26
26
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
27
27
|
"vitest": "^5.0.5"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@canton-network/core-ledger-client-types": "2.
|
|
31
|
-
"@canton-network/core-types": "2.
|
|
32
|
-
"@canton-network/core-wallet-auth": "2.
|
|
30
|
+
"@canton-network/core-ledger-client-types": "2.4.0",
|
|
31
|
+
"@canton-network/core-types": "2.4.0",
|
|
32
|
+
"@canton-network/core-wallet-auth": "2.4.0",
|
|
33
33
|
"@logtape/logtape": "^2.4.1"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|