@taskcluster/client-web 100.4.0 → 100.5.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taskcluster/client-web",
3
- "version": "100.4.0",
3
+ "version": "100.5.0",
4
4
  "main": "src/index.js",
5
5
  "author": "Eli Perelman <eli@eliperelman.com>",
6
6
  "license": "MPL-2.0",
@@ -9,31 +9,23 @@
9
9
  "src"
10
10
  ],
11
11
  "scripts": {
12
- "lint": "eslint src/*.js test/*.js",
13
- "test": "NODE_OPTIONS='--openssl-legacy-provider --network-family-autoselection=false' karma start --single-run"
12
+ "lint": "biome check",
13
+ "lint:fix": "biome check --write",
14
+ "format": "biome format --write",
15
+ "test": "vitest run"
14
16
  },
15
17
  "devDependencies": {
16
- "@babel/core": "^7.29.7",
17
- "chai": "^6.2.2",
18
- "chai-as-promised": "^8.0.2",
19
- "crypto-js": "^4.2.0",
20
- "eslint": "^10.3.0",
21
- "karma": "^6.4.4",
22
- "karma-cli": "^2.0.0",
23
- "karma-coverage": "^2.2.1",
24
- "karma-firefox-launcher": "^2.1.3",
25
- "karma-mocha": "^2.0.1",
26
- "karma-mocha-reporter": "^2.2.5",
27
- "karma-sourcemap-loader": "^0.4.0",
28
- "karma-webpack": "^4.0.2",
29
- "query-string": "^7.0.0",
30
- "webpack": "^4.47.0",
31
- "webpack-cli": "^7.0.2"
18
+ "@biomejs/biome": "^2.4.15",
19
+ "@vitest/browser": "^4.1.9",
20
+ "@vitest/browser-playwright": "^4.1.9",
21
+ "playwright": "1.60.0",
22
+ "vite-plugin-node-polyfills": "^0.28.0",
23
+ "vitest": "^4.1.9"
32
24
  },
33
25
  "dependencies": {
34
26
  "crypto-js": "^4.2.0",
35
27
  "hawk": "^9.0.2",
36
- "query-string": "^7.0.0",
28
+ "query-string": "^9.0.0",
37
29
  "taskcluster-lib-urls": "^13.0.2"
38
30
  },
39
31
  "publishConfig": {
package/src/Client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { withRootUrl } from 'taskcluster-lib-urls';
2
- import { stringify } from 'query-string';
2
+ import queryString from 'query-string';
3
3
  import hawk from 'hawk';
4
4
  import fetch from './fetch';
5
5
 
@@ -28,17 +28,12 @@ export default class Client {
28
28
  throw new Error('Missing required option "rootUrl"');
29
29
  }
30
30
 
31
- if (
32
- this.options.randomizationFactor < 0 ||
33
- this.options.randomizationFactor >= 1
34
- ) {
31
+ if (this.options.randomizationFactor < 0 || this.options.randomizationFactor >= 1) {
35
32
  throw new Error('options.randomizationFactor must be between 0 and 1');
36
33
  }
37
34
 
38
35
  if (this.options.accessToken) {
39
- throw new Error(
40
- 'options.accessToken is no longer supported; use options.credentials',
41
- );
36
+ throw new Error('options.accessToken is no longer supported; use options.credentials');
42
37
  }
43
38
 
44
39
  const { reference } = options;
@@ -59,8 +54,7 @@ export default class Client {
59
54
  if (reference.entries) {
60
55
  reference.entries.forEach(entry => {
61
56
  if (entry.type === 'function') {
62
- // eslint-disable-next-line func-names
63
- this[entry.name] = function(...args) {
57
+ this[entry.name] = function (...args) {
64
58
  this.validate(entry, args);
65
59
 
66
60
  return this.request(entry, args);
@@ -70,8 +64,7 @@ export default class Client {
70
64
  }
71
65
 
72
66
  if (entry.type === 'topic-exchange') {
73
- // eslint-disable-next-line func-names
74
- this[entry.name] = function(pattern) {
67
+ this[entry.name] = function (pattern) {
75
68
  return this.normalizePattern(entry, pattern);
76
69
  };
77
70
  }
@@ -90,7 +83,6 @@ export default class Client {
90
83
  return input ? args.length + 1 : args.length;
91
84
  }
92
85
 
93
- /* eslint-disable consistent-return */
94
86
  buildExtraData(credentials) {
95
87
  if (!credentials) {
96
88
  return;
@@ -108,8 +100,7 @@ export default class Client {
108
100
  // If there is a certificate we have temporary credentials, and we
109
101
  // must provide the certificate
110
102
  if (certificate) {
111
- extra.certificate =
112
- typeof certificate === 'string' ? JSON.parse(certificate) : certificate;
103
+ extra.certificate = typeof certificate === 'string' ? JSON.parse(certificate) : certificate;
113
104
  }
114
105
 
115
106
  // If set of authorized scopes is provided, we'll restrict the request
@@ -123,7 +114,6 @@ export default class Client {
123
114
  return window.btoa(JSON.stringify(extra));
124
115
  }
125
116
  }
126
- /* eslint-enable consistent-return */
127
117
 
128
118
  buildEndpoint(entry, args) {
129
119
  return entry.route.replace(/<([^<>]+)>/g, (text, arg) => {
@@ -138,9 +128,7 @@ export default class Client {
138
128
  const type = typeof param;
139
129
 
140
130
  if (type !== 'string' && type !== 'number') {
141
- throw new Error(
142
- `URL parameter \`${arg}\` expected a string but was provided type "${type}"`,
143
- );
131
+ throw new Error(`URL parameter \`${arg}\` expected a string but was provided type "${type}"`);
144
132
  }
145
133
 
146
134
  return encodeURIComponent(param);
@@ -155,10 +143,10 @@ export default class Client {
155
143
  // Find the method
156
144
  const { entry } = method;
157
145
 
146
+ // TODO: use optional chaining once this package is no longer parsed by webpack 4
147
+ // biome-ignore lint/complexity/useOptionalChain: optional chaining is not supported by webpack 4
158
148
  if (!entry || entry.type !== 'function') {
159
- throw new Error(
160
- 'Method in buildUrl must be an API method from the same object',
161
- );
149
+ throw new Error('Method in buildUrl must be an API method from the same object');
162
150
  }
163
151
 
164
152
  // Get the query string options taken
@@ -166,13 +154,9 @@ export default class Client {
166
154
  const supportsOptions = optionKeys.length !== 0;
167
155
  const arity = entry.args.length;
168
156
 
169
- if (
170
- args.length !== arity &&
171
- (!supportsOptions || args.length !== arity + 1)
172
- ) {
157
+ if (args.length !== arity && (!supportsOptions || args.length !== arity + 1)) {
173
158
  throw new Error(
174
- `Method \`${entry.name}.buildUrl\` expected ${arity +
175
- 1} argument(s) but received ${args.length + 1}`,
159
+ `Method \`${entry.name}.buildUrl\` expected ${arity + 1} argument(s) but received ${args.length + 1}`
176
160
  );
177
161
  }
178
162
 
@@ -181,22 +165,18 @@ export default class Client {
181
165
  if (args[arity]) {
182
166
  Object.keys(args[arity]).forEach(key => {
183
167
  if (!optionKeys.includes(key)) {
184
- throw new Error(
185
- `Method \`${entry.name}\` expected options ${optionKeys.join(
186
- ', ',
187
- )} but received ${key}`,
188
- );
168
+ throw new Error(`Method \`${entry.name}\` expected options ${optionKeys.join(', ')} but received ${key}`);
189
169
  }
190
170
  });
191
171
  }
192
172
 
193
- const queryArgs = args[arity] && stringify(args[arity]);
173
+ const queryArgs = args[arity] && queryString.stringify(args[arity]);
194
174
  const query = queryArgs ? `?${queryArgs}` : '';
195
175
 
196
176
  return withRootUrl(this.options.rootUrl).api(
197
177
  this.options.serviceName,
198
178
  this.options.serviceVersion,
199
- `${endpoint}${query}`,
179
+ `${endpoint}${query}`
200
180
  );
201
181
  }
202
182
 
@@ -238,7 +218,6 @@ export default class Client {
238
218
  const options = args.pop();
239
219
 
240
220
  if (options.expiration) {
241
- // eslint-disable-next-line prefer-destructuring
242
221
  expiration = options.expiration;
243
222
  }
244
223
 
@@ -260,9 +239,7 @@ export default class Client {
260
239
  }
261
240
 
262
241
  if (!accessToken) {
263
- throw new Error(
264
- 'buildSignedUrl missing required credentials accessToken',
265
- );
242
+ throw new Error('buildSignedUrl missing required credentials accessToken');
266
243
  }
267
244
 
268
245
  const bewit = hawk.uri.getBewit(url, {
@@ -275,9 +252,7 @@ export default class Client {
275
252
  ext: this.buildExtraData(credentials),
276
253
  });
277
254
 
278
- return url.includes('?')
279
- ? `${url}&bewit=${bewit}`
280
- : `${url}?bewit=${bewit}`;
255
+ return url.includes('?') ? `${url}&bewit=${bewit}` : `${url}?bewit=${bewit}`;
281
256
  }
282
257
 
283
258
  validate(entry, args = []) {
@@ -285,15 +260,8 @@ export default class Client {
285
260
  const queryOptions = entry.query || [];
286
261
  const arity = args.length;
287
262
 
288
- if (
289
- arity !== expectedArity &&
290
- (queryOptions.length === 0 || arity !== expectedArity + 1)
291
- ) {
292
- throw new Error(
293
- `${
294
- entry.name
295
- } expected ${expectedArity} arguments but only received ${arity}`,
296
- );
263
+ if (arity !== expectedArity && (queryOptions.length === 0 || arity !== expectedArity + 1)) {
264
+ throw new Error(`${entry.name} expected ${expectedArity} arguments but only received ${arity}`);
297
265
  }
298
266
 
299
267
  Object.keys(args[expectedArity] || {}).forEach(key => {
@@ -322,9 +290,7 @@ export default class Client {
322
290
  if (typeof value === 'string') {
323
291
  if (value.includes('.') && !key.multipleWords) {
324
292
  throw new Error(
325
- `routingKeyPattern "${value}" for ${
326
- key.name
327
- } cannot contain dots since it does not hold multiple words`,
293
+ `routingKeyPattern "${value}" for ${key.name} cannot contain dots since it does not hold multiple words`
328
294
  );
329
295
  }
330
296
 
@@ -332,9 +298,7 @@ export default class Client {
332
298
  }
333
299
 
334
300
  if (value != null) {
335
- throw new Error(
336
- `routingKey value "${value}" is not a valid pattern for ${key.name}`,
337
- );
301
+ throw new Error(`routingKey value "${value}" is not a valid pattern for ${key.name}`);
338
302
  }
339
303
 
340
304
  return key.multipleWords ? '#' : '*';
@@ -351,13 +315,11 @@ export default class Client {
351
315
  async request(entry, args) {
352
316
  const expectedArity = this.getMethodExpectedArity(entry);
353
317
  const endpoint = this.buildEndpoint(entry, args);
354
- const query = args[expectedArity]
355
- ? `?${stringify(args[expectedArity])}`
356
- : '';
318
+ const query = args[expectedArity] ? `?${queryString.stringify(args[expectedArity])}` : '';
357
319
  const url = withRootUrl(this.options.rootUrl).api(
358
320
  this.options.serviceName,
359
321
  this.options.serviceVersion,
360
- `${endpoint}${query}`,
322
+ `${endpoint}${query}`
361
323
  );
362
324
  const options = { method: entry.method };
363
325
  const credentials = this.options.credentialAgent
@@ -377,7 +339,7 @@ export default class Client {
377
339
  }
378
340
  }
379
341
 
380
- Client.create = (reference) =>
342
+ Client.create = reference =>
381
343
  class extends Client {
382
344
  constructor(options) {
383
345
  super({ ...options, reference });