@scalar/blocks 0.7.0 → 0.7.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 +6 -0
- package/dist/code-example/helpers/get-snippet.d.ts +1 -1
- package/dist/code-example/helpers/get-snippet.d.ts.map +1 -1
- package/dist/code-example/helpers/get-snippet.js +3 -4
- package/dist/code-example/helpers/get-snippet.js.map +1 -1
- package/dist/constants.js +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -4,5 +4,5 @@ import type { Request as HarRequest } from 'har-format';
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns a code example for given operation
|
|
6
6
|
*/
|
|
7
|
-
export declare const getSnippet: <T extends TargetId>(target: T
|
|
7
|
+
export declare const getSnippet: <T extends TargetId>(target: T, client: ClientId<T>, harRequest: HarRequest) => ErrorResponse<string>;
|
|
8
8
|
//# sourceMappingURL=get-snippet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-snippet.d.ts","sourceRoot":"","sources":["../../../src/code-example/helpers/get-snippet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAY,MAAM,kBAAkB,CAAA;AACzE,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAKvD;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,QAAQ,EAC3C,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"get-snippet.d.ts","sourceRoot":"","sources":["../../../src/code-example/helpers/get-snippet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAY,MAAM,kBAAkB,CAAA;AACzE,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAKvD;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,QAAQ,EAC3C,QAAQ,CAAC,EACT,QAAQ,QAAQ,CAAC,CAAC,CAAC,EACnB,YAAY,UAAU,KACrB,aAAa,CAAC,MAAM,CAsCtB,CAAA"}
|
|
@@ -14,10 +14,9 @@ var t = "ws://replace.me", n = (n, r, i) => {
|
|
|
14
14
|
} catch (e) {
|
|
15
15
|
return console.error("[getSnippet] Invalid JSON body", e), [/* @__PURE__ */ Error("Invalid JSON body"), null];
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return n ? [null, n.replace(`${t}${a}`, "")] : [/* @__PURE__ */ Error("Error generating snippet"), null];
|
|
17
|
+
if (e().hasPlugin(n, r)) {
|
|
18
|
+
let o = e().print(n, r, i);
|
|
19
|
+
return o ? [null, o.replace(`${t}${a}`, "")] : [/* @__PURE__ */ Error("Error generating snippet"), null];
|
|
21
20
|
}
|
|
22
21
|
} catch (e) {
|
|
23
22
|
return console.error("[getSnippet] Error generating snippet", e), [/* @__PURE__ */ Error("Error generating snippet"), null];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-snippet.js","names":["INVALID_URLS_PREFIX","getSnippet","harRequest","separator","error","
|
|
1
|
+
{"version":3,"file":"get-snippet.js","names":["INVALID_URLS_PREFIX","getSnippet","harRequest","separator","error","snippetz","target","client","payload"],"sources":["../../../src/code-example/helpers/get-snippet.ts"],"sourcesContent":["import type { ErrorResponse } from '@scalar/helpers/errors/normalize-error'\nimport { type ClientId, type TargetId, snippetz } from '@scalar/snippetz'\nimport type { Request as HarRequest } from 'har-format'\n\n/** Key used to hack around the invalid urls */\nconst INVALID_URLS_PREFIX = 'ws://replace.me'\n\n/**\n * Returns a code example for given operation\n */\nexport const getSnippet = <T extends TargetId>(\n target: T,\n client: ClientId<T>,\n harRequest: HarRequest,\n): ErrorResponse<string> => {\n try {\n if (!harRequest.url) {\n return [new Error('Please enter a URL to see a code snippet'), null]\n }\n\n const separator = harRequest.url.startsWith('/') ? '' : '/'\n\n // Hack to get around invalid URLS until we update the snippets lib\n try {\n new URL(harRequest.url)\n } catch {\n harRequest.url = `${INVALID_URLS_PREFIX}${separator}${harRequest.url}`\n }\n\n // Ensure we have valid JSON\n if (harRequest.postData?.mimeType === 'application/json') {\n try {\n JSON.parse(harRequest.postData.text || '{}')\n } catch (error) {\n console.error('[getSnippet] Invalid JSON body', error)\n return [new Error('Invalid JSON body'), null]\n }\n }\n if (snippetz().hasPlugin(target, client)) {\n const payload = snippetz().print(target, client, harRequest)\n if (!payload) {\n return [new Error('Error generating snippet'), null]\n }\n\n return [null, payload.replace(`${INVALID_URLS_PREFIX}${separator}`, '')]\n }\n } catch (error) {\n console.error('[getSnippet] Error generating snippet', error)\n return [new Error('Error generating snippet'), null]\n }\n\n return [new Error('No snippet found'), null]\n}\n"],"mappings":";;AAKA,IAAMA,IAAsB,mBAKfC,KACX,GACA,GACA,MAC0B;CAC1B,IAAI;EACF,IAAI,CAACC,EAAW,KACd,OAAO,CAAC,gBAAI,MAAM,0CAA0C,GAAG,IAAI;EAGrE,IAAMC,IAAYD,EAAW,IAAI,WAAW,GAAG,IAAI,KAAK;EAGxD,IAAI;GACF,IAAI,IAAIA,EAAW,GAAG;EACxB,QAAQ;GACN,EAAW,MAAM,GAAGF,IAAsBG,IAAYD,EAAW;EACnE;EAGA,IAAIA,EAAW,UAAU,aAAa,oBACpC,IAAI;GACF,KAAK,MAAMA,EAAW,SAAS,QAAQ,IAAI;EAC7C,SAASE,GAAO;GAEd,OADA,QAAQ,MAAM,kCAAkCA,CAAK,GAC9C,CAAC,gBAAI,MAAM,mBAAmB,GAAG,IAAI;EAC9C;EAEF,IAAIC,EAAS,CAAC,CAAC,UAAUC,GAAQC,CAAM,GAAG;GACxC,IAAMC,IAAUH,EAAS,CAAC,CAAC,MAAMC,GAAQC,GAAQL,CAAU;GAK3D,OAJKM,IAIE,CAAC,MAAMA,EAAQ,QAAQ,GAAGR,IAAsBG,KAAa,EAAE,CAAC,IAH9D,CAAC,gBAAI,MAAM,0BAA0B,GAAG,IAAI;EAIvD;CACF,SAASC,GAAO;EAEd,OADA,QAAQ,MAAM,yCAAyCA,CAAK,GACrD,CAAC,gBAAI,MAAM,0BAA0B,GAAG,IAAI;CACrD;CAEA,OAAO,CAAC,gBAAI,MAAM,kBAAkB,GAAG,IAAI;AAC7C"}
|
package/dist/constants.js
CHANGED
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"blocks",
|
|
18
18
|
"docs"
|
|
19
19
|
],
|
|
20
|
-
"version": "0.7.
|
|
20
|
+
"version": "0.7.1",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=22"
|
|
23
23
|
},
|
|
@@ -62,15 +62,15 @@
|
|
|
62
62
|
"CHANGELOG.md"
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@scalar/components": "0.34.
|
|
66
|
-
"@scalar/helpers": "0.
|
|
65
|
+
"@scalar/components": "0.34.1",
|
|
66
|
+
"@scalar/helpers": "0.18.0",
|
|
67
67
|
"@scalar/icons": "0.7.8",
|
|
68
|
-
"@scalar/localization": "0.2.
|
|
69
|
-
"@scalar/snippetz": "0.10.
|
|
68
|
+
"@scalar/localization": "0.2.12",
|
|
69
|
+
"@scalar/snippetz": "0.10.17",
|
|
70
70
|
"@scalar/themes": "0.20.0",
|
|
71
|
-
"@scalar/types": "0.28.
|
|
72
|
-
"@scalar/use-hooks": "0.4.
|
|
73
|
-
"@scalar/workspace-store": "0.71.
|
|
71
|
+
"@scalar/types": "0.28.1",
|
|
72
|
+
"@scalar/use-hooks": "0.4.25",
|
|
73
|
+
"@scalar/workspace-store": "0.71.1",
|
|
74
74
|
"@types/har-format": "^1.2.16",
|
|
75
75
|
"@vueuse/core": "15.0.0",
|
|
76
76
|
"js-base64": "^3.9.4",
|