@ikas/app-helpers
Advanced tools
Comparing version 1.0.1-alpha.9 to 1.0.1-alpha.10
@@ -11,2 +11,3 @@ export declare class AppBridgeHelper { | ||
static closeApp(): void; | ||
static getNewToken(): Promise<string | undefined>; | ||
static sendEvent(event: AppEvent): void; | ||
@@ -13,0 +14,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AppBridgeCallbackMessageType = exports.AppBridgeMessageType = exports.AppBridgeHelper = void 0; | ||
var AppBridgeHelper = /** @class */ (function () { | ||
function AppBridgeHelper() { | ||
class AppBridgeHelper { | ||
static startListener(callback) { | ||
window.addEventListener('message', callback, false); | ||
} | ||
AppBridgeHelper.startListener = function (callback) { | ||
window.addEventListener("message", callback, false); | ||
}; | ||
AppBridgeHelper.stopListener = function (callback) { | ||
window.removeEventListener("message", callback, false); | ||
}; | ||
AppBridgeHelper.requestToken = function () { | ||
var event = { | ||
static stopListener(callback) { | ||
window.removeEventListener('message', callback, false); | ||
} | ||
static requestToken() { | ||
const event = { | ||
type: AppBridgeMessageType.REQUEST_TOKEN, | ||
@@ -19,5 +17,5 @@ data: {}, | ||
AppBridgeHelper.sendEvent(event); | ||
}; | ||
AppBridgeHelper.closeLoader = function () { | ||
var event = { | ||
} | ||
static closeLoader() { | ||
const event = { | ||
type: AppBridgeMessageType.CLOSE_LOADER, | ||
@@ -27,39 +25,39 @@ data: {}, | ||
AppBridgeHelper.sendEvent(event); | ||
}; | ||
AppBridgeHelper.startMerchantPayment = function (merchantPaymentId) { | ||
var event = { | ||
} | ||
static startMerchantPayment(merchantPaymentId) { | ||
const event = { | ||
type: AppBridgeMessageType.START_MERCHANT_PAYMENT, | ||
data: { | ||
merchantPaymentId: merchantPaymentId, | ||
merchantPaymentId, | ||
}, | ||
}; | ||
AppBridgeHelper.sendEvent(event); | ||
}; | ||
AppBridgeHelper.reAuthorizeApp = function (data) { | ||
var event = { | ||
} | ||
static reAuthorizeApp(data) { | ||
const event = { | ||
type: AppBridgeMessageType.RE_AUTHORIZE_APP, | ||
data: data, | ||
data, | ||
}; | ||
AppBridgeHelper.sendEvent(event); | ||
}; | ||
AppBridgeHelper.openProductPage = function (productId) { | ||
var event = { | ||
} | ||
static openProductPage(productId) { | ||
const event = { | ||
type: AppBridgeMessageType.OPEN_PRODUCT_PAGE, | ||
data: { | ||
productId: productId, | ||
productId, | ||
}, | ||
}; | ||
AppBridgeHelper.sendEvent(event); | ||
}; | ||
AppBridgeHelper.openOrderPage = function (orderId) { | ||
var event = { | ||
} | ||
static openOrderPage(orderId) { | ||
const event = { | ||
type: AppBridgeMessageType.OPEN_ORDER_PAGE, | ||
data: { | ||
orderId: orderId, | ||
orderId, | ||
}, | ||
}; | ||
AppBridgeHelper.sendEvent(event); | ||
}; | ||
AppBridgeHelper.closeApp = function () { | ||
var event = { | ||
} | ||
static closeApp() { | ||
const event = { | ||
type: AppBridgeMessageType.CLOSE_APP, | ||
@@ -69,9 +67,23 @@ data: {}, | ||
AppBridgeHelper.sendEvent(event); | ||
}; | ||
AppBridgeHelper.sendEvent = function (event) { | ||
} | ||
static getNewToken() { | ||
return new Promise((resolve) => { | ||
const callback = (msg) => { | ||
var _a, _b, _c; | ||
if (((_a = msg.data) === null || _a === void 0 ? void 0 : _a.type) === AppBridgeCallbackMessageType.REQUEST_TOKEN) { | ||
const token = (_c = (_b = msg.data) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.token; | ||
resolve(token); | ||
} | ||
resolve(undefined); | ||
AppBridgeHelper.stopListener(callback); | ||
}; | ||
AppBridgeHelper.startListener(callback); | ||
AppBridgeHelper.requestToken(); | ||
}); | ||
} | ||
static sendEvent(event) { | ||
//@ts-ignore | ||
window.top.postMessage(event, '*'); | ||
}; | ||
return AppBridgeHelper; | ||
}()); | ||
} | ||
} | ||
exports.AppBridgeHelper = AppBridgeHelper; | ||
@@ -78,0 +90,0 @@ var AppBridgeMessageType; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getImageSrc = void 0; | ||
function getImageSrc(size, merchantId, imageId) { | ||
if (size === void 0) { size = 180; } | ||
return "https://cdn.myikas.com/images/".concat(merchantId, "/").concat(imageId, "/image_").concat(size, ".webp"); | ||
function getImageSrc(size = 180, merchantId, imageId) { | ||
return `https://cdn.myikas.com/images/${merchantId}/${imageId}/image_${size}.webp`; | ||
} | ||
exports.getImageSrc = getImageSrc; | ||
//# sourceMappingURL=image-helpers.js.map |
{ | ||
"name": "@ikas/app-helpers", | ||
"version": "1.0.1-alpha.9", | ||
"version": "1.0.1-alpha.10", | ||
"description": "ikas store app helpers", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
export class AppBridgeHelper { | ||
static startListener(callback: (msg: MessageEvent) => void) { | ||
window.addEventListener("message", callback, false); | ||
window.addEventListener('message', callback, false); | ||
} | ||
static stopListener(callback: (msg: MessageEvent) => void) { | ||
window.removeEventListener("message", callback, false); | ||
window.removeEventListener('message', callback, false); | ||
} | ||
@@ -79,2 +79,20 @@ | ||
static getNewToken(): Promise<string | undefined> { | ||
return new Promise((resolve) => { | ||
const callback = (msg: MessageEvent) => { | ||
if (msg.data?.type === AppBridgeCallbackMessageType.REQUEST_TOKEN) { | ||
const token = msg.data?.data?.token; | ||
resolve(token); | ||
} | ||
resolve(undefined); | ||
AppBridgeHelper.stopListener(callback); | ||
}; | ||
AppBridgeHelper.startListener(callback); | ||
AppBridgeHelper.requestToken(); | ||
}); | ||
} | ||
static sendEvent(event: AppEvent) { | ||
@@ -86,3 +104,2 @@ //@ts-ignore | ||
export enum AppBridgeMessageType { | ||
@@ -94,8 +111,8 @@ CLOSE_LOADER = 'CLOSE_LOADER', | ||
OPEN_ORDER_PAGE = 'OPEN_ORDER_PAGE', | ||
REQUEST_TOKEN = "REQUEST_TOKEN", | ||
CLOSE_APP = "CLOSE_APP", | ||
REQUEST_TOKEN = 'REQUEST_TOKEN', | ||
CLOSE_APP = 'CLOSE_APP', | ||
} | ||
export enum AppBridgeCallbackMessageType { | ||
REQUEST_TOKEN = "REQUEST_TOKEN" | ||
REQUEST_TOKEN = 'REQUEST_TOKEN', | ||
} | ||
@@ -102,0 +119,0 @@ |
@@ -1,2 +0,2 @@ | ||
export * from './helpers/app-bridge' | ||
export * from './helpers/image-helpers' | ||
export * from './helpers/app-bridge'; | ||
export * from './helpers/image-helpers'; |
@@ -6,3 +6,3 @@ { | ||
"module": "commonjs", | ||
"target": "es5", | ||
"target": "es2015", | ||
"sourceMap": true, | ||
@@ -9,0 +9,0 @@ "declaration": true, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
17567
292