@scalar/oas-utils 0.2.101 → 0.2.103
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 +23 -0
- package/dist/entities/shared/index.d.ts +1 -1
- package/dist/entities/shared/index.d.ts.map +1 -1
- package/dist/entities/shared/index.js +1 -1
- package/dist/entities/shared/utility.d.ts +3 -0
- package/dist/entities/shared/utility.d.ts.map +1 -1
- package/dist/entities/shared/utility.js +6 -1
- package/dist/entities/spec/collection.d.ts +6 -6
- package/dist/entities/spec/collection.d.ts.map +1 -1
- package/dist/entities/spec/collection.js +2 -2
- package/dist/entities/spec/index.d.ts +1 -0
- package/dist/entities/spec/index.d.ts.map +1 -1
- package/dist/entities/spec/index.js +1 -0
- package/dist/entities/spec/operation.d.ts +243 -0
- package/dist/entities/spec/operation.d.ts.map +1 -0
- package/dist/entities/spec/operation.js +9 -0
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +5 -3
- package/dist/entities/spec/requests.d.ts +3 -3
- package/dist/entities/spec/requests.d.ts.map +1 -1
- package/dist/entities/spec/requests.js +2 -2
- package/dist/helpers/ensure-protocol.d.ts +3 -0
- package/dist/helpers/ensure-protocol.d.ts.map +1 -0
- package/dist/helpers/ensure-protocol.js +12 -0
- package/dist/helpers/index.d.ts +2 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +2 -1
- package/dist/helpers/merge-urls.d.ts +15 -0
- package/dist/helpers/merge-urls.d.ts.map +1 -0
- package/dist/helpers/merge-urls.js +72 -0
- package/dist/helpers/redirectToProxy.d.ts.map +1 -1
- package/dist/helpers/redirectToProxy.js +5 -0
- package/dist/helpers/regexHelpers.d.ts +2 -0
- package/dist/helpers/regexHelpers.d.ts.map +1 -1
- package/dist/helpers/regexHelpers.js +2 -0
- package/dist/migrations/data-version.d.ts +2 -1
- package/dist/migrations/data-version.d.ts.map +1 -1
- package/dist/migrations/data-version.js +2 -1
- package/dist/migrations/migrator.d.ts +2 -2
- package/dist/migrations/migrator.d.ts.map +1 -1
- package/dist/migrations/migrator.js +4 -0
- package/dist/migrations/v-2.4.0/types.generated.d.ts +363 -24
- package/dist/migrations/v-2.4.0/types.generated.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/index.d.ts +3 -0
- package/dist/migrations/v-2.5.0/index.d.ts.map +1 -0
- package/dist/migrations/v-2.5.0/index.js +1 -0
- package/dist/migrations/v-2.5.0/migration.d.ts +5 -0
- package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -0
- package/dist/migrations/v-2.5.0/migration.js +46 -0
- package/dist/migrations/v-2.5.0/types.generated.d.ts +38 -0
- package/dist/migrations/v-2.5.0/types.generated.d.ts.map +1 -0
- package/dist/transforms/import-spec.d.ts +5 -0
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +54 -30
- package/dist/transforms/index.js +1 -1
- package/package.json +11 -6
- package/dist/helpers/concatenateUrlAndPath.d.ts +0 -5
- package/dist/helpers/concatenateUrlAndPath.d.ts.map +0 -1
- package/dist/helpers/concatenateUrlAndPath.js +0 -17
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** V-2.4.0 to V-2.5.0 migration */
|
|
2
|
+
const migrate_v_2_5_0 = (data) => {
|
|
3
|
+
console.info('Performing data migration v-2.4.0 to v-2.5.0');
|
|
4
|
+
const requestExamples = Object.entries(data.requestExamples || {}).reduce((acc, [key, example]) => {
|
|
5
|
+
const headers = example.parameters.headers;
|
|
6
|
+
// Check if "Accept" header exists
|
|
7
|
+
const hasAcceptHeader = headers.some((header) => header.key.toLowerCase() === 'accept');
|
|
8
|
+
if (!hasAcceptHeader) {
|
|
9
|
+
// Add "Accept" header as the first entry
|
|
10
|
+
headers.unshift({ key: 'Accept', value: '*/*', enabled: true });
|
|
11
|
+
}
|
|
12
|
+
// Update the example with potentially modified headers
|
|
13
|
+
acc[key] = {
|
|
14
|
+
...example,
|
|
15
|
+
parameters: {
|
|
16
|
+
...example.parameters,
|
|
17
|
+
headers,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
return acc;
|
|
21
|
+
}, {});
|
|
22
|
+
const servers = Object.entries(data.servers || {}).reduce((acc, [key, server]) => {
|
|
23
|
+
acc[key] = {
|
|
24
|
+
...server,
|
|
25
|
+
variables: Object.entries(server.variables || {}).reduce((variablesAcc, [variableKey, variable]) => {
|
|
26
|
+
variablesAcc[variableKey] = {
|
|
27
|
+
...variable,
|
|
28
|
+
enum: variable.enum && variable.enum.length > 0
|
|
29
|
+
? variable.enum
|
|
30
|
+
: undefined,
|
|
31
|
+
default: variable.default ?? '',
|
|
32
|
+
description: variable.description,
|
|
33
|
+
};
|
|
34
|
+
return variablesAcc;
|
|
35
|
+
}, {}),
|
|
36
|
+
};
|
|
37
|
+
return acc;
|
|
38
|
+
}, {});
|
|
39
|
+
return {
|
|
40
|
+
...data,
|
|
41
|
+
requestExamples,
|
|
42
|
+
servers,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { migrate_v_2_5_0 };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Cookie as Ck } from '../../entities/cookie/index.js';
|
|
2
|
+
import type { Environment as E } from '../../entities/environment/index.js';
|
|
3
|
+
import type { Collection as Co, Request as R, RequestExample as RE, Server as S, SecurityScheme as SS, Tag as T } from '../../entities/spec/index.js';
|
|
4
|
+
import type { Workspace as W } from '../../entities/workspace/index.js';
|
|
5
|
+
export declare namespace v_2_5_0 {
|
|
6
|
+
type Cookie = Ck;
|
|
7
|
+
type Environment = E;
|
|
8
|
+
type Collection = Co;
|
|
9
|
+
type Request = R;
|
|
10
|
+
type RequestExample = RE;
|
|
11
|
+
type SecurityScheme = SS;
|
|
12
|
+
type Server = S;
|
|
13
|
+
type Tag = T;
|
|
14
|
+
type Workspace = W;
|
|
15
|
+
type DataRecord = {
|
|
16
|
+
collections: Record<string, Collection>;
|
|
17
|
+
cookies: Record<string, Cookie>;
|
|
18
|
+
environments: Record<string, Environment>;
|
|
19
|
+
requestExamples: Record<string, RequestExample>;
|
|
20
|
+
requests: Record<string, Request>;
|
|
21
|
+
securitySchemes: Record<string, SecurityScheme>;
|
|
22
|
+
servers: Record<string, Server>;
|
|
23
|
+
tags: Record<string, Tag>;
|
|
24
|
+
workspaces: Record<string, Workspace>;
|
|
25
|
+
};
|
|
26
|
+
type DataArray = {
|
|
27
|
+
collections: Collection[];
|
|
28
|
+
cookies: Cookie[];
|
|
29
|
+
environments: Environment[];
|
|
30
|
+
requestExamples: RequestExample[];
|
|
31
|
+
requests: Request[];
|
|
32
|
+
securitySchemes: SecurityScheme[];
|
|
33
|
+
servers: Server[];
|
|
34
|
+
tags: Tag[];
|
|
35
|
+
workspaces: Workspace[];
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=types.generated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.generated.d.ts","sourceRoot":"","sources":["../../../src/migrations/v-2.5.0/types.generated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,EAAE,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,IAAI,CAAC,EAAE,MAAM,wBAAwB,CAAA;AAC9D,OAAO,KAAK,EACV,UAAU,IAAI,EAAE,EAChB,OAAO,IAAI,CAAC,EACZ,cAAc,IAAI,EAAE,EACpB,MAAM,IAAI,CAAC,EACX,cAAc,IAAI,EAAE,EACpB,GAAG,IAAI,CAAC,EACT,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,SAAS,IAAI,CAAC,EAAE,MAAM,sBAAsB,CAAA;AAE1D,yBAAiB,OAAO,CAAC;IACvB,KAAY,MAAM,GAAG,EAAE,CAAA;IACvB,KAAY,WAAW,GAAG,CAAC,CAAA;IAC3B,KAAY,UAAU,GAAG,EAAE,CAAA;IAC3B,K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shared/utility.js';
|
|
1
2
|
import { type Collection, type CollectionPayload, type Request, type RequestExample, type Server, type Tag } from '../entities/spec/index.js';
|
|
2
3
|
import { type SecurityScheme } from '../entities/spec/security.js';
|
|
3
4
|
import type { OpenAPIV3_1 } from '@scalar/openapi-types';
|
|
@@ -14,6 +15,10 @@ export declare const parseSchema: (spec: string | UnknownObject, { shouldLoad }?
|
|
|
14
15
|
schema: OpenAPIV3_1.Document;
|
|
15
16
|
errors: import("@scalar/openapi-parser").ErrorObject[];
|
|
16
17
|
}>;
|
|
18
|
+
/** Converts selected security requirements to uids */
|
|
19
|
+
export declare const getSelectedSecuritySchemeUids: (securityRequirements: SelectedSecuritySchemeUids, authentication: {
|
|
20
|
+
preferredSecurityScheme?: string | null;
|
|
21
|
+
} | undefined, securitySchemeMap: Record<string, string>) => SelectedSecuritySchemeUids;
|
|
17
22
|
export type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' | 'watchMode'> & Pick<ReferenceConfiguration, 'authentication' | 'baseServerURL' | 'servers'> & {
|
|
18
23
|
/** Sets the preferred security scheme on the collection instead of the requests */
|
|
19
24
|
setCollectionSecurity?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,EAMT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,0BAA0B,CAAA;AAWjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,mFAAmF;AACnF,eAAO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B,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,eAAe,EAAE,cAAc,EAAE,CAAA;CAClC,GACD;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,cAAc,EAAE,MAAM,EAAE,CAAA;CAAE,CAC5C,CA4UA;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,WAAW,CAAC,YAAY,EAAE,GAAG,SAAS,EAC/C,EAAE,aAAa,EAAE,GAAE,IAAI,CAAC,sBAAsB,EAAE,eAAe,CAAM,GACpE,MAAM,EAAE,CA8CV"}
|
|
@@ -4,12 +4,12 @@ import { schemaModel } from '../helpers/schema-model.js';
|
|
|
4
4
|
import { keysOf } from '@scalar/object-utils/arrays';
|
|
5
5
|
import { load, upgrade, dereference } from '@scalar/openapi-parser';
|
|
6
6
|
import { serverSchema } from '../entities/spec/server.js';
|
|
7
|
+
import { isDefined } from '../helpers/is-defined.js';
|
|
7
8
|
import { requestSchema } from '../entities/spec/requests.js';
|
|
8
9
|
import { tagSchema } from '../entities/spec/spec-objects.js';
|
|
9
10
|
import { createExampleFromRequest } from '../entities/spec/request-examples.js';
|
|
10
11
|
import { collectionSchema } from '../entities/spec/collection.js';
|
|
11
|
-
import {
|
|
12
|
-
import { isDefined } from '../helpers/is-defined.js';
|
|
12
|
+
import { combineUrlAndPath } from '../helpers/merge-urls.js';
|
|
13
13
|
|
|
14
14
|
/** Takes a string or object and parses it into an openapi spec compliant schema */
|
|
15
15
|
const parseSchema = async (spec, { shouldLoad = true } = {}) => {
|
|
@@ -50,6 +50,17 @@ const parseSchema = async (spec, { shouldLoad = true } = {}) => {
|
|
|
50
50
|
errors: [...loadErrors, ...derefErrors],
|
|
51
51
|
};
|
|
52
52
|
};
|
|
53
|
+
/** Converts selected security requirements to uids */
|
|
54
|
+
const getSelectedSecuritySchemeUids = (securityRequirements, authentication, securitySchemeMap) => {
|
|
55
|
+
const name = authentication?.preferredSecurityScheme &&
|
|
56
|
+
securityRequirements.includes(authentication.preferredSecurityScheme)
|
|
57
|
+
? authentication.preferredSecurityScheme
|
|
58
|
+
: securityRequirements[0];
|
|
59
|
+
const uids = Array.isArray(name)
|
|
60
|
+
? name.map((k) => securitySchemeMap[k])
|
|
61
|
+
: securitySchemeMap[name];
|
|
62
|
+
return [uids];
|
|
63
|
+
};
|
|
53
64
|
/**
|
|
54
65
|
* Imports an OpenAPI document and converts it to workspace entities (Collection, Request, Server, etc.)
|
|
55
66
|
*
|
|
@@ -76,6 +87,13 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
76
87
|
const servers = getServersFromOpenApiDocument(configuredServers || schema.servers, {
|
|
77
88
|
baseServerURL,
|
|
78
89
|
});
|
|
90
|
+
// Fallback to the current window.location.origin if no servers are provided
|
|
91
|
+
if (!servers.length) {
|
|
92
|
+
const fallbackUrl = getFallbackUrl();
|
|
93
|
+
if (fallbackUrl) {
|
|
94
|
+
servers.push(serverSchema.parse({ url: fallbackUrl }));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
79
97
|
/**
|
|
80
98
|
* List of all tag strings. For non compliant specs we may need to
|
|
81
99
|
* add top level tag objects for missing tag objects
|
|
@@ -169,26 +187,18 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
169
187
|
operation.tags?.forEach((t) => tagNames.add(t));
|
|
170
188
|
// Remove security here and add it correctly below
|
|
171
189
|
const { security: operationSecurity, ...operationWithoutSecurity } = operation;
|
|
172
|
-
// Grab the security requirements for this operation
|
|
173
190
|
const securityRequirements = (operationSecurity ??
|
|
174
191
|
schema.security ??
|
|
175
|
-
[])
|
|
192
|
+
[])
|
|
193
|
+
.map((s) => {
|
|
176
194
|
const keys = Object.keys(s);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return [];
|
|
181
|
-
});
|
|
182
|
-
let selectedSecuritySchemeUids = [];
|
|
195
|
+
return keys.length > 1 ? keys : keys[0];
|
|
196
|
+
})
|
|
197
|
+
.filter(isDefined);
|
|
183
198
|
// Set the initially selected security scheme
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
? authentication.preferredSecurityScheme
|
|
188
|
-
: securityRequirements[0];
|
|
189
|
-
const uid = securitySchemeMap[name];
|
|
190
|
-
selectedSecuritySchemeUids = [uid];
|
|
191
|
-
}
|
|
199
|
+
const selectedSecuritySchemeUids = securityRequirements.length && !setCollectionSecurity
|
|
200
|
+
? getSelectedSecuritySchemeUids(securityRequirements, authentication, securitySchemeMap)
|
|
201
|
+
: [];
|
|
192
202
|
const requestPayload = {
|
|
193
203
|
...operationWithoutSecurity,
|
|
194
204
|
method,
|
|
@@ -278,14 +288,15 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
278
288
|
});
|
|
279
289
|
// ---------------------------------------------------------------------------
|
|
280
290
|
// Generate Collection
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
291
|
+
// Grab the security requirements for this operation
|
|
292
|
+
const securityRequirements = (schema.security ?? []).map((s) => {
|
|
293
|
+
const keys = Object.keys(s);
|
|
294
|
+
return keys.length > 1 ? keys : keys[0];
|
|
295
|
+
});
|
|
296
|
+
// Set the initially selected security scheme
|
|
297
|
+
const selectedSecuritySchemeUids = securityRequirements.length && setCollectionSecurity
|
|
298
|
+
? getSelectedSecuritySchemeUids(securityRequirements, authentication, securitySchemeMap)
|
|
299
|
+
: [];
|
|
289
300
|
const collection = collectionSchema.parse({
|
|
290
301
|
...schema,
|
|
291
302
|
watchMode,
|
|
@@ -334,12 +345,13 @@ function getServersFromOpenApiDocument(servers, { baseServerURL } = {}) {
|
|
|
334
345
|
if (parsedSchema?.url?.startsWith('/')) {
|
|
335
346
|
// Use the base server URL (if provided)
|
|
336
347
|
if (baseServerURL) {
|
|
337
|
-
parsedSchema.url =
|
|
348
|
+
parsedSchema.url = combineUrlAndPath(baseServerURL, parsedSchema.url);
|
|
338
349
|
return parsedSchema;
|
|
339
350
|
}
|
|
340
351
|
// Fallback to the current window origin
|
|
341
|
-
|
|
342
|
-
|
|
352
|
+
const fallbackUrl = getFallbackUrl();
|
|
353
|
+
if (fallbackUrl) {
|
|
354
|
+
parsedSchema.url = combineUrlAndPath(fallbackUrl, parsedSchema.url.replace(/^\//, ''));
|
|
343
355
|
return parsedSchema;
|
|
344
356
|
}
|
|
345
357
|
}
|
|
@@ -356,5 +368,17 @@ function getServersFromOpenApiDocument(servers, { baseServerURL } = {}) {
|
|
|
356
368
|
})
|
|
357
369
|
.filter(isDefined);
|
|
358
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Fallback to the current window.location.origin, if available
|
|
373
|
+
*/
|
|
374
|
+
function getFallbackUrl() {
|
|
375
|
+
if (typeof window === 'undefined') {
|
|
376
|
+
return undefined;
|
|
377
|
+
}
|
|
378
|
+
if (typeof window?.location?.origin !== 'string') {
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
381
|
+
return window.location.origin;
|
|
382
|
+
}
|
|
359
383
|
|
|
360
|
-
export { getServersFromOpenApiDocument, importSpecToWorkspace, parseSchema };
|
|
384
|
+
export { getSelectedSecuritySchemeUids, getServersFromOpenApiDocument, importSpecToWorkspace, parseSchema };
|
package/dist/transforms/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { getServersFromOpenApiDocument, importSpecToWorkspace, parseSchema } from './import-spec.js';
|
|
1
|
+
export { getSelectedSecuritySchemeUids, getServersFromOpenApiDocument, importSpecToWorkspace, parseSchema } from './import-spec.js';
|
|
2
2
|
export { exportSpecFromWorkspace } from './export-spec.js';
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.103",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
"types": "./dist/migrations/index.d.ts",
|
|
39
39
|
"default": "./dist/migrations/index.js"
|
|
40
40
|
},
|
|
41
|
+
"./migrations/v-2.5.0": {
|
|
42
|
+
"import": "./dist/migrations/v-2.5.0/index.js",
|
|
43
|
+
"types": "./dist/migrations/v-2.5.0/index.d.ts",
|
|
44
|
+
"default": "./dist/migrations/v-2.5.0/index.js"
|
|
45
|
+
},
|
|
41
46
|
"./migrations/v-2.4.0": {
|
|
42
47
|
"import": "./dist/migrations/v-2.4.0/index.js",
|
|
43
48
|
"types": "./dist/migrations/v-2.4.0/index.d.ts",
|
|
@@ -122,18 +127,18 @@
|
|
|
122
127
|
"yaml": "^2.4.5",
|
|
123
128
|
"zod": "^3.23.8",
|
|
124
129
|
"@scalar/object-utils": "1.1.12",
|
|
125
|
-
"@scalar/openapi-types": "0.1.
|
|
126
|
-
"@scalar/themes": "0.9.
|
|
127
|
-
"@scalar/types": "0.0.
|
|
130
|
+
"@scalar/openapi-types": "0.1.7",
|
|
131
|
+
"@scalar/themes": "0.9.65",
|
|
132
|
+
"@scalar/types": "0.0.31"
|
|
128
133
|
},
|
|
129
134
|
"devDependencies": {
|
|
130
135
|
"type-fest": "^4.20.0",
|
|
131
136
|
"vite": "^5.4.10",
|
|
132
137
|
"vitest": "^1.6.0",
|
|
133
138
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
134
|
-
"@scalar/openapi-parser": "0.10.4",
|
|
135
139
|
"@scalar/build-tooling": "0.1.12",
|
|
136
|
-
"@scalar/openapi-
|
|
140
|
+
"@scalar/openapi-parser": "0.10.5",
|
|
141
|
+
"@scalar/openapi-types": "0.1.7"
|
|
137
142
|
},
|
|
138
143
|
"scripts": {
|
|
139
144
|
"build": "scalar-build-rollup",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"concatenateUrlAndPath.d.ts","sourceRoot":"","sources":["../../src/helpers/concatenateUrlAndPath.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB,QAAS,MAAM,SAAS,MAAM,WAc/D,CAAA"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Make sure the URL and path are concatenated correctly.
|
|
3
|
-
*/
|
|
4
|
-
const concatenateUrlAndPath = (url, path) => {
|
|
5
|
-
if (typeof path !== 'string' || !path.length) {
|
|
6
|
-
return url;
|
|
7
|
-
}
|
|
8
|
-
const trimmedUrl = url.trim();
|
|
9
|
-
const trimmedPath = path.trim();
|
|
10
|
-
const urlWithSlash = trimmedUrl.endsWith('/') ? trimmedUrl : `${trimmedUrl}/`;
|
|
11
|
-
const pathWithoutSlash = trimmedPath.startsWith('/')
|
|
12
|
-
? trimmedPath.slice(1)
|
|
13
|
-
: trimmedPath;
|
|
14
|
-
return [urlWithSlash, pathWithoutSlash].join('');
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export { concatenateUrlAndPath };
|