@scalar/workspace-store 0.28.1 → 0.28.3

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 (102) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/client.d.ts +10 -0
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +42 -2
  5. package/dist/client.js.map +2 -2
  6. package/dist/entities/auth/index.d.ts +75 -0
  7. package/dist/entities/auth/index.d.ts.map +1 -0
  8. package/dist/entities/auth/index.js +89 -0
  9. package/dist/entities/auth/index.js.map +7 -0
  10. package/dist/entities/auth/schema.d.ts +7318 -0
  11. package/dist/entities/auth/schema.d.ts.map +1 -0
  12. package/dist/entities/auth/schema.js +74 -0
  13. package/dist/entities/auth/schema.js.map +7 -0
  14. package/dist/entities/history/index.d.ts +93 -0
  15. package/dist/entities/history/index.d.ts.map +1 -0
  16. package/dist/entities/history/index.js +62 -0
  17. package/dist/entities/history/index.js.map +7 -0
  18. package/dist/entities/history/schema.d.ts +234 -0
  19. package/dist/entities/history/schema.d.ts.map +1 -0
  20. package/dist/{schemas/extensions/operation/x-scalar-history.js → entities/history/schema.js} +5 -6
  21. package/dist/{schemas/extensions/operation/x-scalar-history.js.map → entities/history/schema.js.map} +3 -3
  22. package/dist/events/definitions/auth.d.ts +14 -0
  23. package/dist/events/definitions/auth.d.ts.map +1 -1
  24. package/dist/mutators/auth.d.ts +10 -17
  25. package/dist/mutators/auth.d.ts.map +1 -1
  26. package/dist/mutators/auth.js +87 -57
  27. package/dist/mutators/auth.js.map +2 -2
  28. package/dist/mutators/index.d.ts +4 -12
  29. package/dist/mutators/index.d.ts.map +1 -1
  30. package/dist/mutators/index.js +1 -1
  31. package/dist/mutators/index.js.map +2 -2
  32. package/dist/mutators/operation.d.ts +2 -2
  33. package/dist/mutators/operation.d.ts.map +1 -1
  34. package/dist/mutators/operation.js +9 -16
  35. package/dist/mutators/operation.js.map +2 -2
  36. package/dist/mutators/server.d.ts.map +1 -1
  37. package/dist/mutators/server.js +0 -3
  38. package/dist/mutators/server.js.map +2 -2
  39. package/dist/persistence/index.d.ts +16 -3
  40. package/dist/persistence/index.d.ts.map +1 -1
  41. package/dist/persistence/index.js +47 -3
  42. package/dist/persistence/index.js.map +2 -2
  43. package/dist/plugins/bundler/index.d.ts +7 -0
  44. package/dist/plugins/bundler/index.d.ts.map +1 -1
  45. package/dist/plugins/bundler/index.js +17 -0
  46. package/dist/plugins/bundler/index.js.map +2 -2
  47. package/dist/plugins/client/persistence.d.ts.map +1 -1
  48. package/dist/plugins/client/persistence.js +12 -0
  49. package/dist/plugins/client/persistence.js.map +2 -2
  50. package/dist/resolve.d.ts +9 -0
  51. package/dist/resolve.d.ts.map +1 -0
  52. package/dist/resolve.js +28 -0
  53. package/dist/resolve.js.map +7 -0
  54. package/dist/schemas/extensions/security/index.d.ts +2 -0
  55. package/dist/schemas/extensions/security/index.d.ts.map +1 -0
  56. package/dist/schemas/extensions/security/index.js +1 -0
  57. package/dist/schemas/extensions/security/index.js.map +7 -0
  58. package/dist/schemas/inmemory-workspace.d.ts +2952 -149
  59. package/dist/schemas/inmemory-workspace.d.ts.map +1 -1
  60. package/dist/schemas/inmemory-workspace.js +5 -1
  61. package/dist/schemas/inmemory-workspace.js.map +2 -2
  62. package/dist/schemas/reference-config/index.d.ts +35 -149
  63. package/dist/schemas/reference-config/index.d.ts.map +1 -1
  64. package/dist/schemas/reference-config/settings.d.ts +35 -149
  65. package/dist/schemas/reference-config/settings.d.ts.map +1 -1
  66. package/dist/schemas/v3.1/strict/oauth-flow.d.ts +5 -35
  67. package/dist/schemas/v3.1/strict/oauth-flow.d.ts.map +1 -1
  68. package/dist/schemas/v3.1/strict/oauth-flow.js +1 -16
  69. package/dist/schemas/v3.1/strict/oauth-flow.js.map +2 -2
  70. package/dist/schemas/v3.1/strict/oauthflows.d.ts +0 -29
  71. package/dist/schemas/v3.1/strict/oauthflows.d.ts.map +1 -1
  72. package/dist/schemas/v3.1/strict/openapi-document.d.ts +1245 -6744
  73. package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
  74. package/dist/schemas/v3.1/strict/openapi-document.js +2 -10
  75. package/dist/schemas/v3.1/strict/openapi-document.js.map +2 -2
  76. package/dist/schemas/v3.1/strict/operation.d.ts +1 -70
  77. package/dist/schemas/v3.1/strict/operation.d.ts.map +1 -1
  78. package/dist/schemas/v3.1/strict/operation.js +1 -7
  79. package/dist/schemas/v3.1/strict/operation.js.map +2 -2
  80. package/dist/schemas/v3.1/strict/ref-definitions.d.ts +0 -1
  81. package/dist/schemas/v3.1/strict/ref-definitions.d.ts.map +1 -1
  82. package/dist/schemas/v3.1/strict/ref-definitions.js +1 -3
  83. package/dist/schemas/v3.1/strict/ref-definitions.js.map +2 -2
  84. package/dist/schemas/v3.1/strict/schema.d.ts +50 -46
  85. package/dist/schemas/v3.1/strict/schema.d.ts.map +1 -1
  86. package/dist/schemas/v3.1/strict/schema.js +5 -2
  87. package/dist/schemas/v3.1/strict/schema.js.map +2 -2
  88. package/dist/schemas/v3.1/strict/security-scheme.d.ts +3 -11
  89. package/dist/schemas/v3.1/strict/security-scheme.d.ts.map +1 -1
  90. package/dist/schemas/v3.1/strict/security-scheme.js +0 -7
  91. package/dist/schemas/v3.1/strict/security-scheme.js.map +2 -2
  92. package/dist/schemas/workspace.d.ts +245 -1043
  93. package/dist/schemas/workspace.d.ts.map +1 -1
  94. package/dist/workspace-plugin.d.ts +8 -0
  95. package/dist/workspace-plugin.d.ts.map +1 -1
  96. package/package.json +26 -6
  97. package/dist/schemas/extensions/operation/x-scalar-history.d.ts +0 -217
  98. package/dist/schemas/extensions/operation/x-scalar-history.d.ts.map +0 -1
  99. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts +0 -17
  100. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts.map +0 -1
  101. package/dist/schemas/extensions/security/x-scalar-selected-security.js +0 -14
  102. package/dist/schemas/extensions/security/x-scalar-selected-security.js.map +0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AAW,CAAC,MAAM,CAAC,CAAC,GAAG;YAAE,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;SAAE,CAAA;QACjF,gDAAgD;QAChD,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;IAED;;;OAGG;IACH,6BAA6B,EAAE;QAC7B,6DAA6D;QAC7D,EAAE,EAAE,MAAM,EAAE,CAAA;QACZ,+DAA+D;QAC/D,IAAI,EAAE,MAAM,CAAA;QACZ,oDAAoD;QACpD,MAAM,EAAE,MAAM,EAAE,CAAA;QAChB,oDAAoD;QACpD,eAAe,CAAC,EAAE;YAChB,IAAI,EAAE,MAAM,CAAA;YACZ,WAAW,EAAE,MAAM,CAAA;YACnB,QAAQ,EAAE,MAAM,gBAAgB,CAAA;SACjC,CAAA;QACD,2CAA2C;QAC3C,IAAI,EAAE,QAAQ,CAAA;KACf,CAAA;IAED;;;;;;;;;OASG;IACH,6BAA6B,EAAE;QAC7B,8CAA8C;QAC9C,KAAK,EAAE,MAAM,EAAE,CAAA;KAChB,CAAA;CACF,CAAA"}
@@ -1,3 +1,4 @@
1
+ import type { WorkspaceStore } from '../client.js';
1
2
  import type { AuthEvents } from '../events/definitions/auth.js';
2
3
  import type { WorkspaceDocument } from '../schemas.js';
3
4
  import type { OAuth2Object } from '../schemas/v3.1/strict/security-scheme.js';
@@ -25,7 +26,7 @@ import type { OAuth2Object } from '../schemas/v3.1/strict/security-scheme.js';
25
26
  * })
26
27
  * ```
27
28
  */
28
- export declare const updateSelectedSecuritySchemes: (document: WorkspaceDocument | null, { selectedRequirements, newSchemes, meta }: AuthEvents["auth:update:selected-security-schemes"]) => Promise<void>;
29
+ export declare const updateSelectedSecuritySchemes: (store: WorkspaceStore | null, document: WorkspaceDocument | null, { selectedRequirements, newSchemes, meta }: AuthEvents["auth:update:selected-security-schemes"]) => Promise<void>;
29
30
  /**
30
31
  * Updates a security scheme in the OpenAPI document's components object.
31
32
  * Handles updates for HTTP, API Key, and OAuth2 types, saving secret information and configuration for UI-auth flows.
@@ -49,12 +50,7 @@ export declare const updateSelectedSecuritySchemes: (document: WorkspaceDocument
49
50
  * name: 'MyHttpAuth',
50
51
  * })
51
52
  */
52
- 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 | OAuth2Object | ({
53
- description?: string;
54
- } & {
55
- type: "openIdConnect";
56
- openIdConnectUrl: string;
57
- }) | undefined;
53
+ 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 | OAuth2Object | import("../schemas/v3.1/strict/security-scheme.js").OpenIdConnectObject | undefined;
58
54
  /**
59
55
  * Sets the selected authentication tab (scheme) index for the given OpenAPI document or operation.
60
56
  * - When on the document level, updates the 'selectedIndex' on the document's x-scalar-selected-security extension.
@@ -81,7 +77,7 @@ export declare const updateSecurityScheme: (document: WorkspaceDocument | null,
81
77
  * meta: { type: 'operation', path: '/pets', method: 'get' }
82
78
  * });
83
79
  */
84
- export declare const updateSelectedAuthTab: (document: WorkspaceDocument | null, { index, meta }: AuthEvents["auth:update:active-index"]) => void;
80
+ export declare const updateSelectedAuthTab: (store: WorkspaceStore | null, document: WorkspaceDocument | null, { index, meta }: AuthEvents["auth:update:active-index"]) => void;
85
81
  /**
86
82
  * Updates the scopes for a specific security requirement in the selected security schemes of
87
83
  * a document or operation. Also allow to add a new scope to the scheme.
@@ -115,7 +111,7 @@ export declare const updateSelectedAuthTab: (document: WorkspaceDocument | null,
115
111
  * // After, the first scheme becomes: { "OAuth": ["write:pets"] }
116
112
  * ```
117
113
  */
118
- export declare const updateSelectedScopes: (document: WorkspaceDocument | null, { id, name, scopes, newScopePayload, meta }: AuthEvents["auth:update:selected-scopes"]) => void;
114
+ export declare const updateSelectedScopes: (store: WorkspaceStore | null, document: WorkspaceDocument | null, { id, name, scopes, newScopePayload, meta }: AuthEvents["auth:update:selected-scopes"]) => void;
119
115
  /**
120
116
  * Deletes one or more security schemes from an OpenAPI WorkspaceDocument,
121
117
  * and removes all references to those schemes from selected security, document-level security,
@@ -135,17 +131,14 @@ export declare const updateSelectedScopes: (document: WorkspaceDocument | null,
135
131
  * - All document-level and operation-level security entries referencing those schemes are removed.
136
132
  * - Any extended x-scalar-selected-security references to those schemes are also removed.
137
133
  */
138
- export declare const deleteSecurityScheme: (document: WorkspaceDocument | null, { names }: AuthEvents["auth:delete:security-scheme"]) => void;
139
- export declare const authMutatorsFactory: ({ document }: {
134
+ export declare const deleteSecurityScheme: (store: WorkspaceStore | null, document: WorkspaceDocument | null, { names }: AuthEvents["auth:delete:security-scheme"]) => void;
135
+ export declare const authMutatorsFactory: ({ document, store, }: {
140
136
  document: WorkspaceDocument | null;
137
+ store: WorkspaceStore | null;
141
138
  }) => {
142
139
  updateSelectedSecuritySchemes: (payload: AuthEvents["auth:update:selected-security-schemes"]) => Promise<void>;
143
- updateSecurityScheme: (payload: AuthEvents["auth:update:security-scheme"]) => import("../schemas/v3.1/strict/security-scheme.js").ApiKeyObject | import("../schemas/v3.1/strict/security-scheme.js").HttpObject | OAuth2Object | ({
144
- description?: string;
145
- } & {
146
- type: "openIdConnect";
147
- openIdConnectUrl: string;
148
- }) | undefined;
140
+ updateSecurityScheme: (payload: AuthEvents["auth:update:security-scheme"]) => import("../schemas/v3.1/strict/security-scheme.js").ApiKeyObject | import("../schemas/v3.1/strict/security-scheme.js").HttpObject | OAuth2Object | import("../schemas/v3.1/strict/security-scheme.js").OpenIdConnectObject | undefined;
141
+ updateSecuritySchemeSecrets: (payload: AuthEvents["auth:update:security-scheme-secrets"]) => void;
149
142
  updateSelectedAuthTab: (payload: AuthEvents["auth:update:active-index"]) => void;
150
143
  updateSelectedScopes: (payload: AuthEvents["auth:update:selected-scopes"]) => void;
151
144
  deleteSecurityScheme: (payload: AuthEvents["auth:delete:security-scheme"]) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/mutators/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAK3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAA;AAEzE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,6BAA6B,GACxC,UAAU,iBAAiB,GAAG,IAAI,EAClC,4CAA4C,UAAU,CAAC,uCAAuC,CAAC,kBA+EhG,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,iBAAiB,GAAG,IAAI,EAClC,mBAAmB,UAAU,CAAC,6BAA6B,CAAC;;;;;cAc7D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,qBAAqB,GAChC,UAAU,iBAAiB,GAAG,IAAI,EAClC,iBAAiB,UAAU,CAAC,0BAA0B,CAAC,SA+BxD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,iBAAiB,GAAG,IAAI,EAClC,6CAA6C,UAAU,CAAC,6BAA6B,CAAC,SAkDvF,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,iBAAiB,GAAG,IAAI,EAClC,WAAW,UAAU,CAAC,6BAA6B,CAAC,SA6DrD,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,cAAc;IAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAAE;6CAE3C,UAAU,CAAC,uCAAuC,CAAC;oCAE5D,UAA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,OAAO,cAAc,GAAG,IAAI,EAC5B,UAAU,iBAAiB,GAAG,IAAI,EAClC,WAAW,UAAU,CAAC,6BAA6B,CAAC,SAuErD,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,sBAGjC;IACD,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAA;IAClC,KAAK,EAAE,cAAc,GAAG,IAAI,CAAA;CAC7B;6CAE4C,UAAU,CAAC,uCAAuC,CAAC;oCAE5D,UAAU,CAAC,6BAA6B,CAAC;2CAElC,UAAU,CAAC,qCAAqC,CAAC;qCAEvD,UAAU,CAAC,0BAA0B,CAAC;oCAEvC,UAAU,CAAC,6BAA6B,CAAC;oCAEzC,UAAU,CAAC,6BAA6B,CAAC;CAG5E,CAAA"}
@@ -2,15 +2,17 @@ import { generateUniqueValue } from "../helpers/generate-unique-value.js";
2
2
  import { getResolvedRef } from "../helpers/get-resolved-ref.js";
3
3
  import { isNonOptionalSecurityRequirement } from "../helpers/is-non-optional-security-requirement.js";
4
4
  import { mergeObjects } from "../helpers/merge-object.js";
5
- const updateSelectedSecuritySchemes = async (document, { selectedRequirements, newSchemes, meta }) => {
6
- if (!document) {
5
+ import { unpackProxyObject } from "../helpers/unpack-proxy.js";
6
+ const updateSelectedSecuritySchemes = async (store, document, { selectedRequirements, newSchemes, meta }) => {
7
+ const documentName = document?.["x-scalar-navigation"]?.name;
8
+ if (!documentName) {
7
9
  return;
8
10
  }
9
11
  const getTarget = () => {
10
12
  if (meta.type === "document") {
11
- return document;
13
+ return store?.auth.getAuthSelectedSchemas({ type: "document", documentName });
12
14
  }
13
- return getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
15
+ return store?.auth.getAuthSelectedSchemas({ type: "operation", documentName, path: meta.path, method: meta.method });
14
16
  };
15
17
  const createdSecurityRequirements = await Promise.all(
16
18
  newSchemes.map(async (newScheme) => {
@@ -37,23 +39,25 @@ const updateSelectedSecuritySchemes = async (document, { selectedRequirements, n
37
39
  const createdSchemes = createdSecurityRequirements.filter(Boolean);
38
40
  const target = getTarget();
39
41
  const newSelectedSecuritySchemes = [...selectedRequirements, ...createdSchemes];
40
- if (!target) {
41
- return;
42
- }
43
- if (!target["x-scalar-selected-security"]) {
44
- target["x-scalar-selected-security"] = {
45
- selectedIndex: -1,
46
- selectedSchemes: []
47
- };
48
- }
49
- const selectedIndex = target["x-scalar-selected-security"].selectedIndex;
50
- target["x-scalar-selected-security"].selectedSchemes = newSelectedSecuritySchemes;
51
- if (newSelectedSecuritySchemes.length > 0 && selectedIndex < 0) {
52
- target["x-scalar-selected-security"].selectedIndex = 0;
53
- }
54
- if (selectedIndex >= newSelectedSecuritySchemes.length) {
55
- target["x-scalar-selected-security"].selectedIndex = newSelectedSecuritySchemes.length - 1;
56
- }
42
+ const getSelectedIndex = () => {
43
+ if (!target?.selectedIndex) {
44
+ return 0;
45
+ }
46
+ if (target.selectedIndex >= newSelectedSecuritySchemes.length) {
47
+ return newSelectedSecuritySchemes.length - 1;
48
+ }
49
+ return target.selectedIndex;
50
+ };
51
+ if (meta.type === "document") {
52
+ return store?.auth.setAuthSelectedSchemas(
53
+ { type: "document", documentName },
54
+ { selectedIndex: getSelectedIndex(), selectedSchemes: newSelectedSecuritySchemes }
55
+ );
56
+ }
57
+ return store?.auth.setAuthSelectedSchemas(
58
+ { type: "operation", documentName, path: meta.path, method: meta.method },
59
+ { selectedIndex: getSelectedIndex(), selectedSchemes: newSelectedSecuritySchemes }
60
+ );
57
61
  };
58
62
  const updateSecurityScheme = (document, { payload, name }) => {
59
63
  const target = getResolvedRef(document?.components?.securitySchemes?.[name]);
@@ -66,47 +70,60 @@ const updateSecurityScheme = (document, { payload, name }) => {
66
70
  }
67
71
  return target;
68
72
  };
69
- const updateSelectedAuthTab = (document, { index, meta }) => {
70
- if (!document) {
73
+ const updateSecuritySchemeSecrets = (store, document, { payload, name }) => {
74
+ const documentName = document?.["x-scalar-navigation"]?.name;
75
+ if (!documentName) {
76
+ return;
77
+ }
78
+ const auth = store?.auth.getAuthSecrets(documentName, name);
79
+ const result = mergeObjects(unpackProxyObject(auth, { depth: 1 }) ?? {}, payload);
80
+ store?.auth.setAuthSecrets(documentName, name, result);
81
+ };
82
+ const updateSelectedAuthTab = (store, document, { index, meta }) => {
83
+ const documentName = document?.["x-scalar-navigation"]?.name;
84
+ if (!documentName) {
85
+ return;
86
+ }
87
+ if (meta.type === "operation" && document?.paths?.[meta.path]?.[meta.method] === void 0) {
71
88
  return;
72
89
  }
73
90
  const getTarget = () => {
74
91
  if (meta.type === "document") {
75
- return document;
92
+ return store?.auth.getAuthSelectedSchemas({ type: "document", documentName });
76
93
  }
77
- return getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
94
+ return store?.auth.getAuthSelectedSchemas({ type: "operation", documentName, path: meta.path, method: meta.method });
78
95
  };
79
96
  const target = getTarget();
80
97
  if (!target) {
81
- return;
82
- }
83
- if (!target["x-scalar-selected-security"]) {
84
- target["x-scalar-selected-security"] = {
85
- selectedIndex: 0,
86
- selectedSchemes: []
87
- };
98
+ if (meta.type === "document") {
99
+ return store?.auth.setAuthSelectedSchemas(
100
+ { type: "document", documentName },
101
+ { selectedIndex: index, selectedSchemes: [] }
102
+ );
103
+ }
104
+ return store?.auth.setAuthSelectedSchemas(
105
+ { type: "operation", documentName, path: meta.path, method: meta.method },
106
+ { selectedIndex: index, selectedSchemes: [] }
107
+ );
88
108
  }
89
- target["x-scalar-selected-security"].selectedIndex = index;
109
+ target.selectedIndex = index;
90
110
  };
91
- const updateSelectedScopes = (document, { id, name, scopes, newScopePayload, meta }) => {
92
- if (!document) {
111
+ const updateSelectedScopes = (store, document, { id, name, scopes, newScopePayload, meta }) => {
112
+ const documentName = document?.["x-scalar-navigation"]?.name;
113
+ if (!documentName) {
93
114
  return;
94
115
  }
95
116
  const getTarget = () => {
96
117
  if (meta.type === "document") {
97
- return document;
118
+ return store?.auth.getAuthSelectedSchemas({ type: "document", documentName });
98
119
  }
99
- return getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
120
+ return store?.auth.getAuthSelectedSchemas({ type: "operation", documentName, path: meta.path, method: meta.method });
100
121
  };
101
122
  const target = getTarget();
102
123
  if (!target) {
103
124
  return;
104
125
  }
105
- const selectedSchemes = target["x-scalar-selected-security"]?.selectedSchemes;
106
- if (!selectedSchemes) {
107
- return;
108
- }
109
- const scheme = selectedSchemes.find((scheme2) => JSON.stringify(Object.keys(scheme2)) === JSON.stringify(id));
126
+ const scheme = target.selectedSchemes.find((scheme2) => JSON.stringify(Object.keys(scheme2)) === JSON.stringify(id));
110
127
  if (!isNonOptionalSecurityRequirement(scheme)) {
111
128
  return;
112
129
  }
@@ -123,8 +140,9 @@ const updateSelectedScopes = (document, { id, name, scopes, newScopePayload, met
123
140
  }
124
141
  scheme[name] = scopes;
125
142
  };
126
- const deleteSecurityScheme = (document, { names }) => {
127
- if (!document) {
143
+ const deleteSecurityScheme = (store, document, { names }) => {
144
+ const documentName = document?.["x-scalar-navigation"]?.name;
145
+ if (!documentName) {
128
146
  return;
129
147
  }
130
148
  const target = getResolvedRef(document.components?.securitySchemes);
@@ -137,15 +155,17 @@ const deleteSecurityScheme = (document, { names }) => {
137
155
  const filterSecuritySchemes = (schemes) => {
138
156
  return schemes.filter((scheme) => !names.some((name) => Object.keys(scheme).includes(name)));
139
157
  };
140
- if (document["x-scalar-selected-security"]) {
141
- const selectedSecurity = document["x-scalar-selected-security"];
142
- selectedSecurity.selectedSchemes = filterSecuritySchemes(selectedSecurity.selectedSchemes);
158
+ const documentSelectedSecurity = store?.auth.getAuthSelectedSchemas({ type: "document", documentName });
159
+ if (documentSelectedSecurity) {
160
+ documentSelectedSecurity.selectedSchemes = filterSecuritySchemes(
161
+ unpackProxyObject(documentSelectedSecurity.selectedSchemes, { depth: 1 }) ?? []
162
+ );
143
163
  }
144
164
  if (document["security"]) {
145
165
  document["security"] = filterSecuritySchemes(document["security"]);
146
166
  }
147
- Object.values(document.paths ?? {}).forEach((path) => {
148
- Object.values(path).forEach((operation) => {
167
+ Object.entries(document.paths ?? {}).forEach(([path, pathItemObject]) => {
168
+ Object.entries(pathItemObject).forEach(([method, operation]) => {
149
169
  if (typeof operation !== "object") {
150
170
  return;
151
171
  }
@@ -153,21 +173,31 @@ const deleteSecurityScheme = (document, { names }) => {
153
173
  if ("security" in resolvedOperation && resolvedOperation["security"]) {
154
174
  resolvedOperation["security"] = filterSecuritySchemes(resolvedOperation["security"]);
155
175
  }
156
- if ("x-scalar-selected-security" in resolvedOperation && resolvedOperation["x-scalar-selected-security"]) {
157
- resolvedOperation["x-scalar-selected-security"].selectedSchemes = filterSecuritySchemes(
158
- resolvedOperation["x-scalar-selected-security"].selectedSchemes
176
+ const operationSelectedSecurity = store?.auth.getAuthSelectedSchemas({
177
+ type: "operation",
178
+ documentName,
179
+ path,
180
+ method
181
+ });
182
+ if (operationSelectedSecurity) {
183
+ operationSelectedSecurity.selectedSchemes = filterSecuritySchemes(
184
+ unpackProxyObject(operationSelectedSecurity.selectedSchemes, { depth: 1 }) ?? []
159
185
  );
160
186
  }
161
187
  });
162
188
  });
163
189
  };
164
- const authMutatorsFactory = ({ document }) => {
190
+ const authMutatorsFactory = ({
191
+ document,
192
+ store
193
+ }) => {
165
194
  return {
166
- updateSelectedSecuritySchemes: (payload) => updateSelectedSecuritySchemes(document, payload),
195
+ updateSelectedSecuritySchemes: (payload) => updateSelectedSecuritySchemes(store, document, payload),
167
196
  updateSecurityScheme: (payload) => updateSecurityScheme(document, payload),
168
- updateSelectedAuthTab: (payload) => updateSelectedAuthTab(document, payload),
169
- updateSelectedScopes: (payload) => updateSelectedScopes(document, payload),
170
- deleteSecurityScheme: (payload) => deleteSecurityScheme(document, payload)
197
+ updateSecuritySchemeSecrets: (payload) => updateSecuritySchemeSecrets(store, document, payload),
198
+ updateSelectedAuthTab: (payload) => updateSelectedAuthTab(store, document, payload),
199
+ updateSelectedScopes: (payload) => updateSelectedScopes(store, document, payload),
200
+ deleteSecurityScheme: (payload) => deleteSecurityScheme(store, document, payload)
171
201
  };
172
202
  };
173
203
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mutators/auth.ts"],
4
- "sourcesContent": ["import type { AuthEvents } from '@/events/definitions/auth'\nimport { generateUniqueValue } from '@/helpers/generate-unique-value'\nimport { getResolvedRef } from '@/helpers/get-resolved-ref'\nimport { isNonOptionalSecurityRequirement } from '@/helpers/is-non-optional-security-requirement'\nimport { mergeObjects } from '@/helpers/merge-object'\nimport type { WorkspaceDocument } from '@/schemas'\nimport type { SecurityRequirementObject } from '@/schemas/v3.1/strict/security-requirement'\nimport type { OAuth2Object } from '@/schemas/v3.1/strict/security-scheme'\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 = async (\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 const createdSecurityRequirements = await Promise.all(\n newSchemes.map(async (newScheme) => {\n const uniqueSchemeName = await generateUniqueValue({\n defaultValue: newScheme.name,\n validation: (value) => !document.components?.securitySchemes?.[value],\n maxRetries: 100,\n })\n\n if (!uniqueSchemeName) {\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[uniqueSchemeName] = newScheme.scheme\n\n // Return an OpenAPI Security Requirement Object for this new scheme (empty scope array)\n return {\n [uniqueSchemeName]: [],\n }\n }),\n )\n\n // Create any new security schemes required, ensuring unique names for the components\n const createdSchemes = createdSecurityRequirements.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. Also allow to add a new scope to the scheme.\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 newScopePayload - The payload to add a new scope with\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, newScopePayload, 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 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 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 the scheme is optional, do nothing as it cannot have scopes\n if (!isNonOptionalSecurityRequirement(scheme)) {\n return\n }\n\n // If we have a new scope payload, add it to the scheme\n if (newScopePayload) {\n const securityScheme = getResolvedRef(document.components?.securitySchemes?.[name])\n const flow = (securityScheme as OAuth2Object)?.flows?.[newScopePayload?.flowType]\n if (!flow) {\n return\n }\n flow.scopes ||= {}\n\n flow.scopes[newScopePayload.name] = newScopePayload.description\n scheme[name] = [...scopes, newScopePayload.name]\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\nexport const authMutatorsFactory = ({ document }: { document: WorkspaceDocument | null }) => {\n return {\n updateSelectedSecuritySchemes: (payload: AuthEvents['auth:update:selected-security-schemes']) =>\n updateSelectedSecuritySchemes(document, payload),\n updateSecurityScheme: (payload: AuthEvents['auth:update:security-scheme']) =>\n updateSecurityScheme(document, payload),\n updateSelectedAuthTab: (payload: AuthEvents['auth:update:active-index']) =>\n updateSelectedAuthTab(document, payload),\n updateSelectedScopes: (payload: AuthEvents['auth:update:selected-scopes']) =>\n updateSelectedScopes(document, payload),\n deleteSecurityScheme: (payload: AuthEvents['auth:delete:security-scheme']) =>\n deleteSecurityScheme(document, payload),\n }\n}\n"],
5
- "mappings": "AACA,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,wCAAwC;AACjD,SAAS,oBAAoB;AA6BtB,MAAM,gCAAgC,OAC3C,UACA,EAAE,sBAAsB,YAAY,KAAK,MACtC;AACH,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AAGA,QAAM,YAAY,MAAM;AACtB,QAAI,KAAK,SAAS,YAAY;AAC5B,aAAO;AAAA,IACT;AAEA,WAAO,eAAe,SAAS,QAAQ,KAAK,IAAI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Ae,SAAS;AAGlD,UAAI,cAAc,qBAAqB,kBAAkB,UAAU,GAAG;AACpE,0BAAkB,UAAU,IAAI,sBAAsB,kBAAkB,UAAU,CAAC;AAAA,MACrF;AAGA,UAAI,gCAAgC,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;AAEO,MAAM,sBAAsB,CAAC,EAAE,SAAS,MAA8C;AAC3F,SAAO;AAAA,IACL,+BAA+B,CAAC,YAC9B,8BAA8B,UAAU,OAAO;AAAA,IACjD,sBAAsB,CAAC,YACrB,qBAAqB,UAAU,OAAO;AAAA,IACxC,uBAAuB,CAAC,YACtB,sBAAsB,UAAU,OAAO;AAAA,IACzC,sBAAsB,CAAC,YACrB,qBAAqB,UAAU,OAAO;AAAA,IACxC,sBAAsB,CAAC,YACrB,qBAAqB,UAAU,OAAO;AAAA,EAC1C;AACF;",
4
+ "sourcesContent": ["import type { WorkspaceStore } from '@/client'\nimport type { AuthEvents } from '@/events/definitions/auth'\nimport { generateUniqueValue } from '@/helpers/generate-unique-value'\nimport { getResolvedRef } from '@/helpers/get-resolved-ref'\nimport { isNonOptionalSecurityRequirement } from '@/helpers/is-non-optional-security-requirement'\nimport { mergeObjects } from '@/helpers/merge-object'\nimport { unpackProxyObject } from '@/helpers/unpack-proxy'\nimport type { WorkspaceDocument } from '@/schemas'\nimport type { SecurityRequirementObject } from '@/schemas/v3.1/strict/security-requirement'\nimport type { OAuth2Object } from '@/schemas/v3.1/strict/security-scheme'\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 = async (\n store: WorkspaceStore | null,\n document: WorkspaceDocument | null,\n { selectedRequirements, newSchemes, meta }: AuthEvents['auth:update:selected-security-schemes'],\n) => {\n const documentName = document?.['x-scalar-navigation']?.name\n if (!documentName) {\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 store?.auth.getAuthSelectedSchemas({ type: 'document', documentName })\n }\n\n return store?.auth.getAuthSelectedSchemas({ type: 'operation', documentName, path: meta.path, method: meta.method })\n }\n\n const createdSecurityRequirements = await Promise.all(\n newSchemes.map(async (newScheme) => {\n const uniqueSchemeName = await generateUniqueValue({\n defaultValue: newScheme.name,\n validation: (value) => !document.components?.securitySchemes?.[value],\n maxRetries: 100,\n })\n\n if (!uniqueSchemeName) {\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[uniqueSchemeName] = newScheme.scheme\n\n // Return an OpenAPI Security Requirement Object for this new scheme (empty scope array)\n return {\n [uniqueSchemeName]: [],\n }\n }),\n )\n\n // Create any new security schemes required, ensuring unique names for the components\n const createdSchemes = createdSecurityRequirements.filter(Boolean) as SecurityRequirementObject[]\n\n const target = getTarget()\n\n const newSelectedSecuritySchemes = [...selectedRequirements, ...createdSchemes]\n\n const getSelectedIndex = () => {\n if (!target?.selectedIndex) {\n return 0\n }\n\n if (target.selectedIndex >= newSelectedSecuritySchemes.length) {\n return newSelectedSecuritySchemes.length - 1\n }\n\n return target.selectedIndex\n }\n\n // if (payload. === 'document') {\n if (meta.type === 'document') {\n return store?.auth.setAuthSelectedSchemas(\n { type: 'document', documentName },\n { selectedIndex: getSelectedIndex(), selectedSchemes: newSelectedSecuritySchemes },\n )\n }\n return store?.auth.setAuthSelectedSchemas(\n { type: 'operation', documentName, path: meta.path, method: meta.method },\n { selectedIndex: getSelectedIndex(), selectedSchemes: newSelectedSecuritySchemes },\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\nconst updateSecuritySchemeSecrets = (\n store: WorkspaceStore | null,\n document: WorkspaceDocument | null,\n { payload, name }: AuthEvents['auth:update:security-scheme-secrets'],\n) => {\n const documentName = document?.['x-scalar-navigation']?.name\n if (!documentName) {\n return\n }\n\n const auth = store?.auth.getAuthSecrets(documentName, name)\n const result = mergeObjects(unpackProxyObject(auth, { depth: 1 }) ?? {}, payload) as typeof payload\n store?.auth.setAuthSecrets(documentName, name, result as any)\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 store: WorkspaceStore | null,\n document: WorkspaceDocument | null,\n { index, meta }: AuthEvents['auth:update:active-index'],\n) => {\n const documentName = document?.['x-scalar-navigation']?.name\n if (!documentName) {\n return\n }\n\n // Ensure the path/method exists in the document\n if (meta.type === 'operation' && document?.paths?.[meta.path]?.[meta.method] === undefined) {\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 store?.auth.getAuthSelectedSchemas({ type: 'document', documentName })\n }\n return store?.auth.getAuthSelectedSchemas({ type: 'operation', documentName, path: meta.path, method: meta.method })\n }\n\n const target = getTarget()\n\n if (!target) {\n if (meta.type === 'document') {\n return store?.auth.setAuthSelectedSchemas(\n { type: 'document', documentName },\n { selectedIndex: index, selectedSchemes: [] },\n )\n }\n return store?.auth.setAuthSelectedSchemas(\n { type: 'operation', documentName, path: meta.path, method: meta.method },\n { selectedIndex: index, selectedSchemes: [] },\n )\n }\n\n // Set the selected index\n target.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. Also allow to add a new scope to the scheme.\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 newScopePayload - The payload to add a new scope with\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 store: WorkspaceStore | null,\n document: WorkspaceDocument | null,\n { id, name, scopes, newScopePayload, meta }: AuthEvents['auth:update:selected-scopes'],\n) => {\n const documentName = document?.['x-scalar-navigation']?.name\n if (!documentName) {\n return\n }\n\n // Determine the target object (document or the operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return store?.auth.getAuthSelectedSchemas({ type: 'document', documentName })\n }\n return store?.auth.getAuthSelectedSchemas({ type: 'operation', documentName, path: meta.path, method: meta.method })\n }\n\n const target = getTarget()\n if (!target) {\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 = target.selectedSchemes.find((scheme) => JSON.stringify(Object.keys(scheme)) === JSON.stringify(id))\n\n // If the scheme is optional, do nothing as it cannot have scopes\n if (!isNonOptionalSecurityRequirement(scheme)) {\n return\n }\n\n // If we have a new scope payload, add it to the scheme\n if (newScopePayload) {\n const securityScheme = getResolvedRef(document.components?.securitySchemes?.[name])\n const flow = (securityScheme as OAuth2Object)?.flows?.[newScopePayload?.flowType]\n if (!flow) {\n return\n }\n flow.scopes ||= {}\n\n flow.scopes[newScopePayload.name] = newScopePayload.description\n scheme[name] = [...scopes, newScopePayload.name]\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 store: WorkspaceStore | null,\n document: WorkspaceDocument | null,\n { names }: AuthEvents['auth:delete:security-scheme'],\n) => {\n const documentName = document?.['x-scalar-navigation']?.name\n if (!documentName) {\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 const documentSelectedSecurity = store?.auth.getAuthSelectedSchemas({ type: 'document', documentName })\n\n // -- Remove from document-level `x-scalar-selected-security` extension, if present\n if (documentSelectedSecurity) {\n documentSelectedSecurity.selectedSchemes = filterSecuritySchemes(\n unpackProxyObject(documentSelectedSecurity.selectedSchemes, { depth: 1 }) ?? [],\n )\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.entries(document.paths ?? {}).forEach(([path, pathItemObject]) => {\n Object.entries(pathItemObject).forEach(([method, 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 const operationSelectedSecurity = store?.auth.getAuthSelectedSchemas({\n type: 'operation',\n documentName,\n path,\n method,\n })\n if (operationSelectedSecurity) {\n operationSelectedSecurity.selectedSchemes = filterSecuritySchemes(\n unpackProxyObject(operationSelectedSecurity.selectedSchemes, { depth: 1 }) ?? [],\n )\n }\n })\n })\n}\n\nexport const authMutatorsFactory = ({\n document,\n store,\n}: {\n document: WorkspaceDocument | null\n store: WorkspaceStore | null\n}) => {\n return {\n updateSelectedSecuritySchemes: (payload: AuthEvents['auth:update:selected-security-schemes']) =>\n updateSelectedSecuritySchemes(store, document, payload),\n updateSecurityScheme: (payload: AuthEvents['auth:update:security-scheme']) =>\n updateSecurityScheme(document, payload),\n updateSecuritySchemeSecrets: (payload: AuthEvents['auth:update:security-scheme-secrets']) =>\n updateSecuritySchemeSecrets(store, document, payload),\n updateSelectedAuthTab: (payload: AuthEvents['auth:update:active-index']) =>\n updateSelectedAuthTab(store, document, payload),\n updateSelectedScopes: (payload: AuthEvents['auth:update:selected-scopes']) =>\n updateSelectedScopes(store, document, payload),\n deleteSecurityScheme: (payload: AuthEvents['auth:delete:security-scheme']) =>\n deleteSecurityScheme(store, document, payload),\n }\n}\n"],
5
+ "mappings": "AAEA,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,wCAAwC;AACjD,SAAS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,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,cAAc,MAAM;AACvE,WAAO,QAAQ,cAAc,EAAE,QAAQ,CAAC,CAAC,QAAQ,SAAS,MAAM;AAC9D,UAAI,OAAO,cAAc,UAAU;AAEjC;AAAA,MACF;AAGA,YAAM,oBAAoB,eAAe,SAAS;AAGlD,UAAI,cAAc,qBAAqB,kBAAkB,UAAU,GAAG;AACpE,0BAAkB,UAAU,IAAI,sBAAsB,kBAAkB,UAAU,CAAC;AAAA,MACrF;AAGA,YAAM,4BAA4B,OAAO,KAAK,uBAAuB;AAAA,QACnE,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AACD,UAAI,2BAA2B;AAC7B,kCAA0B,kBAAkB;AAAA,UAC1C,kBAAkB,0BAA0B,iBAAiB,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC;AAAA,QACjF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;AAEO,MAAM,sBAAsB,CAAC;AAAA,EAClC;AAAA,EACA;AACF,MAGM;AACJ,SAAO;AAAA,IACL,+BAA+B,CAAC,YAC9B,8BAA8B,OAAO,UAAU,OAAO;AAAA,IACxD,sBAAsB,CAAC,YACrB,qBAAqB,UAAU,OAAO;AAAA,IACxC,6BAA6B,CAAC,YAC5B,4BAA4B,OAAO,UAAU,OAAO;AAAA,IACtD,uBAAuB,CAAC,YACtB,sBAAsB,OAAO,UAAU,OAAO;AAAA,IAChD,sBAAsB,CAAC,YACrB,qBAAqB,OAAO,UAAU,OAAO;AAAA,IAC/C,sBAAsB,CAAC,YACrB,qBAAqB,OAAO,UAAU,OAAO;AAAA,EACjD;AACF;",
6
6
  "names": ["scheme"]
7
7
  }
@@ -63,12 +63,8 @@ export declare function generateClientMutators(store: WorkspaceStore | null): {
63
63
  active: () => {
64
64
  auth: {
65
65
  updateSelectedSecuritySchemes: (payload: import("../events/definitions/auth.js").AuthEvents["auth:update:selected-security-schemes"]) => Promise<void>;
66
- updateSecurityScheme: (payload: import("../events/definitions/auth.js").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 | ({
67
- description?: string;
68
- } & {
69
- type: "openIdConnect";
70
- openIdConnectUrl: string;
71
- }) | undefined;
66
+ updateSecurityScheme: (payload: import("../events/definitions/auth.js").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
+ updateSecuritySchemeSecrets: (payload: import("../events/definitions/auth.js").AuthEvents["auth:update:security-scheme-secrets"]) => void;
72
68
  updateSelectedAuthTab: (payload: import("../events/definitions/auth.js").AuthEvents["auth:update:active-index"]) => void;
73
69
  updateSelectedScopes: (payload: import("../events/definitions/auth.js").AuthEvents["auth:update:selected-scopes"]) => void;
74
70
  deleteSecurityScheme: (payload: import("../events/definitions/auth.js").AuthEvents["auth:delete:security-scheme"]) => void;
@@ -146,12 +142,8 @@ export declare function generateClientMutators(store: WorkspaceStore | null): {
146
142
  doc: (name: string) => {
147
143
  auth: {
148
144
  updateSelectedSecuritySchemes: (payload: import("../events/definitions/auth.js").AuthEvents["auth:update:selected-security-schemes"]) => Promise<void>;
149
- updateSecurityScheme: (payload: import("../events/definitions/auth.js").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 | ({
150
- description?: string;
151
- } & {
152
- type: "openIdConnect";
153
- openIdConnectUrl: string;
154
- }) | undefined;
145
+ updateSecurityScheme: (payload: import("../events/definitions/auth.js").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;
146
+ updateSecuritySchemeSecrets: (payload: import("../events/definitions/auth.js").AuthEvents["auth:update:security-scheme-secrets"]) => void;
155
147
  updateSelectedAuthTab: (payload: import("../events/definitions/auth.js").AuthEvents["auth:update:active-index"]) => void;
156
148
  updateSelectedScopes: (payload: import("../events/definitions/auth.js").AuthEvents["auth:update:selected-scopes"]) => void;
157
149
  deleteSecurityScheme: (payload: import("../events/definitions/auth.js").AuthEvents["auth:delete:security-scheme"]) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mutators/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAa9C;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAqC/D;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;;;OAIG;gBACS,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAErB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mutators/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAa9C;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAqC/D;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;;;OAIG;gBACS,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAErB"}
@@ -11,7 +11,7 @@ import { workspaceMutatorsFactory } from "../mutators/workspace.js";
11
11
  function generateClientMutators(store) {
12
12
  const documentMutators = (document) => {
13
13
  return {
14
- auth: authMutatorsFactory({ document }),
14
+ auth: authMutatorsFactory({ store, document }),
15
15
  cookie: cookieMutatorsFactory({ collection: document }),
16
16
  document: documentMutatorsFactory({ document, store }),
17
17
  operation: operationMutatorsFactory({ document, store }),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mutators/index.ts"],
4
- "sourcesContent": ["import type { WorkspaceStore } from '@/client'\nimport { authMutatorsFactory } from '@/mutators/auth'\nimport { cookieMutatorsFactory } from '@/mutators/cookie'\nimport { documentMutatorsFactory } from '@/mutators/document'\nimport { environmentMutatorsFactory } from '@/mutators/environment'\nimport { getDocument } from '@/mutators/helpers'\nimport { operationMutatorsFactory } from '@/mutators/operation'\nimport { serverMutatorsFactory } from '@/mutators/server'\nimport { tabsMutatorsFactory } from '@/mutators/tabs'\nimport { tagMutatorsFactory } from '@/mutators/tag'\nimport { workspaceMutatorsFactory } from '@/mutators/workspace'\nimport type { WorkspaceDocument } from '@/schemas'\n\n/**\n * Generates a set of mutators for managing OpenAPI document and workspace state.\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 | null) {\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 = (document: WorkspaceDocument | null) => {\n return {\n auth: authMutatorsFactory({ document }),\n cookie: cookieMutatorsFactory({ collection: document }),\n document: documentMutatorsFactory({ document, store }),\n operation: operationMutatorsFactory({ document, store }),\n server: serverMutatorsFactory({ document }),\n tag: tagMutatorsFactory({ store }),\n environment: environmentMutatorsFactory({ workspace: store?.workspace ?? null, collection: document }),\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 return {\n cookie: cookieMutatorsFactory({ collection: store?.workspace ?? null }),\n tabs: tabsMutatorsFactory({ workspace: store?.workspace ?? null }),\n workspace: workspaceMutatorsFactory({ workspace: store?.workspace ?? null }),\n environment: environmentMutatorsFactory({\n workspace: store?.workspace ?? null,\n collection: store?.workspace ?? null,\n }),\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: () => documentMutators(store?.workspace.activeDocument ?? null),\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(getDocument(store, name)),\n }\n}\n"],
5
- "mappings": "AACA,SAAS,2BAA2B;AACpC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,kCAAkC;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,gCAAgC;AASlC,SAAS,uBAAuB,OAA8B;AAOnE,QAAM,mBAAmB,CAAC,aAAuC;AAC/D,WAAO;AAAA,MACL,MAAM,oBAAoB,EAAE,SAAS,CAAC;AAAA,MACtC,QAAQ,sBAAsB,EAAE,YAAY,SAAS,CAAC;AAAA,MACtD,UAAU,wBAAwB,EAAE,UAAU,MAAM,CAAC;AAAA,MACrD,WAAW,yBAAyB,EAAE,UAAU,MAAM,CAAC;AAAA,MACvD,QAAQ,sBAAsB,EAAE,SAAS,CAAC;AAAA,MAC1C,KAAK,mBAAmB,EAAE,MAAM,CAAC;AAAA,MACjC,aAAa,2BAA2B,EAAE,WAAW,OAAO,aAAa,MAAM,YAAY,SAAS,CAAC;AAAA,IACvG;AAAA,EACF;AAOA,QAAM,oBAAoB,MAAM;AAC9B,WAAO;AAAA,MACL,QAAQ,sBAAsB,EAAE,YAAY,OAAO,aAAa,KAAK,CAAC;AAAA,MACtE,MAAM,oBAAoB,EAAE,WAAW,OAAO,aAAa,KAAK,CAAC;AAAA,MACjE,WAAW,yBAAyB,EAAE,WAAW,OAAO,aAAa,KAAK,CAAC;AAAA,MAC3E,aAAa,2BAA2B;AAAA,QACtC,WAAW,OAAO,aAAa;AAAA,QAC/B,YAAY,OAAO,aAAa;AAAA,MAClC,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AAAA;AAAA;AAAA;AAAA,IAIL,WAAW,MAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,IAKnC,QAAQ,MAAM,iBAAiB,OAAO,UAAU,kBAAkB,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMtE,KAAK,CAAC,SAAiB,iBAAiB,YAAY,OAAO,IAAI,CAAC;AAAA,EAClE;AACF;",
4
+ "sourcesContent": ["import type { WorkspaceStore } from '@/client'\nimport { authMutatorsFactory } from '@/mutators/auth'\nimport { cookieMutatorsFactory } from '@/mutators/cookie'\nimport { documentMutatorsFactory } from '@/mutators/document'\nimport { environmentMutatorsFactory } from '@/mutators/environment'\nimport { getDocument } from '@/mutators/helpers'\nimport { operationMutatorsFactory } from '@/mutators/operation'\nimport { serverMutatorsFactory } from '@/mutators/server'\nimport { tabsMutatorsFactory } from '@/mutators/tabs'\nimport { tagMutatorsFactory } from '@/mutators/tag'\nimport { workspaceMutatorsFactory } from '@/mutators/workspace'\nimport type { WorkspaceDocument } from '@/schemas'\n\n/**\n * Generates a set of mutators for managing OpenAPI document and workspace state.\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 | null) {\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 = (document: WorkspaceDocument | null) => {\n return {\n auth: authMutatorsFactory({ store, document }),\n cookie: cookieMutatorsFactory({ collection: document }),\n document: documentMutatorsFactory({ document, store }),\n operation: operationMutatorsFactory({ document, store }),\n server: serverMutatorsFactory({ document }),\n tag: tagMutatorsFactory({ store }),\n environment: environmentMutatorsFactory({ workspace: store?.workspace ?? null, collection: document }),\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 return {\n cookie: cookieMutatorsFactory({ collection: store?.workspace ?? null }),\n tabs: tabsMutatorsFactory({ workspace: store?.workspace ?? null }),\n workspace: workspaceMutatorsFactory({ workspace: store?.workspace ?? null }),\n environment: environmentMutatorsFactory({\n workspace: store?.workspace ?? null,\n collection: store?.workspace ?? null,\n }),\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: () => documentMutators(store?.workspace.activeDocument ?? null),\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(getDocument(store, name)),\n }\n}\n"],
5
+ "mappings": "AACA,SAAS,2BAA2B;AACpC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,kCAAkC;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,gCAAgC;AASlC,SAAS,uBAAuB,OAA8B;AAOnE,QAAM,mBAAmB,CAAC,aAAuC;AAC/D,WAAO;AAAA,MACL,MAAM,oBAAoB,EAAE,OAAO,SAAS,CAAC;AAAA,MAC7C,QAAQ,sBAAsB,EAAE,YAAY,SAAS,CAAC;AAAA,MACtD,UAAU,wBAAwB,EAAE,UAAU,MAAM,CAAC;AAAA,MACrD,WAAW,yBAAyB,EAAE,UAAU,MAAM,CAAC;AAAA,MACvD,QAAQ,sBAAsB,EAAE,SAAS,CAAC;AAAA,MAC1C,KAAK,mBAAmB,EAAE,MAAM,CAAC;AAAA,MACjC,aAAa,2BAA2B,EAAE,WAAW,OAAO,aAAa,MAAM,YAAY,SAAS,CAAC;AAAA,IACvG;AAAA,EACF;AAOA,QAAM,oBAAoB,MAAM;AAC9B,WAAO;AAAA,MACL,QAAQ,sBAAsB,EAAE,YAAY,OAAO,aAAa,KAAK,CAAC;AAAA,MACtE,MAAM,oBAAoB,EAAE,WAAW,OAAO,aAAa,KAAK,CAAC;AAAA,MACjE,WAAW,yBAAyB,EAAE,WAAW,OAAO,aAAa,KAAK,CAAC;AAAA,MAC3E,aAAa,2BAA2B;AAAA,QACtC,WAAW,OAAO,aAAa;AAAA,QAC/B,YAAY,OAAO,aAAa;AAAA,MAClC,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AAAA;AAAA;AAAA;AAAA,IAIL,WAAW,MAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,IAKnC,QAAQ,MAAM,iBAAiB,OAAO,UAAU,kBAAkB,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMtE,KAAK,CAAC,SAAiB,iBAAiB,YAAY,OAAO,IAAI,CAAC;AAAA,EAClE;AACF;",
6
6
  "names": []
7
7
  }
@@ -179,8 +179,8 @@ export declare const updateOperationRequestBodyExample: (document: WorkspaceDocu
179
179
  * This needs special handling as we store it as an array of objects with a schema type of object
180
180
  */
181
181
  export declare const updateOperationRequestBodyFormValue: (document: WorkspaceDocument | null, { meta, payload, contentType }: OperationEvents["operation:update:requestBody:formValue"]) => void;
182
- export declare const addResponseToHistory: (document: WorkspaceDocument | null, { payload, meta }: HooksEvents["hooks:on:request:complete"]) => Promise<void>;
183
- export declare const reloadOperationHistory: (document: WorkspaceDocument | null, { meta, index, callback }: OperationEvents["operation:reload:history"]) => void;
182
+ export declare const addResponseToHistory: (store: WorkspaceStore | null, document: WorkspaceDocument | null, { payload, meta }: HooksEvents["hooks:on:request:complete"]) => Promise<void>;
183
+ export declare const reloadOperationHistory: (store: WorkspaceStore | null, document: WorkspaceDocument | null, { meta, index, callback }: OperationEvents["operation:reload:history"]) => void;
184
184
  export declare const operationMutatorsFactory: ({ document, store, }: {
185
185
  document: WorkspaceDocument | null;
186
186
  store: WorkspaceStore | null;
@@ -1 +1 @@
1
- {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/mutators/operation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AASrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AA+GlD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,GAC1B,gBAAgB,cAAc,GAAG,IAAI,EACrC,SAAS,eAAe,CAAC,4BAA4B,CAAC,KACrD,MAAM,GAAG,SAkDX,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB,GACjC,UAAU,iBAAiB,GAAG,IAAI,EAClC,gCAAgC,eAAe,CAAC,0BAA0B,CAAC,SAY5E,CAAA;AAwDD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,yBAAyB,GACpC,UAAU,iBAAiB,GAAG,IAAI,EAClC,OAAO,cAAc,GAAG,IAAI,EAC5B,+CAA+C,eAAe,CAAC,6BAA6B,CAAC,KA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AC;iDAE/D,eAAe,CAAC,oCAAoC,CAAC;mDAEnD,eAAe,CAAC,wCAAwC,CAAC;oCAExE,WAAW,CAAC,2BAA2B,CAAC;sCAEtC,eAAe,CAAC,0BAA0B,CAAC;CAGhF,CAAA"}
@@ -204,7 +204,7 @@ const updateOperationPathMethod = (document, store, { meta, payload: { method, p
204
204
  delete document.paths[meta.path];
205
205
  }
206
206
  }
207
- delete operation["x-scalar-history"];
207
+ store.history.clearOperationHistory(document["x-scalar-navigation"]?.name ?? "", meta.path, meta.method);
208
208
  callback("success");
209
209
  };
210
210
  const deleteOperation = (workspace, { meta, documentName }) => {
@@ -392,9 +392,9 @@ const updateOperationRequestBodyFormValue = (document, { meta, payload, contentT
392
392
  }
393
393
  example.value = unpackProxyObject(payload, { depth: 3 });
394
394
  };
395
- const HISTORY_LIMIT = 5;
396
- const addResponseToHistory = async (document, { payload, meta }) => {
397
- if (!document || !payload) {
395
+ const addResponseToHistory = async (store, document, { payload, meta }) => {
396
+ const documentName = document?.["x-scalar-navigation"]?.name;
397
+ if (!document || !documentName || !payload) {
398
398
  return;
399
399
  }
400
400
  const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
@@ -414,14 +414,7 @@ const addResponseToHistory = async (document, { payload, meta }) => {
414
414
  }, {});
415
415
  const requestHar = await fetchRequestToHar({ request: payload.request });
416
416
  const responseHar = await fetchResponseToHar({ response: payload.response });
417
- operation["x-scalar-history"] ||= [];
418
- if (operation["x-scalar-history"].length >= HISTORY_LIMIT) {
419
- operation["x-scalar-history"] = unpackProxyObject(
420
- operation["x-scalar-history"].filter((_, i) => i !== 0),
421
- { depth: 1 }
422
- );
423
- }
424
- operation["x-scalar-history"].push({
417
+ store?.history.addHistory(documentName, meta.path, meta.method, {
425
418
  response: responseHar,
426
419
  request: requestHar,
427
420
  meta: {
@@ -434,7 +427,7 @@ const addResponseToHistory = async (document, { payload, meta }) => {
434
427
  }
435
428
  });
436
429
  };
437
- const reloadOperationHistory = (document, { meta, index, callback }) => {
430
+ const reloadOperationHistory = (store, document, { meta, index, callback }) => {
438
431
  if (!document) {
439
432
  console.error("Document not found", meta.path, meta.method);
440
433
  return;
@@ -444,7 +437,7 @@ const reloadOperationHistory = (document, { meta, index, callback }) => {
444
437
  console.error("Operation not found", meta.path, meta.method);
445
438
  return;
446
439
  }
447
- const historyItem = operation["x-scalar-history"]?.[index];
440
+ const historyItem = store?.history.getHistory(document["x-scalar-navigation"]?.name ?? "", meta.path, meta.method)?.[index];
448
441
  if (!historyItem) {
449
442
  console.error("History item not found", index);
450
443
  return;
@@ -474,8 +467,8 @@ const operationMutatorsFactory = ({
474
467
  updateOperationRequestBodyContentType: (payload) => updateOperationRequestBodyContentType(document, payload),
475
468
  updateOperationRequestBodyExample: (payload) => updateOperationRequestBodyExample(document, payload),
476
469
  updateOperationRequestBodyFormValue: (payload) => updateOperationRequestBodyFormValue(document, payload),
477
- addResponseToHistory: (payload) => addResponseToHistory(document, payload),
478
- reloadOperationHistory: (payload) => reloadOperationHistory(document, payload)
470
+ addResponseToHistory: (payload) => addResponseToHistory(store, document, payload),
471
+ reloadOperationHistory: (payload) => reloadOperationHistory(store, document, payload)
479
472
  };
480
473
  };
481
474
  export {