@droz-js/sdk 0.2.3 → 0.2.5

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,10 +1,10 @@
1
1
  {
2
2
  "name": "@droz-js/sdk",
3
3
  "description": "Droz SDK",
4
- "version": "0.2.3",
4
+ "version": "0.2.5",
5
5
  "private": false,
6
+ "main": "./src/index.js",
6
7
  "exports": {
7
- ".": "./src/index.js",
8
8
  "./*": "./src/*.js",
9
9
  "./server": "./src/index.ts",
10
10
  "./server/*": "./src/*.ts"
@@ -15,6 +15,10 @@ function toAuthorizationProvider(type, ...values) {
15
15
  if (type == 'Bearer') {
16
16
  return `Bearer ${values[0]}`;
17
17
  }
18
+ // TODO to be removed
19
+ if (type == 'Mock') {
20
+ return `Mock ${values[0]}`;
21
+ }
18
22
  throw new Error(`Invalid authentication type '${type}'`);
19
23
  }
20
24
  exports.toAuthorizationProvider = toAuthorizationProvider;
@@ -24,9 +24,12 @@ function emptyAsyncIterator() {
24
24
  }
25
25
  };
26
26
  }
27
- function buildRequestInfo(req) {
27
+ function buildArgs(req) {
28
28
  const operationNames = Array.isArray(req) ? req.map(r => r.operationName) : [req.operationName];
29
- return [...new Set(operationNames)].join(',');
29
+ const params = new URLSearchParams();
30
+ const uniques = new Set(operationNames);
31
+ uniques.forEach(name => params.append('_', name));
32
+ return params.toString();
30
33
  }
31
34
  class HttpRequester {
32
35
  serviceName;
@@ -61,13 +64,14 @@ class HttpRequester {
61
64
  const heads = new Headers();
62
65
  heads.set('Authorization', authorization);
63
66
  heads.set('Content-Type', 'application/json');
67
+ heads.set('Accept', 'application/json');
64
68
  const headers = Object.fromEntries(heads.entries());
65
69
  return { endpoint, headers };
66
70
  }
67
71
  async inbatches(request) {
68
72
  const { endpoint, headers } = await this.buildRequest();
69
73
  const body = JSON.stringify(request);
70
- const args = buildRequestInfo(request);
74
+ const args = buildArgs(request);
71
75
  // make POST request
72
76
  const response = await fetch(`${endpoint}?${args}`, {
73
77
  method: 'POST',
@@ -1,5 +1,5 @@
1
1
  import { GetSdk } from './helpers';
2
2
  export declare function WsClientBuilder<Sdk>(serviceName: string, getSdk: GetSdk<Sdk>): new () => {
3
3
  readonly ws: any;
4
- connect(): Promise<any>;
4
+ connect(): Promise<void>;
5
5
  } & Sdk;
package/src/client/ws.js CHANGED
@@ -31,8 +31,6 @@ class WsRequester {
31
31
  return this.requester.bind(this);
32
32
  }
33
33
  requester(query, variables) {
34
- if (!this.client)
35
- throw new Error('Client not connected, you must call await client.connect(); first');
36
34
  const isSubscription = query.trim().startsWith('subscription ');
37
35
  const operation = { query, variables };
38
36
  const iterable = this.client.iterate(operation);
@@ -56,7 +54,7 @@ function WsClientBuilder(serviceName, getSdk) {
56
54
  Object.assign(this, sdk);
57
55
  }
58
56
  async connect() {
59
- return this.ws.connect();
57
+ await this.ws.connect();
60
58
  }
61
59
  }
62
60
  return Client;
@@ -1,7 +1,7 @@
1
1
  export * from './sdks/drozchat';
2
2
  export declare const DrozChatWs: new () => {
3
3
  readonly ws: any;
4
- connect(): Promise<any>;
4
+ connect(): Promise<void>;
5
5
  } & {
6
6
  createCustomer(variables: import("./sdks/drozchat").Exact<{
7
7
  input: import("./sdks/drozchat").CreateCustomerInput;