dop-sdk
Version:
Mini App SDK for JavaScript by VTB
186 lines • 10.4 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MiniAppUtils = void 0;
var sdkbridge_1 = require("../sdkbridge");
var event_types_1 = require("../event-types");
var error_types_1 = require("../types/error-types");
var miniapp_bridge_utils_1 = require("../helpers/utils/miniapp-bridge-utils");
/** @internal */
var MiniAppUtils = /** @class */ (function () {
function MiniAppUtils() {
}
/**
* Associating closeMiniApp function to MiniAppBridge object.
* @param {withConfirmation} boolean value which will be used by the host app to show/hide close confirmation alert
* which should be set using `setCloseAlert` method in prior before calling this interface
* @see {closeMiniApp}
*/
MiniAppUtils.prototype.closeMiniApp = function (withConfirmation) {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.UtilsEvent.CLOSE_MINI_APP, {
withConfirmationAlert: withConfirmation,
})
.then(function (success) { return success; })
.catch(function (error) { return (0, error_types_1.parseMiniAppError)(error); });
};
/**
* Associating miniAppFinishedLoading function to MiniAppBridge object.
* @returns Promise resolve with string
* Host app can implement an interface miniAppFinishedLoading to perform any operations after the miniapp is loaded.
*/
MiniAppUtils.prototype.miniAppFinishedLoading = function () {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.UtilsEvent.MINI_APP_FINISHED_LOADING, null)
.then(function (success) { return success; })
.catch(function (error) { return error; });
};
MiniAppUtils.prototype.setCloseAlert = function (alertInfo) {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.UtilsEvent.SET_CLOSE_ALERT, {
closeAlertInfo: alertInfo,
});
};
MiniAppUtils.prototype.getHostAppThemeColors = function () {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.UtilsEvent.GET_HOST_APP_THEME_COLORS, null)
.then(function (response) { return JSON.parse(response); })
.catch(function (error) {
throw (0, error_types_1.parseMiniAppError)(error);
});
};
MiniAppUtils.prototype.isDarkMode = function () {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.UtilsEvent.IS_DARK_MODE, null)
.then(function (response) { return miniapp_bridge_utils_1.MiniAppBridgeUtils.BooleanValue(response); })
.catch(function (error) { return (0, error_types_1.parseMiniAppError)(error); });
};
MiniAppUtils.prototype.sendAnalytics = function (analytics) {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.UtilsEvent.SEND_ANALYTICS, { analyticsInfo: analytics })
.then(function (success) { return success; })
.catch(function (error) { return (0, error_types_1.parseMiniAppError)(error); });
};
/**
* This interface will get you the list of all features that is supported by the SDK and Host application
* @returns List of features for eg., ["GET_UNIQUE_ID", "GET_USERNAME", "GET_PROFILE_PHOTO", "IS_DARK_MODE"]
*/
MiniAppUtils.prototype.getFeatureList = function () {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.UtilsEvent.GET_FEATURE_LIST, null)
.then(function (response) { return JSON.parse(response); })
.catch(function (error) { return (0, error_types_1.parseMiniAppError)(error); });
};
/**
* This interface checks if the device contains/has the deeplink to launch
* @param deeplinkURL Deeplink URL that you wanted to check if the device can launch
* @returns true if device can find the deeplink available to launch
*/
MiniAppUtils.prototype.canOpenAppDeeplink = function (deeplinkURL) {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.UtilsEvent.CAN_OPEN_APP_DEEPLINK, { deeplinkURL: deeplinkURL })
.then(function (response) { return miniapp_bridge_utils_1.MiniAppBridgeUtils.BooleanValue(response); })
.catch(function (error) { return error; });
};
/**
* This interface checks if the application supports launching the Deeplink URL,
* sometimes application has whitelist URL, so this interface helps to check it.
* @param deeplinkURL Deeplink URL that you wanted to check if the device can launch
* @returns true if device can find the deeplink available to launch
*/
MiniAppUtils.prototype.isAppDeeplinkSupported = function (deeplinkURL) {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.UtilsEvent.IS_APP_DEEPLINK_SUPPORTED, {
deeplinkURL: deeplinkURL,
})
.then(function (response) { return miniapp_bridge_utils_1.MiniAppBridgeUtils.BooleanValue(response); })
.catch(function (error) { return error; });
};
/**
* Launches the specified URL in an external browser.
* @param {string} url - The URL to be opened in the external browser.
* @returns {Promise<boolean>} - A promise that resolves to true if the URL was successfully opened, otherwise rejects with an error.
* @see {launchExternalBrowser}
*/
MiniAppUtils.prototype.launchExternalBrowser = function (url) {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.BrowserManagerEvent.LAUNCH_EXTERNAL_BROWSER, { url: url })
.then(function (response) { return miniapp_bridge_utils_1.MiniAppBridgeUtils.BooleanValue(response); })
.catch(function (error) { return (0, error_types_1.parseMiniAppError)(error); });
};
/**
* Launches the specified URL in an internal browser.
* @param {string} url - The URL to be opened in the internal browser.
* @returns {Promise<boolean>} - A promise that resolves to true if the URL was successfully opened, otherwise rejects with an error.
* @see {launchInternalBrowser}
*/
MiniAppUtils.prototype.launchInternalBrowser = function (url) {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.BrowserManagerEvent.LAUNCH_INTERNAL_BROWSER, { url: url })
.then(function (response) { return miniapp_bridge_utils_1.MiniAppBridgeUtils.BooleanValue(response); })
.catch(function (error) { return (0, error_types_1.parseMiniAppError)(error); });
};
/**
* Converts a list of Blob objects to a list of number arrays.
* Each Blob is converted to an ArrayBuffer, which is then converted to a Uint8Array.
* The Uint8Array is converted to a regular array of numbers.
*
* @param imageBlob - An optional of Blob object to be converted.
* @returns A promise that resolves to an array of number arrays.
*/
MiniAppUtils.convertBlobToNumberArray = function (imageBlob) {
return __awaiter(this, void 0, void 0, function () {
var arrayBuffer, uint8Array;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!imageBlob) {
return [2 /*return*/, []];
}
return [4 /*yield*/, imageBlob.arrayBuffer()];
case 1:
arrayBuffer = _a.sent();
uint8Array = new Uint8Array(arrayBuffer);
return [2 /*return*/, Array.from(uint8Array)];
}
});
});
};
return MiniAppUtils;
}());
exports.MiniAppUtils = MiniAppUtils;
//# sourceMappingURL=utils.js.map