@droz-js/sdk 0.2.2 → 0.2.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/README.md +2 -2
- package/package.json +1 -1
- 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 +49 -0
- package/src/client/http.d.ts +6 -3
- package/src/client/http.js +35 -13
- 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 +4 -0
- package/src/reclameaqui.d.ts +4 -0
- package/src/sdks/drozbot.d.ts +1 -3
- package/src/sdks/drozchat.d.ts +1 -0
- package/src/sdks/droznexo.d.ts +1 -0
- package/src/sdks/mercadolivre.d.ts +1 -3
- package/src/sdks/nucleus.d.ts +1 -3
- package/src/sdks/reclameaqui.d.ts +1 -3
- package/src/sdks/zendesk.d.ts +1 -3
- 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
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,49 @@
|
|
|
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
|
+
// TODO to be removed
|
|
19
|
+
if (type == 'Mock') {
|
|
20
|
+
return `Mock ${values[0]}`;
|
|
21
|
+
}
|
|
22
|
+
throw new Error(`Invalid authentication type '${type}'`);
|
|
23
|
+
}
|
|
24
|
+
exports.toAuthorizationProvider = toAuthorizationProvider;
|
|
25
|
+
async function resolveAuthorization(provider) {
|
|
26
|
+
if (typeof provider === 'string')
|
|
27
|
+
return provider;
|
|
28
|
+
if (typeof provider === 'function')
|
|
29
|
+
return await provider();
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
exports.resolveAuthorization = resolveAuthorization;
|
|
33
|
+
function mapGraphqlResponse(response) {
|
|
34
|
+
if (response) {
|
|
35
|
+
if (response && 'stack' in response && 'message' in response)
|
|
36
|
+
throw response;
|
|
37
|
+
if ('errors' in response)
|
|
38
|
+
console.error(JSON.stringify(response.errors));
|
|
39
|
+
if ('data' in response)
|
|
40
|
+
return response.data;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.mapGraphqlResponse = mapGraphqlResponse;
|
|
44
|
+
async function* mapAsyncIterableGraphqlResponse(iterable) {
|
|
45
|
+
for await (const each of iterable) {
|
|
46
|
+
yield mapGraphqlResponse(each);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.mapAsyncIterableGraphqlResponse = mapAsyncIterableGraphqlResponse;
|
package/src/client/http.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function HttpClientBuilder<Sdk>(serviceName: string, getSdk:
|
|
3
|
-
|
|
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
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.HttpClientBuilder = void 0;
|
|
13
13
|
const inbatches_1 = require("inbatches");
|
|
14
14
|
const config_1 = require("./config");
|
|
15
|
-
const
|
|
15
|
+
const helpers_1 = require("./helpers");
|
|
16
16
|
// create an empty AsyncIterableIterator
|
|
17
17
|
function emptyAsyncIterator() {
|
|
18
18
|
return {
|
|
@@ -28,11 +28,19 @@ function buildRequestInfo(req) {
|
|
|
28
28
|
const operationNames = Array.isArray(req) ? req.map(r => r.operationName) : [req.operationName];
|
|
29
29
|
return [...new Set(operationNames)].join(',');
|
|
30
30
|
}
|
|
31
|
-
class
|
|
31
|
+
class HttpRequester {
|
|
32
32
|
serviceName;
|
|
33
|
+
tenant;
|
|
34
|
+
authorization;
|
|
33
35
|
constructor(serviceName) {
|
|
34
36
|
this.serviceName = serviceName;
|
|
35
37
|
}
|
|
38
|
+
forTenant(tenant) {
|
|
39
|
+
this.tenant = tenant;
|
|
40
|
+
}
|
|
41
|
+
withAuthorization(authorization) {
|
|
42
|
+
this.authorization = authorization;
|
|
43
|
+
}
|
|
36
44
|
build() {
|
|
37
45
|
return this.requester.bind(this);
|
|
38
46
|
}
|
|
@@ -42,23 +50,30 @@ class HttpSdkRequesterBuilder {
|
|
|
42
50
|
return emptyAsyncIterator();
|
|
43
51
|
// extract operation name and enqueue the request to be executed in batches
|
|
44
52
|
const operationName = /(?:query|mutation) ([^({ ]*)/.exec(query)?.[1];
|
|
45
|
-
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 };
|
|
46
66
|
}
|
|
47
67
|
async inbatches(request) {
|
|
48
|
-
const
|
|
49
|
-
const endpoint = config.getEndpoint(this.serviceName, 'http');
|
|
68
|
+
const { endpoint, headers } = await this.buildRequest();
|
|
50
69
|
const body = JSON.stringify(request);
|
|
51
70
|
const args = buildRequestInfo(request);
|
|
52
|
-
const headers = new Headers();
|
|
53
|
-
headers.set('Authorization', config.authentication);
|
|
54
|
-
headers.set('Content-Type', 'application/json');
|
|
55
71
|
// make POST request
|
|
56
72
|
const response = await fetch(`${endpoint}?${args}`, {
|
|
57
73
|
method: 'POST',
|
|
58
|
-
headers
|
|
74
|
+
headers,
|
|
59
75
|
body
|
|
60
76
|
});
|
|
61
|
-
// treat the response
|
|
62
77
|
return await response.json();
|
|
63
78
|
}
|
|
64
79
|
}
|
|
@@ -67,14 +82,21 @@ __decorate([
|
|
|
67
82
|
__metadata("design:type", Function),
|
|
68
83
|
__metadata("design:paramtypes", [Object]),
|
|
69
84
|
__metadata("design:returntype", Promise)
|
|
70
|
-
],
|
|
85
|
+
], HttpRequester.prototype, "inbatches", null);
|
|
71
86
|
function HttpClientBuilder(serviceName, getSdk) {
|
|
72
87
|
class Client {
|
|
88
|
+
http; // cannot type as HttpSdkRequesterBuilder because it is an anonymous class
|
|
73
89
|
constructor() {
|
|
74
|
-
|
|
75
|
-
const sdk = getSdk(http.build());
|
|
90
|
+
this.http = new HttpRequester(serviceName);
|
|
91
|
+
const sdk = getSdk(this.http.build());
|
|
76
92
|
Object.assign(this, sdk);
|
|
77
93
|
}
|
|
94
|
+
forTenant(tenant) {
|
|
95
|
+
this.http.forTenant(tenant);
|
|
96
|
+
}
|
|
97
|
+
withAuthorization(authorization) {
|
|
98
|
+
this.http.withAuthorization(authorization);
|
|
99
|
+
}
|
|
78
100
|
}
|
|
79
101
|
return Client;
|
|
80
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;
|
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
|
@@ -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",
|
package/src/sdks/drozchat.d.ts
CHANGED
|
@@ -171,6 +171,7 @@ export type PageInfo = {
|
|
|
171
171
|
export type Query = {
|
|
172
172
|
app?: Maybe<Scalars['DRN']['output']>;
|
|
173
173
|
getCustomer?: Maybe<Customer>;
|
|
174
|
+
getHttpEndpoint?: Maybe<Scalars['String']['output']>;
|
|
174
175
|
getTicket?: Maybe<Ticket>;
|
|
175
176
|
getWsEndpoint?: Maybe<Scalars['String']['output']>;
|
|
176
177
|
listCustomers: CustomersConnection;
|
package/src/sdks/droznexo.d.ts
CHANGED
|
@@ -129,6 +129,7 @@ export type PageInfo = {
|
|
|
129
129
|
export type Query = {
|
|
130
130
|
app?: Maybe<Scalars['DRN']['output']>;
|
|
131
131
|
getAgent?: Maybe<Agent>;
|
|
132
|
+
getHttpEndpoint?: Maybe<Scalars['String']['output']>;
|
|
132
133
|
getWsEndpoint?: Maybe<Scalars['String']['output']>;
|
|
133
134
|
listAgentGroups: AgentGroupsConnection;
|
|
134
135
|
listAgents: AgentsConnection;
|
|
@@ -120,6 +120,7 @@ export type PageInfo = {
|
|
|
120
120
|
};
|
|
121
121
|
export type Query = {
|
|
122
122
|
app?: Maybe<Scalars['DRN']['output']>;
|
|
123
|
+
getHttpEndpoint?: Maybe<Scalars['String']['output']>;
|
|
123
124
|
getMercadoLivreInstance?: Maybe<MercadoLivreInstance>;
|
|
124
125
|
listMercadoLivreInstances: Array<MercadoLivreInstance>;
|
|
125
126
|
version?: Maybe<Scalars['String']['output']>;
|
|
@@ -130,9 +131,6 @@ export type QueryGetMercadoLivreInstanceArgs = {
|
|
|
130
131
|
export type RemoveMercadoLivreInstanceInput = {
|
|
131
132
|
id: Scalars['ID']['input'];
|
|
132
133
|
};
|
|
133
|
-
export type Subscription = {
|
|
134
|
-
version?: Maybe<Scalars['String']['output']>;
|
|
135
|
-
};
|
|
136
134
|
export declare enum Typenames {
|
|
137
135
|
Any = "Any",
|
|
138
136
|
GraphqlConnections = "GraphqlConnections",
|
package/src/sdks/nucleus.d.ts
CHANGED
|
@@ -295,6 +295,7 @@ export type Query = {
|
|
|
295
295
|
getCredentials?: Maybe<SafeCredentials>;
|
|
296
296
|
getCredentialsSecret?: Maybe<Credentials>;
|
|
297
297
|
getCronJob?: Maybe<CronJob>;
|
|
298
|
+
getHttpEndpoint?: Maybe<Scalars['String']['output']>;
|
|
298
299
|
getSessionData?: Maybe<Scalars['JSON']['output']>;
|
|
299
300
|
getStateMachineConfig?: Maybe<StateMachineConfig>;
|
|
300
301
|
getXStateMachineConfig?: Maybe<Scalars['JSON']['output']>;
|
|
@@ -427,9 +428,6 @@ export declare enum StateMachineConfigStatus {
|
|
|
427
428
|
Live = "Live",
|
|
428
429
|
Published = "Published"
|
|
429
430
|
}
|
|
430
|
-
export type Subscription = {
|
|
431
|
-
version?: Maybe<Scalars['String']['output']>;
|
|
432
|
-
};
|
|
433
431
|
export declare enum Typenames {
|
|
434
432
|
Any = "Any",
|
|
435
433
|
App = "App",
|
|
@@ -108,6 +108,7 @@ export type PageInfo = {
|
|
|
108
108
|
};
|
|
109
109
|
export type Query = {
|
|
110
110
|
app?: Maybe<Scalars['DRN']['output']>;
|
|
111
|
+
getHttpEndpoint?: Maybe<Scalars['String']['output']>;
|
|
111
112
|
getReclameAquiInstance?: Maybe<ReclameAquiInstance>;
|
|
112
113
|
listReclameAquiInstances: Array<ReclameAquiInstance>;
|
|
113
114
|
version?: Maybe<Scalars['String']['output']>;
|
|
@@ -124,9 +125,6 @@ export type ReclameAquiInstance = {
|
|
|
124
125
|
export type RemoveReclameAquiInstanceInput = {
|
|
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
|
GraphqlConnections = "GraphqlConnections",
|
package/src/sdks/zendesk.d.ts
CHANGED
|
@@ -113,6 +113,7 @@ export type PageInfo = {
|
|
|
113
113
|
};
|
|
114
114
|
export type Query = {
|
|
115
115
|
app?: Maybe<Scalars['DRN']['output']>;
|
|
116
|
+
getHttpEndpoint?: Maybe<Scalars['String']['output']>;
|
|
116
117
|
getZendeskInstance?: Maybe<ZendeskInstance>;
|
|
117
118
|
listZendeskInstances: Array<ZendeskInstance>;
|
|
118
119
|
version?: Maybe<Scalars['String']['output']>;
|
|
@@ -123,9 +124,6 @@ export type QueryGetZendeskInstanceArgs = {
|
|
|
123
124
|
export type RemoveZendeskInstanceInput = {
|
|
124
125
|
id: Scalars['ID']['input'];
|
|
125
126
|
};
|
|
126
|
-
export type Subscription = {
|
|
127
|
-
version?: Maybe<Scalars['String']['output']>;
|
|
128
|
-
};
|
|
129
127
|
export declare enum Typenames {
|
|
130
128
|
Any = "Any",
|
|
131
129
|
GraphqlConnections = "GraphqlConnections",
|
package/src/zendesk.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './sdks/zendesk';
|
|
2
2
|
export declare const Zendesk: new () => {
|
|
3
|
+
readonly http: any;
|
|
4
|
+
forTenant(tenant: string): void;
|
|
5
|
+
withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): void;
|
|
6
|
+
} & {
|
|
3
7
|
getZendeskInstance(variables: import("./sdks/zendesk").Exact<{
|
|
4
8
|
id: string;
|
|
5
9
|
}>, options?: unknown): Promise<import("./sdks/zendesk").GetZendeskInstanceQuery>;
|
package/src/client/utils.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { ExecutionResult } from 'graphql';
|
|
2
|
-
export declare function mapGraphqlResponse<T>(response: ExecutionResult<T> | Error): T;
|
|
3
|
-
export declare function mapAsyncIterableGraphqlResponse<T>(iterable: AsyncIterableIterator<ExecutionResult<T, any>>): AsyncGenerator<Awaited<T>, void, unknown>;
|
package/src/client/utils.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapAsyncIterableGraphqlResponse = exports.mapGraphqlResponse = void 0;
|
|
4
|
-
function mapGraphqlResponse(response) {
|
|
5
|
-
if (response && 'stack' in response && 'message' in response)
|
|
6
|
-
throw response;
|
|
7
|
-
if ('errors' in response)
|
|
8
|
-
console.error(JSON.stringify(response.errors));
|
|
9
|
-
if ('data' in response)
|
|
10
|
-
return response.data;
|
|
11
|
-
}
|
|
12
|
-
exports.mapGraphqlResponse = mapGraphqlResponse;
|
|
13
|
-
async function* mapAsyncIterableGraphqlResponse(iterable) {
|
|
14
|
-
for await (const each of iterable) {
|
|
15
|
-
yield mapGraphqlResponse(each);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.mapAsyncIterableGraphqlResponse = mapAsyncIterableGraphqlResponse;
|