@scalar/oas-utils 0.1.12 → 0.1.13

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,11 @@
1
1
  # @scalar/oas-utils
2
2
 
3
+ ## 0.1.13
4
+
5
+ ### Patch Changes
6
+
7
+ - 5aa656f: feat: [BREAKING CHANGE] use new HTTP proxy (https://github.com/scalar/scalar/pull/1703)
8
+
3
9
  ## 0.1.12
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,3 @@
1
+ /** Fetches an OpenAPI/Swagger specification from a given URL. */
2
+ export declare function fetchSpecFromUrl(url: string, proxy?: string): Promise<string>;
3
+ //# sourceMappingURL=fetchSpecFromUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchSpecFromUrl.d.ts","sourceRoot":"","sources":["../src/fetchSpecFromUrl.ts"],"names":[],"mappings":"AAOA,iEAAiE;AACjE,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAmBjB"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { createHash } from './createHash';
2
2
  export { defaultStateFactory, ssrState } from './ssrState';
3
- export { fetchSpecFromUrl } from './fetch-spec';
3
+ export { fetchSpecFromUrl } from './fetchSpecFromUrl';
4
4
  export { getExampleFromSchema } from './getExampleFromSchema';
5
5
  export { getHarRequest } from './getHarRequest';
6
6
  export { getParametersFromOperation } from './getParametersFromOperation';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AA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AAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,cAAc,qBAAqB,CAAA;AACnC,cAAc,SAAS,CAAA;AACvB,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,IAAI,EACJ,eAAe,EACf,eAAe,EACf,IAAI,GACL,MAAM,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -86,25 +86,22 @@ const parseJsonOrYaml = (value) => {
86
86
  });
87
87
  };
88
88
 
89
+ function redirectToProxy(proxy, url) {
90
+ return `${proxy}?scalar_url=${encodeURI(url)}`;
91
+ }
89
92
  async function fetchSpecFromUrl(url, proxy) {
90
- const response = proxy ? await fetch(proxy, {
91
- method: "POST",
92
- headers: {
93
- "Content-Type": "application/json"
94
- },
95
- body: JSON.stringify({
96
- method: "GET",
97
- url
98
- })
99
- }) : await fetch(url);
93
+ const response = await fetch(proxy ? redirectToProxy(proxy, url) : url);
100
94
  if (response.status !== 200) {
101
- const proxyWarning = proxy ? "" : "Trying to fetch the spec file without a proxy. The CORS headers must be set properly or the request will fail.";
102
95
  console.error(
103
- `[fetchSpecFromUrl] Failed to fetch the spec at ${url}. ${proxyWarning}`
96
+ `[fetchSpecFromUrl] Failed to fetch the specification at ${url} (Status: ${response.status})`
104
97
  );
98
+ if (!proxy) {
99
+ console.warn(
100
+ `[fetchSpecFromUrl] Tried to fetch the specification (url: ${url}) without a proxy. Are the CORS headers configured to allow cross-domain requests? https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS`
101
+ );
102
+ }
105
103
  }
106
- const payload = proxy ? String((await response.json()).data) : await response.text();
107
- return formatJsonOrYamlString(payload);
104
+ return formatJsonOrYamlString(await response.text());
108
105
  }
109
106
 
110
107
  const getExampleFromSchema = (schema, options, level = 0) => {
package/dist/parse.d.ts CHANGED
@@ -25,7 +25,7 @@ export declare const isJsonString: (value?: any) => boolean;
25
25
  * This helper is used to transform the content of the swagger file to JSON, even it was YAML.
26
26
  */
27
27
  export declare const transformToJson: (value: string) => string;
28
- /** Validates a JSON string if provided. Otherwise returns the raw Yaml */
28
+ /** Validates a JSON string if provided. Otherwise returns the raw YAML */
29
29
  export declare function formatJsonOrYamlString(value: string): string;
30
30
  /** Parse JSON or YAML into an object */
31
31
  export declare const parseJsonOrYaml: (value: string | AnyObject) => AnyObject;
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "specification",
17
17
  "yaml"
18
18
  ],
19
- "version": "0.1.12",
19
+ "version": "0.1.13",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
@@ -1,3 +0,0 @@
1
- /** Fetches an OAS spec file from a given URL. */
2
- export declare function fetchSpecFromUrl(url: string, proxy?: string): Promise<string>;
3
- //# sourceMappingURL=fetch-spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch-spec.d.ts","sourceRoot":"","sources":["../src/fetch-spec.ts"],"names":[],"mappings":"AAEA,iDAAiD;AACjD,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CA8BjB"}