@scalar/oas-utils 0.2.140 → 0.2.142

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 (280) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/entities/cookie/cookie.js +14 -13
  3. package/dist/entities/cookie/cookie.js.map +7 -0
  4. package/dist/entities/cookie/index.d.ts +1 -1
  5. package/dist/entities/cookie/index.d.ts.map +1 -1
  6. package/dist/entities/cookie/index.js +5 -1
  7. package/dist/entities/cookie/index.js.map +7 -0
  8. package/dist/entities/environment/environment.js +10 -9
  9. package/dist/entities/environment/environment.js.map +7 -0
  10. package/dist/entities/environment/index.d.ts +1 -1
  11. package/dist/entities/environment/index.d.ts.map +1 -1
  12. package/dist/entities/environment/index.js +5 -1
  13. package/dist/entities/environment/index.js.map +7 -0
  14. package/dist/entities/hotkeys/hotkeys.js +109 -116
  15. package/dist/entities/hotkeys/hotkeys.js.map +7 -0
  16. package/dist/entities/hotkeys/index.d.ts +1 -1
  17. package/dist/entities/hotkeys/index.d.ts.map +1 -1
  18. package/dist/entities/hotkeys/index.js +6 -1
  19. package/dist/entities/hotkeys/index.js.map +7 -0
  20. package/dist/entities/shared/index.d.ts +1 -1
  21. package/dist/entities/shared/index.d.ts.map +1 -1
  22. package/dist/entities/shared/index.js +7 -1
  23. package/dist/entities/shared/index.js.map +7 -0
  24. package/dist/entities/shared/utility.js +9 -12
  25. package/dist/entities/shared/utility.js.map +7 -0
  26. package/dist/entities/spec/collection.d.ts.map +1 -1
  27. package/dist/entities/spec/collection.js +91 -94
  28. package/dist/entities/spec/collection.js.map +7 -0
  29. package/dist/entities/spec/index.d.ts +8 -8
  30. package/dist/entities/spec/index.d.ts.map +1 -1
  31. package/dist/entities/spec/index.js +59 -9
  32. package/dist/entities/spec/index.js.map +7 -0
  33. package/dist/entities/spec/operation.d.ts +1 -1
  34. package/dist/entities/spec/operation.d.ts.map +1 -1
  35. package/dist/entities/spec/operation.js +5 -8
  36. package/dist/entities/spec/operation.js.map +7 -0
  37. package/dist/entities/spec/operation.test.js +43 -0
  38. package/dist/entities/spec/operation.test.js.map +7 -0
  39. package/dist/entities/spec/parameters.d.ts +1 -1
  40. package/dist/entities/spec/parameters.d.ts.map +1 -1
  41. package/dist/entities/spec/parameters.js +40 -38
  42. package/dist/entities/spec/parameters.js.map +7 -0
  43. package/dist/entities/spec/parameters.test.js +71 -0
  44. package/dist/entities/spec/parameters.test.js.map +7 -0
  45. package/dist/entities/spec/request-example.test.js +637 -0
  46. package/dist/entities/spec/request-example.test.js.map +7 -0
  47. package/dist/entities/spec/request-examples.d.ts +3 -3
  48. package/dist/entities/spec/request-examples.d.ts.map +1 -1
  49. package/dist/entities/spec/request-examples.js +323 -338
  50. package/dist/entities/spec/request-examples.js.map +7 -0
  51. package/dist/entities/spec/requests.d.ts +6 -8
  52. package/dist/entities/spec/requests.d.ts.map +1 -1
  53. package/dist/entities/spec/requests.js +80 -101
  54. package/dist/entities/spec/requests.js.map +7 -0
  55. package/dist/entities/spec/server.js +47 -63
  56. package/dist/entities/spec/server.js.map +7 -0
  57. package/dist/entities/spec/server.test.js +120 -0
  58. package/dist/entities/spec/server.test.js.map +7 -0
  59. package/dist/entities/spec/spec-objects.d.ts.map +1 -1
  60. package/dist/entities/spec/spec-objects.js +77 -121
  61. package/dist/entities/spec/spec-objects.js.map +7 -0
  62. package/dist/entities/spec/spec-objects.test.js +205 -0
  63. package/dist/entities/spec/spec-objects.test.js.map +7 -0
  64. package/dist/entities/spec/x-scalar-environments.js +21 -18
  65. package/dist/entities/spec/x-scalar-environments.js.map +7 -0
  66. package/dist/entities/spec/x-scalar-environments.test.js +11 -0
  67. package/dist/entities/spec/x-scalar-environments.test.js.map +7 -0
  68. package/dist/entities/spec/x-scalar-secrets.js +8 -6
  69. package/dist/entities/spec/x-scalar-secrets.js.map +7 -0
  70. package/dist/entities/spec/x-scalar-secrets.test.js +11 -0
  71. package/dist/entities/spec/x-scalar-secrets.test.js.map +7 -0
  72. package/dist/entities/workspace/index.d.ts +1 -1
  73. package/dist/entities/workspace/index.d.ts.map +1 -1
  74. package/dist/entities/workspace/index.js +7 -1
  75. package/dist/entities/workspace/index.js.map +7 -0
  76. package/dist/entities/workspace/workspace.js +46 -50
  77. package/dist/entities/workspace/workspace.js.map +7 -0
  78. package/dist/helpers/create-hash.js +15 -18
  79. package/dist/helpers/create-hash.js.map +7 -0
  80. package/dist/helpers/ensure-protocol.js +9 -10
  81. package/dist/helpers/ensure-protocol.js.map +7 -0
  82. package/dist/helpers/ensure-protocol.test.js +70 -0
  83. package/dist/helpers/ensure-protocol.test.js.map +7 -0
  84. package/dist/helpers/fetch-document.js +24 -32
  85. package/dist/helpers/fetch-document.js.map +7 -0
  86. package/dist/helpers/fetch-document.test.js +63 -0
  87. package/dist/helpers/fetch-document.test.js.map +7 -0
  88. package/dist/helpers/fetch-with-proxy-fallback.js +20 -28
  89. package/dist/helpers/fetch-with-proxy-fallback.js.map +7 -0
  90. package/dist/helpers/find-variables.d.ts +1 -1
  91. package/dist/helpers/find-variables.d.ts.map +1 -1
  92. package/dist/helpers/find-variables.js +6 -8
  93. package/dist/helpers/find-variables.js.map +7 -0
  94. package/dist/helpers/find-variables.test.js +20 -0
  95. package/dist/helpers/find-variables.test.js.map +7 -0
  96. package/dist/helpers/http-methods.d.ts +1 -1
  97. package/dist/helpers/http-methods.d.ts.map +1 -1
  98. package/dist/helpers/http-methods.js +60 -66
  99. package/dist/helpers/http-methods.js.map +7 -0
  100. package/dist/helpers/http-status-codes.js +319 -317
  101. package/dist/helpers/http-status-codes.js.map +7 -0
  102. package/dist/helpers/index.d.ts +27 -27
  103. package/dist/helpers/index.d.ts.map +1 -1
  104. package/dist/helpers/index.js +73 -27
  105. package/dist/helpers/index.js.map +7 -0
  106. package/dist/helpers/is-defined.js +5 -14
  107. package/dist/helpers/is-defined.js.map +7 -0
  108. package/dist/helpers/is-defined.test.js +37 -0
  109. package/dist/helpers/is-defined.test.js.map +7 -0
  110. package/dist/helpers/is-local-url.js +11 -16
  111. package/dist/helpers/is-local-url.js.map +7 -0
  112. package/dist/helpers/is-local-url.test.js +40 -0
  113. package/dist/helpers/is-local-url.test.js.map +7 -0
  114. package/dist/helpers/is-valid-url.js +9 -18
  115. package/dist/helpers/is-valid-url.js.map +7 -0
  116. package/dist/helpers/is-valid-url.test.js +17 -0
  117. package/dist/helpers/is-valid-url.test.js.map +7 -0
  118. package/dist/helpers/iterate-title.js +11 -15
  119. package/dist/helpers/iterate-title.js.map +7 -0
  120. package/dist/helpers/json2xml.js +40 -47
  121. package/dist/helpers/json2xml.js.map +7 -0
  122. package/dist/helpers/json2xml.test.js +19 -0
  123. package/dist/helpers/json2xml.test.js.map +7 -0
  124. package/dist/helpers/local-storage.js +13 -15
  125. package/dist/helpers/local-storage.js.map +7 -0
  126. package/dist/helpers/make-url-absolute.js +11 -17
  127. package/dist/helpers/make-url-absolute.js.map +7 -0
  128. package/dist/helpers/make-url-absolute.test.js +61 -0
  129. package/dist/helpers/make-url-absolute.test.js.map +7 -0
  130. package/dist/helpers/merge-urls.js +50 -75
  131. package/dist/helpers/merge-urls.js.map +7 -0
  132. package/dist/helpers/merge-urls.test.js +339 -0
  133. package/dist/helpers/merge-urls.test.js.map +7 -0
  134. package/dist/helpers/normalize-mime-type-object.js +21 -31
  135. package/dist/helpers/normalize-mime-type-object.js.map +7 -0
  136. package/dist/helpers/normalize-mime-type-object.test.js +53 -0
  137. package/dist/helpers/normalize-mime-type-object.test.js.map +7 -0
  138. package/dist/helpers/normalize-mime-type.js +8 -18
  139. package/dist/helpers/normalize-mime-type.js.map +7 -0
  140. package/dist/helpers/normalize-mime-type.test.js +33 -0
  141. package/dist/helpers/normalize-mime-type.test.js.map +7 -0
  142. package/dist/helpers/object.js +12 -18
  143. package/dist/helpers/object.js.map +7 -0
  144. package/dist/helpers/omit-undefined-values.js +17 -19
  145. package/dist/helpers/omit-undefined-values.js.map +7 -0
  146. package/dist/helpers/omit-undefined-values.test.js +89 -0
  147. package/dist/helpers/omit-undefined-values.test.js.map +7 -0
  148. package/dist/helpers/parse.js +71 -83
  149. package/dist/helpers/parse.js.map +7 -0
  150. package/dist/helpers/parse.test.js +45 -0
  151. package/dist/helpers/parse.test.js.map +7 -0
  152. package/dist/helpers/pretty-print-json.js +31 -35
  153. package/dist/helpers/pretty-print-json.js.map +7 -0
  154. package/dist/helpers/pretty-print-json.test.js +28 -0
  155. package/dist/helpers/pretty-print-json.test.js.map +7 -0
  156. package/dist/helpers/redirect-to-proxy.js +46 -83
  157. package/dist/helpers/redirect-to-proxy.js.map +7 -0
  158. package/dist/helpers/redirect-to-proxy.test.js +54 -0
  159. package/dist/helpers/redirect-to-proxy.test.js.map +7 -0
  160. package/dist/helpers/regex-helpers.js +11 -9
  161. package/dist/helpers/regex-helpers.js.map +7 -0
  162. package/dist/helpers/regex-helpers.test.js +154 -0
  163. package/dist/helpers/regex-helpers.test.js.map +7 -0
  164. package/dist/helpers/replace-variables.js +13 -16
  165. package/dist/helpers/replace-variables.js.map +7 -0
  166. package/dist/helpers/replace-variables.test.js +30 -0
  167. package/dist/helpers/replace-variables.test.js.map +7 -0
  168. package/dist/helpers/schema-model.js +15 -14
  169. package/dist/helpers/schema-model.js.map +7 -0
  170. package/dist/helpers/security/get-schemes.d.ts +1 -1
  171. package/dist/helpers/security/get-schemes.d.ts.map +1 -1
  172. package/dist/helpers/security/get-schemes.js +7 -9
  173. package/dist/helpers/security/get-schemes.js.map +7 -0
  174. package/dist/helpers/security/get-schemes.test.js +71 -0
  175. package/dist/helpers/security/get-schemes.test.js.map +7 -0
  176. package/dist/helpers/security/has-token.js +18 -19
  177. package/dist/helpers/security/has-token.js.map +7 -0
  178. package/dist/helpers/security/has-token.test.js +157 -0
  179. package/dist/helpers/security/has-token.test.js.map +7 -0
  180. package/dist/helpers/security/index.d.ts +2 -2
  181. package/dist/helpers/security/index.d.ts.map +1 -1
  182. package/dist/helpers/security/index.js +7 -2
  183. package/dist/helpers/security/index.js.map +7 -0
  184. package/dist/helpers/should-ignore-entity.d.ts +2 -2
  185. package/dist/helpers/should-ignore-entity.d.ts.map +1 -1
  186. package/dist/helpers/should-ignore-entity.js +5 -6
  187. package/dist/helpers/should-ignore-entity.js.map +7 -0
  188. package/dist/helpers/ssr-state.js +6 -6
  189. package/dist/helpers/ssr-state.js.map +7 -0
  190. package/dist/helpers/string.js +6 -18
  191. package/dist/helpers/string.js.map +7 -0
  192. package/dist/migrations/data-version.js +7 -17
  193. package/dist/migrations/data-version.js.map +7 -0
  194. package/dist/migrations/generate-types.js +56 -0
  195. package/dist/migrations/generate-types.js.map +7 -0
  196. package/dist/migrations/index.d.ts +3 -3
  197. package/dist/migrations/index.d.ts.map +1 -1
  198. package/dist/migrations/index.js +10 -3
  199. package/dist/migrations/index.js.map +7 -0
  200. package/dist/migrations/local-storage.d.ts +1 -1
  201. package/dist/migrations/local-storage.d.ts.map +1 -1
  202. package/dist/migrations/local-storage.js +27 -32
  203. package/dist/migrations/local-storage.js.map +7 -0
  204. package/dist/migrations/migrator.d.ts +1 -1
  205. package/dist/migrations/migrator.d.ts.map +1 -1
  206. package/dist/migrations/migrator.js +51 -58
  207. package/dist/migrations/migrator.js.map +7 -0
  208. package/dist/migrations/semver.js +23 -25
  209. package/dist/migrations/semver.js.map +7 -0
  210. package/dist/migrations/semver.test.js +21 -0
  211. package/dist/migrations/semver.test.js.map +7 -0
  212. package/dist/migrations/v-0.0.0/types.generated.js +1 -0
  213. package/dist/migrations/v-0.0.0/types.generated.js.map +7 -0
  214. package/dist/migrations/v-2.1.0/migration.d.ts +2 -2
  215. package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -1
  216. package/dist/migrations/v-2.1.0/migration.js +256 -273
  217. package/dist/migrations/v-2.1.0/migration.js.map +7 -0
  218. package/dist/migrations/v-2.1.0/types.generated.js +1 -0
  219. package/dist/migrations/v-2.1.0/types.generated.js.map +7 -0
  220. package/dist/migrations/v-2.2.0/migration.d.ts +2 -2
  221. package/dist/migrations/v-2.2.0/migration.d.ts.map +1 -1
  222. package/dist/migrations/v-2.2.0/migration.js +95 -100
  223. package/dist/migrations/v-2.2.0/migration.js.map +7 -0
  224. package/dist/migrations/v-2.2.0/types.generated.js +1 -0
  225. package/dist/migrations/v-2.2.0/types.generated.js.map +7 -0
  226. package/dist/migrations/v-2.3.0/migration.d.ts +2 -2
  227. package/dist/migrations/v-2.3.0/migration.d.ts.map +1 -1
  228. package/dist/migrations/v-2.3.0/migration.js +47 -46
  229. package/dist/migrations/v-2.3.0/migration.js.map +7 -0
  230. package/dist/migrations/v-2.3.0/types.generated.js +1 -0
  231. package/dist/migrations/v-2.3.0/types.generated.js.map +7 -0
  232. package/dist/migrations/v-2.4.0/migration.d.ts +2 -2
  233. package/dist/migrations/v-2.4.0/migration.d.ts.map +1 -1
  234. package/dist/migrations/v-2.4.0/migration.js +24 -26
  235. package/dist/migrations/v-2.4.0/migration.js.map +7 -0
  236. package/dist/migrations/v-2.4.0/migration.test.js +90 -0
  237. package/dist/migrations/v-2.4.0/migration.test.js.map +7 -0
  238. package/dist/migrations/v-2.4.0/types.generated.js +1 -0
  239. package/dist/migrations/v-2.4.0/types.generated.js.map +7 -0
  240. package/dist/migrations/v-2.5.0/migration.d.ts +2 -2
  241. package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
  242. package/dist/migrations/v-2.5.0/migration.js +135 -119
  243. package/dist/migrations/v-2.5.0/migration.js.map +7 -0
  244. package/dist/migrations/v-2.5.0/migration.test.js +108 -0
  245. package/dist/migrations/v-2.5.0/migration.test.js.map +7 -0
  246. package/dist/migrations/v-2.5.0/types.generated.d.ts +8 -8
  247. package/dist/migrations/v-2.5.0/types.generated.d.ts.map +1 -1
  248. package/dist/migrations/v-2.5.0/types.generated.js +1 -0
  249. package/dist/migrations/v-2.5.0/types.generated.js.map +7 -0
  250. package/dist/spec-getters/get-example-from-schema.js +206 -268
  251. package/dist/spec-getters/get-example-from-schema.js.map +7 -0
  252. package/dist/spec-getters/get-example-from-schema.test.js +1092 -0
  253. package/dist/spec-getters/get-example-from-schema.test.js.map +7 -0
  254. package/dist/spec-getters/get-parameters-from-operation.js +22 -42
  255. package/dist/spec-getters/get-parameters-from-operation.js.map +7 -0
  256. package/dist/spec-getters/get-parameters-from-operation.test.js +178 -0
  257. package/dist/spec-getters/get-parameters-from-operation.test.js.map +7 -0
  258. package/dist/spec-getters/get-request-body-from-operation.js +110 -162
  259. package/dist/spec-getters/get-request-body-from-operation.js.map +7 -0
  260. package/dist/spec-getters/get-request-body-from-operation.test.js +289 -0
  261. package/dist/spec-getters/get-request-body-from-operation.test.js.map +7 -0
  262. package/dist/spec-getters/get-server-variable-examples.d.ts +1 -1
  263. package/dist/spec-getters/get-server-variable-examples.d.ts.map +1 -1
  264. package/dist/spec-getters/get-server-variable-examples.js +12 -11
  265. package/dist/spec-getters/get-server-variable-examples.js.map +7 -0
  266. package/dist/spec-getters/index.d.ts +4 -4
  267. package/dist/spec-getters/index.d.ts.map +1 -1
  268. package/dist/spec-getters/index.js +11 -4
  269. package/dist/spec-getters/index.js.map +7 -0
  270. package/dist/transforms/import-spec.d.ts +6 -6
  271. package/dist/transforms/import-spec.d.ts.map +1 -1
  272. package/dist/transforms/import-spec.js +313 -425
  273. package/dist/transforms/import-spec.js.map +7 -0
  274. package/dist/transforms/import-spec.test.js +1124 -0
  275. package/dist/transforms/import-spec.test.js.map +7 -0
  276. package/dist/transforms/index.d.ts +1 -1
  277. package/dist/transforms/index.d.ts.map +1 -1
  278. package/dist/transforms/index.js +13 -1
  279. package/dist/transforms/index.js.map +7 -0
  280. package/package.json +10 -11
@@ -1,53 +1,49 @@
1
- import { themeIds } from '@scalar/themes';
2
- import { z } from 'zod';
3
- import { nanoidSchema } from '@scalar/types/utils';
4
- import { KEYDOWN_KEYS, HOTKEY_EVENT_NAMES } from '../hotkeys/hotkeys.js';
5
-
6
- const modifier = z
7
- .enum(['Meta', 'Control', 'Shift', 'Alt', 'default'])
8
- .optional()
9
- .default('default');
10
- const modifiers = z.array(modifier).optional().default(['default']);
11
- const hotKeys = z.record(z.enum(KEYDOWN_KEYS), z.object({
1
+ import { themeIds } from "@scalar/themes";
2
+ import { z } from "zod";
3
+ import { nanoidSchema } from "@scalar/types/utils";
4
+ import { HOTKEY_EVENT_NAMES, KEYDOWN_KEYS } from "../hotkeys/hotkeys.js";
5
+ const modifier = z.enum(["Meta", "Control", "Shift", "Alt", "default"]).optional().default("default");
6
+ const modifiers = z.array(modifier).optional().default(["default"]);
7
+ const hotKeys = z.record(
8
+ z.enum(KEYDOWN_KEYS),
9
+ z.object({
12
10
  modifiers: modifiers.optional(),
13
- event: z.enum(HOTKEY_EVENT_NAMES),
14
- }));
15
- const hotKeyConfigSchema = z
16
- .object({
17
- modifiers,
18
- hotKeys: hotKeys.optional(),
19
- })
20
- .optional();
11
+ event: z.enum(HOTKEY_EVENT_NAMES)
12
+ })
13
+ );
14
+ const hotKeyConfigSchema = z.object({
15
+ modifiers,
16
+ hotKeys: hotKeys.optional()
17
+ }).optional();
21
18
  const workspaceSchema = z.object({
22
- uid: nanoidSchema.brand(),
23
- name: z.string().default('Default Workspace'),
24
- /** Workspace description */
25
- description: z.string().default('Basic Scalar Workspace'),
26
- /** List of all collection uids in a given workspace */
27
- collections: z.array(z.string().brand()).default([]),
28
- /** List of all environment uids in a given workspace, TODO: why is this a record? */
29
- environments: z.record(z.string()).default({}),
30
- /** Customize hotkeys */
31
- hotKeyConfig: hotKeyConfigSchema,
32
- /** Active Environment ID to use for requests */
33
- activeEnvironmentId: z.string().optional().default('default'),
34
- /** List of all cookie uids in a given workspace */
35
- cookies: z.array(z.string().brand()).default([]),
36
- /** Workspace level proxy for all requests to be sent through */
37
- proxyUrl: z.string().optional(),
38
- /** Workspace level theme, we might move this to user level later */
39
- themeId: z.enum(themeIds).optional().default('default').catch('default'),
40
- /** Currently selected snippet client */
41
- selectedHttpClient: z
42
- .object({
43
- targetKey: z.string(),
44
- clientKey: z.string(),
45
- })
46
- .optional()
47
- .default({
48
- targetKey: 'shell',
49
- clientKey: 'curl',
50
- }),
19
+ uid: nanoidSchema.brand(),
20
+ name: z.string().default("Default Workspace"),
21
+ /** Workspace description */
22
+ description: z.string().default("Basic Scalar Workspace"),
23
+ /** List of all collection uids in a given workspace */
24
+ collections: z.array(z.string().brand()).default([]),
25
+ /** List of all environment uids in a given workspace, TODO: why is this a record? */
26
+ environments: z.record(z.string()).default({}),
27
+ /** Customize hotkeys */
28
+ hotKeyConfig: hotKeyConfigSchema,
29
+ /** Active Environment ID to use for requests */
30
+ activeEnvironmentId: z.string().optional().default("default"),
31
+ /** List of all cookie uids in a given workspace */
32
+ cookies: z.array(z.string().brand()).default([]),
33
+ /** Workspace level proxy for all requests to be sent through */
34
+ proxyUrl: z.string().optional(),
35
+ /** Workspace level theme, we might move this to user level later */
36
+ themeId: z.enum(themeIds).optional().default("default").catch("default"),
37
+ /** Currently selected snippet client */
38
+ selectedHttpClient: z.object({
39
+ targetKey: z.string(),
40
+ clientKey: z.string()
41
+ }).optional().default({
42
+ targetKey: "shell",
43
+ clientKey: "curl"
44
+ })
51
45
  });
52
-
53
- export { workspaceSchema };
46
+ export {
47
+ workspaceSchema
48
+ };
49
+ //# sourceMappingURL=workspace.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/entities/workspace/workspace.ts"],
4
+ "sourcesContent": ["import { themeIds } from '@scalar/themes'\nimport { z } from 'zod'\n\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { HOTKEY_EVENT_NAMES, KEYDOWN_KEYS } from '../hotkeys/hotkeys'\n\nconst modifier = z\n .enum(['Meta', 'Control', 'Shift', 'Alt', 'default'] as const)\n .optional()\n .default('default')\nconst modifiers = z.array(modifier).optional().default(['default'])\n\nexport type HotKeyModifiers = z.infer<typeof modifiers>\n\nconst hotKeys = z.record(\n z.enum(KEYDOWN_KEYS),\n z.object({\n modifiers: modifiers.optional(),\n event: z.enum(HOTKEY_EVENT_NAMES),\n }),\n)\nexport type HotKeyConfig = z.infer<typeof hotKeys>\n\nconst hotKeyConfigSchema = z\n .object({\n modifiers,\n hotKeys: hotKeys.optional(),\n })\n .optional()\n\nexport const workspaceSchema = z.object({\n uid: nanoidSchema.brand<ENTITY_BRANDS['WORKSPACE']>(),\n name: z.string().default('Default Workspace'),\n /** Workspace description */\n description: z.string().default('Basic Scalar Workspace'),\n /** List of all collection uids in a given workspace */\n collections: z.array(z.string().brand<ENTITY_BRANDS['COLLECTION']>()).default([]),\n /** List of all environment uids in a given workspace, TODO: why is this a record? */\n environments: z.record(z.string()).default({}),\n /** Customize hotkeys */\n hotKeyConfig: hotKeyConfigSchema,\n /** Active Environment ID to use for requests */\n activeEnvironmentId: z.string().optional().default('default'),\n /** List of all cookie uids in a given workspace */\n cookies: z.array(z.string().brand<ENTITY_BRANDS['COOKIE']>()).default([]),\n /** Workspace level proxy for all requests to be sent through */\n proxyUrl: z.string().optional(),\n /** Workspace level theme, we might move this to user level later */\n themeId: z.enum(themeIds).optional().default('default').catch('default'),\n /** Currently selected snippet client */\n selectedHttpClient: z\n .object({\n targetKey: z.string(),\n clientKey: z.string(),\n })\n .optional()\n .default({\n targetKey: 'shell',\n clientKey: 'curl',\n }),\n})\n\n/** The base scalar workspace */\nexport type Workspace = z.infer<typeof workspaceSchema>\nexport type WorkspacePayload = z.input<typeof workspaceSchema>\n"],
5
+ "mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,SAAS;AAElB,SAA6B,oBAAoB;AACjD,SAAS,oBAAoB,oBAAoB;AAEjD,MAAM,WAAW,EACd,KAAK,CAAC,QAAQ,WAAW,SAAS,OAAO,SAAS,CAAU,EAC5D,SAAS,EACT,QAAQ,SAAS;AACpB,MAAM,YAAY,EAAE,MAAM,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC;AAIlE,MAAM,UAAU,EAAE;AAAA,EAChB,EAAE,KAAK,YAAY;AAAA,EACnB,EAAE,OAAO;AAAA,IACP,WAAW,UAAU,SAAS;AAAA,IAC9B,OAAO,EAAE,KAAK,kBAAkB;AAAA,EAClC,CAAC;AACH;AAGA,MAAM,qBAAqB,EACxB,OAAO;AAAA,EACN;AAAA,EACA,SAAS,QAAQ,SAAS;AAC5B,CAAC,EACA,SAAS;AAEL,MAAM,kBAAkB,EAAE,OAAO;AAAA,EACtC,KAAK,aAAa,MAAkC;AAAA,EACpD,MAAM,EAAE,OAAO,EAAE,QAAQ,mBAAmB;AAAA;AAAA,EAE5C,aAAa,EAAE,OAAO,EAAE,QAAQ,wBAAwB;AAAA;AAAA,EAExD,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAmC,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA;AAAA,EAEhF,cAAc,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA;AAAA,EAE7C,cAAc;AAAA;AAAA,EAEd,qBAAqB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,SAAS;AAAA;AAAA,EAE5D,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAA+B,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA;AAAA,EAExE,UAAU,EAAE,OAAO,EAAE,SAAS;AAAA;AAAA,EAE9B,SAAS,EAAE,KAAK,QAAQ,EAAE,SAAS,EAAE,QAAQ,SAAS,EAAE,MAAM,SAAS;AAAA;AAAA,EAEvE,oBAAoB,EACjB,OAAO;AAAA,IACN,WAAW,EAAE,OAAO;AAAA,IACpB,WAAW,EAAE,OAAO;AAAA,EACtB,CAAC,EACA,SAAS,EACT,QAAQ;AAAA,IACP,WAAW;AAAA,IACX,WAAW;AAAA,EACb,CAAC;AACL,CAAC;",
6
+ "names": []
7
+ }
@@ -1,21 +1,18 @@
1
- /**
2
- * Simple 32 bit non-secure hash from a string input
3
- *
4
- * @see https://stackoverflow.com/a/7616484/1624255
5
- */
6
1
  const createHash = (input) => {
7
- let chr = 0;
8
- let hash = 0;
9
- let i = 0;
10
- if (!input?.length) {
11
- return hash;
12
- }
13
- for (i = 0; i < input.length; i++) {
14
- chr = input.charCodeAt(i);
15
- hash = (hash << 5) - hash + chr;
16
- hash |= 0; // Convert to 32bit integer
17
- }
2
+ let chr = 0;
3
+ let hash = 0;
4
+ let i = 0;
5
+ if (!input?.length) {
18
6
  return hash;
7
+ }
8
+ for (i = 0; i < input.length; i++) {
9
+ chr = input.charCodeAt(i);
10
+ hash = (hash << 5) - hash + chr;
11
+ hash |= 0;
12
+ }
13
+ return hash;
19
14
  };
20
-
21
- export { createHash };
15
+ export {
16
+ createHash
17
+ };
18
+ //# sourceMappingURL=create-hash.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers/create-hash.ts"],
4
+ "sourcesContent": ["/**\n * Simple 32 bit non-secure hash from a string input\n *\n * @see https://stackoverflow.com/a/7616484/1624255\n */\nexport const createHash = (input?: string): number => {\n let chr = 0\n let hash = 0\n let i = 0\n\n if (!input?.length) {\n return hash\n }\n\n for (i = 0; i < input.length; i++) {\n chr = input.charCodeAt(i)\n hash = (hash << 5) - hash + chr\n hash |= 0 // Convert to 32bit integer\n }\n return hash\n}\n"],
5
+ "mappings": "AAKO,MAAM,aAAa,CAAC,UAA2B;AACpD,MAAI,MAAM;AACV,MAAI,OAAO;AACX,MAAI,IAAI;AAER,MAAI,CAAC,OAAO,QAAQ;AAClB,WAAO;AAAA,EACT;AAEA,OAAK,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACjC,UAAM,MAAM,WAAW,CAAC;AACxB,YAAQ,QAAQ,KAAK,OAAO;AAC5B,YAAQ;AAAA,EACV;AACA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,12 +1,11 @@
1
- import { REGEX } from './regex-helpers.js';
2
-
3
- /** Ensure URL has a protocol prefix */
1
+ import { REGEX } from "./regex-helpers.js";
4
2
  function ensureProtocol(url) {
5
- if (REGEX.PROTOCOL.test(url)) {
6
- return url;
7
- }
8
- // Default to http if no protocol is specified
9
- return `http://${url.replace(/^\//, '')}`;
3
+ if (REGEX.PROTOCOL.test(url)) {
4
+ return url;
5
+ }
6
+ return `http://${url.replace(/^\//, "")}`;
10
7
  }
11
-
12
- export { ensureProtocol };
8
+ export {
9
+ ensureProtocol
10
+ };
11
+ //# sourceMappingURL=ensure-protocol.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers/ensure-protocol.ts"],
4
+ "sourcesContent": ["import { REGEX } from './regex-helpers'\n\n/** Ensure URL has a protocol prefix */\nexport function ensureProtocol(url: string): string {\n if (REGEX.PROTOCOL.test(url)) {\n return url\n }\n\n // Default to http if no protocol is specified\n return `http://${url.replace(/^\\//, '')}`\n}\n"],
5
+ "mappings": "AAAA,SAAS,aAAa;AAGf,SAAS,eAAe,KAAqB;AAClD,MAAI,MAAM,SAAS,KAAK,GAAG,GAAG;AAC5B,WAAO;AAAA,EACT;AAGA,SAAO,UAAU,IAAI,QAAQ,OAAO,EAAE,CAAC;AACzC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,70 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { ensureProtocol } from "./ensure-protocol.js";
3
+ describe("ensureProtocol", () => {
4
+ describe("URLs with existing protocols", () => {
5
+ it("preserves http protocol", () => {
6
+ expect(ensureProtocol("http://example.com")).toBe("http://example.com");
7
+ });
8
+ it("preserves https protocol", () => {
9
+ expect(ensureProtocol("https://example.com")).toBe("https://example.com");
10
+ });
11
+ it("preserves ws protocol", () => {
12
+ expect(ensureProtocol("ws://example.com")).toBe("ws://example.com");
13
+ });
14
+ it("preserves wss protocol", () => {
15
+ expect(ensureProtocol("wss://example.com")).toBe("wss://example.com");
16
+ });
17
+ it("preserves file protocol", () => {
18
+ expect(ensureProtocol("file:///path/to/file")).toBe("file:///path/to/file");
19
+ });
20
+ });
21
+ describe("URLs without protocols", () => {
22
+ it("adds http protocol to domain", () => {
23
+ expect(ensureProtocol("example.com")).toBe("http://example.com");
24
+ });
25
+ it("adds http protocol to domain with path", () => {
26
+ expect(ensureProtocol("example.com/path")).toBe("http://example.com/path");
27
+ });
28
+ it("adds http protocol to domain with query", () => {
29
+ expect(ensureProtocol("example.com?query=1")).toBe("http://example.com?query=1");
30
+ });
31
+ it("adds http protocol to domain with port", () => {
32
+ expect(ensureProtocol("example.com:8080")).toBe("http://example.com:8080");
33
+ });
34
+ it("adds http protocol to localhost", () => {
35
+ expect(ensureProtocol("localhost:3000")).toBe("http://localhost:3000");
36
+ });
37
+ });
38
+ describe("template variables", () => {
39
+ it("prepends http:// to template variables", () => {
40
+ expect(ensureProtocol("{protocol}://example.com")).toBe("http://{protocol}://example.com");
41
+ });
42
+ it("preserves path templates", () => {
43
+ expect(ensureProtocol("/api/{version}")).toBe("http://api/{version}");
44
+ });
45
+ it("prepends http:// to full URL templates", () => {
46
+ expect(ensureProtocol("{protocol}://{host}/{path}")).toBe("http://{protocol}://{host}/{path}");
47
+ });
48
+ });
49
+ describe("edge cases", () => {
50
+ it("handles empty string", () => {
51
+ expect(ensureProtocol("")).toBe("http://");
52
+ });
53
+ it("prepends http:// to invalid URLs", () => {
54
+ expect(ensureProtocol("not://valid")).toBe("http://not://valid");
55
+ });
56
+ it("handles URLs with authentication", () => {
57
+ expect(ensureProtocol("user:pass@example.com")).toBe("http://user:pass@example.com");
58
+ });
59
+ it("handles IP addresses", () => {
60
+ expect(ensureProtocol("127.0.0.1")).toBe("http://127.0.0.1");
61
+ });
62
+ it("handles IPv6 addresses", () => {
63
+ expect(ensureProtocol("[::1]")).toBe("http://[::1]");
64
+ });
65
+ it("handles URLs with fragments", () => {
66
+ expect(ensureProtocol("example.com#section")).toBe("http://example.com#section");
67
+ });
68
+ });
69
+ });
70
+ //# sourceMappingURL=ensure-protocol.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers/ensure-protocol.test.ts"],
4
+ "sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { ensureProtocol } from './ensure-protocol'\n\ndescribe('ensureProtocol', () => {\n describe('URLs with existing protocols', () => {\n it('preserves http protocol', () => {\n expect(ensureProtocol('http://example.com')).toBe('http://example.com')\n })\n\n it('preserves https protocol', () => {\n expect(ensureProtocol('https://example.com')).toBe('https://example.com')\n })\n\n it('preserves ws protocol', () => {\n expect(ensureProtocol('ws://example.com')).toBe('ws://example.com')\n })\n\n it('preserves wss protocol', () => {\n expect(ensureProtocol('wss://example.com')).toBe('wss://example.com')\n })\n\n it('preserves file protocol', () => {\n expect(ensureProtocol('file:///path/to/file')).toBe('file:///path/to/file')\n })\n })\n\n describe('URLs without protocols', () => {\n it('adds http protocol to domain', () => {\n expect(ensureProtocol('example.com')).toBe('http://example.com')\n })\n\n it('adds http protocol to domain with path', () => {\n expect(ensureProtocol('example.com/path')).toBe('http://example.com/path')\n })\n\n it('adds http protocol to domain with query', () => {\n expect(ensureProtocol('example.com?query=1')).toBe('http://example.com?query=1')\n })\n\n it('adds http protocol to domain with port', () => {\n expect(ensureProtocol('example.com:8080')).toBe('http://example.com:8080')\n })\n\n it('adds http protocol to localhost', () => {\n expect(ensureProtocol('localhost:3000')).toBe('http://localhost:3000')\n })\n })\n\n describe('template variables', () => {\n it('prepends http:// to template variables', () => {\n expect(ensureProtocol('{protocol}://example.com')).toBe('http://{protocol}://example.com')\n })\n\n it('preserves path templates', () => {\n expect(ensureProtocol('/api/{version}')).toBe('http://api/{version}')\n })\n\n it('prepends http:// to full URL templates', () => {\n expect(ensureProtocol('{protocol}://{host}/{path}')).toBe('http://{protocol}://{host}/{path}')\n })\n })\n\n describe('edge cases', () => {\n it('handles empty string', () => {\n expect(ensureProtocol('')).toBe('http://')\n })\n\n it('prepends http:// to invalid URLs', () => {\n expect(ensureProtocol('not://valid')).toBe('http://not://valid')\n })\n\n it('handles URLs with authentication', () => {\n expect(ensureProtocol('user:pass@example.com')).toBe('http://user:pass@example.com')\n })\n\n it('handles IP addresses', () => {\n expect(ensureProtocol('127.0.0.1')).toBe('http://127.0.0.1')\n })\n\n it('handles IPv6 addresses', () => {\n expect(ensureProtocol('[::1]')).toBe('http://[::1]')\n })\n\n it('handles URLs with fragments', () => {\n expect(ensureProtocol('example.com#section')).toBe('http://example.com#section')\n })\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB,MAAM;AAC/B,WAAS,gCAAgC,MAAM;AAC7C,OAAG,2BAA2B,MAAM;AAClC,aAAO,eAAe,oBAAoB,CAAC,EAAE,KAAK,oBAAoB;AAAA,IACxE,CAAC;AAED,OAAG,4BAA4B,MAAM;AACnC,aAAO,eAAe,qBAAqB,CAAC,EAAE,KAAK,qBAAqB;AAAA,IAC1E,CAAC;AAED,OAAG,yBAAyB,MAAM;AAChC,aAAO,eAAe,kBAAkB,CAAC,EAAE,KAAK,kBAAkB;AAAA,IACpE,CAAC;AAED,OAAG,0BAA0B,MAAM;AACjC,aAAO,eAAe,mBAAmB,CAAC,EAAE,KAAK,mBAAmB;AAAA,IACtE,CAAC;AAED,OAAG,2BAA2B,MAAM;AAClC,aAAO,eAAe,sBAAsB,CAAC,EAAE,KAAK,sBAAsB;AAAA,IAC5E,CAAC;AAAA,EACH,CAAC;AAED,WAAS,0BAA0B,MAAM;AACvC,OAAG,gCAAgC,MAAM;AACvC,aAAO,eAAe,aAAa,CAAC,EAAE,KAAK,oBAAoB;AAAA,IACjE,CAAC;AAED,OAAG,0CAA0C,MAAM;AACjD,aAAO,eAAe,kBAAkB,CAAC,EAAE,KAAK,yBAAyB;AAAA,IAC3E,CAAC;AAED,OAAG,2CAA2C,MAAM;AAClD,aAAO,eAAe,qBAAqB,CAAC,EAAE,KAAK,4BAA4B;AAAA,IACjF,CAAC;AAED,OAAG,0CAA0C,MAAM;AACjD,aAAO,eAAe,kBAAkB,CAAC,EAAE,KAAK,yBAAyB;AAAA,IAC3E,CAAC;AAED,OAAG,mCAAmC,MAAM;AAC1C,aAAO,eAAe,gBAAgB,CAAC,EAAE,KAAK,uBAAuB;AAAA,IACvE,CAAC;AAAA,EACH,CAAC;AAED,WAAS,sBAAsB,MAAM;AACnC,OAAG,0CAA0C,MAAM;AACjD,aAAO,eAAe,0BAA0B,CAAC,EAAE,KAAK,iCAAiC;AAAA,IAC3F,CAAC;AAED,OAAG,4BAA4B,MAAM;AACnC,aAAO,eAAe,gBAAgB,CAAC,EAAE,KAAK,sBAAsB;AAAA,IACtE,CAAC;AAED,OAAG,0CAA0C,MAAM;AACjD,aAAO,eAAe,4BAA4B,CAAC,EAAE,KAAK,mCAAmC;AAAA,IAC/F,CAAC;AAAA,EACH,CAAC;AAED,WAAS,cAAc,MAAM;AAC3B,OAAG,wBAAwB,MAAM;AAC/B,aAAO,eAAe,EAAE,CAAC,EAAE,KAAK,SAAS;AAAA,IAC3C,CAAC;AAED,OAAG,oCAAoC,MAAM;AAC3C,aAAO,eAAe,aAAa,CAAC,EAAE,KAAK,oBAAoB;AAAA,IACjE,CAAC;AAED,OAAG,oCAAoC,MAAM;AAC3C,aAAO,eAAe,uBAAuB,CAAC,EAAE,KAAK,8BAA8B;AAAA,IACrF,CAAC;AAED,OAAG,wBAAwB,MAAM;AAC/B,aAAO,eAAe,WAAW,CAAC,EAAE,KAAK,kBAAkB;AAAA,IAC7D,CAAC;AAED,OAAG,0BAA0B,MAAM;AACjC,aAAO,eAAe,OAAO,CAAC,EAAE,KAAK,cAAc;AAAA,IACrD,CAAC;AAED,OAAG,+BAA+B,MAAM;AACtC,aAAO,eAAe,qBAAqB,CAAC,EAAE,KAAK,4BAA4B;AAAA,IACjF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -1,35 +1,27 @@
1
- import { formatJsonOrYamlString } from './parse.js';
2
- import { redirectToProxy } from './redirect-to-proxy.js';
3
-
4
- // Doesn’t work
5
- const OLD_PROXY_URL = 'https://api.scalar.com/request-proxy';
6
- // Does work
7
- const NEW_PROXY_URL = 'https://proxy.scalar.com';
8
- /**
9
- * Fetches an OpenAPI/Swagger document from a given URL
10
- *
11
- * @throws an error if the fetch fails
12
- */
1
+ import { formatJsonOrYamlString } from "./parse.js";
2
+ import { redirectToProxy } from "./redirect-to-proxy.js";
3
+ const OLD_PROXY_URL = "https://api.scalar.com/request-proxy";
4
+ const NEW_PROXY_URL = "https://proxy.scalar.com";
13
5
  async function fetchDocument(url, proxyUrl, prettyPrint = true) {
14
- // This replaces the OLD_PROXY_URL with the NEW_PROXY_URL on the fly.
15
- if (proxyUrl === OLD_PROXY_URL) {
16
- // biome-ignore lint/style/noParameterAssign: It’s ok, let’s make an exception here.
17
- proxyUrl = NEW_PROXY_URL;
6
+ if (proxyUrl === OLD_PROXY_URL) {
7
+ proxyUrl = NEW_PROXY_URL;
8
+ }
9
+ const response = await fetch(redirectToProxy(proxyUrl, url));
10
+ if (response.status !== 200) {
11
+ console.error(`[fetchDocument] Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`);
12
+ if (!proxyUrl) {
13
+ console.warn(
14
+ `[fetchDocument] Tried to fetch the OpenAPI document from ${url} without a proxy. Are the CORS headers configured to allow cross-domain requests? https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS`
15
+ );
18
16
  }
19
- const response = await fetch(redirectToProxy(proxyUrl, url));
20
- // Looks like the request failed
21
- if (response.status !== 200) {
22
- console.error(`[fetchDocument] Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`);
23
- if (!proxyUrl) {
24
- console.warn(`[fetchDocument] Tried to fetch the OpenAPI document from ${url} without a proxy. Are the CORS headers configured to allow cross-domain requests? https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS`);
25
- }
26
- throw new Error(`Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`);
27
- }
28
- // If it’s JSON, make it pretty
29
- if (prettyPrint) {
30
- return formatJsonOrYamlString(await response.text());
31
- }
32
- return await response.text();
17
+ throw new Error(`Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`);
18
+ }
19
+ if (prettyPrint) {
20
+ return formatJsonOrYamlString(await response.text());
21
+ }
22
+ return await response.text();
33
23
  }
34
-
35
- export { fetchDocument };
24
+ export {
25
+ fetchDocument
26
+ };
27
+ //# sourceMappingURL=fetch-document.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers/fetch-document.ts"],
4
+ "sourcesContent": ["import { formatJsonOrYamlString } from './parse'\nimport { redirectToProxy } from './redirect-to-proxy'\n\n// Doesn\u2019t work\nconst OLD_PROXY_URL = 'https://api.scalar.com/request-proxy'\n// Does work\nconst NEW_PROXY_URL = 'https://proxy.scalar.com'\n\n/**\n * Fetches an OpenAPI/Swagger document from a given URL\n *\n * @throws an error if the fetch fails\n */\nexport async function fetchDocument(url: string, proxyUrl?: string, prettyPrint = true): Promise<string> {\n // This replaces the OLD_PROXY_URL with the NEW_PROXY_URL on the fly.\n if (proxyUrl === OLD_PROXY_URL) {\n // biome-ignore lint/style/noParameterAssign: It\u2019s ok, let\u2019s make an exception here.\n proxyUrl = NEW_PROXY_URL\n }\n\n const response = await fetch(redirectToProxy(proxyUrl, url))\n\n // Looks like the request failed\n if (response.status !== 200) {\n console.error(`[fetchDocument] Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`)\n\n if (!proxyUrl) {\n console.warn(\n `[fetchDocument] Tried to fetch the OpenAPI document from ${url} without a proxy. Are the CORS headers configured to allow cross-domain requests? https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS`,\n )\n }\n\n throw new Error(`Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`)\n }\n\n // If it\u2019s JSON, make it pretty\n if (prettyPrint) {\n return formatJsonOrYamlString(await response.text())\n }\n\n return await response.text()\n}\n"],
5
+ "mappings": "AAAA,SAAS,8BAA8B;AACvC,SAAS,uBAAuB;AAGhC,MAAM,gBAAgB;AAEtB,MAAM,gBAAgB;AAOtB,eAAsB,cAAc,KAAa,UAAmB,cAAc,MAAuB;AAEvG,MAAI,aAAa,eAAe;AAE9B,eAAW;AAAA,EACb;AAEA,QAAM,WAAW,MAAM,MAAM,gBAAgB,UAAU,GAAG,CAAC;AAG3D,MAAI,SAAS,WAAW,KAAK;AAC3B,YAAQ,MAAM,6DAA6D,GAAG,aAAa,SAAS,MAAM,GAAG;AAE7G,QAAI,CAAC,UAAU;AACb,cAAQ;AAAA,QACN,4DAA4D,GAAG;AAAA,MACjE;AAAA,IACF;AAEA,UAAM,IAAI,MAAM,6CAA6C,GAAG,aAAa,SAAS,MAAM,GAAG;AAAA,EACjG;AAGA,MAAI,aAAa;AACf,WAAO,uBAAuB,MAAM,SAAS,KAAK,CAAC;AAAA,EACrD;AAEA,SAAO,MAAM,SAAS,KAAK;AAC7B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,63 @@
1
+ import { beforeAll, describe, expect, it, vi } from "vitest";
2
+ import { fetchDocument } from "./fetch-document.js";
3
+ const PROXY_PORT = 5051;
4
+ beforeAll(async () => {
5
+ try {
6
+ const result = await fetch(`http://127.0.0.1:${PROXY_PORT}`);
7
+ if (result.ok) {
8
+ return;
9
+ }
10
+ } catch (_error) {
11
+ throw new Error(`
12
+
13
+ [sendRequest.test.ts] Looks like you\u2019re not running @scalar/proxy-server on <http://127.0.0.1:${PROXY_PORT}>, but it\u2019s required for this test file.
14
+
15
+ Try to run it like this:
16
+
17
+ $ pnpm dev:proxy-server
18
+ `);
19
+ }
20
+ });
21
+ describe("fetchDocument", () => {
22
+ it("fetches specifications (without a proxy)", async () => {
23
+ const spec = await fetchDocument("https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml");
24
+ expect(typeof spec).toEqual("string");
25
+ expect(spec.length).toBeGreaterThan(100);
26
+ });
27
+ it("fetches specifications (through proxy.scalar.com)", async () => {
28
+ const spec = await fetchDocument(
29
+ "https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml",
30
+ "https://proxy.scalar.com"
31
+ );
32
+ expect(typeof spec).toEqual("string");
33
+ expect(spec.length).toBeGreaterThan(100);
34
+ });
35
+ it(`fetches specifications (through 127.0.0.1:${PROXY_PORT})`, async () => {
36
+ const spec = await fetchDocument(
37
+ "https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml",
38
+ `http://127.0.0.1:${PROXY_PORT}`
39
+ );
40
+ expect(typeof spec).toEqual("string");
41
+ expect(spec.length).toBeGreaterThan(100);
42
+ });
43
+ it("fetches specifications from localhost without proxy", async () => {
44
+ const originalFetch = globalThis.fetch;
45
+ globalThis.fetch = vi.fn(
46
+ () => Promise.resolve({
47
+ ok: true,
48
+ status: 200,
49
+ text: () => Promise.resolve("")
50
+ })
51
+ );
52
+ const spec = await fetchDocument(`http://127.0.0.1:${PROXY_PORT}/test`);
53
+ expect(typeof spec).toEqual("string");
54
+ globalThis.fetch = originalFetch;
55
+ });
56
+ it("throws error for invalid URLs", async () => {
57
+ await expect(fetchDocument("not-a-valid-url")).rejects.toThrow();
58
+ });
59
+ it("throws error when fetch fails", async () => {
60
+ await expect(fetchDocument("https://does-not-exist.scalar.com/spec.yaml")).rejects.toThrow("fetch failed");
61
+ });
62
+ });
63
+ //# sourceMappingURL=fetch-document.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers/fetch-document.test.ts"],
4
+ "sourcesContent": ["// @vitest-environment jsdom\nimport { beforeAll, describe, expect, it, vi } from 'vitest'\n\nimport { fetchDocument } from './fetch-document'\n\nconst PROXY_PORT = 5051\n\nbeforeAll(async () => {\n // Check whether the proxy-server is running\n try {\n const result = await fetch(`http://127.0.0.1:${PROXY_PORT}`)\n\n if (result.ok) {\n return\n }\n } catch (_error) {\n throw new Error(`\n\n[sendRequest.test.ts] Looks like you\u2019re not running @scalar/proxy-server on <http://127.0.0.1:${PROXY_PORT}>, but it\u2019s required for this test file.\n\nTry to run it like this:\n\n$ pnpm dev:proxy-server\n`)\n }\n})\n\ndescribe('fetchDocument', () => {\n it('fetches specifications (without a proxy)', async () => {\n const spec = await fetchDocument('https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml')\n\n expect(typeof spec).toEqual('string')\n expect(spec.length).toBeGreaterThan(100)\n })\n\n it('fetches specifications (through proxy.scalar.com)', async () => {\n const spec = await fetchDocument(\n 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml',\n 'https://proxy.scalar.com',\n )\n\n expect(typeof spec).toEqual('string')\n expect(spec.length).toBeGreaterThan(100)\n })\n\n it(`fetches specifications (through 127.0.0.1:${PROXY_PORT})`, async () => {\n const spec = await fetchDocument(\n 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml',\n `http://127.0.0.1:${PROXY_PORT}`,\n )\n\n expect(typeof spec).toEqual('string')\n expect(spec.length).toBeGreaterThan(100)\n })\n\n it('fetches specifications from localhost without proxy', async () => {\n const originalFetch = globalThis.fetch\n // mock fetch\n // @ts-expect-error TODO not properly typed\n globalThis.fetch = vi.fn(() =>\n Promise.resolve({\n ok: true,\n status: 200,\n text: () => Promise.resolve(''),\n }),\n )\n\n const spec = await fetchDocument(`http://127.0.0.1:${PROXY_PORT}/test`)\n\n expect(typeof spec).toEqual('string')\n\n // restore fetch\n globalThis.fetch = originalFetch\n })\n\n it('throws error for invalid URLs', async () => {\n await expect(fetchDocument('not-a-valid-url')).rejects.toThrow()\n })\n\n it('throws error when fetch fails', async () => {\n await expect(fetchDocument('https://does-not-exist.scalar.com/spec.yaml')).rejects.toThrow('fetch failed')\n })\n})\n"],
5
+ "mappings": "AACA,SAAS,WAAW,UAAU,QAAQ,IAAI,UAAU;AAEpD,SAAS,qBAAqB;AAE9B,MAAM,aAAa;AAEnB,UAAU,YAAY;AAEpB,MAAI;AACF,UAAM,SAAS,MAAM,MAAM,oBAAoB,UAAU,EAAE;AAE3D,QAAI,OAAO,IAAI;AACb;AAAA,IACF;AAAA,EACF,SAAS,QAAQ;AACf,UAAM,IAAI,MAAM;AAAA;AAAA,qGAE4E,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,CAKzG;AAAA,EACC;AACF,CAAC;AAED,SAAS,iBAAiB,MAAM;AAC9B,KAAG,4CAA4C,YAAY;AACzD,UAAM,OAAO,MAAM,cAAc,8DAA8D;AAE/F,WAAO,OAAO,IAAI,EAAE,QAAQ,QAAQ;AACpC,WAAO,KAAK,MAAM,EAAE,gBAAgB,GAAG;AAAA,EACzC,CAAC;AAED,KAAG,qDAAqD,YAAY;AAClE,UAAM,OAAO,MAAM;AAAA,MACjB;AAAA,MACA;AAAA,IACF;AAEA,WAAO,OAAO,IAAI,EAAE,QAAQ,QAAQ;AACpC,WAAO,KAAK,MAAM,EAAE,gBAAgB,GAAG;AAAA,EACzC,CAAC;AAED,KAAG,6CAA6C,UAAU,KAAK,YAAY;AACzE,UAAM,OAAO,MAAM;AAAA,MACjB;AAAA,MACA,oBAAoB,UAAU;AAAA,IAChC;AAEA,WAAO,OAAO,IAAI,EAAE,QAAQ,QAAQ;AACpC,WAAO,KAAK,MAAM,EAAE,gBAAgB,GAAG;AAAA,EACzC,CAAC;AAED,KAAG,uDAAuD,YAAY;AACpE,UAAM,gBAAgB,WAAW;AAGjC,eAAW,QAAQ,GAAG;AAAA,MAAG,MACvB,QAAQ,QAAQ;AAAA,QACd,IAAI;AAAA,QACJ,QAAQ;AAAA,QACR,MAAM,MAAM,QAAQ,QAAQ,EAAE;AAAA,MAChC,CAAC;AAAA,IACH;AAEA,UAAM,OAAO,MAAM,cAAc,oBAAoB,UAAU,OAAO;AAEtE,WAAO,OAAO,IAAI,EAAE,QAAQ,QAAQ;AAGpC,eAAW,QAAQ;AAAA,EACrB,CAAC;AAED,KAAG,iCAAiC,YAAY;AAC9C,UAAM,OAAO,cAAc,iBAAiB,CAAC,EAAE,QAAQ,QAAQ;AAAA,EACjE,CAAC;AAED,KAAG,iCAAiC,YAAY;AAC9C,UAAM,OAAO,cAAc,6CAA6C,CAAC,EAAE,QAAQ,QAAQ,cAAc;AAAA,EAC3G,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -1,32 +1,24 @@
1
- import { shouldUseProxy, redirectToProxy } from './redirect-to-proxy.js';
2
-
3
- /**
4
- * Fetches an OpenAPI document with a proxyUrl fallback mechanism.
5
- *
6
- * If a proxy is provided and the URL requires it, it will first attempt to fetch using the proxy.
7
- * If the proxy fetch fails or is not used, it will fall back to a direct fetch.
8
- */
1
+ import { redirectToProxy, shouldUseProxy } from "./redirect-to-proxy.js";
9
2
  async function fetchWithProxyFallback(url, { proxyUrl, cache }) {
10
- const fetchOptions = {
11
- cache: cache || 'default',
12
- };
13
- const shouldTryProxy = shouldUseProxy(proxyUrl, url);
14
- const initialUrl = shouldTryProxy ? redirectToProxy(proxyUrl, url) : url;
15
- try {
16
- const result = await fetch(initialUrl, fetchOptions);
17
- if (result.ok || !shouldTryProxy) {
18
- return result;
19
- }
20
- // Retry without proxyUrl if the initial request failed
21
- return await fetch(url, fetchOptions);
3
+ const fetchOptions = {
4
+ cache: cache || "default"
5
+ };
6
+ const shouldTryProxy = shouldUseProxy(proxyUrl, url);
7
+ const initialUrl = shouldTryProxy ? redirectToProxy(proxyUrl, url) : url;
8
+ try {
9
+ const result = await fetch(initialUrl, fetchOptions);
10
+ if (result.ok || !shouldTryProxy) {
11
+ return result;
22
12
  }
23
- catch (error) {
24
- if (shouldTryProxy) {
25
- // If proxyUrl failed, try without it
26
- return await fetch(url, fetchOptions);
27
- }
28
- throw error;
13
+ return await fetch(url, fetchOptions);
14
+ } catch (error) {
15
+ if (shouldTryProxy) {
16
+ return await fetch(url, fetchOptions);
29
17
  }
18
+ throw error;
19
+ }
30
20
  }
31
-
32
- export { fetchWithProxyFallback };
21
+ export {
22
+ fetchWithProxyFallback
23
+ };
24
+ //# sourceMappingURL=fetch-with-proxy-fallback.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers/fetch-with-proxy-fallback.ts"],
4
+ "sourcesContent": ["import { redirectToProxy, shouldUseProxy } from './redirect-to-proxy'\n\nexport type FetchWithProxyFallbackOptions = {\n proxyUrl: string | undefined\n /**\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/cache\n */\n cache?: RequestInit['cache']\n}\n\n/**\n * Fetches an OpenAPI document with a proxyUrl fallback mechanism.\n *\n * If a proxy is provided and the URL requires it, it will first attempt to fetch using the proxy.\n * If the proxy fetch fails or is not used, it will fall back to a direct fetch.\n */\nexport async function fetchWithProxyFallback(url: string, { proxyUrl, cache }: FetchWithProxyFallbackOptions) {\n const fetchOptions = {\n cache: cache || 'default',\n }\n const shouldTryProxy = shouldUseProxy(proxyUrl, url)\n const initialUrl = shouldTryProxy ? redirectToProxy(proxyUrl, url) : url\n\n try {\n const result = await fetch(initialUrl, fetchOptions)\n\n if (result.ok || !shouldTryProxy) {\n return result\n }\n\n // Retry without proxyUrl if the initial request failed\n return await fetch(url, fetchOptions)\n } catch (error) {\n if (shouldTryProxy) {\n // If proxyUrl failed, try without it\n return await fetch(url, fetchOptions)\n }\n throw error\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,iBAAiB,sBAAsB;AAgBhD,eAAsB,uBAAuB,KAAa,EAAE,UAAU,MAAM,GAAkC;AAC5G,QAAM,eAAe;AAAA,IACnB,OAAO,SAAS;AAAA,EAClB;AACA,QAAM,iBAAiB,eAAe,UAAU,GAAG;AACnD,QAAM,aAAa,iBAAiB,gBAAgB,UAAU,GAAG,IAAI;AAErE,MAAI;AACF,UAAM,SAAS,MAAM,MAAM,YAAY,YAAY;AAEnD,QAAI,OAAO,MAAM,CAAC,gBAAgB;AAChC,aAAO;AAAA,IACT;AAGA,WAAO,MAAM,MAAM,KAAK,YAAY;AAAA,EACtC,SAAS,OAAO;AACd,QAAI,gBAAgB;AAElB,aAAO,MAAM,MAAM,KAAK,YAAY;AAAA,IACtC;AACA,UAAM;AAAA,EACR;AACF;",
6
+ "names": []
7
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * Find all strings wrapped in {} or {{}} in value.
3
3
  */
4
- export declare const findVariables: (value: string) => (string | undefined)[];
4
+ export declare const findVariables: (value: string) => string[];
5
5
  //# sourceMappingURL=find-variables.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-variables.d.ts","sourceRoot":"","sources":["../../src/helpers/find-variables.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,2BAE1C,CAAA"}
1
+ {"version":3,"file":"find-variables.d.ts","sourceRoot":"","sources":["../../src/helpers/find-variables.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,aAE1C,CAAA"}
@@ -1,10 +1,8 @@
1
- import { REGEX } from './regex-helpers.js';
2
-
3
- /**
4
- * Find all strings wrapped in {} or {{}} in value.
5
- */
1
+ import { REGEX } from "./regex-helpers.js";
6
2
  const findVariables = (value) => {
7
- return [...value.matchAll(REGEX.PATH), ...value.matchAll(REGEX.VARIABLES)].map((match) => match[1]?.trim()) || [];
3
+ return [...value.matchAll(REGEX.PATH), ...value.matchAll(REGEX.VARIABLES)].map((match) => match[1]?.trim()) || [];
8
4
  };
9
-
10
- export { findVariables };
5
+ export {
6
+ findVariables
7
+ };
8
+ //# sourceMappingURL=find-variables.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers/find-variables.ts"],
4
+ "sourcesContent": ["import { REGEX } from './regex-helpers'\n\n/**\n * Find all strings wrapped in {} or {{}} in value.\n */\nexport const findVariables = (value: string) => {\n return [...value.matchAll(REGEX.PATH), ...value.matchAll(REGEX.VARIABLES)].map((match) => match[1]?.trim()) || []\n}\n"],
5
+ "mappings": "AAAA,SAAS,aAAa;AAKf,MAAM,gBAAgB,CAAC,UAAkB;AAC9C,SAAO,CAAC,GAAG,MAAM,SAAS,MAAM,IAAI,GAAG,GAAG,MAAM,SAAS,MAAM,SAAS,CAAC,EAAE,IAAI,CAAC,UAAU,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;AAClH;",
6
+ "names": []
7
+ }
@@ -0,0 +1,20 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { findVariables } from "./find-variables.js";
3
+ describe("findVariables", () => {
4
+ it("finds variables", async () => {
5
+ expect(findVariables("http://{baseUrl}/foobar")).toEqual(["baseUrl"]);
6
+ });
7
+ it("finds variables with double curly braces", async () => {
8
+ expect(findVariables("http://{{baseUrl}}/foobar")).toEqual(["baseUrl"]);
9
+ });
10
+ it("ignores whitespace", async () => {
11
+ expect(findVariables("http://{ baseUrl }/foobar")).toEqual(["baseUrl"]);
12
+ });
13
+ it("works with special characters", async () => {
14
+ expect(findVariables("http://{Example123_}/foobar")).toEqual(["Example123_"]);
15
+ });
16
+ it("returns an empty array if there\u2019s no variable", async () => {
17
+ expect(findVariables("http://example.com/foobar")).toEqual([]);
18
+ });
19
+ });
20
+ //# sourceMappingURL=find-variables.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers/find-variables.test.ts"],
4
+ "sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { findVariables } from './find-variables'\n\ndescribe('findVariables', () => {\n it('finds variables', async () => {\n expect(findVariables('http://{baseUrl}/foobar')).toEqual(['baseUrl'])\n })\n\n it('finds variables with double curly braces', async () => {\n expect(findVariables('http://{{baseUrl}}/foobar')).toEqual(['baseUrl'])\n })\n\n it('ignores whitespace', async () => {\n expect(findVariables('http://{ baseUrl }/foobar')).toEqual(['baseUrl'])\n })\n\n it('works with special characters', async () => {\n expect(findVariables('http://{Example123_}/foobar')).toEqual(['Example123_'])\n })\n\n it('returns an empty array if there\u2019s no variable', async () => {\n expect(findVariables('http://example.com/foobar')).toEqual([])\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,qBAAqB;AAE9B,SAAS,iBAAiB,MAAM;AAC9B,KAAG,mBAAmB,YAAY;AAChC,WAAO,cAAc,yBAAyB,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC;AAAA,EACtE,CAAC;AAED,KAAG,4CAA4C,YAAY;AACzD,WAAO,cAAc,2BAA2B,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC;AAAA,EACxE,CAAC;AAED,KAAG,sBAAsB,YAAY;AACnC,WAAO,cAAc,2BAA2B,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC;AAAA,EACxE,CAAC;AAED,KAAG,iCAAiC,YAAY;AAC9C,WAAO,cAAc,6BAA6B,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC;AAAA,EAC9E,CAAC;AAED,KAAG,sDAAiD,YAAY;AAC9D,WAAO,cAAc,2BAA2B,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA,EAC/D,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -1,4 +1,4 @@
1
- import { type RequestMethod } from '../entities/spec/requests.ts';
1
+ import { type RequestMethod } from '../entities/spec/requests.js';
2
2
  /**
3
3
  * HTTP methods in a specific order
4
4
  * Do not change the order
@@ -1 +1 @@
1
- {"version":3,"file":"http-methods.d.ts","sourceRoot":"","sources":["../../src/helpers/http-methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,6BAA6B,CAAA;AAEhF;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE;KAC3B,CAAC,IAAI,aAAa,GAAG;QACpB,KAAK,EAAE,MAAM,CAAA;QACb,KAAK,EAAE,MAAM,CAAA;QACb,eAAe,EAAE,MAAM,CAAA;KACxB;CA+CO,CAAA;AAEV,yCAAyC;AACzC,QAAA,MAAM,YAAY,6CAA8C,CAAA;AAChE,KAAK,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/C,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB,WAAY,aAAa,KAAG,MAAM,IAAI,UACvB,CAAA;AAE7C;;GAEG;AACH,eAAO,MAAM,iBAAiB,eAAgB,MAAM;WA/DzC,MAAM;WACN,MAAM;qBACI,MAAM;CAsE1B,CAAA;AAED,yFAAyF;AACzF,eAAO,MAAM,YAAY,YAAa,MAAM,GAAG,SAAS,KAAG,MAAM,IAAI,aACF,CAAA"}
1
+ {"version":3,"file":"http-methods.d.ts","sourceRoot":"","sources":["../../src/helpers/http-methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,0BAA0B,CAAA;AAE7E;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE;KAC3B,CAAC,IAAI,aAAa,GAAG;QACpB,KAAK,EAAE,MAAM,CAAA;QACb,KAAK,EAAE,MAAM,CAAA;QACb,eAAe,EAAE,MAAM,CAAA;KACxB;CA+CO,CAAA;AAEV,yCAAyC;AACzC,QAAA,MAAM,YAAY,6CAA8C,CAAA;AAChE,KAAK,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/C,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB,WAAY,aAAa,KAAG,MAAM,IAAI,UACvB,CAAA;AAE7C;;GAEG;AACH,eAAO,MAAM,iBAAiB,eAAgB,MAAM;WA/DzC,MAAM;WACN,MAAM;qBACI,MAAM;CAsE1B,CAAA;AAED,yFAAyF;AACzF,eAAO,MAAM,YAAY,YAAa,MAAM,GAAG,SAAS,KAAG,MAAM,IAAI,aACF,CAAA"}