@scalar/workspace-store 0.51.2 → 0.52.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 (34) hide show
  1. package/CHANGELOG.md +11 -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 +181 -0
  5. package/dist/channel-example/index.d.ts +5 -0
  6. package/dist/channel-example/index.d.ts.map +1 -0
  7. package/dist/channel-example/index.js +2 -0
  8. package/dist/channel-example/servers.d.ts +36 -0
  9. package/dist/channel-example/servers.d.ts.map +1 -0
  10. package/dist/channel-example/servers.js +54 -0
  11. package/dist/entities/auth/schema.d.ts +60 -0
  12. package/dist/entities/auth/schema.d.ts.map +1 -1
  13. package/dist/events/definitions/log.d.ts +6 -0
  14. package/dist/events/definitions/log.d.ts.map +1 -1
  15. package/dist/request-example/builder/helpers/get-example-from-schema.d.ts.map +1 -1
  16. package/dist/request-example/builder/helpers/get-example-from-schema.js +33 -2
  17. package/dist/schemas/extensions/schema/x-order.d.ts +22 -0
  18. package/dist/schemas/extensions/schema/x-order.d.ts.map +1 -0
  19. package/dist/schemas/extensions/schema/x-order.js +17 -0
  20. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts +4 -1
  21. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts.map +1 -1
  22. package/dist/schemas/extensions/server/x-scalar-selected-server.js +4 -2
  23. package/dist/schemas/reference-config/index.d.ts +12 -0
  24. package/dist/schemas/reference-config/index.d.ts.map +1 -1
  25. package/dist/schemas/reference-config/settings.d.ts +12 -0
  26. package/dist/schemas/reference-config/settings.d.ts.map +1 -1
  27. package/dist/schemas/v3.1/openapi/index.d.ts.map +1 -1
  28. package/dist/schemas/v3.1/openapi/index.js +2 -0
  29. package/dist/schemas/v3.1/strict/openapi-document.d.ts +420 -0
  30. package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
  31. package/dist/schemas/v3.1/strict/schema.d.ts +16 -1
  32. package/dist/schemas/v3.1/strict/schema.d.ts.map +1 -1
  33. package/dist/schemas/v3.1/strict/schema.js +2 -1
  34. package/package.json +11 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @scalar/workspace-store
2
2
 
3
+ ## 0.52.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#9313](https://github.com/scalar/scalar/pull/9313): feat: add AsyncAPI connection URL builder and server list helpers
8
+
9
+ ### Patch Changes
10
+
11
+ - [#9334](https://github.com/scalar/scalar/pull/9334): Add analytics events for document save and registry sync (pull/push) actions
12
+ - [#9333](https://github.com/scalar/scalar/pull/9333): feat: respect the `x-order` extension when building schema examples
13
+
3
14
  ## 0.51.2
4
15
 
5
16
  ## 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;AAuFD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC7B,WAAW,uBAAuB,GAAG,SAAS,EAC9C,kBAAkB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACvC,eAmBF,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAAI,wFAOhC,uBAAuB,KAAG,MAkB5B,CAAA"}
@@ -0,0 +1,181 @@
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
+ const channelProperties = isObject(channelSchema.properties) ? channelSchema.properties : {};
96
+ const operationProperties = isObject(operationSchema.properties) ? operationSchema.properties : {};
97
+ return {
98
+ ...channelSchema,
99
+ ...operationSchema,
100
+ properties: {
101
+ ...channelProperties,
102
+ ...operationProperties,
103
+ },
104
+ };
105
+ };
106
+ const getDefaultValueFromPropertySchema = (propertySchema) => {
107
+ if (propertySchema === true || propertySchema === false || !isObject(propertySchema)) {
108
+ return undefined;
109
+ }
110
+ if ('default' in propertySchema && propertySchema.default !== undefined) {
111
+ return propertySchema.default;
112
+ }
113
+ if ('example' in propertySchema && propertySchema.example !== undefined) {
114
+ return propertySchema.example;
115
+ }
116
+ if ('enum' in propertySchema && Array.isArray(propertySchema.enum) && propertySchema.enum[0] !== undefined) {
117
+ return propertySchema.enum[0];
118
+ }
119
+ return undefined;
120
+ };
121
+ const appendQueryValue = (params, key, value) => {
122
+ if (value === undefined || value === null) {
123
+ return;
124
+ }
125
+ if (Array.isArray(value)) {
126
+ value.forEach((entry) => appendQueryValue(params, key, entry));
127
+ return;
128
+ }
129
+ if (typeof value === 'object') {
130
+ params.append(key, JSON.stringify(value));
131
+ return;
132
+ }
133
+ params.append(key, String(value));
134
+ };
135
+ /**
136
+ * Builds handshake query parameters from merged `bindings.ws.query` schema defaults,
137
+ * then applies explicit overrides.
138
+ */
139
+ export const buildWsQueryParams = (wsBinding, queryParameters) => {
140
+ const params = new URLSearchParams();
141
+ const querySchema = resolveWsQuerySchema(wsBinding?.query);
142
+ if (querySchema && isObject(querySchema.properties)) {
143
+ for (const [name, propertySchema] of objectEntries(querySchema.properties)) {
144
+ const defaultValue = getDefaultValueFromPropertySchema(propertySchema);
145
+ appendQueryValue(params, name, defaultValue);
146
+ }
147
+ }
148
+ if (queryParameters) {
149
+ for (const [name, value] of objectEntries(queryParameters)) {
150
+ params.delete(name);
151
+ appendQueryValue(params, name, value);
152
+ }
153
+ }
154
+ return params;
155
+ };
156
+ /**
157
+ * Builds a WebSocket connection URL from a resolved server, channel, and optional operation.
158
+ *
159
+ * Composition (AsyncAPI 3.x):
160
+ * 1. `server.protocol` → URL scheme
161
+ * 2. `server.host` (+ variables and environment substitution)
162
+ * 3. Optional `server.pathname`
163
+ * 4. Channel `address` (+ path parameter substitution)
164
+ * 5. Query string from merged `bindings.ws.query` (channel + operation) with schema defaults
165
+ */
166
+ export const buildConnectionUrl = ({ server, channel, operation = null, pathParameters = {}, queryParameters = {}, environmentVariables, }) => {
167
+ const serverVariables = getAsyncApiServerVariables(server);
168
+ const baseUrl = buildAsyncApiServerBaseUrl(server, environmentVariables);
169
+ const address = channel.address;
170
+ if (address == null || address === '') {
171
+ const queryParams = buildWsQueryParams(mergeWsBindings(channel, operation), queryParameters);
172
+ return mergeUrls(baseUrl, '', queryParams, true);
173
+ }
174
+ const resolvedAddress = substituteTemplate(address, {
175
+ serverVariables,
176
+ environmentVariables,
177
+ pathParameters,
178
+ });
179
+ const queryParams = buildWsQueryParams(mergeWsBindings(channel, operation), queryParameters);
180
+ return mergeUrls(baseUrl, resolvedAddress, queryParams, true);
181
+ };
@@ -0,0 +1,5 @@
1
+ export type { AsyncApiWebSocketProtocol, BuildConnectionUrlInput } from './build-connection-url.js';
2
+ export { ASYNCAPI_WEBSOCKET_PROTOCOLS, buildAsyncApiServerBaseUrl, buildConnectionUrl, buildWsQueryParams, getAsyncApiServerVariables, getUrlSchemeFromProtocol, isWebSocketProtocol, mergeWsBindings, } from './build-connection-url.js';
3
+ export type { AsyncApiServerEntry, AsyncApiServerListOptions } from './servers.js';
4
+ export { getAsyncApiServers, getSelectedAsyncApiServer } from './servers.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/channel-example/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAChG,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,kBAAkB,EAClB,kBAAkB,EAClB,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,eAAe,GAChB,MAAM,wBAAwB,CAAA;AAC/B,YAAY,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAC/E,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { ASYNCAPI_WEBSOCKET_PROTOCOLS, buildAsyncApiServerBaseUrl, buildConnectionUrl, buildWsQueryParams, getAsyncApiServerVariables, getUrlSchemeFromProtocol, isWebSocketProtocol, mergeWsBindings, } from './build-connection-url.js';
2
+ export { getAsyncApiServers, getSelectedAsyncApiServer } from './servers.js';
@@ -0,0 +1,36 @@
1
+ import type { AsyncApiChannelObject, AsyncApiDocument, AsyncApiOperationObject, AsyncApiServerObject } from '@scalar/types/asyncapi/3.1';
2
+ import { type BuildConnectionUrlInput } from '../channel-example/build-connection-url.js';
3
+ import type { WorkspaceDocument } from '../schemas/workspace.js';
4
+ export type AsyncApiServerListOptions = {
5
+ channel?: AsyncApiChannelObject | null;
6
+ operation?: AsyncApiOperationObject | null;
7
+ pathParameters?: Record<string, string>;
8
+ queryParameters?: Record<string, string>;
9
+ environmentVariables?: BuildConnectionUrlInput['environmentVariables'];
10
+ /** When true (default), only servers with `ws` or `wss` protocol are returned. */
11
+ webSocketOnly?: boolean;
12
+ };
13
+ export type AsyncApiServerEntry = {
14
+ /** Key in `document.servers`. */
15
+ name: string;
16
+ server: AsyncApiServerObject;
17
+ host: string;
18
+ protocol: string;
19
+ description?: string;
20
+ title?: string;
21
+ /** Base URL (scheme + host + pathname) without the channel address. */
22
+ url: string;
23
+ /** Full WebSocket URL when `channel` is provided in list options. */
24
+ connectionUrl?: string;
25
+ /** Whether this server uses a WebSocket protocol (`ws` / `wss`). */
26
+ isWebSocket: boolean;
27
+ };
28
+ /**
29
+ * Returns a normalized list of AsyncAPI servers with computed base `url` and optional `connectionUrl`.
30
+ */
31
+ export declare const getAsyncApiServers: (document: AsyncApiDocument, options?: AsyncApiServerListOptions) => AsyncApiServerEntry[];
32
+ /**
33
+ * Returns the selected AsyncAPI server entry, using `x-scalar-selected-asyncapi-server` on the document.
34
+ */
35
+ export declare const getSelectedAsyncApiServer: (document: WorkspaceDocument | null, servers: AsyncApiServerEntry[], _operation?: AsyncApiOperationObject | null) => AsyncApiServerEntry | null;
36
+ //# sourceMappingURL=servers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"servers.d.ts","sourceRoot":"","sources":["../../src/channel-example/servers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EACL,KAAK,uBAAuB,EAI7B,MAAM,wCAAwC,CAAA;AAG/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE5D,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACtC,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,uBAAuB,CAAC,sBAAsB,CAAC,CAAA;IACtE,kFAAkF;IAClF,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,oBAAoB,CAAA;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAA;IACX,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,oEAAoE;IACpE,WAAW,EAAE,OAAO,CAAA;CACrB,CAAA;AAKD;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAC7B,UAAU,gBAAgB,EAC1B,UAAS,yBAA8B,KACtC,mBAAmB,EA4CrB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB,GACpC,UAAU,iBAAiB,GAAG,IAAI,EAClC,SAAS,mBAAmB,EAAE,EAC9B,aAAa,uBAAuB,GAAG,IAAI,KAC1C,mBAAmB,GAAG,IAYxB,CAAA"}
@@ -0,0 +1,54 @@
1
+ import { objectEntries } from '@scalar/helpers/object/object-entries';
2
+ import { buildAsyncApiServerBaseUrl, buildConnectionUrl, isWebSocketProtocol, } from '../channel-example/build-connection-url.js';
3
+ import { getResolvedRef } from '../helpers/get-resolved-ref.js';
4
+ import { isAsyncApiDocument } from '../schemas/type-guards.js';
5
+ const resolveServer = (server) => getResolvedRef(server);
6
+ /**
7
+ * Returns a normalized list of AsyncAPI servers with computed base `url` and optional `connectionUrl`.
8
+ */
9
+ export const getAsyncApiServers = (document, options = {}) => {
10
+ const { channel = null, operation = null, pathParameters = {}, queryParameters = {}, environmentVariables, webSocketOnly = true, } = options;
11
+ const servers = document.servers ?? {};
12
+ return objectEntries(servers)
13
+ .map(([name, serverRef]) => {
14
+ const server = resolveServer(serverRef);
15
+ const protocol = server.protocol.trim().toLowerCase();
16
+ const isWebSocket = isWebSocketProtocol(protocol);
17
+ const url = buildAsyncApiServerBaseUrl(server, environmentVariables);
18
+ const entry = {
19
+ name,
20
+ server,
21
+ host: server.host,
22
+ protocol,
23
+ description: server.description,
24
+ title: server.title,
25
+ url,
26
+ isWebSocket,
27
+ };
28
+ if (channel) {
29
+ entry.connectionUrl = buildConnectionUrl({
30
+ server,
31
+ channel,
32
+ operation,
33
+ pathParameters,
34
+ queryParameters,
35
+ environmentVariables,
36
+ });
37
+ }
38
+ return entry;
39
+ })
40
+ .filter((entry) => (webSocketOnly ? entry.isWebSocket : true));
41
+ };
42
+ /**
43
+ * Returns the selected AsyncAPI server entry, using `x-scalar-selected-asyncapi-server` on the document.
44
+ */
45
+ export const getSelectedAsyncApiServer = (document, servers, _operation) => {
46
+ if (!isAsyncApiDocument(document)) {
47
+ return servers[0] ?? null;
48
+ }
49
+ const selectedName = document['x-scalar-selected-server'];
50
+ if (selectedName == null) {
51
+ return servers[0] ?? null;
52
+ }
53
+ return servers.find(({ name }) => name === selectedName) ?? servers[0] ?? null;
54
+ };