@cfworker/cosmos 1.13.0 → 1.13.3

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
@@ -7,14 +7,14 @@ export class CosmosClient {
7
7
  constructor(config) {
8
8
  this.requestCharges = 0;
9
9
  this.retries = { count: 0, delayMs: 0 };
10
- let { endpoint, accountKey } = 'connectionString' in config
10
+ let { endpoint, masterKey } = 'connectionString' in config
11
11
  ? parseConnectionString(config.connectionString)
12
12
  : config;
13
13
  if (endpoint.endsWith('/')) {
14
14
  endpoint = endpoint.slice(0, -1);
15
15
  }
16
16
  this.endpoint = endpoint;
17
- this.signer = getSigner(accountKey);
17
+ this.signer = getSigner(masterKey);
18
18
  this.retryPolicy = config.retryPolicy ?? defaultRetryPolicy;
19
19
  this.consistencyLevel = config.consistencyLevel ?? 'Session';
20
20
  this.dbId = config.dbId;
@@ -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.d.ts CHANGED
@@ -9,4 +9,4 @@ export declare class Signer {
9
9
  resourceId: string;
10
10
  };
11
11
  }
12
- export declare function getSigner(accountKey: string): Signer;
12
+ export declare function getSigner(masterKey: string): Signer;
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
  }
@@ -35,9 +35,9 @@ export class Signer {
35
35
  }
36
36
  }
37
37
  const signers = {};
38
- export function getSigner(accountKey) {
39
- if (!signers[accountKey]) {
40
- signers[accountKey] = new Signer(accountKey);
38
+ export function getSigner(masterKey) {
39
+ if (!signers[masterKey]) {
40
+ signers[masterKey] = new Signer(masterKey);
41
41
  }
42
- return signers[accountKey];
42
+ return signers[masterKey];
43
43
  }
package/dist/types.d.ts CHANGED
@@ -58,5 +58,5 @@ export interface Collection extends PersistedResource {
58
58
  }
59
59
  export interface ConnectionInfo {
60
60
  endpoint: string;
61
- accountKey: string;
61
+ masterKey: string;
62
62
  }
package/dist/util.js CHANGED
@@ -31,6 +31,6 @@ export function parseConnectionString(connString) {
31
31
  }
32
32
  return {
33
33
  endpoint: props.AccountEndpoint,
34
- accountKey: props.AccountKey
34
+ masterKey: props.AccountKey
35
35
  };
36
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfworker/cosmos",
3
- "version": "1.13.0",
3
+ "version": "1.13.3",
4
4
  "description": "Azure Cosmos DB client for Cloudflare Workers and service workers",
5
5
  "keywords": [
6
6
  "azure",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "@cfworker/worker-types": "^1.12.1",
41
41
  "@cloudflare/workers-types": "^2.2.2",
42
- "base64-arraybuffer": "^1.0.2"
42
+ "rfc4648": "^1.5.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@cfworker/dev": "^1.14.0",
package/src/client.ts CHANGED
@@ -27,7 +27,7 @@ export type CosmosClientConfig =
27
27
  /**
28
28
  * Cosmos DB connection string.
29
29
  * @example
30
- * "AccountEndpoint=https://xxxxxxxxxx.documents.azure.com:443/;accountKey=xxxxxxxxxx;"
30
+ * "AccountEndpoint=https://xxxxxxxxxx.documents.azure.com:443/;AccountKey=xxxxxxxxxx;"
31
31
  */
32
32
  connectionString: string;
33
33
  } & CosmosClientConfigBase);
@@ -84,7 +84,7 @@ export class CosmosClient {
84
84
  public retries = { count: 0, delayMs: 0 };
85
85
 
86
86
  constructor(config: CosmosClientConfig) {
87
- let { endpoint, accountKey } =
87
+ let { endpoint, masterKey } =
88
88
  'connectionString' in config
89
89
  ? parseConnectionString(config.connectionString)
90
90
  : config;
@@ -92,7 +92,7 @@ export class CosmosClient {
92
92
  endpoint = endpoint.slice(0, -1);
93
93
  }
94
94
  this.endpoint = endpoint;
95
- this.signer = getSigner(accountKey);
95
+ this.signer = getSigner(masterKey);
96
96
  this.retryPolicy = config.retryPolicy ?? defaultRetryPolicy;
97
97
  this.consistencyLevel = config.consistencyLevel ?? 'Session';
98
98
  this.dbId = config.dbId;
@@ -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}`)
@@ -55,9 +52,9 @@ export class Signer {
55
52
 
56
53
  const signers: Record<string, Signer> = {};
57
54
 
58
- export function getSigner(accountKey: string) {
59
- if (!signers[accountKey]) {
60
- signers[accountKey] = new Signer(accountKey);
55
+ export function getSigner(masterKey: string) {
56
+ if (!signers[masterKey]) {
57
+ signers[masterKey] = new Signer(masterKey);
61
58
  }
62
- return signers[accountKey];
59
+ return signers[masterKey];
63
60
  }
package/src/types.ts CHANGED
@@ -78,5 +78,5 @@ export interface ConnectionInfo {
78
78
  /**
79
79
  * Cosmos DB key.
80
80
  */
81
- accountKey: string;
81
+ masterKey: string;
82
82
  }
package/src/util.ts CHANGED
@@ -54,6 +54,6 @@ export function parseConnectionString(connString: string): ConnectionInfo {
54
54
  }
55
55
  return {
56
56
  endpoint: props.AccountEndpoint,
57
- accountKey: props.AccountKey
57
+ masterKey: props.AccountKey
58
58
  };
59
59
  }