@or-sdk/ccp 1.0.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/README.md +21 -0
- package/dist/cjs/Ccp.js +81 -0
- package/dist/cjs/Ccp.js.map +1 -0
- package/dist/cjs/api/baseApi.js +11 -0
- package/dist/cjs/api/baseApi.js.map +1 -0
- package/dist/cjs/api/customersApi.js +91 -0
- package/dist/cjs/api/customersApi.js.map +1 -0
- package/dist/cjs/api/index.js +9 -0
- package/dist/cjs/api/index.js.map +1 -0
- package/dist/cjs/apiError.js +31 -0
- package/dist/cjs/apiError.js.map +1 -0
- package/dist/cjs/constants.js +5 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types.js +12 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/Ccp.js +47 -0
- package/dist/esm/Ccp.js.map +1 -0
- package/dist/esm/api/baseApi.js +6 -0
- package/dist/esm/api/baseApi.js.map +1 -0
- package/dist/esm/api/customersApi.js +33 -0
- package/dist/esm/api/customersApi.js.map +1 -0
- package/dist/esm/api/index.js +2 -0
- package/dist/esm/api/index.js.map +1 -0
- package/dist/esm/apiError.js +9 -0
- package/dist/esm/apiError.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 +9 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/types/Ccp.d.ts +12 -0
- package/dist/types/Ccp.d.ts.map +1 -0
- package/dist/types/api/baseApi.d.ts +6 -0
- package/dist/types/api/baseApi.d.ts.map +1 -0
- package/dist/types/api/customersApi.d.ts +8 -0
- package/dist/types/api/customersApi.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +2 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/apiError.d.ts +7 -0
- package/dist/types/apiError.d.ts.map +1 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types.d.ts +34 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +30 -0
- package/src/Ccp.ts +72 -0
- package/src/api/baseApi.ts +5 -0
- package/src/api/customersApi.ts +26 -0
- package/src/api/index.ts +1 -0
- package/src/apiError.ts +13 -0
- package/src/constants.ts +1 -0
- package/src/index.ts +2 -0
- package/src/types.ts +54 -0
- package/tsconfig.dev.json +8 -0
- package/tsconfig.esm.json +12 -0
- package/tsconfig.json +7 -0
- package/tsconfig.types.json +10 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
## Installation:
|
|
2
|
+
```
|
|
3
|
+
$ npm i @or-sdk/ccp
|
|
4
|
+
```
|
|
5
|
+
|
|
6
|
+
## Usage:
|
|
7
|
+
```typescript
|
|
8
|
+
import { CCP } from '@or-sdk/ccp'
|
|
9
|
+
|
|
10
|
+
// with direct api url
|
|
11
|
+
const ccp = new CCP({
|
|
12
|
+
token: 'my-account-token-string',
|
|
13
|
+
ccpApiUrl: 'http://example.account-settings/endpoint'
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// with service discovery (slower)
|
|
17
|
+
const ccp = new CCP({
|
|
18
|
+
token: 'my-account-token-string',
|
|
19
|
+
discoveryUrl: 'http://example.account-settings/endpoint'
|
|
20
|
+
});
|
|
21
|
+
```
|
package/dist/cjs/Ccp.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
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 __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.Ccp = void 0;
|
|
30
|
+
var base_1 = require("@or-sdk/base");
|
|
31
|
+
var api_1 = require("./api");
|
|
32
|
+
var apiError_1 = require("./apiError");
|
|
33
|
+
var constants_1 = require("./constants");
|
|
34
|
+
var Ccp = (function (_super) {
|
|
35
|
+
__extends(Ccp, _super);
|
|
36
|
+
function Ccp(params) {
|
|
37
|
+
var _this = this;
|
|
38
|
+
var token = params.token, discoveryUrl = params.discoveryUrl, ccpApiUrl = params.ccpApiUrl;
|
|
39
|
+
_this = _super.call(this, {
|
|
40
|
+
token: token,
|
|
41
|
+
discoveryUrl: discoveryUrl,
|
|
42
|
+
serviceUrl: ccpApiUrl,
|
|
43
|
+
serviceKey: constants_1.SERVICE_KEY,
|
|
44
|
+
}) || this;
|
|
45
|
+
var apiCall = _this.callApi.bind(_this);
|
|
46
|
+
_this.withApiErrorLog = Boolean(params.withApiErrorLog);
|
|
47
|
+
_this.customersApi = new api_1.CustomersApi(apiCall);
|
|
48
|
+
return _this;
|
|
49
|
+
}
|
|
50
|
+
Ccp.prototype.callApi = function (params) {
|
|
51
|
+
return _super.prototype.callApiV2.call(this, __assign({}, params));
|
|
52
|
+
};
|
|
53
|
+
Ccp.prototype.parseError = function (e) {
|
|
54
|
+
if (e.isAxiosError) {
|
|
55
|
+
var code = e.code, message = e.message, stack = e.stack;
|
|
56
|
+
if (this.withApiErrorLog) {
|
|
57
|
+
this.logApiError(e);
|
|
58
|
+
}
|
|
59
|
+
return new apiError_1.ApiError(code, message, stack);
|
|
60
|
+
}
|
|
61
|
+
var parsedError = _super.prototype.parseError.call(this, e);
|
|
62
|
+
return parsedError;
|
|
63
|
+
};
|
|
64
|
+
Ccp.prototype.logApiError = function (e) {
|
|
65
|
+
var _a, _b, _c;
|
|
66
|
+
console.error("url : ".concat((_a = e.config) === null || _a === void 0 ? void 0 : _a.url));
|
|
67
|
+
console.error("method : ".concat(e.request.method));
|
|
68
|
+
console.error("params : ".concat(JSON.stringify(((_b = e.config) === null || _b === void 0 ? void 0 : _b.params) || {})));
|
|
69
|
+
console.error("data : ".concat((function () {
|
|
70
|
+
var _a;
|
|
71
|
+
var str = JSON.stringify(((_a = e.config) === null || _a === void 0 ? void 0 : _a.data) || {});
|
|
72
|
+
return str.length > 150 ? str.slice(0, 149) + '...' : str;
|
|
73
|
+
})()));
|
|
74
|
+
console.error("status code : ".concat(e.request.res.statusCode));
|
|
75
|
+
console.error("status message: ".concat(e.request.res.statusMessage));
|
|
76
|
+
console.error("authorization : ".concat((_c = e.config) === null || _c === void 0 ? void 0 : _c.headers.Authorization));
|
|
77
|
+
};
|
|
78
|
+
return Ccp;
|
|
79
|
+
}(base_1.Base));
|
|
80
|
+
exports.Ccp = Ccp;
|
|
81
|
+
//# sourceMappingURL=Ccp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ccp.js","sourceRoot":"","sources":["../../src/Ccp.ts"],"names":[],"mappings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
this.apiCall = apiCall;
|
|
7
|
+
}
|
|
8
|
+
return BaseApi;
|
|
9
|
+
}());
|
|
10
|
+
exports.BaseApi = BaseApi;
|
|
11
|
+
//# sourceMappingURL=baseApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseApi.js","sourceRoot":"","sources":["../../../src/api/baseApi.ts"],"names":[],"mappings":";;;AAEA;IACE,iBAA+B,OAAgD;QAAhD,YAAO,GAAP,OAAO,CAAyC;IAAG,CAAC;IACrF,cAAC;AAAD,CAAC,AAFD,IAEC;AAFqB,0BAAO"}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
|
+
var baseApi_1 = require("./baseApi");
|
|
55
|
+
var CustomersApi = (function (_super) {
|
|
56
|
+
__extends(CustomersApi, _super);
|
|
57
|
+
function CustomersApi() {
|
|
58
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
59
|
+
_this.apiBasePath = 'api/v1/customers';
|
|
60
|
+
return _this;
|
|
61
|
+
}
|
|
62
|
+
CustomersApi.prototype.currentCustomer = function () {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0: return [4, this.apiCall({
|
|
67
|
+
method: 'GET',
|
|
68
|
+
route: "".concat(this.apiBasePath, "/"),
|
|
69
|
+
})];
|
|
70
|
+
case 1: return [2, _a.sent()];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
CustomersApi.prototype.listOfCustomers = function () {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
switch (_a.label) {
|
|
79
|
+
case 0: return [4, this.apiCall({
|
|
80
|
+
method: 'GET',
|
|
81
|
+
route: "".concat(this.apiBasePath, "/list"),
|
|
82
|
+
})];
|
|
83
|
+
case 1: return [2, _a.sent()];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return CustomersApi;
|
|
89
|
+
}(baseApi_1.BaseApi));
|
|
90
|
+
exports.default = CustomersApi;
|
|
91
|
+
//# sourceMappingURL=customersApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customersApi.js","sourceRoot":"","sources":["../../../src/api/customersApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAoC;AAGpC;IAA0C,gCAAO;IAAjD;;QACmB,iBAAW,GAAG,kBAAkB,CAAC;;IAqBpD,CAAC;IAhBc,sCAAe,GAA5B;;;;4BACS,WAAM,IAAI,CAAC,OAAO,CAAC;4BACxB,MAAM,EAAE,KAAK;4BACb,KAAK,EAAE,UAAG,IAAI,CAAC,WAAW,MAAG;yBAC9B,CAAC,EAAA;4BAHF,WAAO,SAGL,EAAC;;;;KACJ;IAKY,sCAAe,GAA5B;;;;4BACS,WAAM,IAAI,CAAC,OAAO,CAAC;4BACxB,MAAM,EAAE,KAAK;4BACb,KAAK,EAAE,UAAG,IAAI,CAAC,WAAW,UAAO;yBAClC,CAAC,EAAA;4BAHF,WAAO,SAGL,EAAC;;;;KACJ;IACH,mBAAC;AAAD,CAAC,AAtBD,CAA0C,iBAAO,GAsBhD"}
|
|
@@ -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.CustomersApi = void 0;
|
|
7
|
+
var customersApi_1 = require("./customersApi");
|
|
8
|
+
Object.defineProperty(exports, "CustomersApi", { enumerable: true, get: function () { return __importDefault(customersApi_1).default; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAyD;AAAhD,6HAAA,OAAO,OAAgB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ApiError = void 0;
|
|
19
|
+
var ApiError = (function (_super) {
|
|
20
|
+
__extends(ApiError, _super);
|
|
21
|
+
function ApiError(statusCode, message, stack, translationKey) {
|
|
22
|
+
var _this = _super.call(this, message) || this;
|
|
23
|
+
_this.statusCode = statusCode;
|
|
24
|
+
_this.stack = stack;
|
|
25
|
+
_this.translationKey = translationKey;
|
|
26
|
+
return _this;
|
|
27
|
+
}
|
|
28
|
+
return ApiError;
|
|
29
|
+
}(Error));
|
|
30
|
+
exports.ApiError = ApiError;
|
|
31
|
+
//# sourceMappingURL=apiError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiError.js","sourceRoot":"","sources":["../../src/apiError.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAGA;IAA8B,4BAAK;IACjC,kBACkB,UAAe,EAC/B,OAAe,EACC,KAAc,EACd,cAAuB;QAEvC,YAAA,MAAK,YAAC,OAAO,CAAC,SAAC;QALC,gBAAU,GAAV,UAAU,CAAK;QAEf,WAAK,GAAL,KAAK,CAAS;QACd,oBAAc,GAAd,cAAc,CAAS;;IAGzC,CAAC;IACH,eAAC;AAAD,CAAC,AATD,CAA8B,KAAK,GASlC;AATY,4BAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Ccp = void 0;
|
|
18
|
+
var Ccp_1 = require("./Ccp");
|
|
19
|
+
Object.defineProperty(exports, "Ccp", { enumerable: true, get: function () { return Ccp_1.Ccp; } });
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6BAA4B;AAAnB,0FAAA,GAAG,OAAA;AACZ,0CAAwB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomerStatus = void 0;
|
|
4
|
+
var CustomerStatus;
|
|
5
|
+
(function (CustomerStatus) {
|
|
6
|
+
CustomerStatus["ACTIVE"] = "active";
|
|
7
|
+
CustomerStatus["INACTIVE"] = "inactive";
|
|
8
|
+
CustomerStatus["SUSPENDED"] = "suspended";
|
|
9
|
+
CustomerStatus["DELETED"] = "deleted";
|
|
10
|
+
CustomerStatus["TRIAL"] = "trial";
|
|
11
|
+
})(CustomerStatus || (exports.CustomerStatus = CustomerStatus = {}));
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AA0BA,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,uCAAqB,CAAA;IACrB,yCAAuB,CAAA;IACvB,qCAAmB,CAAA;IACnB,iCAAe,CAAA;AACjB,CAAC,EANW,cAAc,8BAAd,cAAc,QAMzB"}
|
package/dist/esm/Ccp.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Base } from '@or-sdk/base';
|
|
2
|
+
import { CustomersApi } from './api';
|
|
3
|
+
import { ApiError } from './apiError';
|
|
4
|
+
import { SERVICE_KEY } from './constants';
|
|
5
|
+
export class Ccp extends Base {
|
|
6
|
+
constructor(params) {
|
|
7
|
+
const { token, discoveryUrl, ccpApiUrl } = params;
|
|
8
|
+
super({
|
|
9
|
+
token,
|
|
10
|
+
discoveryUrl,
|
|
11
|
+
serviceUrl: ccpApiUrl,
|
|
12
|
+
serviceKey: SERVICE_KEY,
|
|
13
|
+
});
|
|
14
|
+
const apiCall = this.callApi.bind(this);
|
|
15
|
+
this.withApiErrorLog = Boolean(params.withApiErrorLog);
|
|
16
|
+
this.customersApi = new CustomersApi(apiCall);
|
|
17
|
+
}
|
|
18
|
+
callApi(params) {
|
|
19
|
+
return super.callApiV2(Object.assign({}, params));
|
|
20
|
+
}
|
|
21
|
+
parseError(e) {
|
|
22
|
+
if (e.isAxiosError) {
|
|
23
|
+
const { code, message, stack } = e;
|
|
24
|
+
if (this.withApiErrorLog) {
|
|
25
|
+
this.logApiError(e);
|
|
26
|
+
}
|
|
27
|
+
return new ApiError(code, message, stack);
|
|
28
|
+
}
|
|
29
|
+
const parsedError = super.parseError(e);
|
|
30
|
+
return parsedError;
|
|
31
|
+
}
|
|
32
|
+
logApiError(e) {
|
|
33
|
+
var _a, _b, _c;
|
|
34
|
+
console.error(`url : ${(_a = e.config) === null || _a === void 0 ? void 0 : _a.url}`);
|
|
35
|
+
console.error(`method : ${e.request.method}`);
|
|
36
|
+
console.error(`params : ${JSON.stringify(((_b = e.config) === null || _b === void 0 ? void 0 : _b.params) || {})}`);
|
|
37
|
+
console.error(`data : ${(() => {
|
|
38
|
+
var _a;
|
|
39
|
+
const str = JSON.stringify(((_a = e.config) === null || _a === void 0 ? void 0 : _a.data) || {});
|
|
40
|
+
return str.length > 150 ? str.slice(0, 149) + '...' : str;
|
|
41
|
+
})()}`);
|
|
42
|
+
console.error(`status code : ${e.request.res.statusCode}`);
|
|
43
|
+
console.error(`status message: ${e.request.res.statusMessage}`);
|
|
44
|
+
console.error(`authorization : ${(_c = e.config) === null || _c === void 0 ? void 0 : _c.headers.Authorization}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=Ccp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ccp.js","sourceRoot":"","sources":["../../src/Ccp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,IAAI,EAAgB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAS1C,MAAM,OAAO,G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AC,CAAA,MAAA,CAAC,CAAC,MAAM,0CAAE,MAAM,KAAI,EAAE,CAAC,EAAE,CAAC,CAAC;QAC3E,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,GAAG,EAAE;;YACrC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA,MAAA,CAAC,CAAC,MAAM,0CAAE,IAAI,KAAI,EAAE,CAAC,CAAC;YACjD,OAAO,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;QAC5D,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACR,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;QAC7D,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC;QAChE,OAAO,CAAC,KAAK,CAAC,mBAAmB,MAAA,CAAC,CAAC,MAAM,0CAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IACtE,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseApi.js","sourceRoot":"","sources":["../../../src/api/baseApi.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,OAAO;IAC3B,YAA+B,OAAgD;QAAhD,YAAO,GAAP,OAAO,CAAyC;IAAG,CAAC;CACpF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { BaseApi } from './baseApi';
|
|
11
|
+
export default class CustomersApi extends BaseApi {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.apiBasePath = 'api/v1/customers';
|
|
15
|
+
}
|
|
16
|
+
currentCustomer() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
return yield this.apiCall({
|
|
19
|
+
method: 'GET',
|
|
20
|
+
route: `${this.apiBasePath}/`,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
listOfCustomers() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return yield this.apiCall({
|
|
27
|
+
method: 'GET',
|
|
28
|
+
route: `${this.apiBasePath}/list`,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=customersApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customersApi.js","sourceRoot":"","sources":["../../../src/api/customersApi.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,OAAO;IAAjD;;QACmB,gBAAW,GAAG,kBAAkB,CAAC;IAqBpD,CAAC;IAhBc,eAAe;;YAC1B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;gBACxB,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,GAAG,IAAI,CAAC,WAAW,GAAG;aAC9B,CAAC,CAAC;QACL,CAAC;KAAA;IAKY,eAAe;;YAC1B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;gBACxB,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,GAAG,IAAI,CAAC,WAAW,OAAO;aAClC,CAAC,CAAC;QACL,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiError.js","sourceRoot":"","sources":["../../src/apiError.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YACkB,UAAe,EAC/B,OAAe,EACC,KAAc,EACd,cAAuB;QAEvC,KAAK,CAAC,OAAO,CAAC,CAAC;QALC,eAAU,GAAV,UAAU,CAAK;QAEf,UAAK,GAAL,KAAK,CAAS;QACd,mBAAc,GAAd,cAAc,CAAS;IAGzC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var CustomerStatus;
|
|
2
|
+
(function (CustomerStatus) {
|
|
3
|
+
CustomerStatus["ACTIVE"] = "active";
|
|
4
|
+
CustomerStatus["INACTIVE"] = "inactive";
|
|
5
|
+
CustomerStatus["SUSPENDED"] = "suspended";
|
|
6
|
+
CustomerStatus["DELETED"] = "deleted";
|
|
7
|
+
CustomerStatus["TRIAL"] = "trial";
|
|
8
|
+
})(CustomerStatus || (CustomerStatus = {}));
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AA0BA,MAAM,CAAN,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,uCAAqB,CAAA;IACrB,yCAAuB,CAAA;IACvB,qCAAmB,CAAA;IACnB,iCAAe,CAAA;AACjB,CAAC,EANW,cAAc,KAAd,cAAc,QAMzB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AxiosError, Base, CalApiParams } from '@or-sdk/base';
|
|
2
|
+
import { CustomersApi } from './api';
|
|
3
|
+
import { CcpConfig } from './types';
|
|
4
|
+
export declare class Ccp extends Base {
|
|
5
|
+
readonly customersApi: CustomersApi;
|
|
6
|
+
private withApiErrorLog;
|
|
7
|
+
constructor(params: CcpConfig);
|
|
8
|
+
callApi<T>(params: CalApiParams): Promise<T>;
|
|
9
|
+
parseError(e: AxiosError): Error;
|
|
10
|
+
private logApiError;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=Ccp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ccp.d.ts","sourceRoot":"","sources":["../../src/Ccp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAUpC,qBAAa,GAAI,SAAQ,IAAI;IAC3B,SAAgB,YAAY,EAAE,YAAY,CAAC;IAC3C,OAAO,CAAC,eAAe,CAAU;gBAQrB,MAAM,EAAE,SAAS;IAiB7B,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC;IAM5C,UAAU,CAAC,CAAC,EAAE,UAAU,GAAG,KAAK;IAahC,OAAO,CAAC,WAAW;CAYpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseApi.d.ts","sourceRoot":"","sources":["../../../src/api/baseApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,8BAAsB,OAAO;IACf,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC;gBAAhD,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC;CAChF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseApi } from './baseApi';
|
|
2
|
+
import { Customer } from '../types';
|
|
3
|
+
export default class CustomersApi extends BaseApi {
|
|
4
|
+
private readonly apiBasePath;
|
|
5
|
+
currentCustomer(): Promise<Customer>;
|
|
6
|
+
listOfCustomers(): Promise<Customer[]>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=customersApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customersApi.d.ts","sourceRoot":"","sources":["../../../src/api/customersApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,OAAO;IAC/C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsB;IAKrC,eAAe,IAAI,OAAO,CAAC,QAAQ,CAAC;IAUpC,eAAe,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;CAMpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class ApiError extends Error {
|
|
2
|
+
readonly statusCode: any;
|
|
3
|
+
readonly stack?: string | undefined;
|
|
4
|
+
readonly translationKey?: string | undefined;
|
|
5
|
+
constructor(statusCode: any, message: string, stack?: string | undefined, translationKey?: string | undefined);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=apiError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiError.d.ts","sourceRoot":"","sources":["../../src/apiError.ts"],"names":[],"mappings":"AAGA,qBAAa,QAAS,SAAQ,KAAK;aAEf,UAAU,EAAE,GAAG;aAEf,KAAK,CAAC;aACN,cAAc,CAAC;gBAHf,UAAU,EAAE,GAAG,EAC/B,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,oBAAQ,EACd,cAAc,CAAC,oBAAQ;CAI1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Token } from '@or-sdk/base';
|
|
2
|
+
export type CcpConfig = {
|
|
3
|
+
token: Token;
|
|
4
|
+
discoveryUrl?: string;
|
|
5
|
+
ccpApiUrl?: string;
|
|
6
|
+
serviceKey?: string;
|
|
7
|
+
withApiErrorLog?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare enum CustomerStatus {
|
|
10
|
+
ACTIVE = "active",
|
|
11
|
+
INACTIVE = "inactive",
|
|
12
|
+
SUSPENDED = "suspended",
|
|
13
|
+
DELETED = "deleted",
|
|
14
|
+
TRIAL = "trial"
|
|
15
|
+
}
|
|
16
|
+
export interface CustomerBillingAddress {
|
|
17
|
+
billingEmail: string[];
|
|
18
|
+
billingContactName?: string;
|
|
19
|
+
billingPhoneNumber?: string;
|
|
20
|
+
country?: string;
|
|
21
|
+
state?: string;
|
|
22
|
+
city?: string;
|
|
23
|
+
streetAddress?: string;
|
|
24
|
+
zipCode?: string | number;
|
|
25
|
+
}
|
|
26
|
+
export interface Customer {
|
|
27
|
+
Id: string;
|
|
28
|
+
Name: string;
|
|
29
|
+
Status: CustomerStatus;
|
|
30
|
+
Billable?: boolean;
|
|
31
|
+
BillingAddress?: CustomerBillingAddress;
|
|
32
|
+
IdwCustomerId?: string;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,MAAM,MAAM,SAAS,GAAG;IAItB,KAAK,EAAE,KAAK,CAAC;IAIb,YAAY,CAAC,EAAE,MAAM,CAAC;IAItB,SAAS,CAAC,EAAE,MAAM,CAAC;IAInB,UAAU,CAAC,EAAE,MAAM,CAAC;IAKpB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,oBAAY,cAAc;IACxB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,cAAc,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,sBAAsB,CAAC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@or-sdk/ccp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs",
|
|
10
|
+
"build:cjs": "tsc --project tsconfig.json",
|
|
11
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
12
|
+
"build:types": "tsc --project tsconfig.types.json",
|
|
13
|
+
"build:watch": "concurrently -r --hide 1,2 \"pnpm build:watch:cjs\" \"pnpm build:watch:esm\" \"pnpm build:watch:types\"",
|
|
14
|
+
"build:watch:cjs": "tsc --project tsconfig.json -w",
|
|
15
|
+
"build:watch:esm": "tsc --project tsconfig.esm.json -w",
|
|
16
|
+
"build:watch:types": "tsc --project tsconfig.types.json -w",
|
|
17
|
+
"clean": "rm -rf ./dist",
|
|
18
|
+
"dev": "pnpm build:watch:esm"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@or-sdk/base": "^0.38.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"concurrently": "8.2.2",
|
|
25
|
+
"typescript": "^4.4.4"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/Ccp.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { AxiosError, Base, CalApiParams } from '@or-sdk/base';
|
|
2
|
+
import { CustomersApi } from './api';
|
|
3
|
+
import { ApiError } from './apiError';
|
|
4
|
+
import { CcpConfig } from './types';
|
|
5
|
+
import { SERVICE_KEY } from './constants';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* OneReach Ccp service client
|
|
9
|
+
* ## Installation:
|
|
10
|
+
* ```
|
|
11
|
+
* $ npm i @or-sdk/ccp
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export class Ccp extends Base {
|
|
15
|
+
public readonly customersApi: CustomersApi;
|
|
16
|
+
private withApiErrorLog: boolean;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { Ccp } from '@or-sdk/ccp'
|
|
21
|
+
* const ccp = new Ccp({token: 'my-account-token-string', discoveryUrl: 'http://example.tables/endpoint'});
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
constructor(params: CcpConfig) {
|
|
25
|
+
const { token, discoveryUrl, ccpApiUrl } = params;
|
|
26
|
+
|
|
27
|
+
super({
|
|
28
|
+
token,
|
|
29
|
+
discoveryUrl,
|
|
30
|
+
serviceUrl: ccpApiUrl,
|
|
31
|
+
serviceKey: SERVICE_KEY,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const apiCall = this.callApi.bind(this);
|
|
35
|
+
|
|
36
|
+
this.withApiErrorLog = Boolean(params.withApiErrorLog);
|
|
37
|
+
|
|
38
|
+
this.customersApi = new CustomersApi(apiCall);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
callApi<T>(params: CalApiParams): Promise<T> {
|
|
42
|
+
return super.callApiV2({
|
|
43
|
+
...params,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
parseError(e: AxiosError): Error {
|
|
48
|
+
if (e.isAxiosError) {
|
|
49
|
+
const { code, message, stack } = e;
|
|
50
|
+
if (this.withApiErrorLog) {
|
|
51
|
+
this.logApiError(e);
|
|
52
|
+
}
|
|
53
|
+
return new ApiError(code, message, stack);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const parsedError = super.parseError(e);
|
|
57
|
+
return parsedError;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private logApiError(e: AxiosError): void {
|
|
61
|
+
console.error(`url : ${e.config?.url}`);
|
|
62
|
+
console.error(`method : ${e.request.method}`);
|
|
63
|
+
console.error(`params : ${JSON.stringify(e.config?.params || {})}`);
|
|
64
|
+
console.error(`data : ${(() => {
|
|
65
|
+
const str = JSON.stringify(e.config?.data || {});
|
|
66
|
+
return str.length > 150 ? str.slice(0, 149) + '...' : str;
|
|
67
|
+
})()}`);
|
|
68
|
+
console.error(`status code : ${e.request.res.statusCode}`);
|
|
69
|
+
console.error(`status message: ${e.request.res.statusMessage}`);
|
|
70
|
+
console.error(`authorization : ${e.config?.headers.Authorization}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseApi } from './baseApi';
|
|
2
|
+
import { Customer } from '../types';
|
|
3
|
+
|
|
4
|
+
export default class CustomersApi extends BaseApi {
|
|
5
|
+
private readonly apiBasePath = 'api/v1/customers';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @description get current customer
|
|
9
|
+
*/
|
|
10
|
+
public async currentCustomer(): Promise<Customer> {
|
|
11
|
+
return await this.apiCall({
|
|
12
|
+
method: 'GET',
|
|
13
|
+
route: `${this.apiBasePath}/`,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @description get all customers list
|
|
19
|
+
*/
|
|
20
|
+
public async listOfCustomers(): Promise<Customer[]> {
|
|
21
|
+
return await this.apiCall({
|
|
22
|
+
method: 'GET',
|
|
23
|
+
route: `${this.apiBasePath}/list`,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as CustomersApi } from './customersApi';
|
package/src/apiError.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common parent for all api errors
|
|
3
|
+
*/
|
|
4
|
+
export class ApiError extends Error {
|
|
5
|
+
constructor(
|
|
6
|
+
public readonly statusCode: any,
|
|
7
|
+
message: string,
|
|
8
|
+
public readonly stack?: string,
|
|
9
|
+
public readonly translationKey?: string
|
|
10
|
+
) {
|
|
11
|
+
super(message);
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SERVICE_KEY = 'customer-portal-api';
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Token } from '@or-sdk/base';
|
|
2
|
+
|
|
3
|
+
export type CcpConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* token
|
|
6
|
+
*/
|
|
7
|
+
token: Token;
|
|
8
|
+
/**
|
|
9
|
+
* function which return token
|
|
10
|
+
*/
|
|
11
|
+
discoveryUrl?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Url of OneReach Customer Care Portal api
|
|
14
|
+
*/
|
|
15
|
+
ccpApiUrl?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Service key
|
|
18
|
+
*/
|
|
19
|
+
serviceKey?: string;
|
|
20
|
+
/**
|
|
21
|
+
* If true, the API error details like request url, params and body,
|
|
22
|
+
* will be outputted to console
|
|
23
|
+
*/
|
|
24
|
+
withApiErrorLog?: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export enum CustomerStatus {
|
|
28
|
+
ACTIVE = 'active',
|
|
29
|
+
INACTIVE = 'inactive',
|
|
30
|
+
SUSPENDED = 'suspended',
|
|
31
|
+
DELETED = 'deleted',
|
|
32
|
+
TRIAL = 'trial',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface CustomerBillingAddress {
|
|
36
|
+
billingEmail: string[];
|
|
37
|
+
billingContactName?: string;
|
|
38
|
+
billingPhoneNumber?: string;
|
|
39
|
+
country?: string;
|
|
40
|
+
state?: string;
|
|
41
|
+
city?: string;
|
|
42
|
+
streetAddress?: string;
|
|
43
|
+
zipCode?: string | number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface Customer {
|
|
47
|
+
Id: string;
|
|
48
|
+
Name: string;
|
|
49
|
+
Status: CustomerStatus;
|
|
50
|
+
Billable?: boolean;
|
|
51
|
+
BillingAddress?: CustomerBillingAddress;
|
|
52
|
+
IdwCustomerId?: string;
|
|
53
|
+
}
|
|
54
|
+
|
package/tsconfig.json
ADDED