dop-sdk
Version:
Mini App SDK for JavaScript by VTB
298 lines • 14.3 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
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.MiniApp = void 0;
var user_info_1 = require("./modules/user-info");
var chat_service_1 = require("./modules/chat-service");
var sdkbridge_1 = require("./sdkbridge");
var secure_storage_1 = require("./modules/secure-storage");
var universal_bridge_1 = require("./modules/universal-bridge");
var utils_1 = require("./modules/utils");
var in_app_purchase_1 = require("./modules/in-app-purchase");
var cookie_manager_1 = require("./modules/cookie-manager");
var bridge_info_converter_1 = require("./modules/bridge-info-converter");
var miniapp_preferences_1 = require("./modules/miniapp-preferences");
var gallery_manager_1 = require("./modules/gallery-manager");
var webview_config_provider_1 = require("./modules/webview-config-provider");
var event_types_1 = require("./event-types");
var error_types_1 = require("./types/error-types");
var custom_permission_1 = require("./types/custom-permission");
var device_permission_1 = require("./types/device-permission");
var MiniApp = /** @class */ (function () {
function MiniApp() {
this.user = new user_info_1.UserInfo();
this.chatService = new chat_service_1.ChatService();
this.secureStorageService = new secure_storage_1.SecureStorageService();
this.universalBridge = new universal_bridge_1.UniversalBridge();
this.miniappUtils = new utils_1.MiniAppUtils();
this.purchaseService = new in_app_purchase_1.Purchases();
this.cookieManager = new cookie_manager_1.CookieManager();
this.preferences = new miniapp_preferences_1.MiniAppPreference();
this.galleryManager = new gallery_manager_1.GalleryBridge();
this.webviewManager = new webview_config_provider_1.WebviewManager();
}
MiniApp.prototype.requestPermission = function (permissionType) {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.REQUEST_PERMISSION, {
permission: permissionType,
});
};
/**
* @deprecated Deprecated method for getting the uniqueId use `getMessagingUniqueId` or `getMauid` instead
*/
/**
* Deprecated method for associating getUniqueId function to MiniAppBridge object.
* Use `getMessagingUniqueId` or `getMauid` instead
*/
MiniApp.prototype.getUniqueId = function () {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.GET_UNIQUE_ID, null);
};
/**
* Associating getMessagingUniqueId function to MiniAppBridge object.
*/
MiniApp.prototype.getMessagingUniqueId = function () {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.GET_UNIQUE_ID, null);
};
/**
* Associating getMauid function to MiniAppBridge object.
*/
MiniApp.prototype.getMauid = function () {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.GET_MAU_ID, null);
};
MiniApp.prototype.requestLocationPermission = function (permissionDescription) {
var _this = this;
if (permissionDescription === void 0) { permissionDescription = ''; }
var locationPermission = [
{
name: custom_permission_1.CustomPermissionName.LOCATION,
description: permissionDescription,
},
];
return this.requestCustomPermissions(locationPermission)
.then(function (permission) {
return permission.find(function (result) {
return result.status === custom_permission_1.CustomPermissionStatus.ALLOWED ||
// Case where older Android SDK doesn't support the Location custom permission
result.status === custom_permission_1.CustomPermissionStatus.PERMISSION_NOT_AVAILABLE;
});
})
.catch(function (error) {
// Case where older iOS SDK doesn't support the Location custom permission
return typeof error === 'string' &&
error.startsWith('invalidCustomPermissionsList')
? Promise.resolve(true)
: Promise.reject(error);
})
.then(function (hasPermission) {
return hasPermission
? _this.requestPermission(device_permission_1.DevicePermission.LOCATION)
: Promise.reject('User denied location permission to this mini app.');
});
};
/**
* Associating requestCustomPermissions function to MiniAppBridge object
* @param [CustomPermissionType[] permissionTypes, Types of custom permissions that are requested
* using an Array including the parameters eg. name, description.
*
* For eg., Miniapps can pass the array of valid custom permissions as following
* [
* {"name":"rakuten.miniapp.user.USER_NAME", "description": "Reason to request for the custom permission"},
* {"name":"rakuten.miniapp.user.PROFILE_PHOTO", "description": "Reason to request for the custom permission"},
* {"name":"rakuten.miniapp.user.CONTACT_LIST", "description": "Reason to request for the custom permission"}
* ]
*/
MiniApp.prototype.requestCustomPermissions = function (permissions) {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.CommonEvents.REQUEST_CUSTOM_PERMISSIONS, {
permissions: permissions,
})
.then(function (permissionResult) { return permissionResult.permissions; });
};
/**
* Associating loadInterstitialAd function to MiniAppBridge object.
* This function preloads interstitial ad before they are requested for display.
* Can be called multiple times to pre-load multiple ads.
* @param {string} id ad unit id of the interstitial ad that needs to be loaded.
*/
MiniApp.prototype.loadInterstitialAd = function (id) {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.LOAD_AD, {
adType: 0 /* AdTypes.INTERSTITIAL */,
adUnitId: id,
});
};
/**
* Associating loadRewardedAd function to MiniAppBridge object.
* This function preloads Rewarded ad before they are requested for display.
* Can be called multiple times to pre-load multiple ads.
* @param {string} id ad unit id of the Rewarded ad that needs to be loaded.
*/
MiniApp.prototype.loadRewardedAd = function (id) {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.LOAD_AD, {
adType: 1 /* AdTypes.REWARDED */,
adUnitId: id,
});
};
/**
* Associating showInterstitialAd function to MiniAppBridge object.
* @param {string} id ad unit id of the intertitial ad
*/
MiniApp.prototype.showInterstitialAd = function (id) {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.SHOW_AD, {
adType: 0 /* AdTypes.INTERSTITIAL */,
adUnitId: id,
});
};
/**
* Associating showRewardedAd function to MiniAppBridge object.
* @param {string} id ad unit id of the Rewarded ad
*/
MiniApp.prototype.showRewardedAd = function (id) {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.SHOW_AD, {
adType: 1 /* AdTypes.REWARDED */,
adUnitId: id,
});
};
/**
* Associating shareInfo function to MiniAppBridge object.
* This function returns the shared info action state.
* @param {info} The shared info object.
*/
MiniApp.prototype.shareInfo = function (info) {
return __awaiter(this, void 0, void 0, function () {
var blob, shareInfo;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, utils_1.MiniAppUtils.convertBlobToNumberArray(info.imageBlob)];
case 1:
blob = _a.sent();
shareInfo = {
content: info.content,
url: info.url,
imageData: blob.length ? blob : undefined,
};
return [2 /*return*/, (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.SHARE_INFO, shareInfo)];
}
});
});
};
/**
* Get the platform which injects this bridge.
* @returns The platform name. It could be 'Android' or 'iOS'.
*/
MiniApp.prototype.getPlatform = function () {
var platform = 'Unknown';
try {
platform = (0, sdkbridge_1.getBridge)().platform;
}
catch (e) { }
return platform;
};
/**
* This function does not return anything back on success.
* @param {screenAction} The screen state that miniapp wants to set on device.
*/
MiniApp.prototype.setScreenOrientation = function (screenOrientation) {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.SET_SCREEN_ORIENTATION, {
action: screenOrientation,
});
};
/**
* Associating get point balance function to MiniAppBridge object.
* (provided rakuten.miniapp.user.POINTS is allowed by the user)
*/
MiniApp.prototype.getPoints = function () {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.GET_POINTS, null);
};
MiniApp.prototype.getHostEnvironmentInfo = function () {
return __awaiter(this, void 0, void 0, function () {
var infoStringfy, info;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.GET_HOST_ENVIRONMENT_INFO, null)];
case 1:
infoStringfy = _a.sent();
info = __assign(__assign({}, JSON.parse(infoStringfy)), { platform: (0, sdkbridge_1.getBridge)().platform });
info.platform = (0, sdkbridge_1.getBridge)().platform;
return [2 /*return*/, bridge_info_converter_1.BridgeInfoConverter.convertJsonToPlatformInfo(info)];
}
});
});
};
MiniApp.prototype.downloadFile = function (filename, url, headers) {
if (headers === void 0) { headers = {}; }
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.CommonEvents.DOWNLOAD_FILE, {
filename: filename,
url: url,
headers: headers,
})
.then(function (id) {
if (id !== 'null' && id !== null) {
return id;
}
else {
return null;
}
})
.catch(function (error) {
return (0, error_types_1.parseMiniAppError)(error);
});
};
/**
* @param alertInfo Close confirmation alert info.
* @see {setCloseAlert}
*/
MiniApp.prototype.setCloseAlert = function (alertInfo) {
return (0, sdkbridge_1.getBridge)().sendToNative(event_types_1.CommonEvents.SET_CLOSE_ALERT, {
closeAlertInfo: alertInfo,
});
};
return MiniApp;
}());
exports.MiniApp = MiniApp;
//# sourceMappingURL=miniapp.js.map