@ikas/api-client 0.0.1-canary.15 → 0.0.1-canary.16
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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# ikas-api-client-node
|
|
2
|
-
|
|
2
|
+
Beta Version of ikas public api client
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { IkasWebhook, IWebhookData } from '../models';
|
|
2
|
+
export declare const validateIkasWebhookMiddleware: (clientSecret: string) => (req: any, res: any, next: () => any) => Promise<void>;
|
|
3
|
+
export declare function validateIkasWebhookSignature(data: IkasWebhook, clientSecret: string): boolean;
|
|
4
|
+
export declare function getParsedIkasWebhookData(data: IkasWebhook, clientSecret: string): IWebhookData;
|
|
@@ -39,19 +39,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.
|
|
42
|
+
exports.getParsedIkasWebhookData = exports.validateIkasWebhookSignature = exports.validateIkasWebhookMiddleware = void 0;
|
|
43
43
|
var crypto_1 = __importDefault(require("crypto"));
|
|
44
|
-
var
|
|
45
|
-
var data
|
|
44
|
+
var validateIkasWebhookMiddleware = function (clientSecret) { return function (req, res, next) { return __awaiter(void 0, void 0, void 0, function () {
|
|
45
|
+
var data;
|
|
46
46
|
return __generator(this, function (_a) {
|
|
47
47
|
switch (_a.label) {
|
|
48
48
|
case 0:
|
|
49
49
|
data = req.body;
|
|
50
|
-
|
|
51
|
-
.createHmac('sha256', clientSecret || '')
|
|
52
|
-
.update(data.data, 'utf8')
|
|
53
|
-
.digest('hex');
|
|
54
|
-
if (!(generatedHash === data.signature)) return [3 /*break*/, 2];
|
|
50
|
+
if (!validateIkasWebhookSignature(data, clientSecret)) return [3 /*break*/, 2];
|
|
55
51
|
return [4 /*yield*/, next()];
|
|
56
52
|
case 1:
|
|
57
53
|
_a.sent();
|
|
@@ -63,5 +59,22 @@ var webhookValidate = function (clientSecret) { return function (req, res, next)
|
|
|
63
59
|
}
|
|
64
60
|
});
|
|
65
61
|
}); }; };
|
|
66
|
-
exports.
|
|
62
|
+
exports.validateIkasWebhookMiddleware = validateIkasWebhookMiddleware;
|
|
63
|
+
function validateIkasWebhookSignature(data, clientSecret) {
|
|
64
|
+
var generatedHash = crypto_1.default
|
|
65
|
+
.createHmac('sha256', clientSecret || '')
|
|
66
|
+
.update(data.data, 'utf8')
|
|
67
|
+
.digest('hex');
|
|
68
|
+
return generatedHash === data.signature;
|
|
69
|
+
}
|
|
70
|
+
exports.validateIkasWebhookSignature = validateIkasWebhookSignature;
|
|
71
|
+
function getParsedIkasWebhookData(data, clientSecret) {
|
|
72
|
+
if (validateIkasWebhookSignature(data, clientSecret)) {
|
|
73
|
+
return JSON.parse(data.data);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
throw new Error('invalid signature');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.getParsedIkasWebhookData = getParsedIkasWebhookData;
|
|
67
80
|
//# sourceMappingURL=webhook-validate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook-validate.js","sourceRoot":"","sources":["../../src/helpers/webhook-validate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kDAA4B;AAErB,IAAM,
|
|
1
|
+
{"version":3,"file":"webhook-validate.js","sourceRoot":"","sources":["../../src/helpers/webhook-validate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kDAA4B;AAErB,IAAM,6BAA6B,GAAG,UAAC,YAAoB,IAAK,OAAA,UAAO,GAAQ,EAAE,GAAQ,EAAE,IAAe;;;;;gBACzG,IAAI,GAAgB,GAAG,CAAC,IAAI,CAAC;qBAE/B,4BAA4B,CAAC,IAAI,EAAE,YAAY,CAAC,EAAhD,wBAAgD;gBAClD,qBAAM,IAAI,EAAE,EAAA;;gBAAZ,SAAY,CAAC;;;gBAEb,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;;;;;KAE3E,EARsE,CAQtE,CAAC;AARW,QAAA,6BAA6B,iCAQxC;AAEF,SAAgB,4BAA4B,CAAC,IAAiB,EAAE,YAAoB;IAClF,IAAM,aAAa,GAAG,gBAAM;SACzB,UAAU,CAAC,QAAQ,EAAE,YAAY,IAAI,EAAE,CAAC;SACxC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC;SACzB,MAAM,CAAC,KAAK,CAAC,CAAC;IAEjB,OAAO,aAAa,KAAK,IAAI,CAAC,SAAS,CAAA;AACzC,CAAC;AAPD,oEAOC;AAGD,SAAgB,wBAAwB,CAAC,IAAiB,EAAE,YAAoB;IAE9E,IAAG,4BAA4B,CAAC,IAAI,EAAE,YAAY,CAAC,EAAC;QAClD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;KAC7B;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACrC;AACH,CAAC;AAPD,4DAOC"}
|
|
@@ -65,4 +65,5 @@ export declare type IWebhookStoreAppPaymentData = {
|
|
|
65
65
|
appSubscription?: MerchantAppSubscription[] | null;
|
|
66
66
|
};
|
|
67
67
|
};
|
|
68
|
+
export declare type IWebhookData = IWebhookOrder | IWebhookCustomer | IWebhookStock | IWebhookStoreAppPaymentData | IWebhookProduct;
|
|
68
69
|
export {};
|