UNPKG

@test-org122/merchant-iframe

Version:

Mediator iFrame package. This is used to sandbox the connector code away from the running hypernet core.

73 lines 3.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const neverthrow_1 = require("neverthrow"); const postmate_1 = __importDefault(require("postmate")); const utils_1 = require("@test-org122/utils"); class PostmateApi extends utils_1.ChildProxy { constructor(merchantService, contextProvider) { super(); this.merchantService = merchantService; this.contextProvider = contextProvider; const context = contextProvider.getMerchantContext(); context.onMerchantConnectorActivated.subscribe({ next: (merchantConnector) => { // We are going to relay the RXJS events merchantConnector.onSendFundsRequested.subscribe((val) => { var _a; (_a = this.parent) === null || _a === void 0 ? void 0 : _a.emit("onSendFundsRequested", val); }); merchantConnector.onAuthorizeFundsRequested.subscribe((val) => { var _a; (_a = this.parent) === null || _a === void 0 ? void 0 : _a.emit("onAuthorizeFundsRequested", val); }); merchantConnector.onDisplayRequested.subscribe((val) => { var _a; (_a = this.parent) === null || _a === void 0 ? void 0 : _a.emit("onDisplayRequested", val); }); }, }); } getModel() { // Fire up the Postmate model. The merchant iframe has two halves- the parts that work before the merchant connector has been activated // and the parts that work afterward. Postmate only supports a single model, so you have to have all the functions defined up front. return new postmate_1.default.Model({ activateConnector: (data) => { this.returnForModel(() => { console.log("activateConnector!"); return this.merchantService.activateMerchantConnector().map((merchantConnector) => { this.merchantConnector = merchantConnector; }); }, data.callId); }, resolveChallenge: (data) => { this.returnForModel(() => { if (this.merchantConnector == null) { return neverthrow_1.errAsync(new Error("No merchant connector available!")); } return neverthrow_1.ResultAsync.fromPromise(this.merchantConnector.resolveChallenge(data.data), (e) => e); }, data.callId); }, getPublicKey: (data) => { this.returnForModel(() => { if (this.merchantConnector == null) { return neverthrow_1.errAsync(new Error("No merchant connector available!")); } return neverthrow_1.ResultAsync.fromPromise(this.merchantConnector.getPublicKey(), (e) => e); }, data.callId); }, getValidatedSignature: (data) => { this.returnForModel(() => { const context = this.contextProvider.getMerchantContext(); console.log(`In iframe, validatedMerchantSignature = ${context.validatedMerchantSignature}`); return neverthrow_1.okAsync(context.validatedMerchantSignature); }, data.callId); }, }); } onModelActivated(parent) { } } exports.default = PostmateApi; //# sourceMappingURL=PostmateApi.js.map