@scalar/workspace-store 0.51.2 → 0.53.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.
Files changed (92) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/channel-example/build-connection-url.d.ts +42 -0
  3. package/dist/channel-example/build-connection-url.d.ts.map +1 -0
  4. package/dist/channel-example/build-connection-url.js +184 -0
  5. package/dist/channel-example/get-all-channel-messages.d.ts +10 -0
  6. package/dist/channel-example/get-all-channel-messages.d.ts.map +1 -0
  7. package/dist/channel-example/get-all-channel-messages.js +16 -0
  8. package/dist/channel-example/get-asyncapi-security-requirements.d.ts +7 -0
  9. package/dist/channel-example/get-asyncapi-security-requirements.d.ts.map +1 -0
  10. package/dist/channel-example/get-asyncapi-security-requirements.js +76 -0
  11. package/dist/channel-example/get-channel-connection-context.d.ts +16 -0
  12. package/dist/channel-example/get-channel-connection-context.d.ts.map +1 -0
  13. package/dist/channel-example/get-channel-connection-context.js +120 -0
  14. package/dist/channel-example/get-channel-connection-security.d.ts +8 -0
  15. package/dist/channel-example/get-channel-connection-security.d.ts.map +1 -0
  16. package/dist/channel-example/get-channel-connection-security.js +20 -0
  17. package/dist/channel-example/get-channel-operations.d.ts +11 -0
  18. package/dist/channel-example/get-channel-operations.d.ts.map +1 -0
  19. package/dist/channel-example/get-channel-operations.js +20 -0
  20. package/dist/channel-example/get-channel-parameters.d.ts +14 -0
  21. package/dist/channel-example/get-channel-parameters.d.ts.map +1 -0
  22. package/dist/channel-example/get-channel-parameters.js +59 -0
  23. package/dist/channel-example/index.d.ts +20 -0
  24. package/dist/channel-example/index.d.ts.map +1 -0
  25. package/dist/channel-example/index.js +11 -0
  26. package/dist/channel-example/resolve-channel.d.ts +11 -0
  27. package/dist/channel-example/resolve-channel.d.ts.map +1 -0
  28. package/dist/channel-example/resolve-channel.js +13 -0
  29. package/dist/channel-example/resolve-operation-channel.d.ts +11 -0
  30. package/dist/channel-example/resolve-operation-channel.d.ts.map +1 -0
  31. package/dist/channel-example/resolve-operation-channel.js +39 -0
  32. package/dist/channel-example/resolve-operation-with-traits.d.ts +6 -0
  33. package/dist/channel-example/resolve-operation-with-traits.d.ts.map +1 -0
  34. package/dist/channel-example/resolve-operation-with-traits.js +41 -0
  35. package/dist/channel-example/servers.d.ts +36 -0
  36. package/dist/channel-example/servers.d.ts.map +1 -0
  37. package/dist/channel-example/servers.js +77 -0
  38. package/dist/channel-example/types.d.ts +41 -0
  39. package/dist/channel-example/types.d.ts.map +1 -0
  40. package/dist/channel-example/types.js +1 -0
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +8 -8
  43. package/dist/entities/auth/schema.d.ts +1266 -81
  44. package/dist/entities/auth/schema.d.ts.map +1 -1
  45. package/dist/events/definitions/log.d.ts +6 -0
  46. package/dist/events/definitions/log.d.ts.map +1 -1
  47. package/dist/helpers/get-name-from-ref.d.ts +15 -0
  48. package/dist/helpers/get-name-from-ref.d.ts.map +1 -0
  49. package/dist/helpers/get-name-from-ref.js +37 -0
  50. package/dist/navigation/get-navigation-options.d.ts +2 -2
  51. package/dist/navigation/get-navigation-options.d.ts.map +1 -1
  52. package/dist/navigation/get-navigation-options.js +26 -3
  53. package/dist/navigation/helpers/traverse-asyncapi-document.d.ts +23 -0
  54. package/dist/navigation/helpers/traverse-asyncapi-document.d.ts.map +1 -0
  55. package/dist/navigation/helpers/traverse-asyncapi-document.js +479 -0
  56. package/dist/navigation/helpers/traverse-description.d.ts +4 -3
  57. package/dist/navigation/helpers/traverse-description.d.ts.map +1 -1
  58. package/dist/navigation/helpers/traverse-description.js +2 -2
  59. package/dist/navigation/helpers/traverse-document.d.ts.map +1 -1
  60. package/dist/navigation/helpers/traverse-document.js +3 -3
  61. package/dist/navigation/index.d.ts +1 -0
  62. package/dist/navigation/index.d.ts.map +1 -1
  63. package/dist/navigation/index.js +1 -0
  64. package/dist/navigation/types.d.ts +3 -0
  65. package/dist/navigation/types.d.ts.map +1 -1
  66. package/dist/request-example/builder/helpers/get-example-from-schema.d.ts.map +1 -1
  67. package/dist/request-example/builder/helpers/get-example-from-schema.js +33 -2
  68. package/dist/schemas/extensions/schema/x-order.d.ts +22 -0
  69. package/dist/schemas/extensions/schema/x-order.d.ts.map +1 -0
  70. package/dist/schemas/extensions/schema/x-order.js +17 -0
  71. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts +4 -1
  72. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts.map +1 -1
  73. package/dist/schemas/extensions/server/x-scalar-selected-server.js +4 -2
  74. package/dist/schemas/navigation.d.ts +113 -4
  75. package/dist/schemas/navigation.d.ts.map +1 -1
  76. package/dist/schemas/navigation.js +22 -0
  77. package/dist/schemas/reference-config/index.d.ts +245 -8
  78. package/dist/schemas/reference-config/index.d.ts.map +1 -1
  79. package/dist/schemas/reference-config/settings.d.ts +245 -8
  80. package/dist/schemas/reference-config/settings.d.ts.map +1 -1
  81. package/dist/schemas/v3.1/openapi/index.d.ts.map +1 -1
  82. package/dist/schemas/v3.1/openapi/index.js +61 -17
  83. package/dist/schemas/v3.1/strict/openapi-document.d.ts +9731 -1436
  84. package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
  85. package/dist/schemas/v3.1/strict/openapi-document.js +4 -1
  86. package/dist/schemas/v3.1/strict/ref-definitions.d.ts +3 -0
  87. package/dist/schemas/v3.1/strict/ref-definitions.d.ts.map +1 -1
  88. package/dist/schemas/v3.1/strict/ref-definitions.js +3 -0
  89. package/dist/schemas/v3.1/strict/schema.d.ts +275 -27
  90. package/dist/schemas/v3.1/strict/schema.d.ts.map +1 -1
  91. package/dist/schemas/v3.1/strict/schema.js +39 -29
  92. package/package.json +12 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @scalar/workspace-store
2
2
 
3
+ ## 0.53.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#9340](https://github.com/scalar/scalar/pull/9340): feat: add getChannelConnectionContext for AsyncAPI WebSocket channels
8
+
9
+ Add channel connection context helpers that resolve channel, messages, parameters, servers, security, and connection URL for WebSocket client UI.
10
+
11
+ - [#9372](https://github.com/scalar/scalar/pull/9372): Render AsyncAPI `components.schemas` as Models, listed in the sidebar and content just like OpenAPI schemas
12
+ - [#9331](https://github.com/scalar/scalar/pull/9331): feat: generate AsyncAPI sidebar navigation on document ingest
13
+
14
+ Add `TraversedAsyncApiChannel`, `TraversedAsyncApiOperation`, and `TraversedAsyncApiMessage` navigation entry types, plus `traverseAsyncApiDocument` wired into the AsyncAPI ingest path. Navigation is structured as channel → operation → message, with messages resolved per operation (all channel messages by default, or filtered via `operation.messages`).
15
+
16
+ ### Patch Changes
17
+
18
+ - [#9255](https://github.com/scalar/scalar/pull/9255): Surface the Introduction entry and any headings extracted from `info.description` of AsyncAPI documents in the sidebar, mirroring how OpenAPI documents are handled.
19
+ - [#9309](https://github.com/scalar/scalar/pull/9309): feat: add `modelsSectionLabel` configuration (`'Models' | 'Schemas' | string`) to use OpenAPI-style Schemas terminology in the sidebar, content, and search.
20
+ - [#9383](https://github.com/scalar/scalar/pull/9383): fix: preserve multi-type schema arrays when coercing schemas with validation keywords
21
+
22
+ ## 0.52.0
23
+
24
+ ### Minor Changes
25
+
26
+ - [#9313](https://github.com/scalar/scalar/pull/9313): feat: add AsyncAPI connection URL builder and server list helpers
27
+
28
+ ### Patch Changes
29
+
30
+ - [#9334](https://github.com/scalar/scalar/pull/9334): Add analytics events for document save and registry sync (pull/push) actions
31
+ - [#9333](https://github.com/scalar/scalar/pull/9333): feat: respect the `x-order` extension when building schema examples
32
+
3
33
  ## 0.51.2
4
34
 
5
35
  ## 0.51.1
@@ -0,0 +1,42 @@
1
+ import type { AsyncApiChannelObject, AsyncApiOperationObject, AsyncApiServerObject, AsyncApiWsBindingObject } from '@scalar/types/asyncapi/3.1';
2
+ /** AsyncAPI server protocols supported for WebSocket connections in the API client MVP. */
3
+ export declare const ASYNCAPI_WEBSOCKET_PROTOCOLS: readonly ["ws", "wss"];
4
+ export type AsyncApiWebSocketProtocol = (typeof ASYNCAPI_WEBSOCKET_PROTOCOLS)[number];
5
+ export type BuildConnectionUrlInput = {
6
+ server: AsyncApiServerObject;
7
+ channel: AsyncApiChannelObject;
8
+ operation?: AsyncApiOperationObject | null;
9
+ pathParameters?: Record<string, string>;
10
+ queryParameters?: Record<string, string>;
11
+ environmentVariables?: Record<string, string> | ((key: string) => string | null);
12
+ };
13
+ /**
14
+ * Extracts default values of variables defined on an AsyncAPI Server Object.
15
+ */
16
+ export declare const getAsyncApiServerVariables: (server: AsyncApiServerObject | null) => Record<string, string>;
17
+ /** Maps AsyncAPI `server.protocol` to a URL scheme (MVP: ws and wss). */
18
+ export declare const getUrlSchemeFromProtocol: (protocol: string) => string;
19
+ export declare const isWebSocketProtocol: (protocol: string) => protocol is AsyncApiWebSocketProtocol;
20
+ /**
21
+ * Builds the server base URL: scheme, host, and optional pathname (no channel address).
22
+ */
23
+ export declare const buildAsyncApiServerBaseUrl: (server: AsyncApiServerObject, environmentVariables?: BuildConnectionUrlInput["environmentVariables"]) => string;
24
+ /** Merges channel and operation WebSocket bindings; operation fields override channel. */
25
+ export declare const mergeWsBindings: (channel: AsyncApiChannelObject, operation?: AsyncApiOperationObject | null) => AsyncApiWsBindingObject | undefined;
26
+ /**
27
+ * Builds handshake query parameters from merged `bindings.ws.query` schema defaults,
28
+ * then applies explicit overrides.
29
+ */
30
+ export declare const buildWsQueryParams: (wsBinding: AsyncApiWsBindingObject | undefined, queryParameters?: Record<string, string>) => URLSearchParams;
31
+ /**
32
+ * Builds a WebSocket connection URL from a resolved server, channel, and optional operation.
33
+ *
34
+ * Composition (AsyncAPI 3.x):
35
+ * 1. `server.protocol` → URL scheme
36
+ * 2. `server.host` (+ variables and environment substitution)
37
+ * 3. Optional `server.pathname`
38
+ * 4. Channel `address` (+ path parameter substitution)
39
+ * 5. Query string from merged `bindings.ws.query` (channel + operation) with schema defaults
40
+ */
41
+ export declare const buildConnectionUrl: ({ server, channel, operation, pathParameters, queryParameters, environmentVariables, }: BuildConnectionUrlInput) => string;
42
+ //# sourceMappingURL=build-connection-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-connection-url.d.ts","sourceRoot":"","sources":["../../src/channel-example/build-connection-url.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,4BAA4B,CAAA;AAInC,2FAA2F;AAC3F,eAAO,MAAM,4BAA4B,wBAAyB,CAAA;AAElE,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAA;AAErF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,oBAAoB,CAAA;IAC5B,OAAO,EAAE,qBAAqB,CAAA;IAC9B,SAAS,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAA;IAC1C,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC,CAAA;CACjF,CAAA;AAQD;;GAEG;AACH,eAAO,MAAM,0BAA0B,GAAI,QAAQ,oBAAoB,GAAG,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAYrG,CAAA;AAoBD,yEAAyE;AACzE,eAAO,MAAM,wBAAwB,GAAI,UAAU,MAAM,KAAG,MAAuC,CAAA;AAEnG,eAAO,MAAM,mBAAmB,GAAI,UAAU,MAAM,KAAG,QAAQ,IAAI,yBAC0B,CAAA;AAE7F;;GAEG;AACH,eAAO,MAAM,0BAA0B,GACrC,QAAQ,oBAAoB,EAC5B,uBAAuB,uBAAuB,CAAC,sBAAsB,CAAC,KACrE,MAYF,CAAA;AAaD,0FAA0F;AAC1F,eAAO,MAAM,eAAe,GAC1B,SAAS,qBAAqB,EAC9B,YAAY,uBAAuB,GAAG,IAAI,KACzC,uBAAuB,GAAG,SAa5B,CAAA;AA0FD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC7B,WAAW,uBAAuB,GAAG,SAAS,EAC9C,kBAAkB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACvC,eAoBF,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAAI,wFAOhC,uBAAuB,KAAG,MAkB5B,CAAA"}
@@ -0,0 +1,184 @@
1
+ import { isObject } from '@scalar/helpers/object/is-object';
2
+ import { objectEntries } from '@scalar/helpers/object/object-entries';
3
+ import { replaceEnvVariables, replacePathVariables } from '@scalar/helpers/regex/replace-variables';
4
+ import { combineUrlAndPath, mergeUrls } from '@scalar/helpers/url/merge-urls';
5
+ import { getResolvedRef } from '../helpers/get-resolved-ref.js';
6
+ /** AsyncAPI server protocols supported for WebSocket connections in the API client MVP. */
7
+ export const ASYNCAPI_WEBSOCKET_PROTOCOLS = ['ws', 'wss'];
8
+ /**
9
+ * Extracts default values of variables defined on an AsyncAPI Server Object.
10
+ */
11
+ export const getAsyncApiServerVariables = (server) => {
12
+ if (!server?.variables) {
13
+ return {};
14
+ }
15
+ return objectEntries(server.variables).reduce((acc, [name, variable]) => {
16
+ const resolved = getResolvedRef(variable);
17
+ if (resolved.default != null) {
18
+ acc[String(name)] = String(resolved.default);
19
+ }
20
+ return acc;
21
+ }, {});
22
+ };
23
+ const substituteTemplate = (template, options) => {
24
+ let result = template;
25
+ if (options.serverVariables) {
26
+ result = replacePathVariables(result, options.serverVariables);
27
+ }
28
+ if (options.environmentVariables) {
29
+ result = replaceEnvVariables(result, options.environmentVariables);
30
+ }
31
+ if (options.pathParameters) {
32
+ result = replacePathVariables(result, options.pathParameters);
33
+ }
34
+ return result;
35
+ };
36
+ /** Maps AsyncAPI `server.protocol` to a URL scheme (MVP: ws and wss). */
37
+ export const getUrlSchemeFromProtocol = (protocol) => protocol.trim().toLowerCase();
38
+ export const isWebSocketProtocol = (protocol) => ASYNCAPI_WEBSOCKET_PROTOCOLS.includes(protocol.trim().toLowerCase());
39
+ /**
40
+ * Builds the server base URL: scheme, host, and optional pathname (no channel address).
41
+ */
42
+ export const buildAsyncApiServerBaseUrl = (server, environmentVariables) => {
43
+ const serverVariables = getAsyncApiServerVariables(server);
44
+ const scheme = getUrlSchemeFromProtocol(server.protocol);
45
+ const host = substituteTemplate(server.host, { serverVariables, environmentVariables });
46
+ const origin = `${scheme}://${host}`;
47
+ if (!server.pathname) {
48
+ return origin;
49
+ }
50
+ const pathname = substituteTemplate(server.pathname, { serverVariables, environmentVariables });
51
+ return combineUrlAndPath(origin, pathname);
52
+ };
53
+ const resolveWsBinding = (bindings) => {
54
+ if (!bindings) {
55
+ return undefined;
56
+ }
57
+ const resolved = getResolvedRef(bindings);
58
+ return resolved.ws;
59
+ };
60
+ /** Merges channel and operation WebSocket bindings; operation fields override channel. */
61
+ export const mergeWsBindings = (channel, operation) => {
62
+ const channelBinding = resolveWsBinding(channel.bindings);
63
+ const operationBinding = operation ? resolveWsBinding(operation.bindings) : undefined;
64
+ if (!channelBinding && !operationBinding) {
65
+ return undefined;
66
+ }
67
+ return {
68
+ ...channelBinding,
69
+ ...operationBinding,
70
+ query: mergeWsQuerySchemas(channelBinding?.query, operationBinding?.query),
71
+ };
72
+ };
73
+ const resolveWsQuerySchema = (query) => {
74
+ if (!query) {
75
+ return undefined;
76
+ }
77
+ const resolved = getResolvedRef(query);
78
+ if (resolved === true || resolved === false || !isObject(resolved)) {
79
+ return undefined;
80
+ }
81
+ return resolved;
82
+ };
83
+ const mergeWsQuerySchemas = (channelQuery, operationQuery) => {
84
+ const channelSchema = resolveWsQuerySchema(channelQuery);
85
+ const operationSchema = resolveWsQuerySchema(operationQuery);
86
+ if (!channelSchema && !operationSchema) {
87
+ return undefined;
88
+ }
89
+ if (!channelSchema) {
90
+ return operationQuery;
91
+ }
92
+ if (!operationSchema) {
93
+ return channelQuery;
94
+ }
95
+ // `properties` only exists on the object-schema branch of the Schema Object union,
96
+ // so reach it through an `in` check rather than assuming it is present.
97
+ const channelProperties = 'properties' in channelSchema ? channelSchema.properties : undefined;
98
+ const operationProperties = 'properties' in operationSchema ? operationSchema.properties : undefined;
99
+ // Merge via Object.assign so the result is an intersection of the two schemas rather than a
100
+ // distributed union of every Schema Object variant, which keeps it assignable to the query type.
101
+ return Object.assign({}, channelSchema, operationSchema, {
102
+ properties: {
103
+ ...channelProperties,
104
+ ...operationProperties,
105
+ },
106
+ });
107
+ };
108
+ const getDefaultValueFromPropertySchema = (propertySchema) => {
109
+ if (propertySchema === true || propertySchema === false || !isObject(propertySchema)) {
110
+ return undefined;
111
+ }
112
+ if ('default' in propertySchema && propertySchema.default !== undefined) {
113
+ return propertySchema.default;
114
+ }
115
+ if ('example' in propertySchema && propertySchema.example !== undefined) {
116
+ return propertySchema.example;
117
+ }
118
+ if ('enum' in propertySchema && Array.isArray(propertySchema.enum) && propertySchema.enum[0] !== undefined) {
119
+ return propertySchema.enum[0];
120
+ }
121
+ return undefined;
122
+ };
123
+ const appendQueryValue = (params, key, value) => {
124
+ if (value === undefined || value === null) {
125
+ return;
126
+ }
127
+ if (Array.isArray(value)) {
128
+ value.forEach((entry) => appendQueryValue(params, key, entry));
129
+ return;
130
+ }
131
+ if (typeof value === 'object') {
132
+ params.append(key, JSON.stringify(value));
133
+ return;
134
+ }
135
+ params.append(key, String(value));
136
+ };
137
+ /**
138
+ * Builds handshake query parameters from merged `bindings.ws.query` schema defaults,
139
+ * then applies explicit overrides.
140
+ */
141
+ export const buildWsQueryParams = (wsBinding, queryParameters) => {
142
+ const params = new URLSearchParams();
143
+ const querySchema = resolveWsQuerySchema(wsBinding?.query);
144
+ const properties = querySchema && 'properties' in querySchema ? querySchema.properties : undefined;
145
+ if (isObject(properties)) {
146
+ for (const [name, propertySchema] of Object.entries(properties)) {
147
+ const defaultValue = getDefaultValueFromPropertySchema(propertySchema);
148
+ appendQueryValue(params, name, defaultValue);
149
+ }
150
+ }
151
+ if (queryParameters) {
152
+ for (const [name, value] of objectEntries(queryParameters)) {
153
+ params.delete(name);
154
+ appendQueryValue(params, name, value);
155
+ }
156
+ }
157
+ return params;
158
+ };
159
+ /**
160
+ * Builds a WebSocket connection URL from a resolved server, channel, and optional operation.
161
+ *
162
+ * Composition (AsyncAPI 3.x):
163
+ * 1. `server.protocol` → URL scheme
164
+ * 2. `server.host` (+ variables and environment substitution)
165
+ * 3. Optional `server.pathname`
166
+ * 4. Channel `address` (+ path parameter substitution)
167
+ * 5. Query string from merged `bindings.ws.query` (channel + operation) with schema defaults
168
+ */
169
+ export const buildConnectionUrl = ({ server, channel, operation = null, pathParameters = {}, queryParameters = {}, environmentVariables, }) => {
170
+ const serverVariables = getAsyncApiServerVariables(server);
171
+ const baseUrl = buildAsyncApiServerBaseUrl(server, environmentVariables);
172
+ const address = channel.address;
173
+ if (address == null || address === '') {
174
+ const queryParams = buildWsQueryParams(mergeWsBindings(channel, operation), queryParameters);
175
+ return mergeUrls(baseUrl, '', queryParams, true);
176
+ }
177
+ const resolvedAddress = substituteTemplate(address, {
178
+ serverVariables,
179
+ environmentVariables,
180
+ pathParameters,
181
+ });
182
+ const queryParams = buildWsQueryParams(mergeWsBindings(channel, operation), queryParameters);
183
+ return mergeUrls(baseUrl, resolvedAddress, queryParams, true);
184
+ };
@@ -0,0 +1,10 @@
1
+ import type { AsyncApiChannelObject, AsyncApiDocument, AsyncApiMessageObject } from '@scalar/types/asyncapi/3.1';
2
+ export type ChannelMessageEntry = {
3
+ name: string;
4
+ message: AsyncApiMessageObject;
5
+ };
6
+ /**
7
+ * Resolves every message defined on a channel (AsyncAPI data store for payloads).
8
+ */
9
+ export declare const getAllChannelMessages: (_document: AsyncApiDocument, channel: AsyncApiChannelObject) => ChannelMessageEntry[];
10
+ //# sourceMappingURL=get-all-channel-messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-all-channel-messages.d.ts","sourceRoot":"","sources":["../../src/channel-example/get-all-channel-messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAIhH,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,qBAAqB,CAAA;CAC/B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAChC,WAAW,gBAAgB,EAC3B,SAAS,qBAAqB,KAC7B,mBAAmB,EAWrB,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { objectEntries } from '@scalar/helpers/object/object-entries';
2
+ import { getResolvedRef } from '../helpers/get-resolved-ref.js';
3
+ /**
4
+ * Resolves every message defined on a channel (AsyncAPI data store for payloads).
5
+ */
6
+ export const getAllChannelMessages = (_document, channel) => {
7
+ if (!channel.messages) {
8
+ return [];
9
+ }
10
+ return objectEntries(channel.messages)
11
+ .map(([name, messageRef]) => {
12
+ const message = getResolvedRef(messageRef);
13
+ return { name, message };
14
+ })
15
+ .filter((entry) => entry.message != null);
16
+ };
@@ -0,0 +1,7 @@
1
+ import type { AsyncApiDocument, AsyncApiOperationObject, AsyncApiServerObject } from '@scalar/types/asyncapi/3.1';
2
+ import type { SecurityRequirementObject } from '../schemas/v3.1/strict/security-requirement.js';
3
+ /**
4
+ * Converts AsyncAPI security arrays (operation, traits, server) into OpenAPI-style requirement objects.
5
+ */
6
+ export declare const getAsyncApiSecurityRequirements: (document: AsyncApiDocument, operation?: AsyncApiOperationObject | null, server?: AsyncApiServerObject | null) => SecurityRequirementObject[];
7
+ //# sourceMappingURL=get-asyncapi-security-requirements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-asyncapi-security-requirements.d.ts","sourceRoot":"","sources":["../../src/channel-example/get-asyncapi-security-requirements.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EAEvB,oBAAoB,EACrB,MAAM,4BAA4B,CAAA;AAInC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAA;AA6E3F;;GAEG;AACH,eAAO,MAAM,+BAA+B,GAC1C,UAAU,gBAAgB,EAC1B,YAAY,uBAAuB,GAAG,IAAI,EAC1C,SAAS,oBAAoB,GAAG,IAAI,KACnC,yBAAyB,EAqB3B,CAAA"}
@@ -0,0 +1,76 @@
1
+ import { isObjectEqual } from '@scalar/helpers/object/is-object-equal';
2
+ import { getNameFromRef } from '../helpers/get-name-from-ref.js';
3
+ import { getResolvedRef } from '../helpers/get-resolved-ref.js';
4
+ const getSecuritySchemeNameFromRef = (ref) => getNameFromRef(ref, ['components', 'securitySchemes']);
5
+ /** Strips requirement-only `scopes` so inline entries can match component scheme definitions. */
6
+ const getSecuritySchemeDefinition = (entry) => {
7
+ const resolved = getResolvedRef(entry);
8
+ if (resolved == null) {
9
+ return undefined;
10
+ }
11
+ if (!('scopes' in resolved)) {
12
+ return resolved;
13
+ }
14
+ const { scopes: _scopes, ...scheme } = resolved;
15
+ return scheme;
16
+ };
17
+ const getSecuritySchemeName = (document, entry) => {
18
+ if ('$ref' in entry) {
19
+ const nameFromRef = getSecuritySchemeNameFromRef(entry.$ref);
20
+ if (nameFromRef) {
21
+ return nameFromRef;
22
+ }
23
+ }
24
+ const resolvedDefinition = getSecuritySchemeDefinition(entry);
25
+ if (resolvedDefinition == null) {
26
+ return undefined;
27
+ }
28
+ const components = document.components ? getResolvedRef(document.components) : undefined;
29
+ if (components?.securitySchemes) {
30
+ for (const [name, schemeRef] of Object.entries(components.securitySchemes)) {
31
+ const scheme = getResolvedRef(schemeRef);
32
+ if (scheme === resolvedDefinition || isObjectEqual(scheme, resolvedDefinition)) {
33
+ return name;
34
+ }
35
+ }
36
+ }
37
+ return undefined;
38
+ };
39
+ const securityEntryToRequirement = (document, entry) => {
40
+ const schemeName = getSecuritySchemeName(document, entry);
41
+ if (!schemeName) {
42
+ return undefined;
43
+ }
44
+ const resolved = getResolvedRef(entry);
45
+ const scopes = resolved != null && 'scopes' in resolved && Array.isArray(resolved.scopes) ? [...resolved.scopes] : [];
46
+ return { [schemeName]: scopes };
47
+ };
48
+ const collectSecurityRequirements = (document, security) => {
49
+ if (!security?.length) {
50
+ return [];
51
+ }
52
+ return security
53
+ .map((entry) => securityEntryToRequirement(document, entry))
54
+ .filter((requirement) => requirement != null);
55
+ };
56
+ /**
57
+ * Converts AsyncAPI security arrays (operation, traits, server) into OpenAPI-style requirement objects.
58
+ */
59
+ export const getAsyncApiSecurityRequirements = (document, operation, server) => {
60
+ const operationRequirements = collectSecurityRequirements(document, operation?.security);
61
+ const serverRequirements = collectSecurityRequirements(document, server?.security);
62
+ const combined = operationRequirements.length === 0
63
+ ? serverRequirements
64
+ : serverRequirements.length === 0
65
+ ? operationRequirements
66
+ : [...operationRequirements, ...serverRequirements];
67
+ const seen = new Set();
68
+ return combined.filter((requirement) => {
69
+ const key = JSON.stringify(requirement);
70
+ if (seen.has(key)) {
71
+ return false;
72
+ }
73
+ seen.add(key);
74
+ return true;
75
+ });
76
+ };
@@ -0,0 +1,16 @@
1
+ import type { AuthenticationConfiguration } from '@scalar/types/api-reference';
2
+ import type { BuildChannelConnectionContext, ChannelConnectionMeta } from '../channel-example/types.js';
3
+ import type { WorkspaceStore } from '../client.js';
4
+ import type { Result } from '../request-example/types.js';
5
+ import type { WorkspaceDocument } from '../schemas/workspace.js';
6
+ /**
7
+ * Builds context for testing a WebSocket channel (Postman-style): one connection per channel,
8
+ * with AsyncAPI messages, servers, and parameters as the data store.
9
+ */
10
+ export declare const getChannelConnectionContext: (workspaceStore: WorkspaceStore, documentName: string, channelConnectionMeta: ChannelConnectionMeta, options?: Partial<{
11
+ pathParameters: Record<string, string>;
12
+ queryParameters: Record<string, string>;
13
+ authentication: AuthenticationConfiguration;
14
+ fallbackDocument: WorkspaceDocument | null;
15
+ }>) => Result<BuildChannelConnectionContext>;
16
+ //# sourceMappingURL=get-channel-connection-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-channel-connection-context.d.ts","sourceRoot":"","sources":["../../src/channel-example/get-channel-connection-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAA;AAS9E,OAAO,KAAK,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AACnG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAQ9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAK5D;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GACtC,gBAAgB,cAAc,EAC9B,cAAc,MAAM,EACpB,uBAAuB,qBAAqB,EAC5C,UAAS,OAAO,CAAC;IACf,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACtC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvC,cAAc,EAAE,2BAA2B,CAAA;IAC3C,gBAAgB,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAC3C,CAAM,KACN,MAAM,CAAC,6BAA6B,CAwItC,CAAA"}
@@ -0,0 +1,120 @@
1
+ import { buildConnectionUrl } from '../channel-example/build-connection-url.js';
2
+ import { getAllChannelMessages } from '../channel-example/get-all-channel-messages.js';
3
+ import { getChannelConnectionSecurityRequirements } from '../channel-example/get-channel-connection-security.js';
4
+ import { getChannelOperations } from '../channel-example/get-channel-operations.js';
5
+ import { getChannelParameters } from '../channel-example/get-channel-parameters.js';
6
+ import { resolveChannel } from '../channel-example/resolve-channel.js';
7
+ import { getAsyncApiServers, getSelectedAsyncApiServer } from '../channel-example/servers.js';
8
+ import { getResolvedRef } from '../helpers/get-resolved-ref.js';
9
+ import { getEnvironmentVariables } from '../request-example/builder/helpers/get-environment-variables.js';
10
+ import { getActiveEnvironment } from '../request-example/context/environment.js';
11
+ import { getSecuritySchemes } from '../request-example/context/security/get-security-schemes.js';
12
+ import { getSelectedSecurity } from '../request-example/context/security/get-selected-security.js';
13
+ import { mergeSecurity } from '../request-example/context/security/merge-security.js';
14
+ import { isAsyncApiDocument } from '../schemas/type-guards.js';
15
+ /** Uses channel name as the auth path key for AsyncAPI channel connections. */
16
+ const ASYNCAPI_CHANNEL_AUTH_METHOD = 'get';
17
+ /**
18
+ * Builds context for testing a WebSocket channel (Postman-style): one connection per channel,
19
+ * with AsyncAPI messages, servers, and parameters as the data store.
20
+ */
21
+ export const getChannelConnectionContext = (workspaceStore, documentName, channelConnectionMeta, options = {}) => {
22
+ const { channelName } = channelConnectionMeta;
23
+ const document = workspaceStore.workspace.documents[documentName] ?? options.fallbackDocument ?? undefined;
24
+ if (!document) {
25
+ return {
26
+ ok: false,
27
+ error: `Document ${documentName} not found`,
28
+ };
29
+ }
30
+ if (!isAsyncApiDocument(document)) {
31
+ return {
32
+ ok: false,
33
+ error: `Document ${documentName} is not an AsyncAPI document`,
34
+ };
35
+ }
36
+ const resolvedChannel = resolveChannel(document, channelName);
37
+ if (!resolvedChannel) {
38
+ return {
39
+ ok: false,
40
+ error: `Channel ${channelName} not found`,
41
+ };
42
+ }
43
+ const { channel, channelAddress } = resolvedChannel;
44
+ const environment = getActiveEnvironment(workspaceStore, document);
45
+ const environmentVariables = getEnvironmentVariables(environment.environment);
46
+ const channelOperations = getChannelOperations(document, channelName);
47
+ const parameters = getChannelParameters(channel, null, {
48
+ path: options.pathParameters,
49
+ query: options.queryParameters,
50
+ });
51
+ const servers = getAsyncApiServers(document, {
52
+ channel,
53
+ operation: null,
54
+ pathParameters: parameters.path,
55
+ queryParameters: parameters.query,
56
+ environmentVariables,
57
+ });
58
+ const selectedServer = getSelectedAsyncApiServer(document, servers, null);
59
+ const serverForUrl = selectedServer?.server ?? servers[0]?.server;
60
+ if (!serverForUrl) {
61
+ return {
62
+ ok: false,
63
+ error: `No WebSocket servers available for channel ${channelName}`,
64
+ };
65
+ }
66
+ const connectionUrl = selectedServer?.connectionUrl ??
67
+ buildConnectionUrl({
68
+ server: serverForUrl,
69
+ channel,
70
+ operation: null,
71
+ pathParameters: parameters.path,
72
+ queryParameters: parameters.query,
73
+ environmentVariables,
74
+ });
75
+ const messages = getAllChannelMessages(document, channel);
76
+ const selectedMessage = messages[0] ?? null;
77
+ const documentSelectedSecurity = workspaceStore.auth.getAuthSelectedSchemas({
78
+ type: 'document',
79
+ documentName,
80
+ });
81
+ const channelSelectedSecurity = workspaceStore.auth.getAuthSelectedSchemas({
82
+ type: 'operation',
83
+ documentName,
84
+ path: channelName,
85
+ method: ASYNCAPI_CHANNEL_AUTH_METHOD,
86
+ });
87
+ const components = document.components ? getResolvedRef(document.components) : undefined;
88
+ const securitySchemes = mergeSecurity((components?.securitySchemes ?? {}), options.authentication?.securitySchemes ?? {}, workspaceStore.auth, documentName);
89
+ const securityRequirements = getChannelConnectionSecurityRequirements(document, channel, selectedServer?.server ?? null, channelOperations);
90
+ const selectedSecurity = getSelectedSecurity(documentSelectedSecurity, channelSelectedSecurity, securityRequirements, securitySchemes, options.authentication?.preferredSecurityScheme);
91
+ const selectedSecuritySchemes = getSecuritySchemes(securitySchemes, selectedSecurity.selectedSchemes[selectedSecurity.selectedIndex] ?? {});
92
+ const authMeta = channelSelectedSecurity
93
+ ? { type: 'operation', path: channelName, method: ASYNCAPI_CHANNEL_AUTH_METHOD }
94
+ : { type: 'document' };
95
+ return {
96
+ ok: true,
97
+ data: {
98
+ channel,
99
+ channelName,
100
+ channelAddress,
101
+ operations: channelOperations,
102
+ messages,
103
+ selectedMessage,
104
+ servers: {
105
+ list: servers,
106
+ selected: selectedServer,
107
+ },
108
+ connectionUrl,
109
+ parameters,
110
+ security: {
111
+ schemes: securitySchemes,
112
+ requirements: securityRequirements,
113
+ selected: selectedSecurity,
114
+ selectedSchemes: selectedSecuritySchemes,
115
+ meta: authMeta,
116
+ },
117
+ environment,
118
+ },
119
+ };
120
+ };
@@ -0,0 +1,8 @@
1
+ import type { AsyncApiChannelObject, AsyncApiDocument, AsyncApiServerObject } from '@scalar/types/asyncapi/3.1';
2
+ import type { SecurityRequirementObject } from '../schemas/v3.1/strict/security-requirement.js';
3
+ import type { ChannelOperationSummary } from './get-channel-operations.js';
4
+ /**
5
+ * Merges security requirements from the selected server and all operations on a channel.
6
+ */
7
+ export declare const getChannelConnectionSecurityRequirements: (document: AsyncApiDocument, _channel: AsyncApiChannelObject, server: AsyncApiServerObject | null, channelOperations: ChannelOperationSummary[]) => SecurityRequirementObject[];
8
+ //# sourceMappingURL=get-channel-connection-security.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-channel-connection-security.d.ts","sourceRoot":"","sources":["../../src/channel-example/get-channel-connection-security.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAG/G,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAA;AAE3F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAevE;;GAEG;AACH,eAAO,MAAM,wCAAwC,GACnD,UAAU,gBAAgB,EAC1B,UAAU,qBAAqB,EAC/B,QAAQ,oBAAoB,GAAG,IAAI,EACnC,mBAAmB,uBAAuB,EAAE,KAC3C,yBAAyB,EAQ3B,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { getAsyncApiSecurityRequirements } from '../channel-example/get-asyncapi-security-requirements.js';
2
+ const dedupeRequirements = (requirements) => {
3
+ const seen = new Set();
4
+ return requirements.filter((requirement) => {
5
+ const key = JSON.stringify(requirement);
6
+ if (seen.has(key)) {
7
+ return false;
8
+ }
9
+ seen.add(key);
10
+ return true;
11
+ });
12
+ };
13
+ /**
14
+ * Merges security requirements from the selected server and all operations on a channel.
15
+ */
16
+ export const getChannelConnectionSecurityRequirements = (document, _channel, server, channelOperations) => {
17
+ const serverRequirements = getAsyncApiSecurityRequirements(document, null, server);
18
+ const operationRequirements = channelOperations.flatMap(({ operation }) => getAsyncApiSecurityRequirements(document, operation, null));
19
+ return dedupeRequirements([...serverRequirements, ...operationRequirements]);
20
+ };
@@ -0,0 +1,11 @@
1
+ import type { AsyncApiDocument, AsyncApiOperationObject } from '@scalar/types/asyncapi/3.1';
2
+ export type ChannelOperationSummary = {
3
+ operationName: string;
4
+ operation: AsyncApiOperationObject;
5
+ action: 'send' | 'receive';
6
+ };
7
+ /**
8
+ * Lists AsyncAPI operations that target a given channel (for reference in the channel connection UI).
9
+ */
10
+ export declare const getChannelOperations: (document: AsyncApiDocument, channelName: string) => ChannelOperationSummary[];
11
+ //# sourceMappingURL=get-channel-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-channel-operations.d.ts","sourceRoot":"","sources":["../../src/channel-example/get-channel-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AAO3F,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,uBAAuB,CAAA;IAClC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;CAC3B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,UAAU,gBAAgB,EAAE,aAAa,MAAM,KAAG,uBAAuB,EAgB7G,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { getResolvedRef } from '../helpers/get-resolved-ref.js';
2
+ import { resolveOperationChannel } from './resolve-operation-channel.js';
3
+ import { resolveOperationWithTraits } from './resolve-operation-with-traits.js';
4
+ /**
5
+ * Lists AsyncAPI operations that target a given channel (for reference in the channel connection UI).
6
+ */
7
+ export const getChannelOperations = (document, channelName) => {
8
+ const operations = document.operations ?? {};
9
+ return Object.entries(operations)
10
+ .map(([operationName, operationRef]) => {
11
+ const operation = resolveOperationWithTraits(getResolvedRef(operationRef));
12
+ const resolved = resolveOperationChannel(document, operation);
13
+ if (resolved?.channelName !== channelName) {
14
+ return undefined;
15
+ }
16
+ const action = operation.action === 'send' ? 'send' : 'receive';
17
+ return { operationName, operation, action };
18
+ })
19
+ .filter((entry) => entry != null);
20
+ };
@@ -0,0 +1,14 @@
1
+ import type { AsyncApiChannelObject, AsyncApiOperationObject, AsyncApiParameterObject } from '@scalar/types/asyncapi/3.1';
2
+ export type ChannelParametersContext = {
3
+ /** Resolved channel parameter definitions keyed by name. */
4
+ definitions: Record<string, AsyncApiParameterObject>;
5
+ /** Values substituted into the channel address path segments. */
6
+ path: Record<string, string>;
7
+ /** Values substituted into WebSocket handshake query parameters. */
8
+ query: Record<string, string>;
9
+ };
10
+ /**
11
+ * Builds default path and query parameter values from channel definitions and ws bindings.
12
+ */
13
+ export declare const getChannelParameters: (channel: AsyncApiChannelObject, operation?: AsyncApiOperationObject | null, overrides?: Partial<Pick<ChannelParametersContext, "path" | "query">>) => ChannelParametersContext;
14
+ //# sourceMappingURL=get-channel-parameters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-channel-parameters.d.ts","sourceRoot":"","sources":["../../src/channel-example/get-channel-parameters.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,4BAA4B,CAAA;AAKnC,MAAM,MAAM,wBAAwB,GAAG;IACrC,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAA;IACpD,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC9B,CAAA;AA+BD;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAC/B,SAAS,qBAAqB,EAC9B,YAAY,uBAAuB,GAAG,IAAI,EAC1C,YAAW,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,MAAM,GAAG,OAAO,CAAC,CAAM,KACxE,wBAgCF,CAAA"}