@scalar/workspace-store 0.40.2 → 0.40.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/client.d.ts +7 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +820 -681
- package/dist/entities/auth/index.js +96 -101
- package/dist/entities/auth/schema.js +42 -116
- package/dist/entities/history/index.js +80 -60
- package/dist/entities/history/schema.js +94 -88
- package/dist/events/bus.js +146 -93
- package/dist/events/definitions/analytics.js +1 -1
- package/dist/events/definitions/auth.js +1 -1
- package/dist/events/definitions/common.js +1 -1
- package/dist/events/definitions/cookie.js +1 -1
- package/dist/events/definitions/document.js +1 -1
- package/dist/events/definitions/environment.js +1 -1
- package/dist/events/definitions/hooks.js +1 -1
- package/dist/events/definitions/index.js +1 -1
- package/dist/events/definitions/meta.js +1 -1
- package/dist/events/definitions/operation.js +1 -1
- package/dist/events/definitions/server.js +1 -1
- package/dist/events/definitions/tabs.js +1 -1
- package/dist/events/definitions/tag.js +1 -1
- package/dist/events/definitions/ui.js +1 -1
- package/dist/events/definitions/workspace.js +1 -1
- package/dist/events/index.js +3 -9
- package/dist/events/listeners.js +20 -22
- package/dist/events/old-definitions.js +15 -12
- package/dist/helpers/deep-clone.js +33 -17
- package/dist/helpers/detect-changes-proxy.js +95 -57
- package/dist/helpers/general.js +78 -23
- package/dist/helpers/generate-unique-value.js +77 -45
- package/dist/helpers/get-fetch.js +12 -10
- package/dist/helpers/get-resolved-ref.js +11 -10
- package/dist/helpers/is-non-optional-security-requirement.js +3 -6
- package/dist/helpers/merge-object.js +71 -30
- package/dist/helpers/overrides-proxy.js +98 -58
- package/dist/helpers/unpack-proxy.js +60 -58
- package/dist/mutators/auth.js +358 -230
- package/dist/mutators/cookie.js +59 -42
- package/dist/mutators/document.js +104 -66
- package/dist/mutators/environment.js +97 -72
- package/dist/mutators/helpers.js +9 -13
- package/dist/mutators/index.js +62 -49
- package/dist/mutators/operation/body.js +88 -57
- package/dist/mutators/operation/extensions.js +20 -12
- package/dist/mutators/operation/helpers/fetch-request-to-har.js +144 -107
- package/dist/mutators/operation/helpers/fetch-response-to-har.js +143 -95
- package/dist/mutators/operation/helpers/get-parameter-position.js +12 -12
- package/dist/mutators/operation/helpers/har-to-operation.js +169 -132
- package/dist/mutators/operation/helpers/sync-path-parameters.js +109 -60
- package/dist/mutators/operation/history.js +60 -64
- package/dist/mutators/operation/index.js +25 -49
- package/dist/mutators/operation/operation.js +349 -240
- package/dist/mutators/operation/parameters.js +157 -93
- package/dist/mutators/server.js +213 -152
- package/dist/mutators/tabs.js +173 -130
- package/dist/mutators/tag.js +131 -97
- package/dist/mutators/workspace.js +72 -42
- package/dist/navigation/get-navigation-options.js +97 -84
- package/dist/navigation/helpers/get-openapi-object.js +46 -29
- package/dist/navigation/helpers/get-operation-entries.js +72 -32
- package/dist/navigation/helpers/get-parent-entry.js +16 -12
- package/dist/navigation/helpers/get-tag-entries.js +56 -29
- package/dist/navigation/helpers/get-tag.js +22 -23
- package/dist/navigation/helpers/get-x-keys.js +13 -9
- package/dist/navigation/helpers/traverse-description.js +90 -72
- package/dist/navigation/helpers/traverse-document.js +111 -98
- package/dist/navigation/helpers/traverse-examples.js +35 -31
- package/dist/navigation/helpers/traverse-paths.js +118 -106
- package/dist/navigation/helpers/traverse-schemas.js +65 -64
- package/dist/navigation/helpers/traverse-tags.js +158 -129
- package/dist/navigation/helpers/traverse-webhooks.js +96 -90
- package/dist/navigation/helpers/update-order-ids.js +59 -51
- package/dist/navigation/helpers/utils.js +71 -21
- package/dist/navigation/index.js +5 -13
- package/dist/navigation/types.js +1 -1
- package/dist/persistence/index.js +283 -285
- package/dist/persistence/indexdb.js +263 -126
- package/dist/plugins/bundler/helpers.js +21 -12
- package/dist/plugins/bundler/index.d.ts +7 -0
- package/dist/plugins/bundler/index.d.ts.map +1 -1
- package/dist/plugins/bundler/index.js +305 -171
- package/dist/plugins/client/index.js +1 -5
- package/dist/plugins/client/persistence.js +95 -90
- package/dist/resolve.js +18 -25
- package/dist/schemas/compose.js +6 -7
- package/dist/schemas/extensions/document/x-internal.js +3 -7
- package/dist/schemas/extensions/document/x-scalar-environments.js +16 -22
- package/dist/schemas/extensions/document/x-scalar-icon.js +3 -7
- package/dist/schemas/extensions/document/x-scalar-ignore.js +3 -7
- package/dist/schemas/extensions/document/x-scalar-is-dirty.js +21 -8
- package/dist/schemas/extensions/document/x-scalar-original-document-hash.js +17 -8
- package/dist/schemas/extensions/document/x-scalar-registry-meta.js +15 -21
- package/dist/schemas/extensions/document/x-scalar-sdk-installation.js +5 -13
- package/dist/schemas/extensions/document/x-scalar-watch-mode.js +4 -8
- package/dist/schemas/extensions/document/x-tags.js +3 -7
- package/dist/schemas/extensions/example/x-disabled.js +17 -7
- package/dist/schemas/extensions/general/x-scalar-active-environment.js +4 -7
- package/dist/schemas/extensions/general/x-scalar-cookies.js +9 -14
- package/dist/schemas/extensions/general/x-scalar-order.js +8 -7
- package/dist/schemas/extensions/operation/index.js +4 -23
- package/dist/schemas/extensions/operation/x-badge.js +42 -50
- package/dist/schemas/extensions/operation/x-code-samples.js +8 -12
- package/dist/schemas/extensions/operation/x-draft-examples.js +3 -7
- package/dist/schemas/extensions/operation/x-post-response.js +18 -7
- package/dist/schemas/extensions/operation/x-scalar-disable-parameters.js +57 -13
- package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js +9 -7
- package/dist/schemas/extensions/operation/x-scalar-stability.js +15 -14
- package/dist/schemas/extensions/parameter/x-global.js +12 -7
- package/dist/schemas/extensions/schema/x-additional-properties-name.js +10 -7
- package/dist/schemas/extensions/schema/x-enum-descriptions.js +17 -12
- package/dist/schemas/extensions/schema/x-enum-varnames.js +21 -8
- package/dist/schemas/extensions/schema/x-examples.js +3 -7
- package/dist/schemas/extensions/schema/x-variable.js +3 -7
- package/dist/schemas/extensions/security/index.js +1 -1
- package/dist/schemas/extensions/security/x-default-scopes.js +16 -7
- package/dist/schemas/extensions/security/x-scalar-credentials-location.js +16 -7
- package/dist/schemas/extensions/security/x-scalar-security-body.js +14 -7
- package/dist/schemas/extensions/security/x-scalar-security-query.js +14 -7
- package/dist/schemas/extensions/security/x-scalar-security-secrets.js +66 -37
- package/dist/schemas/extensions/security/x-tokenName.js +11 -7
- package/dist/schemas/extensions/security/x-use-pkce.js +6 -10
- package/dist/schemas/extensions/server/x-scalar-selected-server.js +3 -7
- package/dist/schemas/extensions/tag/index.js +1 -1
- package/dist/schemas/extensions/tag/x-display-name.js +11 -7
- package/dist/schemas/extensions/tag/x-tag-groups.js +13 -15
- package/dist/schemas/extensions/workspace/index.js +2 -11
- package/dist/schemas/extensions/workspace/x-scalar-active-proxy.js +13 -7
- package/dist/schemas/extensions/workspace/x-scalar-tabs.js +15 -13
- package/dist/schemas/extensions.js +11 -15
- package/dist/schemas/inmemory-workspace.js +13 -21
- package/dist/schemas/navigation.js +48 -85
- package/dist/schemas/reference-config/appearance.js +15 -22
- package/dist/schemas/reference-config/features.js +14 -21
- package/dist/schemas/reference-config/index.js +42 -44
- package/dist/schemas/reference-config/meta.js +11 -18
- package/dist/schemas/reference-config/routing.js +7 -14
- package/dist/schemas/reference-config/settings.js +10 -17
- package/dist/schemas/typebox-coerce.js +23 -6
- package/dist/schemas/v3.1/strict/callback.js +6 -12
- package/dist/schemas/v3.1/strict/components.js +26 -48
- package/dist/schemas/v3.1/strict/contact.js +9 -12
- package/dist/schemas/v3.1/strict/discriminator.js +11 -10
- package/dist/schemas/v3.1/strict/encoding.js +15 -12
- package/dist/schemas/v3.1/strict/example.js +11 -13
- package/dist/schemas/v3.1/strict/external-documentation.js +7 -10
- package/dist/schemas/v3.1/strict/header.js +27 -28
- package/dist/schemas/v3.1/strict/info.js +10 -16
- package/dist/schemas/v3.1/strict/license.js +9 -12
- package/dist/schemas/v3.1/strict/link.js +22 -19
- package/dist/schemas/v3.1/strict/media-type.js +17 -16
- package/dist/schemas/v3.1/strict/oauth-flow.js +28 -62
- package/dist/schemas/v3.1/strict/oauthflows.js +14 -20
- package/dist/schemas/v3.1/strict/openapi-document.js +126 -210
- package/dist/schemas/v3.1/strict/operation.js +16 -43
- package/dist/schemas/v3.1/strict/parameter.js +27 -35
- package/dist/schemas/v3.1/strict/path-item.js +36 -40
- package/dist/schemas/v3.1/strict/paths.js +8 -11
- package/dist/schemas/v3.1/strict/ref-definitions.js +76 -100
- package/dist/schemas/v3.1/strict/reference.js +18 -21
- package/dist/schemas/v3.1/strict/request-body.js +8 -16
- package/dist/schemas/v3.1/strict/response.js +12 -16
- package/dist/schemas/v3.1/strict/responses.js +13 -11
- package/dist/schemas/v3.1/strict/schema.js +149 -157
- package/dist/schemas/v3.1/strict/security-requirement.js +13 -12
- package/dist/schemas/v3.1/strict/security-scheme.js +29 -41
- package/dist/schemas/v3.1/strict/server-variable.js +9 -12
- package/dist/schemas/v3.1/strict/server.js +10 -13
- package/dist/schemas/v3.1/strict/tag.js +11 -20
- package/dist/schemas/v3.1/strict/type-guards.js +20 -20
- package/dist/schemas/v3.1/strict/xml.js +17 -16
- package/dist/schemas/workspace-specification/index.js +11 -23
- package/dist/schemas/workspace-specification/info.js +4 -8
- package/dist/schemas/workspace.js +25 -51
- package/dist/schemas.js +2 -6
- package/dist/server.js +286 -176
- package/dist/workspace-plugin.js +1 -1
- package/package.json +13 -19
- package/dist/client.js.map +0 -7
- package/dist/entities/auth/index.js.map +0 -7
- package/dist/entities/auth/schema.js.map +0 -7
- package/dist/entities/history/index.js.map +0 -7
- package/dist/entities/history/schema.js.map +0 -7
- package/dist/events/bus.js.map +0 -7
- package/dist/events/definitions/analytics.js.map +0 -7
- package/dist/events/definitions/auth.js.map +0 -7
- package/dist/events/definitions/common.js.map +0 -7
- package/dist/events/definitions/cookie.js.map +0 -7
- package/dist/events/definitions/document.js.map +0 -7
- package/dist/events/definitions/environment.js.map +0 -7
- package/dist/events/definitions/hooks.js.map +0 -7
- package/dist/events/definitions/index.js.map +0 -7
- package/dist/events/definitions/meta.js.map +0 -7
- package/dist/events/definitions/operation.js.map +0 -7
- package/dist/events/definitions/server.js.map +0 -7
- package/dist/events/definitions/tabs.js.map +0 -7
- package/dist/events/definitions/tag.js.map +0 -7
- package/dist/events/definitions/ui.js.map +0 -7
- package/dist/events/definitions/workspace.js.map +0 -7
- package/dist/events/index.js.map +0 -7
- package/dist/events/listeners.js.map +0 -7
- package/dist/events/old-definitions.js.map +0 -7
- package/dist/helpers/apply-selective-updates.d.ts +0 -19
- package/dist/helpers/apply-selective-updates.d.ts.map +0 -1
- package/dist/helpers/apply-selective-updates.js +0 -37
- package/dist/helpers/apply-selective-updates.js.map +0 -7
- package/dist/helpers/deep-clone.js.map +0 -7
- package/dist/helpers/detect-changes-proxy.js.map +0 -7
- package/dist/helpers/general.js.map +0 -7
- package/dist/helpers/generate-unique-value.js.map +0 -7
- package/dist/helpers/get-fetch.js.map +0 -7
- package/dist/helpers/get-resolved-ref.js.map +0 -7
- package/dist/helpers/is-non-optional-security-requirement.js.map +0 -7
- package/dist/helpers/merge-object.js.map +0 -7
- package/dist/helpers/overrides-proxy.js.map +0 -7
- package/dist/helpers/unpack-proxy.js.map +0 -7
- package/dist/mutators/auth.js.map +0 -7
- package/dist/mutators/cookie.js.map +0 -7
- package/dist/mutators/document.js.map +0 -7
- package/dist/mutators/environment.js.map +0 -7
- package/dist/mutators/helpers.js.map +0 -7
- package/dist/mutators/index.js.map +0 -7
- package/dist/mutators/operation/body.js.map +0 -7
- package/dist/mutators/operation/extensions.js.map +0 -7
- package/dist/mutators/operation/helpers/fetch-request-to-har.js.map +0 -7
- package/dist/mutators/operation/helpers/fetch-response-to-har.js.map +0 -7
- package/dist/mutators/operation/helpers/get-parameter-position.js.map +0 -7
- package/dist/mutators/operation/helpers/har-to-operation.js.map +0 -7
- package/dist/mutators/operation/helpers/sync-path-parameters.js.map +0 -7
- package/dist/mutators/operation/history.js.map +0 -7
- package/dist/mutators/operation/index.js.map +0 -7
- package/dist/mutators/operation/operation.js.map +0 -7
- package/dist/mutators/operation/parameters.js.map +0 -7
- package/dist/mutators/server.js.map +0 -7
- package/dist/mutators/tabs.js.map +0 -7
- package/dist/mutators/tag.js.map +0 -7
- package/dist/mutators/workspace.js.map +0 -7
- package/dist/navigation/get-navigation-options.js.map +0 -7
- package/dist/navigation/helpers/get-openapi-object.js.map +0 -7
- package/dist/navigation/helpers/get-operation-entries.js.map +0 -7
- package/dist/navigation/helpers/get-parent-entry.js.map +0 -7
- package/dist/navigation/helpers/get-tag-entries.js.map +0 -7
- package/dist/navigation/helpers/get-tag.js.map +0 -7
- package/dist/navigation/helpers/get-x-keys.js.map +0 -7
- package/dist/navigation/helpers/traverse-description.js.map +0 -7
- package/dist/navigation/helpers/traverse-document.js.map +0 -7
- package/dist/navigation/helpers/traverse-examples.js.map +0 -7
- package/dist/navigation/helpers/traverse-paths.js.map +0 -7
- package/dist/navigation/helpers/traverse-schemas.js.map +0 -7
- package/dist/navigation/helpers/traverse-tags.js.map +0 -7
- package/dist/navigation/helpers/traverse-webhooks.js.map +0 -7
- package/dist/navigation/helpers/update-order-ids.js.map +0 -7
- package/dist/navigation/helpers/utils.js.map +0 -7
- package/dist/navigation/index.js.map +0 -7
- package/dist/navigation/types.js.map +0 -7
- package/dist/persistence/index.js.map +0 -7
- package/dist/persistence/indexdb.js.map +0 -7
- package/dist/plugins/bundler/helpers.js.map +0 -7
- package/dist/plugins/bundler/index.js.map +0 -7
- package/dist/plugins/client/index.js.map +0 -7
- package/dist/plugins/client/persistence.js.map +0 -7
- package/dist/resolve.js.map +0 -7
- package/dist/schemas/compose.js.map +0 -7
- package/dist/schemas/extensions/document/x-internal.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-environments.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-icon.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-ignore.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-is-dirty.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-original-document-hash.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-registry-meta.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-sdk-installation.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-watch-mode.js.map +0 -7
- package/dist/schemas/extensions/document/x-tags.js.map +0 -7
- package/dist/schemas/extensions/example/x-disabled.js.map +0 -7
- package/dist/schemas/extensions/general/x-scalar-active-environment.js.map +0 -7
- package/dist/schemas/extensions/general/x-scalar-cookies.js.map +0 -7
- package/dist/schemas/extensions/general/x-scalar-order.js.map +0 -7
- package/dist/schemas/extensions/operation/index.js.map +0 -7
- package/dist/schemas/extensions/operation/x-badge.js.map +0 -7
- package/dist/schemas/extensions/operation/x-code-samples.js.map +0 -7
- package/dist/schemas/extensions/operation/x-draft-examples.js.map +0 -7
- package/dist/schemas/extensions/operation/x-post-response.js.map +0 -7
- package/dist/schemas/extensions/operation/x-scalar-disable-parameters.js.map +0 -7
- package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js.map +0 -7
- package/dist/schemas/extensions/operation/x-scalar-stability.js.map +0 -7
- package/dist/schemas/extensions/parameter/x-global.js.map +0 -7
- package/dist/schemas/extensions/schema/x-additional-properties-name.js.map +0 -7
- package/dist/schemas/extensions/schema/x-enum-descriptions.js.map +0 -7
- package/dist/schemas/extensions/schema/x-enum-varnames.js.map +0 -7
- package/dist/schemas/extensions/schema/x-examples.js.map +0 -7
- package/dist/schemas/extensions/schema/x-variable.js.map +0 -7
- package/dist/schemas/extensions/security/index.js.map +0 -7
- package/dist/schemas/extensions/security/x-default-scopes.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-credentials-location.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-security-body.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-security-query.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-security-secrets.js.map +0 -7
- package/dist/schemas/extensions/security/x-tokenName.js.map +0 -7
- package/dist/schemas/extensions/security/x-use-pkce.js.map +0 -7
- package/dist/schemas/extensions/server/x-scalar-selected-server.js.map +0 -7
- package/dist/schemas/extensions/tag/index.js.map +0 -7
- package/dist/schemas/extensions/tag/x-display-name.js.map +0 -7
- package/dist/schemas/extensions/tag/x-tag-groups.js.map +0 -7
- package/dist/schemas/extensions/workspace/index.js.map +0 -7
- package/dist/schemas/extensions/workspace/x-scalar-active-proxy.js.map +0 -7
- package/dist/schemas/extensions/workspace/x-scalar-tabs.js.map +0 -7
- package/dist/schemas/extensions.js.map +0 -7
- package/dist/schemas/inmemory-workspace.js.map +0 -7
- package/dist/schemas/navigation.js.map +0 -7
- package/dist/schemas/reference-config/appearance.js.map +0 -7
- package/dist/schemas/reference-config/features.js.map +0 -7
- package/dist/schemas/reference-config/index.js.map +0 -7
- package/dist/schemas/reference-config/meta.js.map +0 -7
- package/dist/schemas/reference-config/routing.js.map +0 -7
- package/dist/schemas/reference-config/settings.js.map +0 -7
- package/dist/schemas/typebox-coerce.js.map +0 -7
- package/dist/schemas/v3.1/strict/callback.js.map +0 -7
- package/dist/schemas/v3.1/strict/components.js.map +0 -7
- package/dist/schemas/v3.1/strict/contact.js.map +0 -7
- package/dist/schemas/v3.1/strict/discriminator.js.map +0 -7
- package/dist/schemas/v3.1/strict/encoding.js.map +0 -7
- package/dist/schemas/v3.1/strict/example.js.map +0 -7
- package/dist/schemas/v3.1/strict/external-documentation.js.map +0 -7
- package/dist/schemas/v3.1/strict/header.js.map +0 -7
- package/dist/schemas/v3.1/strict/info.js.map +0 -7
- package/dist/schemas/v3.1/strict/license.js.map +0 -7
- package/dist/schemas/v3.1/strict/link.js.map +0 -7
- package/dist/schemas/v3.1/strict/media-type.js.map +0 -7
- package/dist/schemas/v3.1/strict/oauth-flow.js.map +0 -7
- package/dist/schemas/v3.1/strict/oauthflows.js.map +0 -7
- package/dist/schemas/v3.1/strict/openapi-document.js.map +0 -7
- package/dist/schemas/v3.1/strict/operation.js.map +0 -7
- package/dist/schemas/v3.1/strict/parameter.js.map +0 -7
- package/dist/schemas/v3.1/strict/path-item.js.map +0 -7
- package/dist/schemas/v3.1/strict/paths.js.map +0 -7
- package/dist/schemas/v3.1/strict/ref-definitions.js.map +0 -7
- package/dist/schemas/v3.1/strict/reference.js.map +0 -7
- package/dist/schemas/v3.1/strict/request-body.js.map +0 -7
- package/dist/schemas/v3.1/strict/response.js.map +0 -7
- package/dist/schemas/v3.1/strict/responses.js.map +0 -7
- package/dist/schemas/v3.1/strict/schema.js.map +0 -7
- package/dist/schemas/v3.1/strict/security-requirement.js.map +0 -7
- package/dist/schemas/v3.1/strict/security-scheme.js.map +0 -7
- package/dist/schemas/v3.1/strict/server-variable.js.map +0 -7
- package/dist/schemas/v3.1/strict/server.js.map +0 -7
- package/dist/schemas/v3.1/strict/tag.js.map +0 -7
- package/dist/schemas/v3.1/strict/type-guards.js.map +0 -7
- package/dist/schemas/v3.1/strict/xml.js.map +0 -7
- package/dist/schemas/workspace-specification/index.js.map +0 -7
- package/dist/schemas/workspace-specification/info.js.map +0 -7
- package/dist/schemas/workspace.js.map +0 -7
- package/dist/schemas.js.map +0 -7
- package/dist/server.js.map +0 -7
- package/dist/workspace-plugin.js.map +0 -7
|
@@ -1,62 +1,93 @@
|
|
|
1
|
-
import { getResolvedRef } from
|
|
2
|
-
import { unpackProxyObject } from
|
|
1
|
+
import { getResolvedRef } from '../../helpers/get-resolved-ref.js';
|
|
2
|
+
import { unpackProxyObject } from '../../helpers/unpack-proxy.js';
|
|
3
|
+
/** Ensure the json that we need exists up to the example object in the request body */
|
|
3
4
|
const findOrCreateRequestBodyExample = (document, contentType, meta) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
const operation = getResolvedRef(document?.paths?.[meta.path]?.[meta.method]);
|
|
6
|
+
if (!operation) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
// Ensure that the request body exists
|
|
10
|
+
let requestBody = getResolvedRef(operation.requestBody);
|
|
11
|
+
if (!requestBody) {
|
|
12
|
+
operation.requestBody = {
|
|
13
|
+
content: {},
|
|
14
|
+
};
|
|
15
|
+
requestBody = getResolvedRef(operation.requestBody);
|
|
16
|
+
}
|
|
17
|
+
// Ensure that the example exists
|
|
18
|
+
requestBody.content[contentType] ||= {};
|
|
19
|
+
requestBody.content[contentType].examples ||= {};
|
|
20
|
+
requestBody.content[contentType].examples[meta.exampleKey] ||= {};
|
|
21
|
+
const example = getResolvedRef(requestBody.content[contentType].examples?.[meta.exampleKey]);
|
|
22
|
+
return example ?? null;
|
|
20
23
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Sets the selected request-body content type for the current `exampleKey`.
|
|
26
|
+
* This stores the selection under `x-scalar-selected-content-type` on the
|
|
27
|
+
* resolved requestBody. Safely no-ops if the document or operation does not exist.
|
|
28
|
+
*
|
|
29
|
+
* Example:
|
|
30
|
+
* ```ts
|
|
31
|
+
* updateOperationRequestBodyContentType({
|
|
32
|
+
* document,
|
|
33
|
+
* meta: { method: 'post', path: '/upload', exampleKey: 'default' },
|
|
34
|
+
* payload: { contentType: 'multipart/form-data' },
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const updateOperationRequestBodyContentType = (document, { meta, payload }) => {
|
|
39
|
+
if (!document) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
|
|
43
|
+
if (!operation) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let requestBody = getResolvedRef(operation.requestBody);
|
|
47
|
+
if (!requestBody) {
|
|
48
|
+
operation.requestBody = {
|
|
49
|
+
content: {},
|
|
50
|
+
};
|
|
51
|
+
requestBody = getResolvedRef(operation.requestBody);
|
|
52
|
+
}
|
|
53
|
+
if (!requestBody['x-scalar-selected-content-type']) {
|
|
54
|
+
requestBody['x-scalar-selected-content-type'] = {};
|
|
55
|
+
}
|
|
56
|
+
requestBody['x-scalar-selected-content-type'][meta.exampleKey] = payload.contentType;
|
|
40
57
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Creates or updates a concrete example value for a specific request-body
|
|
60
|
+
* `contentType` and `exampleKey`. Safely no-ops if the document or operation
|
|
61
|
+
* does not exist.
|
|
62
|
+
*
|
|
63
|
+
* Example:
|
|
64
|
+
* ```ts
|
|
65
|
+
* updateOperationRequestBodyExample({
|
|
66
|
+
* document,
|
|
67
|
+
* contentType: 'application/json',
|
|
68
|
+
* meta: { method: 'post', path: '/users', exampleKey: 'default' },
|
|
69
|
+
* payload: { value: JSON.stringify({ name: 'Ada' }) },
|
|
70
|
+
* })
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export const updateOperationRequestBodyExample = (document, { meta, payload, contentType }) => {
|
|
74
|
+
const example = findOrCreateRequestBodyExample(document, contentType, meta);
|
|
75
|
+
if (!example) {
|
|
76
|
+
console.error('Example not found', meta.exampleKey);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
example.value = payload;
|
|
48
80
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Stores the form data for the request body example
|
|
83
|
+
*
|
|
84
|
+
* This needs special handling as we store it as an array of objects with a schema type of object
|
|
85
|
+
*/
|
|
86
|
+
export const updateOperationRequestBodyFormValue = (document, { meta, payload, contentType }) => {
|
|
87
|
+
const example = findOrCreateRequestBodyExample(document, contentType, meta);
|
|
88
|
+
if (!example) {
|
|
89
|
+
console.error('Example not found', meta.exampleKey);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
example.value = unpackProxyObject(payload, { depth: 3 });
|
|
56
93
|
};
|
|
57
|
-
export {
|
|
58
|
-
updateOperationRequestBodyContentType,
|
|
59
|
-
updateOperationRequestBodyExample,
|
|
60
|
-
updateOperationRequestBodyFormValue
|
|
61
|
-
};
|
|
62
|
-
//# sourceMappingURL=body.js.map
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { getResolvedRef } from
|
|
2
|
-
import { mergeObjects } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { getResolvedRef } from '../../helpers/get-resolved-ref.js';
|
|
2
|
+
import { mergeObjects } from '../../helpers/merge-object.js';
|
|
3
|
+
/**
|
|
4
|
+
* Updates an extension of the operation
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* updateOperationExtension({
|
|
9
|
+
* document,
|
|
10
|
+
* meta: { method: 'get', path: '/users' },
|
|
11
|
+
* payload: { 'x-post-response': 'console.log(response)' },
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const updateOperationExtension = (document, { meta, payload }) => {
|
|
16
|
+
const operation = getResolvedRef(document?.paths?.[meta.path]?.[meta.method]);
|
|
17
|
+
if (!operation) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
mergeObjects(operation, payload);
|
|
9
21
|
};
|
|
10
|
-
export {
|
|
11
|
-
updateOperationExtension
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=extensions.js.map
|
|
@@ -1,117 +1,154 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Converts a Fetch API Request object to HAR (HTTP Archive) Request format.
|
|
3
|
+
*
|
|
4
|
+
* This function transforms a standard JavaScript Fetch API Request into the
|
|
5
|
+
* HAR format, which is useful for:
|
|
6
|
+
* - Recording HTTP requests for replay or analysis
|
|
7
|
+
* - Creating request fixtures from real API calls
|
|
8
|
+
* - Debugging and monitoring HTTP traffic
|
|
9
|
+
* - Storing request history in a standard format
|
|
10
|
+
* - Generating API documentation from real requests
|
|
11
|
+
*
|
|
12
|
+
* The conversion handles:
|
|
13
|
+
* - Request method and URL
|
|
14
|
+
* - Headers extraction (excluding sensitive headers if needed)
|
|
15
|
+
* - Query parameters extraction from URL
|
|
16
|
+
* - Cookie extraction from headers
|
|
17
|
+
* - Request body reading (with automatic cloning to preserve the original)
|
|
18
|
+
* - Content-Type detection and MIME type extraction
|
|
19
|
+
* - Size calculations for headers and body
|
|
20
|
+
* - Form data bodies are converted to params array
|
|
21
|
+
* - Other body types are read as text
|
|
22
|
+
*
|
|
23
|
+
* Note: The Fetch API does not expose the HTTP version, so it defaults to HTTP/1.1
|
|
24
|
+
* unless specified otherwise.
|
|
25
|
+
*
|
|
26
|
+
* @see https://w3c.github.io/web-performance/specs/HAR/Overview.html
|
|
27
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const request = new Request('https://api.example.com/users', {
|
|
31
|
+
* method: 'POST',
|
|
32
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
33
|
+
* body: JSON.stringify({ name: 'John' })
|
|
34
|
+
* })
|
|
35
|
+
* const harRequest = await fetchRequestToHar({ request })
|
|
36
|
+
* console.log(harRequest.method) // 'POST'
|
|
37
|
+
* console.log(harRequest.postData?.text) // '{"name":"John"}'
|
|
38
|
+
*/
|
|
39
|
+
export const fetchRequestToHar = async ({ request, includeBody = true, httpVersion = 'HTTP/1.1',
|
|
40
|
+
// Default to 1MB
|
|
41
|
+
bodySizeLimit = 1048576, }) => {
|
|
42
|
+
// Extract query string from URL
|
|
43
|
+
const url = new URL(request.url);
|
|
44
|
+
// Extract the query strings from the URL
|
|
45
|
+
const queryString = Array.from(url.searchParams.entries()).map(([name, value]) => ({ name, value }));
|
|
46
|
+
// Extract the headers from the request
|
|
47
|
+
const { headers, headersSize, cookies } = processRequestHeaders(request);
|
|
48
|
+
// Extract the MIME type from the request headers
|
|
49
|
+
const mimeType = request.headers.get('content-type')?.split(';')[0]?.trim() ?? 'text/plain';
|
|
50
|
+
// Read the request body if requested
|
|
51
|
+
const bodyDetails = await (async () => {
|
|
52
|
+
if (includeBody && request.body) {
|
|
53
|
+
const details = await processRequestBody(request.clone());
|
|
54
|
+
if (details.size <= bodySizeLimit) {
|
|
55
|
+
return details;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { text: '', size: -1 };
|
|
59
|
+
})();
|
|
60
|
+
// Create the HAR request object
|
|
61
|
+
const harRequest = {
|
|
62
|
+
method: request.method,
|
|
63
|
+
url: request.url,
|
|
64
|
+
httpVersion,
|
|
65
|
+
headers,
|
|
66
|
+
cookies,
|
|
67
|
+
queryString,
|
|
68
|
+
headersSize,
|
|
69
|
+
bodySize: bodyDetails.size,
|
|
70
|
+
postData: 'params' in bodyDetails
|
|
71
|
+
? {
|
|
72
|
+
mimeType,
|
|
73
|
+
params: bodyDetails.params,
|
|
74
|
+
}
|
|
75
|
+
: {
|
|
76
|
+
mimeType,
|
|
77
|
+
text: bodyDetails.text,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
return harRequest;
|
|
39
81
|
};
|
|
40
82
|
const processRequestBody = async (request) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return { size, text: new TextDecoder().decode(arrayBuffer) };
|
|
83
|
+
const formData = await tryGetRequestFormData(request.clone());
|
|
84
|
+
if (formData) {
|
|
85
|
+
return Array.from(formData.entries()).reduce((acc, [name, value]) => {
|
|
86
|
+
if (value instanceof File) {
|
|
87
|
+
const fileName = `@${value.name}`;
|
|
88
|
+
acc.params.push({ name, value: fileName });
|
|
89
|
+
acc.size += fileName.length;
|
|
90
|
+
return acc;
|
|
91
|
+
}
|
|
92
|
+
acc.params.push({ name, value });
|
|
93
|
+
acc.size += value.length;
|
|
94
|
+
return acc;
|
|
95
|
+
}, { params: [], size: 0 });
|
|
96
|
+
}
|
|
97
|
+
// Skip binary bodies
|
|
98
|
+
if (request.headers.get('content-type')?.includes('application/octet-stream')) {
|
|
99
|
+
return { text: '', size: -1 };
|
|
100
|
+
}
|
|
101
|
+
// Read the request body as text
|
|
102
|
+
const arrayBuffer = await request.arrayBuffer();
|
|
103
|
+
const size = arrayBuffer.byteLength;
|
|
104
|
+
return { size, text: new TextDecoder().decode(arrayBuffer) };
|
|
64
105
|
};
|
|
65
106
|
async function tryGetRequestFormData(request) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
107
|
+
if (typeof request.formData !== 'function') {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
if (request.bodyUsed) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const contentType = request.headers.get('content-type') ?? '';
|
|
114
|
+
if (!contentType.includes('multipart/form-data') && !contentType.includes('application/x-www-form-urlencoded')) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return await request.formData();
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
81
123
|
}
|
|
82
124
|
const processRequestHeaders = (request) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
{ headers: [], headersSize: 0, cookies: [] }
|
|
95
|
-
);
|
|
125
|
+
return Array.from(request.headers.entries()).reduce((acc, [name, value]) => {
|
|
126
|
+
if (name.toLowerCase() === 'cookie') {
|
|
127
|
+
const parsedCookies = parseCookieHeader(value);
|
|
128
|
+
acc.cookies.push(...parsedCookies.cookies);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
acc.headers.push({ name, value });
|
|
132
|
+
acc.headersSize += name.length + 2 + value.length + 2;
|
|
133
|
+
}
|
|
134
|
+
return acc;
|
|
135
|
+
}, { headers: [], headersSize: 0, cookies: [] });
|
|
96
136
|
};
|
|
137
|
+
/**
|
|
138
|
+
* Parses a Cookie header value into an array of cookie objects.
|
|
139
|
+
* Cookie format: name1=value1; name2=value2
|
|
140
|
+
*/
|
|
97
141
|
const parseCookieHeader = (cookieValue) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
142
|
+
return cookieValue.split(';').reduce((acc, part) => {
|
|
143
|
+
const trimmedPart = part.trim();
|
|
144
|
+
const equalIndex = trimmedPart.indexOf('=');
|
|
145
|
+
if (equalIndex === -1) {
|
|
146
|
+
return acc;
|
|
147
|
+
}
|
|
148
|
+
const name = trimmedPart.substring(0, equalIndex).trim();
|
|
149
|
+
const value = trimmedPart.substring(equalIndex + 1).trim();
|
|
150
|
+
acc.cookies.push({ name, value });
|
|
151
|
+
acc.size += name.length + 2 + value.length + 2;
|
|
103
152
|
return acc;
|
|
104
|
-
|
|
105
|
-
const name = trimmedPart.substring(0, equalIndex).trim();
|
|
106
|
-
const value = trimmedPart.substring(equalIndex + 1).trim();
|
|
107
|
-
acc.cookies.push({ name, value });
|
|
108
|
-
acc.size += name.length + 2 + value.length + 2;
|
|
109
|
-
return acc;
|
|
110
|
-
},
|
|
111
|
-
{ cookies: [], size: 0 }
|
|
112
|
-
);
|
|
113
|
-
};
|
|
114
|
-
export {
|
|
115
|
-
fetchRequestToHar
|
|
153
|
+
}, { cookies: [], size: 0 });
|
|
116
154
|
};
|
|
117
|
-
//# sourceMappingURL=fetch-request-to-har.js.map
|