@or-sdk/identifiers 0.6.0
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/dist/cjs/Identifiers.js +196 -0
- package/dist/cjs/Identifiers.js.map +1 -0
- package/dist/cjs/constants.js +5 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/index.js +17 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils/extractIdentifierProvidersResponse.js +17 -0
- package/dist/cjs/utils/extractIdentifierProvidersResponse.js.map +1 -0
- package/dist/cjs/utils/index.js +9 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/esm/Identifiers.js +113 -0
- package/dist/esm/Identifiers.js.map +1 -0
- package/dist/esm/constants.js +2 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/extractIdentifierProvidersResponse.js +12 -0
- package/dist/esm/utils/extractIdentifierProvidersResponse.js.map +1 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/types/Identifiers.d.ts +14 -0
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/types.d.ts +56 -0
- package/dist/types/utils/extractIdentifierProvidersResponse.d.ts +3 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +31 -0
- package/src/Identifiers.ts +182 -0
- package/src/constants.ts +1 -0
- package/src/index.ts +2 -0
- package/src/types.ts +74 -0
- package/src/utils/extractIdentifierProvidersResponse.ts +14 -0
- package/src/utils/index.ts +4 -0
- package/tsconfig.esm.json +9 -0
- package/tsconfig.json +7 -0
- package/tsconfig.types.json +9 -0
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.Identifiers = void 0;
|
|
55
|
+
var base_1 = require("@or-sdk/base");
|
|
56
|
+
var constants_1 = require("./constants");
|
|
57
|
+
var utils_1 = require("./utils");
|
|
58
|
+
var Identifiers = (function (_super) {
|
|
59
|
+
__extends(Identifiers, _super);
|
|
60
|
+
function Identifiers(params) {
|
|
61
|
+
var _this = this;
|
|
62
|
+
var token = params.token, discoveryUrl = params.discoveryUrl;
|
|
63
|
+
_this = _super.call(this, {
|
|
64
|
+
token: token,
|
|
65
|
+
discoveryUrl: discoveryUrl,
|
|
66
|
+
serviceKey: constants_1.SERVICE_KEY,
|
|
67
|
+
}) || this;
|
|
68
|
+
return _this;
|
|
69
|
+
}
|
|
70
|
+
Identifiers.prototype.makeApiUrl = function (data) {
|
|
71
|
+
return "".concat(data.url, "/http/provider");
|
|
72
|
+
};
|
|
73
|
+
Identifiers.prototype.listIdentifiers = function (id) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var params;
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
params = {
|
|
78
|
+
fullInfo: true,
|
|
79
|
+
groupDetails: true,
|
|
80
|
+
identifier: id ? id : undefined,
|
|
81
|
+
};
|
|
82
|
+
return [2, this.callApi({
|
|
83
|
+
method: 'GET',
|
|
84
|
+
route: '/identifiers',
|
|
85
|
+
params: params,
|
|
86
|
+
})];
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
Identifiers.prototype.getIdentifier = function (id) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
+
var result;
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
switch (_a.label) {
|
|
95
|
+
case 0: return [4, this.listIdentifiers(id)];
|
|
96
|
+
case 1:
|
|
97
|
+
result = _a.sent();
|
|
98
|
+
return [2, result[0]];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
Identifiers.prototype.listObtainableIdentifiers = function (params) {
|
|
104
|
+
if (params === void 0) { params = {}; }
|
|
105
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
return [2, this.callApi({
|
|
108
|
+
method: 'GET',
|
|
109
|
+
route: '/obtainable-identifiers',
|
|
110
|
+
params: params,
|
|
111
|
+
})];
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
Identifiers.prototype.releaseIdentifier = function (id) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
117
|
+
var params;
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
params = {
|
|
120
|
+
identifier: id,
|
|
121
|
+
};
|
|
122
|
+
return [2, this.callApi({
|
|
123
|
+
method: 'DELETE',
|
|
124
|
+
route: '/identifiers',
|
|
125
|
+
params: params,
|
|
126
|
+
})];
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
Identifiers.prototype.buyIdentifier = function (identifiers) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
132
|
+
var data;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
data = {
|
|
135
|
+
identifiers: Array.isArray(identifiers) ? identifiers : [identifiers],
|
|
136
|
+
};
|
|
137
|
+
return [2, this.callApi({
|
|
138
|
+
method: 'POST',
|
|
139
|
+
route: '/identifiers',
|
|
140
|
+
data: data,
|
|
141
|
+
})];
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
Identifiers.prototype.createProvider = function (provider, settings) {
|
|
146
|
+
if (settings === void 0) { settings = {}; }
|
|
147
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
+
var data;
|
|
149
|
+
return __generator(this, function (_a) {
|
|
150
|
+
data = {
|
|
151
|
+
provider: provider,
|
|
152
|
+
settings: settings,
|
|
153
|
+
};
|
|
154
|
+
return [2, this.callApi({
|
|
155
|
+
method: 'POST',
|
|
156
|
+
route: '/identifier-providers',
|
|
157
|
+
data: data,
|
|
158
|
+
})];
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
Identifiers.prototype.listProviders = function () {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
164
|
+
var data;
|
|
165
|
+
return __generator(this, function (_a) {
|
|
166
|
+
switch (_a.label) {
|
|
167
|
+
case 0: return [4, this.callApi({
|
|
168
|
+
method: 'GET',
|
|
169
|
+
route: '/identifier-providers',
|
|
170
|
+
})];
|
|
171
|
+
case 1:
|
|
172
|
+
data = _a.sent();
|
|
173
|
+
return [2, (0, utils_1.extractIdentifierProvidersResponse)(data)];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
Identifiers.prototype.deleteProvider = function (provider) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
180
|
+
var params;
|
|
181
|
+
return __generator(this, function (_a) {
|
|
182
|
+
params = {
|
|
183
|
+
provider: provider,
|
|
184
|
+
};
|
|
185
|
+
return [2, this.callApi({
|
|
186
|
+
method: 'DELETE',
|
|
187
|
+
route: '/identifier-providers',
|
|
188
|
+
params: params,
|
|
189
|
+
})];
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
return Identifiers;
|
|
194
|
+
}(base_1.Base));
|
|
195
|
+
exports.Identifiers = Identifiers;
|
|
196
|
+
//# sourceMappingURL=Identifiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Identifiers.js","sourceRoot":"","sources":["../../src/Identifiers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAA8D;AAQ9D,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;;;;g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AA3B,UAA4B,QAAoC,EAAE,QAA6C;QAA7C,yBAAA,EAAA,aAA6C;;;;gBACvG,IAAI,GAAG;oBACX,QAAQ,UAAA;oBACR,QAAQ,UAAA;iBACT,CAAC;gBAEF,WAAO,IAAI,CAAC,OAAO,CAAC;wBAClB,MAAM,EAAE,MAAM;wBACd,KAAK,EAAE,uBAAuB;wBAC9B,IAAI,MAAA;qBACL,CAAC,EAAC;;;KACJ;IAQY,mCAAa,GAA1B;;;;;4BACe,WAAM,IAAI,CAAC,OAAO,CAAwB;4BACrD,MAAM,EAAE,KAAK;4BACb,KAAK,EAAE,uBAAuB;yBAC/B,CAAC,EAAA;;wBAHI,IAAI,GAAG,SAGX;wBAEF,WAAO,IAAA,0CAAkC,EAAC,IAAI,CAAC,EAAC;;;;KACjD;IAQY,oCAAc,GAA3B,UAA4B,QAAoC;;;;gBACxD,MAAM,GAAG;oBACb,QAAQ,UAAA;iBACT,CAAC;gBAEF,WAAO,IAAI,CAAC,OAAO,CAAC;wBAClB,MAAM,EAAE,QAAQ;wBAChB,KAAK,EAAE,uBAAuB;wBAC9B,MAAM,QAAA;qBACP,CAAC,EAAC;;;KACJ;IACH,kBAAC;AAAD,CAAC,AAnKD,CAAiC,WAAI,GAmKpC;AAnKY,kCAAW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.Identifiers = void 0;
|
|
14
|
+
var Identifiers_1 = require("./Identifiers");
|
|
15
|
+
Object.defineProperty(exports, "Identifiers", { enumerable: true, get: function () { return Identifiers_1.Identifiers; } });
|
|
16
|
+
__exportStar(require("./types"), exports);
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,0CAAwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
var lodash_1 = __importDefault(require("lodash"));
|
|
7
|
+
function extractIdentifierProvidersResponse(response) {
|
|
8
|
+
return lodash_1.default.reduce(response, function (acc, value, key) {
|
|
9
|
+
acc.push(({
|
|
10
|
+
name: key,
|
|
11
|
+
settings: value,
|
|
12
|
+
}));
|
|
13
|
+
return acc;
|
|
14
|
+
}, []);
|
|
15
|
+
}
|
|
16
|
+
exports.default = extractIdentifierProvidersResponse;
|
|
17
|
+
//# sourceMappingURL=extractIdentifierProvidersResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractIdentifierProvidersResponse.js","sourceRoot":"","sources":["../../../src/utils/extractIdentifierProvidersResponse.ts"],"names":[],"mappings":";;;;;AAAA,kDAAuB;AAGvB,SAAS,kCAAkC,CAAC,QAA+B;IACzE,OAAO,gBAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAC,GAAyB,EAAE,KAAiC,EAAE,GAAW;QAClG,GAAG,CAAC,IAAI,CAAC,CAAC;YACR,IAAI,EAAE,GAAG;YACT,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC,CAAC;QACJ,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED,kBAAe,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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.extractIdentifierProvidersResponse = void 0;
|
|
7
|
+
var extractIdentifierProvidersResponse_1 = require("./extractIdentifierProvidersResponse");
|
|
8
|
+
Object.defineProperty(exports, "extractIdentifierProvidersResponse", { enumerable: true, get: function () { return __importDefault(extractIdentifierProvidersResponse_1).default; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAGA,2FAAqG;AAA5F,yKAAA,OAAO,OAAsC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Base } from '@or-sdk/base';
|
|
11
|
+
import { SERVICE_KEY } from './constants';
|
|
12
|
+
import { extractIdentifierProvidersResponse } from './utils';
|
|
13
|
+
export class Identifiers extends Base {
|
|
14
|
+
constructor(params) {
|
|
15
|
+
const { token, discoveryUrl } = params;
|
|
16
|
+
super({
|
|
17
|
+
token,
|
|
18
|
+
discoveryUrl,
|
|
19
|
+
serviceKey: SERVICE_KEY,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
makeApiUrl(data) {
|
|
23
|
+
return `${data.url}/http/provider`;
|
|
24
|
+
}
|
|
25
|
+
listIdentifiers(id) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const params = {
|
|
28
|
+
fullInfo: true,
|
|
29
|
+
groupDetails: true,
|
|
30
|
+
identifier: id ? id : undefined,
|
|
31
|
+
};
|
|
32
|
+
return this.callApi({
|
|
33
|
+
method: 'GET',
|
|
34
|
+
route: '/identifiers',
|
|
35
|
+
params,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
getIdentifier(id) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const result = yield this.listIdentifiers(id);
|
|
42
|
+
return result[0];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
listObtainableIdentifiers(params = {}) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
return this.callApi({
|
|
48
|
+
method: 'GET',
|
|
49
|
+
route: '/obtainable-identifiers',
|
|
50
|
+
params,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
releaseIdentifier(id) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const params = {
|
|
57
|
+
identifier: id,
|
|
58
|
+
};
|
|
59
|
+
return this.callApi({
|
|
60
|
+
method: 'DELETE',
|
|
61
|
+
route: '/identifiers',
|
|
62
|
+
params,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
buyIdentifier(identifiers) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const data = {
|
|
69
|
+
identifiers: Array.isArray(identifiers) ? identifiers : [identifiers],
|
|
70
|
+
};
|
|
71
|
+
return this.callApi({
|
|
72
|
+
method: 'POST',
|
|
73
|
+
route: '/identifiers',
|
|
74
|
+
data,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
createProvider(provider, settings = {}) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const data = {
|
|
81
|
+
provider,
|
|
82
|
+
settings,
|
|
83
|
+
};
|
|
84
|
+
return this.callApi({
|
|
85
|
+
method: 'POST',
|
|
86
|
+
route: '/identifier-providers',
|
|
87
|
+
data,
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
listProviders() {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const data = yield this.callApi({
|
|
94
|
+
method: 'GET',
|
|
95
|
+
route: '/identifier-providers',
|
|
96
|
+
});
|
|
97
|
+
return extractIdentifierProvidersResponse(data);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
deleteProvider(provider) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const params = {
|
|
103
|
+
provider,
|
|
104
|
+
};
|
|
105
|
+
return this.callApi({
|
|
106
|
+
method: 'DELETE',
|
|
107
|
+
route: '/identifier-providers',
|
|
108
|
+
params,
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sour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
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
function extractIdentifierProvidersResponse(response) {
|
|
3
|
+
return _.reduce(response, (acc, value, key) => {
|
|
4
|
+
acc.push(({
|
|
5
|
+
name: key,
|
|
6
|
+
settings: value,
|
|
7
|
+
}));
|
|
8
|
+
return acc;
|
|
9
|
+
}, []);
|
|
10
|
+
}
|
|
11
|
+
export default extractIdentifierProvidersResponse;
|
|
12
|
+
//# sourceMappingURL=extractIdentifierProvidersResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractIdentifierProvidersResponse.js","sourceRoot":"","sources":["../../../src/utils/extractIdentifierProvidersResponse.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AAGvB,SAAS,kCAAkC,CAAC,QAA+B;IACzE,OAAO,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAyB,EAAE,KAAiC,EAAE,GAAW,EAAE,EAAE;QACtG,GAAG,CAAC,IAAI,CAAC,CAAC;YACR,IAAI,EAAE,GAAG;YACT,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC,CAAC;QACJ,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED,eAAe,kCAAkC,CAAC"}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Base, ServiceDiscoveryResponse } from '@or-sdk/base';
|
|
2
|
+
import { IdentifiersConfig, Identifier, ObtainableIdentifierRequestParams, ObtainableIdentifier, BuyIdentifierResponse, IdentifierProvider } from './types';
|
|
3
|
+
export declare class Identifiers extends Base {
|
|
4
|
+
constructor(params: IdentifiersConfig);
|
|
5
|
+
makeApiUrl(data: ServiceDiscoveryResponse): string;
|
|
6
|
+
listIdentifiers(id?: Identifier['id']): Promise<Identifier[]>;
|
|
7
|
+
getIdentifier(id: Identifier['id']): Promise<Identifier>;
|
|
8
|
+
listObtainableIdentifiers(params?: ObtainableIdentifierRequestParams): Promise<ObtainableIdentifier[]>;
|
|
9
|
+
releaseIdentifier(id: Identifier['id']): Promise<void>;
|
|
10
|
+
buyIdentifier(identifiers: ObtainableIdentifier | ObtainableIdentifier[]): Promise<BuyIdentifierResponse>;
|
|
11
|
+
createProvider(provider: IdentifierProvider['name'], settings?: IdentifierProvider['settings']): Promise<void>;
|
|
12
|
+
listProviders(): Promise<IdentifierProvider[]>;
|
|
13
|
+
deleteProvider(provider: IdentifierProvider['name']): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SERVICE_KEY = "sdk-api";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Token } from '@or-sdk/base';
|
|
2
|
+
export declare type IdentifiersConfig = {
|
|
3
|
+
token: Token;
|
|
4
|
+
discoveryUrl: string;
|
|
5
|
+
};
|
|
6
|
+
export declare type Type = 'local' | 'tollfree' | 'mobile';
|
|
7
|
+
export declare type PatternType = 'starts' | 'ends' | 'contains';
|
|
8
|
+
export declare type Capability = 'voice' | 'sms' | 'mms';
|
|
9
|
+
export declare type Identifier = {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
phoneNumber: string;
|
|
13
|
+
provider: number;
|
|
14
|
+
isoCountry: string;
|
|
15
|
+
region: string;
|
|
16
|
+
type: Type;
|
|
17
|
+
channels: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare type ObtainableIdentifierRequestParams = {
|
|
20
|
+
country?: string;
|
|
21
|
+
region?: string;
|
|
22
|
+
type?: Type;
|
|
23
|
+
limit?: number;
|
|
24
|
+
pattern?: string;
|
|
25
|
+
patternType?: PatternType;
|
|
26
|
+
capabilities?: Capability[];
|
|
27
|
+
};
|
|
28
|
+
export declare type ObtainableIdentifier = {
|
|
29
|
+
provider: string;
|
|
30
|
+
isoCountry?: string;
|
|
31
|
+
capabilities?: {
|
|
32
|
+
voice: boolean;
|
|
33
|
+
SMS: boolean;
|
|
34
|
+
MMS: boolean;
|
|
35
|
+
};
|
|
36
|
+
region?: string;
|
|
37
|
+
type?: Type;
|
|
38
|
+
phoneNumber: string;
|
|
39
|
+
friendlyName?: string;
|
|
40
|
+
};
|
|
41
|
+
export declare type BuyIdentifierResponseElem = {
|
|
42
|
+
phoneNumber: string;
|
|
43
|
+
};
|
|
44
|
+
export declare type BuyIdentifierResponse = BuyIdentifierResponseElem[];
|
|
45
|
+
export declare type ListProvidersResponse = {
|
|
46
|
+
[key: string]: {
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export declare type IdentifierProviderSettings = {
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
};
|
|
53
|
+
export declare type IdentifierProvider = {
|
|
54
|
+
name: string;
|
|
55
|
+
settings: IdentifierProviderSettings;
|
|
56
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as extractIdentifierProvidersResponse } from './extractIdentifierProvidersResponse';
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.6.0",
|
|
3
|
+
"name": "@or-sdk/identifiers",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.js",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "npm run clean && concurrently \"npm run build:cjs\" \"npm run build:esm\" \"npm run build:types\"",
|
|
9
|
+
"build:watch": "concurrently -r --hide 1,2 \"npm run build:watch:cjs\" \"npm run build:watch:esm\" \"npm run build:watch:types\"",
|
|
10
|
+
"build:cjs": "tsc --project tsconfig.json",
|
|
11
|
+
"build:watch:cjs": "tsc --project tsconfig.json -w",
|
|
12
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
13
|
+
"build:watch:esm": "tsc --project tsconfig.esm.json -w",
|
|
14
|
+
"build:types": "tsc --project tsconfig.types.json",
|
|
15
|
+
"build:watch:types": "tsc --project tsconfig.types.json -w",
|
|
16
|
+
"clean": "rm -rf ./dist"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/lodash": "^4.14.176",
|
|
20
|
+
"concurrently": "^6.4.0",
|
|
21
|
+
"typescript": "^4.4.4"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@or-sdk/base": "^0.6.0",
|
|
28
|
+
"lodash": "^4.17.21"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "638b7198f7b70373ea8a3248443cfd2d2d13faa2"
|
|
31
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Base, ServiceDiscoveryResponse } from '@or-sdk/base';
|
|
2
|
+
import {
|
|
3
|
+
IdentifiersConfig,
|
|
4
|
+
Identifier,
|
|
5
|
+
ObtainableIdentifierRequestParams,
|
|
6
|
+
ObtainableIdentifier,
|
|
7
|
+
BuyIdentifierResponse, ListProvidersResponse, IdentifierProvider,
|
|
8
|
+
} from './types';
|
|
9
|
+
import { SERVICE_KEY } from './constants';
|
|
10
|
+
import { extractIdentifierProvidersResponse } from './utils';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* OneReach Identifiers service client
|
|
14
|
+
* ## Installation:
|
|
15
|
+
* ```
|
|
16
|
+
* $ npm i @or-sdk/identifiers
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export class Identifiers extends Base {
|
|
20
|
+
/**
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { Identifiers } from '@or-sdk/identifiers'
|
|
23
|
+
* const identifiers = new Identifiers({token: 'my-account-token-string', discoveryUrl: 'http://example.identifiers/endpoint'});
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
constructor(params: IdentifiersConfig) {
|
|
27
|
+
const { token, discoveryUrl } = params;
|
|
28
|
+
|
|
29
|
+
super({
|
|
30
|
+
token,
|
|
31
|
+
discoveryUrl,
|
|
32
|
+
serviceKey: SERVICE_KEY,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
makeApiUrl(data: ServiceDiscoveryResponse): string {
|
|
37
|
+
return `${data.url}/http/provider`;
|
|
38
|
+
}
|
|
39
|
+
|
|
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<Identifier[]> {
|
|
49
|
+
const params = {
|
|
50
|
+
fullInfo: true,
|
|
51
|
+
groupDetails: true,
|
|
52
|
+
identifier: id ? id : undefined,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return this.callApi({
|
|
56
|
+
method: 'GET',
|
|
57
|
+
route: '/identifiers',
|
|
58
|
+
params,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get identifier
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const identifier = await identifiers.getIdentifier('identifier-id');
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
public async getIdentifier(id: Identifier['id']): Promise<Identifier> {
|
|
69
|
+
const result = await this.listIdentifiers(id);
|
|
70
|
+
|
|
71
|
+
return result[0];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* List obtainable identifiers
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const obtainableIdentifiers = await identifiers.listObtainableIdentifiers({
|
|
78
|
+
* country: 'US',
|
|
79
|
+
* type: 'local',
|
|
80
|
+
* limit: 30,
|
|
81
|
+
* pattern: 'pattern',
|
|
82
|
+
* patternType: 'starts',
|
|
83
|
+
* capabilities: ['voice','sms','mms'],
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
public async listObtainableIdentifiers(params: ObtainableIdentifierRequestParams = {}): Promise<ObtainableIdentifier[]> {
|
|
88
|
+
return this.callApi({
|
|
89
|
+
method: 'GET',
|
|
90
|
+
route: '/obtainable-identifiers',
|
|
91
|
+
params,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Remove identifiers
|
|
97
|
+
* ```typescript
|
|
98
|
+
* await identifiers.releaseIdentifier('identifier-id');
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
public async releaseIdentifier(id: Identifier['id']): Promise<void> {
|
|
102
|
+
const params = {
|
|
103
|
+
identifier: id,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return this.callApi({
|
|
107
|
+
method: 'DELETE',
|
|
108
|
+
route: '/identifiers',
|
|
109
|
+
params,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Buy identifiers
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const identifiers = await identifiers.buyIdentifier([ { provider: 'providerName', phoneNumber: 'phoneNumber' } ]);
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
public async buyIdentifier(identifiers: ObtainableIdentifier | ObtainableIdentifier[]): Promise<BuyIdentifierResponse> {
|
|
120
|
+
const data = {
|
|
121
|
+
identifiers: Array.isArray(identifiers) ? identifiers : [identifiers],
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return this.callApi({
|
|
125
|
+
method: 'POST',
|
|
126
|
+
route: '/identifiers',
|
|
127
|
+
data,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Create new provider
|
|
133
|
+
* ```typescript
|
|
134
|
+
* await identifiers.createProvider('providerName', { settingKey: 'settingValue' });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
public async createProvider(provider: IdentifierProvider['name'], settings: IdentifierProvider['settings'] = {}): Promise<void> {
|
|
138
|
+
const data = {
|
|
139
|
+
provider,
|
|
140
|
+
settings,
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
return this.callApi({
|
|
144
|
+
method: 'POST',
|
|
145
|
+
route: '/identifier-providers',
|
|
146
|
+
data,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* List providers
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const providers = await identifiers.listProviders();
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
public async listProviders(): Promise<IdentifierProvider[]> {
|
|
157
|
+
const data = await this.callApi<ListProvidersResponse>({
|
|
158
|
+
method: 'GET',
|
|
159
|
+
route: '/identifier-providers',
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
return extractIdentifierProvidersResponse(data);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Delete provider
|
|
167
|
+
* ```typescript
|
|
168
|
+
* await identifiers.deleteProvider('providerName');
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
public async deleteProvider(provider: IdentifierProvider['name']): Promise<void> {
|
|
172
|
+
const params = {
|
|
173
|
+
provider,
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
return this.callApi({
|
|
177
|
+
method: 'DELETE',
|
|
178
|
+
route: '/identifier-providers',
|
|
179
|
+
params,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SERVICE_KEY = 'sdk-api';
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Token } from '@or-sdk/base';
|
|
2
|
+
|
|
3
|
+
export type IdentifiersConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* token
|
|
6
|
+
*/
|
|
7
|
+
token: Token;
|
|
8
|
+
/**
|
|
9
|
+
* function which return token
|
|
10
|
+
*/
|
|
11
|
+
discoveryUrl: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type Type = 'local'|'tollfree'|'mobile';
|
|
15
|
+
|
|
16
|
+
export type PatternType = 'starts'|'ends'|'contains';
|
|
17
|
+
|
|
18
|
+
export type Capability = 'voice'|'sms'|'mms';
|
|
19
|
+
|
|
20
|
+
export type Identifier = {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
phoneNumber: string;
|
|
24
|
+
provider: number;
|
|
25
|
+
isoCountry: string;
|
|
26
|
+
region: string;
|
|
27
|
+
type: Type;
|
|
28
|
+
channels: string[];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type ObtainableIdentifierRequestParams = {
|
|
32
|
+
country?: string;
|
|
33
|
+
region?: string;
|
|
34
|
+
type?: Type;
|
|
35
|
+
limit?: number;
|
|
36
|
+
pattern?: string;
|
|
37
|
+
patternType?: PatternType;
|
|
38
|
+
capabilities?: Capability[];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type ObtainableIdentifier = {
|
|
42
|
+
provider: string;
|
|
43
|
+
isoCountry?: string;
|
|
44
|
+
capabilities?: {
|
|
45
|
+
voice: boolean;
|
|
46
|
+
SMS: boolean;
|
|
47
|
+
MMS: boolean;
|
|
48
|
+
};
|
|
49
|
+
region?: string;
|
|
50
|
+
type?: Type;
|
|
51
|
+
phoneNumber: string;
|
|
52
|
+
friendlyName?: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type BuyIdentifierResponseElem = {
|
|
56
|
+
phoneNumber: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type BuyIdentifierResponse = BuyIdentifierResponseElem[];
|
|
60
|
+
|
|
61
|
+
export type ListProvidersResponse = {
|
|
62
|
+
[key: string]: {
|
|
63
|
+
[key: string]: unknown;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type IdentifierProviderSettings = {
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export type IdentifierProvider = {
|
|
72
|
+
name: string;
|
|
73
|
+
settings: IdentifierProviderSettings;
|
|
74
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { IdentifierProvider, IdentifierProviderSettings, ListProvidersResponse } from '../types';
|
|
3
|
+
|
|
4
|
+
function extractIdentifierProvidersResponse(response: ListProvidersResponse): IdentifierProvider[] {
|
|
5
|
+
return _.reduce(response, (acc: IdentifierProvider[], value: IdentifierProviderSettings, key: string) => {
|
|
6
|
+
acc.push(({
|
|
7
|
+
name: key,
|
|
8
|
+
settings: value,
|
|
9
|
+
}));
|
|
10
|
+
return acc;
|
|
11
|
+
}, []);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default extractIdentifierProvidersResponse;
|
package/tsconfig.json
ADDED