@scalar/api-client 3.11.0 → 3.13.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 (142) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/plugins/posthog/sanitize-event-payload.d.ts.map +1 -1
  3. package/dist/plugins/posthog/sanitize-event-payload.js +1 -0
  4. package/dist/plugins/posthog/sanitize-event-payload.js.map +1 -1
  5. package/dist/style.css +15 -69
  6. package/dist/v2/blocks/operation-block/OperationBlock.vue.d.ts.map +1 -1
  7. package/dist/v2/blocks/operation-block/OperationBlock.vue.js.map +1 -1
  8. package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js +1 -1
  9. package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js.map +1 -1
  10. package/dist/v2/blocks/operation-block/helpers/validate-path-parameters.d.ts.map +1 -1
  11. package/dist/v2/blocks/operation-block/helpers/validate-path-parameters.js +1 -2
  12. package/dist/v2/blocks/operation-block/helpers/validate-path-parameters.js.map +1 -1
  13. package/dist/v2/blocks/request-block/RequestBlock.vue.d.ts +1 -1
  14. package/dist/v2/blocks/request-block/RequestBlock.vue.d.ts.map +1 -1
  15. package/dist/v2/blocks/request-block/RequestBlock.vue.js +1 -1
  16. package/dist/v2/blocks/request-block/RequestBlock.vue.js.map +1 -1
  17. package/dist/v2/blocks/request-block/RequestBlock.vue.script.js +2 -2
  18. package/dist/v2/blocks/request-block/RequestBlock.vue.script.js.map +1 -1
  19. package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.d.ts +2 -2
  20. package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.d.ts.map +1 -1
  21. package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.js.map +1 -1
  22. package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.script.js +2 -6
  23. package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.script.js.map +1 -1
  24. package/dist/v2/blocks/request-block/helpers/create-parameter-handlers.d.ts.map +1 -1
  25. package/dist/v2/blocks/request-block/helpers/create-parameter-handlers.js +17 -3
  26. package/dist/v2/blocks/request-block/helpers/create-parameter-handlers.js.map +1 -1
  27. package/dist/v2/blocks/request-block/helpers/create-parameter-rows.d.ts.map +1 -1
  28. package/dist/v2/blocks/request-block/helpers/create-parameter-rows.js +28 -17
  29. package/dist/v2/blocks/request-block/helpers/create-parameter-rows.js.map +1 -1
  30. package/dist/v2/blocks/request-block/helpers/get-form-body-rows.js +1 -1
  31. package/dist/v2/blocks/scalar-auth-selector-block/components/AuthSelector.vue.script.js.map +1 -1
  32. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.d.ts +3 -0
  33. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.d.ts.map +1 -1
  34. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.js.map +1 -1
  35. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.script.js +8 -4
  36. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.script.js.map +1 -1
  37. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.d.ts +27 -1
  38. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.d.ts.map +1 -1
  39. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js +30 -5
  40. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js.map +1 -1
  41. package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.d.ts.map +1 -1
  42. package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.js +1 -1
  43. package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.js.map +1 -1
  44. package/dist/v2/components/data-table/DataTableInput.vue.d.ts +1 -1
  45. package/dist/v2/components/data-table/DataTableInput.vue.d.ts.map +1 -1
  46. package/dist/v2/constants.js +1 -1
  47. package/dist/v2/features/modal/helpers/create-api-client-modal.js +1 -1
  48. package/dist/v2/features/operation/Operation.vue.script.js +1 -1
  49. package/dist/v2/types/options.d.ts +7 -0
  50. package/dist/v2/types/options.d.ts.map +1 -1
  51. package/dist/v2/workspace-events.d.ts.map +1 -1
  52. package/dist/v2/workspace-events.js +1 -0
  53. package/dist/v2/workspace-events.js.map +1 -1
  54. package/dist/vue-styles.css +6 -48
  55. package/package.json +11 -22
  56. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.d.ts +0 -16
  57. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.d.ts.map +0 -1
  58. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.js +0 -7
  59. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.js.map +0 -1
  60. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.script.js +0 -53
  61. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.script.js.map +0 -1
  62. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.d.ts +0 -26
  63. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.d.ts.map +0 -1
  64. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.js +0 -7
  65. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.js.map +0 -1
  66. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.script.js +0 -33
  67. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.script.js.map +0 -1
  68. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.d.ts +0 -141
  69. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.d.ts.map +0 -1
  70. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.js +0 -9
  71. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.js.map +0 -1
  72. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.script.js +0 -272
  73. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.script.js.map +0 -1
  74. package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.d.ts +0 -9
  75. package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.d.ts.map +0 -1
  76. package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.js +0 -37
  77. package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.js.map +0 -1
  78. package/dist/v2/blocks/operation-code-sample/helpers/find-client.d.ts +0 -41
  79. package/dist/v2/blocks/operation-code-sample/helpers/find-client.d.ts.map +0 -1
  80. package/dist/v2/blocks/operation-code-sample/helpers/find-client.js +0 -48
  81. package/dist/v2/blocks/operation-code-sample/helpers/find-client.js.map +0 -1
  82. package/dist/v2/blocks/operation-code-sample/helpers/format-language.d.ts +0 -8
  83. package/dist/v2/blocks/operation-code-sample/helpers/format-language.d.ts.map +0 -1
  84. package/dist/v2/blocks/operation-code-sample/helpers/format-language.js +0 -70
  85. package/dist/v2/blocks/operation-code-sample/helpers/format-language.js.map +0 -1
  86. package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.d.ts +0 -30
  87. package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.d.ts.map +0 -1
  88. package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.js +0 -63
  89. package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.js.map +0 -1
  90. package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.d.ts +0 -39
  91. package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.d.ts.map +0 -1
  92. package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.js +0 -38
  93. package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.js.map +0 -1
  94. package/dist/v2/blocks/operation-code-sample/helpers/get-clients.d.ts +0 -13
  95. package/dist/v2/blocks/operation-code-sample/helpers/get-clients.d.ts.map +0 -1
  96. package/dist/v2/blocks/operation-code-sample/helpers/get-clients.js +0 -37
  97. package/dist/v2/blocks/operation-code-sample/helpers/get-clients.js.map +0 -1
  98. package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.d.ts +0 -45
  99. package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.d.ts.map +0 -1
  100. package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.js +0 -84
  101. package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.js.map +0 -1
  102. package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.d.ts +0 -27
  103. package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.d.ts.map +0 -1
  104. package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.js +0 -41
  105. package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.js.map +0 -1
  106. package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.d.ts +0 -4
  107. package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.d.ts.map +0 -1
  108. package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.js +0 -18
  109. package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.js.map +0 -1
  110. package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.d.ts +0 -8
  111. package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.d.ts.map +0 -1
  112. package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.js +0 -38
  113. package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.js.map +0 -1
  114. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.d.ts +0 -72
  115. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.d.ts.map +0 -1
  116. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.js +0 -114
  117. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.js.map +0 -1
  118. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.d.ts +0 -13
  119. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.d.ts.map +0 -1
  120. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.js +0 -196
  121. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.js.map +0 -1
  122. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.d.ts +0 -24
  123. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.d.ts.map +0 -1
  124. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.js +0 -237
  125. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.js.map +0 -1
  126. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.d.ts +0 -15
  127. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.d.ts.map +0 -1
  128. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.js +0 -65
  129. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.js.map +0 -1
  130. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.d.ts +0 -6
  131. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.d.ts.map +0 -1
  132. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.js +0 -19
  133. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.js.map +0 -1
  134. package/dist/v2/blocks/operation-code-sample/index.d.ts +0 -9
  135. package/dist/v2/blocks/operation-code-sample/index.d.ts.map +0 -1
  136. package/dist/v2/blocks/operation-code-sample/index.js +0 -8
  137. package/dist/v2/blocks/operation-code-sample/types.d.ts +0 -46
  138. package/dist/v2/blocks/operation-code-sample/types.d.ts.map +0 -1
  139. package/dist/v2/blocks/request-block/helpers/is-param-disabled.d.ts +0 -13
  140. package/dist/v2/blocks/request-block/helpers/is-param-disabled.d.ts.map +0 -1
  141. package/dist/v2/blocks/request-block/helpers/is-param-disabled.js +0 -21
  142. package/dist/v2/blocks/request-block/helpers/is-param-disabled.js.map +0 -1
@@ -1,63 +0,0 @@
1
- import { capitalize } from "vue";
2
- import { AVAILABLE_CLIENTS, snippetz } from "@scalar/snippetz";
3
- //#region src/v2/blocks/operation-code-sample/helpers/generate-client-options.ts
4
- /**
5
- * Build stable, language-keyed ids for an operation's custom code samples.
6
- *
7
- * Custom samples are defined per operation, but a selection (e.g. the Python SDK
8
- * example) should sync across every operation that ships the same language. So we
9
- * key the id by language rather than by position: the first sample of a language
10
- * becomes `custom/<lang>`, and any further samples that repeat a language fall back
11
- * to `custom/<lang>/<n>` so they stay individually selectable within the operation.
12
- *
13
- * The language is lower-cased so a selection still matches when operations (or
14
- * extensions) spell the same language with different casing (e.g. `Python` vs
15
- * `python`).
16
- *
17
- * @param samples - The custom code samples for a single operation
18
- * @returns A list of ids aligned by index with the input samples
19
- */
20
- var getCustomClientIds = (samples) => {
21
- const countByLang = /* @__PURE__ */ new Map();
22
- return samples.map((sample) => {
23
- const lang = (sample.lang || "plaintext").toLowerCase();
24
- const seen = countByLang.get(lang) ?? 0;
25
- countByLang.set(lang, seen + 1);
26
- return seen === 0 ? `custom/${lang}` : `custom/${lang}/${seen}`;
27
- });
28
- };
29
- /**
30
- * Generate client options for the request example block by filtering by allowed clients
31
- *
32
- * @param allowedClients - The list of allowed clients to include in the options
33
- * @returns A list of client option groups
34
- */
35
- var generateClientOptions = (allowedClients = AVAILABLE_CLIENTS) => {
36
- /** Create set of allowlist for quicker lookups */
37
- const allowedClientsSet = new Set(allowedClients);
38
- return snippetz().clients().flatMap((group) => {
39
- const options = group.clients.flatMap((plugin) => {
40
- const id = `${group.key}/${plugin.client}`;
41
- if (!allowedClientsSet.has(id)) return [];
42
- return {
43
- id,
44
- lang: plugin.client === "curl" ? "curl" : group.key,
45
- title: `${capitalize(group.title)} ${plugin.title}`,
46
- label: plugin.title,
47
- targetKey: group.key,
48
- targetTitle: group.title,
49
- clientKey: plugin.client
50
- };
51
- });
52
- if (options.length === 0) return [];
53
- return {
54
- label: group.title,
55
- key: group.key,
56
- options
57
- };
58
- });
59
- };
60
- //#endregion
61
- export { generateClientOptions, getCustomClientIds };
62
-
63
- //# sourceMappingURL=generate-client-options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-client-options.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/generate-client-options.ts"],"sourcesContent":["import { AVAILABLE_CLIENTS, type AvailableClients, snippetz } from '@scalar/snippetz'\nimport type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation'\nimport { capitalize } from 'vue'\n\nimport type { ClientOptionGroup } from '@/v2/blocks/operation-code-sample/types'\n\n/** Type of custom code sample IDs */\nexport type CustomCodeSampleId = `custom/${string}`\n\n/**\n * Build stable, language-keyed ids for an operation's custom code samples.\n *\n * Custom samples are defined per operation, but a selection (e.g. the Python SDK\n * example) should sync across every operation that ships the same language. So we\n * key the id by language rather than by position: the first sample of a language\n * becomes `custom/<lang>`, and any further samples that repeat a language fall back\n * to `custom/<lang>/<n>` so they stay individually selectable within the operation.\n *\n * The language is lower-cased so a selection still matches when operations (or\n * extensions) spell the same language with different casing (e.g. `Python` vs\n * `python`).\n *\n * @param samples - The custom code samples for a single operation\n * @returns A list of ids aligned by index with the input samples\n */\nexport const getCustomClientIds = (samples: XCodeSample[]): CustomCodeSampleId[] => {\n const countByLang = new Map<string, number>()\n\n return samples.map((sample): CustomCodeSampleId => {\n const lang = (sample.lang || 'plaintext').toLowerCase()\n const seen = countByLang.get(lang) ?? 0\n countByLang.set(lang, seen + 1)\n\n return seen === 0 ? `custom/${lang}` : `custom/${lang}/${seen}`\n })\n}\n\n/**\n * Generate client options for the request example block by filtering by allowed clients\n *\n * @param allowedClients - The list of allowed clients to include in the options\n * @returns A list of client option groups\n */\nexport const generateClientOptions = (allowedClients: AvailableClients = AVAILABLE_CLIENTS): ClientOptionGroup[] => {\n /** Create set of allowlist for quicker lookups */\n const allowedClientsSet = new Set(allowedClients)\n\n const options = snippetz()\n .clients()\n .flatMap((group) => {\n const options = group.clients.flatMap((plugin) => {\n const id = `${group.key}/${plugin.client}` as AvailableClients[number]\n\n // If the client is not allowed, skip it\n if (!allowedClientsSet.has(id)) {\n return []\n }\n\n return {\n id,\n lang: plugin.client === 'curl' ? ('curl' as const) : group.key,\n title: `${capitalize(group.title)} ${plugin.title}`,\n label: plugin.title,\n targetKey: group.key,\n targetTitle: group.title,\n clientKey: plugin.client,\n }\n })\n\n // If no clients are allowed, skip this group\n if (options.length === 0) {\n return []\n }\n\n return {\n label: group.title,\n key: group.key,\n options,\n }\n })\n\n return options\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBA,IAAa,sBAAsB,YAAiD;CAClF,MAAM,8BAAc,IAAI,KAAqB;AAE7C,QAAO,QAAQ,KAAK,WAA+B;EACjD,MAAM,QAAQ,OAAO,QAAQ,aAAa,aAAa;EACvD,MAAM,OAAO,YAAY,IAAI,KAAK,IAAI;AACtC,cAAY,IAAI,MAAM,OAAO,EAAE;AAE/B,SAAO,SAAS,IAAI,UAAU,SAAS,UAAU,KAAK,GAAG;GACzD;;;;;;;;AASJ,IAAa,yBAAyB,iBAAmC,sBAA2C;;CAElH,MAAM,oBAAoB,IAAI,IAAI,eAAe;AAoCjD,QAlCgB,UAAU,CACvB,SAAS,CACT,SAAS,UAAU;EAClB,MAAM,UAAU,MAAM,QAAQ,SAAS,WAAW;GAChD,MAAM,KAAK,GAAG,MAAM,IAAI,GAAG,OAAO;AAGlC,OAAI,CAAC,kBAAkB,IAAI,GAAG,CAC5B,QAAO,EAAE;AAGX,UAAO;IACL;IACA,MAAM,OAAO,WAAW,SAAU,SAAmB,MAAM;IAC3D,OAAO,GAAG,WAAW,MAAM,MAAM,CAAC,GAAG,OAAO;IAC5C,OAAO,OAAO;IACd,WAAW,MAAM;IACjB,aAAa,MAAM;IACnB,WAAW,OAAO;IACnB;IACD;AAGF,MAAI,QAAQ,WAAW,EACrB,QAAO,EAAE;AAGX,SAAO;GACL,OAAO,MAAM;GACb,KAAK,MAAM;GACX;GACD;GACD"}
@@ -1,39 +0,0 @@
1
- import type { HttpMethod } from '@scalar/helpers/http/http-methods';
2
- import type { AvailableClient } from '@scalar/snippetz';
3
- import type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example';
4
- import type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies';
5
- import type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation';
6
- import type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
7
- import { type CustomCodeSampleId } from './generate-client-options.js';
8
- type GenerateCodeSnippetProps = {
9
- /** The selected client/language for code generation (e.g., 'node/fetch') or a custom code sample ID. */
10
- clientId: AvailableClient | CustomCodeSampleId | undefined;
11
- /** The Content-Type header value for the request body (e.g., 'application/json'). */
12
- contentType: string | undefined;
13
- /** Array of custom code samples defined in the OpenAPI x-codeSamples extension. */
14
- customCodeSamples: XCodeSample[];
15
- /** The specific example value to use when generating the code snippet. */
16
- example: string | undefined;
17
- /** The HTTP method for the operation (e.g., GET, POST, PUT). */
18
- method: HttpMethod;
19
- /** The OpenAPI operation object containing request/response details. */
20
- operation: OperationObject;
21
- /** The API endpoint path (e.g., '/users/{id}'). */
22
- path: string;
23
- /** Array of security schemes to apply to the request (e.g., API keys, OAuth). */
24
- securitySchemes: SecuritySchemeObjectSecret[];
25
- /** The server object defining the base URL for the API request. */
26
- server: ServerObject | null;
27
- /** Workspace + document cookies */
28
- globalCookies?: XScalarCookie[];
29
- /** Whether to include default headers (e.g., Accept, Content-Type) automatically. */
30
- includeDefaultHeaders?: boolean;
31
- /** Selected oneOf/anyOf variants for nested request body example generation. */
32
- requestBodyCompositionSelection?: Record<string, number>;
33
- /** Whether to disable parameters by default. */
34
- defaultDisabledParameters?: boolean;
35
- };
36
- /** Generate the code snippet for the selected example OR operation */
37
- export declare const generateCodeSnippet: ({ clientId, customCodeSamples, includeDefaultHeaders, operation, method, path, example, contentType, server, securitySchemes, globalCookies, requestBodyCompositionSelection, defaultDisabledParameters, }: GenerateCodeSnippetProps) => string;
38
- export {};
39
- //# sourceMappingURL=generate-code-snippet.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-code-snippet.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/generate-code-snippet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAsB,MAAM,kBAAkB,CAAA;AAC3E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AACzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AACxG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,8DAA8D,CAAA;AAIjH,OAAO,EAAE,KAAK,kBAAkB,EAAsB,MAAM,2BAA2B,CAAA;AAGvF,KAAK,wBAAwB,GAAG;IAC9B,wGAAwG;IACxG,QAAQ,EAAE,eAAe,GAAG,kBAAkB,GAAG,SAAS,CAAA;IAC1D,qFAAqF;IACrF,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,mFAAmF;IACnF,iBAAiB,EAAE,WAAW,EAAE,CAAA;IAChC,0EAA0E;IAC1E,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,gEAAgE;IAChE,MAAM,EAAE,UAAU,CAAA;IAClB,wEAAwE;IACxE,SAAS,EAAE,eAAe,CAAA;IAC1B,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,iFAAiF;IACjF,eAAe,EAAE,0BAA0B,EAAE,CAAA;IAC7C,mEAAmE;IACnE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA;IAC3B,mCAAmC;IACnC,aAAa,CAAC,EAAE,aAAa,EAAE,CAAA;IAC/B,qFAAqF;IACrF,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,gFAAgF;IAChF,+BAA+B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxD,gDAAgD;IAChD,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC,CAAA;AAED,sEAAsE;AACtE,eAAO,MAAM,mBAAmB,GAAI,4MAcjC,wBAAwB,KAAG,MAyC7B,CAAA"}
@@ -1,38 +0,0 @@
1
- import { operationToHar } from "./operation-to-har/operation-to-har.js";
2
- import { getCustomClientIds } from "./generate-client-options.js";
3
- import { getSnippet } from "./get-snippet.js";
4
- //#region src/v2/blocks/operation-code-sample/helpers/generate-code-snippet.ts
5
- /** Generate the code snippet for the selected example OR operation */
6
- var generateCodeSnippet = ({ clientId, customCodeSamples, includeDefaultHeaders = false, operation, method, path, example, contentType, server, securitySchemes, globalCookies, requestBodyCompositionSelection, defaultDisabledParameters }) => {
7
- try {
8
- if (!clientId) return "";
9
- if (clientId.startsWith("custom")) return customCodeSamples[getCustomClientIds(customCodeSamples).indexOf(clientId)]?.source ?? "Custom example not found";
10
- const harRequest = operationToHar({
11
- operation,
12
- contentType,
13
- method,
14
- path,
15
- server,
16
- securitySchemes,
17
- example,
18
- globalCookies,
19
- includeDefaultHeaders,
20
- requestBodyCompositionSelection,
21
- defaultDisabledParameters
22
- });
23
- const [targetKey, clientKey] = clientId.split("/");
24
- const [error, payload] = getSnippet(targetKey, clientKey, harRequest);
25
- if (error) {
26
- console.error("[generateCodeSnippet]", error);
27
- return error.message ?? "Error generating code snippet";
28
- }
29
- return payload;
30
- } catch (error) {
31
- console.error("[generateCodeSnippet]", error);
32
- return "Error generating code snippet";
33
- }
34
- };
35
- //#endregion
36
- export { generateCodeSnippet };
37
-
38
- //# sourceMappingURL=generate-code-snippet.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-code-snippet.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/generate-code-snippet.ts"],"sourcesContent":["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport type { AvailableClient, ClientId, TargetId } from '@scalar/snippetz'\nimport type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies'\nimport type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\n\nimport { operationToHar } from '@/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har'\n\nimport { type CustomCodeSampleId, getCustomClientIds } from './generate-client-options'\nimport { getSnippet } from './get-snippet'\n\ntype GenerateCodeSnippetProps = {\n /** The selected client/language for code generation (e.g., 'node/fetch') or a custom code sample ID. */\n clientId: AvailableClient | CustomCodeSampleId | undefined\n /** The Content-Type header value for the request body (e.g., 'application/json'). */\n contentType: string | undefined\n /** Array of custom code samples defined in the OpenAPI x-codeSamples extension. */\n customCodeSamples: XCodeSample[]\n /** The specific example value to use when generating the code snippet. */\n example: string | undefined\n /** The HTTP method for the operation (e.g., GET, POST, PUT). */\n method: HttpMethod\n /** The OpenAPI operation object containing request/response details. */\n operation: OperationObject\n /** The API endpoint path (e.g., '/users/{id}'). */\n path: string\n /** Array of security schemes to apply to the request (e.g., API keys, OAuth). */\n securitySchemes: SecuritySchemeObjectSecret[]\n /** The server object defining the base URL for the API request. */\n server: ServerObject | null\n /** Workspace + document cookies */\n globalCookies?: XScalarCookie[]\n /** Whether to include default headers (e.g., Accept, Content-Type) automatically. */\n includeDefaultHeaders?: boolean\n /** Selected oneOf/anyOf variants for nested request body example generation. */\n requestBodyCompositionSelection?: Record<string, number>\n /** Whether to disable parameters by default. */\n defaultDisabledParameters?: boolean\n}\n\n/** Generate the code snippet for the selected example OR operation */\nexport const generateCodeSnippet = ({\n clientId,\n customCodeSamples,\n includeDefaultHeaders = false,\n operation,\n method,\n path,\n example,\n contentType,\n server,\n securitySchemes,\n globalCookies,\n requestBodyCompositionSelection,\n defaultDisabledParameters,\n}: GenerateCodeSnippetProps): string => {\n try {\n if (!clientId) {\n return ''\n }\n\n // Use the selected custom example, matched by its language-keyed id\n if (clientId.startsWith('custom')) {\n const ids = getCustomClientIds(customCodeSamples)\n const index = ids.indexOf(clientId as CustomCodeSampleId)\n\n return customCodeSamples[index]?.source ?? 'Custom example not found'\n }\n\n const harRequest = operationToHar({\n operation,\n contentType,\n method,\n path,\n server,\n securitySchemes,\n example,\n globalCookies,\n includeDefaultHeaders,\n requestBodyCompositionSelection,\n defaultDisabledParameters,\n })\n\n const [targetKey, clientKey] = clientId.split('/') as [TargetId, ClientId<TargetId>]\n\n const [error, payload] = getSnippet(targetKey, clientKey, harRequest)\n if (error) {\n console.error('[generateCodeSnippet]', error)\n return error.message ?? 'Error generating code snippet'\n }\n\n return payload\n } catch (error) {\n console.error('[generateCodeSnippet]', error)\n return 'Error generating code snippet'\n }\n}\n"],"mappings":";;;;;AA0CA,IAAa,uBAAuB,EAClC,UACA,mBACA,wBAAwB,OACxB,WACA,QACA,MACA,SACA,aACA,QACA,iBACA,eACA,iCACA,gCACsC;AACtC,KAAI;AACF,MAAI,CAAC,SACH,QAAO;AAIT,MAAI,SAAS,WAAW,SAAS,CAI/B,QAAO,kBAHK,mBAAmB,kBAAkB,CAC/B,QAAQ,SAA+B,GAExB,UAAU;EAG7C,MAAM,aAAa,eAAe;GAChC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CAAC;EAEF,MAAM,CAAC,WAAW,aAAa,SAAS,MAAM,IAAI;EAElD,MAAM,CAAC,OAAO,WAAW,WAAW,WAAW,WAAW,WAAW;AACrE,MAAI,OAAO;AACT,WAAQ,MAAM,yBAAyB,MAAM;AAC7C,UAAO,MAAM,WAAW;;AAG1B,SAAO;UACA,OAAO;AACd,UAAQ,MAAM,yBAAyB,MAAM;AAC7C,SAAO"}
@@ -1,13 +0,0 @@
1
- import type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation';
2
- import type { ClientOptionGroup } from '../../../../v2/blocks/operation-code-sample/index.js';
3
- import type { CustomClientOptionGroup } from '../../../../v2/blocks/operation-code-sample/types';
4
- /**
5
- * Merges custom code samples with the client options
6
- *
7
- * @param customCodeSamples - The custom code samples from the operation to merge with the client options
8
- * @param clientOptions - The client options to merge with the custom code samples
9
- * @param label - The label for the custom samples group (e.g. "SDK" or "Code Examples")
10
- * @returns A list of client option groups
11
- */
12
- export declare const getClients: (customCodeSamples: XCodeSample[], clientOptions: ClientOptionGroup[], label?: string) => CustomClientOptionGroup[];
13
- //# sourceMappingURL=get-clients.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-clients.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-clients.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AAEvF,OAAO,KAAK,EAAE,iBAAiB,EAAsB,MAAM,mCAAmC,CAAA;AAI9F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAA;AAEtF;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACrB,mBAAmB,WAAW,EAAE,EAChC,eAAe,iBAAiB,EAAE,EAClC,QAAO,MAAkC,KACxC,uBAAuB,EA+BzB,CAAA"}
@@ -1,37 +0,0 @@
1
- import { formatLanguage } from "./format-language.js";
2
- import { getCustomClientIds } from "./generate-client-options.js";
3
- import { CODE_EXAMPLES_GROUP_LABEL } from "./get-custom-code-samples.js";
4
- //#region src/v2/blocks/operation-code-sample/helpers/get-clients.ts
5
- /**
6
- * Merges custom code samples with the client options
7
- *
8
- * @param customCodeSamples - The custom code samples from the operation to merge with the client options
9
- * @param clientOptions - The client options to merge with the custom code samples
10
- * @param label - The label for the custom samples group (e.g. "SDK" or "Code Examples")
11
- * @returns A list of client option groups
12
- */
13
- var getClients = (customCodeSamples, clientOptions, label = CODE_EXAMPLES_GROUP_LABEL) => {
14
- if (customCodeSamples.length) {
15
- const ids = getCustomClientIds(customCodeSamples);
16
- return [{
17
- label,
18
- key: "custom",
19
- options: customCodeSamples.map((sample, index) => {
20
- const id = ids[index] ?? `custom/${index}`;
21
- const label = sample.label || formatLanguage(sample.lang) || id;
22
- return {
23
- id,
24
- lang: sample.lang || "plaintext",
25
- title: label,
26
- label,
27
- clientKey: "custom"
28
- };
29
- })
30
- }, ...clientOptions];
31
- }
32
- return clientOptions;
33
- };
34
- //#endregion
35
- export { getClients };
36
-
37
- //# sourceMappingURL=get-clients.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-clients.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-clients.ts"],"sourcesContent":["import type { TargetId } from '@scalar/types/snippetz'\nimport type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation'\n\nimport type { ClientOptionGroup, CustomClientOption } from '@/v2/blocks/operation-code-sample'\nimport { formatLanguage } from '@/v2/blocks/operation-code-sample/helpers/format-language'\nimport { getCustomClientIds } from '@/v2/blocks/operation-code-sample/helpers/generate-client-options'\nimport { CODE_EXAMPLES_GROUP_LABEL } from '@/v2/blocks/operation-code-sample/helpers/get-custom-code-samples'\nimport type { CustomClientOptionGroup } from '@/v2/blocks/operation-code-sample/types'\n\n/**\n * Merges custom code samples with the client options\n *\n * @param customCodeSamples - The custom code samples from the operation to merge with the client options\n * @param clientOptions - The client options to merge with the custom code samples\n * @param label - The label for the custom samples group (e.g. \"SDK\" or \"Code Examples\")\n * @returns A list of client option groups\n */\nexport const getClients = (\n customCodeSamples: XCodeSample[],\n clientOptions: ClientOptionGroup[],\n label: string = CODE_EXAMPLES_GROUP_LABEL,\n): CustomClientOptionGroup[] => {\n // Handle custom code examples\n if (customCodeSamples.length) {\n // Language-keyed ids so the same sample can be selected across operations\n const ids = getCustomClientIds(customCodeSamples)\n\n const customClients = customCodeSamples.map((sample, index) => {\n const id = ids[index] ?? `custom/${index}`\n const label = sample.label || formatLanguage(sample.lang) || id\n const lang = (sample.lang as TargetId) || 'plaintext'\n\n return {\n id,\n lang,\n title: label,\n label,\n clientKey: 'custom',\n } satisfies CustomClientOption\n })\n\n return [\n {\n label,\n key: 'custom',\n options: customClients,\n },\n ...clientOptions,\n ]\n }\n\n return clientOptions\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,IAAa,cACX,mBACA,eACA,QAAgB,8BACc;AAE9B,KAAI,kBAAkB,QAAQ;EAE5B,MAAM,MAAM,mBAAmB,kBAAkB;AAgBjD,SAAO,CACL;GACE;GACA,KAAK;GACL,SAlBkB,kBAAkB,KAAK,QAAQ,UAAU;IAC7D,MAAM,KAAK,IAAI,UAAU,UAAU;IACnC,MAAM,QAAQ,OAAO,SAAS,eAAe,OAAO,KAAK,IAAI;AAG7D,WAAO;KACL;KACA,MAJY,OAAO,QAAqB;KAKxC,OAAO;KACP;KACA,WAAW;KACZ;KACD;GAOC,EACD,GAAG,cACJ;;AAGH,QAAO"}
@@ -1,45 +0,0 @@
1
- import type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation';
2
- import type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
3
- /** Picker group label for samples generated by an SDK provider (Scalar, Stainless, …). */
4
- declare const SDK_GROUP_LABEL = "SDK";
5
- /** Picker group label for generic or docs-platform samples (the standard `x-codeSamples` family, ReadMe, …). */
6
- export declare const CODE_EXAMPLES_GROUP_LABEL = "Code Examples";
7
- type CustomCodeSampleGroupLabel = typeof SDK_GROUP_LABEL | typeof CODE_EXAMPLES_GROUP_LABEL;
8
- type CustomCodeSamples = {
9
- /**
10
- * Group label for the code sample picker.
11
- *
12
- * Samples that come from an SDK provider extension (`x-scalar-examples`,
13
- * `x-stainless-snippets`, `x-stainless-examples`) surface under "SDK". Generic
14
- * or docs-platform samples (`x-readme`, the `x-codeSamples` family) surface
15
- * under "Code Examples".
16
- */
17
- label: CustomCodeSampleGroupLabel;
18
- /** The custom code samples, in picker order. */
19
- samples: XCodeSample[];
20
- };
21
- /**
22
- * Grabs any custom code samples from the operation.
23
- *
24
- * Several tools write code samples into OpenAPI under different extensions. When
25
- * more than one is present we use the highest-priority source only, rather than
26
- * showing duplicates from every tool. Priority, highest first:
27
- *
28
- * 1. `x-scalar-examples` (SDK)
29
- * 2. `x-stainless-snippets` (SDK, overrides `x-stainless-examples`)
30
- * 3. `x-stainless-examples` (SDK)
31
- * 4. `x-readme.code-samples` (Code Examples)
32
- * 5. `x-codeSamples` / `x-code-samples` / `x-custom-examples` (Code Examples)
33
- *
34
- * The winning source also determines the picker group label: SDK-provider
35
- * extensions surface under "SDK", everything else under "Code Examples".
36
- *
37
- * Note that Speakeasy does not have its own extension — it writes into the
38
- * standard `x-codeSamples`, so its snippets surface under "Code Examples".
39
- *
40
- * @param operation - The operation to get the custom code samples from
41
- * @returns The picker group label and the custom code samples which exist in the operation
42
- */
43
- export declare const getCustomCodeSamples: (operation: OperationObject) => CustomCodeSamples;
44
- export {};
45
- //# sourceMappingURL=get-custom-code-samples.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-custom-code-samples.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EAGZ,MAAM,sDAAsD,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8DAA8D,CAAA;AA+BnG,0FAA0F;AAC1F,QAAA,MAAM,eAAe,QAAQ,CAAA;AAE7B,gHAAgH;AAChH,eAAO,MAAM,yBAAyB,kBAAkB,CAAA;AAExD,KAAK,0BAA0B,GAAG,OAAO,eAAe,GAAG,OAAO,yBAAyB,CAAA;AAE3F,KAAK,iBAAiB,GAAG;IACvB;;;;;;;OAOG;IACH,KAAK,EAAE,0BAA0B,CAAA;IACjC,gDAAgD;IAChD,OAAO,EAAE,WAAW,EAAE,CAAA;CACvB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,oBAAoB,GAAI,WAAW,eAAe,KAAG,iBAuBjE,CAAA"}
@@ -1,84 +0,0 @@
1
- //#region src/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.ts
2
- /** Turns a `{ language: source }` map (x-stainless-snippets) into code samples. */
3
- var fromSnippetMap = (snippets, label) => Object.entries(snippets ?? {}).map(([lang, source]) => ({
4
- lang,
5
- source,
6
- ...label ? { label } : {}
7
- }));
8
- /**
9
- * Turns `x-stainless-examples` / `x-scalar-examples` into code samples.
10
- *
11
- * Each example carries per-language request snippets and an optional title that
12
- * we surface as the picker label. The response is only used for documentation,
13
- * so it is ignored here.
14
- */
15
- var fromLanguageExamples = (examples) => {
16
- if (!examples) return [];
17
- return (Array.isArray(examples) ? examples : [examples]).flatMap((example) => fromSnippetMap(example.request, example.title));
18
- };
19
- /** Turns ReadMe's `x-readme.code-samples` into code samples. */
20
- var fromReadmeSamples = (samples) => (samples ?? []).map((sample) => ({
21
- lang: sample.language,
22
- source: sample.code,
23
- ...sample.name ? { label: sample.name } : {}
24
- }));
25
- /** Picker group label for samples generated by an SDK provider (Scalar, Stainless, …). */
26
- var SDK_GROUP_LABEL = "SDK";
27
- /** Picker group label for generic or docs-platform samples (the standard `x-codeSamples` family, ReadMe, …). */
28
- var CODE_EXAMPLES_GROUP_LABEL = "Code Examples";
29
- /**
30
- * Grabs any custom code samples from the operation.
31
- *
32
- * Several tools write code samples into OpenAPI under different extensions. When
33
- * more than one is present we use the highest-priority source only, rather than
34
- * showing duplicates from every tool. Priority, highest first:
35
- *
36
- * 1. `x-scalar-examples` (SDK)
37
- * 2. `x-stainless-snippets` (SDK, overrides `x-stainless-examples`)
38
- * 3. `x-stainless-examples` (SDK)
39
- * 4. `x-readme.code-samples` (Code Examples)
40
- * 5. `x-codeSamples` / `x-code-samples` / `x-custom-examples` (Code Examples)
41
- *
42
- * The winning source also determines the picker group label: SDK-provider
43
- * extensions surface under "SDK", everything else under "Code Examples".
44
- *
45
- * Note that Speakeasy does not have its own extension — it writes into the
46
- * standard `x-codeSamples`, so its snippets surface under "Code Examples".
47
- *
48
- * @param operation - The operation to get the custom code samples from
49
- * @returns The picker group label and the custom code samples which exist in the operation
50
- */
51
- var getCustomCodeSamples = (operation) => {
52
- const scalarExamples = operation["x-scalar-examples"] ?? [];
53
- if (scalarExamples.length) return {
54
- label: SDK_GROUP_LABEL,
55
- samples: scalarExamples
56
- };
57
- const stainlessSnippets = fromSnippetMap(operation["x-stainless-snippets"]);
58
- if (stainlessSnippets.length) return {
59
- label: SDK_GROUP_LABEL,
60
- samples: stainlessSnippets
61
- };
62
- const stainlessExamples = fromLanguageExamples(operation["x-stainless-examples"]);
63
- if (stainlessExamples.length) return {
64
- label: SDK_GROUP_LABEL,
65
- samples: stainlessExamples
66
- };
67
- const readmeSamples = fromReadmeSamples(operation["x-readme"]?.["code-samples"]);
68
- if (readmeSamples.length) return {
69
- label: CODE_EXAMPLES_GROUP_LABEL,
70
- samples: readmeSamples
71
- };
72
- return {
73
- label: CODE_EXAMPLES_GROUP_LABEL,
74
- samples: [
75
- "x-custom-examples",
76
- "x-codeSamples",
77
- "x-code-samples"
78
- ].flatMap((key) => operation[key] ?? [])
79
- };
80
- };
81
- //#endregion
82
- export { CODE_EXAMPLES_GROUP_LABEL, getCustomCodeSamples };
83
-
84
- //# sourceMappingURL=get-custom-code-samples.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-custom-code-samples.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/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,kBAAkB,UAA8C,UACpE,OAAO,QAAQ,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,aAAa;CAAE;CAAM;CAAQ,GAAI,QAAQ,EAAE,OAAO,GAAG,EAAE;CAAG,EAAE;;;;;;;;AASzG,IAAM,wBAAwB,aAA+E;AAC3G,KAAI,CAAC,SACH,QAAO,EAAE;AAGX,SAAQ,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,SAAS,EAAE,SAAS,YAChE,eAAe,QAAQ,SAAS,QAAQ,MAAM,CAC/C;;;AAIH,IAAM,qBAAqB,aACxB,WAAW,EAAE,EAAE,KAAK,YAAY;CAC/B,MAAM,OAAO;CACb,QAAQ,OAAO;CACf,GAAI,OAAO,OAAO,EAAE,OAAO,OAAO,MAAM,GAAG,EAAE;CAC9C,EAAE;;AAGL,IAAM,kBAAkB;;AAGxB,IAAa,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;AAwCzC,IAAa,wBAAwB,cAAkD;CACrF,MAAM,iBAAiB,UAAU,wBAAwB,EAAE;AAC3D,KAAI,eAAe,OACjB,QAAO;EAAE,OAAO;EAAiB,SAAS;EAAgB;CAG5D,MAAM,oBAAoB,eAAe,UAAU,wBAAwB;AAC3E,KAAI,kBAAkB,OACpB,QAAO;EAAE,OAAO;EAAiB,SAAS;EAAmB;CAG/D,MAAM,oBAAoB,qBAAqB,UAAU,wBAAwB;AACjF,KAAI,kBAAkB,OACpB,QAAO;EAAE,OAAO;EAAiB,SAAS;EAAmB;CAG/D,MAAM,gBAAgB,kBAAkB,UAAU,cAAc,gBAAgB;AAChF,KAAI,cAAc,OAChB,QAAO;EAAE,OAAO;EAA2B,SAAS;EAAe;AAIrE,QAAO;EAAE,OAAO;EAA2B,SADpB;GAAC;GAAqB;GAAiB;GAAiB,CACZ,SAAS,QAAQ,UAAU,QAAQ,EAAE,CAAC;EAAE"}
@@ -1,27 +0,0 @@
1
- import { type Dereference } from '@scalar/workspace-store/helpers/get-resolved-ref';
2
- type RefNode<Node> = Partial<Node> & {
3
- $ref: string;
4
- '$ref-value': Node | RefNode<Node>;
5
- };
6
- type NodeInput<Node> = Node | RefNode<Node>;
7
- /**
8
- * Recursively resolves $ref objects
9
- * This type helper ensures proper typing for deeply nested ref resolution.
10
- * Properties that could contain $ref objects may resolve to '[circular]' if we have a circular reference.
11
- */
12
- type DeepDereference<T> = Dereference<T> extends T ? T extends readonly (infer U)[] ? DeepDereference<U>[] : T extends object ? {
13
- [K in keyof T]: T[K] extends RefNode<any> ? DeepDereference<T[K]> | '[circular]' : DeepDereference<T[K]>;
14
- } : T : Dereference<T> extends object ? {
15
- [K in keyof Dereference<T>]: Dereference<T>[K] extends RefNode<any> ? DeepDereference<Dereference<T>[K]> | '[circular]' : DeepDereference<Dereference<T>[K]>;
16
- } : Dereference<T>;
17
- /**
18
- * Recursively resolves all $ref objects in a data structure to their actual values.
19
- * Traverses through objects, arrays, and nested structures to find and resolve
20
- * any $ref references at any depth level.
21
- *
22
- * Handles circular references gracefully by detecting them and returning '[circular]'
23
- * to prevent infinite loops.
24
- */
25
- export declare const getResolvedRefDeep: <Node>(node: NodeInput<Node>) => DeepDereference<NodeInput<Node>>;
26
- export {};
27
- //# sourceMappingURL=get-resolved-ref-deep.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-resolved-ref-deep.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,kDAAkD,CAAA;AAGnG,KAAK,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAA;AACzF,KAAK,SAAS,CAAC,IAAI,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAE3C;;;;GAIG;AACH,KAAK,eAAe,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,GAC9C,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC5B,eAAe,CAAC,CAAC,CAAC,EAAE,GACpB,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAC5G,CAAC,GACL,WAAW,CAAC,CAAC,CAAC,SAAS,MAAM,GAC3B;KACG,CAAC,IAAI,MAAM,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,GAC/D,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,GACjD,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACvC,GACD,WAAW,CAAC,CAAC,CAAC,CAAA;AAEpB;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,IAAI,EAAE,MAAM,SAAS,CAAC,IAAI,CAAC,KAAG,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,CA8C/F,CAAA"}
@@ -1,41 +0,0 @@
1
- import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
2
- import { unpackProxyObject } from "@scalar/workspace-store/helpers/unpack-proxy";
3
- import { isObject } from "@scalar/helpers/object/is-object";
4
- //#region src/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.ts
5
- /**
6
- * Recursively resolves all $ref objects in a data structure to their actual values.
7
- * Traverses through objects, arrays, and nested structures to find and resolve
8
- * any $ref references at any depth level.
9
- *
10
- * Handles circular references gracefully by detecting them and returning '[circular]'
11
- * to prevent infinite loops.
12
- */
13
- var getResolvedRefDeep = (node) => {
14
- const visited = /* @__PURE__ */ new WeakSet();
15
- const cachedResults = /* @__PURE__ */ new WeakMap();
16
- const resolveNode = (current) => {
17
- if (!isObject(current) && !Array.isArray(current)) return current;
18
- const rawValue = unpackProxyObject(current, { depth: 1 });
19
- if (cachedResults.has(rawValue)) return cachedResults.get(rawValue);
20
- if (visited.has(rawValue)) return "[circular]";
21
- visited.add(rawValue);
22
- if ("$ref" in current) {
23
- const result = resolveNode(getResolvedRef(current));
24
- cachedResults.set(rawValue, result);
25
- return result;
26
- }
27
- if (Array.isArray(current)) {
28
- const result = current.map(resolveNode);
29
- cachedResults.set(rawValue, result);
30
- return result;
31
- }
32
- const result = Object.fromEntries(Object.entries(current).map(([key, value]) => [key, resolveNode(value)]));
33
- cachedResults.set(rawValue, result);
34
- return result;
35
- };
36
- return resolveNode(node);
37
- };
38
- //#endregion
39
- export { getResolvedRefDeep };
40
-
41
- //# sourceMappingURL=get-resolved-ref-deep.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-resolved-ref-deep.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.ts"],"sourcesContent":["import { isObject } from '@scalar/helpers/object/is-object'\nimport { type Dereference, getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\n\ntype RefNode<Node> = Partial<Node> & { $ref: string; '$ref-value': Node | RefNode<Node> }\ntype NodeInput<Node> = Node | RefNode<Node>\n\n/**\n * Recursively resolves $ref objects\n * This type helper ensures proper typing for deeply nested ref resolution.\n * Properties that could contain $ref objects may resolve to '[circular]' if we have a circular reference.\n */\ntype DeepDereference<T> = Dereference<T> extends T\n ? T extends readonly (infer U)[]\n ? DeepDereference<U>[]\n : T extends object\n ? { [K in keyof T]: T[K] extends RefNode<any> ? DeepDereference<T[K]> | '[circular]' : DeepDereference<T[K]> }\n : T\n : Dereference<T> extends object\n ? {\n [K in keyof Dereference<T>]: Dereference<T>[K] extends RefNode<any>\n ? DeepDereference<Dereference<T>[K]> | '[circular]'\n : DeepDereference<Dereference<T>[K]>\n }\n : Dereference<T>\n\n/**\n * Recursively resolves all $ref objects in a data structure to their actual values.\n * Traverses through objects, arrays, and nested structures to find and resolve\n * any $ref references at any depth level.\n *\n * Handles circular references gracefully by detecting them and returning '[circular]'\n * to prevent infinite loops.\n */\nexport const getResolvedRefDeep = <Node>(node: NodeInput<Node>): DeepDereference<NodeInput<Node>> => {\n const visited = new WeakSet<object>()\n const cachedResults = new WeakMap<object, any>()\n\n const resolveNode = (current: any): any => {\n // Only recurse into objects and arrays; return primitives as-is\n if (!isObject(current) && !Array.isArray(current)) {\n return current\n }\n\n const rawValue = unpackProxyObject(current, { depth: 1 })\n\n // We don't have to recurse into the same object again\n // This helps us having to manually remove the tracked node after we recurse into the tree\n if (cachedResults.has(rawValue)) {\n return cachedResults.get(rawValue)\n }\n\n // Break circular references\n if (visited.has(rawValue)) {\n return '[circular]'\n }\n\n // Track visited nodes\n visited.add(rawValue)\n\n if ('$ref' in current) {\n const resolved = getResolvedRef(current)\n const result = resolveNode(resolved)\n cachedResults.set(rawValue, result)\n return result\n }\n\n // For arrays\n if (Array.isArray(current)) {\n const result = current.map(resolveNode)\n cachedResults.set(rawValue, result)\n return result\n }\n\n const result = Object.fromEntries(Object.entries(current).map(([key, value]) => [key, resolveNode(value)]))\n cachedResults.set(rawValue, result)\n return result\n }\n\n return resolveNode(node)\n}\n"],"mappings":";;;;;;;;;;;;AAkCA,IAAa,sBAA4B,SAA4D;CACnG,MAAM,0BAAU,IAAI,SAAiB;CACrC,MAAM,gCAAgB,IAAI,SAAsB;CAEhD,MAAM,eAAe,YAAsB;AAEzC,MAAI,CAAC,SAAS,QAAQ,IAAI,CAAC,MAAM,QAAQ,QAAQ,CAC/C,QAAO;EAGT,MAAM,WAAW,kBAAkB,SAAS,EAAE,OAAO,GAAG,CAAC;AAIzD,MAAI,cAAc,IAAI,SAAS,CAC7B,QAAO,cAAc,IAAI,SAAS;AAIpC,MAAI,QAAQ,IAAI,SAAS,CACvB,QAAO;AAIT,UAAQ,IAAI,SAAS;AAErB,MAAI,UAAU,SAAS;GAErB,MAAM,SAAS,YADE,eAAe,QAAQ,CACJ;AACpC,iBAAc,IAAI,UAAU,OAAO;AACnC,UAAO;;AAIT,MAAI,MAAM,QAAQ,QAAQ,EAAE;GAC1B,MAAM,SAAS,QAAQ,IAAI,YAAY;AACvC,iBAAc,IAAI,UAAU,OAAO;AACnC,UAAO;;EAGT,MAAM,SAAS,OAAO,YAAY,OAAO,QAAQ,QAAQ,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC;AAC3G,gBAAc,IAAI,UAAU,OAAO;AACnC,SAAO;;AAGT,QAAO,YAAY,KAAK"}
@@ -1,4 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-secrets.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/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"}
@@ -1,18 +0,0 @@
1
- import { encode } from "js-base64";
2
- //#region src/v2/blocks/operation-code-sample/helpers/get-secrets.ts
3
- /** Extract secrets from security schemes */
4
- var getSecrets = (securitySchemes) => securitySchemes.flatMap((scheme) => {
5
- if (scheme.type === "apiKey") return scheme["x-scalar-secret-token"];
6
- if (scheme?.type === "http") return [
7
- scheme["x-scalar-secret-token"],
8
- scheme["x-scalar-secret-username"],
9
- scheme["x-scalar-secret-password"],
10
- encode(`${scheme["x-scalar-secret-username"]}:${scheme["x-scalar-secret-password"]}`)
11
- ];
12
- if (scheme.type === "oauth2") return Object.values(scheme.flows).map((flow) => flow["x-scalar-secret-token"]);
13
- return [];
14
- }).filter(Boolean);
15
- //#endregion
16
- export { getSecrets };
17
-
18
- //# sourceMappingURL=get-secrets.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-secrets.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/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,cAAc,oBACzB,gBACG,SAAS,WAAW;AACnB,KAAI,OAAO,SAAS,SAClB,QAAO,OAAO;AAEhB,KAAI,QAAQ,SAAS,OACnB,QAAO;EACL,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO,GAAG,OAAO,4BAA4B,GAAG,OAAO,8BAA8B;EACtF;AAEH,KAAI,OAAO,SAAS,SAElB,QADc,OAAO,OAAO,OAAO,MAAM,CAC5B,KAAK,SAAS,KAAK,yBAAyB;AAG3D,QAAO,EAAE;EACT,CACD,OAAO,QAAQ"}
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-snippet.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/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"}
@@ -1,38 +0,0 @@
1
- import { snippetz } from "@scalar/snippetz";
2
- //#region src/v2/blocks/operation-code-sample/helpers/get-snippet.ts
3
- /** Key used to hack around the invalid urls */
4
- var INVALID_URLS_PREFIX = "ws://replace.me";
5
- /**
6
- * Returns a code example for given operation
7
- */
8
- var getSnippet = (target, client, harRequest) => {
9
- try {
10
- if (!harRequest.url) return [/* @__PURE__ */ new Error("Please enter a URL to see a code snippet"), null];
11
- const separator = harRequest.url.startsWith("/") ? "" : "/";
12
- try {
13
- new URL(harRequest.url);
14
- } catch {
15
- harRequest.url = `${INVALID_URLS_PREFIX}${separator}${harRequest.url}`;
16
- }
17
- if (harRequest.postData?.mimeType === "application/json") try {
18
- JSON.parse(harRequest.postData.text || "{}");
19
- } catch (error) {
20
- console.error("[getSnippet] Invalid JSON body", error);
21
- return [/* @__PURE__ */ new Error("Invalid JSON body"), null];
22
- }
23
- const snippetzTargetKey = target.replace("javascript", "js");
24
- if (snippetz().hasPlugin(snippetzTargetKey, client)) {
25
- const payload = snippetz().print(snippetzTargetKey, client, harRequest);
26
- if (!payload) return [/* @__PURE__ */ new Error("Error generating snippet"), null];
27
- return [null, payload.replace(`${INVALID_URLS_PREFIX}${separator}`, "")];
28
- }
29
- } catch (error) {
30
- console.error("[getSnippet] Error generating snippet", error);
31
- return [/* @__PURE__ */ new Error("Error generating snippet"), null];
32
- }
33
- return [/* @__PURE__ */ new Error("No snippet found"), null];
34
- };
35
- //#endregion
36
- export { getSnippet };
37
-
38
- //# sourceMappingURL=get-snippet.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-snippet.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/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,sBAAsB;;;;AAK5B,IAAa,cACX,QACA,QACA,eAC0B;AAC1B,KAAI;AACF,MAAI,CAAC,WAAW,IACd,QAAO,iBAAC,IAAI,MAAM,2CAA2C,EAAE,KAAK;EAGtE,MAAM,YAAY,WAAW,IAAI,WAAW,IAAI,GAAG,KAAK;AAGxD,MAAI;AACF,OAAI,IAAI,WAAW,IAAI;UACjB;AACN,cAAW,MAAM,GAAG,sBAAsB,YAAY,WAAW;;AAInE,MAAI,WAAW,UAAU,aAAa,mBACpC,KAAI;AACF,QAAK,MAAM,WAAW,SAAS,QAAQ,KAAK;WACrC,OAAO;AACd,WAAQ,MAAM,kCAAkC,MAAM;AACtD,UAAO,iBAAC,IAAI,MAAM,oBAAoB,EAAE,KAAK;;EAIjD,MAAM,oBAAoB,OAAO,QAAQ,cAAc,KAAK;AAE5D,MAAI,UAAU,CAAC,UAAU,mBAAmB,OAAO,EAAE;GACnD,MAAM,UAAU,UAAU,CAAC,MAAM,mBAAmB,QAA8B,WAAW;AAC7F,OAAI,CAAC,QACH,QAAO,iBAAC,IAAI,MAAM,2BAA2B,EAAE,KAAK;AAGtD,UAAO,CAAC,MAAM,QAAQ,QAAQ,GAAG,sBAAsB,aAAa,GAAG,CAAC;;UAEnE,OAAO;AACd,UAAQ,MAAM,yCAAyC,MAAM;AAC7D,SAAO,iBAAC,IAAI,MAAM,2BAA2B,EAAE,KAAK;;AAGtD,QAAO,iBAAC,IAAI,MAAM,mBAAmB,EAAE,KAAK"}