UNPKG

react-native-firebase-compiled

Version:

A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Functions, Messaging (FCM), Remote Config, Sto

130 lines (107 loc) 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.statics = exports.default = exports.MODULE_NAME = exports.NAMESPACE = void 0; var _ModuleBase = _interopRequireDefault(require("../../utils/ModuleBase")); var _utils = require("../../utils"); var _native = require("../../utils/native"); var _firebase = _interopRequireDefault(require("../core/firebase")); var _HttpsError = _interopRequireDefault(require("./HttpsError")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * * Functions representation wrapper */ const NAMESPACE = 'functions'; exports.NAMESPACE = NAMESPACE; const MODULE_NAME = 'RNFirebaseFunctions'; /** * ------------- * INTERNALS * ------------- */ exports.MODULE_NAME = MODULE_NAME; function errorOrResult(possibleError) { if ((0, _utils.isObject)(possibleError) && possibleError.__error) { const code = possibleError.code, message = possibleError.message, details = possibleError.details; return Promise.reject(new _HttpsError.default(statics.HttpsErrorCode[code] || statics.HttpsErrorCode.UNKNOWN, message, details)); } return Promise.resolve(possibleError); } /** * ------------- * functions() * ------------- */ class Functions extends _ModuleBase.default { constructor(appOrRegion, region) { let _app = appOrRegion; let _region = region || 'us-central1'; if (typeof _app === 'string') { _region = _app; _app = _firebase.default.app(); } super(_app, { hasMultiAppSupport: true, hasCustomUrlSupport: false, hasRegionsSupport: true, namespace: NAMESPACE, moduleName: MODULE_NAME }, _region); } /** * ------------- * PUBLIC API * ------------- */ /** * Returns a reference to the callable https trigger with the given name. * @param name The name of the trigger. */ httpsCallable(name) { return data => { const promise = (0, _native.getNativeModule)(this).httpsCallable(name, { data }); return promise.then(errorOrResult); }; } /** * Changes this instance to point to a Cloud Functions emulator running * locally. * * See https://firebase.google.com/docs/functions/local-emulator * * @param origin the origin string of the local emulator started via firebase tools * "http://10.0.0.8:1337". */ useFunctionsEmulator(origin) { return (0, _native.getNativeModule)(this).useFunctionsEmulator(origin); } } exports.default = Functions; const statics = { HttpsErrorCode: { OK: 'ok', CANCELLED: 'cancelled', UNKNOWN: 'unknown', INVALID_ARGUMENT: 'invalid-argument', DEADLINE_EXCEEDED: 'deadline-exceeded', NOT_FOUND: 'not-found', ALREADY_EXISTS: 'already-exists', PERMISSION_DENIED: 'permission-denied', UNAUTHENTICATED: 'unauthenticated', RESOURCE_EXHAUSTED: 'resource-exhausted', FAILED_PRECONDITION: 'failed-precondition', ABORTED: 'aborted', OUT_OF_RANGE: 'out-of-range', UNIMPLEMENTED: 'unimplemented', INTERNAL: 'internal', UNAVAILABLE: 'unavailable', DATA_LOSS: 'data-loss' } }; exports.statics = statics;