@cfworker/cosmos 1.13.1 → 1.13.4

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/dist/client.js CHANGED
@@ -180,7 +180,7 @@ export class CosmosClient {
180
180
  };
181
181
  }
182
182
  async fetchWithRetry(request, context) {
183
- const retryRequest = request.clone();
183
+ const retryRequest = new Request(request.url, request);
184
184
  const response = await this.fetch(request);
185
185
  context ??= { attempts: 0, cumulativeWaitMs: 0, request, response };
186
186
  context.attempts++;
package/dist/signer.js CHANGED
@@ -1,15 +1,15 @@
1
- import { decode as base64ToArrayBuffer, encode as arrayBufferToBase64 } from 'base64-arraybuffer';
1
+ import { base64 } from 'rfc4648';
2
2
  export class Signer {
3
3
  constructor(masterkey) {
4
4
  this.encoder = new TextEncoder();
5
- const promiseLike = crypto.subtle.importKey('raw', base64ToArrayBuffer(masterkey), { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']);
5
+ const promiseLike = crypto.subtle.importKey('raw', base64.parse(masterkey), { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']);
6
6
  this.masterkey = Promise.resolve(promiseLike);
7
7
  }
8
8
  async sign(request, date = new Date()) {
9
9
  const key = await this.masterkey;
10
10
  const payload = this.getPayload(request, date);
11
11
  const hashed = await crypto.subtle.sign('HMAC', key, payload);
12
- const signature = arrayBufferToBase64(hashed);
12
+ const signature = base64.stringify(new Uint8Array(hashed));
13
13
  request.headers.set('authorization', encodeURIComponent(`type=master&ver=1.0&sig=${signature}`));
14
14
  request.headers.set('x-ms-date', date.toUTCString());
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfworker/cosmos",
3
- "version": "1.13.1",
3
+ "version": "1.13.4",
4
4
  "description": "Azure Cosmos DB client for Cloudflare Workers and service workers",
5
5
  "keywords": [
6
6
  "azure",
@@ -37,16 +37,16 @@
37
37
  "test": "cfworker test test/**/*.spec.ts"
38
38
  },
39
39
  "dependencies": {
40
- "@cfworker/worker-types": "^1.12.1",
40
+ "@cfworker/worker-types": "^1.12.2",
41
41
  "@cloudflare/workers-types": "^2.2.2",
42
- "base64-arraybuffer": "^1.0.2"
42
+ "rfc4648": "^1.5.2"
43
43
  },
44
44
  "devDependencies": {
45
- "@cfworker/dev": "^1.14.0",
46
- "@types/chai": "^4.3.0",
47
- "@types/mocha": "^9.1.0",
45
+ "@cfworker/dev": "^1.14.1",
46
+ "@types/chai": "^4.3.3",
47
+ "@types/mocha": "^9.1.1",
48
48
  "chai": "^4.3.6",
49
- "mocha": "^9.2.1",
50
- "typescript": "^4.5.5"
49
+ "mocha": "^10.0.0",
50
+ "typescript": "^4.7.4"
51
51
  }
52
52
  }
package/src/client.ts CHANGED
@@ -330,7 +330,7 @@ export class CosmosClient {
330
330
  request: Request,
331
331
  context?: RetryContext
332
332
  ): Promise<Response> {
333
- const retryRequest = request.clone();
333
+ const retryRequest = new Request(request.url, request);
334
334
 
335
335
  const response = await this.fetch(request);
336
336
 
package/src/signer.ts CHANGED
@@ -1,7 +1,4 @@
1
- import {
2
- decode as base64ToArrayBuffer,
3
- encode as arrayBufferToBase64
4
- } from 'base64-arraybuffer';
1
+ import { base64 } from 'rfc4648';
5
2
 
6
3
  export class Signer {
7
4
  private readonly masterkey: Promise<CryptoKey>;
@@ -10,7 +7,7 @@ export class Signer {
10
7
  constructor(masterkey: string) {
11
8
  const promiseLike = crypto.subtle.importKey(
12
9
  'raw',
13
- base64ToArrayBuffer(masterkey),
10
+ base64.parse(masterkey),
14
11
  { name: 'HMAC', hash: { name: 'SHA-256' } },
15
12
  false,
16
13
  ['sign']
@@ -22,7 +19,7 @@ export class Signer {
22
19
  const key = await this.masterkey;
23
20
  const payload = this.getPayload(request, date);
24
21
  const hashed = await crypto.subtle.sign('HMAC', key, payload);
25
- const signature = arrayBufferToBase64(hashed);
22
+ const signature = base64.stringify(new Uint8Array(hashed));
26
23
  request.headers.set(
27
24
  'authorization',
28
25
  encodeURIComponent(`type=master&ver=1.0&sig=${signature}`)