@or-sdk/identifiers 0.10.0 → 0.13.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.
Files changed (39) hide show
  1. package/dist/cjs/Identifiers.js +124 -74
  2. package/dist/cjs/Identifiers.js.map +1 -1
  3. package/dist/cjs/constants.js +0 -3
  4. package/dist/cjs/constants.js.map +1 -1
  5. package/dist/cjs/utils/getGroupIdentifiers.js +7 -0
  6. package/dist/cjs/utils/getGroupIdentifiers.js.map +1 -0
  7. package/dist/cjs/utils/getSingleIdentifiers.js +7 -0
  8. package/dist/cjs/utils/getSingleIdentifiers.js.map +1 -0
  9. package/dist/cjs/utils/index.js +7 -1
  10. package/dist/cjs/utils/index.js.map +1 -1
  11. package/dist/cjs/utils/makeIdentifierGroups.js +31 -0
  12. package/dist/cjs/utils/makeIdentifierGroups.js.map +1 -0
  13. package/dist/esm/Identifiers.js +53 -27
  14. package/dist/esm/Identifiers.js.map +1 -1
  15. package/dist/esm/constants.js +1 -1
  16. package/dist/esm/constants.js.map +1 -1
  17. package/dist/esm/utils/getGroupIdentifiers.js +5 -0
  18. package/dist/esm/utils/getGroupIdentifiers.js.map +1 -0
  19. package/dist/esm/utils/getSingleIdentifiers.js +5 -0
  20. package/dist/esm/utils/getSingleIdentifiers.js.map +1 -0
  21. package/dist/esm/utils/index.js +3 -0
  22. package/dist/esm/utils/index.js.map +1 -1
  23. package/dist/esm/utils/makeIdentifierGroups.js +15 -0
  24. package/dist/esm/utils/makeIdentifierGroups.js.map +1 -0
  25. package/dist/types/Identifiers.d.ts +10 -6
  26. package/dist/types/constants.d.ts +0 -1
  27. package/dist/types/types.d.ts +17 -6
  28. package/dist/types/utils/getGroupIdentifiers.d.ts +3 -0
  29. package/dist/types/utils/getSingleIdentifiers.d.ts +3 -0
  30. package/dist/types/utils/index.d.ts +3 -0
  31. package/dist/types/utils/makeIdentifierGroups.d.ts +3 -0
  32. package/package.json +4 -3
  33. package/src/Identifiers.ts +76 -36
  34. package/src/constants.ts +0 -1
  35. package/src/types.ts +20 -6
  36. package/src/utils/getGroupIdentifiers.ts +10 -0
  37. package/src/utils/getSingleIdentifiers.ts +10 -0
  38. package/src/utils/index.ts +3 -0
  39. package/src/utils/makeIdentifierGroups.ts +27 -0
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -53,55 +38,102 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
53
38
  Object.defineProperty(exports, "__esModule", { value: true });
54
39
  exports.Identifiers = void 0;
55
40
  var base_1 = require("@or-sdk/base");
56
- var constants_1 = require("./constants");
41
+ var sdk_api_1 = require("@or-sdk/sdk-api");
57
42
  var utils_1 = require("./utils");
58
- var Identifiers = (function (_super) {
59
- __extends(Identifiers, _super);
43
+ var Identifiers = (function () {
60
44
  function Identifiers(params) {
61
- var _this = this;
62
45
  var token = params.token, discoveryUrl = params.discoveryUrl;
63
- _this = _super.call(this, {
46
+ this.sdkApi = new sdk_api_1.SdkApi({
64
47
  token: token,
65
48
  discoveryUrl: discoveryUrl,
66
- serviceKey: constants_1.SERVICE_KEY,
67
- }) || this;
68
- return _this;
49
+ });
69
50
  }
70
- Identifiers.prototype.makeApiUrl = function (data) {
71
- return "".concat(data.url, "/http/provider");
51
+ Identifiers.prototype.init = function () {
52
+ return __awaiter(this, void 0, void 0, function () {
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0: return [4, this.sdkApi.init()];
56
+ case 1:
57
+ _a.sent();
58
+ return [2];
59
+ }
60
+ });
61
+ });
72
62
  };
73
- Identifiers.prototype.listIdentifiers = function (id) {
63
+ Identifiers.prototype.fetchIdentifiers = function (id, groupDetails) {
64
+ if (groupDetails === void 0) { groupDetails = true; }
74
65
  return __awaiter(this, void 0, void 0, function () {
75
- var params, result;
66
+ var params;
67
+ return __generator(this, function (_a) {
68
+ params = {
69
+ fullInfo: true,
70
+ groupDetails: groupDetails,
71
+ identifier: id ? id : undefined,
72
+ };
73
+ return [2, this.sdkApi.makeRequest({
74
+ method: 'GET',
75
+ route: '/http/provider/identifiers',
76
+ params: params,
77
+ })];
78
+ });
79
+ });
80
+ };
81
+ Identifiers.prototype.listIdentifiers = function () {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ var result;
76
84
  return __generator(this, function (_a) {
77
85
  switch (_a.label) {
78
- case 0:
79
- params = {
80
- fullInfo: true,
81
- groupDetails: true,
82
- identifier: id ? id : undefined,
83
- };
84
- return [4, this.callApi({
85
- method: 'GET',
86
- route: '/identifiers',
87
- params: params,
88
- })];
86
+ case 0: return [4, this.fetchIdentifiers()];
89
87
  case 1:
90
88
  result = _a.sent();
91
- return [2, (0, base_1.makeList)(result)];
89
+ return [2, (0, base_1.makeList)((0, utils_1.getSingleIdentifiers)(result))];
92
90
  }
93
91
  });
94
92
  });
95
93
  };
96
- Identifiers.prototype.getIdentifier = function (id) {
94
+ Identifiers.prototype.listIdentifierGroups = function () {
97
95
  return __awaiter(this, void 0, void 0, function () {
98
96
  var result;
99
97
  return __generator(this, function (_a) {
100
98
  switch (_a.label) {
101
- case 0: return [4, this.listIdentifiers(id)];
99
+ case 0: return [4, this.fetchIdentifiers()];
100
+ case 1:
101
+ result = _a.sent();
102
+ return [2, (0, base_1.makeList)((0, utils_1.makeIdentifierGroups)(result))];
103
+ }
104
+ });
105
+ });
106
+ };
107
+ Identifiers.prototype.getIdentifier = function (id) {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var result, singleIdentifiers;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0: return [4, this.fetchIdentifiers(id, false)];
113
+ case 1:
114
+ result = _a.sent();
115
+ singleIdentifiers = (0, utils_1.getSingleIdentifiers)(result);
116
+ if (singleIdentifiers.length === 0) {
117
+ throw "Id ".concat(id, " doesn't belong to an identifier");
118
+ }
119
+ return [2, singleIdentifiers[0]];
120
+ }
121
+ });
122
+ });
123
+ };
124
+ Identifiers.prototype.getIdentifierGroup = function (id) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var result, groupIdentifiers;
127
+ return __generator(this, function (_a) {
128
+ switch (_a.label) {
129
+ case 0: return [4, this.fetchIdentifiers(id)];
102
130
  case 1:
103
131
  result = _a.sent();
104
- return [2, result.rows[0]];
132
+ groupIdentifiers = (0, utils_1.getGroupIdentifiers)(result);
133
+ if (groupIdentifiers.length === 0) {
134
+ throw "Id ".concat(id, " doesn't belong to an identifier group");
135
+ }
136
+ return [2, (0, utils_1.makeIdentifierGroups)(result)[0]];
105
137
  }
106
138
  });
107
139
  });
@@ -112,9 +144,9 @@ var Identifiers = (function (_super) {
112
144
  var result;
113
145
  return __generator(this, function (_a) {
114
146
  switch (_a.label) {
115
- case 0: return [4, this.callApi({
147
+ case 0: return [4, this.sdkApi.makeRequest({
116
148
  method: 'GET',
117
- route: '/obtainable-identifiers',
149
+ route: '/http/provider/obtainable-identifiers',
118
150
  params: params,
119
151
  })];
120
152
  case 1:
@@ -128,14 +160,20 @@ var Identifiers = (function (_super) {
128
160
  return __awaiter(this, void 0, void 0, function () {
129
161
  var params;
130
162
  return __generator(this, function (_a) {
131
- params = {
132
- identifier: id,
133
- };
134
- return [2, this.callApi({
135
- method: 'DELETE',
136
- route: '/identifiers',
137
- params: params,
138
- })];
163
+ switch (_a.label) {
164
+ case 0:
165
+ params = {
166
+ identifier: id,
167
+ };
168
+ return [4, this.sdkApi.makeRequest({
169
+ method: 'DELETE',
170
+ route: '/http/provider/identifiers',
171
+ params: params,
172
+ })];
173
+ case 1:
174
+ _a.sent();
175
+ return [2];
176
+ }
139
177
  });
140
178
  });
141
179
  };
@@ -146,9 +184,9 @@ var Identifiers = (function (_super) {
146
184
  data = {
147
185
  identifiers: Array.isArray(identifiers) ? identifiers : [identifiers],
148
186
  };
149
- return [2, this.callApi({
187
+ return [2, this.sdkApi.makeRequest({
150
188
  method: 'POST',
151
- route: '/identifiers',
189
+ route: '/http/provider/identifiers',
152
190
  data: data,
153
191
  })];
154
192
  });
@@ -159,15 +197,21 @@ var Identifiers = (function (_super) {
159
197
  return __awaiter(this, void 0, void 0, function () {
160
198
  var data;
161
199
  return __generator(this, function (_a) {
162
- data = {
163
- provider: provider,
164
- settings: settings,
165
- };
166
- return [2, this.callApi({
167
- method: 'POST',
168
- route: '/identifier-providers',
169
- data: data,
170
- })];
200
+ switch (_a.label) {
201
+ case 0:
202
+ data = {
203
+ provider: provider,
204
+ settings: settings,
205
+ };
206
+ return [4, this.sdkApi.makeRequest({
207
+ method: 'POST',
208
+ route: '/http/provider/identifier-providers',
209
+ data: data,
210
+ })];
211
+ case 1:
212
+ _a.sent();
213
+ return [2];
214
+ }
171
215
  });
172
216
  });
173
217
  };
@@ -176,9 +220,9 @@ var Identifiers = (function (_super) {
176
220
  var data;
177
221
  return __generator(this, function (_a) {
178
222
  switch (_a.label) {
179
- case 0: return [4, this.callApi({
223
+ case 0: return [4, this.sdkApi.makeRequest({
180
224
  method: 'GET',
181
- route: '/identifier-providers',
225
+ route: '/http/provider/identifier-providers',
182
226
  })];
183
227
  case 1:
184
228
  data = _a.sent();
@@ -191,18 +235,24 @@ var Identifiers = (function (_super) {
191
235
  return __awaiter(this, void 0, void 0, function () {
192
236
  var params;
193
237
  return __generator(this, function (_a) {
194
- params = {
195
- provider: provider,
196
- };
197
- return [2, this.callApi({
198
- method: 'DELETE',
199
- route: '/identifier-providers',
200
- params: params,
201
- })];
238
+ switch (_a.label) {
239
+ case 0:
240
+ params = {
241
+ provider: provider,
242
+ };
243
+ return [4, this.sdkApi.makeRequest({
244
+ method: 'DELETE',
245
+ route: '/http/provider/identifier-providers',
246
+ params: params,
247
+ })];
248
+ case 1:
249
+ _a.sent();
250
+ return [2];
251
+ }
202
252
  });
203
253
  });
204
254
  };
205
255
  return Identifiers;
206
- }(base_1.Base));
256
+ }());
207
257
  exports.Identifiers = Identifiers;
208
258
  //# sourceMappingURL=Identifiers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Identifiers.js","sourceRoot":"","sources":["../../src/Identifiers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAA8E;AAQ9E,yCAA0C;AAC1C,iCAA6D;AAS7D;IAAiC,+BAAI;IAOnC,qBAAY,MAAyB;QAArC,iBAQC;QAPS,IAAA,KAAK,GAAmB,MAAM,MAAzB,EAAE,YAAY,GAAK,MAAM,aAAX,CAAY;QAEvC,QAAA,kBAAM;YACJ,KAAK,OAAA;YACL,YAAY,cAAA;YACZ,UAAU,EAAE,uBAAW;SACxB,CAAC,SAAC;;IACL,CAAC;IAED,gCAAU,GAAV,UAAW,IAA8B;QACvC,OAAO,UAAG,IAAI,CAAC,GAAG,mBAAgB,CAAC;IACrC,CAAC;IAUY,qCAAe,GAA5B,UAA6B,EAAqB;;;;;;wBAC1C,MAAM,GAAG;4BACb,QAAQ,EAAE,IAAI;4BACd,YAAY,EAAE,IAAI;4BAClB,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;yBAChC,CAAC;wBAEa,WAAM,IAAI,CAAC,OAAO,CAAe;gCAC9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,yBAAA,EAAA,aAA6C;;;;;;wBACvG,IAAI,GAAG;4BACX,QAAQ,UAAA;4BACR,QAAQ,UAAA;yBACT,CAAC;wBAEF,WAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAO;gCAClC,MAAM,EAAE,MAAM;gCACd,KAAK,EAAE,qCAAqC;gCAC5C,IAAI,MAAA;6BACL,CAAC,EAAA;;wBAJF,SAIE,CAAC;;;;;KACJ;IAQY,mCAAa,GAA1B;;;;;4BACe,WAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAwB;4BAChE,MAAM,EAAE,KAAK;4BACb,KAAK,EAAE,qCAAqC;yBAC7C,CAAC,EAAA;;wBAHI,IAAI,GAAG,SAGX;wBAEF,WAAO,IAAA,0CAAkC,EAAC,IAAI,CAAC,EAAC;;;;KACjD;IAQY,oCAAc,GAA3B,UAA4B,QAAoC;;;;;;wBACxD,MAAM,GAAG;4BACb,QAAQ,UAAA;yBACT,CAAC;wBAEF,WAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAO;gCAClC,MAAM,EAAE,QAAQ;gCAChB,KAAK,EAAE,qCAAqC;gCAC5C,MAAM,QAAA;6BACP,CAAC,EAAA;;wBAJF,SAIE,CAAC;;;;;KACJ;IACH,kBAAC;AAAD,CAAC,AA7MD,IA6MC;AA7MY,kCAAW"}
@@ -1,5 +1,2 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SERVICE_KEY = void 0;
4
- exports.SERVICE_KEY = 'sdk-api';
5
2
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,SAAS,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function getGroupIdentifiers(identifierArr) {
4
+ return identifierArr.filter(function (identifier) { return identifier.isGroup; });
5
+ }
6
+ exports.default = getGroupIdentifiers;
7
+ //# sourceMappingURL=getGroupIdentifiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getGroupIdentifiers.js","sourceRoot":"","sources":["../../../src/utils/getGroupIdentifiers.ts"],"names":[],"mappings":";;AAKA,SAAS,mBAAmB,CAAC,aAA2B;IACtD,OAAO,aAAa,CAAC,MAAM,CAAC,UAAA,UAAU,IAAI,OAAA,UAAU,CAAC,OAAO,EAAlB,CAAkB,CAAC,CAAC;AAChE,CAAC;AAED,kBAAe,mBAAmB,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function getSingleIdentifiers(identifierArr) {
4
+ return identifierArr.filter(function (identifier) { return !identifier.isGroup; });
5
+ }
6
+ exports.default = getSingleIdentifiers;
7
+ //# sourceMappingURL=getSingleIdentifiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSingleIdentifiers.js","sourceRoot":"","sources":["../../../src/utils/getSingleIdentifiers.ts"],"names":[],"mappings":";;AAKA,SAAS,oBAAoB,CAAC,aAA2B;IACvD,OAAO,aAAa,CAAC,MAAM,CAAC,UAAA,UAAU,IAAI,OAAA,CAAC,UAAU,CAAC,OAAO,EAAnB,CAAmB,CAAC,CAAC;AACjE,CAAC;AAED,kBAAe,oBAAoB,CAAC"}
@@ -3,7 +3,13 @@ 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.extractIdentifierProvidersResponse = void 0;
6
+ exports.makeIdentifierGroups = exports.getSingleIdentifiers = exports.getGroupIdentifiers = exports.extractIdentifierProvidersResponse = void 0;
7
7
  var extractIdentifierProvidersResponse_1 = require("./extractIdentifierProvidersResponse");
8
8
  Object.defineProperty(exports, "extractIdentifierProvidersResponse", { enumerable: true, get: function () { return __importDefault(extractIdentifierProvidersResponse_1).default; } });
9
+ var getGroupIdentifiers_1 = require("./getGroupIdentifiers");
10
+ Object.defineProperty(exports, "getGroupIdentifiers", { enumerable: true, get: function () { return __importDefault(getGroupIdentifiers_1).default; } });
11
+ var getSingleIdentifiers_1 = require("./getSingleIdentifiers");
12
+ Object.defineProperty(exports, "getSingleIdentifiers", { enumerable: true, get: function () { return __importDefault(getSingleIdentifiers_1).default; } });
13
+ var makeIdentifierGroups_1 = require("./makeIdentifierGroups");
14
+ Object.defineProperty(exports, "makeIdentifierGroups", { enumerable: true, get: function () { return __importDefault(makeIdentifierGroups_1).default; } });
9
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAGA,2FAAqG;AAA5F,yKAAA,OAAO,OAAsC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAGA,2FAAqG;AAA5F,yKAAA,OAAO,OAAsC;AACtD,6DAAuE;AAA9D,2IAAA,OAAO,OAAuB;AACvC,+DAAyE;AAAhE,6IAAA,OAAO,OAAwB;AACxC,+DAAyE;AAAhE,6IAAA,OAAO,OAAwB"}
@@ -0,0 +1,31 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var lodash_1 = __importDefault(require("lodash"));
18
+ var utils_1 = require("../utils");
19
+ function makeIdentifierGroups(identifierArr) {
20
+ var groupIdentifiers = (0, utils_1.getGroupIdentifiers)(identifierArr);
21
+ var singleIdentifiers = (0, utils_1.getSingleIdentifiers)(identifierArr);
22
+ var identifierGroups = groupIdentifiers.map(function (groupIdentifier) {
23
+ var members = singleIdentifiers.filter(function (identifier) { return identifier.group &&
24
+ identifier.group === groupIdentifier.phoneNumber; });
25
+ var groupCopy = lodash_1.default.clone(groupIdentifier);
26
+ return __assign(__assign({}, groupCopy), { identifiers: members });
27
+ });
28
+ return identifierGroups;
29
+ }
30
+ exports.default = makeIdentifierGroups;
31
+ //# sourceMappingURL=makeIdentifierGroups.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeIdentifierGroups.js","sourceRoot":"","sources":["../../../src/utils/makeIdentifierGroups.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAuB;AAMvB,kCAAqE;AAErE,SAAS,oBAAoB,CAAC,aAA2B;IACvD,IAAM,gBAAgB,GAAG,IAAA,2BAAmB,EAAC,aAAa,CAAC,CAAC;IAC5D,IAAM,iBAAiB,GAAG,IAAA,4BAAoB,EAAC,aAAa,CAAC,CAAC;IAE9D,IAAM,gBAAgB,GAAG,gBAAgB,CAAC,GAAG,CAAC,UAAA,eAAe;QAC3D,IAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,UAAA,UAAU,IAAI,OAAA,UAAU,CAAC,KAAK;YACrE,UAAU,CAAC,KAAK,KAAK,eAAe,CAAC,WAAW,EADK,CACL,CAAC,CAAC;QACpD,IAAM,SAAS,GAAG,gBAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAE3C,6BACK,SAAS,KACZ,WAAW,EAAE,OAAO,IACpB;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,kBAAe,oBAAoB,CAAC"}
@@ -7,47 +7,73 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Base, makeList } from '@or-sdk/base';
11
- import { SERVICE_KEY } from './constants';
12
- import { extractIdentifierProvidersResponse } from './utils';
13
- export class Identifiers extends Base {
10
+ import { makeList } from '@or-sdk/base';
11
+ import { SdkApi } from '@or-sdk/sdk-api';
12
+ import { extractIdentifierProvidersResponse, getSingleIdentifiers, getGroupIdentifiers, makeIdentifierGroups } from './utils';
13
+ export class Identifiers {
14
14
  constructor(params) {
15
15
  const { token, discoveryUrl } = params;
16
- super({
16
+ this.sdkApi = new SdkApi({
17
17
  token,
18
18
  discoveryUrl,
19
- serviceKey: SERVICE_KEY,
20
19
  });
21
20
  }
22
- makeApiUrl(data) {
23
- return `${data.url}/http/provider`;
21
+ init() {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ yield this.sdkApi.init();
24
+ });
24
25
  }
25
- listIdentifiers(id) {
26
+ fetchIdentifiers(id, groupDetails = true) {
26
27
  return __awaiter(this, void 0, void 0, function* () {
27
28
  const params = {
28
29
  fullInfo: true,
29
- groupDetails: true,
30
+ groupDetails,
30
31
  identifier: id ? id : undefined,
31
32
  };
32
- const result = yield this.callApi({
33
+ return this.sdkApi.makeRequest({
33
34
  method: 'GET',
34
- route: '/identifiers',
35
+ route: '/http/provider/identifiers',
35
36
  params,
36
37
  });
37
- return makeList(result);
38
+ });
39
+ }
40
+ listIdentifiers() {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const result = yield this.fetchIdentifiers();
43
+ return makeList(getSingleIdentifiers(result));
44
+ });
45
+ }
46
+ listIdentifierGroups() {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const result = yield this.fetchIdentifiers();
49
+ return makeList(makeIdentifierGroups(result));
38
50
  });
39
51
  }
40
52
  getIdentifier(id) {
41
53
  return __awaiter(this, void 0, void 0, function* () {
42
- const result = yield this.listIdentifiers(id);
43
- return result.rows[0];
54
+ const result = yield this.fetchIdentifiers(id, false);
55
+ const singleIdentifiers = getSingleIdentifiers(result);
56
+ if (singleIdentifiers.length === 0) {
57
+ throw `Id ${id} doesn't belong to an identifier`;
58
+ }
59
+ return singleIdentifiers[0];
60
+ });
61
+ }
62
+ getIdentifierGroup(id) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ const result = yield this.fetchIdentifiers(id);
65
+ const groupIdentifiers = getGroupIdentifiers(result);
66
+ if (groupIdentifiers.length === 0) {
67
+ throw `Id ${id} doesn't belong to an identifier group`;
68
+ }
69
+ return makeIdentifierGroups(result)[0];
44
70
  });
45
71
  }
46
72
  listObtainableIdentifiers(params = {}) {
47
73
  return __awaiter(this, void 0, void 0, function* () {
48
- const result = yield this.callApi({
74
+ const result = yield this.sdkApi.makeRequest({
49
75
  method: 'GET',
50
- route: '/obtainable-identifiers',
76
+ route: '/http/provider/obtainable-identifiers',
51
77
  params,
52
78
  });
53
79
  return makeList(result);
@@ -58,9 +84,9 @@ export class Identifiers extends Base {
58
84
  const params = {
59
85
  identifier: id,
60
86
  };
61
- return this.callApi({
87
+ yield this.sdkApi.makeRequest({
62
88
  method: 'DELETE',
63
- route: '/identifiers',
89
+ route: '/http/provider/identifiers',
64
90
  params,
65
91
  });
66
92
  });
@@ -70,9 +96,9 @@ export class Identifiers extends Base {
70
96
  const data = {
71
97
  identifiers: Array.isArray(identifiers) ? identifiers : [identifiers],
72
98
  };
73
- return this.callApi({
99
+ return this.sdkApi.makeRequest({
74
100
  method: 'POST',
75
- route: '/identifiers',
101
+ route: '/http/provider/identifiers',
76
102
  data,
77
103
  });
78
104
  });
@@ -83,18 +109,18 @@ export class Identifiers extends Base {
83
109
  provider,
84
110
  settings,
85
111
  };
86
- return this.callApi({
112
+ yield this.sdkApi.makeRequest({
87
113
  method: 'POST',
88
- route: '/identifier-providers',
114
+ route: '/http/provider/identifier-providers',
89
115
  data,
90
116
  });
91
117
  });
92
118
  }
93
119
  listProviders() {
94
120
  return __awaiter(this, void 0, void 0, function* () {
95
- const data = yield this.callApi({
121
+ const data = yield this.sdkApi.makeRequest({
96
122
  method: 'GET',
97
- route: '/identifier-providers',
123
+ route: '/http/provider/identifier-providers',
98
124
  });
99
125
  return extractIdentifierProvidersResponse(data);
100
126
  });
@@ -104,9 +130,9 @@ export class Identifiers extends Base {
104
130
  const params = {
105
131
  provider,
106
132
  };
107
- return this.callApi({
133
+ yield this.sdkApi.makeRequest({
108
134
  method: 'DELETE',
109
- route: '/identifier-providers',
135
+ route: '/http/provider/identifier-providers',
110
136
  params,
111
137
  });
112
138
  });
@@ -1 +1 @@
1
- {"version":3,"file":"Identifiers.js","sourceRoot":"","sources":["../../src/Identifiers.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAkC,QAAQ,EAAE,MAAM,cAAc,CAAC;AAQ9E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,kCAAkC,EAAE,MAAM,SAAS,CAAC;AAS7D,MAAM,OAAO,WAAY,SAAQ,IAAI;IAOnC,YAAY,MAAyB;QACnC,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;QAEvC,KAAK,CAAC;YACJ,KAAK;YACL,YAAY;YACZ,UAAU,EAAE,WAAW;SACxB,CAAC,CAAC;IACL,CAAC;IAED,UAAU,CAAC,IAA8B;QACvC,OAAO,GAAG,IAAI,CAAC,GAAG,gBAAgB,CAAC;IACrC,CAAC;IAUY,eAAe,CAAC,EAAqB;;YAChD,MAAM,MAAM,GAAG;gBACb,QAAQ,EAAE,IAAI;gBACd,YAAY,EAAE,IAAI;gBAClB,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;aAChC,CAAC;YAEF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAe;gBAC9C,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,cAAc;gBACrB,MAAM;aACP,CAAC,CAAC;YAE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T,CAAC;YAEF,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAO;gBAClC,MAAM,EAAE,QAAQ;gBAChB,KAAK,EAAE,qCAAqC;gBAC5C,MAAM;aACP,CAAC,CAAC;QACL,CAAC;KAAA;CACF"}
@@ -1,2 +1,2 @@
1
- export const SERVICE_KEY = 'sdk-api';
1
+ "use strict";
2
2
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ function getGroupIdentifiers(identifierArr) {
2
+ return identifierArr.filter(identifier => identifier.isGroup);
3
+ }
4
+ export default getGroupIdentifiers;
5
+ //# sourceMappingURL=getGroupIdentifiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getGroupIdentifiers.js","sourceRoot":"","sources":["../../../src/utils/getGroupIdentifiers.ts"],"names":[],"mappings":"AAKA,SAAS,mBAAmB,CAAC,aAA2B;IACtD,OAAO,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAChE,CAAC;AAED,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,5 @@
1
+ function getSingleIdentifiers(identifierArr) {
2
+ return identifierArr.filter(identifier => !identifier.isGroup);
3
+ }
4
+ export default getSingleIdentifiers;
5
+ //# sourceMappingURL=getSingleIdentifiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSingleIdentifiers.js","sourceRoot":"","sources":["../../../src/utils/getSingleIdentifiers.ts"],"names":[],"mappings":"AAKA,SAAS,oBAAoB,CAAC,aAA2B;IACvD,OAAO,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACjE,CAAC;AAED,eAAe,oBAAoB,CAAC"}
@@ -1,2 +1,5 @@
1
1
  export { default as extractIdentifierProvidersResponse } from './extractIdentifierProvidersResponse';
2
+ export { default as getGroupIdentifiers } from './getGroupIdentifiers';
3
+ export { default as getSingleIdentifiers } from './getSingleIdentifiers';
4
+ export { default as makeIdentifierGroups } from './makeIdentifierGroups';
2
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,kCAAkC,EAAE,MAAM,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AACrG,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import _ from 'lodash';
2
+ import { getSingleIdentifiers, getGroupIdentifiers } from '../utils';
3
+ function makeIdentifierGroups(identifierArr) {
4
+ const groupIdentifiers = getGroupIdentifiers(identifierArr);
5
+ const singleIdentifiers = getSingleIdentifiers(identifierArr);
6
+ const identifierGroups = groupIdentifiers.map(groupIdentifier => {
7
+ const members = singleIdentifiers.filter(identifier => identifier.group &&
8
+ identifier.group === groupIdentifier.phoneNumber);
9
+ const groupCopy = _.clone(groupIdentifier);
10
+ return Object.assign(Object.assign({}, groupCopy), { identifiers: members });
11
+ });
12
+ return identifierGroups;
13
+ }
14
+ export default makeIdentifierGroups;
15
+ //# sourceMappingURL=makeIdentifierGroups.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeIdentifierGroups.js","sourceRoot":"","sources":["../../../src/utils/makeIdentifierGroups.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AAMvB,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAErE,SAAS,oBAAoB,CAAC,aAA2B;IACvD,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,aAAa,CAAC,CAAC;IAC5D,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,aAAa,CAAC,CAAC;IAE9D,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE;QAC9D,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK;YACrE,UAAU,CAAC,KAAK,KAAK,eAAe,CAAC,WAAW,CAAC,CAAC;QACpD,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAE3C,uCACK,SAAS,KACZ,WAAW,EAAE,OAAO,IACpB;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,eAAe,oBAAoB,CAAC"}
@@ -1,10 +1,14 @@
1
- import { Base, ServiceDiscoveryResponse, List } from '@or-sdk/base';
2
- import { IdentifiersConfig, Identifier, ObtainableIdentifierRequestParams, ObtainableIdentifier, BuyIdentifierResponse, IdentifierProvider } from './types';
3
- export declare class Identifiers extends Base {
1
+ import { List } from '@or-sdk/base';
2
+ import { IdentifiersConfig, Identifier, SingleIdentifier, IdentifierGroup, ObtainableIdentifierRequestParams, ObtainableIdentifier, BuyIdentifierResponse, IdentifierProvider } from './types';
3
+ export declare class Identifiers {
4
+ private readonly sdkApi;
4
5
  constructor(params: IdentifiersConfig);
5
- makeApiUrl(data: ServiceDiscoveryResponse): string;
6
- listIdentifiers(id?: Identifier['id']): Promise<List<Identifier>>;
7
- getIdentifier(id: Identifier['id']): Promise<Identifier>;
6
+ init(): Promise<void>;
7
+ private fetchIdentifiers;
8
+ listIdentifiers(): Promise<List<SingleIdentifier>>;
9
+ listIdentifierGroups(): Promise<List<IdentifierGroup>>;
10
+ getIdentifier(id: Identifier['id']): Promise<SingleIdentifier>;
11
+ getIdentifierGroup(id: Identifier['id']): Promise<IdentifierGroup>;
8
12
  listObtainableIdentifiers(params?: ObtainableIdentifierRequestParams): Promise<List<ObtainableIdentifier>>;
9
13
  releaseIdentifier(id: Identifier['id']): Promise<void>;
10
14
  buyIdentifier(identifiers: ObtainableIdentifier | ObtainableIdentifier[]): Promise<BuyIdentifierResponse>;
@@ -1 +0,0 @@
1
- export declare const SERVICE_KEY = "sdk-api";
@@ -6,15 +6,26 @@ export declare type IdentifiersConfig = {
6
6
  export declare type Type = 'local' | 'tollfree' | 'mobile';
7
7
  export declare type PatternType = 'starts' | 'ends' | 'contains';
8
8
  export declare type Capability = 'voice' | 'sms' | 'mms';
9
- export declare type Identifier = {
9
+ export declare type SingleIdentifier = {
10
10
  id: string;
11
11
  name: string;
12
12
  phoneNumber: string;
13
- provider: number;
14
- isoCountry: string;
15
- region: string;
16
- type: Type;
17
- channels: string[];
13
+ provider?: number;
14
+ isoCountry?: string;
15
+ region?: string;
16
+ type?: Type;
17
+ channels?: string[];
18
+ group?: string;
19
+ };
20
+ export declare type GroupIdentifier = {
21
+ id: string;
22
+ name: string;
23
+ phoneNumber: string;
24
+ isGroup?: boolean;
25
+ };
26
+ export declare type Identifier = SingleIdentifier & GroupIdentifier;
27
+ export declare type IdentifierGroup = GroupIdentifier & {
28
+ identifiers: SingleIdentifier[];
18
29
  };
19
30
  export declare type ObtainableIdentifierRequestParams = {
20
31
  country?: string;
@@ -0,0 +1,3 @@
1
+ import { GroupIdentifier, Identifier } from '../types';
2
+ declare function getGroupIdentifiers(identifierArr: Identifier[]): GroupIdentifier[];
3
+ export default getGroupIdentifiers;
@@ -0,0 +1,3 @@
1
+ import { SingleIdentifier, Identifier } from '../types';
2
+ declare function getSingleIdentifiers(identifierArr: Identifier[]): SingleIdentifier[];
3
+ export default getSingleIdentifiers;
@@ -1 +1,4 @@
1
1
  export { default as extractIdentifierProvidersResponse } from './extractIdentifierProvidersResponse';
2
+ export { default as getGroupIdentifiers } from './getGroupIdentifiers';
3
+ export { default as getSingleIdentifiers } from './getSingleIdentifiers';
4
+ export { default as makeIdentifierGroups } from './makeIdentifierGroups';
@@ -0,0 +1,3 @@
1
+ import { Identifier, IdentifierGroup } from '../types';
2
+ declare function makeIdentifierGroups(identifierArr: Identifier[]): IdentifierGroup[];
3
+ export default makeIdentifierGroups;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.10.0",
2
+ "version": "0.13.1",
3
3
  "name": "@or-sdk/identifiers",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
@@ -24,8 +24,9 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@or-sdk/base": "^0.10.0",
27
+ "@or-sdk/base": "^0.13.1",
28
+ "@or-sdk/sdk-api": "^0.13.1",
28
29
  "lodash": "^4.17.21"
29
30
  },
30
- "gitHead": "23aeec7f6d64271cf5e44480379e40b87eb9115d"
31
+ "gitHead": "2c86c545ff23d9464ebba1a5287cde3651ed98c1"
31
32
  }
@@ -1,13 +1,15 @@
1
- import { Base, ServiceDiscoveryResponse, List, makeList } from '@or-sdk/base';
1
+ import { List, makeList } from '@or-sdk/base';
2
+ import { SdkApi } from '@or-sdk/sdk-api';
2
3
  import {
3
4
  IdentifiersConfig,
4
5
  Identifier,
6
+ SingleIdentifier,
7
+ IdentifierGroup,
5
8
  ObtainableIdentifierRequestParams,
6
9
  ObtainableIdentifier,
7
10
  BuyIdentifierResponse, ListProvidersResponse, IdentifierProvider,
8
11
  } from './types';
9
- import { SERVICE_KEY } from './constants';
10
- import { extractIdentifierProvidersResponse } from './utils';
12
+ import { extractIdentifierProvidersResponse, getSingleIdentifiers, getGroupIdentifiers, makeIdentifierGroups } from './utils';
11
13
 
12
14
  /**
13
15
  * OneReach Identifiers service client
@@ -16,49 +18,65 @@ import { extractIdentifierProvidersResponse } from './utils';
16
18
  * $ npm i @or-sdk/identifiers
17
19
  * ```
18
20
  */
19
- export class Identifiers extends Base {
21
+ export class Identifiers {
22
+ private readonly sdkApi: SdkApi;
23
+
20
24
  /**
21
25
  * ```typescript
22
26
  * import { Identifiers } from '@or-sdk/identifiers'
23
27
  * const identifiers = new Identifiers({token: 'my-account-token-string', discoveryUrl: 'http://example.identifiers/endpoint'});
28
+ * await identifiers.init();
24
29
  * ```
25
30
  */
26
31
  constructor(params: IdentifiersConfig) {
27
32
  const { token, discoveryUrl } = params;
28
33
 
29
- super({
34
+ this.sdkApi = new SdkApi({
30
35
  token,
31
36
  discoveryUrl,
32
- serviceKey: SERVICE_KEY,
33
37
  });
34
38
  }
35
39
 
36
- makeApiUrl(data: ServiceDiscoveryResponse): string {
37
- return `${data.url}/http/provider`;
40
+ async init() {
41
+ await this.sdkApi.init();
38
42
  }
39
43
 
40
- /**
41
- * List identifiers
42
- *
43
- * If id is passed - returns info for the specified identifier
44
- * ```typescript
45
- * const identifierList = await identifiers.listIdentifiers();
46
- * ```
47
- */
48
- public async listIdentifiers(id?: Identifier['id']): Promise<List<Identifier>> {
44
+ private async fetchIdentifiers(id?: Identifier['id'], groupDetails = true): Promise<Identifier[]> {
49
45
  const params = {
50
46
  fullInfo: true,
51
- groupDetails: true,
47
+ groupDetails,
52
48
  identifier: id ? id : undefined,
53
49
  };
54
50
 
55
- const result = await this.callApi<Identifier[]>({
51
+ return this.sdkApi.makeRequest<Identifier[]>({
56
52
  method: 'GET',
57
- route: '/identifiers',
53
+ route: '/http/provider/identifiers',
58
54
  params,
59
55
  });
56
+ }
60
57
 
61
- return makeList<Identifier>(result);
58
+ /**
59
+ * List identifiers
60
+ * ```typescript
61
+ * const identifierList = await identifiers.listIdentifiers();
62
+ * ```
63
+ */
64
+ public async listIdentifiers(): Promise<List<SingleIdentifier>> {
65
+ const result = await this.fetchIdentifiers();
66
+
67
+ return makeList<SingleIdentifier>(getSingleIdentifiers(result));
68
+ }
69
+
70
+ /**
71
+ * List identifier groups
72
+ * ```typescript
73
+ * const identifierGroupList = await identifiers.listIdentifierGroups();
74
+ * ```
75
+ */
76
+ public async listIdentifierGroups(): Promise<List<IdentifierGroup>> {
77
+ const result = await this.fetchIdentifiers();
78
+
79
+ return makeList<IdentifierGroup>(makeIdentifierGroups(result));
62
80
  }
63
81
 
64
82
  /**
@@ -67,10 +85,32 @@ export class Identifiers extends Base {
67
85
  * const identifier = await identifiers.getIdentifier('identifier-id');
68
86
  * ```
69
87
  */
70
- public async getIdentifier(id: Identifier['id']): Promise<Identifier> {
71
- const result = await this.listIdentifiers(id);
88
+ public async getIdentifier(id: Identifier['id']): Promise<SingleIdentifier> {
89
+ const result = await this.fetchIdentifiers(id, false);
90
+ const singleIdentifiers = getSingleIdentifiers(result);
91
+
92
+ if (singleIdentifiers.length === 0) {
93
+ throw `Id ${id} doesn't belong to an identifier`;
94
+ }
95
+
96
+ return singleIdentifiers[0];
97
+ }
98
+
99
+ /**
100
+ * Get identifier group
101
+ * ```typescript
102
+ * const identifierGroup = await identifiers.getIdentifierGroup('identifier-group-id');
103
+ * ```
104
+ */
105
+ public async getIdentifierGroup(id: Identifier['id']): Promise<IdentifierGroup> {
106
+ const result = await this.fetchIdentifiers(id);
107
+ const groupIdentifiers = getGroupIdentifiers(result);
108
+
109
+ if (groupIdentifiers.length === 0) {
110
+ throw `Id ${id} doesn't belong to an identifier group`;
111
+ }
72
112
 
73
- return result.rows[0];
113
+ return makeIdentifierGroups(result)[0];
74
114
  }
75
115
 
76
116
  /**
@@ -87,9 +127,9 @@ export class Identifiers extends Base {
87
127
  * ```
88
128
  */
89
129
  public async listObtainableIdentifiers(params: ObtainableIdentifierRequestParams = {}): Promise<List<ObtainableIdentifier>> {
90
- const result = await this.callApi<ObtainableIdentifier[]>({
130
+ const result = await this.sdkApi.makeRequest<ObtainableIdentifier[]>({
91
131
  method: 'GET',
92
- route: '/obtainable-identifiers',
132
+ route: '/http/provider/obtainable-identifiers',
93
133
  params,
94
134
  });
95
135
 
@@ -107,9 +147,9 @@ export class Identifiers extends Base {
107
147
  identifier: id,
108
148
  };
109
149
 
110
- return this.callApi({
150
+ await this.sdkApi.makeRequest<void>({
111
151
  method: 'DELETE',
112
- route: '/identifiers',
152
+ route: '/http/provider/identifiers',
113
153
  params,
114
154
  });
115
155
  }
@@ -125,9 +165,9 @@ export class Identifiers extends Base {
125
165
  identifiers: Array.isArray(identifiers) ? identifiers : [identifiers],
126
166
  };
127
167
 
128
- return this.callApi({
168
+ return this.sdkApi.makeRequest<BuyIdentifierResponse>({
129
169
  method: 'POST',
130
- route: '/identifiers',
170
+ route: '/http/provider/identifiers',
131
171
  data,
132
172
  });
133
173
  }
@@ -144,9 +184,9 @@ export class Identifiers extends Base {
144
184
  settings,
145
185
  };
146
186
 
147
- return this.callApi({
187
+ await this.sdkApi.makeRequest<void>({
148
188
  method: 'POST',
149
- route: '/identifier-providers',
189
+ route: '/http/provider/identifier-providers',
150
190
  data,
151
191
  });
152
192
  }
@@ -158,9 +198,9 @@ export class Identifiers extends Base {
158
198
  * ```
159
199
  */
160
200
  public async listProviders(): Promise<IdentifierProvider[]> {
161
- const data = await this.callApi<ListProvidersResponse>({
201
+ const data = await this.sdkApi.makeRequest<ListProvidersResponse>({
162
202
  method: 'GET',
163
- route: '/identifier-providers',
203
+ route: '/http/provider/identifier-providers',
164
204
  });
165
205
 
166
206
  return extractIdentifierProvidersResponse(data);
@@ -177,9 +217,9 @@ export class Identifiers extends Base {
177
217
  provider,
178
218
  };
179
219
 
180
- return this.callApi({
220
+ await this.sdkApi.makeRequest<void>({
181
221
  method: 'DELETE',
182
- route: '/identifier-providers',
222
+ route: '/http/provider/identifier-providers',
183
223
  params,
184
224
  });
185
225
  }
package/src/constants.ts CHANGED
@@ -1 +0,0 @@
1
- export const SERVICE_KEY = 'sdk-api';
package/src/types.ts CHANGED
@@ -17,15 +17,29 @@ export type PatternType = 'starts'|'ends'|'contains';
17
17
 
18
18
  export type Capability = 'voice'|'sms'|'mms';
19
19
 
20
- export type Identifier = {
20
+ export type SingleIdentifier = {
21
21
  id: string;
22
22
  name: string;
23
23
  phoneNumber: string;
24
- provider: number;
25
- isoCountry: string;
26
- region: string;
27
- type: Type;
28
- channels: string[];
24
+ provider?: number;
25
+ isoCountry?: string;
26
+ region?: string;
27
+ type?: Type;
28
+ channels?: string[];
29
+ group?: string;
30
+ };
31
+
32
+ export type GroupIdentifier = {
33
+ id: string;
34
+ name: string;
35
+ phoneNumber: string;
36
+ isGroup?: boolean;
37
+ };
38
+
39
+ export type Identifier = SingleIdentifier & GroupIdentifier;
40
+
41
+ export type IdentifierGroup = GroupIdentifier & {
42
+ identifiers: SingleIdentifier[];
29
43
  };
30
44
 
31
45
  export type ObtainableIdentifierRequestParams = {
@@ -0,0 +1,10 @@
1
+ import {
2
+ GroupIdentifier,
3
+ Identifier,
4
+ } from '../types';
5
+
6
+ function getGroupIdentifiers(identifierArr: Identifier[]): GroupIdentifier[] {
7
+ return identifierArr.filter(identifier => identifier.isGroup);
8
+ }
9
+
10
+ export default getGroupIdentifiers;
@@ -0,0 +1,10 @@
1
+ import {
2
+ SingleIdentifier,
3
+ Identifier,
4
+ } from '../types';
5
+
6
+ function getSingleIdentifiers(identifierArr: Identifier[]): SingleIdentifier[] {
7
+ return identifierArr.filter(identifier => !identifier.isGroup);
8
+ }
9
+
10
+ export default getSingleIdentifiers;
@@ -2,3 +2,6 @@
2
2
  * @internal
3
3
  */
4
4
  export { default as extractIdentifierProvidersResponse } from './extractIdentifierProvidersResponse';
5
+ export { default as getGroupIdentifiers } from './getGroupIdentifiers';
6
+ export { default as getSingleIdentifiers } from './getSingleIdentifiers';
7
+ export { default as makeIdentifierGroups } from './makeIdentifierGroups';
@@ -0,0 +1,27 @@
1
+ import _ from 'lodash';
2
+ import {
3
+ Identifier,
4
+ IdentifierGroup,
5
+ } from '../types';
6
+
7
+ import { getSingleIdentifiers, getGroupIdentifiers } from '../utils';
8
+
9
+ function makeIdentifierGroups(identifierArr: Identifier[]): IdentifierGroup[] {
10
+ const groupIdentifiers = getGroupIdentifiers(identifierArr);
11
+ const singleIdentifiers = getSingleIdentifiers(identifierArr);
12
+
13
+ const identifierGroups = groupIdentifiers.map(groupIdentifier => {
14
+ const members = singleIdentifiers.filter(identifier => identifier.group &&
15
+ identifier.group === groupIdentifier.phoneNumber);
16
+ const groupCopy = _.clone(groupIdentifier);
17
+
18
+ return {
19
+ ...groupCopy,
20
+ identifiers: members,
21
+ };
22
+ });
23
+
24
+ return identifierGroups;
25
+ }
26
+
27
+ export default makeIdentifierGroups;