@scalar/snippetz 0.2.9 → 0.2.10

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.
@@ -1 +1 @@
1
- {"version":3,"file":"clients.d.ts","sourceRoot":"","sources":["../src/clients.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAAM,EA6G3B,CAAA"}
1
+ {"version":3,"file":"clients.d.ts","sourceRoot":"","sources":["../src/clients.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAAM,EAmH3B,CAAA"}
package/dist/clients.js CHANGED
@@ -5,6 +5,7 @@ import { javaUnirest } from './plugins/java/unirest/unirest.js';
5
5
  import { csharpHttpclient } from './plugins/csharp/httpclient/httpclient.js';
6
6
  import { csharpRestsharp } from './plugins/csharp/restsharp/restsharp.js';
7
7
  import { clojureCljhttp } from './plugins/clojure/clj_http/clj_http.js';
8
+ import { dartHttp } from './plugins/dart/http/http.js';
8
9
  import { goNative } from './plugins/go/native/native.js';
9
10
  import { httpHttp11 } from './plugins/http/http11/http11.js';
10
11
  import { javaAsynchttp } from './plugins/java/asynchttp/asynchttp.js';
@@ -55,6 +56,12 @@ const clients = [
55
56
  default: 'clj_http',
56
57
  clients: [clojureCljhttp],
57
58
  },
59
+ {
60
+ key: 'dart',
61
+ title: 'Dart',
62
+ default: 'http',
63
+ clients: [dartHttp],
64
+ },
58
65
  {
59
66
  key: 'go',
60
67
  title: 'Go',
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '../../../types/index.js';
2
+ /**
3
+ * dart/http
4
+ */
5
+ export declare const dartHttp: Plugin;
6
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dart/http/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MA8HtB,CAAA"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * dart/http
3
+ */
4
+ const dartHttp = {
5
+ target: 'dart',
6
+ client: 'http',
7
+ title: 'Http',
8
+ generate(request, options) {
9
+ // Defaults
10
+ const normalizedRequest = {
11
+ method: 'GET',
12
+ ...request,
13
+ };
14
+ // Normalize method to uppercase
15
+ normalizedRequest.method = normalizedRequest.method.toUpperCase();
16
+ // Start building the Dart code
17
+ let code = `import 'package:http/http.dart' as http;\n\nvoid main() async {\n`;
18
+ // Handle cookies
19
+ let cookieHeader = '';
20
+ let cookieString = '';
21
+ if (normalizedRequest.cookies && normalizedRequest.cookies.length > 0) {
22
+ cookieString = normalizedRequest.cookies
23
+ .map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`)
24
+ .join('; ');
25
+ cookieHeader = ` "Cookie": "${cookieString}",\n`;
26
+ }
27
+ // Handle headers
28
+ const headers = normalizedRequest.headers?.reduce((acc, header) => {
29
+ if (header.value && !/[; ]/.test(header.name)) {
30
+ acc[header.name] = header.value;
31
+ }
32
+ return acc;
33
+ }, {}) || {};
34
+ // Add Authorization header if credentials are provided
35
+ if (options?.auth) {
36
+ const { username, password } = options.auth;
37
+ if (username && password) {
38
+ const credentials = `${username}:${password}`;
39
+ headers['Authorization'] =
40
+ `'Basic ' + base64Encode(utf8.encode('${credentials}'))`;
41
+ }
42
+ }
43
+ if (cookieHeader) {
44
+ headers['Cookie'] = cookieString;
45
+ }
46
+ if (Object.keys(headers).length > 0) {
47
+ code += ` final headers = <String,String>{\n`;
48
+ for (const [key, value] of Object.entries(headers)) {
49
+ if (value.includes('utf8.encode')) {
50
+ code += ` '${key}': ${value},\n`;
51
+ }
52
+ else {
53
+ code += ` '${key}': '${value}',\n`;
54
+ }
55
+ }
56
+ code += ` };\n\n`;
57
+ }
58
+ // Handle query string
59
+ const queryString = normalizedRequest.queryString?.length
60
+ ? '?' +
61
+ normalizedRequest.queryString
62
+ .map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value)}`)
63
+ .join('&')
64
+ : '';
65
+ const url = `${normalizedRequest.url}${queryString}`;
66
+ // Handle body
67
+ let body = '';
68
+ if (normalizedRequest.postData) {
69
+ if (normalizedRequest.postData.mimeType === 'application/json') {
70
+ body = ` final body = r'${normalizedRequest.postData.text}';\n\n`;
71
+ }
72
+ else if (normalizedRequest.postData.mimeType ===
73
+ 'application/x-www-form-urlencoded') {
74
+ body = ` final body = '${normalizedRequest.postData.params?.map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value ?? '')}`).join('&') || ''}';\n\n`;
75
+ }
76
+ else if (normalizedRequest.postData.mimeType === 'multipart/form-data') {
77
+ body = ` final body = <String,String>{\n`;
78
+ for (const param of normalizedRequest.postData.params || []) {
79
+ const value = param.value || '';
80
+ const fileName = param.fileName || '';
81
+ body += ` '${param.name}': '${fileName || value}',\n`;
82
+ }
83
+ body += ` };\n\n`;
84
+ }
85
+ else if (normalizedRequest.postData.mimeType === 'application/octet-stream') {
86
+ body = ` final body = '${normalizedRequest.postData.text}';\n\n`;
87
+ }
88
+ }
89
+ if (body) {
90
+ code += body;
91
+ }
92
+ // Handle method and request
93
+ const method = normalizedRequest.method.toLowerCase();
94
+ const headersPart = Object.keys(headers).length > 0 ? ', headers: headers' : '';
95
+ const bodyPart = body ? ', body: body' : '';
96
+ code += ` final response = await http.${method}(Uri.parse('${url}')${headersPart}${bodyPart});\n`;
97
+ code += ` print(response.body);\n`;
98
+ code += `}`;
99
+ return code;
100
+ },
101
+ };
102
+
103
+ export { dartHttp };
@@ -0,0 +1,2 @@
1
+ export * from './http.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dart/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
@@ -0,0 +1 @@
1
+ export { dartHttp } from './http.js';
@@ -6,8 +6,8 @@ export declare function snippetz(): {
6
6
  print<T extends TargetId>(target: T, client: ClientId<T>, request: Partial<HarRequest>): string | undefined;
7
7
  clients(): import("./types/index.js").Target[];
8
8
  plugins(): {
9
- target: "c" | "clojure" | "csharp" | "go" | "http" | "java" | "js" | "kotlin" | "node" | "objc" | "ocaml" | "php" | "powershell" | "python" | "r" | "ruby" | "shell" | "swift";
10
- client: "libcurl" | "clj_http" | "httpclient" | "restsharp" | "native" | "http1.1" | "asynchttp" | "nethttp" | "okhttp" | "unirest" | "axios" | "fetch" | "jquery" | "ofetch" | "xhr" | "undici" | "nsurlsession" | "cohttp" | "curl" | "guzzle" | "restmethod" | "webrequest" | "python3" | "requests" | "httr" | "httpie" | "wget";
9
+ target: "c" | "clojure" | "csharp" | "go" | "http" | "java" | "js" | "kotlin" | "node" | "objc" | "ocaml" | "php" | "powershell" | "python" | "r" | "ruby" | "shell" | "swift" | "dart";
10
+ client: "libcurl" | "clj_http" | "httpclient" | "restsharp" | "native" | "http" | "http1.1" | "asynchttp" | "nethttp" | "okhttp" | "unirest" | "axios" | "fetch" | "jquery" | "ofetch" | "xhr" | "undici" | "nsurlsession" | "cohttp" | "curl" | "guzzle" | "restmethod" | "webrequest" | "python3" | "requests" | "httr" | "httpie" | "wget";
11
11
  }[];
12
12
  findPlugin<T extends TargetId>(target: T | string, client: ClientId<T> | string): import("./types/index.js").Plugin | undefined;
13
13
  hasPlugin<T extends TargetId>(target: T | string, client: ClientId<T> | string): boolean;
@@ -37,7 +37,8 @@ export type AvailableClients = [
37
37
  'shell/curl',
38
38
  'shell/httpie',
39
39
  'shell/wget',
40
- 'swift/nsurlsession'
40
+ 'swift/nsurlsession',
41
+ 'dart/http'
41
42
  ];
42
43
  /** Programming language */
43
44
  export type TargetId = AvailableClients[number] extends `${infer T}/${string}` ? T : never;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvD,YAAY,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW;IACX,kBAAkB;IAClB,mBAAmB;IACnB,kBAAkB;IAClB,WAAW;IACX,cAAc;IACd,gBAAgB;IAChB,cAAc;IACd,aAAa;IACb,cAAc;IACd,UAAU;IACV,UAAU;IACV,WAAW;IACX,WAAW;IACX,QAAQ;IACR,eAAe;IACf,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,aAAa;IACb,mBAAmB;IACnB,cAAc;IACd,UAAU;IACV,YAAY;IACZ,uBAAuB;IACvB,uBAAuB;IACvB,gBAAgB;IAChB,iBAAiB;IACjB,QAAQ;IACR,aAAa;IACb,YAAY;IACZ,cAAc;IACd,YAAY;IACZ,oBAAoB;CACrB,CAAA;AAED,2BAA2B;AAC3B,MAAM,MAAM,QAAQ,GAAG,gBAAgB,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,MAAM,EAAE,GAC1E,CAAC,GACD,KAAK,CAAA;AAET,iCAAiC;AACjC,MAAM,MAAM,MAAM,GAAG;KAClB,CAAC,IAAI,QAAQ,GAAG;QACf,GAAG,EAAE,CAAC,CAAA;QACN,KAAK,EAAE,MAAM,CAAA;QACb,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;QACpB,OAAO,EAAE,MAAM,EAAE,CAAA;KAClB;CACF,CAAC,QAAQ,CAAC,CAAA;AAEX,kBAAkB;AAClB,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,QAAQ,GACvD,OAAO,CACL,gBAAgB,CAAC,MAAM,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CAAA;KAAE,CAAA;CAC9C,CAAA"}
package/package.json CHANGED
@@ -6,10 +6,10 @@
6
6
  "bugs": "https://github.com/scalar/scalar/issues/new/choose",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/scalar/scalar.git",
9
+ "url": "git+https://github.com/scalar/scalar.git",
10
10
  "directory": "packages/snippetz"
11
11
  },
12
- "version": "0.2.9",
12
+ "version": "0.2.10",
13
13
  "engines": {
14
14
  "node": ">=18"
15
15
  },
@@ -181,6 +181,11 @@
181
181
  "types": "./dist/plugins/go/native/index.d.ts",
182
182
  "default": "./dist/plugins/go/native/index.js"
183
183
  },
184
+ "./plugins/dart/http": {
185
+ "import": "./dist/plugins/dart/http/index.js",
186
+ "types": "./dist/plugins/dart/http/index.d.ts",
187
+ "default": "./dist/plugins/dart/http/index.js"
188
+ },
184
189
  "./plugins/csharp/restsharp": {
185
190
  "import": "./dist/plugins/csharp/restsharp/index.js",
186
191
  "types": "./dist/plugins/csharp/restsharp/index.d.ts",