@webuildbots/webuildbots-sdk 11.0.0 → 11.1.1

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/lib/index.d.ts CHANGED
@@ -23,4 +23,6 @@ import ResponseBuilder from './builder/response-builder';
23
23
  import { WebhookRequest, WebhookResponse, ResponseUnitType, ResponseUnit, BlockPointer, Client, JWTPayload } from './interfaces/webhook';
24
24
  import LogicBB from './builder/block/logic-bb';
25
25
  import ImageBB from './builder/block/image-bb';
26
- export { BlockBuilder, ComplexBB, FunctionBB, EmailFormTableBB, UnsetFormBB, MediaBB, ImageBB, SelectBB, TextBB, VideoBB, DevSwitchBB, LogicBB, BlockCB, ChoiceBuilder, DefinedCB, DefinedIB, ExtensionCB, LocationCB, PhoneCB, UrlCB, GalleryBB, BasicBB, ItemBuilder, WebhookResponse, WebhookRequest, ResponseUnit, ResponseUnitType, BlockPointer, ResponseBuilder, Client, JWTPayload };
26
+ import ResponseService from './services/ResponseService';
27
+ import IntentService from './services/IntentService';
28
+ export { BlockBuilder, ComplexBB, FunctionBB, EmailFormTableBB, UnsetFormBB, MediaBB, ImageBB, SelectBB, TextBB, VideoBB, DevSwitchBB, LogicBB, BlockCB, ChoiceBuilder, DefinedCB, DefinedIB, ExtensionCB, LocationCB, PhoneCB, UrlCB, GalleryBB, BasicBB, ItemBuilder, WebhookResponse, WebhookRequest, ResponseUnit, ResponseUnitType, BlockPointer, ResponseBuilder, Client, JWTPayload, ResponseService, IntentService };
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ResponseBuilder = exports.ResponseUnitType = exports.ItemBuilder = exports.BasicBB = exports.GalleryBB = exports.UrlCB = exports.PhoneCB = exports.LocationCB = exports.ExtensionCB = exports.DefinedIB = exports.DefinedCB = exports.ChoiceBuilder = exports.BlockCB = exports.LogicBB = exports.DevSwitchBB = exports.VideoBB = exports.TextBB = exports.SelectBB = exports.ImageBB = exports.MediaBB = exports.UnsetFormBB = exports.EmailFormTableBB = exports.FunctionBB = exports.ComplexBB = exports.BlockBuilder = void 0;
6
+ exports.IntentService = exports.ResponseService = exports.ResponseBuilder = exports.ResponseUnitType = exports.ItemBuilder = exports.BasicBB = exports.GalleryBB = exports.UrlCB = exports.PhoneCB = exports.LocationCB = exports.ExtensionCB = exports.DefinedIB = exports.DefinedCB = exports.ChoiceBuilder = exports.BlockCB = exports.LogicBB = exports.DevSwitchBB = exports.VideoBB = exports.TextBB = exports.SelectBB = exports.ImageBB = exports.MediaBB = exports.UnsetFormBB = exports.EmailFormTableBB = exports.FunctionBB = exports.ComplexBB = exports.BlockBuilder = void 0;
7
7
  var block_builder_1 = __importDefault(require("./builder/block/block-builder"));
8
8
  exports.BlockBuilder = block_builder_1.default;
9
9
  var basic_bb_1 = __importDefault(require("./builder/block/basic-bb"));
@@ -54,3 +54,7 @@ var logic_bb_1 = __importDefault(require("./builder/block/logic-bb"));
54
54
  exports.LogicBB = logic_bb_1.default;
55
55
  var image_bb_1 = __importDefault(require("./builder/block/image-bb"));
56
56
  exports.ImageBB = image_bb_1.default;
57
+ var ResponseService_1 = __importDefault(require("./services/ResponseService"));
58
+ exports.ResponseService = ResponseService_1.default;
59
+ var IntentService_1 = __importDefault(require("./services/IntentService"));
60
+ exports.IntentService = IntentService_1.default;
@@ -0,0 +1,12 @@
1
+ export default class ApiService {
2
+ private sdkToken;
3
+ private baseURL;
4
+ constructor(sdkToken: any, rootURL?: string);
5
+ hitApi(endpoint: any, client: any, options: any): Promise<{
6
+ data: any;
7
+ error: any;
8
+ } | {
9
+ data: any;
10
+ error: any;
11
+ }>;
12
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ var cross_fetch_1 = __importDefault(require("cross-fetch"));
54
+ var ApiService = /** @class */ (function () {
55
+ function ApiService(sdkToken, rootURL) {
56
+ if (rootURL === void 0) { rootURL = 'https://backend.logicdialog.ai'; }
57
+ this.sdkToken = sdkToken;
58
+ this.sdkToken = sdkToken;
59
+ this.baseURL = rootURL;
60
+ }
61
+ ApiService.prototype.hitApi = function (endpoint, client, options) {
62
+ return __awaiter(this, void 0, void 0, function () {
63
+ var response, data, error_1, errorResponse;
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
66
+ case 0:
67
+ _a.trys.push([0, 3, , 4]);
68
+ return [4 /*yield*/, cross_fetch_1.default(this.baseURL + "/" + endpoint, __assign(__assign({}, options), { body: JSON.stringify(options.body), headers: __assign({ Authorization: 'Bearer ' + this.sdkToken, 'content-type': 'application/json', Accept: 'application/json', 'wbb-client': client }, options.headers) }))];
69
+ case 1:
70
+ response = _a.sent();
71
+ if (!response.ok) {
72
+ throw new Error("HTTP error " + response.status);
73
+ }
74
+ return [4 /*yield*/, response.json()];
75
+ case 2:
76
+ data = _a.sent();
77
+ return [2 /*return*/, { data: data, error: null }];
78
+ case 3:
79
+ error_1 = _a.sent();
80
+ errorResponse = {
81
+ errorMessage: error_1
82
+ };
83
+ return [2 /*return*/, { data: null, error: error_1 || errorResponse }];
84
+ case 4: return [2 /*return*/];
85
+ }
86
+ });
87
+ });
88
+ };
89
+ return ApiService;
90
+ }());
91
+ exports.default = ApiService;
@@ -0,0 +1,15 @@
1
+ export default class IntentService {
2
+ private apiService;
3
+ private client;
4
+ constructor(token: any, client: any, rootURL: any);
5
+ createIntent(title: string, utterances: string[], name: string, groups?: string[], parentName?: string, module?: string, isWbbDocument?: boolean): Promise<any>;
6
+ updateIntent(_id: string, title: string, utterances: string[], name: string, created: string, groups?: string[], parentName?: string, module?: string, isWbbDocument?: boolean): Promise<any>;
7
+ getIntents(searchText?: string): Promise<any>;
8
+ deleteIntent(_id: string): Promise<any>;
9
+ createMapping(block: {
10
+ blockId: string;
11
+ module?: string;
12
+ }, intentId: string): Promise<any>;
13
+ deleteMapping(_id: string): Promise<any>;
14
+ getMappings(responseId?: string): Promise<any>;
15
+ }
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var ApiService_1 = __importDefault(require("./ApiService"));
43
+ var IntentService = /** @class */ (function () {
44
+ function IntentService(token, client, rootURL) {
45
+ this.apiService = new ApiService_1.default(token, rootURL);
46
+ this.client = client;
47
+ }
48
+ IntentService.prototype.createIntent = function (title, utterances, name, groups, parentName, module, isWbbDocument) {
49
+ return __awaiter(this, void 0, void 0, function () {
50
+ var intent, res, options, e_1;
51
+ return __generator(this, function (_a) {
52
+ switch (_a.label) {
53
+ case 0:
54
+ intent = {
55
+ title: title,
56
+ utterances: utterances,
57
+ name: name,
58
+ created: new Date(),
59
+ groups: groups,
60
+ parentName: parentName,
61
+ module: module,
62
+ isWbbDocument: isWbbDocument
63
+ };
64
+ options = {
65
+ method: 'POST',
66
+ body: intent
67
+ };
68
+ _a.label = 1;
69
+ case 1:
70
+ _a.trys.push([1, 3, , 4]);
71
+ return [4 /*yield*/, this.apiService.hitApi('api/agent/knowlbase/intent', this.client, options)];
72
+ case 2:
73
+ res = _a.sent();
74
+ return [3 /*break*/, 4];
75
+ case 3:
76
+ e_1 = _a.sent();
77
+ throw Error(e_1);
78
+ case 4: return [2 /*return*/, res];
79
+ }
80
+ });
81
+ });
82
+ };
83
+ IntentService.prototype.updateIntent = function (_id, title, utterances, name, created, groups, parentName, module, isWbbDocument) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var intent, res, options, e_2;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ intent = {
90
+ title: title,
91
+ utterances: utterances,
92
+ name: name,
93
+ groups: groups,
94
+ parentName: parentName,
95
+ module: module,
96
+ isWbbDocument: isWbbDocument,
97
+ created: created
98
+ };
99
+ options = {
100
+ method: 'PUT',
101
+ body: intent
102
+ };
103
+ _a.label = 1;
104
+ case 1:
105
+ _a.trys.push([1, 3, , 4]);
106
+ return [4 /*yield*/, this.apiService.hitApi('api/agent/knowlbase/intent/' + _id, this.client, options)];
107
+ case 2:
108
+ res = _a.sent();
109
+ return [3 /*break*/, 4];
110
+ case 3:
111
+ e_2 = _a.sent();
112
+ throw Error(e_2);
113
+ case 4: return [2 /*return*/, res];
114
+ }
115
+ });
116
+ });
117
+ };
118
+ IntentService.prototype.getIntents = function (searchText) {
119
+ return __awaiter(this, void 0, void 0, function () {
120
+ var res, options, query, endpoint, e_3;
121
+ return __generator(this, function (_a) {
122
+ switch (_a.label) {
123
+ case 0:
124
+ options = {
125
+ method: 'GET'
126
+ };
127
+ query = "?q=" + searchText;
128
+ endpoint = 'api/agent/knowlbase/intent';
129
+ _a.label = 1;
130
+ case 1:
131
+ _a.trys.push([1, 3, , 4]);
132
+ return [4 /*yield*/, this.apiService.hitApi(searchText ? endpoint + query : endpoint, this.client, options)];
133
+ case 2:
134
+ res = _a.sent();
135
+ return [3 /*break*/, 4];
136
+ case 3:
137
+ e_3 = _a.sent();
138
+ throw Error(e_3);
139
+ case 4: return [2 /*return*/, res];
140
+ }
141
+ });
142
+ });
143
+ };
144
+ IntentService.prototype.deleteIntent = function (_id) {
145
+ return __awaiter(this, void 0, void 0, function () {
146
+ var res, options, e_4;
147
+ return __generator(this, function (_a) {
148
+ switch (_a.label) {
149
+ case 0:
150
+ options = {
151
+ method: 'DELETE'
152
+ };
153
+ _a.label = 1;
154
+ case 1:
155
+ _a.trys.push([1, 3, , 4]);
156
+ return [4 /*yield*/, this.apiService.hitApi('api/agent/knowlbase/intent/' + _id, this.client, options)];
157
+ case 2:
158
+ res = _a.sent();
159
+ return [3 /*break*/, 4];
160
+ case 3:
161
+ e_4 = _a.sent();
162
+ throw Error(e_4);
163
+ case 4: return [2 /*return*/, res];
164
+ }
165
+ });
166
+ });
167
+ };
168
+ IntentService.prototype.createMapping = function (block, intentId) {
169
+ return __awaiter(this, void 0, void 0, function () {
170
+ var res, options, e_5;
171
+ return __generator(this, function (_a) {
172
+ switch (_a.label) {
173
+ case 0:
174
+ options = {
175
+ method: 'POST',
176
+ body: {
177
+ block: block,
178
+ intentId: intentId
179
+ }
180
+ };
181
+ _a.label = 1;
182
+ case 1:
183
+ _a.trys.push([1, 3, , 4]);
184
+ return [4 /*yield*/, this.apiService.hitApi('api/agent/knowlbase/intent-mapping', this.client, options)];
185
+ case 2:
186
+ res = _a.sent();
187
+ return [3 /*break*/, 4];
188
+ case 3:
189
+ e_5 = _a.sent();
190
+ throw Error(e_5);
191
+ case 4: return [2 /*return*/, res];
192
+ }
193
+ });
194
+ });
195
+ };
196
+ IntentService.prototype.deleteMapping = function (_id) {
197
+ return __awaiter(this, void 0, void 0, function () {
198
+ var res, options, e_6;
199
+ return __generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0:
202
+ options = {
203
+ method: 'DELETE'
204
+ };
205
+ _a.label = 1;
206
+ case 1:
207
+ _a.trys.push([1, 3, , 4]);
208
+ return [4 /*yield*/, this.apiService.hitApi('api/agent/knowlbase/intent-mapping/' + _id, this.client, options)];
209
+ case 2:
210
+ res = _a.sent();
211
+ return [3 /*break*/, 4];
212
+ case 3:
213
+ e_6 = _a.sent();
214
+ throw Error(e_6);
215
+ case 4: return [2 /*return*/, res];
216
+ }
217
+ });
218
+ });
219
+ };
220
+ IntentService.prototype.getMappings = function (responseId) {
221
+ return __awaiter(this, void 0, void 0, function () {
222
+ var res, options, e_7;
223
+ return __generator(this, function (_a) {
224
+ switch (_a.label) {
225
+ case 0:
226
+ options = {
227
+ method: 'GET'
228
+ };
229
+ _a.label = 1;
230
+ case 1:
231
+ _a.trys.push([1, 3, , 4]);
232
+ return [4 /*yield*/, this.apiService.hitApi('api/agent/knowlbase/intent-mapping', this.client, options)];
233
+ case 2:
234
+ res = _a.sent();
235
+ return [3 /*break*/, 4];
236
+ case 3:
237
+ e_7 = _a.sent();
238
+ throw Error(e_7);
239
+ case 4:
240
+ if (res && responseId) {
241
+ res = res.filter(function (mapping) { return mapping.block.blockId == responseId; });
242
+ }
243
+ return [2 /*return*/, res];
244
+ }
245
+ });
246
+ });
247
+ };
248
+ return IntentService;
249
+ }());
250
+ exports.default = IntentService;
@@ -0,0 +1,23 @@
1
+ import { BlockTypes } from '../const/block-enums';
2
+ import { Languages } from '../const/languages-enums';
3
+ export default class ResponseService {
4
+ private apiService;
5
+ private client;
6
+ constructor(token: any, client: any, rootURL: any);
7
+ createResponse(title: {
8
+ language: Languages;
9
+ value: string;
10
+ }, module: string, description: string, type: BlockTypes, name?: import("../const/block-enums").CommonGroups, group?: import("../const/block-enums").CommonGroups, variable?: {
11
+ title: string;
12
+ value: string;
13
+ }, formFieldCallbackArgs?: any, next?: string): Promise<any>;
14
+ updateResponse(blockId: any, title?: {
15
+ language: Languages;
16
+ value: string;
17
+ }, module?: string, description?: string, type?: BlockTypes, name?: string, group?: string, variable?: {
18
+ title: string;
19
+ value: string;
20
+ }, formFieldCallbackArgs?: any, next?: string): Promise<any>;
21
+ deleteResponse(blockId: any): Promise<any>;
22
+ getResponses(searchText?: string, types?: any[], groups?: any[]): Promise<any>;
23
+ }
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ var __1 = require("..");
54
+ var ApiService_1 = __importDefault(require("./ApiService"));
55
+ var ResponseService = /** @class */ (function () {
56
+ function ResponseService(token, client, rootURL) {
57
+ this.apiService = new ApiService_1.default(token, rootURL);
58
+ this.client = client;
59
+ }
60
+ ResponseService.prototype.createResponse = function (title, module, description, type, name, group, variable, formFieldCallbackArgs, next) {
61
+ if (name === void 0) { name = __1.BlockBuilder.DEFAULT_NAME; }
62
+ if (group === void 0) { group = __1.BlockBuilder.DEFAULT_GROUP; }
63
+ return __awaiter(this, void 0, void 0, function () {
64
+ var block, res, options, e_1;
65
+ var _a;
66
+ return __generator(this, function (_b) {
67
+ switch (_b.label) {
68
+ case 0:
69
+ block = {
70
+ name: name,
71
+ type: type,
72
+ group: group,
73
+ version: __1.BlockBuilder.VERSION,
74
+ created: new Date(),
75
+ content: {
76
+ title: (_a = {}, _a[title.language] = title.value, _a)
77
+ },
78
+ module: module,
79
+ meta: {
80
+ description: description
81
+ },
82
+ variables: [__assign({}, variable)],
83
+ formFieldCallback: formFieldCallbackArgs,
84
+ next: next
85
+ };
86
+ options = {
87
+ method: 'POST',
88
+ body: block,
89
+ headers: { 'content-type': 'multipart/form-data' }
90
+ };
91
+ _b.label = 1;
92
+ case 1:
93
+ _b.trys.push([1, 3, , 4]);
94
+ return [4 /*yield*/, this.apiService.hitApi('api/agent/block', this.client, options)];
95
+ case 2:
96
+ res = _b.sent();
97
+ return [3 /*break*/, 4];
98
+ case 3:
99
+ e_1 = _b.sent();
100
+ throw Error(e_1);
101
+ case 4: return [2 /*return*/, res];
102
+ }
103
+ });
104
+ });
105
+ };
106
+ ResponseService.prototype.updateResponse = function (blockId, title, module, description, type, name, group, variable, formFieldCallbackArgs, next) {
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ var res, options, e_2;
109
+ var _a;
110
+ return __generator(this, function (_b) {
111
+ switch (_b.label) {
112
+ case 0:
113
+ options = {
114
+ method: 'PUT',
115
+ body: {
116
+ name: name,
117
+ type: type,
118
+ group: group,
119
+ content: {
120
+ title: (_a = {}, _a[title.language] = title.value, _a)
121
+ },
122
+ module: module,
123
+ meta: {
124
+ description: description
125
+ },
126
+ variables: [__assign({}, variable)],
127
+ formFieldCallback: formFieldCallbackArgs,
128
+ next: next
129
+ },
130
+ headers: { 'content-type': 'multipart/form-data' }
131
+ };
132
+ _b.label = 1;
133
+ case 1:
134
+ _b.trys.push([1, 3, , 4]);
135
+ return [4 /*yield*/, this.apiService.hitApi('api/agent/block/' + blockId, this.client, options)];
136
+ case 2:
137
+ res = _b.sent();
138
+ return [3 /*break*/, 4];
139
+ case 3:
140
+ e_2 = _b.sent();
141
+ throw Error(e_2);
142
+ case 4: return [2 /*return*/, res];
143
+ }
144
+ });
145
+ });
146
+ };
147
+ ResponseService.prototype.deleteResponse = function (blockId) {
148
+ return __awaiter(this, void 0, void 0, function () {
149
+ var res, options, e_3;
150
+ return __generator(this, function (_a) {
151
+ switch (_a.label) {
152
+ case 0:
153
+ options = {
154
+ method: 'DELETE'
155
+ };
156
+ _a.label = 1;
157
+ case 1:
158
+ _a.trys.push([1, 3, , 4]);
159
+ return [4 /*yield*/, this.apiService.hitApi('api/agent/block/' + blockId, this.client, options)];
160
+ case 2:
161
+ res = _a.sent();
162
+ return [3 /*break*/, 4];
163
+ case 3:
164
+ e_3 = _a.sent();
165
+ throw Error(e_3);
166
+ case 4: return [2 /*return*/, res];
167
+ }
168
+ });
169
+ });
170
+ };
171
+ ResponseService.prototype.getResponses = function (searchText, types, groups) {
172
+ if (searchText === void 0) { searchText = ''; }
173
+ if (types === void 0) { types = []; }
174
+ if (groups === void 0) { groups = []; }
175
+ return __awaiter(this, void 0, void 0, function () {
176
+ var res, query, _i, types_1, type, _a, groups_1, group, options, e_4;
177
+ return __generator(this, function (_b) {
178
+ switch (_b.label) {
179
+ case 0:
180
+ query = "?searchText=" + searchText;
181
+ if (types.length) {
182
+ for (_i = 0, types_1 = types; _i < types_1.length; _i++) {
183
+ type = types_1[_i];
184
+ query + ("&type[]=" + type);
185
+ }
186
+ }
187
+ if (groups.length) {
188
+ for (_a = 0, groups_1 = groups; _a < groups_1.length; _a++) {
189
+ group = groups_1[_a];
190
+ query + ("&group[]=" + group);
191
+ }
192
+ }
193
+ options = {
194
+ method: 'GET'
195
+ };
196
+ _b.label = 1;
197
+ case 1:
198
+ _b.trys.push([1, 3, , 4]);
199
+ return [4 /*yield*/, this.apiService.hitApi('api/agent/block/' + query, this.client, options)];
200
+ case 2:
201
+ res = _b.sent();
202
+ return [3 /*break*/, 4];
203
+ case 3:
204
+ e_4 = _b.sent();
205
+ throw Error(e_4);
206
+ case 4: return [2 /*return*/, res];
207
+ }
208
+ });
209
+ });
210
+ };
211
+ return ResponseService;
212
+ }());
213
+ exports.default = ResponseService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webuildbots/webuildbots-sdk",
3
- "version": "11.0.0",
3
+ "version": "11.1.1",
4
4
  "description": "webuildbots sdk",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -54,6 +54,7 @@
54
54
  "dependencies": {
55
55
  "@types/json-logic-js": "^1.2.1",
56
56
  "bson-objectid": "^1.3.1",
57
+ "cross-fetch": "^3.1.5",
57
58
  "deep-equal": "^2.0.4",
58
59
  "flatted": "^3.1.0",
59
60
  "http-status-codes": "^2.1.4",
File without changes
File without changes
@@ -1,6 +0,0 @@
1
- interface Address1And2 {
2
- address1: string;
3
- address2: string;
4
- }
5
- export declare const compareAddress: (a: Address1And2, b: Address1And2) => boolean;
6
- export {};
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compareAddress = void 0;
4
- var string_utils_1 = require("./string-utils");
5
- var compareAddress = function (a, b) {
6
- return (string_utils_1.eqIgnoreCaseAndPunctuations(a.address1, b.address1) ||
7
- string_utils_1.eqIgnoreCaseAndPunctuations(a.address1, b.address1 + " " + b.address2) ||
8
- string_utils_1.eqIgnoreCaseAndPunctuations(a.address1 + " " + a.address2, b.address1) ||
9
- string_utils_1.eqIgnoreCaseAndPunctuations(a.address1 + " " + a.address2, b.address1 + " " + b.address2));
10
- };
11
- exports.compareAddress = compareAddress;
@@ -1,14 +0,0 @@
1
- /**
2
- * Strip emojis and punctuation from {@code s}
3
- *
4
- * @param s
5
- */
6
- export declare function stripEmojiPunc(s: string): string;
7
- /**
8
- * Fill a given path with parameters by replacing the placeholder
9
- * @param path e.g. /user/{id}/edit
10
- * @param params key-value pair
11
- */
12
- export declare const fillPath: (path: string, params: Record<string, any>) => string;
13
- export declare const removeNonAlphaNum: (s: string) => string;
14
- export declare const eqIgnoreCaseAndPunctuations: (a: string, b: string) => boolean;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.eqIgnoreCaseAndPunctuations = exports.removeNonAlphaNum = exports.fillPath = exports.stripEmojiPunc = void 0;
7
- var emoji_regex_1 = __importDefault(require("emoji-regex"));
8
- var emojiRE = emoji_regex_1.default();
9
- /**
10
- * Strip emojis and punctuation from {@code s}
11
- *
12
- * @param s
13
- */
14
- function stripEmojiPunc(s) {
15
- return s.replace(/[.,/#!$%^&*;:{}=\-_`~()]/g, '').replace(emojiRE, '');
16
- }
17
- exports.stripEmojiPunc = stripEmojiPunc;
18
- /**
19
- * Fill a given path with parameters by replacing the placeholder
20
- * @param path e.g. /user/{id}/edit
21
- * @param params key-value pair
22
- */
23
- var fillPath = function (path, params) {
24
- for (var _i = 0, _a = Object.keys(params); _i < _a.length; _i++) {
25
- var key = _a[_i];
26
- path = path.replace(new RegExp("{" + key + "}", 'g'), params[key]);
27
- }
28
- return path;
29
- };
30
- exports.fillPath = fillPath;
31
- // remove any non alphabet or number character
32
- var removeNonAlphaNum = function (s) { return s.replace(/[^A-z0-9]/g, ''); };
33
- exports.removeNonAlphaNum = removeNonAlphaNum;
34
- var eqIgnoreCaseAndPunctuations = function (a, b) {
35
- return exports.removeNonAlphaNum(a).toLowerCase() === exports.removeNonAlphaNum(b).toLowerCase();
36
- };
37
- exports.eqIgnoreCaseAndPunctuations = eqIgnoreCaseAndPunctuations;