@droz-js/sdk 0.2.1 → 0.2.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/README.md +2 -2
- package/package.json +1 -3
- package/src/client/config.d.ts +23 -13
- package/src/client/config.js +52 -51
- package/src/client/helpers.d.ts +9 -0
- package/src/client/helpers.js +45 -0
- package/src/client/http.d.ts +6 -6
- package/src/client/http.js +48 -19
- package/src/client/ws.d.ts +5 -7
- package/src/client/ws.js +12 -11
- package/src/drozbot.d.ts +4 -0
- package/src/drozchat-ws.d.ts +3 -2
- package/src/drozchat.d.ts +4 -0
- package/src/droznexo.d.ts +4 -0
- package/src/mercadolivre.d.ts +4 -0
- package/src/nucleus.d.ts +41 -0
- package/src/reclameaqui.d.ts +4 -0
- package/src/sdks/drozbot.d.ts +3 -5
- package/src/sdks/drozchat.d.ts +17 -16
- package/src/sdks/drozchat.js +15 -40
- package/src/sdks/droznexo.d.ts +7 -6
- package/src/sdks/droznexo.js +4 -7
- package/src/sdks/mercadolivre.d.ts +3 -5
- package/src/sdks/nucleus.d.ts +152 -38
- package/src/sdks/nucleus.js +162 -16
- package/src/sdks/reclameaqui.d.ts +3 -5
- package/src/sdks/zendesk.d.ts +3 -5
- package/src/zendesk.d.ts +4 -0
- package/src/client/utils.d.ts +0 -3
- package/src/client/utils.js +0 -18
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ first before making any sdk calls. The sdk will fail if you don't set up the ten
|
|
|
8
8
|
```typescript
|
|
9
9
|
import { DrozSdk } from '@droz-js/sdk';
|
|
10
10
|
|
|
11
|
-
DrozSdk.forTenant('dev').
|
|
11
|
+
DrozSdk.forTenant('dev').withAuthorization('Basic', 'username', 'password');
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
You can also split the setup in two steps
|
|
@@ -20,7 +20,7 @@ import { DrozSdk } from '@droz-js/sdk';
|
|
|
20
20
|
DrozSdk.forTenant('dev');
|
|
21
21
|
|
|
22
22
|
// (optional) later when you have the authentication token you can set it and it will automatically be used in the new requests
|
|
23
|
-
DrozSdk.
|
|
23
|
+
DrozSdk.withAuthorization('Basic', 'username', 'password');
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
## Websocket
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@droz-js/sdk",
|
|
3
3
|
"description": "Droz SDK",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./src/index.js",
|
|
@@ -16,9 +16,7 @@
|
|
|
16
16
|
"prepublishOnly": "npm run build"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"cross-fetch": "^3.1.8",
|
|
20
19
|
"graphql": "^16.8.1",
|
|
21
|
-
"graphql-tag": "^2.12.6",
|
|
22
20
|
"graphql-ws": "^5.14.1",
|
|
23
21
|
"inbatches": "^0.0.10"
|
|
24
22
|
},
|
package/src/client/config.d.ts
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { AuthorizationProvider } from './helpers';
|
|
2
|
+
export interface Service {
|
|
3
|
+
tenantId: string;
|
|
4
|
+
serviceId: string;
|
|
5
|
+
type: string;
|
|
6
|
+
endpoint: string;
|
|
7
|
+
}
|
|
8
|
+
declare class TenantConfig {
|
|
9
|
+
readonly tenant: string;
|
|
10
|
+
private readonly services;
|
|
11
|
+
constructor(tenant: string, instances: Service[]);
|
|
9
12
|
getEndpoint(serviceName: string, type?: 'http' | 'ws'): string;
|
|
10
|
-
private reset;
|
|
11
|
-
private initialize;
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* The DrozSdk is the entry point for the SDK. It allows to configure the default tenant and authorization provider.
|
|
16
|
+
*/
|
|
13
17
|
export declare class DrozSdk {
|
|
14
|
-
private static
|
|
18
|
+
private static defaultTenant?;
|
|
19
|
+
private static defaultAuthorizationProvider?;
|
|
20
|
+
private static readonly tenantConfigs;
|
|
15
21
|
static forTenant(tenant: string): typeof DrozSdk;
|
|
16
|
-
static
|
|
17
|
-
static
|
|
22
|
+
static withAuthorization(type?: string, ...values: string[]): void;
|
|
23
|
+
static withAuthorizationProvider(provider: () => Promise<string>): void;
|
|
24
|
+
static getAuthorization(customProvider?: AuthorizationProvider): Promise<string>;
|
|
25
|
+
static getTenantConfig(customTenant?: string): Promise<TenantConfig>;
|
|
26
|
+
private static getOrDiscoverTenantConfig;
|
|
27
|
+
private static discoverTenantConfig;
|
|
18
28
|
}
|
|
19
29
|
export {};
|
package/src/client/config.js
CHANGED
|
@@ -1,39 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DrozSdk = void 0;
|
|
4
|
-
const
|
|
5
|
-
class
|
|
6
|
-
authentication;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
class TenantConfig {
|
|
7
6
|
tenant;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
instances = [];
|
|
11
|
-
setTenant(tenant) {
|
|
7
|
+
services;
|
|
8
|
+
constructor(tenant, instances) {
|
|
12
9
|
this.tenant = tenant;
|
|
13
|
-
this.
|
|
14
|
-
}
|
|
15
|
-
setAuthentication(type, ...values) {
|
|
16
|
-
if (!['Bearer', 'Basic'].includes(type)) {
|
|
17
|
-
throw new Error(`Invalid authentication type ${type}`);
|
|
18
|
-
}
|
|
19
|
-
if (values.length && values.every(Boolean)) {
|
|
20
|
-
if (type == 'Basic')
|
|
21
|
-
this.authentication = `Basic ${Buffer.from(values.join(':')).toString('base64')}`;
|
|
22
|
-
if (type == 'Bearer')
|
|
23
|
-
this.authentication = `Bearer ${values[0]}`;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
this.authentication = undefined;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
async get() {
|
|
30
|
-
if (this.initialized)
|
|
31
|
-
return this;
|
|
32
|
-
return await this.initialize();
|
|
10
|
+
this.services = instances;
|
|
33
11
|
}
|
|
34
12
|
getEndpoint(serviceName, type = 'http') {
|
|
35
13
|
const serviceId = serviceName.replace('@droz/', '');
|
|
36
|
-
const instance = this.
|
|
14
|
+
const instance = this.services.find(instance => {
|
|
37
15
|
return instance.serviceId == serviceId && instance.type == type;
|
|
38
16
|
});
|
|
39
17
|
if (instance) {
|
|
@@ -44,36 +22,59 @@ class DrozSdkConfig {
|
|
|
44
22
|
}
|
|
45
23
|
return instance.endpoint;
|
|
46
24
|
}
|
|
47
|
-
throw new Error(`
|
|
48
|
-
}
|
|
49
|
-
reset() {
|
|
50
|
-
this.initialized = false;
|
|
51
|
-
this.instances = [];
|
|
52
|
-
}
|
|
53
|
-
async initialize() {
|
|
54
|
-
this.initialized = true;
|
|
55
|
-
// fetch instances from discovery service
|
|
56
|
-
const data = await fetch(`${discoveryEndpoint}/discover/${this.tenant}`);
|
|
57
|
-
const json = await data.json();
|
|
58
|
-
this.instances = json.instances ?? [];
|
|
59
|
-
// validate it's a valid tenant
|
|
60
|
-
if (this.instances.length === 0) {
|
|
61
|
-
throw new Error(`Invalid tenant '${this.tenant}', no instances found`);
|
|
62
|
-
}
|
|
63
|
-
return this;
|
|
25
|
+
throw new Error(`Tenant "${this.tenant}" endpoint for service "${serviceId}" and type "${type}" not found`);
|
|
64
26
|
}
|
|
65
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The DrozSdk is the entry point for the SDK. It allows to configure the default tenant and authorization provider.
|
|
30
|
+
*/
|
|
66
31
|
class DrozSdk {
|
|
67
|
-
static
|
|
32
|
+
static defaultTenant;
|
|
33
|
+
static defaultAuthorizationProvider;
|
|
34
|
+
static tenantConfigs = new Map();
|
|
68
35
|
static forTenant(tenant) {
|
|
69
|
-
this.
|
|
36
|
+
this.defaultTenant = tenant;
|
|
37
|
+
this.tenantConfigs.delete(tenant);
|
|
70
38
|
return this;
|
|
71
39
|
}
|
|
72
|
-
static
|
|
73
|
-
this.
|
|
40
|
+
static withAuthorization(type, ...values) {
|
|
41
|
+
this.defaultAuthorizationProvider = (0, helpers_1.toAuthorizationProvider)(type, ...values);
|
|
42
|
+
}
|
|
43
|
+
static withAuthorizationProvider(provider) {
|
|
44
|
+
this.defaultAuthorizationProvider = provider;
|
|
45
|
+
}
|
|
46
|
+
static async getAuthorization(customProvider) {
|
|
47
|
+
if (customProvider)
|
|
48
|
+
return await (0, helpers_1.resolveAuthorization)(customProvider);
|
|
49
|
+
const defaultProvider = this.defaultAuthorizationProvider;
|
|
50
|
+
if (defaultProvider)
|
|
51
|
+
return await (0, helpers_1.resolveAuthorization)(defaultProvider);
|
|
52
|
+
}
|
|
53
|
+
static async getTenantConfig(customTenant) {
|
|
54
|
+
if (customTenant)
|
|
55
|
+
return await this.getOrDiscoverTenantConfig(customTenant);
|
|
56
|
+
const defaultTenant = this.defaultTenant;
|
|
57
|
+
return this.getOrDiscoverTenantConfig(defaultTenant);
|
|
58
|
+
}
|
|
59
|
+
static async getOrDiscoverTenantConfig(tenant) {
|
|
60
|
+
if (this.tenantConfigs.has(tenant)) {
|
|
61
|
+
return this.tenantConfigs.get(tenant);
|
|
62
|
+
}
|
|
63
|
+
return await this.discoverTenantConfig(tenant);
|
|
74
64
|
}
|
|
75
|
-
static async
|
|
76
|
-
|
|
65
|
+
static async discoverTenantConfig(tenant) {
|
|
66
|
+
// fetch instances from discovery service
|
|
67
|
+
const data = await fetch(`${helpers_1.serviceDiscoveryEndpoint}/discover/${tenant}`);
|
|
68
|
+
const json = await data.json();
|
|
69
|
+
const instances = json.instances ?? [];
|
|
70
|
+
// validate it's a valid tenant
|
|
71
|
+
if (instances.length === 0) {
|
|
72
|
+
throw new Error(`Invalid tenant '${tenant}', no instances found on service discovery`);
|
|
73
|
+
}
|
|
74
|
+
// create tenant config and cache it
|
|
75
|
+
const config = new TenantConfig(tenant, instances);
|
|
76
|
+
this.tenantConfigs.set(tenant, config);
|
|
77
|
+
return config;
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
exports.DrozSdk = DrozSdk;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExecutionResult } from 'graphql';
|
|
2
|
+
export declare const serviceDiscoveryEndpoint = "https://th3xrek4rane2scfwwfoo7wemq0tvuzm.lambda-url.sa-east-1.on.aws";
|
|
3
|
+
export type AuthorizationProvider = string | (() => Promise<string>) | (() => string);
|
|
4
|
+
export type Requester<C = {}> = <R, V>(doc: string, vars?: V, options?: C) => Promise<R> | AsyncIterableIterator<R>;
|
|
5
|
+
export type GetSdk<Sdk> = (requester: Requester<Sdk>) => Sdk;
|
|
6
|
+
export declare function toAuthorizationProvider(type?: string, ...values: string[]): AuthorizationProvider;
|
|
7
|
+
export declare function resolveAuthorization(provider?: AuthorizationProvider): Promise<string>;
|
|
8
|
+
export declare function mapGraphqlResponse<T>(response: ExecutionResult<T> | Error): T;
|
|
9
|
+
export declare function mapAsyncIterableGraphqlResponse<T>(iterable: AsyncIterableIterator<ExecutionResult<T, any>>): AsyncGenerator<Awaited<T>, void, unknown>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapAsyncIterableGraphqlResponse = exports.mapGraphqlResponse = exports.resolveAuthorization = exports.toAuthorizationProvider = exports.serviceDiscoveryEndpoint = void 0;
|
|
4
|
+
exports.serviceDiscoveryEndpoint = 'https://th3xrek4rane2scfwwfoo7wemq0tvuzm.lambda-url.sa-east-1.on.aws';
|
|
5
|
+
function toAuthorizationProvider(type, ...values) {
|
|
6
|
+
// this means it is unsetting the authorization token
|
|
7
|
+
if (!type)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (!values.every(Boolean))
|
|
10
|
+
return undefined;
|
|
11
|
+
if (type == 'Basic') {
|
|
12
|
+
const base64 = Buffer.from(values.join(':')).toString('base64');
|
|
13
|
+
return `Basic ${base64}`;
|
|
14
|
+
}
|
|
15
|
+
if (type == 'Bearer') {
|
|
16
|
+
return `Bearer ${values[0]}`;
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`Invalid authentication type '${type}'`);
|
|
19
|
+
}
|
|
20
|
+
exports.toAuthorizationProvider = toAuthorizationProvider;
|
|
21
|
+
async function resolveAuthorization(provider) {
|
|
22
|
+
if (typeof provider === 'string')
|
|
23
|
+
return provider;
|
|
24
|
+
if (typeof provider === 'function')
|
|
25
|
+
return await provider();
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
exports.resolveAuthorization = resolveAuthorization;
|
|
29
|
+
function mapGraphqlResponse(response) {
|
|
30
|
+
if (response) {
|
|
31
|
+
if (response && 'stack' in response && 'message' in response)
|
|
32
|
+
throw response;
|
|
33
|
+
if ('errors' in response)
|
|
34
|
+
console.error(JSON.stringify(response.errors));
|
|
35
|
+
if ('data' in response)
|
|
36
|
+
return response.data;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.mapGraphqlResponse = mapGraphqlResponse;
|
|
40
|
+
async function* mapAsyncIterableGraphqlResponse(iterable) {
|
|
41
|
+
for await (const each of iterable) {
|
|
42
|
+
yield mapGraphqlResponse(each);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.mapAsyncIterableGraphqlResponse = mapAsyncIterableGraphqlResponse;
|
package/src/client/http.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { AuthorizationProvider, GetSdk } from './helpers';
|
|
2
|
+
export declare function HttpClientBuilder<Sdk>(serviceName: string, getSdk: GetSdk<Sdk>): new () => {
|
|
3
|
+
readonly http: any;
|
|
4
|
+
forTenant(tenant: string): void;
|
|
5
|
+
withAuthorization(authorization: AuthorizationProvider): void;
|
|
6
|
+
} & Sdk;
|
package/src/client/http.js
CHANGED
|
@@ -9,49 +9,71 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.HttpClientBuilder =
|
|
12
|
+
exports.HttpClientBuilder = void 0;
|
|
13
13
|
const inbatches_1 = require("inbatches");
|
|
14
14
|
const config_1 = require("./config");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const helpers_1 = require("./helpers");
|
|
16
|
+
// create an empty AsyncIterableIterator
|
|
17
|
+
function emptyAsyncIterator() {
|
|
18
|
+
return {
|
|
19
|
+
[Symbol.asyncIterator]() {
|
|
20
|
+
return this;
|
|
21
|
+
},
|
|
22
|
+
async next() {
|
|
23
|
+
return { done: true, value: undefined };
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
20
27
|
function buildRequestInfo(req) {
|
|
21
28
|
const operationNames = Array.isArray(req) ? req.map(r => r.operationName) : [req.operationName];
|
|
22
29
|
return [...new Set(operationNames)].join(',');
|
|
23
30
|
}
|
|
24
|
-
class
|
|
31
|
+
class HttpRequester {
|
|
25
32
|
serviceName;
|
|
33
|
+
tenant;
|
|
34
|
+
authorization;
|
|
26
35
|
constructor(serviceName) {
|
|
27
36
|
this.serviceName = serviceName;
|
|
28
37
|
}
|
|
38
|
+
forTenant(tenant) {
|
|
39
|
+
this.tenant = tenant;
|
|
40
|
+
}
|
|
41
|
+
withAuthorization(authorization) {
|
|
42
|
+
this.authorization = authorization;
|
|
43
|
+
}
|
|
29
44
|
build() {
|
|
30
45
|
return this.requester.bind(this);
|
|
31
46
|
}
|
|
32
47
|
requester(query, variables) {
|
|
33
48
|
// subscriptions are not executable with the http sdk
|
|
34
49
|
if (query.match(/subscription .*{/))
|
|
35
|
-
return
|
|
50
|
+
return emptyAsyncIterator();
|
|
36
51
|
// extract operation name and enqueue the request to be executed in batches
|
|
37
52
|
const operationName = /(?:query|mutation) ([^({ ]*)/.exec(query)?.[1];
|
|
38
|
-
return this.inbatches({ query, variables, operationName }).then(
|
|
53
|
+
return this.inbatches({ query, variables, operationName }).then(helpers_1.mapGraphqlResponse);
|
|
54
|
+
}
|
|
55
|
+
async buildRequest() {
|
|
56
|
+
const [authorization, tenant] = await Promise.all([
|
|
57
|
+
config_1.DrozSdk.getAuthorization(this.authorization),
|
|
58
|
+
config_1.DrozSdk.getTenantConfig(this.tenant)
|
|
59
|
+
]);
|
|
60
|
+
const endpoint = tenant.getEndpoint(this.serviceName);
|
|
61
|
+
const heads = new Headers();
|
|
62
|
+
heads.set('Authorization', authorization);
|
|
63
|
+
heads.set('Content-Type', 'application/json');
|
|
64
|
+
const headers = Object.fromEntries(heads.entries());
|
|
65
|
+
return { endpoint, headers };
|
|
39
66
|
}
|
|
40
67
|
async inbatches(request) {
|
|
41
|
-
const
|
|
42
|
-
const endpoint = config.getEndpoint(this.serviceName, 'http');
|
|
68
|
+
const { endpoint, headers } = await this.buildRequest();
|
|
43
69
|
const body = JSON.stringify(request);
|
|
44
70
|
const args = buildRequestInfo(request);
|
|
45
|
-
const headers = new Headers();
|
|
46
|
-
headers.set('Authorization', config.authentication);
|
|
47
|
-
headers.set('Content-Type', 'application/json');
|
|
48
71
|
// make POST request
|
|
49
72
|
const response = await fetch(`${endpoint}?${args}`, {
|
|
50
73
|
method: 'POST',
|
|
51
|
-
headers
|
|
74
|
+
headers,
|
|
52
75
|
body
|
|
53
76
|
});
|
|
54
|
-
// treat the response
|
|
55
77
|
return await response.json();
|
|
56
78
|
}
|
|
57
79
|
}
|
|
@@ -60,14 +82,21 @@ __decorate([
|
|
|
60
82
|
__metadata("design:type", Function),
|
|
61
83
|
__metadata("design:paramtypes", [Object]),
|
|
62
84
|
__metadata("design:returntype", Promise)
|
|
63
|
-
],
|
|
85
|
+
], HttpRequester.prototype, "inbatches", null);
|
|
64
86
|
function HttpClientBuilder(serviceName, getSdk) {
|
|
65
87
|
class Client {
|
|
88
|
+
http; // cannot type as HttpSdkRequesterBuilder because it is an anonymous class
|
|
66
89
|
constructor() {
|
|
67
|
-
|
|
68
|
-
const sdk = getSdk(http.build());
|
|
90
|
+
this.http = new HttpRequester(serviceName);
|
|
91
|
+
const sdk = getSdk(this.http.build());
|
|
69
92
|
Object.assign(this, sdk);
|
|
70
93
|
}
|
|
94
|
+
forTenant(tenant) {
|
|
95
|
+
this.http.forTenant(tenant);
|
|
96
|
+
}
|
|
97
|
+
withAuthorization(authorization) {
|
|
98
|
+
this.http.withAuthorization(authorization);
|
|
99
|
+
}
|
|
71
100
|
}
|
|
72
101
|
return Client;
|
|
73
102
|
}
|
package/src/client/ws.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
connect(): Promise<
|
|
5
|
-
};
|
|
6
|
-
export declare function WsClientBuilder<Sdk>(serviceName: string, getSdk: (requester: Requester<Sdk>) => Sdk): new () => Sdk & Connect;
|
|
7
|
-
export {};
|
|
1
|
+
import { GetSdk } from './helpers';
|
|
2
|
+
export declare function WsClientBuilder<Sdk>(serviceName: string, getSdk: GetSdk<Sdk>): new () => {
|
|
3
|
+
readonly ws: any;
|
|
4
|
+
connect(): Promise<any>;
|
|
5
|
+
} & Sdk;
|
package/src/client/ws.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WsClientBuilder = void 0;
|
|
4
4
|
const graphql_ws_1 = require("graphql-ws");
|
|
5
5
|
const config_1 = require("./config");
|
|
6
|
-
const
|
|
7
|
-
class
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
7
|
+
class WsRequester {
|
|
8
8
|
serviceName;
|
|
9
9
|
client;
|
|
10
10
|
constructor(serviceName) {
|
|
@@ -13,16 +13,17 @@ class WsSdkRequesterBuilder {
|
|
|
13
13
|
async connect() {
|
|
14
14
|
if (this.client)
|
|
15
15
|
return this.client;
|
|
16
|
-
const
|
|
17
|
-
|
|
16
|
+
const [tenant, authorization] = await Promise.all([
|
|
17
|
+
config_1.DrozSdk.getTenantConfig(),
|
|
18
|
+
config_1.DrozSdk.getAuthorization()
|
|
19
|
+
]);
|
|
20
|
+
const endpoint = tenant.getEndpoint(this.serviceName, 'ws');
|
|
18
21
|
this.client = (0, graphql_ws_1.createClient)({
|
|
19
22
|
url: endpoint,
|
|
20
23
|
lazy: true,
|
|
21
24
|
retryAttempts: 128,
|
|
22
25
|
keepAlive: 25000,
|
|
23
|
-
connectionParams: {
|
|
24
|
-
authorization: config.authentication
|
|
25
|
-
}
|
|
26
|
+
connectionParams: { authorization }
|
|
26
27
|
});
|
|
27
28
|
return this.client;
|
|
28
29
|
}
|
|
@@ -37,20 +38,20 @@ class WsSdkRequesterBuilder {
|
|
|
37
38
|
const iterable = this.client.iterate(operation);
|
|
38
39
|
// subscription
|
|
39
40
|
if (isSubscription) {
|
|
40
|
-
return (0,
|
|
41
|
+
return (0, helpers_1.mapAsyncIterableGraphqlResponse)(iterable);
|
|
41
42
|
}
|
|
42
43
|
// single query or mutation
|
|
43
44
|
return iterable
|
|
44
45
|
.next()
|
|
45
46
|
.then(one => one.value)
|
|
46
|
-
.then(res => (0,
|
|
47
|
+
.then(res => (0, helpers_1.mapGraphqlResponse)(res));
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
function WsClientBuilder(serviceName, getSdk) {
|
|
50
51
|
class Client {
|
|
51
|
-
ws;
|
|
52
|
+
ws; // cannot type as WsSdkRequester because it is an anonymous class
|
|
52
53
|
constructor() {
|
|
53
|
-
this.ws = new
|
|
54
|
+
this.ws = new WsRequester(serviceName);
|
|
54
55
|
const sdk = getSdk(this.ws.build());
|
|
55
56
|
Object.assign(this, sdk);
|
|
56
57
|
}
|
package/src/drozbot.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './sdks/drozbot';
|
|
2
2
|
export declare const DrozBot: new () => {
|
|
3
|
+
readonly http: any;
|
|
4
|
+
forTenant(tenant: string): void;
|
|
5
|
+
withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): void;
|
|
6
|
+
} & {
|
|
3
7
|
getDrozBotInstance(variables: import("./sdks/drozbot").Exact<{
|
|
4
8
|
id: string;
|
|
5
9
|
}>, options?: unknown): Promise<import("./sdks/drozbot").GetDrozBotInstanceQuery>;
|
package/src/drozchat-ws.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export * from './sdks/drozchat';
|
|
2
2
|
export declare const DrozChatWs: new () => {
|
|
3
|
+
readonly ws: any;
|
|
4
|
+
connect(): Promise<any>;
|
|
5
|
+
} & {
|
|
3
6
|
createCustomer(variables: import("./sdks/drozchat").Exact<{
|
|
4
7
|
input: import("./sdks/drozchat").CreateCustomerInput;
|
|
5
8
|
}>, options?: unknown): Promise<import("./sdks/drozchat").CreateCustomerMutation>;
|
|
@@ -66,6 +69,4 @@ export declare const DrozChatWs: new () => {
|
|
|
66
69
|
onTicketMessage(variables: import("./sdks/drozchat").Exact<{
|
|
67
70
|
ticketId: string;
|
|
68
71
|
}>, options?: unknown): AsyncIterable<import("./sdks/drozchat").OnTicketMessageSubscription>;
|
|
69
|
-
} & {
|
|
70
|
-
connect(): Promise<import("graphql-ws").Client>;
|
|
71
72
|
};
|
package/src/drozchat.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './sdks/drozchat';
|
|
2
2
|
export declare const DrozChat: new () => {
|
|
3
|
+
readonly http: any;
|
|
4
|
+
forTenant(tenant: string): void;
|
|
5
|
+
withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): void;
|
|
6
|
+
} & {
|
|
3
7
|
createCustomer(variables: import("./sdks/drozchat").Exact<{
|
|
4
8
|
input: import("./sdks/drozchat").CreateCustomerInput;
|
|
5
9
|
}>, options?: unknown): Promise<import("./sdks/drozchat").CreateCustomerMutation>;
|
package/src/droznexo.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './sdks/droznexo';
|
|
2
2
|
export declare const DrozNexo: new () => {
|
|
3
|
+
readonly http: any;
|
|
4
|
+
forTenant(tenant: string): void;
|
|
5
|
+
withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): void;
|
|
6
|
+
} & {
|
|
3
7
|
createAgent(variables: import("./sdks/droznexo").Exact<{
|
|
4
8
|
input: import("./sdks/droznexo").CreateAgentInput;
|
|
5
9
|
}>, options?: unknown): Promise<import("./sdks/droznexo").CreateAgentMutation>;
|
package/src/mercadolivre.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './sdks/mercadolivre';
|
|
2
2
|
export declare const MercadoLivre: new () => {
|
|
3
|
+
readonly http: any;
|
|
4
|
+
forTenant(tenant: string): void;
|
|
5
|
+
withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): void;
|
|
6
|
+
} & {
|
|
3
7
|
getMercadoLivreInstance(variables: import("./sdks/mercadolivre").Exact<{
|
|
4
8
|
id: string;
|
|
5
9
|
}>, options?: unknown): Promise<import("./sdks/mercadolivre").GetMercadoLivreInstanceQuery>;
|
package/src/nucleus.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './sdks/nucleus';
|
|
2
2
|
export declare const Nucleus: new () => {
|
|
3
|
+
readonly http: any;
|
|
4
|
+
forTenant(tenant: string): void;
|
|
5
|
+
withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): void;
|
|
6
|
+
} & {
|
|
3
7
|
getApp(variables: import("./sdks/nucleus").Exact<{
|
|
4
8
|
appId: string;
|
|
5
9
|
withInstances?: boolean;
|
|
@@ -65,4 +69,41 @@ export declare const Nucleus: new () => {
|
|
|
65
69
|
id: string;
|
|
66
70
|
versionId: string;
|
|
67
71
|
}>, options?: unknown): Promise<import("./sdks/nucleus").GetStateMachineQuery>;
|
|
72
|
+
listLiveStateMachineConfigs(variables?: import("./sdks/nucleus").Exact<{
|
|
73
|
+
[key: string]: never;
|
|
74
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").ListLiveStateMachineConfigsQuery>;
|
|
75
|
+
listDraftStateMachineConfigs(variables?: import("./sdks/nucleus").Exact<{
|
|
76
|
+
[key: string]: never;
|
|
77
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").ListDraftStateMachineConfigsQuery>;
|
|
78
|
+
listStateMachineConfigVersions(variables: import("./sdks/nucleus").Exact<{
|
|
79
|
+
id: string;
|
|
80
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").ListStateMachineConfigVersionsQuery>;
|
|
81
|
+
getXStateMachineConfig(variables: import("./sdks/nucleus").Exact<{
|
|
82
|
+
id: string;
|
|
83
|
+
versionId: string;
|
|
84
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").GetXStateMachineConfigQuery>;
|
|
85
|
+
createStateMachineConfig(variables: import("./sdks/nucleus").Exact<{
|
|
86
|
+
input: import("./sdks/nucleus").CreateStateMachineConfigInput;
|
|
87
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").CreateStateMachineConfigMutation>;
|
|
88
|
+
updateStateMachineConfig(variables: import("./sdks/nucleus").Exact<{
|
|
89
|
+
input: import("./sdks/nucleus").UpdateStateMachineConfigInput;
|
|
90
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").UpdateStateMachineConfigMutation>;
|
|
91
|
+
removeStateMachineConfig(variables: import("./sdks/nucleus").Exact<{
|
|
92
|
+
input: import("./sdks/nucleus").RemoveStateMachineConfigInput;
|
|
93
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").RemoveStateMachineConfigMutation>;
|
|
94
|
+
editStateMachineConfig(variables: import("./sdks/nucleus").Exact<{
|
|
95
|
+
input: import("./sdks/nucleus").EditStateMachineConfigInput;
|
|
96
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").EditStateMachineConfigMutation>;
|
|
97
|
+
publishStateMachineConfig(variables: import("./sdks/nucleus").Exact<{
|
|
98
|
+
input: import("./sdks/nucleus").PublishStateMachineConfigInput;
|
|
99
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").PublishStateMachineConfigMutation>;
|
|
100
|
+
createStateMachineConfigState(variables: import("./sdks/nucleus").Exact<{
|
|
101
|
+
input: import("./sdks/nucleus").CreateStateMachineConfigStateInput;
|
|
102
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").CreateStateMachineConfigStateMutation>;
|
|
103
|
+
updateStateMachineConfigState(variables: import("./sdks/nucleus").Exact<{
|
|
104
|
+
input: import("./sdks/nucleus").UpdateStateMachineConfigStateInput;
|
|
105
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").UpdateStateMachineConfigStateMutation>;
|
|
106
|
+
removeStateMachineConfigState(variables: import("./sdks/nucleus").Exact<{
|
|
107
|
+
input: import("./sdks/nucleus").RemoveStateMachineConfigStateInput;
|
|
108
|
+
}>, options?: unknown): Promise<import("./sdks/nucleus").RemoveStateMachineConfigStateMutation>;
|
|
68
109
|
};
|
package/src/reclameaqui.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './sdks/reclameaqui';
|
|
2
2
|
export declare const Reclameaqui: new () => {
|
|
3
|
+
readonly http: any;
|
|
4
|
+
forTenant(tenant: string): void;
|
|
5
|
+
withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): void;
|
|
6
|
+
} & {
|
|
3
7
|
getReclameAquiInstance(variables: import("./sdks/reclameaqui").Exact<{
|
|
4
8
|
id: string;
|
|
5
9
|
}>, options?: unknown): Promise<import("./sdks/reclameaqui").GetReclameAquiInstanceQuery>;
|
package/src/sdks/drozbot.d.ts
CHANGED
|
@@ -70,8 +70,8 @@ export type Scalars = {
|
|
|
70
70
|
output: any;
|
|
71
71
|
};
|
|
72
72
|
Set: {
|
|
73
|
-
input: any
|
|
74
|
-
output: any;
|
|
73
|
+
input: Set<any>;
|
|
74
|
+
output: any[];
|
|
75
75
|
};
|
|
76
76
|
URL: {
|
|
77
77
|
input: string;
|
|
@@ -115,6 +115,7 @@ export type PageInfo = {
|
|
|
115
115
|
export type Query = {
|
|
116
116
|
app?: Maybe<Scalars['DRN']['output']>;
|
|
117
117
|
getDrozBotInstance?: Maybe<DrozBotInstance>;
|
|
118
|
+
getHttpEndpoint?: Maybe<Scalars['String']['output']>;
|
|
118
119
|
listDrozBotInstances: Array<Maybe<DrozBotInstance>>;
|
|
119
120
|
version?: Maybe<Scalars['String']['output']>;
|
|
120
121
|
};
|
|
@@ -124,9 +125,6 @@ export type QueryGetDrozBotInstanceArgs = {
|
|
|
124
125
|
export type RemoveDrozBotInstanceInput = {
|
|
125
126
|
id: Scalars['ID']['input'];
|
|
126
127
|
};
|
|
127
|
-
export type Subscription = {
|
|
128
|
-
version?: Maybe<Scalars['String']['output']>;
|
|
129
|
-
};
|
|
130
128
|
export declare enum Typenames {
|
|
131
129
|
Any = "Any",
|
|
132
130
|
DrozBotInstance = "DrozBotInstance",
|