@scalar/oas-utils 0.10.8 → 0.10.10

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 (129) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/entities/cookie/cookie.js +11 -15
  3. package/dist/entities/cookie/index.js +1 -5
  4. package/dist/entities/environment/environment.js +7 -11
  5. package/dist/entities/environment/index.js +1 -5
  6. package/dist/entities/hotkeys/hotkeys.js +116 -111
  7. package/dist/entities/hotkeys/index.js +1 -6
  8. package/dist/entities/shared/index.js +1 -7
  9. package/dist/entities/shared/utility.js +9 -9
  10. package/dist/entities/spec/collection.js +91 -89
  11. package/dist/entities/spec/index.js +10 -59
  12. package/dist/entities/spec/operation.js +6 -6
  13. package/dist/entities/spec/parameters.js +38 -38
  14. package/dist/entities/spec/request-examples.js +421 -331
  15. package/dist/entities/spec/requests.js +102 -84
  16. package/dist/entities/spec/server.js +61 -46
  17. package/dist/entities/spec/spec-objects.js +121 -76
  18. package/dist/entities/spec/x-scalar-environments.js +18 -20
  19. package/dist/entities/spec/x-scalar-secrets.js +6 -8
  20. package/dist/entities/workspace/index.js +1 -7
  21. package/dist/entities/workspace/workspace.js +47 -46
  22. package/dist/helpers/client-plugins.js +13 -13
  23. package/dist/helpers/fetch-document.js +30 -25
  24. package/dist/helpers/fetch-with-proxy-fallback.js +26 -21
  25. package/dist/helpers/index.d.ts +1 -2
  26. package/dist/helpers/index.d.ts.map +1 -1
  27. package/dist/helpers/index.js +80 -119
  28. package/dist/helpers/normalize-mime-type-object.js +19 -18
  29. package/dist/helpers/normalize-mime-type.js +11 -9
  30. package/dist/helpers/operation-stability.js +25 -20
  31. package/dist/helpers/parse.d.ts +0 -4
  32. package/dist/helpers/parse.d.ts.map +1 -1
  33. package/dist/helpers/parse.js +77 -77
  34. package/dist/helpers/schema-model.js +13 -16
  35. package/dist/helpers/security/get-schemes.js +7 -8
  36. package/dist/helpers/security/has-token.js +18 -19
  37. package/dist/helpers/security/index.js +2 -7
  38. package/dist/helpers/servers.js +128 -79
  39. package/dist/helpers/should-ignore-entity.js +4 -5
  40. package/dist/migrations/data-version.js +15 -7
  41. package/dist/migrations/generate-types.js +34 -37
  42. package/dist/migrations/index.js +4 -18
  43. package/dist/migrations/local-storage.js +31 -29
  44. package/dist/migrations/migrate-to-indexdb.js +706 -529
  45. package/dist/migrations/migrator.js +58 -54
  46. package/dist/migrations/semver.js +24 -24
  47. package/dist/migrations/v-0.0.0/types.generated.js +1 -1
  48. package/dist/migrations/v-2.1.0/migration.js +272 -258
  49. package/dist/migrations/v-2.1.0/types.generated.js +1 -1
  50. package/dist/migrations/v-2.2.0/migration.js +99 -96
  51. package/dist/migrations/v-2.2.0/types.generated.js +1 -1
  52. package/dist/migrations/v-2.3.0/migration.js +45 -48
  53. package/dist/migrations/v-2.3.0/types.generated.js +1 -1
  54. package/dist/migrations/v-2.4.0/migration.js +25 -25
  55. package/dist/migrations/v-2.4.0/types.generated.js +1 -1
  56. package/dist/migrations/v-2.5.0/migration.js +122 -139
  57. package/dist/migrations/v-2.5.0/types.generated.js +1 -1
  58. package/dist/spec-getters/get-example-from-schema.js +489 -385
  59. package/dist/spec-getters/get-parameters-from-operation.js +39 -23
  60. package/dist/spec-getters/get-request-body-from-operation.d.ts.map +1 -1
  61. package/dist/spec-getters/get-request-body-from-operation.js +168 -126
  62. package/dist/spec-getters/get-server-variable-examples.js +10 -13
  63. package/dist/spec-getters/index.js +4 -11
  64. package/dist/transforms/import-spec.js +381 -291
  65. package/dist/transforms/index.js +1 -11
  66. package/package.json +15 -19
  67. package/dist/entities/cookie/cookie.js.map +0 -7
  68. package/dist/entities/cookie/index.js.map +0 -7
  69. package/dist/entities/environment/environment.js.map +0 -7
  70. package/dist/entities/environment/index.js.map +0 -7
  71. package/dist/entities/hotkeys/hotkeys.js.map +0 -7
  72. package/dist/entities/hotkeys/index.js.map +0 -7
  73. package/dist/entities/shared/index.js.map +0 -7
  74. package/dist/entities/shared/utility.js.map +0 -7
  75. package/dist/entities/spec/collection.js.map +0 -7
  76. package/dist/entities/spec/index.js.map +0 -7
  77. package/dist/entities/spec/operation.js.map +0 -7
  78. package/dist/entities/spec/parameters.js.map +0 -7
  79. package/dist/entities/spec/request-examples.js.map +0 -7
  80. package/dist/entities/spec/requests.js.map +0 -7
  81. package/dist/entities/spec/server.js.map +0 -7
  82. package/dist/entities/spec/spec-objects.js.map +0 -7
  83. package/dist/entities/spec/x-scalar-environments.js.map +0 -7
  84. package/dist/entities/spec/x-scalar-secrets.js.map +0 -7
  85. package/dist/entities/workspace/index.js.map +0 -7
  86. package/dist/entities/workspace/workspace.js.map +0 -7
  87. package/dist/helpers/client-plugins.js.map +0 -7
  88. package/dist/helpers/fetch-document.js.map +0 -7
  89. package/dist/helpers/fetch-with-proxy-fallback.js.map +0 -7
  90. package/dist/helpers/index.js.map +0 -7
  91. package/dist/helpers/normalize-mime-type-object.js.map +0 -7
  92. package/dist/helpers/normalize-mime-type.js.map +0 -7
  93. package/dist/helpers/operation-stability.js.map +0 -7
  94. package/dist/helpers/parse.js.map +0 -7
  95. package/dist/helpers/pretty-print-json.d.ts +0 -9
  96. package/dist/helpers/pretty-print-json.d.ts.map +0 -1
  97. package/dist/helpers/pretty-print-json.js +0 -38
  98. package/dist/helpers/pretty-print-json.js.map +0 -7
  99. package/dist/helpers/schema-model.js.map +0 -7
  100. package/dist/helpers/security/get-schemes.js.map +0 -7
  101. package/dist/helpers/security/has-token.js.map +0 -7
  102. package/dist/helpers/security/index.js.map +0 -7
  103. package/dist/helpers/servers.js.map +0 -7
  104. package/dist/helpers/should-ignore-entity.js.map +0 -7
  105. package/dist/migrations/data-version.js.map +0 -7
  106. package/dist/migrations/generate-types.js.map +0 -7
  107. package/dist/migrations/index.js.map +0 -7
  108. package/dist/migrations/local-storage.js.map +0 -7
  109. package/dist/migrations/migrate-to-indexdb.js.map +0 -7
  110. package/dist/migrations/migrator.js.map +0 -7
  111. package/dist/migrations/semver.js.map +0 -7
  112. package/dist/migrations/v-0.0.0/types.generated.js.map +0 -7
  113. package/dist/migrations/v-2.1.0/migration.js.map +0 -7
  114. package/dist/migrations/v-2.1.0/types.generated.js.map +0 -7
  115. package/dist/migrations/v-2.2.0/migration.js.map +0 -7
  116. package/dist/migrations/v-2.2.0/types.generated.js.map +0 -7
  117. package/dist/migrations/v-2.3.0/migration.js.map +0 -7
  118. package/dist/migrations/v-2.3.0/types.generated.js.map +0 -7
  119. package/dist/migrations/v-2.4.0/migration.js.map +0 -7
  120. package/dist/migrations/v-2.4.0/types.generated.js.map +0 -7
  121. package/dist/migrations/v-2.5.0/migration.js.map +0 -7
  122. package/dist/migrations/v-2.5.0/types.generated.js.map +0 -7
  123. package/dist/spec-getters/get-example-from-schema.js.map +0 -7
  124. package/dist/spec-getters/get-parameters-from-operation.js.map +0 -7
  125. package/dist/spec-getters/get-request-body-from-operation.js.map +0 -7
  126. package/dist/spec-getters/get-server-variable-examples.js.map +0 -7
  127. package/dist/spec-getters/index.js.map +0 -7
  128. package/dist/transforms/import-spec.js.map +0 -7
  129. package/dist/transforms/index.js.map +0 -7
@@ -1,266 +1,280 @@
1
- import { capitalize } from "@scalar/helpers/string/capitalize";
2
- import { camelToTitleWords } from "@scalar/helpers/string/camel-to-title";
3
- import { parseLocalStorage } from "../../migrations/local-storage.js";
4
- const migrate_v_2_1_0 = (data) => {
5
- console.info("Performing data migration v-0.0.0 to v-2.1.0");
6
- const oldData = {
7
- ...data,
8
- // @ts-expect-error Tags used to be called folders
9
- folders: parseLocalStorage("folder")
10
- };
11
- const flattenChildren = (childUids) => childUids.reduce(
12
- (prev, uid) => {
13
- const request = oldData.requests[uid];
14
- if (request) {
15
- prev.requestUids.add(uid);
16
- request.securitySchemeUids?.forEach((s) => prev.authUids.add(s));
17
- } else if (oldData.folders[uid]) {
18
- const { requestUids, tagUids, authUids } = flattenChildren(oldData.folders[uid].childUids ?? []);
19
- prev.tagUids.add(uid);
20
- requestUids.forEach((r) => prev.requestUids.add(r));
21
- tagUids.forEach((t) => prev.tagUids.add(t));
22
- authUids.forEach((a) => prev.authUids.add(a));
23
- }
24
- return prev;
25
- },
26
- {
27
- requestUids: /* @__PURE__ */ new Set(),
28
- tagUids: /* @__PURE__ */ new Set(),
29
- authUids: /* @__PURE__ */ new Set()
30
- }
31
- );
32
- const migrateAuth = (scheme) => {
33
- if (scheme.type === "apiKey") {
34
- return { type: "apiKey", name: scheme.name, value: scheme.value ?? "" };
35
- }
36
- if (scheme.type === "http") {
37
- return {
38
- type: "http",
39
- username: scheme.value ?? "",
40
- password: scheme.secondValue ?? "",
41
- token: scheme.value ?? ""
42
- };
43
- }
44
- if (scheme.type === "oauth2" && scheme.flow.type === "implicit") {
45
- return {
46
- type: "oauth-implicit",
47
- token: scheme.flow.token ?? ""
48
- };
49
- }
50
- if (scheme.type === "oauth2" && scheme.flow.type === "password") {
51
- return {
52
- type: "oauth-password",
53
- token: scheme.flow.token ?? "",
54
- username: scheme.flow.value ?? "",
55
- password: scheme.flow.secondValue ?? "",
56
- clientSecret: scheme.flow.clientSecret ?? ""
57
- };
58
- }
59
- if (scheme.type === "oauth2" && scheme.flow.type === "clientCredentials") {
60
- return {
61
- type: "oauth-clientCredentials",
62
- token: scheme.flow.token ?? "",
63
- clientSecret: scheme.flow.clientSecret ?? ""
64
- };
65
- }
66
- if (scheme.type === "oauth2" && scheme.flow.type === "authorizationCode") {
67
- return {
68
- type: "oauth-authorizationCode",
69
- token: scheme.flow.token ?? "",
70
- clientSecret: scheme.flow.clientSecret ?? ""
71
- };
72
- }
73
- return {
74
- type: "apiKey",
75
- name: "",
76
- value: ""
1
+ import { capitalize } from '@scalar/helpers/string/capitalize';
2
+ import { camelToTitleWords } from '@scalar/helpers/string/camel-to-title';
3
+ import { parseLocalStorage } from '../../migrations/local-storage.js';
4
+ /** V-0.0.0 to V-2.1.0 migration */
5
+ export const migrate_v_2_1_0 = (data) => {
6
+ console.info('Performing data migration v-0.0.0 to v-2.1.0');
7
+ // Augment the previous data
8
+ const oldData = {
9
+ ...data,
10
+ // @ts-expect-error Tags used to be called folders
11
+ folders: parseLocalStorage('folder'),
77
12
  };
78
- };
79
- const requestSecurityDict = {};
80
- const collections = Object.values(oldData.collections ?? {}).reduce((prev, c) => {
81
- const { requestUids, tagUids, authUids } = flattenChildren(c.childUids ?? []);
82
- const securitySchemesSet = /* @__PURE__ */ new Set([...authUids, ...Object.values(c.securitySchemeDict ?? {})]);
83
- const securitySchemes2 = [...securitySchemesSet];
84
- requestUids.forEach((r) => requestSecurityDict[r] = securitySchemes2);
85
- const auth = securitySchemes2.reduce(
86
- (_prev, uid) => {
87
- const scheme = oldData.securitySchemes[uid];
88
- if (scheme?.uid && _prev) {
89
- _prev[uid] = migrateAuth(scheme);
13
+ /** To grab requests and tags we must traverse children, also for security */
14
+ const flattenChildren = (childUids) => childUids.reduce((prev, uid) => {
15
+ const request = oldData.requests[uid];
16
+ // Request
17
+ if (request) {
18
+ prev.requestUids.add(uid);
19
+ // Security
20
+ request.securitySchemeUids?.forEach((s) => prev.authUids.add(s));
21
+ }
22
+ // Folder -> tag
23
+ else if (oldData.folders[uid]) {
24
+ const { requestUids, tagUids, authUids } = flattenChildren(oldData.folders[uid].childUids ?? []);
25
+ prev.tagUids.add(uid);
26
+ requestUids.forEach((r) => prev.requestUids.add(r));
27
+ tagUids.forEach((t) => prev.tagUids.add(t));
28
+ authUids.forEach((a) => prev.authUids.add(a));
29
+ }
30
+ return prev;
31
+ }, {
32
+ requestUids: new Set(),
33
+ tagUids: new Set(),
34
+ authUids: new Set(),
35
+ });
36
+ /** Migrate values from old securitySchemes to the new auth */
37
+ const migrateAuth = (scheme) => {
38
+ if (scheme.type === 'apiKey') {
39
+ // ApiKey
40
+ return { type: 'apiKey', name: scheme.name, value: scheme.value ?? '' };
41
+ }
42
+ // HTTP
43
+ if (scheme.type === 'http') {
44
+ return {
45
+ type: 'http',
46
+ username: scheme.value ?? '',
47
+ password: scheme.secondValue ?? '',
48
+ token: scheme.value ?? '',
49
+ };
50
+ }
51
+ // Oauth2 Implicit
52
+ if (scheme.type === 'oauth2' && scheme.flow.type === 'implicit') {
53
+ return {
54
+ type: 'oauth-implicit',
55
+ token: scheme.flow.token ?? '',
56
+ };
57
+ }
58
+ // Oauth2 Password
59
+ if (scheme.type === 'oauth2' && scheme.flow.type === 'password') {
60
+ return {
61
+ type: 'oauth-password',
62
+ token: scheme.flow.token ?? '',
63
+ username: scheme.flow.value ?? '',
64
+ password: scheme.flow.secondValue ?? '',
65
+ clientSecret: scheme.flow.clientSecret ?? '',
66
+ };
67
+ }
68
+ // Oauth2 clientCredentials
69
+ if (scheme.type === 'oauth2' && scheme.flow.type === 'clientCredentials') {
70
+ return {
71
+ type: 'oauth-clientCredentials',
72
+ token: scheme.flow.token ?? '',
73
+ clientSecret: scheme.flow.clientSecret ?? '',
74
+ };
75
+ }
76
+ // Oauth2 Authorization Code
77
+ if (scheme.type === 'oauth2' && scheme.flow.type === 'authorizationCode') {
78
+ return {
79
+ type: 'oauth-authorizationCode',
80
+ token: scheme.flow.token ?? '',
81
+ clientSecret: scheme.flow.clientSecret ?? '',
82
+ };
90
83
  }
91
- return _prev;
92
- },
93
- {}
94
- );
95
- prev[c.uid] = {
96
- "type": "collection",
97
- "openapi": c.spec?.openapi || "3.1.0",
98
- "info": c.spec?.info || { title: "OpenAPI Spec", version: "0.0.1" },
99
- "security": c.spec?.security || [],
100
- "externalDocs": c.spec?.externalDocs,
101
- "uid": c.uid,
102
- securitySchemes: securitySchemes2,
103
- "selectedSecuritySchemeUids": [],
104
- "selectedServerUid": c.selectedServerUid || c.spec?.serverUids?.[0] || "",
105
- "servers": c.spec?.serverUids || [],
106
- "requests": [...requestUids],
107
- "tags": [...tagUids],
108
- auth,
109
- "children": c.childUids || [],
110
- "x-scalar-icon": "interface-content-folder",
111
- "watchMode": false,
112
- "watchModeStatus": "IDLE"
84
+ // Default - should not get hit
85
+ return {
86
+ type: 'apiKey',
87
+ name: '',
88
+ value: '',
89
+ };
113
90
  };
114
- return prev;
115
- }, {});
116
- const cookies = oldData.cookies ?? {};
117
- const environments = Object.values(oldData.environments ?? {}).reduce(
118
- (prev, e) => {
119
- prev[e.uid] = {
120
- ...e,
121
- value: e.raw ?? ""
122
- };
123
- return prev;
124
- },
125
- {}
126
- );
127
- const requests = Object.values(oldData.requests ?? {}).reduce((prev, r) => {
128
- const parameters = [
129
- ...Object.values(r.parameters?.path ?? {}),
130
- ...Object.values(r.parameters?.query ?? {}),
131
- ...Object.values(r.parameters?.headers ?? {}),
132
- ...Object.values(r.parameters?.cookies ?? {})
133
- ].filter((p) => p);
134
- const selectedSecuritySchemeUids = (r.selectedSecuritySchemeUids || []).filter(
135
- (s) => requestSecurityDict[r.uid]?.includes(s)
136
- );
137
- prev[r.uid] = {
138
- ...r,
139
- parameters,
140
- type: "request",
141
- method: r.method?.toLowerCase() ?? "get",
142
- examples: r.childUids || [],
143
- selectedSecuritySchemeUids,
144
- selectedServerUid: "",
145
- servers: []
91
+ /** This is needed due to our previous data being poluted, we will only allow auth on a requst which is in the spec */
92
+ const requestSecurityDict = {};
93
+ // Collections
94
+ const collections = Object.values(oldData.collections ?? {}).reduce((prev, c) => {
95
+ const { requestUids, tagUids, authUids } = flattenChildren(c.childUids ?? []);
96
+ // Ensure we got unique uids
97
+ const securitySchemesSet = new Set([...authUids, ...Object.values(c.securitySchemeDict ?? {})]);
98
+ const securitySchemes = [...securitySchemesSet];
99
+ // Add this auth to each request
100
+ requestUids.forEach((r) => (requestSecurityDict[r] = securitySchemes));
101
+ // Migrate auth
102
+ const auth = securitySchemes.reduce((_prev, uid) => {
103
+ const scheme = oldData.securitySchemes[uid];
104
+ if (scheme?.uid && _prev) {
105
+ _prev[uid] = migrateAuth(scheme);
106
+ }
107
+ return _prev;
108
+ }, {});
109
+ prev[c.uid] = {
110
+ 'type': 'collection',
111
+ 'openapi': c.spec?.openapi || '3.1.0',
112
+ 'info': c.spec?.info || { title: 'OpenAPI Spec', version: '0.0.1' },
113
+ 'security': c.spec?.security || [],
114
+ 'externalDocs': c.spec?.externalDocs,
115
+ 'uid': c.uid,
116
+ securitySchemes,
117
+ 'selectedSecuritySchemeUids': [],
118
+ 'selectedServerUid': c.selectedServerUid || c.spec?.serverUids?.[0] || '',
119
+ 'servers': c.spec?.serverUids || [],
120
+ 'requests': [...requestUids],
121
+ 'tags': [...tagUids],
122
+ auth,
123
+ 'children': c.childUids || [],
124
+ 'x-scalar-icon': 'interface-content-folder',
125
+ 'watchMode': false,
126
+ 'watchModeStatus': 'IDLE',
127
+ };
128
+ return prev;
129
+ }, {});
130
+ // Cookies
131
+ const cookies = oldData.cookies ?? {};
132
+ // Environments
133
+ const environments = Object.values(oldData.environments ?? {}).reduce((prev, e) => {
134
+ prev[e.uid] = {
135
+ ...e,
136
+ value: e.raw ?? '',
137
+ };
138
+ return prev;
139
+ }, {});
140
+ // Requests
141
+ const requests = Object.values(oldData.requests ?? {}).reduce((prev, r) => {
142
+ // Convert parameters
143
+ const parameters = [
144
+ ...Object.values(r.parameters?.path ?? {}),
145
+ ...Object.values(r.parameters?.query ?? {}),
146
+ ...Object.values(r.parameters?.headers ?? {}),
147
+ ...Object.values(r.parameters?.cookies ?? {}),
148
+ ].filter((p) => p);
149
+ // Ensure this request can access these schemes
150
+ const selectedSecuritySchemeUids = (r.selectedSecuritySchemeUids || []).filter((s) => requestSecurityDict[r.uid]?.includes(s));
151
+ prev[r.uid] = {
152
+ ...r,
153
+ parameters,
154
+ type: 'request',
155
+ method: r.method?.toLowerCase() ?? 'get',
156
+ examples: r.childUids || [],
157
+ selectedSecuritySchemeUids,
158
+ selectedServerUid: '',
159
+ servers: [],
160
+ };
161
+ return prev;
162
+ }, {});
163
+ // Request Examples
164
+ const requestExamples = Object.values(oldData.requestExamples ?? {}).reduce((prev, e) => {
165
+ prev[e.uid] = {
166
+ ...e,
167
+ type: 'requestExample',
168
+ };
169
+ return prev;
170
+ }, {});
171
+ /** Specifically handle each oauth2 flow */
172
+ const migrateFlow = (flow) => {
173
+ const base = {
174
+ refreshUrl: flow.refreshUrl || '',
175
+ selectedScopes: flow.selectedScopes || [],
176
+ scopes: flow.scopes || {},
177
+ };
178
+ if (flow.type === 'implicit') {
179
+ return {
180
+ ...flow,
181
+ ...base,
182
+ 'type': 'implicit',
183
+ 'x-scalar-redirect-uri': ('redirectUri' in flow ? flow.redirectUri : '') || '',
184
+ };
185
+ }
186
+ if (flow.type === 'password') {
187
+ return {
188
+ ...flow,
189
+ ...base,
190
+ tokenUrl: flow.tokenUrl || '',
191
+ };
192
+ }
193
+ if (flow.type === 'clientCredentials') {
194
+ return {
195
+ ...flow,
196
+ ...base,
197
+ tokenUrl: flow.tokenUrl || '',
198
+ };
199
+ }
200
+ return {
201
+ ...flow,
202
+ ...base,
203
+ 'x-usePkce': 'no',
204
+ 'x-scalar-redirect-uri': ('redirectUri' in flow ? flow.redirectUri : '') || '',
205
+ 'authorizationUrl': flow.authorizationUrl || '',
206
+ 'tokenUrl': flow.tokenUrl || '',
207
+ };
146
208
  };
147
- return prev;
148
- }, {});
149
- const requestExamples = Object.values(oldData.requestExamples ?? {}).reduce(
150
- (prev, e) => {
151
- prev[e.uid] = {
152
- ...e,
153
- type: "requestExample"
154
- };
155
- return prev;
156
- },
157
- {}
158
- );
159
- const migrateFlow = (flow) => {
160
- const base = {
161
- refreshUrl: flow.refreshUrl || "",
162
- selectedScopes: flow.selectedScopes || [],
163
- scopes: flow.scopes || {}
209
+ /** Generate a nameKey based on the type of oauth */
210
+ const getNameKey = (scheme) => {
211
+ switch (scheme?.type) {
212
+ case 'apiKey':
213
+ return `${capitalize(scheme.in)}`;
214
+ case 'http': {
215
+ return `${capitalize(scheme.scheme)} Authentication`;
216
+ }
217
+ case 'oauth2':
218
+ return camelToTitleWords(scheme.flow.type);
219
+ case 'openIdConnect':
220
+ return 'Open ID Connect';
221
+ default:
222
+ return 'None';
223
+ }
164
224
  };
165
- if (flow.type === "implicit") {
166
- return {
167
- ...flow,
168
- ...base,
169
- "type": "implicit",
170
- "x-scalar-redirect-uri": ("redirectUri" in flow ? flow.redirectUri : "") || ""
171
- };
172
- }
173
- if (flow.type === "password") {
174
- return {
175
- ...flow,
176
- ...base,
177
- tokenUrl: flow.tokenUrl || ""
178
- };
179
- }
180
- if (flow.type === "clientCredentials") {
181
- return {
182
- ...flow,
183
- ...base,
184
- tokenUrl: flow.tokenUrl || ""
185
- };
186
- }
225
+ // Security Schemes
226
+ const securitySchemes = Object.values(oldData.securitySchemes ?? {}).reduce((prev, s) => {
227
+ prev[s.uid] =
228
+ s.type === 'oauth2'
229
+ ? {
230
+ ...s,
231
+ 'nameKey': getNameKey(s),
232
+ 'x-scalar-client-id': s.clientId || '',
233
+ 'flow': migrateFlow(s.flow),
234
+ }
235
+ : { ...s, nameKey: getNameKey(s) };
236
+ return prev;
237
+ }, {});
238
+ // Servers
239
+ const servers = Object.values(oldData.servers ?? {}).reduce((prev, s) => {
240
+ prev[s.uid] = {
241
+ ...s,
242
+ variables: s.variables ?? {},
243
+ };
244
+ return prev;
245
+ }, {});
246
+ // Tags
247
+ const tags = Object.values(oldData.folders ?? {}).reduce((prev, f) => {
248
+ prev[f.uid] = {
249
+ 'type': 'tag',
250
+ 'uid': f.uid,
251
+ 'name': f.name || 'unknownTag',
252
+ 'description': f.description,
253
+ 'children': f.childUids || [],
254
+ 'x-scalar-children': [],
255
+ };
256
+ return prev;
257
+ }, {});
258
+ // Workspaces
259
+ const workspaces = Object.values(oldData.workspaces ?? {}).reduce((prev, w) => {
260
+ prev[w.uid] = {
261
+ ...w,
262
+ description: w.description ?? 'Basic Scalar Workspace',
263
+ cookies: w.cookieUids || [],
264
+ collections: w.collectionUids || [],
265
+ environments: w.environmentUids || [],
266
+ };
267
+ return prev;
268
+ }, {});
187
269
  return {
188
- ...flow,
189
- ...base,
190
- "x-usePkce": "no",
191
- "x-scalar-redirect-uri": ("redirectUri" in flow ? flow.redirectUri : "") || "",
192
- "authorizationUrl": flow.authorizationUrl || "",
193
- "tokenUrl": flow.tokenUrl || ""
270
+ collections,
271
+ cookies,
272
+ environments,
273
+ requestExamples,
274
+ requests,
275
+ securitySchemes,
276
+ servers,
277
+ tags,
278
+ workspaces,
194
279
  };
195
- };
196
- const getNameKey = (scheme) => {
197
- switch (scheme?.type) {
198
- case "apiKey":
199
- return `${capitalize(scheme.in)}`;
200
- case "http": {
201
- return `${capitalize(scheme.scheme)} Authentication`;
202
- }
203
- case "oauth2":
204
- return camelToTitleWords(scheme.flow.type);
205
- case "openIdConnect":
206
- return "Open ID Connect";
207
- default:
208
- return "None";
209
- }
210
- };
211
- const securitySchemes = Object.values(oldData.securitySchemes ?? {}).reduce(
212
- (prev, s) => {
213
- prev[s.uid] = s.type === "oauth2" ? {
214
- ...s,
215
- "nameKey": getNameKey(s),
216
- "x-scalar-client-id": s.clientId || "",
217
- "flow": migrateFlow(s.flow)
218
- } : { ...s, nameKey: getNameKey(s) };
219
- return prev;
220
- },
221
- {}
222
- );
223
- const servers = Object.values(oldData.servers ?? {}).reduce((prev, s) => {
224
- prev[s.uid] = {
225
- ...s,
226
- variables: s.variables ?? {}
227
- };
228
- return prev;
229
- }, {});
230
- const tags = Object.values(oldData.folders ?? {}).reduce((prev, f) => {
231
- prev[f.uid] = {
232
- "type": "tag",
233
- "uid": f.uid,
234
- "name": f.name || "unknownTag",
235
- "description": f.description,
236
- "children": f.childUids || [],
237
- "x-scalar-children": []
238
- };
239
- return prev;
240
- }, {});
241
- const workspaces = Object.values(oldData.workspaces ?? {}).reduce((prev, w) => {
242
- prev[w.uid] = {
243
- ...w,
244
- description: w.description ?? "Basic Scalar Workspace",
245
- cookies: w.cookieUids || [],
246
- collections: w.collectionUids || [],
247
- environments: w.environmentUids || []
248
- };
249
- return prev;
250
- }, {});
251
- return {
252
- collections,
253
- cookies,
254
- environments,
255
- requestExamples,
256
- requests,
257
- securitySchemes,
258
- servers,
259
- tags,
260
- workspaces
261
- };
262
- };
263
- export {
264
- migrate_v_2_1_0
265
280
  };
266
- //# sourceMappingURL=migration.js.map
@@ -1 +1 @@
1
- //# sourceMappingURL=types.generated.js.map
1
+ export {};