doover-js 0.1.0 → 0.1.2

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.
@@ -15,6 +15,7 @@ export interface RequestOptions {
15
15
  query?: QueryParams;
16
16
  body?: BodyInit | object | null;
17
17
  headers?: HeadersInit;
18
+ omitSharingHeader?: boolean;
18
19
  }
19
20
  type QueryValue = string | number | boolean | null | undefined | Array<string | number | boolean>;
20
21
  type QueryParams = Record<string, QueryValue> | object;
@@ -16,7 +16,9 @@ class RestClient {
16
16
  const url = this.buildUrl(options.baseUrl ?? this.config.dataRestUrl, options.path, options.query);
17
17
  const headers = new Headers(options.headers);
18
18
  const body = this.normalizeBody(options.body, headers);
19
- headers.set("X-Doover-Sharing", this.config.sharing);
19
+ if (!options.omitSharingHeader) {
20
+ headers.set("X-Doover-Sharing", this.config.sharing);
21
+ }
20
22
  if (this.config.organisationId) {
21
23
  headers.set("X-Doover-Organisation", this.config.organisationId);
22
24
  }
@@ -40,6 +40,8 @@ const helpers_1 = require("./helpers");
40
40
  await (0, chai_1.expect)(provider.getAgents()).to.eventually.deep.equal({ agents: [] });
41
41
  (0, chai_1.expect)(fetchMock.getCall(0).args[0]).to.equal("https://control.example.com/users/me");
42
42
  (0, chai_1.expect)(fetchMock.getCall(1).args[0]).to.equal("https://control.example.com/agents");
43
+ (0, chai_1.expect)((fetchMock.getCall(0).args[1]?.headers).get("X-Doover-Sharing")).to.equal("internal");
44
+ (0, chai_1.expect)((fetchMock.getCall(1).args[1]?.headers).get("X-Doover-Sharing")).to.equal(null);
43
45
  });
44
46
  (0, mocha_1.it)("returns undefined for missing identifiers where expected", async () => {
45
47
  const fetchMock = (0, helpers_1.createFetchMock)();
@@ -33,6 +33,23 @@ const helpers_1 = require("./helpers");
33
33
  (0, chai_1.expect)(headers.get("X-Doover-Organisation")).to.equal("org-1");
34
34
  (0, chai_1.expect)(headers.get("X-Doover-Assume")).to.equal("user-2");
35
35
  });
36
+ (0, mocha_1.it)("can omit the sharing header for specific requests", async () => {
37
+ const fetchMock = (0, helpers_1.createFetchMock)();
38
+ const client = new rest_client_1.RestClient({
39
+ dataRestUrl: "https://api.example.com",
40
+ controlApiUrl: "https://control.example.com",
41
+ dataWssUrl: "wss://ws.example.com",
42
+ fetchImpl: fetchMock,
43
+ });
44
+ await client.request({
45
+ path: "/agents",
46
+ baseUrl: "https://control.example.com",
47
+ omitSharingHeader: true,
48
+ });
49
+ const [, init] = fetchMock.getCall(0).args;
50
+ const headers = init?.headers;
51
+ (0, chai_1.expect)(headers.get("X-Doover-Sharing")).to.equal(null);
52
+ });
36
53
  (0, mocha_1.it)("serializes JSON request bodies", async () => {
37
54
  const fetchMock = (0, helpers_1.createFetchMock)();
38
55
  const client = new rest_client_1.RestClient({
@@ -42,7 +42,11 @@ class DooverDataProvider {
42
42
  return this.rest.get("/users/me", undefined, this.config.controlApiUrl);
43
43
  }
44
44
  getAgents() {
45
- return this.rest.get("/agents", undefined, this.config.controlApiUrl);
45
+ return this.rest.request({
46
+ path: "/agents",
47
+ baseUrl: this.config.controlApiUrl,
48
+ omitSharingHeader: true,
49
+ });
46
50
  }
47
51
  async getChannels(identifier, options) {
48
52
  if (!identifier.agentId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doover-js",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "TypeScript client for Doover.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,11 +12,11 @@
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "https://github.com/get-doover/doover-js.git"
15
+ "url": "https://github.com/getdoover/doover-js.git"
16
16
  },
17
- "homepage": "https://github.com/get-doover/doover-js#readme",
17
+ "homepage": "https://github.com/getdoover/doover-js#readme",
18
18
  "bugs": {
19
- "url": "https://github.com/get-doover/doover-js/issues"
19
+ "url": "https://github.com/getdoover/doover-js/issues"
20
20
  },
21
21
  "files": [
22
22
  "dist"