@scalar/oas-utils 0.12.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @scalar/oas-utils
2
2
 
3
+ ## 0.13.1
4
+
5
+ ## 0.13.0
6
+
7
+ ### Minor Changes
8
+
9
+ - [#8865](https://github.com/scalar/scalar/pull/8865): feat: add plugin support for custom response body content types
10
+
11
+ ### Patch Changes
12
+
13
+ - [#8810](https://github.com/scalar/scalar/pull/8810): refactor: move telemetry to an optional plugin
14
+
3
15
  ## 0.12.0
4
16
 
5
17
  ### Minor Changes
@@ -2,7 +2,33 @@ import type { ApiReferenceEvents } from '@scalar/workspace-store/events';
2
2
  import type { RequestFactory, VariablesStore } from '@scalar/workspace-store/request-example';
3
3
  import type { OpenApiDocument } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
4
4
  import type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/operation';
5
- import type { DefineComponent } from 'vue';
5
+ import type { Component, DefineComponent } from 'vue';
6
+ /** Shared fields present on every response body handler variant */
7
+ type ResponseBodyHandlerBase = {
8
+ /** MIME type patterns this handler matches (exact or glob like "application/vnd.*+json") */
9
+ mimeTypes: string[];
10
+ /** Custom decoder: transform raw bytes into displayable data */
11
+ decode?: (buffer: ArrayBuffer, contentType: string) => string | Blob | Promise<string | Blob>;
12
+ /** Custom component for the preview view */
13
+ previewComponent?: Component;
14
+ };
15
+ /**
16
+ * Describes how a plugin handles a specific content type in the response body.
17
+ *
18
+ * The raw view is configured with either:
19
+ * - `rawComponent`: A custom Vue component (receives `content` and `contentType` props).
20
+ * - `language`: A CodeMirror language hint for the built-in raw renderer.
21
+ *
22
+ * These two options are mutually exclusive — providing `rawComponent` means the
23
+ * built-in renderer is not used, so `language` would have no effect.
24
+ */
25
+ export type ResponseBodyHandler = ResponseBodyHandlerBase & ({
26
+ rawComponent: Component;
27
+ language?: never;
28
+ } | {
29
+ rawComponent?: never;
30
+ language?: string;
31
+ });
6
32
  /** A type representing the hooks that a client plugin can define */
7
33
  type ClientPluginHooks = {
8
34
  beforeRequest: (payload: {
@@ -58,12 +84,41 @@ type ClientPluginComponents = {
58
84
  * components: {
59
85
  * request: MyRequestComponent, // Custom Vue component for rendering the request section
60
86
  * response: MyResponseComponent // Custom Vue component for rendering the response section
61
- * }
87
+ * },
88
+ * responseBody: [{
89
+ * mimeTypes: ['application/msgpack', 'application/x-msgpack'],
90
+ * decode: (buffer) => {
91
+ * const decoded = msgpack.decode(new Uint8Array(buffer));
92
+ * return JSON.stringify(decoded, null, 2);
93
+ * },
94
+ * language: 'json',
95
+ * }]
62
96
  * }
63
97
  */
98
+ /** Lifecycle hooks for app-level plugin concerns (analytics, logging, etc.) */
99
+ type ClientPluginLifecycle = {
100
+ /** Called when the API client is initialized */
101
+ onInit?: (context?: {
102
+ config: Record<string, unknown>;
103
+ }) => void;
104
+ /** Called when the API client configuration changes */
105
+ onConfigChange?: (context: {
106
+ config: Record<string, unknown>;
107
+ }) => void;
108
+ /** Called when the API client is destroyed */
109
+ onDestroy?: () => void;
110
+ };
64
111
  export type ClientPlugin = {
65
112
  hooks?: Partial<ClientPluginHooks>;
66
113
  components?: Partial<ClientPluginComponents>;
114
+ /** Lifecycle hooks for app-level concerns */
115
+ lifecycle?: ClientPluginLifecycle;
116
+ /** Subscribe to event bus events. The framework handles subscribe/unsubscribe automatically. */
117
+ on?: Partial<{
118
+ [K in keyof ApiReferenceEvents]: (payload: ApiReferenceEvents[K]) => void;
119
+ }>;
120
+ /** Custom response body handlers for specific content types */
121
+ responseBody?: ResponseBodyHandler[];
67
122
  };
68
123
  /**
69
124
  * Maps hook names to their expected payload types.
@@ -1 +1 @@
1
- {"version":3,"file":"client-plugins.d.ts","sourceRoot":"","sources":["../../src/helpers/client-plugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAg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CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAClC,UAAU,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAA;IAC5C,6CAA6C;IAC7C,SAAS,CAAC,EAAE,qBAAqB,CAAA;IACjC,gGAAgG;IAChG,EAAE,CAAC,EAAE,OAAO,CAAC;SAAG,CAAC,IAAI,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,IAAI;KAAE,CAAC,CAAA;IAC3F,+DAA+D;IAC/D,YAAY,CAAC,EAAE,mBAAmB,EAAE,CAAA;CACrC,CAAA;AAED;;;;GAIG;AACH,KAAK,cAAc,GAAG;KACnB,CAAC,IAAI,MAAM,iBAAiB,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACpE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAU,CAAC,SAAS,MAAM,cAAc,EAC9D,SAAS,cAAc,CAAC,CAAC,CAAC,EAC1B,UAAU,CAAC,EACX,SAAS,YAAY,EAAE,KACtB,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAY3B,CAAA"}
@@ -1,3 +1,3 @@
1
- export { type ClientPlugin, executeHook } from './client-plugins.js';
1
+ export { type ClientPlugin, type ResponseBodyHandler, executeHook } from './client-plugins.js';
2
2
  export { formatJsonOrYamlString, json, parseJsonOrYaml, transformToJson, yaml } from './parse.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC3F,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA"}
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "specification",
17
17
  "yaml"
18
18
  ],
19
- "version": "0.12.0",
19
+ "version": "0.13.1",
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
@@ -44,10 +44,10 @@
44
44
  "github-slugger": "2.0.0",
45
45
  "vue": "^3.5.30",
46
46
  "yaml": "^2.8.0",
47
- "@scalar/helpers": "0.5.0",
47
+ "@scalar/helpers": "0.5.1",
48
48
  "@scalar/themes": "0.15.3",
49
- "@scalar/workspace-store": "0.46.0",
50
- "@scalar/types": "0.9.0"
49
+ "@scalar/types": "0.9.1",
50
+ "@scalar/workspace-store": "0.46.2"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "^24.1.0",