@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.
- package/CHANGELOG.md +8 -0
- package/dist/entities/cookie/cookie.js +11 -15
- package/dist/entities/cookie/index.js +1 -5
- package/dist/entities/environment/environment.js +7 -11
- package/dist/entities/environment/index.js +1 -5
- package/dist/entities/hotkeys/hotkeys.js +116 -111
- package/dist/entities/hotkeys/index.js +1 -6
- package/dist/entities/shared/index.js +1 -7
- package/dist/entities/shared/utility.js +9 -9
- package/dist/entities/spec/collection.js +91 -89
- package/dist/entities/spec/index.js +10 -59
- package/dist/entities/spec/operation.js +6 -6
- package/dist/entities/spec/parameters.js +38 -38
- package/dist/entities/spec/request-examples.js +421 -331
- package/dist/entities/spec/requests.js +102 -84
- package/dist/entities/spec/server.js +61 -46
- package/dist/entities/spec/spec-objects.js +121 -76
- package/dist/entities/spec/x-scalar-environments.js +18 -20
- package/dist/entities/spec/x-scalar-secrets.js +6 -8
- package/dist/entities/workspace/index.js +1 -7
- package/dist/entities/workspace/workspace.js +47 -46
- package/dist/helpers/client-plugins.js +13 -13
- package/dist/helpers/fetch-document.js +30 -25
- package/dist/helpers/fetch-with-proxy-fallback.js +26 -21
- package/dist/helpers/index.d.ts +1 -2
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +80 -119
- package/dist/helpers/normalize-mime-type-object.js +19 -18
- package/dist/helpers/normalize-mime-type.js +11 -9
- package/dist/helpers/operation-stability.js +25 -20
- package/dist/helpers/parse.d.ts +0 -4
- package/dist/helpers/parse.d.ts.map +1 -1
- package/dist/helpers/parse.js +77 -77
- package/dist/helpers/schema-model.js +13 -16
- package/dist/helpers/security/get-schemes.js +7 -8
- package/dist/helpers/security/has-token.js +18 -19
- package/dist/helpers/security/index.js +2 -7
- package/dist/helpers/servers.js +128 -79
- package/dist/helpers/should-ignore-entity.js +4 -5
- package/dist/migrations/data-version.js +15 -7
- package/dist/migrations/generate-types.js +34 -37
- package/dist/migrations/index.js +4 -18
- package/dist/migrations/local-storage.js +31 -29
- package/dist/migrations/migrate-to-indexdb.js +706 -529
- package/dist/migrations/migrator.js +58 -54
- package/dist/migrations/semver.js +24 -24
- package/dist/migrations/v-0.0.0/types.generated.js +1 -1
- package/dist/migrations/v-2.1.0/migration.js +272 -258
- package/dist/migrations/v-2.1.0/types.generated.js +1 -1
- package/dist/migrations/v-2.2.0/migration.js +99 -96
- package/dist/migrations/v-2.2.0/types.generated.js +1 -1
- package/dist/migrations/v-2.3.0/migration.js +45 -48
- package/dist/migrations/v-2.3.0/types.generated.js +1 -1
- package/dist/migrations/v-2.4.0/migration.js +25 -25
- package/dist/migrations/v-2.4.0/types.generated.js +1 -1
- package/dist/migrations/v-2.5.0/migration.js +122 -139
- package/dist/migrations/v-2.5.0/types.generated.js +1 -1
- package/dist/spec-getters/get-example-from-schema.js +489 -385
- package/dist/spec-getters/get-parameters-from-operation.js +39 -23
- package/dist/spec-getters/get-request-body-from-operation.d.ts.map +1 -1
- package/dist/spec-getters/get-request-body-from-operation.js +168 -126
- package/dist/spec-getters/get-server-variable-examples.js +10 -13
- package/dist/spec-getters/index.js +4 -11
- package/dist/transforms/import-spec.js +381 -291
- package/dist/transforms/index.js +1 -11
- package/package.json +15 -19
- package/dist/entities/cookie/cookie.js.map +0 -7
- package/dist/entities/cookie/index.js.map +0 -7
- package/dist/entities/environment/environment.js.map +0 -7
- package/dist/entities/environment/index.js.map +0 -7
- package/dist/entities/hotkeys/hotkeys.js.map +0 -7
- package/dist/entities/hotkeys/index.js.map +0 -7
- package/dist/entities/shared/index.js.map +0 -7
- package/dist/entities/shared/utility.js.map +0 -7
- package/dist/entities/spec/collection.js.map +0 -7
- package/dist/entities/spec/index.js.map +0 -7
- package/dist/entities/spec/operation.js.map +0 -7
- package/dist/entities/spec/parameters.js.map +0 -7
- package/dist/entities/spec/request-examples.js.map +0 -7
- package/dist/entities/spec/requests.js.map +0 -7
- package/dist/entities/spec/server.js.map +0 -7
- package/dist/entities/spec/spec-objects.js.map +0 -7
- package/dist/entities/spec/x-scalar-environments.js.map +0 -7
- package/dist/entities/spec/x-scalar-secrets.js.map +0 -7
- package/dist/entities/workspace/index.js.map +0 -7
- package/dist/entities/workspace/workspace.js.map +0 -7
- package/dist/helpers/client-plugins.js.map +0 -7
- package/dist/helpers/fetch-document.js.map +0 -7
- package/dist/helpers/fetch-with-proxy-fallback.js.map +0 -7
- package/dist/helpers/index.js.map +0 -7
- package/dist/helpers/normalize-mime-type-object.js.map +0 -7
- package/dist/helpers/normalize-mime-type.js.map +0 -7
- package/dist/helpers/operation-stability.js.map +0 -7
- package/dist/helpers/parse.js.map +0 -7
- package/dist/helpers/pretty-print-json.d.ts +0 -9
- package/dist/helpers/pretty-print-json.d.ts.map +0 -1
- package/dist/helpers/pretty-print-json.js +0 -38
- package/dist/helpers/pretty-print-json.js.map +0 -7
- package/dist/helpers/schema-model.js.map +0 -7
- package/dist/helpers/security/get-schemes.js.map +0 -7
- package/dist/helpers/security/has-token.js.map +0 -7
- package/dist/helpers/security/index.js.map +0 -7
- package/dist/helpers/servers.js.map +0 -7
- package/dist/helpers/should-ignore-entity.js.map +0 -7
- package/dist/migrations/data-version.js.map +0 -7
- package/dist/migrations/generate-types.js.map +0 -7
- package/dist/migrations/index.js.map +0 -7
- package/dist/migrations/local-storage.js.map +0 -7
- package/dist/migrations/migrate-to-indexdb.js.map +0 -7
- package/dist/migrations/migrator.js.map +0 -7
- package/dist/migrations/semver.js.map +0 -7
- package/dist/migrations/v-0.0.0/types.generated.js.map +0 -7
- package/dist/migrations/v-2.1.0/migration.js.map +0 -7
- package/dist/migrations/v-2.1.0/types.generated.js.map +0 -7
- package/dist/migrations/v-2.2.0/migration.js.map +0 -7
- package/dist/migrations/v-2.2.0/types.generated.js.map +0 -7
- package/dist/migrations/v-2.3.0/migration.js.map +0 -7
- package/dist/migrations/v-2.3.0/types.generated.js.map +0 -7
- package/dist/migrations/v-2.4.0/migration.js.map +0 -7
- package/dist/migrations/v-2.4.0/types.generated.js.map +0 -7
- package/dist/migrations/v-2.5.0/migration.js.map +0 -7
- package/dist/migrations/v-2.5.0/types.generated.js.map +0 -7
- package/dist/spec-getters/get-example-from-schema.js.map +0 -7
- package/dist/spec-getters/get-parameters-from-operation.js.map +0 -7
- package/dist/spec-getters/get-request-body-from-operation.js.map +0 -7
- package/dist/spec-getters/get-server-variable-examples.js.map +0 -7
- package/dist/spec-getters/index.js.map +0 -7
- package/dist/transforms/import-spec.js.map +0 -7
- package/dist/transforms/index.js.map +0 -7
|
@@ -1,266 +1,280 @@
|
|
|
1
|
-
import { capitalize } from
|
|
2
|
-
import { camelToTitleWords } from
|
|
3
|
-
import { parseLocalStorage } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
...
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
1
|
+
export {};
|