@scalar/workspace-store 0.18.1 → 0.20.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 (110) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +1 -1
  4. package/dist/client.js.map +2 -2
  5. package/dist/events/definitions/auth.d.ts +77 -14
  6. package/dist/events/definitions/auth.d.ts.map +1 -1
  7. package/dist/events/definitions/document.d.ts +5 -1
  8. package/dist/events/definitions/document.d.ts.map +1 -1
  9. package/dist/events/definitions/index.d.ts +1 -2
  10. package/dist/events/definitions/index.d.ts.map +1 -1
  11. package/dist/events/definitions/operation.d.ts +200 -0
  12. package/dist/events/definitions/operation.d.ts.map +1 -1
  13. package/dist/events/definitions/server.d.ts +20 -28
  14. package/dist/events/definitions/server.d.ts.map +1 -1
  15. package/dist/events/definitions/ui.d.ts +5 -0
  16. package/dist/events/definitions/ui.d.ts.map +1 -1
  17. package/dist/events/index.d.ts +2 -2
  18. package/dist/events/index.d.ts.map +1 -1
  19. package/dist/events/index.js.map +2 -2
  20. package/dist/helpers/generate-unique-value.d.ts +40 -0
  21. package/dist/helpers/generate-unique-value.d.ts.map +1 -0
  22. package/dist/helpers/generate-unique-value.js +42 -0
  23. package/dist/helpers/generate-unique-value.js.map +7 -0
  24. package/dist/helpers/overrides-proxy.d.ts.map +1 -1
  25. package/dist/helpers/overrides-proxy.js +1 -1
  26. package/dist/helpers/overrides-proxy.js.map +2 -2
  27. package/dist/helpers/unpack-proxy.d.ts +1 -1
  28. package/dist/helpers/unpack-proxy.d.ts.map +1 -1
  29. package/dist/helpers/unpack-proxy.js.map +2 -2
  30. package/dist/mutators/auth.d.ts +147 -0
  31. package/dist/mutators/auth.d.ts.map +1 -0
  32. package/dist/mutators/auth.js +156 -0
  33. package/dist/mutators/auth.js.map +7 -0
  34. package/dist/mutators/document.d.ts +6 -0
  35. package/dist/mutators/document.d.ts.map +1 -0
  36. package/dist/mutators/document.js +10 -0
  37. package/dist/mutators/document.js.map +7 -0
  38. package/dist/mutators/index.d.ts +12 -7
  39. package/dist/mutators/index.d.ts.map +1 -1
  40. package/dist/mutators/index.js +74 -1
  41. package/dist/mutators/index.js.map +3 -3
  42. package/dist/mutators/operation.d.ts +313 -0
  43. package/dist/mutators/operation.d.ts.map +1 -0
  44. package/dist/mutators/operation.js +340 -0
  45. package/dist/mutators/operation.js.map +7 -0
  46. package/dist/mutators/server.d.ts +43 -8
  47. package/dist/mutators/server.d.ts.map +1 -1
  48. package/dist/mutators/server.js +112 -20
  49. package/dist/mutators/server.js.map +2 -2
  50. package/dist/navigation/helpers/traverse-document.d.ts +1 -0
  51. package/dist/navigation/helpers/traverse-document.d.ts.map +1 -1
  52. package/dist/navigation/helpers/traverse-document.js +2 -1
  53. package/dist/navigation/helpers/traverse-document.js.map +2 -2
  54. package/dist/plugins/client/persistence.d.ts +2 -1
  55. package/dist/plugins/client/persistence.d.ts.map +1 -1
  56. package/dist/plugins/client/persistence.js +11 -9
  57. package/dist/plugins/client/persistence.js.map +2 -2
  58. package/dist/schemas/extensions/document/x-scalar-document-security.d.ts +13 -0
  59. package/dist/schemas/extensions/document/x-scalar-document-security.d.ts.map +1 -0
  60. package/dist/schemas/extensions/document/x-scalar-document-security.js +8 -0
  61. package/dist/schemas/extensions/document/x-scalar-document-security.js.map +7 -0
  62. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.d.ts +13 -0
  63. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.d.ts.map +1 -0
  64. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.js +9 -0
  65. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.js.map +7 -0
  66. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.d.ts +21 -0
  67. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.d.ts.map +1 -0
  68. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js +8 -0
  69. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js.map +7 -0
  70. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts +17 -0
  71. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts.map +1 -0
  72. package/dist/schemas/extensions/security/x-scalar-selected-security.js +14 -0
  73. package/dist/schemas/extensions/security/x-scalar-selected-security.js.map +7 -0
  74. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts +8 -0
  75. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts.map +1 -0
  76. package/dist/schemas/extensions/server/x-scalar-selected-server.js +8 -0
  77. package/dist/schemas/extensions/server/x-scalar-selected-server.js.map +7 -0
  78. package/dist/schemas/inmemory-workspace.d.ts +44 -8
  79. package/dist/schemas/inmemory-workspace.d.ts.map +1 -1
  80. package/dist/schemas/navigation.d.ts +5 -0
  81. package/dist/schemas/navigation.d.ts.map +1 -1
  82. package/dist/schemas/navigation.js +1 -0
  83. package/dist/schemas/navigation.js.map +2 -2
  84. package/dist/schemas/reference-config/index.d.ts +22 -4
  85. package/dist/schemas/reference-config/index.d.ts.map +1 -1
  86. package/dist/schemas/reference-config/settings.d.ts +22 -4
  87. package/dist/schemas/reference-config/settings.d.ts.map +1 -1
  88. package/dist/schemas/v3.1/strict/openapi-document.d.ts +752 -138
  89. package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
  90. package/dist/schemas/v3.1/strict/openapi-document.js +12 -1
  91. package/dist/schemas/v3.1/strict/openapi-document.js.map +2 -2
  92. package/dist/schemas/v3.1/strict/operation.d.ts +10 -6
  93. package/dist/schemas/v3.1/strict/operation.d.ts.map +1 -1
  94. package/dist/schemas/v3.1/strict/operation.js +9 -7
  95. package/dist/schemas/v3.1/strict/operation.js.map +2 -2
  96. package/dist/schemas/v3.1/strict/request-body.d.ts +6 -3
  97. package/dist/schemas/v3.1/strict/request-body.d.ts.map +1 -1
  98. package/dist/schemas/v3.1/strict/request-body.js +15 -8
  99. package/dist/schemas/v3.1/strict/request-body.js.map +2 -2
  100. package/dist/schemas/workspace-specification/config.d.ts +22 -4
  101. package/dist/schemas/workspace-specification/config.d.ts.map +1 -1
  102. package/dist/schemas/workspace-specification/index.d.ts +22 -4
  103. package/dist/schemas/workspace-specification/index.d.ts.map +1 -1
  104. package/dist/schemas/workspace.d.ts +154 -28
  105. package/dist/schemas/workspace.d.ts.map +1 -1
  106. package/package.json +5 -5
  107. package/dist/helpers/debounce.d.ts +0 -28
  108. package/dist/helpers/debounce.d.ts.map +0 -1
  109. package/dist/helpers/debounce.js +0 -31
  110. package/dist/helpers/debounce.js.map +0 -7
@@ -0,0 +1,147 @@
1
+ import type { HttpMethod } from '@scalar/helpers/http/http-methods';
2
+ import type { AuthEvents } from '../events/definitions/auth.js';
3
+ import type { WorkspaceDocument } from '../schemas.js';
4
+ /**
5
+ * AuthMeta defines the meta information needed to specify whether the authentication operation
6
+ * is being performed at the document level (entire API), or for a specific operation (specific path and method).
7
+ *
8
+ * - If type is 'document', the operation applies to the whole OpenAPI document.
9
+ * - If type is 'operation', it targets a specific operation, identified by its path and method.
10
+ */
11
+ export type AuthMeta = {
12
+ type: 'document';
13
+ } | {
14
+ type: 'operation';
15
+ path: string;
16
+ method: HttpMethod;
17
+ };
18
+ /**
19
+ * Updates the selected security schemes for either the entire document or a specific operation.
20
+ * - Adds newly created security schemes (if any) to the workspace document's components.
21
+ * - Ensures that each new scheme name is unique within the document by using `generateUniqueValue`.
22
+ * - Updates the `x-scalar-selected-security` property on the target (document or operation) to reflect the new set of selected security schemes.
23
+ * - Corrects and maintains the selected index so it points to a valid security scheme.
24
+ *
25
+ * @param document - The workspace OpenAPI document to mutate (can be null, in which case nothing happens)
26
+ * @param selectedSecuritySchemes - The current list of selected security scheme objects
27
+ * @param create - Array of new schemes to create, each with a name and a scheme definition
28
+ * @param meta - Location to update: whole document or a specific operation (`{ type: 'document' }` or `{ type: 'operation', path, method }`)
29
+ *
30
+ * Example usage:
31
+ * ```
32
+ * updateSelectedSecuritySchemes({
33
+ * document,
34
+ * selectedSecuritySchemes: [{ bearerAuth: [] }],
35
+ * create: [
36
+ * { name: 'ApiKeyAuth', scheme: { type: 'apiKey', in: 'header', name: 'X-API-Key' } }
37
+ * ],
38
+ * meta: { type: 'document' }
39
+ * })
40
+ * ```
41
+ */
42
+ export declare const updateSelectedSecuritySchemes: (document: WorkspaceDocument | null, { selectedRequirements, newSchemes, meta }: AuthEvents["auth:update:selected-security-schemes"]) => void;
43
+ /**
44
+ * Updates a security scheme in the OpenAPI document's components object.
45
+ * Handles updates for HTTP, API Key, and OAuth2 types, saving secret information and configuration for UI-auth flows.
46
+ *
47
+ * @param document - The OpenAPI workspace document (can be null)
48
+ * @param data - The update information, including type and payload
49
+ * @param name - The name of the security scheme in document.components.securitySchemes
50
+ *
51
+ * Example usage:
52
+ *
53
+ * updateSecurityScheme({
54
+ * document,
55
+ * data: {
56
+ * type: 'http',
57
+ * payload: {
58
+ * username: 'user123',
59
+ * password: 'pw123',
60
+ * token: 'tokenval'
61
+ * }
62
+ * },
63
+ * name: 'MyHttpAuth',
64
+ * })
65
+ */
66
+ export declare const updateSecurityScheme: (document: WorkspaceDocument | null, { payload, name }: AuthEvents["auth:update:security-scheme"]) => import("../schemas/v3.1/strict/security-scheme.js").ApiKeyObject | import("../schemas/v3.1/strict/security-scheme.js").HttpObject | import("../schemas/v3.1/strict/security-scheme.js").OAuth2Object | import("../schemas/v3.1/strict/security-scheme.js").OpenIdConnectObject | undefined;
67
+ /**
68
+ * Sets the selected authentication tab (scheme) index for the given OpenAPI document or operation.
69
+ * - When on the document level, updates the 'selectedIndex' on the document's x-scalar-selected-security extension.
70
+ * - When on an operation (endpoint) level, updates the 'selectedIndex' for that operation's x-scalar-selected-security.
71
+ *
72
+ * Also initializes the x-scalar-selected-security extension if it does not exist.
73
+ *
74
+ * @param document The OpenAPI document object (may be null)
75
+ * @param index The index to set as selected
76
+ * @param meta Context where the selection applies ('document' or specific operation)
77
+ *
78
+ * @example
79
+ * // Document-level tab selection
80
+ * updateSelectedAuthTab({
81
+ * document,
82
+ * index: 1,
83
+ * meta: { type: 'document' }
84
+ * });
85
+ *
86
+ * // Operation-level tab selection (e.g., GET /pets)
87
+ * updateSelectedAuthTab({
88
+ * document,
89
+ * index: 0,
90
+ * meta: { type: 'operation', path: '/pets', method: 'get' }
91
+ * });
92
+ */
93
+ export declare const updateSelectedAuthTab: (document: WorkspaceDocument | null, { index, meta }: AuthEvents["auth:update:active-index"]) => void;
94
+ /**
95
+ * Updates the scopes for a specific security requirement in the selected security schemes of
96
+ * a document or operation.
97
+ *
98
+ * @param document - The OpenAPI WorkspaceDocument to update.
99
+ * @param id - An array of scheme names that uniquely identifies the target security requirement.
100
+ * For example: ['OAuth', 'ApiKeyAuth']
101
+ * @param name - The security scheme name to update scopes for (e.g., 'OAuth').
102
+ * @param scopes - The new list of scopes to set. For example: ['read:pets', 'write:pets']
103
+ * @param meta - The context specifying whether the update is at the document-level or operation-level.
104
+ *
105
+ * Example usage:
106
+ * ```ts
107
+ * // Suppose your document (or operation) x-scalar-selected-security looks like:
108
+ * // "x-scalar-selected-security": {
109
+ * // selectedIndex: 0,
110
+ * // selectedSchemes: [
111
+ * // { "OAuth": ["read:pets"] },
112
+ * // { "ApiKeyAuth": [] }
113
+ * // ]
114
+ * // }
115
+ *
116
+ * updateSelectedScopes({
117
+ * document,
118
+ * id: ["OAuth"], // identifies the scheme object: { "OAuth": [...] }
119
+ * name: "OAuth", // scheme name to update within this security requirement
120
+ * scopes: ["write:pets"], // new scopes array
121
+ * meta: { type: "document" }
122
+ * })
123
+ * // After, the first scheme becomes: { "OAuth": ["write:pets"] }
124
+ * ```
125
+ */
126
+ export declare const updateSelectedScopes: (document: WorkspaceDocument | null, { id, name, scopes, meta }: AuthEvents["auth:update:selected-scopes"]) => void;
127
+ /**
128
+ * Deletes one or more security schemes from an OpenAPI WorkspaceDocument,
129
+ * and removes all references to those schemes from selected security, document-level security,
130
+ * and operation-level security/selected security (e.g., on paths).
131
+ *
132
+ * Example usage:
133
+ *
134
+ * ```ts
135
+ * deleteSecurityScheme({
136
+ * document, // The OpenAPI document to update
137
+ * names: ['ApiKeyAuth', 'BearerAuth'], // The names of security schemes you want to delete
138
+ * });
139
+ * ```
140
+ *
141
+ * After running this function:
142
+ * - The named security schemes are removed from the components.securitySchemes section.
143
+ * - All document-level and operation-level security entries referencing those schemes are removed.
144
+ * - Any extended x-scalar-selected-security references to those schemes are also removed.
145
+ */
146
+ export declare const deleteSecurityScheme: (document: WorkspaceDocument | null, { names }: AuthEvents["auth:delete:security-scheme"]) => void;
147
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/mutators/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAEnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAI3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAGlD;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAChB;IACE,IAAI,EAAE,UAAU,CAAA;CACjB,GACD;IACE,IAAI,EAAE,WAAW,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,UAAU,CAAA;CACnB,CAAA;AAEL;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,6BAA6B,GACxC,UAAU,iBAAiB,GAAG,IAAI,EAClC,4CAA4C,UAAU,CAAC,uCAAuC,CAAC,SA6EhG,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,iBAAiB,GAAG,IAAI,EAClC,mBAAmB,UAAU,CAAC,6BAA6B,CAAC,mRAc7D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,qBAAqB,GAChC,UAAU,iBAAiB,GAAG,IAAI,EAClC,iBAAiB,UAAU,CAAC,0BAA0B,CAAC,SA+BxD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,iBAAiB,GAAG,IAAI,EAClC,4BAA4B,UAAU,CAAC,6BAA6B,CAAC,SAqCtE,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,iBAAiB,GAAG,IAAI,EAClC,WAAW,UAAU,CAAC,6BAA6B,CAAC,SA6DrD,CAAA"}
@@ -0,0 +1,156 @@
1
+ import { generateUniqueValue } from "../helpers/generate-unique-value.js";
2
+ import { getResolvedRef } from "../helpers/get-resolved-ref.js";
3
+ import { mergeObjects } from "../helpers/merge-object.js";
4
+ const updateSelectedSecuritySchemes = (document, { selectedRequirements, newSchemes, meta }) => {
5
+ if (!document) {
6
+ return;
7
+ }
8
+ const getTarget = () => {
9
+ if (meta.type === "document") {
10
+ return document;
11
+ }
12
+ return getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
13
+ };
14
+ const createdSchemes = newSchemes.map((scheme) => {
15
+ const name = generateUniqueValue({
16
+ defaultValue: scheme.name,
17
+ validation: (value) => !document.components?.securitySchemes?.[value],
18
+ maxRetries: 100
19
+ });
20
+ if (!name) {
21
+ return;
22
+ }
23
+ if (!document.components) {
24
+ document.components = {};
25
+ }
26
+ if (!document.components.securitySchemes) {
27
+ document.components.securitySchemes = {};
28
+ }
29
+ document.components.securitySchemes[name] = scheme.scheme;
30
+ return {
31
+ [name]: []
32
+ };
33
+ }).filter(Boolean);
34
+ const target = getTarget();
35
+ const newSelectedSecuritySchemes = [...selectedRequirements, ...createdSchemes];
36
+ if (!target) {
37
+ return;
38
+ }
39
+ if (!target["x-scalar-selected-security"]) {
40
+ target["x-scalar-selected-security"] = {
41
+ selectedIndex: -1,
42
+ selectedSchemes: []
43
+ };
44
+ }
45
+ const selectedIndex = target["x-scalar-selected-security"].selectedIndex;
46
+ target["x-scalar-selected-security"].selectedSchemes = newSelectedSecuritySchemes;
47
+ if (newSelectedSecuritySchemes.length > 0 && selectedIndex < 0) {
48
+ target["x-scalar-selected-security"].selectedIndex = 0;
49
+ }
50
+ if (selectedIndex >= newSelectedSecuritySchemes.length) {
51
+ target["x-scalar-selected-security"].selectedIndex = newSelectedSecuritySchemes.length - 1;
52
+ }
53
+ };
54
+ const updateSecurityScheme = (document, { payload, name }) => {
55
+ const target = getResolvedRef(document?.components?.securitySchemes?.[name]);
56
+ if (!target) {
57
+ console.error(`Security scheme ${name} not found`);
58
+ return;
59
+ }
60
+ if (target.type === payload.type) {
61
+ mergeObjects(target, payload);
62
+ }
63
+ return target;
64
+ };
65
+ const updateSelectedAuthTab = (document, { index, meta }) => {
66
+ if (!document) {
67
+ return;
68
+ }
69
+ const getTarget = () => {
70
+ if (meta.type === "document") {
71
+ return document;
72
+ }
73
+ return getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
74
+ };
75
+ const target = getTarget();
76
+ if (!target) {
77
+ return;
78
+ }
79
+ if (!target["x-scalar-selected-security"]) {
80
+ target["x-scalar-selected-security"] = {
81
+ selectedIndex: 0,
82
+ selectedSchemes: []
83
+ };
84
+ }
85
+ target["x-scalar-selected-security"].selectedIndex = index;
86
+ };
87
+ const updateSelectedScopes = (document, { id, name, scopes, meta }) => {
88
+ if (!document) {
89
+ return;
90
+ }
91
+ const getTarget = () => {
92
+ if (meta.type === "document") {
93
+ return document;
94
+ }
95
+ return getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
96
+ };
97
+ const target = getTarget();
98
+ if (!target) {
99
+ return;
100
+ }
101
+ const selectedSchemes = target["x-scalar-selected-security"]?.selectedSchemes;
102
+ if (!selectedSchemes) {
103
+ return;
104
+ }
105
+ const scheme = selectedSchemes.find((scheme2) => JSON.stringify(Object.keys(scheme2)) === JSON.stringify(id));
106
+ if (!scheme) {
107
+ return;
108
+ }
109
+ scheme[name] = scopes;
110
+ };
111
+ const deleteSecurityScheme = (document, { names }) => {
112
+ if (!document) {
113
+ return;
114
+ }
115
+ const target = getResolvedRef(document.components?.securitySchemes);
116
+ if (!target) {
117
+ return;
118
+ }
119
+ names.forEach((name) => {
120
+ delete target[name];
121
+ });
122
+ const filterSecuritySchemes = (schemes) => {
123
+ return schemes.filter((scheme) => !names.some((name) => Object.keys(scheme).includes(name)));
124
+ };
125
+ if (document["x-scalar-selected-security"]) {
126
+ const selectedSecurity = document["x-scalar-selected-security"];
127
+ selectedSecurity.selectedSchemes = filterSecuritySchemes(selectedSecurity.selectedSchemes);
128
+ }
129
+ if (document["security"]) {
130
+ document["security"] = filterSecuritySchemes(document["security"]);
131
+ }
132
+ Object.values(document.paths ?? {}).forEach((path) => {
133
+ Object.values(path).forEach((operation) => {
134
+ if (typeof operation !== "object") {
135
+ return;
136
+ }
137
+ const resolvedOperation = getResolvedRef(operation);
138
+ if ("security" in resolvedOperation && resolvedOperation["security"]) {
139
+ resolvedOperation["security"] = filterSecuritySchemes(resolvedOperation["security"]);
140
+ }
141
+ if ("x-scalar-selected-security" in resolvedOperation && resolvedOperation["x-scalar-selected-security"]) {
142
+ resolvedOperation["x-scalar-selected-security"].selectedSchemes = filterSecuritySchemes(
143
+ resolvedOperation["x-scalar-selected-security"].selectedSchemes
144
+ );
145
+ }
146
+ });
147
+ });
148
+ };
149
+ export {
150
+ deleteSecurityScheme,
151
+ updateSecurityScheme,
152
+ updateSelectedAuthTab,
153
+ updateSelectedScopes,
154
+ updateSelectedSecuritySchemes
155
+ };
156
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/mutators/auth.ts"],
4
+ "sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\n\nimport type { AuthEvents } from '@/events/definitions/auth'\nimport { generateUniqueValue } from '@/helpers/generate-unique-value'\nimport { getResolvedRef } from '@/helpers/get-resolved-ref'\nimport { mergeObjects } from '@/helpers/merge-object'\nimport type { WorkspaceDocument } from '@/schemas'\nimport type { SecurityRequirementObject } from '@/schemas/v3.1/strict/security-requirement'\n\n/**\n * AuthMeta defines the meta information needed to specify whether the authentication operation\n * is being performed at the document level (entire API), or for a specific operation (specific path and method).\n *\n * - If type is 'document', the operation applies to the whole OpenAPI document.\n * - If type is 'operation', it targets a specific operation, identified by its path and method.\n */\nexport type AuthMeta =\n | {\n type: 'document'\n }\n | {\n type: 'operation'\n path: string\n method: HttpMethod\n }\n\n/**\n * Updates the selected security schemes for either the entire document or a specific operation.\n * - Adds newly created security schemes (if any) to the workspace document's components.\n * - Ensures that each new scheme name is unique within the document by using `generateUniqueValue`.\n * - Updates the `x-scalar-selected-security` property on the target (document or operation) to reflect the new set of selected security schemes.\n * - Corrects and maintains the selected index so it points to a valid security scheme.\n *\n * @param document - The workspace OpenAPI document to mutate (can be null, in which case nothing happens)\n * @param selectedSecuritySchemes - The current list of selected security scheme objects\n * @param create - Array of new schemes to create, each with a name and a scheme definition\n * @param meta - Location to update: whole document or a specific operation (`{ type: 'document' }` or `{ type: 'operation', path, method }`)\n *\n * Example usage:\n * ```\n * updateSelectedSecuritySchemes({\n * document,\n * selectedSecuritySchemes: [{ bearerAuth: [] }],\n * create: [\n * { name: 'ApiKeyAuth', scheme: { type: 'apiKey', in: 'header', name: 'X-API-Key' } }\n * ],\n * meta: { type: 'document' }\n * })\n * ```\n */\nexport const updateSelectedSecuritySchemes = (\n document: WorkspaceDocument | null,\n { selectedRequirements, newSchemes, meta }: AuthEvents['auth:update:selected-security-schemes'],\n) => {\n if (!document) {\n return\n }\n\n // Helper to get the target (whole document or a specific operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n // Create any new security schemes required, ensuring unique names for the components\n const createdSchemes = newSchemes\n .map((scheme) => {\n const name = generateUniqueValue({\n defaultValue: scheme.name,\n validation: (value) => !document.components?.securitySchemes?.[value],\n maxRetries: 100,\n })\n\n if (!name) {\n return\n }\n\n // Ensure components and securitySchemes exist\n if (!document.components) {\n document.components = {}\n }\n if (!document.components.securitySchemes) {\n document.components.securitySchemes = {}\n }\n\n // Add the new security scheme definition\n document.components.securitySchemes[name] = scheme.scheme\n\n // Return an OpenAPI Security Requirement Object for this new scheme (empty scope array)\n return {\n [name]: [],\n }\n })\n .filter(Boolean) as SecurityRequirementObject[]\n\n const target = getTarget()\n\n const newSelectedSecuritySchemes = [...selectedRequirements, ...createdSchemes]\n\n // If the target (document/operation) doesn't exist, do nothing\n if (!target) {\n return\n }\n\n // Ensure the x-scalar-selected-security structure exists on the target\n if (!target['x-scalar-selected-security']) {\n target['x-scalar-selected-security'] = {\n selectedIndex: -1,\n selectedSchemes: [],\n }\n }\n\n const selectedIndex = target['x-scalar-selected-security'].selectedIndex\n\n // Update the schemes array\n target['x-scalar-selected-security'].selectedSchemes = newSelectedSecuritySchemes\n\n // Adjust selected index if there are schemes and the index is unset/invalid\n if (newSelectedSecuritySchemes.length > 0 && selectedIndex < 0) {\n target['x-scalar-selected-security'].selectedIndex = 0\n }\n\n // If the selected index is now out of bounds, select the last available\n if (selectedIndex >= newSelectedSecuritySchemes.length) {\n target['x-scalar-selected-security'].selectedIndex = newSelectedSecuritySchemes.length - 1\n }\n}\n\n/**\n * Updates a security scheme in the OpenAPI document's components object.\n * Handles updates for HTTP, API Key, and OAuth2 types, saving secret information and configuration for UI-auth flows.\n *\n * @param document - The OpenAPI workspace document (can be null)\n * @param data - The update information, including type and payload\n * @param name - The name of the security scheme in document.components.securitySchemes\n *\n * Example usage:\n *\n * updateSecurityScheme({\n * document,\n * data: {\n * type: 'http',\n * payload: {\n * username: 'user123',\n * password: 'pw123',\n * token: 'tokenval'\n * }\n * },\n * name: 'MyHttpAuth',\n * })\n */\nexport const updateSecurityScheme = (\n document: WorkspaceDocument | null,\n { payload, name }: AuthEvents['auth:update:security-scheme'],\n) => {\n const target = getResolvedRef(document?.components?.securitySchemes?.[name])\n if (!target) {\n console.error(`Security scheme ${name} not found`)\n return\n }\n\n // Handle HTTP (basic, bearer, etc.)\n if (target.type === payload.type) {\n mergeObjects(target, payload)\n }\n\n return target\n}\n\n/**\n * Sets the selected authentication tab (scheme) index for the given OpenAPI document or operation.\n * - When on the document level, updates the 'selectedIndex' on the document's x-scalar-selected-security extension.\n * - When on an operation (endpoint) level, updates the 'selectedIndex' for that operation's x-scalar-selected-security.\n *\n * Also initializes the x-scalar-selected-security extension if it does not exist.\n *\n * @param document The OpenAPI document object (may be null)\n * @param index The index to set as selected\n * @param meta Context where the selection applies ('document' or specific operation)\n *\n * @example\n * // Document-level tab selection\n * updateSelectedAuthTab({\n * document,\n * index: 1,\n * meta: { type: 'document' }\n * });\n *\n * // Operation-level tab selection (e.g., GET /pets)\n * updateSelectedAuthTab({\n * document,\n * index: 0,\n * meta: { type: 'operation', path: '/pets', method: 'get' }\n * });\n */\nexport const updateSelectedAuthTab = (\n document: WorkspaceDocument | null,\n { index, meta }: AuthEvents['auth:update:active-index'],\n) => {\n if (!document) {\n return\n }\n\n // Determine the target object for setting the auth tab index:\n // - Document/root level\n // - Operation/endpoint level (if meta specifies operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n const target = getTarget()\n if (!target) {\n return\n }\n\n // Ensure the 'x-scalar-selected-security' extension exists\n if (!target['x-scalar-selected-security']) {\n target['x-scalar-selected-security'] = {\n selectedIndex: 0,\n selectedSchemes: [],\n }\n }\n\n // Set the selected auth tab index\n target['x-scalar-selected-security'].selectedIndex = index\n}\n\n/**\n * Updates the scopes for a specific security requirement in the selected security schemes of\n * a document or operation.\n *\n * @param document - The OpenAPI WorkspaceDocument to update.\n * @param id - An array of scheme names that uniquely identifies the target security requirement.\n * For example: ['OAuth', 'ApiKeyAuth']\n * @param name - The security scheme name to update scopes for (e.g., 'OAuth').\n * @param scopes - The new list of scopes to set. For example: ['read:pets', 'write:pets']\n * @param meta - The context specifying whether the update is at the document-level or operation-level.\n *\n * Example usage:\n * ```ts\n * // Suppose your document (or operation) x-scalar-selected-security looks like:\n * // \"x-scalar-selected-security\": {\n * // selectedIndex: 0,\n * // selectedSchemes: [\n * // { \"OAuth\": [\"read:pets\"] },\n * // { \"ApiKeyAuth\": [] }\n * // ]\n * // }\n *\n * updateSelectedScopes({\n * document,\n * id: [\"OAuth\"], // identifies the scheme object: { \"OAuth\": [...] }\n * name: \"OAuth\", // scheme name to update within this security requirement\n * scopes: [\"write:pets\"], // new scopes array\n * meta: { type: \"document\" }\n * })\n * // After, the first scheme becomes: { \"OAuth\": [\"write:pets\"] }\n * ```\n */\nexport const updateSelectedScopes = (\n document: WorkspaceDocument | null,\n { id, name, scopes, meta }: AuthEvents['auth:update:selected-scopes'],\n) => {\n if (!document) {\n return\n }\n\n // Determine the target object (document or the operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n const target = getTarget()\n\n if (!target) {\n return\n }\n\n // Array of security requirement objects under x-scalar-selected-security\n const selectedSchemes = target['x-scalar-selected-security']?.selectedSchemes\n\n if (!selectedSchemes) {\n return\n }\n\n // Find the security requirement that matches the given id (scheme key names)\n // For example: if id = [\"OAuth\"], matches { OAuth: [...] }\n const scheme = selectedSchemes.find((scheme) => JSON.stringify(Object.keys(scheme)) === JSON.stringify(id))\n\n if (!scheme) {\n return\n }\n\n // Set the scopes array for the named security scheme within the found security requirement\n scheme[name] = scopes\n}\n\n/**\n * Deletes one or more security schemes from an OpenAPI WorkspaceDocument,\n * and removes all references to those schemes from selected security, document-level security,\n * and operation-level security/selected security (e.g., on paths).\n *\n * Example usage:\n *\n * ```ts\n * deleteSecurityScheme({\n * document, // The OpenAPI document to update\n * names: ['ApiKeyAuth', 'BearerAuth'], // The names of security schemes you want to delete\n * });\n * ```\n *\n * After running this function:\n * - The named security schemes are removed from the components.securitySchemes section.\n * - All document-level and operation-level security entries referencing those schemes are removed.\n * - Any extended x-scalar-selected-security references to those schemes are also removed.\n */\nexport const deleteSecurityScheme = (\n document: WorkspaceDocument | null,\n { names }: AuthEvents['auth:delete:security-scheme'],\n) => {\n if (!document) {\n // Early exit if there is no document to modify\n return\n }\n\n // Get the mutable reference to securitySchemes in components (may be a proxy/resolved reference)\n const target = getResolvedRef(document.components?.securitySchemes)\n\n if (!target) {\n // If there are no security schemes to delete from, return early\n return\n }\n\n // Remove each named security scheme from the components.securitySchemes object\n names.forEach((name) => {\n delete target[name]\n })\n\n // Function to remove any security requirement objects that reference given scheme names.\n const filterSecuritySchemes = (schemes: SecurityRequirementObject[]) => {\n // Remove schemes whose key is included in the `names` to be deleted.\n return schemes.filter((scheme) => !names.some((name) => Object.keys(scheme).includes(name)))\n }\n\n // -- Remove from document-level `x-scalar-selected-security` extension, if present\n if (document['x-scalar-selected-security']) {\n const selectedSecurity = document['x-scalar-selected-security']\n selectedSecurity.selectedSchemes = filterSecuritySchemes(selectedSecurity.selectedSchemes)\n }\n\n // -- Remove from document-level `security` property, if present\n if (document['security']) {\n document['security'] = filterSecuritySchemes(document['security'])\n }\n\n // -- For each path and operation, remove deleted security schemes from operation-level security and custom extension\n Object.values(document.paths ?? {}).forEach((path) => {\n Object.values(path).forEach((operation) => {\n if (typeof operation !== 'object') {\n // Ignore operations that are not objects (could be undefined)\n return\n }\n\n // Get mutable reference for the operation (could resolve $ref proxies)\n const resolvedOperation = getResolvedRef(operation)\n\n // Remove from operation-level security array\n if ('security' in resolvedOperation && resolvedOperation['security']) {\n resolvedOperation['security'] = filterSecuritySchemes(resolvedOperation['security'])\n }\n\n // Remove from operation-level x-scalar-selected-security array\n if ('x-scalar-selected-security' in resolvedOperation && resolvedOperation['x-scalar-selected-security']) {\n resolvedOperation['x-scalar-selected-security'].selectedSchemes = filterSecuritySchemes(\n resolvedOperation['x-scalar-selected-security'].selectedSchemes,\n )\n }\n })\n })\n}\n"],
5
+ "mappings": "AAGA,S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CAAgC,qBAAqB,kBAAkB,4BAA4B,GAAG;AACxG,0BAAkB,4BAA4B,EAAE,kBAAkB;AAAA,UAChE,kBAAkB,4BAA4B,EAAE;AAAA,QAClD;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;",
6
+ "names": ["scheme"]
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { WorkspaceDocument } from '../schemas.js';
2
+ /**
3
+ * Toggle use document security
4
+ */
5
+ export declare const toggleDocumentSecurity: (document: WorkspaceDocument | null) => void;
6
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/mutators/document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAElD;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,UAAU,iBAAiB,GAAG,IAAI,SAMxE,CAAA"}
@@ -0,0 +1,10 @@
1
+ const toggleDocumentSecurity = (document) => {
2
+ if (!document) {
3
+ return;
4
+ }
5
+ document["x-scalar-document-security"] = !document["x-scalar-document-security"];
6
+ };
7
+ export {
8
+ toggleDocumentSecurity
9
+ };
10
+ //# sourceMappingURL=document.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/mutators/document.ts"],
4
+ "sourcesContent": ["import type { WorkspaceDocument } from '@/schemas'\n\n/**\n * Toggle use document security\n */\nexport const toggleDocumentSecurity = (document: WorkspaceDocument | null) => {\n if (!document) {\n return\n }\n\n document['x-scalar-document-security'] = !document['x-scalar-document-security']\n}\n"],
5
+ "mappings": "AAKO,MAAM,yBAAyB,CAAC,aAAuC;AAC5E,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AAEA,WAAS,4BAA4B,IAAI,CAAC,SAAS,4BAA4B;AACjF;",
6
+ "names": []
7
+ }
@@ -1,5 +1,6 @@
1
- /** biome-ignore-all lint/performance/noBarrelFile: this will probably get deleted later */
1
+ /** biome-ignore-all lint/performance/noBarrelFile: Mutators entry point */
2
2
  import type { WorkspaceStore } from '../client.js';
3
+ import type { ServerObject } from '../schemas/v3.1/strict/openapi-document.js';
3
4
  /**
4
5
  * Generates a set of mutators for managing OpenAPI document and workspace state.
5
6
  *
@@ -18,11 +19,11 @@ export declare function generateClientMutators(store: WorkspaceStore): {
18
19
  deleteCookie: (cookieName: string) => boolean;
19
20
  };
20
21
  serverMutators: {
21
- addServer: (server: import("../schemas/v3.1/strict/server.js").ServerObject) => boolean;
22
+ addServer: (server: ServerObject) => boolean;
22
23
  deleteServer: (url: string) => boolean;
23
24
  };
24
25
  securitySchemeMutators: {
25
- addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/security-scheme.js").SecuritySchemeObject) => boolean;
26
+ addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/openapi-document.js").SecuritySchemeObject) => boolean;
26
27
  deleteSecurityScheme: (name: string) => boolean;
27
28
  };
28
29
  };
@@ -39,7 +40,7 @@ export declare function generateClientMutators(store: WorkspaceStore): {
39
40
  deleteRequest: ({ path, method }: import("../mutators/request.js").OperationIdentifier) => boolean;
40
41
  };
41
42
  securitySchemeMutators: {
42
- addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/security-scheme.js").SecuritySchemeObject) => boolean;
43
+ addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/openapi-document.js").SecuritySchemeObject) => boolean;
43
44
  deleteSecurityScheme: (name: string) => boolean;
44
45
  };
45
46
  cookieMutators: {
@@ -47,7 +48,7 @@ export declare function generateClientMutators(store: WorkspaceStore): {
47
48
  deleteCookie: (cookieName: string) => boolean;
48
49
  };
49
50
  serverMutators: {
50
- addServer: (server: import("../schemas/v3.1/strict/server.js").ServerObject) => boolean;
51
+ addServer: (server: ServerObject) => boolean;
51
52
  deleteServer: (url: string) => boolean;
52
53
  };
53
54
  };
@@ -65,7 +66,7 @@ export declare function generateClientMutators(store: WorkspaceStore): {
65
66
  deleteRequest: ({ path, method }: import("../mutators/request.js").OperationIdentifier) => boolean;
66
67
  };
67
68
  securitySchemeMutators: {
68
- addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/security-scheme.js").SecuritySchemeObject) => boolean;
69
+ addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/openapi-document.js").SecuritySchemeObject) => boolean;
69
70
  deleteSecurityScheme: (name: string) => boolean;
70
71
  };
71
72
  cookieMutators: {
@@ -73,10 +74,14 @@ export declare function generateClientMutators(store: WorkspaceStore): {
73
74
  deleteCookie: (cookieName: string) => boolean;
74
75
  };
75
76
  serverMutators: {
76
- addServer: (server: import("../schemas/v3.1/strict/server.js").ServerObject) => boolean;
77
+ addServer: (server: ServerObject) => boolean;
77
78
  deleteServer: (url: string) => boolean;
78
79
  };
79
80
  };
80
81
  };
82
+ export { type AuthMeta, deleteSecurityScheme, updateSecurityScheme, updateSelectedAuthTab, updateSelectedScopes, updateSelectedSecuritySchemes, } from './auth.js';
83
+ export { toggleDocumentSecurity } from './document.js';
81
84
  export { upsertEnvironment, upsertEnvironmentVariable, } from './environment.js';
85
+ export { type OperationExampleMeta, type OperationMeta, addOperationParameter, addOperationRequestBodyFormRow, deleteAllOperationParameters, deleteOperationParameter, deleteOperationRequestBodyFormRow, updateOperationMethodDraft as updateOperationMethod, updateOperationParameter, updateOperationPathDraft as updateOperationPath, updateOperationRequestBodyContentType, updateOperationRequestBodyExample, updateOperationRequestBodyFormRow, updateOperationSummary, } from './operation.js';
86
+ export { addServer, deleteServer, updateSelectedServer, updateServer, updateServerVariables, } from './server.js';
82
87
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mutators/index.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAO9C;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAA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iC,EACjC,iCAAiC,EACjC,sBAAsB,GACvB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,SAAS,EACT,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,GACtB,MAAM,UAAU,CAAA"}
@@ -2,8 +2,29 @@ import { cookieMutators } from "../mutators/cookie.js";
2
2
  import { getDocument } from "../mutators/helpers.js";
3
3
  import { requestMutators } from "../mutators/request.js";
4
4
  import { securitySchemeMutators } from "../mutators/security-schemes.js";
5
- import { serverMutators } from "../mutators/server.js";
6
5
  function generateClientMutators(store) {
6
+ const serverMutators = (target) => {
7
+ const addServer2 = (server) => {
8
+ if (!target) {
9
+ return false;
10
+ }
11
+ target.push(server);
12
+ return true;
13
+ };
14
+ const deleteServer2 = (url) => {
15
+ if (!target) {
16
+ return false;
17
+ }
18
+ const newTarget = [...target.filter((it) => it.url !== url)];
19
+ target.splice(0, target.length);
20
+ target.push(...newTarget);
21
+ return true;
22
+ };
23
+ return {
24
+ addServer: addServer2,
25
+ deleteServer: deleteServer2
26
+ };
27
+ };
7
28
  const documentMutators = (documentName) => {
8
29
  const document = getDocument(store, documentName);
9
30
  if (document) {
@@ -56,12 +77,64 @@ function generateClientMutators(store) {
56
77
  doc: (name) => documentMutators(name)
57
78
  };
58
79
  }
80
+ import {
81
+ deleteSecurityScheme,
82
+ updateSecurityScheme,
83
+ updateSelectedAuthTab,
84
+ updateSelectedScopes,
85
+ updateSelectedSecuritySchemes
86
+ } from "./auth.js";
87
+ import { toggleDocumentSecurity } from "./document.js";
59
88
  import {
60
89
  upsertEnvironment,
61
90
  upsertEnvironmentVariable
62
91
  } from "./environment.js";
92
+ import {
93
+ addOperationParameter,
94
+ addOperationRequestBodyFormRow,
95
+ deleteAllOperationParameters,
96
+ deleteOperationParameter,
97
+ deleteOperationRequestBodyFormRow,
98
+ updateOperationMethodDraft,
99
+ updateOperationParameter,
100
+ updateOperationPathDraft,
101
+ updateOperationRequestBodyContentType,
102
+ updateOperationRequestBodyExample,
103
+ updateOperationRequestBodyFormRow,
104
+ updateOperationSummary
105
+ } from "./operation.js";
106
+ import {
107
+ addServer,
108
+ deleteServer,
109
+ updateSelectedServer,
110
+ updateServer,
111
+ updateServerVariables
112
+ } from "./server.js";
63
113
  export {
114
+ addOperationParameter,
115
+ addOperationRequestBodyFormRow,
116
+ addServer,
117
+ deleteAllOperationParameters,
118
+ deleteOperationParameter,
119
+ deleteOperationRequestBodyFormRow,
120
+ deleteSecurityScheme,
121
+ deleteServer,
64
122
  generateClientMutators,
123
+ toggleDocumentSecurity,
124
+ updateOperationMethodDraft as updateOperationMethod,
125
+ updateOperationParameter,
126
+ updateOperationPathDraft as updateOperationPath,
127
+ updateOperationRequestBodyContentType,
128
+ updateOperationRequestBodyExample,
129
+ updateOperationRequestBodyFormRow,
130
+ updateOperationSummary,
131
+ updateSecurityScheme,
132
+ updateSelectedAuthTab,
133
+ updateSelectedScopes,
134
+ updateSelectedSecuritySchemes,
135
+ updateSelectedServer,
136
+ updateServer,
137
+ updateServerVariables,
65
138
  upsertEnvironment,
66
139
  upsertEnvironmentVariable
67
140
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mutators/index.ts"],
4
- "sourcesContent": ["/** biome-ignore-all lint/performance/noBarrelFile: this will probably get deleted later */\nimport type { WorkspaceStore } from '@/client'\nimport { cookieMutators } from '@/mutators/cookie'\nimport { getDocument } from '@/mutators/helpers'\nimport { requestMutators } from '@/mutators/request'\nimport { securitySchemeMutators } from '@/mutators/security-schemes'\nimport { serverMutators } from '@/mutators/server'\n\n/**\n * Generates a set of mutators for managing OpenAPI document and workspace state.\n *\n * @deprecated use the individual mutators instead, this will be removed after we move fully to the new store\n *\n * @param store - The workspace store containing all documents and workspace-level data\n * @returns An object with mutators for the workspace, the active document, and any named document\n */\nexport function generateClientMutators(store: WorkspaceStore) {\n /**\n * Returns mutators for a specific document by name.\n *\n * @param documentName - The name of the document to get mutators for\n * @returns An object containing mutators for requests, request examples, security schemes, environments, and cookies\n */\n const documentMutators = (documentName: string) => {\n const document = getDocument(store, documentName)\n\n if (document) {\n // Make sure the document has a servers array\n if (!document.servers) {\n document.servers = []\n }\n\n // Make sure the document has the securitySchema object\n if (!document.components) {\n document.components = {}\n }\n\n if (!document.components.securitySchemes) {\n document.components.securitySchemes = {}\n }\n }\n\n return {\n requestMutators: requestMutators(document),\n securitySchemeMutators: securitySchemeMutators(document?.components?.securitySchemes),\n cookieMutators: cookieMutators(document),\n serverMutators: serverMutators(document?.servers),\n }\n }\n\n /**\n * Returns mutators for the workspace-level configuration.\n *\n * @returns An object containing mutators for environments and cookies at the workspace level\n */\n const workspaceMutators = () => {\n const workspace = store.workspace\n\n // Make sure the workspace has a servers array\n if (!workspace['x-scalar-client-config-servers']) {\n workspace['x-scalar-client-config-servers'] = []\n }\n\n // Make sure the workspace has the securitySchema object\n if (!store.workspace['x-scalar-client-config-security-schemes']) {\n store.workspace['x-scalar-client-config-security-schemes'] = {}\n }\n\n return {\n cookieMutators: cookieMutators(store.workspace),\n serverMutators: serverMutators(store.workspace['x-scalar-client-config-servers']),\n securitySchemeMutators: securitySchemeMutators(store.workspace['x-scalar-client-config-security-schemes']),\n }\n }\n\n return {\n /**\n * Returns mutators for the workspace-level configuration.\n */\n workspace: () => workspaceMutators(),\n /**\n * Returns mutators for the currently active document.\n * Falls back to the first document if no active document is set.\n */\n active: () =>\n documentMutators(store.workspace['x-scalar-active-document'] ?? Object.keys(store.workspace.documents)[0] ?? ''),\n /**\n * Returns mutators for a specific document by name.\n *\n * @param name - The name of the document\n */\n doc: (name: string) => documentMutators(name),\n }\n}\n\nexport {\n upsertEnvironment,\n upsertEnvironmentVariable,\n} from './environment'\n"],
5
- "mappings": "AAEA,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AACvC,SAAS,sBAAsB;AAUxB,SAAS,uBAAuB,OAAuB;AAO5D,QAAM,mBAAm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AAAA,OACK;",
6
- "names": []
4
+ "sourcesContent": ["/** biome-ignore-all lint/performance/noBarrelFile: Mutators entry point */\nimport type { WorkspaceStore } from '@/client'\nimport { cookieMutators } from '@/mutators/cookie'\nimport { getDocument } from '@/mutators/helpers'\nimport { requestMutators } from '@/mutators/request'\nimport { securitySchemeMutators } from '@/mutators/security-schemes'\nimport type { ServerObject } from '@/schemas/v3.1/strict/openapi-document'\n\n/**\n * Generates a set of mutators for managing OpenAPI document and workspace state.\n *\n * @deprecated use the individual mutators instead, this will be removed after we move fully to the new store\n *\n * @param store - The workspace store containing all documents and workspace-level data\n * @returns An object with mutators for the workspace, the active document, and any named document\n */\nexport function generateClientMutators(store: WorkspaceStore) {\n /**\n * Provides mutator functions for managing an array of OpenAPI ServerObject entries.\n *\n * @param target - The array of ServerObject to mutate. If not provided, mutators will be no-ops.\n * @returns An object with addServer and deleteServer methods.\n */\n const serverMutators = (target?: ServerObject[]) => {\n /**\n * Adds a new ServerObject to the target array.\n * @param server - The ServerObject to add.\n * @returns true if the server was added, false if target is undefined.\n */\n const addServer = (server: ServerObject): boolean => {\n if (!target) {\n return false\n }\n target.push(server)\n return true\n }\n\n /**\n * Deletes a ServerObject at the specified index from the target array.\n * @param index - The index of the server to delete.\n * @returns true if the server was deleted, false if target is undefined.\n */\n const deleteServer = (url: string): boolean => {\n if (!target) {\n return false\n }\n const newTarget = [...target.filter((it) => it.url !== url)]\n target.splice(0, target.length)\n target.push(...newTarget)\n return true\n }\n\n return {\n addServer,\n deleteServer,\n }\n }\n\n /**\n * Returns mutators for a specific document by name.\n *\n * @param documentName - The name of the document to get mutators for\n * @returns An object containing mutators for requests, request examples, security schemes, environments, and cookies\n */\n const documentMutators = (documentName: string) => {\n const document = getDocument(store, documentName)\n\n if (document) {\n // Make sure the document has a servers array\n if (!document.servers) {\n document.servers = []\n }\n\n // Make sure the document has the securitySchema object\n if (!document.components) {\n document.components = {}\n }\n\n if (!document.components.securitySchemes) {\n document.components.securitySchemes = {}\n }\n }\n\n return {\n requestMutators: requestMutators(document),\n securitySchemeMutators: securitySchemeMutators(document?.components?.securitySchemes),\n cookieMutators: cookieMutators(document),\n serverMutators: serverMutators(document?.servers),\n }\n }\n\n /**\n * Returns mutators for the workspace-level configuration.\n *\n * @returns An object containing mutators for environments and cookies at the workspace level\n */\n const workspaceMutators = () => {\n const workspace = store.workspace\n\n // Make sure the workspace has a servers array\n if (!workspace['x-scalar-client-config-servers']) {\n workspace['x-scalar-client-config-servers'] = []\n }\n\n // Make sure the workspace has the securitySchema object\n if (!store.workspace['x-scalar-client-config-security-schemes']) {\n store.workspace['x-scalar-client-config-security-schemes'] = {}\n }\n\n return {\n cookieMutators: cookieMutators(store.workspace),\n serverMutators: serverMutators(store.workspace['x-scalar-client-config-servers']),\n securitySchemeMutators: securitySchemeMutators(store.workspace['x-scalar-client-config-security-schemes']),\n }\n }\n\n return {\n /**\n * Returns mutators for the workspace-level configuration.\n */\n workspace: () => workspaceMutators(),\n /**\n * Returns mutators for the currently active document.\n * Falls back to the first document if no active document is set.\n */\n active: () =>\n documentMutators(store.workspace['x-scalar-active-document'] ?? Object.keys(store.workspace.documents)[0] ?? ''),\n /**\n * Returns mutators for a specific document by name.\n *\n * @param name - The name of the document\n */\n doc: (name: string) => documentMutators(name),\n }\n}\n\nexport {\n type AuthMeta,\n deleteSecurityScheme,\n updateSecurityScheme,\n updateSelectedAuthTab,\n updateSelectedScopes,\n updateSelectedSecuritySchemes,\n} from './auth'\nexport { toggleDocumentSecurity } from './document'\nexport {\n upsertEnvironment,\n upsertEnvironmentVariable,\n} from './environment'\nexport {\n type OperationExampleMeta,\n type OperationMeta,\n addOperationParameter,\n addOperationRequestBodyFormRow,\n deleteAllOperationParameters,\n deleteOperationParameter,\n deleteOperationRequestBodyFormRow,\n updateOperationMethodDraft as updateOperationMethod,\n updateOperationParameter,\n updateOperationPathDraft as updateOperationPath,\n updateOperationRequestBodyContentType,\n updateOperationRequestBodyExample,\n updateOperationRequestBodyFormRow,\n updateOperationSummary,\n} from './operation'\nexport {\n addServer,\n deleteServer,\n updateSelectedServer,\n updateServer,\n updateServerVariables,\n} from './server'\n"],
5
+ "mappings": "AAEA,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AAWhC,SAAS,uBAAuB,OAAuB;AAO5D,QAAM,iBAAiB,CAAC,WAA4B;AAMlD,UAAMA,aAAY,CAAC,WAAkC;AACnD,UAAI,CAAC,QAAQ;AACX,eAAO;AAAA,MACT;AACA,aAAO,KAAK,MAAM;AAClB,aAAO;AAAA,IACT;AAOA,UAAMC,gBAAe,CAAC,QAAyB;AAC7C,UAAI,CAAC,QAAQ;AACX,eAAO;AAAA,MACT;AACA,YAAM,YAAY,CAAC,GAAG,OAAO,OAAO,CAAC,OAAO,GAAG,QAAQ,GAAG,CAAC;AAC3D,aAAO,OAAO,GAAG,OAAO,MAAM;AAC9B,aAAO,KAAK,GAAG,SAAS;AACxB,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,MACL,WAAAD;AAAA,MACA,cAAAC;AAAA,IACF;AAAA,EACF;AAQA,QAAM,mBAAmB,CAAC,iBAAyB;AACjD,UAAM,WAAW,YAAY,OAAO,YAAY;AAEhD,QAAI,UAAU;AAEZ,UAAI,CAAC,SAAS,SAAS;AACrB,iBAAS,UAAU,CAAC;AAAA,MACtB;AAGA,UAAI,CAAC,SAAS,YAAY;AACxB,iBAAS,aAAa,CAAC;AAAA,MACzB;AAEA,UAAI,CAAC,SAAS,WAAW,iBAAiB;AACxC,iBAAS,WAAW,kBAAkB,CAAC;AAAA,MACzC;AAAA,IACF;AAEA,WAAO;AAAA,MACL,iBAAiB,gBAAgB,QAAQ;AAAA,MACzC,wBAAwB,uBAAuB,UAAU,YAAY,eAAe;AAAA,MACpF,gBAAgB,eAAe,QAAQ;AAAA,MACvC,gBAAgB,eAAe,UAAU,OAAO;AAAA,IAClD;AAAA,EACF;AAOA,QAAM,oBAAoB,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