@scalar/oas-utils 0.2.124 → 0.2.126

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # @scalar/oas-utils
2
2
 
3
+ ## 0.2.126
4
+
5
+ ### Patch Changes
6
+
7
+ - a571d36: refactor: use central helper fetchDocument to fetch OpenAPI documents
8
+ - Updated dependencies [3783345]
9
+ - @scalar/types@0.1.6
10
+ - @scalar/themes@0.9.84
11
+
12
+ ## 0.2.125
13
+
14
+ ### Patch Changes
15
+
16
+ - e62e677: feat: make zod remove undefined values recursively
17
+ - 04e27a1: feat: support x-default-scopes
18
+ - 846d015: fix: add cap on horizontal expententially expanding bodys
19
+ - Updated dependencies [e62e677]
20
+ - Updated dependencies [e09dab3]
21
+ - Updated dependencies [82f16a5]
22
+ - Updated dependencies [04e27a1]
23
+ - @scalar/openapi-types@0.2.0
24
+ - @scalar/types@0.1.5
25
+ - @scalar/themes@0.9.83
26
+
3
27
  ## 0.2.124
4
28
 
5
29
  ### Patch Changes
@@ -46,10 +46,10 @@ export declare const requestExampleParametersSchema: z.ZodEffects<z.ZodObject<{
46
46
  description?: string | undefined;
47
47
  default?: any;
48
48
  required?: boolean | undefined;
49
+ key?: string | undefined;
49
50
  examples?: string[] | undefined;
50
51
  format?: string | undefined;
51
52
  enum?: string[] | undefined;
52
- key?: string | undefined;
53
53
  enabled?: boolean | undefined;
54
54
  file?: any;
55
55
  nullable?: boolean | undefined;
@@ -76,10 +76,10 @@ export declare const requestExampleParametersSchema: z.ZodEffects<z.ZodObject<{
76
76
  description?: string | undefined;
77
77
  default?: any;
78
78
  required?: boolean | undefined;
79
+ key?: string | undefined;
79
80
  examples?: string[] | undefined;
80
81
  format?: string | undefined;
81
82
  enum?: string[] | undefined;
82
- key?: string | undefined;
83
83
  enabled?: boolean | undefined;
84
84
  file?: any;
85
85
  nullable?: boolean | undefined;
@@ -211,10 +211,10 @@ export declare const exampleRequestBodySchema: z.ZodObject<{
211
211
  description?: string | undefined;
212
212
  default?: any;
213
213
  required?: boolean | undefined;
214
+ key?: string | undefined;
214
215
  examples?: string[] | undefined;
215
216
  format?: string | undefined;
216
217
  enum?: string[] | undefined;
217
- key?: string | undefined;
218
218
  enabled?: boolean | undefined;
219
219
  file?: any;
220
220
  nullable?: boolean | undefined;
@@ -241,10 +241,10 @@ export declare const exampleRequestBodySchema: z.ZodObject<{
241
241
  description?: string | undefined;
242
242
  default?: any;
243
243
  required?: boolean | undefined;
244
+ key?: string | undefined;
244
245
  examples?: string[] | undefined;
245
246
  format?: string | undefined;
246
247
  enum?: string[] | undefined;
247
- key?: string | undefined;
248
248
  enabled?: boolean | undefined;
249
249
  file?: any;
250
250
  nullable?: boolean | undefined;
@@ -276,10 +276,10 @@ export declare const exampleRequestBodySchema: z.ZodObject<{
276
276
  description?: string | undefined;
277
277
  default?: any;
278
278
  required?: boolean | undefined;
279
+ key?: string | undefined;
279
280
  examples?: string[] | undefined;
280
281
  format?: string | undefined;
281
282
  enum?: string[] | undefined;
282
- key?: string | undefined;
283
283
  enabled?: boolean | undefined;
284
284
  file?: any;
285
285
  nullable?: boolean | undefined;
@@ -325,10 +325,10 @@ export declare const exampleRequestBodySchema: z.ZodObject<{
325
325
  description?: string | undefined;
326
326
  default?: any;
327
327
  required?: boolean | undefined;
328
+ key?: string | undefined;
328
329
  examples?: string[] | undefined;
329
330
  format?: string | undefined;
330
331
  enum?: string[] | undefined;
331
- key?: string | undefined;
332
332
  enabled?: boolean | undefined;
333
333
  file?: any;
334
334
  nullable?: boolean | undefined;
@@ -439,10 +439,10 @@ export declare const requestExampleSchema: z.ZodObject<{
439
439
  description?: string | undefined;
440
440
  default?: any;
441
441
  required?: boolean | undefined;
442
+ key?: string | undefined;
442
443
  examples?: string[] | undefined;
443
444
  format?: string | undefined;
444
445
  enum?: string[] | undefined;
445
- key?: string | undefined;
446
446
  enabled?: boolean | undefined;
447
447
  file?: any;
448
448
  nullable?: boolean | undefined;
@@ -469,10 +469,10 @@ export declare const requestExampleSchema: z.ZodObject<{
469
469
  description?: string | undefined;
470
470
  default?: any;
471
471
  required?: boolean | undefined;
472
+ key?: string | undefined;
472
473
  examples?: string[] | undefined;
473
474
  format?: string | undefined;
474
475
  enum?: string[] | undefined;
475
- key?: string | undefined;
476
476
  enabled?: boolean | undefined;
477
477
  file?: any;
478
478
  nullable?: boolean | undefined;
@@ -504,10 +504,10 @@ export declare const requestExampleSchema: z.ZodObject<{
504
504
  description?: string | undefined;
505
505
  default?: any;
506
506
  required?: boolean | undefined;
507
+ key?: string | undefined;
507
508
  examples?: string[] | undefined;
508
509
  format?: string | undefined;
509
510
  enum?: string[] | undefined;
510
- key?: string | undefined;
511
511
  enabled?: boolean | undefined;
512
512
  file?: any;
513
513
  nullable?: boolean | undefined;
@@ -553,10 +553,10 @@ export declare const requestExampleSchema: z.ZodObject<{
553
553
  description?: string | undefined;
554
554
  default?: any;
555
555
  required?: boolean | undefined;
556
+ key?: string | undefined;
556
557
  examples?: string[] | undefined;
557
558
  format?: string | undefined;
558
559
  enum?: string[] | undefined;
559
- key?: string | undefined;
560
560
  enabled?: boolean | undefined;
561
561
  file?: any;
562
562
  nullable?: boolean | undefined;
@@ -610,10 +610,10 @@ export declare const requestExampleSchema: z.ZodObject<{
610
610
  description?: string | undefined;
611
611
  default?: any;
612
612
  required?: boolean | undefined;
613
+ key?: string | undefined;
613
614
  examples?: string[] | undefined;
614
615
  format?: string | undefined;
615
616
  enum?: string[] | undefined;
616
- key?: string | undefined;
617
617
  enabled?: boolean | undefined;
618
618
  file?: any;
619
619
  nullable?: boolean | undefined;
@@ -640,10 +640,10 @@ export declare const requestExampleSchema: z.ZodObject<{
640
640
  description?: string | undefined;
641
641
  default?: any;
642
642
  required?: boolean | undefined;
643
+ key?: string | undefined;
643
644
  examples?: string[] | undefined;
644
645
  format?: string | undefined;
645
646
  enum?: string[] | undefined;
646
- key?: string | undefined;
647
647
  enabled?: boolean | undefined;
648
648
  file?: any;
649
649
  nullable?: boolean | undefined;
@@ -686,10 +686,10 @@ export declare const requestExampleSchema: z.ZodObject<{
686
686
  description?: string | undefined;
687
687
  default?: any;
688
688
  required?: boolean | undefined;
689
+ key?: string | undefined;
689
690
  examples?: string[] | undefined;
690
691
  format?: string | undefined;
691
692
  enum?: string[] | undefined;
692
- key?: string | undefined;
693
693
  enabled?: boolean | undefined;
694
694
  file?: any;
695
695
  nullable?: boolean | undefined;
@@ -716,10 +716,10 @@ export declare const requestExampleSchema: z.ZodObject<{
716
716
  description?: string | undefined;
717
717
  default?: any;
718
718
  required?: boolean | undefined;
719
+ key?: string | undefined;
719
720
  examples?: string[] | undefined;
720
721
  format?: string | undefined;
721
722
  enum?: string[] | undefined;
722
- key?: string | undefined;
723
723
  enabled?: boolean | undefined;
724
724
  file?: any;
725
725
  nullable?: boolean | undefined;
@@ -762,10 +762,10 @@ export declare const requestExampleSchema: z.ZodObject<{
762
762
  description?: string | undefined;
763
763
  default?: any;
764
764
  required?: boolean | undefined;
765
+ key?: string | undefined;
765
766
  examples?: string[] | undefined;
766
767
  format?: string | undefined;
767
768
  enum?: string[] | undefined;
768
- key?: string | undefined;
769
769
  enabled?: boolean | undefined;
770
770
  file?: any;
771
771
  nullable?: boolean | undefined;
@@ -792,10 +792,10 @@ export declare const requestExampleSchema: z.ZodObject<{
792
792
  description?: string | undefined;
793
793
  default?: any;
794
794
  required?: boolean | undefined;
795
+ key?: string | undefined;
795
796
  examples?: string[] | undefined;
796
797
  format?: string | undefined;
797
798
  enum?: string[] | undefined;
798
- key?: string | undefined;
799
799
  enabled?: boolean | undefined;
800
800
  file?: any;
801
801
  nullable?: boolean | undefined;
@@ -838,10 +838,10 @@ export declare const requestExampleSchema: z.ZodObject<{
838
838
  description?: string | undefined;
839
839
  default?: any;
840
840
  required?: boolean | undefined;
841
+ key?: string | undefined;
841
842
  examples?: string[] | undefined;
842
843
  format?: string | undefined;
843
844
  enum?: string[] | undefined;
844
- key?: string | undefined;
845
845
  enabled?: boolean | undefined;
846
846
  file?: any;
847
847
  nullable?: boolean | undefined;
@@ -868,10 +868,10 @@ export declare const requestExampleSchema: z.ZodObject<{
868
868
  description?: string | undefined;
869
869
  default?: any;
870
870
  required?: boolean | undefined;
871
+ key?: string | undefined;
871
872
  examples?: string[] | undefined;
872
873
  format?: string | undefined;
873
874
  enum?: string[] | undefined;
874
- key?: string | undefined;
875
875
  enabled?: boolean | undefined;
876
876
  file?: any;
877
877
  nullable?: boolean | undefined;
@@ -950,10 +950,10 @@ export declare const requestExampleSchema: z.ZodObject<{
950
950
  description?: string | undefined;
951
951
  default?: any;
952
952
  required?: boolean | undefined;
953
+ key?: string | undefined;
953
954
  examples?: string[] | undefined;
954
955
  format?: string | undefined;
955
956
  enum?: string[] | undefined;
956
- key?: string | undefined;
957
957
  enabled?: boolean | undefined;
958
958
  file?: any;
959
959
  nullable?: boolean | undefined;
@@ -966,10 +966,10 @@ export declare const requestExampleSchema: z.ZodObject<{
966
966
  description?: string | undefined;
967
967
  default?: any;
968
968
  required?: boolean | undefined;
969
+ key?: string | undefined;
969
970
  examples?: string[] | undefined;
970
971
  format?: string | undefined;
971
972
  enum?: string[] | undefined;
972
- key?: string | undefined;
973
973
  enabled?: boolean | undefined;
974
974
  file?: any;
975
975
  nullable?: boolean | undefined;
@@ -982,10 +982,10 @@ export declare const requestExampleSchema: z.ZodObject<{
982
982
  description?: string | undefined;
983
983
  default?: any;
984
984
  required?: boolean | undefined;
985
+ key?: string | undefined;
985
986
  examples?: string[] | undefined;
986
987
  format?: string | undefined;
987
988
  enum?: string[] | undefined;
988
- key?: string | undefined;
989
989
  enabled?: boolean | undefined;
990
990
  file?: any;
991
991
  nullable?: boolean | undefined;
@@ -998,10 +998,10 @@ export declare const requestExampleSchema: z.ZodObject<{
998
998
  description?: string | undefined;
999
999
  default?: any;
1000
1000
  required?: boolean | undefined;
1001
+ key?: string | undefined;
1001
1002
  examples?: string[] | undefined;
1002
1003
  format?: string | undefined;
1003
1004
  enum?: string[] | undefined;
1004
- key?: string | undefined;
1005
1005
  enabled?: boolean | undefined;
1006
1006
  file?: any;
1007
1007
  nullable?: boolean | undefined;
@@ -1123,10 +1123,10 @@ export declare const requestExampleSchema: z.ZodObject<{
1123
1123
  description?: string | undefined;
1124
1124
  default?: any;
1125
1125
  required?: boolean | undefined;
1126
+ key?: string | undefined;
1126
1127
  examples?: string[] | undefined;
1127
1128
  format?: string | undefined;
1128
1129
  enum?: string[] | undefined;
1129
- key?: string | undefined;
1130
1130
  enabled?: boolean | undefined;
1131
1131
  file?: any;
1132
1132
  nullable?: boolean | undefined;
@@ -1151,10 +1151,10 @@ export declare const requestExampleSchema: z.ZodObject<{
1151
1151
  description?: string | undefined;
1152
1152
  default?: any;
1153
1153
  required?: boolean | undefined;
1154
+ key?: string | undefined;
1154
1155
  examples?: string[] | undefined;
1155
1156
  format?: string | undefined;
1156
1157
  enum?: string[] | undefined;
1157
- key?: string | undefined;
1158
1158
  enabled?: boolean | undefined;
1159
1159
  file?: any;
1160
1160
  nullable?: boolean | undefined;
@@ -1167,10 +1167,10 @@ export declare const requestExampleSchema: z.ZodObject<{
1167
1167
  description?: string | undefined;
1168
1168
  default?: any;
1169
1169
  required?: boolean | undefined;
1170
+ key?: string | undefined;
1170
1171
  examples?: string[] | undefined;
1171
1172
  format?: string | undefined;
1172
1173
  enum?: string[] | undefined;
1173
- key?: string | undefined;
1174
1174
  enabled?: boolean | undefined;
1175
1175
  file?: any;
1176
1176
  nullable?: boolean | undefined;
@@ -1183,10 +1183,10 @@ export declare const requestExampleSchema: z.ZodObject<{
1183
1183
  description?: string | undefined;
1184
1184
  default?: any;
1185
1185
  required?: boolean | undefined;
1186
+ key?: string | undefined;
1186
1187
  examples?: string[] | undefined;
1187
1188
  format?: string | undefined;
1188
1189
  enum?: string[] | undefined;
1189
- key?: string | undefined;
1190
1190
  enabled?: boolean | undefined;
1191
1191
  file?: any;
1192
1192
  nullable?: boolean | undefined;
@@ -1199,10 +1199,10 @@ export declare const requestExampleSchema: z.ZodObject<{
1199
1199
  description?: string | undefined;
1200
1200
  default?: any;
1201
1201
  required?: boolean | undefined;
1202
+ key?: string | undefined;
1202
1203
  examples?: string[] | undefined;
1203
1204
  format?: string | undefined;
1204
1205
  enum?: string[] | undefined;
1205
- key?: string | undefined;
1206
1206
  enabled?: boolean | undefined;
1207
1207
  file?: any;
1208
1208
  nullable?: boolean | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"spec-objects.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/spec-objects.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,MAAM,QAAQ,CAAC,KAAG,CAE/D,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB;IAEzB,mDAAmD;;IAEnD,2GAA2G;;IAE3G;;OAEG;;;;;;;;;;;;;;;;;;EAG0B,CAAA;AAEjC;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB;IAEzB,+DAA+D;;IAE/D,sFAAsF;;IAEtF,0GAA0G;;;;;;;;;;;;;;;;;;EAG7E,CAAA;AAEjC;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa;IAEtB,sCAAsC;;IAEtC,kCAAkC;;IAElC,4FAA4F;;IAE5F,oFAAoF;;IAEpF,mDAAmD;;QA3BnD,+DAA+D;;QAE/D,sFAAsF;;QAEtF,0GAA0G;;;;;;;;;;;;;;;;;;;IAyB1G,mDAAmD;;QAjDnD,mDAAmD;;QAEnD,2GAA2G;;QAE3G;;WAEG;;;;;;;;;;;;;;;;;;;IA6CH;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG0B,CAAA;AAEjC;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B;IAEvC,6GAA6G;;IAE7G,yFAAyF;;;;;;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-7,7 +7,14 @@ import { z } from 'zod';
7
7
  * Can be used as a transform function for any Zod schema.
8
8
  */
9
9
  const omitUndefinedValues = (data) => {
10
- return Object.fromEntries(Object.entries(data).filter(([_, value]) => value !== undefined));
10
+ return Object.fromEntries(Object.entries(data)
11
+ .filter(([_, value]) => value !== undefined)
12
+ .map(([key, value]) => {
13
+ if (typeof value === 'object' && value !== null) {
14
+ return [key, omitUndefinedValues(value)];
15
+ }
16
+ return [key, value];
17
+ }));
11
18
  };
12
19
  /**
13
20
  * License Object
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Fetches an OpenAPI/Swagger document from a given URL
3
+ *
4
+ * @throws an error if the fetch fails
5
+ */
6
+ export declare function fetchDocument(url: string, proxyUrl?: string, prettyPrint?: boolean): Promise<string>;
7
+ //# sourceMappingURL=fetch-document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-document.d.ts","sourceRoot":"","sources":["../../src/helpers/fetch-document.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,WAAW,UAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BvG"}
@@ -0,0 +1,35 @@
1
+ import { formatJsonOrYamlString } from './parse.js';
2
+ import { redirectToProxy } from './redirect-to-proxy.js';
3
+
4
+ // Doesn’t work
5
+ const OLD_PROXY_URL = 'https://api.scalar.com/request-proxy';
6
+ // Does work
7
+ const NEW_PROXY_URL = 'https://proxy.scalar.com';
8
+ /**
9
+ * Fetches an OpenAPI/Swagger document from a given URL
10
+ *
11
+ * @throws an error if the fetch fails
12
+ */
13
+ async function fetchDocument(url, proxyUrl, prettyPrint = true) {
14
+ // This replaces the OLD_PROXY_URL with the NEW_PROXY_URL on the fly.
15
+ if (proxyUrl === OLD_PROXY_URL) {
16
+ // biome-ignore lint/style/noParameterAssign: It’s ok, let’s make an exception here.
17
+ proxyUrl = NEW_PROXY_URL;
18
+ }
19
+ const response = await fetch(redirectToProxy(proxyUrl, url));
20
+ // Looks like the request failed
21
+ if (response.status !== 200) {
22
+ console.error(`[fetchDocument] Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`);
23
+ if (!proxyUrl) {
24
+ console.warn(`[fetchDocument] Tried to fetch the OpenAPI document from ${url} without a proxy. Are the CORS headers configured to allow cross-domain requests? https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS`);
25
+ }
26
+ throw new Error(`Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`);
27
+ }
28
+ // If it’s JSON, make it pretty
29
+ if (prettyPrint) {
30
+ return formatJsonOrYamlString(await response.text());
31
+ }
32
+ return await response.text();
33
+ }
34
+
35
+ export { fetchDocument };
@@ -1,15 +1,15 @@
1
1
  export type FetchWithProxyFallbackOptions = {
2
- proxy: string | undefined;
2
+ proxyUrl: string | undefined;
3
3
  /**
4
4
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
5
5
  */
6
6
  cache?: RequestInit['cache'];
7
7
  };
8
8
  /**
9
- * Fetches an OpenAPI document with a proxy fallback mechanism.
9
+ * Fetches an OpenAPI document with a proxyUrl fallback mechanism.
10
10
  *
11
11
  * If a proxy is provided and the URL requires it, it will first attempt to fetch using the proxy.
12
12
  * If the proxy fetch fails or is not used, it will fall back to a direct fetch.
13
13
  */
14
- export declare function fetchWithProxyFallback(url: string, { proxy, cache }: FetchWithProxyFallbackOptions): Promise<Response>;
14
+ export declare function fetchWithProxyFallback(url: string, { proxyUrl, cache }: FetchWithProxyFallbackOptions): Promise<Response>;
15
15
  //# sourceMappingURL=fetch-with-proxy-fallback.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-with-proxy-fallback.d.ts","sourceRoot":"","sources":["../../src/helpers/fetch-with-proxy-fallback.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,6BAA6B,GAAG;IAC1C,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB;;OAEG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAC7B,CAAA;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,6BAA6B,qBAuBxG"}
1
+ {"version":3,"file":"fetch-with-proxy-fallback.d.ts","sourceRoot":"","sources":["../../src/helpers/fetch-with-proxy-fallback.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B;;OAEG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAC7B,CAAA;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,6BAA6B,qBAuB3G"}
@@ -1,28 +1,28 @@
1
1
  import { shouldUseProxy, redirectToProxy } from './redirect-to-proxy.js';
2
2
 
3
3
  /**
4
- * Fetches an OpenAPI document with a proxy fallback mechanism.
4
+ * Fetches an OpenAPI document with a proxyUrl fallback mechanism.
5
5
  *
6
6
  * If a proxy is provided and the URL requires it, it will first attempt to fetch using the proxy.
7
7
  * If the proxy fetch fails or is not used, it will fall back to a direct fetch.
8
8
  */
9
- async function fetchWithProxyFallback(url, { proxy, cache }) {
9
+ async function fetchWithProxyFallback(url, { proxyUrl, cache }) {
10
10
  const fetchOptions = {
11
11
  cache: cache || 'default',
12
12
  };
13
- const shouldTryProxy = shouldUseProxy(proxy, url);
14
- const initialUrl = shouldTryProxy ? redirectToProxy(proxy, url) : url;
13
+ const shouldTryProxy = shouldUseProxy(proxyUrl, url);
14
+ const initialUrl = shouldTryProxy ? redirectToProxy(proxyUrl, url) : url;
15
15
  try {
16
16
  const result = await fetch(initialUrl, fetchOptions);
17
17
  if (result.ok || !shouldTryProxy) {
18
18
  return result;
19
19
  }
20
- // Retry without proxy if the initial request failed
20
+ // Retry without proxyUrl if the initial request failed
21
21
  return await fetch(url, fetchOptions);
22
22
  }
23
23
  catch (error) {
24
24
  if (shouldTryProxy) {
25
- // If proxy failed, try without it
25
+ // If proxyUrl failed, try without it
26
26
  return await fetch(url, fetchOptions);
27
27
  }
28
28
  throw error;
@@ -1,6 +1,6 @@
1
1
  export { createHash } from './create-hash.ts';
2
2
  export { ensureProtocol } from './ensure-protocol.ts';
3
- export { fetchSpecFromUrl } from './fetch-spec-from-url.ts';
3
+ export { fetchDocument } from './fetch-document.ts';
4
4
  export { type FetchWithProxyFallbackOptions, fetchWithProxyFallback } from './fetch-with-proxy-fallback.ts';
5
5
  export { findVariables } from './find-variables.ts';
6
6
  export { canMethodHaveBody, getHttpMethodInfo, isHttpMethod, REQUEST_METHODS } from './http-methods.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,KAAK,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAC3G,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACvG,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACnG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,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,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA"}
@@ -1,6 +1,6 @@
1
1
  export { createHash } from './create-hash.js';
2
2
  export { ensureProtocol } from './ensure-protocol.js';
3
- export { fetchSpecFromUrl } from './fetch-spec-from-url.js';
3
+ export { fetchDocument } from './fetch-document.js';
4
4
  export { fetchWithProxyFallback } from './fetch-with-proxy-fallback.js';
5
5
  export { findVariables } from './find-variables.js';
6
6
  export { REQUEST_METHODS, canMethodHaveBody, getHttpMethodInfo, isHttpMethod } from './http-methods.js';
@@ -1,7 +1,17 @@
1
- /** Redirects the request to a proxy server with a given URL. */
2
- export declare function redirectToProxy(proxy?: string, url?: string): string;
3
- /** Check if the URL is relative or if it's a domain without protocol */
1
+ /**
2
+ * Redirects the request to a proxy server with a given URL. But not for:
3
+ *
4
+ * - Relative URLs
5
+ * - URLs that seem to point to a local IP (except the proxy is on the same domain)
6
+ * - URLs that don’t look like a domain
7
+ **/
8
+ export declare function redirectToProxy(proxyUrl?: string, url?: string): string;
9
+ /**
10
+ * Check if the URL is relative or if it's a domain without protocol
11
+ **/
4
12
  export declare const isRelativePath: (url: string) => boolean;
5
- /** Returns false for requests to localhost, relative URLs, if no proxy is defined … */
6
- export declare function shouldUseProxy(proxy?: string, url?: string): boolean;
13
+ /**
14
+ * Returns false for requests to localhost, relative URLs, if no proxy is defined …
15
+ **/
16
+ export declare function shouldUseProxy(proxyUrl?: string, url?: string): url is string;
7
17
  //# sourceMappingURL=redirect-to-proxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"redirect-to-proxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirect-to-proxy.ts"],"names":[],"mappings":"AAGA,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAepE;AAED,wEAAwE;AACxE,eAAO,MAAM,cAAc,QAAS,MAAM,YAazC,CAAA;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAiBpE"}
1
+ {"version":3,"file":"redirect-to-proxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirect-to-proxy.ts"],"names":[],"mappings":"AAGA;;;;;;IAMI;AACJ,wBAAgB,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAmCvE;AAED;;IAEI;AACJ,eAAO,MAAM,cAAc,QAAS,MAAM,YAazC,CAAA;AAED;;IAEI;AACJ,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,IAAI,MAAM,CAkC7E"}
@@ -1,20 +1,47 @@
1
1
  import { isLocalUrl } from './is-local-url.js';
2
2
  import { REGEX } from './regex-helpers.js';
3
3
 
4
- /** Redirects the request to a proxy server with a given URL. */
5
- function redirectToProxy(proxy, url) {
6
- if (!shouldUseProxy(proxy, url)) {
4
+ /**
5
+ * Redirects the request to a proxy server with a given URL. But not for:
6
+ *
7
+ * - Relative URLs
8
+ * - URLs that seem to point to a local IP (except the proxy is on the same domain)
9
+ * - URLs that don’t look like a domain
10
+ **/
11
+ function redirectToProxy(proxyUrl, url) {
12
+ try {
13
+ if (!shouldUseProxy(proxyUrl, url)) {
14
+ console.log('should not use proxy', proxyUrl, url);
15
+ return url ?? '';
16
+ }
17
+ // Create new URL object from url
18
+ const newUrl = new URL(url);
19
+ // Add temporary domain for relative proxy URLs
20
+ //
21
+ // Q: Why isn’t proxyUrl type guarded?
22
+ // A: Type guarding works for one parameter only (as of now).
23
+ //
24
+ // Q: Why do we need to add http://localhost to relative proxy URLs?
25
+ // A: Because the `new URL()` would otherwise fail.
26
+ //
27
+ const temporaryProxyUrl = isRelativePath(proxyUrl) ? `http://localhost${proxyUrl}` : proxyUrl;
28
+ // Rewrite the URL with the proxy
29
+ newUrl.href = temporaryProxyUrl;
30
+ // Add the original URL as a query parameter
31
+ newUrl.searchParams.append('scalar_url', url);
32
+ // Remove the temporary domain if we added it, but only from the start of the URL
33
+ const result = isRelativePath(proxyUrl)
34
+ ? newUrl.toString().replace(/^http:\/\/localhost/, '')
35
+ : newUrl.toString();
36
+ return result;
37
+ }
38
+ catch {
7
39
  return url ?? '';
8
40
  }
9
- // Create new URL object from url
10
- const newUrl = new URL(url);
11
- // Rewrite the URL with the proxy
12
- newUrl.href = proxy;
13
- // Add the original URL as a query parameter
14
- newUrl.searchParams.append('scalar_url', url);
15
- return newUrl.toString();
16
41
  }
17
- /** Check if the URL is relative or if it's a domain without protocol */
42
+ /**
43
+ * Check if the URL is relative or if it's a domain without protocol
44
+ **/
18
45
  const isRelativePath = (url) => {
19
46
  // Allow http:// https:// and other protocols such as file://
20
47
  if (REGEX.PROTOCOL.test(url)) {
@@ -27,21 +54,39 @@ const isRelativePath = (url) => {
27
54
  }
28
55
  return true;
29
56
  };
30
- /** Returns false for requests to localhost, relative URLs, if no proxy is defined … */
31
- function shouldUseProxy(proxy, url) {
32
- // No proxy or url
33
- if (!proxy || !url) {
34
- return false;
57
+ /**
58
+ * Returns false for requests to localhost, relative URLs, if no proxy is defined …
59
+ **/
60
+ function shouldUseProxy(proxyUrl, url) {
61
+ try {
62
+ // ❌ We don’t have a proxy URL or the URL
63
+ if (!proxyUrl || !url) {
64
+ return false;
65
+ }
66
+ // ❌ Request to relative URLs (won’t be blocked by CORS anyway)
67
+ if (isRelativePath(url)) {
68
+ return false;
69
+ }
70
+ // ✅ Proxy URL is on the same domain (e.g. /proxy)
71
+ // It’s more likely (not guaranteed, though) that the proxy has access to local domains.
72
+ if (isRelativePath(proxyUrl)) {
73
+ return true;
74
+ }
75
+ // ✅ Proxy URL is local
76
+ if (isLocalUrl(proxyUrl)) {
77
+ return true;
78
+ }
79
+ // ❌ Requests to localhost
80
+ // We won’t reach them from a (likely remote) proxy.
81
+ if (isLocalUrl(url)) {
82
+ return false;
83
+ }
84
+ // ✅ Seems fine (e.g. remote proxy + remote URL)
85
+ return true;
35
86
  }
36
- // Relative URLs
37
- if (isRelativePath(url)) {
87
+ catch {
38
88
  return false;
39
89
  }
40
- // Requests to localhost
41
- if (isLocalUrl(url)) {
42
- return false;
43
- }
44
- return true;
45
90
  }
46
91
 
47
92
  export { isRelativePath, redirectToProxy, shouldUseProxy };
@@ -1 +1 @@
1
- {"version":3,"file":"get-example-from-schema.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-example-from-schema.ts"],"names":[],"mappings":"AAyDA;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YACjB;IACR;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/B;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAA;CACzC,UACM,MAAM,iBACE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAC3B,MAAM,KACZ,GA8QF,CAAA"}
1
+ {"version":3,"file":"get-example-from-schema.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-example-from-schema.ts"],"names":[],"mappings":"AA2DA;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YACjB;IACR;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/B;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAA;CACzC,UACM,MAAM,iBACE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAC3B,MAAM,KACZ,GAgRF,CAAA"}