@scalar/blocks 0.1.0

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 (97) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +21 -0
  3. package/README.md +33 -0
  4. package/dist/_virtual/_plugin-vue_export-helper.js +8 -0
  5. package/dist/code-example/components/CodeExample.vue.d.ts +139 -0
  6. package/dist/code-example/components/CodeExample.vue.d.ts.map +1 -0
  7. package/dist/code-example/components/CodeExample.vue.js +9 -0
  8. package/dist/code-example/components/CodeExample.vue.js.map +1 -0
  9. package/dist/code-example/components/CodeExample.vue.script.js +223 -0
  10. package/dist/code-example/components/CodeExample.vue.script.js.map +1 -0
  11. package/dist/code-example/components/ExamplePicker.vue.d.ts +16 -0
  12. package/dist/code-example/components/ExamplePicker.vue.d.ts.map +1 -0
  13. package/dist/code-example/components/ExamplePicker.vue.js +7 -0
  14. package/dist/code-example/components/ExamplePicker.vue.js.map +1 -0
  15. package/dist/code-example/components/ExamplePicker.vue.script.js +48 -0
  16. package/dist/code-example/components/ExamplePicker.vue.script.js.map +1 -0
  17. package/dist/code-example/components/HttpMethod.vue.d.ts +26 -0
  18. package/dist/code-example/components/HttpMethod.vue.d.ts.map +1 -0
  19. package/dist/code-example/components/HttpMethod.vue.js +7 -0
  20. package/dist/code-example/components/HttpMethod.vue.js.map +1 -0
  21. package/dist/code-example/components/HttpMethod.vue.script.js +27 -0
  22. package/dist/code-example/components/HttpMethod.vue.script.js.map +1 -0
  23. package/dist/code-example/helpers/filter-clients-by-query.d.ts +9 -0
  24. package/dist/code-example/helpers/filter-clients-by-query.d.ts.map +1 -0
  25. package/dist/code-example/helpers/filter-clients-by-query.js +21 -0
  26. package/dist/code-example/helpers/filter-clients-by-query.js.map +1 -0
  27. package/dist/code-example/helpers/find-client.d.ts +41 -0
  28. package/dist/code-example/helpers/find-client.d.ts.map +1 -0
  29. package/dist/code-example/helpers/find-client.js +20 -0
  30. package/dist/code-example/helpers/find-client.js.map +1 -0
  31. package/dist/code-example/helpers/format-language.d.ts +8 -0
  32. package/dist/code-example/helpers/format-language.d.ts.map +1 -0
  33. package/dist/code-example/helpers/format-language.js +54 -0
  34. package/dist/code-example/helpers/format-language.js.map +1 -0
  35. package/dist/code-example/helpers/generate-client-options.d.ts +30 -0
  36. package/dist/code-example/helpers/generate-client-options.d.ts.map +1 -0
  37. package/dist/code-example/helpers/generate-client-options.js +35 -0
  38. package/dist/code-example/helpers/generate-client-options.js.map +1 -0
  39. package/dist/code-example/helpers/generate-code-snippet.d.ts +39 -0
  40. package/dist/code-example/helpers/generate-code-snippet.d.ts.map +1 -0
  41. package/dist/code-example/helpers/generate-code-snippet.js +30 -0
  42. package/dist/code-example/helpers/generate-code-snippet.js.map +1 -0
  43. package/dist/code-example/helpers/get-clients.d.ts +12 -0
  44. package/dist/code-example/helpers/get-clients.d.ts.map +1 -0
  45. package/dist/code-example/helpers/get-clients.js +28 -0
  46. package/dist/code-example/helpers/get-clients.js.map +1 -0
  47. package/dist/code-example/helpers/get-custom-code-samples.d.ts +45 -0
  48. package/dist/code-example/helpers/get-custom-code-samples.d.ts.map +1 -0
  49. package/dist/code-example/helpers/get-custom-code-samples.js +42 -0
  50. package/dist/code-example/helpers/get-custom-code-samples.js.map +1 -0
  51. package/dist/code-example/helpers/get-secrets.d.ts +4 -0
  52. package/dist/code-example/helpers/get-secrets.d.ts.map +1 -0
  53. package/dist/code-example/helpers/get-secrets.js +12 -0
  54. package/dist/code-example/helpers/get-secrets.js.map +1 -0
  55. package/dist/code-example/helpers/get-snippet.d.ts +8 -0
  56. package/dist/code-example/helpers/get-snippet.d.ts.map +1 -0
  57. package/dist/code-example/helpers/get-snippet.js +30 -0
  58. package/dist/code-example/helpers/get-snippet.js.map +1 -0
  59. package/dist/code-example/helpers/operation-to-har/operation-to-har.d.ts +72 -0
  60. package/dist/code-example/helpers/operation-to-har/operation-to-har.d.ts.map +1 -0
  61. package/dist/code-example/helpers/operation-to-har/operation-to-har.js +78 -0
  62. package/dist/code-example/helpers/operation-to-har/operation-to-har.js.map +1 -0
  63. package/dist/code-example/helpers/operation-to-har/process-body.d.ts +13 -0
  64. package/dist/code-example/helpers/operation-to-har/process-body.d.ts.map +1 -0
  65. package/dist/code-example/helpers/operation-to-har/process-body.js +100 -0
  66. package/dist/code-example/helpers/operation-to-har/process-body.js.map +1 -0
  67. package/dist/code-example/helpers/operation-to-har/process-parameters.d.ts +24 -0
  68. package/dist/code-example/helpers/operation-to-har/process-parameters.d.ts.map +1 -0
  69. package/dist/code-example/helpers/operation-to-har/process-parameters.js +189 -0
  70. package/dist/code-example/helpers/operation-to-har/process-parameters.js.map +1 -0
  71. package/dist/code-example/helpers/operation-to-har/process-security-schemes.d.ts +15 -0
  72. package/dist/code-example/helpers/operation-to-har/process-security-schemes.d.ts.map +1 -0
  73. package/dist/code-example/helpers/operation-to-har/process-security-schemes.js +59 -0
  74. package/dist/code-example/helpers/operation-to-har/process-security-schemes.js.map +1 -0
  75. package/dist/code-example/helpers/operation-to-har/process-server-url.d.ts +6 -0
  76. package/dist/code-example/helpers/operation-to-har/process-server-url.d.ts.map +1 -0
  77. package/dist/code-example/helpers/operation-to-har/process-server-url.js +12 -0
  78. package/dist/code-example/helpers/operation-to-har/process-server-url.js.map +1 -0
  79. package/dist/code-example/index.d.ts +17 -0
  80. package/dist/code-example/index.d.ts.map +1 -0
  81. package/dist/code-example/index.js +14 -0
  82. package/dist/code-example/mount.d.ts +51 -0
  83. package/dist/code-example/mount.d.ts.map +1 -0
  84. package/dist/code-example/mount.js +61 -0
  85. package/dist/code-example/mount.js.map +1 -0
  86. package/dist/code-example/test-utils.d.ts +4 -0
  87. package/dist/code-example/test-utils.d.ts.map +1 -0
  88. package/dist/code-example/types.d.ts +46 -0
  89. package/dist/code-example/types.d.ts.map +1 -0
  90. package/dist/constants.d.ts +3 -0
  91. package/dist/constants.d.ts.map +1 -0
  92. package/dist/constants.js +6 -0
  93. package/dist/constants.js.map +1 -0
  94. package/dist/style.css +4995 -0
  95. package/dist/styles/tailwind.config.css +12 -0
  96. package/dist/vue-styles.css +2 -0
  97. package/package.json +80 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-custom-code-samples.js","names":[],"sources":["../../../src/code-example/helpers/get-custom-code-samples.ts"],"sourcesContent":["import type {\n XCodeSample,\n XLanguageExample,\n XReadmeCodeSample,\n} from '@scalar/workspace-store/schemas/extensions/operation'\nimport type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\n\n/** Turns a `{ language: source }` map (x-stainless-snippets) into code samples. */\nconst fromSnippetMap = (snippets: Record<string, string> | undefined, label?: string): XCodeSample[] =>\n Object.entries(snippets ?? {}).map(([lang, source]) => ({ lang, source, ...(label ? { label } : {}) }))\n\n/**\n * Turns `x-stainless-examples` / `x-scalar-examples` into code samples.\n *\n * Each example carries per-language request snippets and an optional title that\n * we surface as the picker label. The response is only used for documentation,\n * so it is ignored here.\n */\nconst fromLanguageExamples = (examples: XLanguageExample | XLanguageExample[] | undefined): XCodeSample[] => {\n if (!examples) {\n return []\n }\n\n return (Array.isArray(examples) ? examples : [examples]).flatMap((example) =>\n fromSnippetMap(example.request, example.title),\n )\n}\n\n/** Turns ReadMe's `x-readme.code-samples` into code samples. */\nconst fromReadmeSamples = (samples: XReadmeCodeSample[] | undefined): XCodeSample[] =>\n (samples ?? []).map((sample) => ({\n lang: sample.language,\n source: sample.code,\n ...(sample.name ? { label: sample.name } : {}),\n }))\n\n/** Picker group label for samples generated by an SDK provider (Scalar, Stainless, …). */\nconst SDK_GROUP_LABEL = 'SDK'\n\n/** Picker group label for generic or docs-platform samples (the standard `x-codeSamples` family, ReadMe, …). */\nexport const CODE_EXAMPLES_GROUP_LABEL = 'Code Examples'\n\ntype CustomCodeSampleGroupLabel = typeof SDK_GROUP_LABEL | typeof CODE_EXAMPLES_GROUP_LABEL\n\ntype CustomCodeSamples = {\n /**\n * Group label for the code sample picker.\n *\n * Samples that come from an SDK provider extension (`x-scalar-examples`,\n * `x-stainless-snippets`, `x-stainless-examples`) surface under \"SDK\". Generic\n * or docs-platform samples (`x-readme`, the `x-codeSamples` family) surface\n * under \"Code Examples\".\n */\n label: CustomCodeSampleGroupLabel\n /** The custom code samples, in picker order. */\n samples: XCodeSample[]\n}\n\n/**\n * Grabs any custom code samples from the operation.\n *\n * Several tools write code samples into OpenAPI under different extensions. When\n * more than one is present we use the highest-priority source only, rather than\n * showing duplicates from every tool. Priority, highest first:\n *\n * 1. `x-scalar-examples` (SDK)\n * 2. `x-stainless-snippets` (SDK, overrides `x-stainless-examples`)\n * 3. `x-stainless-examples` (SDK)\n * 4. `x-readme.code-samples` (Code Examples)\n * 5. `x-codeSamples` / `x-code-samples` / `x-custom-examples` (Code Examples)\n *\n * The winning source also determines the picker group label: SDK-provider\n * extensions surface under \"SDK\", everything else under \"Code Examples\".\n *\n * Note that Speakeasy does not have its own extension — it writes into the\n * standard `x-codeSamples`, so its snippets surface under \"Code Examples\".\n *\n * @param operation - The operation to get the custom code samples from\n * @returns The picker group label and the custom code samples which exist in the operation\n */\nexport const getCustomCodeSamples = (operation: OperationObject): CustomCodeSamples => {\n const scalarExamples = operation['x-scalar-examples'] ?? []\n if (scalarExamples.length) {\n return { label: SDK_GROUP_LABEL, samples: scalarExamples }\n }\n\n const stainlessSnippets = fromSnippetMap(operation['x-stainless-snippets'])\n if (stainlessSnippets.length) {\n return { label: SDK_GROUP_LABEL, samples: stainlessSnippets }\n }\n\n const stainlessExamples = fromLanguageExamples(operation['x-stainless-examples'])\n if (stainlessExamples.length) {\n return { label: SDK_GROUP_LABEL, samples: stainlessExamples }\n }\n\n const readmeSamples = fromReadmeSamples(operation['x-readme']?.['code-samples'])\n if (readmeSamples.length) {\n return { label: CODE_EXAMPLES_GROUP_LABEL, samples: readmeSamples }\n }\n\n const customCodeKeys = ['x-custom-examples', 'x-codeSamples', 'x-code-samples'] as const\n return { label: CODE_EXAMPLES_GROUP_LABEL, samples: customCodeKeys.flatMap((key) => operation[key] ?? []) }\n}\n"],"mappings":";AAQA,IAAM,KAAkB,GAA8C,MACpE,OAAO,QAAQ,KAAY,EAAE,CAAC,CAAC,KAAK,CAAC,GAAM,QAAa;CAAE;CAAM;CAAQ,GAAI,IAAQ,EAAE,UAAO,GAAG,EAAE;CAAG,EAAE,EASnG,KAAwB,MACvB,KAIG,MAAM,QAAQ,EAAS,GAAG,IAAW,CAAC,EAAS,EAAE,SAAS,MAChE,EAAe,EAAQ,SAAS,EAAQ,MAAM,CAC/C,GALQ,EAAE,EASP,KAAqB,OACxB,KAAW,EAAE,EAAE,KAAK,OAAY;CAC/B,MAAM,EAAO;CACb,QAAQ,EAAO;CACf,GAAI,EAAO,OAAO,EAAE,OAAO,EAAO,MAAM,GAAG,EAAE;CAC9C,EAAE,EAGC,IAAkB,OAGX,IAA4B,iBAwC5B,KAAwB,MAAkD;CACrF,IAAM,IAAiB,EAAU,wBAAwB,EAAE;AAC3D,KAAI,EAAe,OACjB,QAAO;EAAE,OAAO;EAAiB,SAAS;EAAgB;CAG5D,IAAM,IAAoB,EAAe,EAAU,wBAAwB;AAC3E,KAAI,EAAkB,OACpB,QAAO;EAAE,OAAO;EAAiB,SAAS;EAAmB;CAG/D,IAAM,IAAoB,EAAqB,EAAU,wBAAwB;AACjF,KAAI,EAAkB,OACpB,QAAO;EAAE,OAAO;EAAiB,SAAS;EAAmB;CAG/D,IAAM,IAAgB,EAAkB,EAAU,cAAc,gBAAgB;AAMhF,QALI,EAAc,SACT;EAAE,OAAO;EAA2B,SAAS;EAAe,GAI9D;EAAE,OAAO;EAA2B,SADpB;GAAC;GAAqB;GAAiB;GAAiB,CACZ,SAAS,MAAQ,EAAU,MAAQ,EAAE,CAAC;EAAE"}
@@ -0,0 +1,4 @@
1
+ import type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example';
2
+ /** Extract secrets from security schemes */
3
+ export declare const getSecrets: (securitySchemes: SecuritySchemeObjectSecret[]) => string[];
4
+ //# sourceMappingURL=get-secrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-secrets.d.ts","sourceRoot":"","sources":["../../../src/code-example/helpers/get-secrets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AAGzF,4CAA4C;AAC5C,eAAO,MAAM,UAAU,GAAI,iBAAiB,0BAA0B,EAAE,KAAG,MAAM,EAqB7D,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { encode as e } from "js-base64";
2
+ //#region src/code-example/helpers/get-secrets.ts
3
+ var t = (t) => t.flatMap((t) => t.type === "apiKey" ? t["x-scalar-secret-token"] : t?.type === "http" ? [
4
+ t["x-scalar-secret-token"],
5
+ t["x-scalar-secret-username"],
6
+ t["x-scalar-secret-password"],
7
+ e(`${t["x-scalar-secret-username"]}:${t["x-scalar-secret-password"]}`)
8
+ ] : t.type === "oauth2" ? Object.values(t.flows).map((e) => e["x-scalar-secret-token"]) : []).filter(Boolean);
9
+ //#endregion
10
+ export { t as getSecrets };
11
+
12
+ //# sourceMappingURL=get-secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-secrets.js","names":[],"sources":["../../../src/code-example/helpers/get-secrets.ts"],"sourcesContent":["import type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport { encode } from 'js-base64'\n\n/** Extract secrets from security schemes */\nexport const getSecrets = (securitySchemes: SecuritySchemeObjectSecret[]): string[] =>\n securitySchemes\n .flatMap((scheme) => {\n if (scheme.type === 'apiKey') {\n return scheme['x-scalar-secret-token']\n }\n if (scheme?.type === 'http') {\n return [\n scheme['x-scalar-secret-token'],\n scheme['x-scalar-secret-username'],\n scheme['x-scalar-secret-password'],\n encode(`${scheme['x-scalar-secret-username']}:${scheme['x-scalar-secret-password']}`),\n ]\n }\n if (scheme.type === 'oauth2') {\n const flows = Object.values(scheme.flows)\n return flows.map((flow) => flow['x-scalar-secret-token'])\n }\n\n return []\n })\n .filter(Boolean)\n"],"mappings":";;AAIA,IAAa,KAAc,MACzB,EACG,SAAS,MACJ,EAAO,SAAS,WACX,EAAO,2BAEZ,GAAQ,SAAS,SACZ;CACL,EAAO;CACP,EAAO;CACP,EAAO;CACP,EAAO,GAAG,EAAO,4BAA4B,GAAG,EAAO,8BAA8B;CACtF,GAEC,EAAO,SAAS,WACJ,OAAO,OAAO,EAAO,MAAM,CAC5B,KAAK,MAAS,EAAK,yBAAyB,GAGpD,EAAE,CACT,CACD,OAAO,QAAQ"}
@@ -0,0 +1,8 @@
1
+ import type { ErrorResponse } from '@scalar/helpers/errors/normalize-error';
2
+ import { type ClientId, type TargetId } from '@scalar/snippetz';
3
+ import type { Request as HarRequest } from 'har-format';
4
+ /**
5
+ * Returns a code example for given operation
6
+ */
7
+ export declare const getSnippet: <T extends TargetId>(target: T | "javascript", client: ClientId<T>, harRequest: HarRequest) => ErrorResponse<string>;
8
+ //# sourceMappingURL=get-snippet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-snippet.d.ts","sourceRoot":"","sources":["../../../src/code-example/helpers/get-snippet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAY,MAAM,kBAAkB,CAAA;AACzE,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAKvD;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,QAAQ,EAC3C,QAAQ,CAAC,GAAG,YAAY,EACxB,QAAQ,QAAQ,CAAC,CAAC,CAAC,EACnB,YAAY,UAAU,KACrB,aAAa,CAAC,MAAM,CAyCtB,CAAA"}
@@ -0,0 +1,30 @@
1
+ import { snippetz as e } from "@scalar/snippetz";
2
+ //#region src/code-example/helpers/get-snippet.ts
3
+ var t = "ws://replace.me", n = (n, r, i) => {
4
+ try {
5
+ if (!i.url) return [/* @__PURE__ */ Error("Please enter a URL to see a code snippet"), null];
6
+ let a = i.url.startsWith("/") ? "" : "/";
7
+ try {
8
+ new URL(i.url);
9
+ } catch {
10
+ i.url = `${t}${a}${i.url}`;
11
+ }
12
+ if (i.postData?.mimeType === "application/json") try {
13
+ JSON.parse(i.postData.text || "{}");
14
+ } catch (e) {
15
+ return console.error("[getSnippet] Invalid JSON body", e), [/* @__PURE__ */ Error("Invalid JSON body"), null];
16
+ }
17
+ let o = n.replace("javascript", "js");
18
+ if (e().hasPlugin(o, r)) {
19
+ let n = e().print(o, r, i);
20
+ return n ? [null, n.replace(`${t}${a}`, "")] : [/* @__PURE__ */ Error("Error generating snippet"), null];
21
+ }
22
+ } catch (e) {
23
+ return console.error("[getSnippet] Error generating snippet", e), [/* @__PURE__ */ Error("Error generating snippet"), null];
24
+ }
25
+ return [/* @__PURE__ */ Error("No snippet found"), null];
26
+ };
27
+ //#endregion
28
+ export { n as getSnippet };
29
+
30
+ //# sourceMappingURL=get-snippet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-snippet.js","names":[],"sources":["../../../src/code-example/helpers/get-snippet.ts"],"sourcesContent":["import type { ErrorResponse } from '@scalar/helpers/errors/normalize-error'\nimport { type ClientId, type TargetId, snippetz } from '@scalar/snippetz'\nimport type { Request as HarRequest } from 'har-format'\n\n/** Key used to hack around the invalid urls */\nconst INVALID_URLS_PREFIX = 'ws://replace.me'\n\n/**\n * Returns a code example for given operation\n */\nexport const getSnippet = <T extends TargetId>(\n target: T | 'javascript',\n client: ClientId<T>,\n harRequest: HarRequest,\n): ErrorResponse<string> => {\n try {\n if (!harRequest.url) {\n return [new Error('Please enter a URL to see a code snippet'), null]\n }\n\n const separator = harRequest.url.startsWith('/') ? '' : '/'\n\n // Hack to get around invalid URLS until we update the snippets lib\n try {\n new URL(harRequest.url)\n } catch {\n harRequest.url = `${INVALID_URLS_PREFIX}${separator}${harRequest.url}`\n }\n\n // Ensure we have valid JSON\n if (harRequest.postData?.mimeType === 'application/json') {\n try {\n JSON.parse(harRequest.postData.text || '{}')\n } catch (error) {\n console.error('[getSnippet] Invalid JSON body', error)\n return [new Error('Invalid JSON body'), null]\n }\n }\n // TODO: Fix this, use js (instead of javascript) everywhere\n const snippetzTargetKey = target.replace('javascript', 'js') as TargetId\n\n if (snippetz().hasPlugin(snippetzTargetKey, client)) {\n const payload = snippetz().print(snippetzTargetKey, client as ClientId<TargetId>, harRequest)\n if (!payload) {\n return [new Error('Error generating snippet'), null]\n }\n\n return [null, payload.replace(`${INVALID_URLS_PREFIX}${separator}`, '')]\n }\n } catch (error) {\n console.error('[getSnippet] Error generating snippet', error)\n return [new Error('Error generating snippet'), null]\n }\n\n return [new Error('No snippet found'), null]\n}\n"],"mappings":";;AAKA,IAAM,IAAsB,mBAKf,KACX,GACA,GACA,MAC0B;AAC1B,KAAI;AACF,MAAI,CAAC,EAAW,IACd,QAAO,CAAC,gBAAI,MAAM,2CAA2C,EAAE,KAAK;EAGtE,IAAM,IAAY,EAAW,IAAI,WAAW,IAAI,GAAG,KAAK;AAGxD,MAAI;AACF,OAAI,IAAI,EAAW,IAAI;UACjB;AACN,KAAW,MAAM,GAAG,IAAsB,IAAY,EAAW;;AAInE,MAAI,EAAW,UAAU,aAAa,mBACpC,KAAI;AACF,QAAK,MAAM,EAAW,SAAS,QAAQ,KAAK;WACrC,GAAO;AAEd,UADA,QAAQ,MAAM,kCAAkC,EAAM,EAC/C,CAAC,gBAAI,MAAM,oBAAoB,EAAE,KAAK;;EAIjD,IAAM,IAAoB,EAAO,QAAQ,cAAc,KAAK;AAE5D,MAAI,GAAU,CAAC,UAAU,GAAmB,EAAO,EAAE;GACnD,IAAM,IAAU,GAAU,CAAC,MAAM,GAAmB,GAA8B,EAAW;AAK7F,UAJK,IAIE,CAAC,MAAM,EAAQ,QAAQ,GAAG,IAAsB,KAAa,GAAG,CAAC,GAH/D,CAAC,gBAAI,MAAM,2BAA2B,EAAE,KAAK;;UAKjD,GAAO;AAEd,SADA,QAAQ,MAAM,yCAAyC,EAAM,EACtD,CAAC,gBAAI,MAAM,2BAA2B,EAAE,KAAK;;AAGtD,QAAO,CAAC,gBAAI,MAAM,mBAAmB,EAAE,KAAK"}
@@ -0,0 +1,72 @@
1
+ import type { HttpMethod } from '@scalar/helpers/http/http-methods';
2
+ import { type SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example';
3
+ import type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies';
4
+ import type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
5
+ import type { Request as HarRequest } from 'har-format';
6
+ export type OperationToHarProps = {
7
+ /** OpenAPI Operation object */
8
+ operation: OperationObject;
9
+ /** HTTP method of the operation */
10
+ method: HttpMethod;
11
+ /** Path of the operation */
12
+ path: string;
13
+ /**
14
+ * Name of the currently selected operation example
15
+ *
16
+ * Applies to both the body and the parameters
17
+ */
18
+ example?: string;
19
+ /**
20
+ * Content type of the operation
21
+ *
22
+ * Applies to both the body and the parameters (if applicable)
23
+ * @defaults to the first content type in the MediaTypeObject
24
+ */
25
+ contentType?: string;
26
+ /** OpenAPI Server object */
27
+ server?: ServerObject | null;
28
+ /** OpenAPI SecurityScheme objects which are applicable to the operation */
29
+ securitySchemes?: SecuritySchemeObjectSecret[];
30
+ /** Workspace + document cookies */
31
+ globalCookies?: XScalarCookie[];
32
+ /**
33
+ * Whether to include default headers (e.g., Accept, Content-Type) automatically.
34
+ * If false, default headers will be omitted from the HAR request.
35
+ * @default true
36
+ */
37
+ includeDefaultHeaders?: boolean;
38
+ /**
39
+ * Selected oneOf/anyOf variants for nested request body example generation
40
+ * (e.g. from the schema dropdowns in the API reference).
41
+ */
42
+ requestBodyCompositionSelection?: Record<string, number>;
43
+ /**
44
+ * Whether to disable parameters by default.
45
+ * @default false
46
+ */
47
+ defaultDisabledParameters?: boolean;
48
+ };
49
+ /**
50
+ * Converts an OpenAPI Operation to a HarRequest format for generating HTTP request snippets.
51
+ *
52
+ * This function transforms OpenAPI 3.1 operation objects into HAR (HTTP Archive) format requests,
53
+ * which can be used to generate code snippets for various programming languages and HTTP clients.
54
+ *
55
+ * The conversion handles:
56
+ * - Server URL processing and path parameter substitution
57
+ * - Query parameter formatting based on OpenAPI parameter styles
58
+ * - Request body processing with content type handling
59
+ * - Security scheme integration (API keys, etc.)
60
+ *
61
+ * The resulting HarRequest object follows the HAR specification and includes:
62
+ * - HTTP method and URL
63
+ * - Headers and query parameters
64
+ * - Request body (if present)
65
+ * - Cookie information
66
+ * - Size calculations for headers and body
67
+ *
68
+ * @see https://w3c.github.io/web-performance/specs/HAR/Overview.html
69
+ * @see https://spec.openapis.org/oas/v3.1.0#operation-object
70
+ */
71
+ export declare const operationToHar: ({ includeDefaultHeaders, operation, contentType, method, path, server, example, securitySchemes, globalCookies, requestBodyCompositionSelection, defaultDisabledParameters, }: OperationToHarProps) => HarRequest;
72
+ //# sourceMappingURL=operation-to-har.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation-to-har.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/operation-to-har.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAEnE,OAAO,EACL,KAAK,0BAA0B,EAIhC,MAAM,yCAAyC,CAAA;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AACxG,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,8DAA8D,CAAA;AACjH,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AASvD,MAAM,MAAM,mBAAmB,GAAG;IAChC,+BAA+B;IAC/B,SAAS,EAAE,eAAe,CAAA;IAC1B,mCAAmC;IACnC,MAAM,EAAE,UAAU,CAAA;IAClB,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;IAC5B,2EAA2E;IAC3E,eAAe,CAAC,EAAE,0BAA0B,EAAE,CAAA;IAC9C,mCAAmC;IACnC,aAAa,CAAC,EAAE,aAAa,EAAE,CAAA;IAC/B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B;;;OAGG;IACH,+BAA+B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxD;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,cAAc,GAAI,+KAY5B,mBAAmB,KAAG,UAwGxB,CAAA"}
@@ -0,0 +1,78 @@
1
+ import { APP_VERSION as e } from "../../../constants.js";
2
+ import { processBody as t } from "./process-body.js";
3
+ import { processParameters as n } from "./process-parameters.js";
4
+ import { processSecuritySchemes as r } from "./process-security-schemes.js";
5
+ import { processServerUrl as i } from "./process-server-url.js";
6
+ import { getResolvedRef as a } from "@scalar/workspace-store/helpers/get-resolved-ref";
7
+ import { isElectron as o } from "@scalar/helpers/general/is-electron";
8
+ import { filterGlobalCookie as s, getDefaultHeaders as c, restoreConventionalDefaultHeaderNames as l } from "@scalar/workspace-store/request-example";
9
+ //#region src/code-example/helpers/operation-to-har/operation-to-har.ts
10
+ var u = ({ includeDefaultHeaders: u = !1, operation: d, contentType: f, method: p, path: m, server: h = null, example: g, securitySchemes: _, globalCookies: v, requestBodyCompositionSelection: y, defaultDisabledParameters: b = !1 }) => {
11
+ let x = l(u ? c({
12
+ method: p,
13
+ operation: d,
14
+ exampleName: g ?? "default",
15
+ hideDisabledHeaders: !0,
16
+ hideOverriddenHeaders: !0,
17
+ options: {
18
+ isElectron: o(),
19
+ appVersion: e
20
+ }
21
+ }) : {}), S = d["x-scalar-disable-parameters"]?.["global-cookies"]?.[g ?? "default"] ?? {}, C = {
22
+ method: p,
23
+ url: i(h, m),
24
+ headers: Object.entries(x).map(([e, t]) => ({
25
+ name: e,
26
+ value: t
27
+ })),
28
+ queryString: [],
29
+ postData: void 0,
30
+ httpVersion: "HTTP/1.1",
31
+ cookies: [],
32
+ headersSize: -1,
33
+ bodySize: -1
34
+ };
35
+ if (d.parameters) {
36
+ let { url: e, headers: t, queryString: r, cookies: i } = n({
37
+ harRequest: C,
38
+ parameters: d.parameters,
39
+ example: g,
40
+ defaultDisabled: b
41
+ }), a = v?.filter((t) => s({
42
+ cookie: t,
43
+ url: e,
44
+ disabledGlobalCookies: S
45
+ }))?.map((e) => ({
46
+ name: e.name,
47
+ value: e.value
48
+ })) ?? [];
49
+ C.url = e, C.headers = t, C.queryString = r, C.cookies = [...a, ...i];
50
+ }
51
+ let w = a(d.requestBody);
52
+ if (w?.content) {
53
+ let e = t({
54
+ requestBody: w,
55
+ contentType: f,
56
+ example: g,
57
+ requestBodyCompositionSelection: y
58
+ });
59
+ if (e && (C.postData = e, C.bodySize = e.text?.length ?? -1, e.mimeType)) {
60
+ let t = C.headers.find((e) => e.name.toLowerCase() === "content-type");
61
+ t && !t.value ? t.value = e.mimeType : t || C.headers.push({
62
+ name: "Content-Type",
63
+ value: e.mimeType
64
+ });
65
+ }
66
+ }
67
+ if (_) {
68
+ let { headers: e, queryString: t, cookies: n } = r(_);
69
+ C.headers.push(...e), C.queryString.push(...t), C.cookies.push(...n);
70
+ }
71
+ let T = 0;
72
+ for (let e of C.headers) T += (e.name?.length ?? 0) + 2 + (e.value?.length ?? 0) + 2;
73
+ return C.headersSize = T, C;
74
+ };
75
+ //#endregion
76
+ export { u as operationToHar };
77
+
78
+ //# sourceMappingURL=operation-to-har.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation-to-har.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/operation-to-har.ts"],"sourcesContent":["import { isElectron } from '@scalar/helpers/general/is-electron'\nimport type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n type SecuritySchemeObjectSecret,\n filterGlobalCookie,\n getDefaultHeaders,\n restoreConventionalDefaultHeaderNames,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\nimport type { Request as HarRequest } from 'har-format'\n\nimport { APP_VERSION } from '@/constants'\n\nimport { processBody } from './process-body'\nimport { processParameters } from './process-parameters'\nimport { processSecuritySchemes } from './process-security-schemes'\nimport { processServerUrl } from './process-server-url'\n\nexport type OperationToHarProps = {\n /** OpenAPI Operation object */\n operation: OperationObject\n /** HTTP method of the operation */\n method: HttpMethod\n /** Path of the operation */\n path: string\n /**\n * Name of the currently selected operation example\n *\n * Applies to both the body and the parameters\n */\n example?: string\n /**\n * Content type of the operation\n *\n * Applies to both the body and the parameters (if applicable)\n * @defaults to the first content type in the MediaTypeObject\n */\n contentType?: string\n /** OpenAPI Server object */\n server?: ServerObject | null\n /** OpenAPI SecurityScheme objects which are applicable to the operation */\n securitySchemes?: SecuritySchemeObjectSecret[]\n /** Workspace + document cookies */\n globalCookies?: XScalarCookie[]\n /**\n * Whether to include default headers (e.g., Accept, Content-Type) automatically.\n * If false, default headers will be omitted from the HAR request.\n * @default true\n */\n includeDefaultHeaders?: boolean\n /**\n * Selected oneOf/anyOf variants for nested request body example generation\n * (e.g. from the schema dropdowns in the API reference).\n */\n requestBodyCompositionSelection?: Record<string, number>\n /**\n * Whether to disable parameters by default.\n * @default false\n */\n defaultDisabledParameters?: boolean\n}\n\n/**\n * Converts an OpenAPI Operation to a HarRequest format for generating HTTP request snippets.\n *\n * This function transforms OpenAPI 3.1 operation objects into HAR (HTTP Archive) format requests,\n * which can be used to generate code snippets for various programming languages and HTTP clients.\n *\n * The conversion handles:\n * - Server URL processing and path parameter substitution\n * - Query parameter formatting based on OpenAPI parameter styles\n * - Request body processing with content type handling\n * - Security scheme integration (API keys, etc.)\n *\n * The resulting HarRequest object follows the HAR specification and includes:\n * - HTTP method and URL\n * - Headers and query parameters\n * - Request body (if present)\n * - Cookie information\n * - Size calculations for headers and body\n *\n * @see https://w3c.github.io/web-performance/specs/HAR/Overview.html\n * @see https://spec.openapis.org/oas/v3.1.0#operation-object\n */\nexport const operationToHar = ({\n includeDefaultHeaders = false,\n operation,\n contentType,\n method,\n path,\n server = null,\n example,\n securitySchemes,\n globalCookies,\n requestBodyCompositionSelection,\n defaultDisabledParameters = false,\n}: OperationToHarProps): HarRequest => {\n const defaultHeaders = includeDefaultHeaders\n ? getDefaultHeaders({\n method,\n operation,\n exampleName: example ?? 'default',\n hideDisabledHeaders: true,\n hideOverriddenHeaders: true,\n options: { isElectron: isElectron(), appVersion: APP_VERSION },\n })\n : {}\n const defaultHeadersWithConventionalNames = restoreConventionalDefaultHeaderNames(defaultHeaders)\n\n const disabledGlobalCookies =\n operation['x-scalar-disable-parameters']?.['global-cookies']?.[example ?? 'default'] ?? {}\n\n const serverUrl = processServerUrl(server, path)\n\n // Initialize the HAR request with basic properties\n const harRequest: HarRequest = {\n method,\n url: serverUrl,\n headers: Object.entries(defaultHeadersWithConventionalNames).map(([name, value]) => ({ name, value })),\n queryString: [],\n postData: undefined,\n httpVersion: 'HTTP/1.1',\n cookies: [],\n headersSize: -1,\n bodySize: -1,\n }\n\n // Handle parameters\n if (operation.parameters) {\n const { url, headers, queryString, cookies } = processParameters({\n harRequest,\n parameters: operation.parameters,\n example,\n defaultDisabled: defaultDisabledParameters,\n })\n\n // Correctly filter the global cookies by the processed url\n const filteredGlobalCookies =\n globalCookies\n ?.filter((cookie) => filterGlobalCookie({ cookie, url, disabledGlobalCookies }))\n ?.map((cookie) => ({ name: cookie.name, value: cookie.value })) ?? []\n\n harRequest.url = url\n harRequest.headers = headers\n harRequest.queryString = queryString\n harRequest.cookies = [...filteredGlobalCookies, ...cookies]\n }\n\n const body = getResolvedRef(operation.requestBody)\n\n // Handle request body\n if (body?.content) {\n const postData = processBody({\n requestBody: body,\n contentType,\n example,\n requestBodyCompositionSelection,\n })\n\n if (postData) {\n harRequest.postData = postData\n harRequest.bodySize = postData.text?.length ?? -1\n\n // Add or update Content-Type header\n if (postData.mimeType) {\n const existingContentTypeHeader = harRequest.headers.find(\n (header) => header.name.toLowerCase() === 'content-type',\n )\n // Update existing header if it has an empty value\n if (existingContentTypeHeader && !existingContentTypeHeader.value) {\n existingContentTypeHeader.value = postData.mimeType\n }\n // Add new header if none exists\n else if (!existingContentTypeHeader) {\n harRequest.headers.push({\n name: 'Content-Type',\n value: postData.mimeType,\n })\n }\n }\n }\n }\n\n // Handle security schemes\n if (securitySchemes) {\n const { headers, queryString, cookies } = processSecuritySchemes(securitySchemes)\n harRequest.headers.push(...headers)\n harRequest.queryString.push(...queryString)\n harRequest.cookies.push(...cookies)\n }\n\n // Calculate headers size without allocating a large joined string\n let headersSize = 0\n for (const h of harRequest.headers) {\n // name + \": \" + value + \"\\r\\n\"\n headersSize += (h.name?.length ?? 0) + 2 + (h.value?.length ?? 0) + 2\n }\n harRequest.headersSize = headersSize\n\n return harRequest\n}\n"],"mappings":";;;;;;;;;AAsFA,IAAa,KAAkB,EAC7B,2BAAwB,IACxB,cACA,gBACA,WACA,SACA,YAAS,MACT,YACA,oBACA,kBACA,oCACA,+BAA4B,SACS;CAWrC,IAAM,IAAsC,EAVrB,IACnB,EAAkB;EAChB;EACA;EACA,aAAa,KAAW;EACxB,qBAAqB;EACrB,uBAAuB;EACvB,SAAS;GAAE,YAAY,GAAY;GAAE,YAAY;GAAa;EAC/D,CAAC,GACF,EAAE,CAC2F,EAE3F,IACJ,EAAU,iCAAiC,oBAAoB,KAAW,cAAc,EAAE,EAKtF,IAAyB;EAC7B;EACA,KALgB,EAAiB,GAAQ,EAAK;EAM9C,SAAS,OAAO,QAAQ,EAAoC,CAAC,KAAK,CAAC,GAAM,QAAY;GAAE;GAAM;GAAO,EAAE;EACtG,aAAa,EAAE;EACf,UAAU,KAAA;EACV,aAAa;EACb,SAAS,EAAE;EACX,aAAa;EACb,UAAU;EACX;AAGD,KAAI,EAAU,YAAY;EACxB,IAAM,EAAE,QAAK,YAAS,gBAAa,eAAY,EAAkB;GAC/D;GACA,YAAY,EAAU;GACtB;GACA,iBAAiB;GAClB,CAAC,EAGI,IACJ,GACI,QAAQ,MAAW,EAAmB;GAAE;GAAQ;GAAK;GAAuB,CAAC,CAAC,EAC9E,KAAK,OAAY;GAAE,MAAM,EAAO;GAAM,OAAO,EAAO;GAAO,EAAE,IAAI,EAAE;AAKzE,EAHA,EAAW,MAAM,GACjB,EAAW,UAAU,GACrB,EAAW,cAAc,GACzB,EAAW,UAAU,CAAC,GAAG,GAAuB,GAAG,EAAQ;;CAG7D,IAAM,IAAO,EAAe,EAAU,YAAY;AAGlD,KAAI,GAAM,SAAS;EACjB,IAAM,IAAW,EAAY;GAC3B,aAAa;GACb;GACA;GACA;GACD,CAAC;AAEF,MAAI,MACF,EAAW,WAAW,GACtB,EAAW,WAAW,EAAS,MAAM,UAAU,IAG3C,EAAS,WAAU;GACrB,IAAM,IAA4B,EAAW,QAAQ,MAClD,MAAW,EAAO,KAAK,aAAa,KAAK,eAC3C;AAED,GAAI,KAA6B,CAAC,EAA0B,QAC1D,EAA0B,QAAQ,EAAS,WAGnC,KACR,EAAW,QAAQ,KAAK;IACtB,MAAM;IACN,OAAO,EAAS;IACjB,CAAC;;;AAOV,KAAI,GAAiB;EACnB,IAAM,EAAE,YAAS,gBAAa,eAAY,EAAuB,EAAgB;AAGjF,EAFA,EAAW,QAAQ,KAAK,GAAG,EAAQ,EACnC,EAAW,YAAY,KAAK,GAAG,EAAY,EAC3C,EAAW,QAAQ,KAAK,GAAG,EAAQ;;CAIrC,IAAI,IAAc;AAClB,MAAK,IAAM,KAAK,EAAW,QAEzB,OAAgB,EAAE,MAAM,UAAU,KAAK,KAAK,EAAE,OAAO,UAAU,KAAK;AAItE,QAFA,EAAW,cAAc,GAElB"}
@@ -0,0 +1,13 @@
1
+ import type { RequestBodyObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
2
+ import type { PostData } from 'har-format';
3
+ import type { OperationToHarProps } from './operation-to-har';
4
+ type ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'example' | 'requestBodyCompositionSelection'> & {
5
+ requestBody: RequestBodyObject;
6
+ };
7
+ /**
8
+ * Processes the request body and returns the processed data
9
+ * Returns undefined if no example is found
10
+ */
11
+ export declare const processBody: ({ requestBody, contentType, example, requestBodyCompositionSelection, }: ProcessBodyProps) => PostData | undefined;
12
+ export {};
13
+ //# sourceMappingURL=process-body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-body.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAEV,iBAAiB,EAElB,MAAM,8DAA8D,CAAA;AACrE,OAAO,KAAK,EAAS,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,KAAK,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,SAAS,GAAG,iCAAiC,CAAC,GAAG;IACjH,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAyJD;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,yEAKzB,gBAAgB,KAAG,QAAQ,GAAG,SAyFhC,CAAA"}
@@ -0,0 +1,100 @@
1
+ import { getResolvedRefDeep as e } from "@scalar/workspace-store/helpers/get-resolved-ref-deep";
2
+ import { getResolvedRef as t } from "@scalar/workspace-store/helpers/get-resolved-ref";
3
+ import { getExample as n, getExampleFromSchema as r, serializeFormPropertyWithEncoding as i } from "@scalar/workspace-store/request-example";
4
+ import { json2xml as a } from "@scalar/helpers/file/json2xml";
5
+ import { unpackProxyObject as o } from "@scalar/workspace-store/helpers/unpack-proxy";
6
+ //#region src/code-example/helpers/operation-to-har/process-body.ts
7
+ var s = (e, t, n, r = !1) => {
8
+ let a = [], c = Array.isArray(e) ? e.filter((e) => !e.isDisabled).map((e) => [String(e.name), e.value]) : Object.entries(e);
9
+ for (let [e, l] of c) {
10
+ if (l == null) continue;
11
+ let c = n ? void 0 : t?.[e], u = c && (c.style !== void 0 || c.explode !== void 0 || c.allowReserved !== void 0), d = u || !r ? void 0 : c?.contentType, f = n ? null : i(e, l, c);
12
+ if (f) for (let e of f) a.push({
13
+ name: e.key,
14
+ value: e.value
15
+ });
16
+ else if (l instanceof File) {
17
+ let t = o(l);
18
+ a.push({
19
+ name: e,
20
+ value: `@${t.name}`,
21
+ ...d ? { contentType: d } : {}
22
+ });
23
+ } else if (d && typeof l == "object") a.push({
24
+ name: e,
25
+ value: JSON.stringify(o(l)),
26
+ contentType: d
27
+ });
28
+ else if (r && !n && !u && typeof l == "object" && !Array.isArray(l)) a.push({
29
+ name: e,
30
+ value: JSON.stringify(o(l)),
31
+ contentType: "application/json"
32
+ });
33
+ else if (Array.isArray(l)) for (let t of l) if (t instanceof File) {
34
+ let n = o(t);
35
+ a.push({
36
+ name: e,
37
+ value: `@${n.name}`
38
+ });
39
+ } else r && !n && !u && typeof t == "object" && t ? a.push({
40
+ name: e,
41
+ value: JSON.stringify(o(t)),
42
+ contentType: "application/json"
43
+ }) : a.push({
44
+ name: e,
45
+ value: String(t)
46
+ });
47
+ else if (typeof l == "object") {
48
+ let t = s(l, void 0, e);
49
+ for (let n of t) a.push({
50
+ name: `${e}.${n.name}`,
51
+ value: n.value
52
+ });
53
+ } else a.push({
54
+ name: e,
55
+ value: String(l),
56
+ ...d ? { contentType: d } : {}
57
+ });
58
+ }
59
+ return a;
60
+ }, c = ({ requestBody: i, contentType: c, example: l, requestBodyCompositionSelection: u }) => {
61
+ let d = c || Object.keys(i.content)[0] || "", f = d === "other" ? "" : d, p = (e) => `@${o(e).name || "filename"}`, m = i.content[d]?.encoding, h = d === "multipart/form-data" || d === "application/x-www-form-urlencoded", g = d === "application/xml", _ = n(i, l, c)?.value;
62
+ if (_ !== void 0) {
63
+ let e = typeof _ == "object" && _ ? o(_) : _;
64
+ return h && typeof e == "object" && e ? {
65
+ mimeType: f,
66
+ params: s(e, m, void 0, d === "multipart/form-data")
67
+ } : g && typeof e == "object" && e ? {
68
+ mimeType: f,
69
+ text: a(e)
70
+ } : e instanceof File ? {
71
+ mimeType: f,
72
+ text: p(e)
73
+ } : {
74
+ mimeType: f,
75
+ text: typeof e == "string" ? e : JSON.stringify(e)
76
+ };
77
+ }
78
+ let v = t(i.content[d]?.schema);
79
+ if (v !== void 0) {
80
+ let t = r(e(v), {
81
+ compositionSelection: u,
82
+ mode: "write",
83
+ xml: g
84
+ }, { schemaPath: ["requestBody"] });
85
+ if (t !== void 0) return h && typeof t == "object" && t ? {
86
+ mimeType: f,
87
+ params: s(t, m, void 0, d === "multipart/form-data")
88
+ } : g && typeof t == "object" && t ? {
89
+ mimeType: f,
90
+ text: a(t)
91
+ } : {
92
+ mimeType: f,
93
+ text: typeof t == "string" ? t : JSON.stringify(t)
94
+ };
95
+ }
96
+ };
97
+ //#endregion
98
+ export { c as processBody };
99
+
100
+ //# sourceMappingURL=process-body.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-body.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"sourcesContent":["import { json2xml } from '@scalar/helpers/file/json2xml'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { getResolvedRefDeep } from '@scalar/workspace-store/helpers/get-resolved-ref-deep'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n getExample,\n getExampleFromSchema,\n serializeFormPropertyWithEncoding,\n} from '@scalar/workspace-store/request-example'\nimport type {\n MediaTypeObject,\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\nimport type { Param, PostData } from 'har-format'\n\nimport type { OperationToHarProps } from './operation-to-har'\n\ntype ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'example' | 'requestBodyCompositionSelection'> & {\n requestBody: RequestBodyObject\n}\n\ntype MultipartEncodingMap = MediaTypeObject['encoding']\n\n/**\n * Converts a form-data body into HAR `Param[]` entries for `multipart/form-data`\n * and `application/x-www-form-urlencoded` requests.\n *\n * Per OpenAPI 3.1.x Encoding Object, each property's serialization is governed\n * by an optional Encoding entry. When `style` / `explode` / `allowReserved` is\n * set, the value is serialized RFC6570-style and `contentType` is ignored.\n * When only `contentType` is set, the property becomes a single part with that\n * type. Otherwise spec defaults apply (object → `application/json` for multipart,\n * primitives → `text/plain`).\n *\n * @param obj - The form-data payload, either an object keyed by property name\n * or a HAR-style `{ name, value, isDisabled }[]` array.\n * @param encoding - The `encoding` map from the Media Type Object, if any.\n * Used only at the top level (`parentKey` undefined).\n * @param parentKey - When set, we are flattening a nested object inside another\n * property; encoding is ignored and keys are joined with `.` (legacy default).\n * @param isMultipart - True for `multipart/form-data`. Gates the spec defaults\n * for object/array properties that should become a single `application/json`\n * part. Urlencoded bodies skip those branches and fall through to flattening.\n */\nconst objectToFormParams = (\n obj: object | { name: string; value: unknown; isDisabled: boolean }[],\n encoding?: MultipartEncodingMap,\n parentKey?: string,\n isMultipart = false,\n): Param[] => {\n const params: Param[] = []\n\n /** Ensure we do not include disabled items */\n const entries: [string, unknown][] = Array.isArray(obj)\n ? obj.filter((item) => !item.isDisabled).map((item) => [String(item.name), item.value])\n : Object.entries(obj)\n\n for (const [key, value] of entries) {\n if (value === undefined || value === null) {\n continue\n }\n\n const partEncoding = parentKey ? undefined : encoding?.[key]\n /**\n * Per OpenAPI 3.1.1: when style, explode, or allowReserved is explicitly set on the\n * encoding entry, contentType (implicit or explicit) is ignored and the value is\n * serialized as if it were a query-style parameter.\n */\n const hasFormStyle =\n partEncoding &&\n (partEncoding.style !== undefined ||\n partEncoding.explode !== undefined ||\n partEncoding.allowReserved !== undefined)\n /**\n * Per OAS 3.1.x Encoding Object: `contentType` SHALL be ignored if the request body\n * media type is not a multipart. For `application/x-www-form-urlencoded` we still\n * honor `style`/`explode`/`allowReserved` (handled above), but a `contentType`-only\n * entry has no effect — values fall through to the dotted-key flattening default.\n */\n const explicitContentType = hasFormStyle || !isMultipart ? undefined : partEncoding?.contentType\n\n /**\n * When the encoding sets style/explode/allowReserved, serialize the value RFC6570-style\n * (bracket/exploded notation) and ignore contentType. See `serializeFormPropertyWithEncoding`\n * for the per-style rules; it returns null for primitives, Files, and arrays of Files, which\n * then fall through to the dedicated branches below. HAR represents multipart and urlencoded\n * the same way via `PostData.params`, so the resulting parts work for both.\n */\n const styleParams = parentKey ? null : serializeFormPropertyWithEncoding(key, value, partEncoding)\n if (styleParams) {\n for (const param of styleParams) {\n params.push({ name: param.key, value: param.value })\n }\n } else if (value instanceof File) {\n /**\n * File values render as `@filename` references, the conventional cURL syntax for an\n * attached file. Picked up by snippet renderers downstream (e.g. `--form 'x=@file.png'`).\n */\n const file = unpackProxyObject(value)\n params.push({\n name: key,\n value: `@${file.name}`,\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n } else if (explicitContentType && typeof value === 'object') {\n /**\n * Per OAS 3.1.x Encoding Object: an explicit `encoding[key].contentType` on a\n * complex value overrides the default and emits a single part containing the value\n * JSON-stringified into that media type. Only reachable when style/explode/allowReserved\n * are unset (otherwise contentType is ignored — see the style branch above).\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: explicitContentType,\n })\n } else if (isMultipart && !parentKey && !hasFormStyle && typeof value === 'object' && !Array.isArray(value)) {\n /**\n * Per OpenAPI 3.x: a top-level multipart property whose value is an object (and not a File)\n * defaults to a single part encoded as application/json, rather than being flattened\n * into multiple parts with dotted keys.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: 'application/json',\n })\n } else if (Array.isArray(value)) {\n for (const item of value) {\n if (item instanceof File) {\n const file = unpackProxyObject(item)\n params.push({ name: key, value: `@${file.name}` })\n } else if (isMultipart && !parentKey && !hasFormStyle && typeof item === 'object' && item !== null) {\n /**\n * Per OpenAPI 3.x: a top-level multipart array of complex items defaults each part\n * to application/json, instead of flattening object items into dotted keys.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(item)),\n contentType: 'application/json',\n })\n } else {\n params.push({ name: key, value: String(item) })\n }\n }\n } else if (typeof value === 'object') {\n /**\n * Legacy fallback: flatten nested objects into dotted-key parts. Reached when the\n * multipart JSON-default branches above don't apply — i.e. either inside a recursive\n * call (`parentKey` set) or on `application/x-www-form-urlencoded` bodies without an\n * explicit encoding entry. Strict OAS 3.1.x would use `style: form, explode: true` as\n * the urlencoded default (inner keys become top-level params); we keep dotted keys for\n * backwards compatibility with consumers that already parse this shape.\n */\n const nestedParams = objectToFormParams(value, undefined, key)\n\n for (const param of nestedParams) {\n params.push({ name: `${key}.${param.name}`, value: param.value })\n }\n } else {\n params.push({\n name: key,\n value: String(value),\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n }\n }\n\n return params\n}\n\n/**\n * Processes the request body and returns the processed data\n * Returns undefined if no example is found\n */\nexport const processBody = ({\n requestBody,\n contentType,\n example,\n requestBodyCompositionSelection,\n}: ProcessBodyProps): PostData | undefined => {\n const _contentType = contentType || Object.keys(requestBody.content)[0] || ''\n /** Empty when \"Other\" is selected so snippets do not inject `Content-Type: other`. */\n const harMimeType = _contentType === 'other' ? '' : _contentType\n const formatBinaryFile = (file: File) => {\n const unwrappedFile = unpackProxyObject(file)\n return `@${unwrappedFile.name || 'filename'}`\n }\n const encoding = requestBody.content[_contentType]?.encoding\n\n // Check if this is a form data content type\n const isFormData = _contentType === 'multipart/form-data' || _contentType === 'application/x-www-form-urlencoded'\n\n // Check if this is an XML content type\n const isXml = _contentType === 'application/xml'\n\n // Get the example value\n const _example = getExample(requestBody, example, contentType)?.value\n\n // Return the provided top level example\n if (typeof _example !== 'undefined') {\n const exampleValue = _example !== null && typeof _example === 'object' ? unpackProxyObject(_example) : _example\n\n if (isFormData && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(exampleValue, encoding, undefined, _contentType === 'multipart/form-data'),\n }\n }\n\n if (isXml && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n text: json2xml(exampleValue),\n }\n }\n\n if (exampleValue instanceof File) {\n return {\n mimeType: harMimeType,\n text: formatBinaryFile(exampleValue),\n }\n }\n\n return {\n mimeType: harMimeType,\n text: typeof exampleValue === 'string' ? exampleValue : JSON.stringify(exampleValue),\n }\n }\n\n // Try to extract examples from the schema\n const contentSchema = getResolvedRef(requestBody.content[_contentType]?.schema)\n if (typeof contentSchema !== 'undefined') {\n const resolvedContentSchema = getResolvedRefDeep(contentSchema) as SchemaObject\n const extractedExample = getExampleFromSchema(\n resolvedContentSchema,\n {\n compositionSelection: requestBodyCompositionSelection,\n mode: 'write',\n xml: isXml,\n },\n {\n schemaPath: ['requestBody'],\n },\n )\n\n if (extractedExample !== undefined) {\n if (isFormData && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(extractedExample, encoding, undefined, _contentType === 'multipart/form-data'),\n }\n }\n\n if (isXml && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n text: json2xml(extractedExample),\n }\n }\n\n return {\n mimeType: harMimeType,\n text: typeof extractedExample === 'string' ? extractedExample : JSON.stringify(extractedExample),\n }\n }\n }\n\n return undefined\n}\n"],"mappings":"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"}
@@ -0,0 +1,24 @@
1
+ import type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
2
+ import type { Request as HarRequest } from 'har-format';
3
+ type ProcessedParameters = {
4
+ url: string;
5
+ headers: HarRequest['headers'];
6
+ queryString: HarRequest['queryString'];
7
+ cookies: HarRequest['cookies'];
8
+ };
9
+ /**
10
+ * Process OpenAPI parameters and return the updated properties.
11
+ * Handles path, query, and header parameters with various styles and explode options.
12
+ *
13
+ * @see https://spec.openapis.org/oas/latest.html#style-values
14
+ */
15
+ export declare const processParameters: ({ harRequest, parameters, example, defaultDisabled, }: {
16
+ harRequest: HarRequest;
17
+ parameters: OperationObject["parameters"];
18
+ /** The name of the example to use */
19
+ example?: string | undefined;
20
+ /** Whether to disable parameters by default. */
21
+ defaultDisabled: boolean;
22
+ }) => ProcessedParameters;
23
+ export {};
24
+ //# sourceMappingURL=process-parameters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-parameters.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-parameters.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,8DAA8D,CAAA;AACpH,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvD,KAAK,mBAAmB,GAAG;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;IAC9B,WAAW,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;IACtC,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;CAC/B,CAAA;AA2FD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,uDAK/B;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,EAAE,eAAe,CAAC,YAAY,CAAC,CAAA;IACzC,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,gDAAgD;IAChD,eAAe,EAAE,OAAO,CAAA;CACzB,KAAG,mBAqIH,CAAA"}
@@ -0,0 +1,189 @@
1
+ import { getResolvedRef as e } from "@scalar/workspace-store/helpers/get-resolved-ref";
2
+ import { deSerializeParameter as t, getExample as n, getExampleFromSchema as r, isParamDisabled as i, serializeContentValue as a, serializeDeepObjectStyle as o, serializeFormStyle as s, serializeFormStyleForCookies as c, serializePipeDelimitedStyle as l, serializeSimpleStyle as u, serializeSpaceDelimitedStyle as d } from "@scalar/workspace-store/request-example";
3
+ //#region src/code-example/helpers/operation-to-har/process-parameters.ts
4
+ var f = (t) => (t ?? []).map((t) => e(t)), p = (e) => "allowReserved" in e && e.allowReserved !== void 0 ? e.allowReserved : "schema" in e && e.schema && typeof e.schema == "object" && "allowReserved" in e.schema ? e.schema.allowReserved === !0 : !1, m = (e, t) => p(t) ? e : encodeURIComponent(e), h = (e) => {
5
+ if (e.in === "header") return {
6
+ style: "simple",
7
+ explode: "explode" in e && e.explode !== void 0 ? e.explode : !1
8
+ };
9
+ if (e.in === "cookie") return {
10
+ style: "form",
11
+ explode: "explode" in e && e.explode !== void 0 ? e.explode : !0
12
+ };
13
+ let t = {
14
+ path: "simple",
15
+ query: "form",
16
+ header: "simple",
17
+ cookie: "form"
18
+ }[e.in], n = "style" in e && e.style ? e.style : t;
19
+ return {
20
+ style: n,
21
+ explode: "explode" in e && e.explode !== void 0 ? e.explode : n === "form"
22
+ };
23
+ }, g = (a, o, s, c) => {
24
+ let l = n(a, o, s);
25
+ if (i(a, l, c)) return;
26
+ if (l?.value !== void 0) return t(l.value, a);
27
+ if (!("schema" in a) || !a.schema) return;
28
+ let u = a.in === "path" ? { emptyString: `{${a.name}}` } : {};
29
+ return r(e(a.schema), u);
30
+ }, _ = ({ harRequest: e, parameters: t, example: n, defaultDisabled: r }) => {
31
+ let i = [...e.headers], p = [...e.queryString], _ = e.url, y = f(t);
32
+ for (let t of y) {
33
+ if (!t.in || !t.name) continue;
34
+ let f = g(t, n, void 0, r);
35
+ if (f === void 0) continue;
36
+ let { style: y, explode: b } = h(t);
37
+ switch (t.in) {
38
+ case "path":
39
+ _ = v(_, t, f, y, b);
40
+ break;
41
+ case "query":
42
+ if ("content" in t && t.content) {
43
+ let e = a(f, Object.keys(t.content)[0] ?? "application/json");
44
+ p.push({
45
+ name: t.name,
46
+ value: m(e, t)
47
+ });
48
+ break;
49
+ }
50
+ switch (y) {
51
+ case "form": {
52
+ let e = s(f, b);
53
+ if (Array.isArray(e)) for (let n of e) {
54
+ let e = n.key || t.name;
55
+ p.push({
56
+ name: e,
57
+ value: m(String(n.value), t)
58
+ });
59
+ }
60
+ else p.push({
61
+ name: t.name,
62
+ value: m(String(e), t)
63
+ });
64
+ break;
65
+ }
66
+ case "spaceDelimited": {
67
+ let e = d(f);
68
+ p.push({
69
+ name: t.name,
70
+ value: m(e, t)
71
+ });
72
+ break;
73
+ }
74
+ case "pipeDelimited": {
75
+ let e = l(f);
76
+ p.push({
77
+ name: t.name,
78
+ value: m(e, t)
79
+ });
80
+ break;
81
+ }
82
+ case "deepObject":
83
+ if (Array.isArray(f)) {
84
+ let e = s(f, !0);
85
+ if (Array.isArray(e)) for (let n of e) {
86
+ let e = n.key || t.name;
87
+ p.push({
88
+ name: e,
89
+ value: m(String(n.value), t)
90
+ });
91
+ }
92
+ else p.push({
93
+ name: t.name,
94
+ value: m(String(e), t)
95
+ });
96
+ } else {
97
+ let e = o(t.name, f);
98
+ for (let n of e) p.push({
99
+ name: n.key,
100
+ value: m(n.value, t)
101
+ });
102
+ }
103
+ break;
104
+ default: p.push({
105
+ name: t.name,
106
+ value: m(String(f), t)
107
+ });
108
+ }
109
+ break;
110
+ case "header": {
111
+ let e = u(f, b);
112
+ i.push({
113
+ name: t.name,
114
+ value: String(e)
115
+ });
116
+ break;
117
+ }
118
+ case "cookie": {
119
+ let n = c(f, b);
120
+ if (Array.isArray(n)) for (let r of n) {
121
+ let n = r.key || t.name, i = r.value === null ? "null" : String(r.value);
122
+ e.cookies.push({
123
+ name: n,
124
+ value: i
125
+ });
126
+ }
127
+ else {
128
+ let r = n === null ? "null" : String(n);
129
+ e.cookies.push({
130
+ name: t.name,
131
+ value: r
132
+ });
133
+ }
134
+ break;
135
+ }
136
+ }
137
+ }
138
+ return {
139
+ url: _,
140
+ headers: i,
141
+ queryString: p,
142
+ cookies: e.cookies
143
+ };
144
+ }, v = (e, t, n, r, i) => {
145
+ switch (r) {
146
+ case "matrix":
147
+ if (i) {
148
+ if (Array.isArray(n)) {
149
+ let r = n.map((e) => `${t.name}=${e}`).join(";");
150
+ return e.replace(`{;${t.name}}`, `;${r}`);
151
+ }
152
+ if (typeof n == "object" && n) {
153
+ let r = Object.entries(n).map(([e, t]) => `${e}=${t}`).join(";");
154
+ return e.replace(`{;${t.name}}`, `;${r}`);
155
+ }
156
+ return e.replace(`{;${t.name}}`, `;${t.name}=${n}`);
157
+ }
158
+ if (Array.isArray(n)) return e.replace(`{;${t.name}}`, `;${t.name}=${n.join(",")}`);
159
+ if (typeof n == "object" && n) {
160
+ let r = Object.entries(n).map(([e, t]) => `${e},${t}`).join(",");
161
+ return e.replace(`{;${t.name}}`, `;${t.name}=${r}`);
162
+ }
163
+ return e.replace(`{;${t.name}}`, `;${t.name}=${n}`);
164
+ case "label":
165
+ if (i) {
166
+ if (Array.isArray(n)) return e.replace(`{.${t.name}}`, `.${n.join(".")}`);
167
+ if (typeof n == "object" && n) {
168
+ let r = Object.entries(n).map(([e, t]) => `${e}=${t}`).join(".");
169
+ return e.replace(`{.${t.name}}`, `.${r}`);
170
+ }
171
+ return e.replace(`{.${t.name}}`, `.${n}`);
172
+ }
173
+ if (Array.isArray(n)) return e.replace(`{.${t.name}}`, `.${n.join(",")}`);
174
+ if (typeof n == "object" && n) {
175
+ let r = Object.entries(n).map(([e, t]) => `${e},${t}`).join(",");
176
+ return e.replace(`{.${t.name}}`, `.${r}`);
177
+ }
178
+ return e.replace(`{.${t.name}}`, `.${n}`);
179
+ case "simple": {
180
+ let r = u(n, i);
181
+ return e.replace(`{${t.name}}`, String(r));
182
+ }
183
+ default: return e.replace(`{${t.name}}`, String(n));
184
+ }
185
+ };
186
+ //#endregion
187
+ export { _ as processParameters };
188
+
189
+ //# sourceMappingURL=process-parameters.js.map