{"version":3,"sources":["webpack:///firebase-functions.js","webpack:///./functions/index.js","webpack:///../functions/dist/esm/src/api/error.js","webpack:///../functions/dist/esm/src/serializer.js","webpack:///../functions/dist/esm/index.js","webpack:///../functions/dist/esm/src/context.js","webpack:///../functions/dist/esm/src/api/service.js"],"names":["webpackJsonpFirebase","118","module","exports","__webpack_require__","119","__webpack_exports__","codeForHTTPStatus","status","_errorForResponse","bodyJSON","serializer","code","description","details","undefined","errorJSON","error","status_1","errorCodeMap","error_HttpsErrorImpl","message","decode","e","mapValues","o","f","result","key","hasOwnProperty","factory","app","unused","region","service_Service","registerFunctions","instance","namespaceExports","Functions","INTERNAL","registerService","FUNCTIONS_TYPE","Object","defineProperty","value","esm","tslib_es6","OK","CANCELLED","UNKNOWN","INVALID_ARGUMENT","DEADLINE_EXCEEDED","NOT_FOUND","ALREADY_EXISTS","PERMISSION_DENIED","UNAUTHENTICATED","RESOURCE_EXHAUSTED","FAILED_PRECONDITION","ABORTED","OUT_OF_RANGE","UNIMPLEMENTED","UNAVAILABLE","DATA_LOSS","_super","HttpsErrorImpl","_this","call","this","setPrototypeOf","prototype","Error","context_ContextProvider","ContextProvider","getAuthToken","token","e_1","_a","label","trys","push","getToken","sent","accessToken","getInstanceIdToken","messaging","e_2","getContext","authToken","instanceIdToken","Serializer","encode","data","Number","valueOf","isFinite","toString","Array","isArray","map","x","json","parseFloat","isNaN","Service","app_","region_","contextProvider","get","enumerable","configurable","_url","name","projectId","options","httpsCallable","postJSON","url","body","headers","response","append","fetch","method","JSON","stringify","context","responseData","decodedData","Headers"],"mappings":";;;;;AAKA,IACQA,sBAAsB,IAExBC,IACA,SAAUC,EAAQC,EAASC,GCOjCA,EAAA,MDgBMC,IACA,SAAUH,EAAQI,EAAqBF,GAE7C,YEkCA,SAAAG,GAAAC,GAEA,GAAAA,GAAA,KAAAA,EAAA,IACA,UAEA,QAAAA,GACA,OAEA,gBACA,UACA,wBACA,UACA,uBACA,UACA,yBACA,UACA,iBACA,UACA,e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1B,QAChC2B,EAAA,GAAAU,UACA,EAAA7D,KAAAuC,gBAAApB,aACA,QAQA,MAPAuC,GAAAjD,EAAAK,OACA4C,EAAAtC,WACA+B,EAAAE,OAAA,0BAAAK,EAAAtC,WAEAsC,EAAArC,iBACA8B,EAAAE,OAAA,6BAAAK,EAAArC,kBAEA,EAAArB,KAAAgD,SAAAC,EAAAC,EAAAC,GACA,QAGA,GAFAC,EAAA3C,EAAAK,OACAhE,EAAAR,EAAA8G,EAAA/G,OAAA+G,EAAAnB,KAAAjC,KAAAxD,YAEA,KAAAM,EAEA,KAAAsG,EAAAnB,KACA,SAAAhF,GAAA,gDAQA,IANA0G,EAAAP,EAAAnB,KAAAT,SAGA,KAAAmC,IACAA,EAAAP,EAAAnB,KAAAzE,YAEA,KAAAmG,EAEA,SAAA1G,GAAA,6CAGA,OADA2G,GAAA5D,KAAAxD,WAAAW,OAAAwG,IACA,GAA+CnC,KAAAoC,UAK/CxB,IFxKAjG,GAAA,kBAAA6B,CAoBA,IAAAM,GAAA,WAeAN,GAAAU,EAAA,YJqjBG,MACO,MAAM5B,GACN,KAAUqD,OACR","file":"firebase-functions.js","sourcesContent":["/*!\n * @license Firebase v4.12.1\n * Build: rev-5cfbafd\n * Terms: https://firebase.google.com/terms/\n */\ntry {\n webpackJsonpFirebase([4],{\n\n/***/ 118:\n/***/ (function(module, exports, __webpack_require__) {\n\n/**\n * Copyright 2017 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n__webpack_require__(119);\n\n\n/***/ }),\n\n/***/ 119:\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\nObject.defineProperty(__webpack_exports__, \"__esModule\", { value: true });\n\n// EXTERNAL MODULE: ../app/dist/esm/index.js + 1 modules\nvar esm = __webpack_require__(7);\n\n// EXTERNAL MODULE: /tmp/tmp-200660cAD3hoK2kLNh/node_modules/tslib/tslib.es6.js\nvar tslib_es6 = __webpack_require__(2);\n\n// CONCATENATED MODULE: ../functions/dist/esm/src/api/error.js\n/**\n * Copyright 2017 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Standard error codes for different ways a request can fail, as defined by:\n * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto\n *\n * This map is used primarily to convert from a backend error code string to\n * a client SDK error code string, and make sure it's in the supported set.\n */\nvar errorCodeMap = {\n OK: 'ok',\n CANCELLED: 'cancelled',\n UNKNOWN: 'unknown',\n INVALID_ARGUMENT: 'invalid-argument',\n DEADLINE_EXCEEDED: 'deadline-exceeded',\n NOT_FOUND: 'not-found',\n ALREADY_EXISTS: 'already-exists',\n PERMISSION_DENIED: 'permission-denied',\n UNAUTHENTICATED: 'unauthenticated',\n RESOURCE_EXHAUSTED: 'resource-exhausted',\n FAILED_PRECONDITION: 'failed-precondition',\n ABORTED: 'aborted',\n OUT_OF_RANGE: 'out-of-range',\n UNIMPLEMENTED: 'unimplemented',\n INTERNAL: 'internal',\n UNAVAILABLE: 'unavailable',\n DATA_LOSS: 'data-loss'\n};\n/**\n * An explicit error that can be thrown from a handler to send an error to the\n * client that called the function.\n */\nvar error_HttpsErrorImpl = /** @class */ (function (_super) {\n tslib_es6[\"__extends\"](HttpsErrorImpl, _super);\n function HttpsErrorImpl(code, message, details) {\n var _this = _super.call(this, message) || this;\n // This is a workaround for a bug in TypeScript when extending Error:\n // tslint:disable-next-line\n // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(_this, HttpsErrorImpl.prototype);\n _this.code = code;\n _this.details = details;\n return _this;\n }\n return HttpsErrorImpl;\n}(Error));\n\n/**\n * Takes an HTTP status code and returns the corresponding ErrorCode.\n * This is the standard HTTP status code -> error mapping defined in:\n * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto\n *\n * @param status An HTTP status code.\n * @return The corresponding ErrorCode, or ErrorCode.UNKNOWN if none.\n */\nfunction codeForHTTPStatus(status) {\n // Make sure any successful status is OK.\n if (status >= 200 && status < 300) {\n return 'ok';\n }\n switch (status) {\n case 0:\n // This can happen if the server returns 500.\n return 'internal';\n case 400:\n return 'invalid-argument';\n case 401:\n return 'unauthenticated';\n case 403:\n return 'permission-denied';\n case 404:\n return 'not-found';\n case 409:\n return 'aborted';\n case 429:\n return 'resource-exhausted';\n case 499:\n return 'cancelled';\n case 500:\n return 'internal';\n case 501:\n return 'unimplemented';\n case 503:\n return 'unavailable';\n case 504:\n return 'deadline-exceeded';\n }\n return 'unknown';\n}\n/**\n * Takes an HTTP response and returns the corresponding Error, if any.\n */\nfunction _errorForResponse(status, bodyJSON, serializer) {\n var code = codeForHTTPStatus(status);\n // Start with reasonable defaults from the status code.\n var description = code;\n var details = undefined;\n // Then look through the body for explicit details.\n try {\n var errorJSON = bodyJSON.error;\n if (errorJSON) {\n var status_1 = errorJSON.status;\n if (typeof status_1 === 'string') {\n if (!errorCodeMap[status_1]) {\n // They must've included an unknown error code in the body.\n return new error_HttpsErrorImpl('internal', 'internal');\n }\n code = errorCodeMap[status_1];\n }\n // TODO(klimt): Add better default descriptions for error enums.\n // The default description needs to be updated for the new code.\n description = status_1;\n var message = errorJSON.message;\n if (typeof message === 'string') {\n description = message;\n }\n details = errorJSON.details;\n if (details !== undefined) {\n details = serializer.decode(details);\n }\n }\n }\n catch (e) {\n // If we couldn't parse explicit error data, that's fine.\n }\n if (code === 'ok') {\n // Technically, there's an edge case where a developer could explicitly\n // return an error code of OK, and we will treat it as success, but that\n // seems reasonable.\n return null;\n }\n return new error_HttpsErrorImpl(code, description, details);\n}\n\n//# sourceMappingURL=error.js.map\n\n// CONCATENATED MODULE: ../functions/dist/esm/src/context.js\n\n/**\n * Helper class to get metadata that should be included with a function call.\n */\nvar context_ContextProvider = /** @class */ (function () {\n function ContextProvider(app) {\n this.app = app;\n }\n ContextProvider.prototype.getAuthToken = function () {\n return tslib_es6[\"__awaiter\"](this, void 0, void 0, function () {\n var token, e_1;\n return tslib_es6[\"__generator\"](this, function (_a) {\n switch (_a.label) {\n case 0:\n _a.trys.push([0, 2, , 3]);\n return [4 /*yield*/, this.app.INTERNAL.getToken()];\n case 1:\n token = _a.sent();\n if (!token) {\n return [2 /*return*/, undefined];\n }\n return [2 /*return*/, token.accessToken];\n case 2:\n e_1 = _a.sent();\n // If there's any error when trying to get the auth token, leave it off.\n return [2 /*return*/, undefined];\n case 3: return [2 /*return*/];\n }\n });\n });\n };\n ContextProvider.prototype.getInstanceIdToken = function () {\n return tslib_es6[\"__awaiter\"](this, void 0, void 0, function () {\n var messaging, token, e_2;\n return tslib_es6[\"__generator\"](this, function (_a) {\n switch (_a.label) {\n case 0:\n _a.trys.push([0, 2, , 3]);\n // HACK: Until we have a separate instanceId package, this is a quick way\n // to load in the messaging instance for this app.\n if (!this.app.messaging) {\n return [2 /*return*/, undefined];\n }\n messaging = this.app.messaging();\n return [4 /*yield*/, messaging.getToken()];\n case 1:\n token = _a.sent();\n if (!token) {\n return [2 /*return*/, undefined];\n }\n return [2 /*return*/, token];\n case 2:\n e_2 = _a.sent();\n // We don't warn on this, because it usually means messaging isn't set up.\n // console.warn('Failed to retrieve instance id token.', e);\n // If there's any error when trying to get the token, leave it off.\n return [2 /*return*/, undefined];\n case 3: return [2 /*return*/];\n }\n });\n });\n };\n ContextProvider.prototype.getContext = function () {\n return tslib_es6[\"__awaiter\"](this, void 0, void 0, function () {\n var authToken, instanceIdToken;\n return tslib_es6[\"__generator\"](this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this.getAuthToken()];\n case 1:\n authToken = _a.sent();\n return [4 /*yield*/, this.getInstanceIdToken()];\n case 2:\n instanceIdToken = _a.sent();\n return [2 /*return*/, { authToken: authToken, instanceIdToken: instanceIdToken }];\n }\n });\n });\n };\n return ContextProvider;\n}());\n\n\n//# sourceMappingURL=context.js.map\n\n// CONCATENATED MODULE: ../functions/dist/esm/src/serializer.js\n/**\n * Copyright 2017 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nvar LONG_TYPE = 'type.googleapis.com/google.protobuf.Int64Value';\nvar UNSIGNED_LONG_TYPE = 'type.googleapis.com/google.protobuf.UInt64Value';\nfunction mapValues(o, f) {\n var result = {};\n for (var key in o) {\n if (o.hasOwnProperty(key)) {\n result[key] = f(o[key]);\n }\n }\n return result;\n}\nvar Serializer = /** @class */ (function () {\n function Serializer() {\n }\n // Takes data and encodes it in a JSON-friendly way, such that types such as\n // Date are preserved.\n Serializer.prototype.encode = function (data) {\n var _this = this;\n if (data === null || data === undefined) {\n return null;\n }\n if (data instanceof Number) {\n data = data.valueOf();\n }\n if (typeof data === 'number' && isFinite(data)) {\n // Any number in JS is safe to put directly in JSON and parse as a double\n // without any loss of precision.\n return data;\n }\n if (data === true || data === false) {\n return data;\n }\n if (toString.call(data) === '[object String]') {\n return data;\n }\n if (Array.isArray(data)) {\n return data.map(function (x) { return _this.encode(x); });\n }\n if (typeof data === 'function' || typeof data === 'object') {\n return mapValues(data, function (x) { return _this.encode(x); });\n }\n // If we got this far, the data is not encodable.\n throw new Error('Data cannot be encoded in JSON: ' + data);\n };\n // Takes data that's been encoded in a JSON-friendly form and returns a form\n // with richer datatypes, such as Dates, etc.\n Serializer.prototype.decode = function (json) {\n var _this = this;\n if (json === null) {\n return json;\n }\n if (json['@type']) {\n switch (json['@type']) {\n case LONG_TYPE:\n // Fall through and handle this the same as unsigned.\n case UNSIGNED_LONG_TYPE: {\n // Technically, this could work return a valid number for malformed\n // data if there was a number followed by garbage. But it's just not\n // worth all the extra code to detect that case.\n var value = parseFloat(json.value);\n if (isNaN(value)) {\n throw new Error('Data cannot be decoded from JSON: ' + json);\n }\n return value;\n }\n default: {\n throw new Error('Data cannot be decoded from JSON: ' + json);\n }\n }\n }\n if (Array.isArray(json)) {\n return json.map(function (x) { return _this.decode(x); });\n }\n if (typeof json === 'function' || typeof json === 'object') {\n return mapValues(json, function (x) { return _this.decode(x); });\n }\n // Anything else is safe to return.\n return json;\n };\n return Serializer;\n}());\n\n\n//# sourceMappingURL=serializer.js.map\n\n// CONCATENATED MODULE: ../functions/dist/esm/src/api/service.js\n/**\n * Copyright 2017 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\n\n\n/**\n * The main class for the Firebase Functions SDK.\n */\nvar service_Service = /** @class */ (function () {\n /**\n * Creates a new Functions service for the given app and (optional) region.\n * @param app_ The FirebaseApp to use.\n * @param region_ The region to call functions in.\n */\n function Service(app_, region_) {\n if (region_ === void 0) { region_ = 'us-central1'; }\n this.app_ = app_;\n this.region_ = region_;\n this.serializer = new Serializer();\n this.contextProvider = new context_ContextProvider(app_);\n }\n Object.defineProperty(Service.prototype, \"app\", {\n get: function () {\n return this.app_;\n },\n enumerable: true,\n configurable: true\n });\n /**\n * Returns the URL for a callable with the given name.\n * @param name The name of the callable.\n */\n Service.prototype._url = function (name) {\n var projectId = this.app_.options.projectId;\n var region = this.region_;\n return \"https://\" + region + \"-\" + projectId + \".cloudfunctions.net/\" + name;\n };\n /**\n * Returns a reference to the callable https trigger with the given name.\n * @param name The name of the trigger.\n */\n Service.prototype.httpsCallable = function (name) {\n var _this = this;\n var callable = function (data) {\n return _this.call(name, data);\n };\n return callable;\n };\n /**\n * Does an HTTP POST and returns the completed response.\n * @param url The url to post to.\n * @param body The JSON body of the post.\n * @param headers The HTTP headers to include in the request.\n * @return A Promise that will succeed when the request finishes.\n */\n Service.prototype.postJSON = function (url, body, headers) {\n return tslib_es6[\"__awaiter\"](this, void 0, void 0, function () {\n var response, e_1, json, e_2;\n return tslib_es6[\"__generator\"](this, function (_a) {\n switch (_a.label) {\n case 0:\n headers.append('Content-Type', 'application/json');\n _a.label = 1;\n case 1:\n _a.trys.push([1, 3, , 4]);\n return [4 /*yield*/, fetch(url, {\n method: 'POST',\n body: JSON.stringify(body),\n headers: headers\n })];\n case 2:\n response = _a.sent();\n return [3 /*break*/, 4];\n case 3:\n e_1 = _a.sent();\n // This could be an unhandled error on the backend, or it could be a\n // network error. There's no way to no, since an unhandled error on the\n // backend will fail to set the proper CORS header, and thus will be\n // treated as a network error by fetch.\n return [2 /*return*/, {\n status: 0,\n json: null\n }];\n case 4:\n json = null;\n _a.label = 5;\n case 5:\n _a.trys.push([5, 7, , 8]);\n return [4 /*yield*/, response.json()];\n case 6:\n json = _a.sent();\n return [3 /*break*/, 8];\n case 7:\n e_2 = _a.sent();\n return [3 /*break*/, 8];\n case 8: return [2 /*return*/, {\n status: response.status,\n json: json\n }];\n }\n });\n });\n };\n /**\n * Calls a callable function asynchronously and returns the result.\n * @param name The name of the callable trigger.\n * @param data The data to pass as params to the function.s\n */\n Service.prototype.call = function (name, data) {\n return tslib_es6[\"__awaiter\"](this, void 0, void 0, function () {\n var url, body, headers, context, response, error, responseData, decodedData;\n return tslib_es6[\"__generator\"](this, function (_a) {\n switch (_a.label) {\n case 0:\n url = this._url(name);\n // Encode any special types, such as dates, in the input data.\n data = this.serializer.encode(data);\n body = { data: data };\n headers = new Headers();\n return [4 /*yield*/, this.contextProvider.getContext()];\n case 1:\n context = _a.sent();\n if (context.authToken) {\n headers.append('Authorization', 'Bearer ' + context.authToken);\n }\n if (context.instanceIdToken) {\n headers.append('Firebase-Instance-ID-Token', context.instanceIdToken);\n }\n return [4 /*yield*/, this.postJSON(url, body, headers)];\n case 2:\n response = _a.sent();\n error = _errorForResponse(response.status, response.json, this.serializer);\n if (error) {\n throw error;\n }\n if (!response.json) {\n throw new error_HttpsErrorImpl('internal', 'Response is not valid JSON object.');\n }\n responseData = response.json.data;\n // TODO(klimt): For right now, allow \"result\" instead of \"data\", for\n // backwards compatibility.\n if (typeof responseData === 'undefined') {\n responseData = response.json.result;\n }\n if (typeof responseData === 'undefined') {\n // Consider the response malformed.\n throw new error_HttpsErrorImpl('internal', 'Response is missing data field.');\n }\n decodedData = this.serializer.decode(responseData);\n return [2 /*return*/, { data: decodedData }];\n }\n });\n });\n };\n return Service;\n}());\n\n\n//# sourceMappingURL=service.js.map\n\n// CONCATENATED MODULE: ../functions/dist/esm/index.js\n/* harmony export (immutable) */ __webpack_exports__[\"registerFunctions\"] = registerFunctions;\n/**\n * Copyright 2017 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\n/**\n * Type constant for Firebase Functions.\n */\nvar FUNCTIONS_TYPE = 'functions';\nfunction factory(app, unused, region) {\n return new service_Service(app, region);\n}\nfunction registerFunctions(instance) {\n var namespaceExports = {\n // no-inline\n Functions: service_Service\n };\n instance.INTERNAL.registerService(FUNCTIONS_TYPE, factory, namespaceExports, \n // We don't need to wait on any AppHooks.\n undefined, \n // Allow multiple functions instances per app.\n true);\n}\nregisterFunctions(esm[\"default\"]);\n\n//# sourceMappingURL=index.js.map\n\n\n/***/ })\n\n},[118]);\n } catch(error) {\n throw new Error(\n 'Cannot instantiate firebase-functions.js - ' +\n 'be sure to load firebase-app.js first.'\n )\n }\n\n\n// WEBPACK FOOTER //\n// firebase-functions.js","/**\n * Copyright 2017 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nrequire('@firebase/functions');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./functions/index.js\n// module id = 118\n// module chunks = 4","/**\n * Copyright 2017 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as tslib_1 from \"tslib\";\n/**\n * Standard error codes for different ways a request can fail, as defined by:\n * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto\n *\n * This map is used primarily to convert from a backend error code string to\n * a client SDK error code string, and make sure it's in the supported set.\n */\nvar errorCodeMap = {\n OK: 'ok',\n CANCELLED: 'cancelled',\n UNKNOWN: 'unknown',\n INVALID_ARGUMENT: 'invalid-argument',\n DEADLINE_EXCEEDED: 'deadline-exceeded',\n NOT_FOUND: 'not-found',\n ALREADY_EXISTS: 'already-exists',\n PERMISSION_DENIED: 'permission-denied',\n UNAUTHENTICATED: 'unauthenticated',\n RESOURCE_EXHAUSTED: 'resource-exhausted',\n FAILED_PRECONDITION: 'failed-precondition',\n ABORTED: 'aborted',\n OUT_OF_RANGE: 'out-of-range',\n UNIMPLEMENTED: 'unimplemented',\n INTERNAL: 'internal',\n UNAVAILABLE: 'unavailable',\n DATA_LOSS: 'data-loss'\n};\n/**\n * An explicit error that can be thrown from a handler to send an error to the\n * client that called the function.\n */\nvar HttpsErrorImpl = /** @class */ (function (_super) {\n tslib_1.__extends(HttpsErrorImpl, _super);\n function HttpsErrorImpl(code, message, details) {\n var _this = _super.call(this, message) || this;\n // This is a workaround for a bug in TypeScript when extending Error:\n // tslint:disable-next-line\n // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(_this, HttpsErrorImpl.prototype);\n _this.code = code;\n _this.details = details;\n return _this;\n }\n return HttpsErrorImpl;\n}(Error));\nexport { HttpsErrorImpl };\n/**\n * Takes an HTTP status code and returns the corresponding ErrorCode.\n * This is the standard HTTP status code -> error mapping defined in:\n * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto\n *\n * @param status An HTTP status code.\n * @return The corresponding ErrorCode, or ErrorCode.UNKNOWN if none.\n */\nfunction codeForHTTPStatus(status) {\n // Make sure any successful status is OK.\n if (status >= 200 && status < 300) {\n return 'ok';\n }\n switch (status) {\n case 0:\n // This can happen if the server returns 500.\n return 'internal';\n case 400:\n return 'invalid-argument';\n case 401:\n return 'unauthenticated';\n case 403:\n return 'permission-denied';\n case 404:\n return 'not-found';\n case 409:\n return 'aborted';\n case 429:\n return 'resource-exhausted';\n case 499:\n return 'cancelled';\n case 500:\n return 'internal';\n case 501:\n return 'unimplemented';\n case 503:\n return 'unavailable';\n case 504:\n return 'deadline-exceeded';\n }\n return 'unknown';\n}\n/**\n * Takes an HTTP response and returns the corresponding Error, if any.\n */\nexport function _errorForResponse(status, bodyJSON, serializer) {\n var code = codeForHTTPStatus(status);\n // Start with reasonable defaults from the status code.\n var description = code;\n var details = undefined;\n // Then look through the body for explicit details.\n try {\n var errorJSON = bodyJSON.error;\n if (errorJSON) {\n var status_1 = errorJSON.status;\n if (typeof status_1 === 'string') {\n if (!errorCodeMap[status_1]) {\n // They must've included an unknown error code in the body.\n return new HttpsErrorImpl('internal', 'internal');\n }\n code = errorCodeMap[status_1];\n }\n // TODO(klimt): Add better default descriptions for error enums.\n // The default description needs to be updated for the new code.\n description = status_1;\n var message = errorJSON.message;\n if (typeof message === 'string') {\n description = message;\n }\n details = errorJSON.details;\n if (details !== undefined) {\n details = serializer.decode(details);\n }\n }\n }\n catch (e) {\n // If we couldn't parse explicit error data, that's fine.\n }\n if (code === 'ok') {\n // Technically, there's an edge case where a developer could explicitly\n // return an error code of OK, and we will treat it as success, but that\n // seems reasonable.\n return null;\n }\n return new HttpsErrorImpl(code, description, details);\n}\n\n//# sourceMappingURL=error.js.map\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../functions/dist/esm/src/api/error.js\n// module id = null\n// module chunks = ","/**\n * Copyright 2017 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nvar LONG_TYPE = 'type.googleapis.com/google.protobuf.Int64Value';\nvar UNSIGNED_LONG_TYPE = 'type.googleapis.com/google.protobuf.UInt64Value';\nfunction mapValues(o, f) {\n var result = {};\n for (var key in o) {\n if (o.hasOwnProperty(key)) {\n result[key] = f(o[key]);\n }\n }\n return result;\n}\nvar Serializer = /** @class */ (function () {\n function Serializer() {\n }\n // Takes data and encodes it in a JSON-friendly way, such that types such as\n // Date are preserved.\n Serializer.prototype.encode = function (data) {\n var _this = this;\n if (data === null || data === undefined) {\n return null;\n }\n if (data instanceof Number) {\n data = data.valueOf();\n }\n if (typeof data === 'number' && isFinite(data)) {\n // Any number in JS is safe to put directly in JSON and parse as a double\n // without any loss of precision.\n return data;\n }\n if (data === true || data === false) {\n return data;\n }\n if (toString.call(data) === '[object String]') {\n return data;\n }\n if (Array.isArray(data)) {\n return data.map(function (x) { return _this.encode(x); });\n }\n if (typeof data === 'function' || typeof data === 'object') {\n return mapValues(data, function (x) { return _this.encode(x); });\n }\n // If we got this far, the data is not encodable.\n throw new Error('Data cannot be encoded in JSON: ' + data);\n };\n // Takes data that's been encoded in a JSON-friendly form and returns a form\n // with richer datatypes, such as Dates, etc.\n Serializer.prototype.decode = function (json) {\n var _this = this;\n if (json === null) {\n return json;\n }\n if (json['@type']) {\n switch (json['@type']) {\n case LONG_TYPE:\n // Fall through and handle this the same as unsigned.\n case UNSIGNED_LONG_TYPE: {\n // Technically, this could work return a valid number for malformed\n // data if there was a number followed by garbage. But it's just not\n // worth all the extra code to detect that case.\n var value = parseFloat(json.value);\n if (isNaN(value)) {\n throw new Error('Data cannot be decoded from JSON: ' + json);\n }\n return value;\n }\n default: {\n throw new Error('Data cannot be decoded from JSON: ' + json);\n }\n }\n }\n if (Array.isArray(json)) {\n return json.map(function (x) { return _this.decode(x); });\n }\n if (typeof json === 'function' || typeof json === 'object') {\n return mapValues(json, function (x) { return _this.decode(x); });\n }\n // Anything else is safe to return.\n return json;\n };\n return Serializer;\n}());\nexport { Serializer };\n\n//# sourceMappingURL=serializer.js.map\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../functions/dist/esm/src/serializer.js\n// module id = null\n// module chunks = ","/**\n * Copyright 2017 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport firebase from '@firebase/app';\nimport { Service } from './src/api/service';\n/**\n * Type constant for Firebase Functions.\n */\nvar FUNCTIONS_TYPE = 'functions';\nfunction factory(app, unused, region) {\n return new Service(app, region);\n}\nexport function registerFunctions(instance) {\n var namespaceExports = {\n // no-inline\n Functions: Service\n };\n instance.INTERNAL.registerService(FUNCTIONS_TYPE, factory, namespaceExports, \n // We don't need to wait on any AppHooks.\n undefined, \n // Allow multiple functions instances per app.\n true);\n}\nregisterFunctions(firebase);\n\n//# sourceMappingURL=index.js.map\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../functions/dist/esm/index.js\n// module id = null\n// module chunks = ","import * as tslib_1 from \"tslib\";\n/**\n * Helper class to get metadata that should be included with a function call.\n */\nvar ContextProvider = /** @class */ (function () {\n function ContextProvider(app) {\n this.app = app;\n }\n ContextProvider.prototype.getAuthToken = function () {\n return tslib_1.__awaiter(this, void 0, void 0, function () {\n var token, e_1;\n return tslib_1.__generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _a.trys.push([0, 2, , 3]);\n return [4 /*yield*/, this.app.INTERNAL.getToken()];\n case 1:\n token = _a.sent();\n if (!token) {\n return [2 /*return*/, undefined];\n }\n return [2 /*return*/, token.accessToken];\n case 2:\n e_1 = _a.sent();\n // If there's any error when trying to get the auth token, leave it off.\n return [2 /*return*/, undefined];\n case 3: return [2 /*return*/];\n }\n });\n });\n };\n ContextProvider.prototype.getInstanceIdToken = function () {\n return tslib_1.__awaiter(this, void 0, void 0, function () {\n var messaging, token, e_2;\n return tslib_1.__generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _a.trys.push([0, 2, , 3]);\n // HACK: Until we have a separate instanceId package, this is a quick way\n // to load in the messaging instance for this app.\n if (!this.app.messaging) {\n return [2 /*return*/, undefined];\n }\n messaging = this.app.messaging();\n return [4 /*yield*/, messaging.getToken()];\n case 1:\n token = _a.sent();\n if (!token) {\n return [2 /*return*/, undefined];\n }\n return [2 /*return*/, token];\n case 2:\n e_2 = _a.sent();\n // We don't warn on this, because it usually means messaging isn't set up.\n // console.warn('Failed to retrieve instance id token.', e);\n // If there's any error when trying to get the token, leave it off.\n return [2 /*return*/, undefined];\n case 3: return [2 /*return*/];\n }\n });\n });\n };\n ContextProvider.prototype.getContext = function () {\n return tslib_1.__awaiter(this, void 0, void 0, function () {\n var authToken, instanceIdToken;\n return tslib_1.__generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this.getAuthToken()];\n case 1:\n authToken = _a.sent();\n return [4 /*yield*/, this.getInstanceIdToken()];\n case 2:\n instanceIdToken = _a.sent();\n return [2 /*return*/, { authToken: authToken, instanceIdToken: instanceIdToken }];\n }\n });\n });\n };\n return ContextProvider;\n}());\nexport { ContextProvider };\n\n//# sourceMappingURL=context.js.map\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../functions/dist/esm/src/context.js\n// module id = null\n// module chunks = ","/**\n * Copyright 2017 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as tslib_1 from \"tslib\";\nimport { _errorForResponse, HttpsErrorImpl } from './error';\nimport { ContextProvider } from '../context';\nimport { Serializer } from '../serializer';\n/**\n * The main class for the Firebase Functions SDK.\n */\nvar Service = /** @class */ (function () {\n /**\n * Creates a new Functions service for the given app and (optional) region.\n * @param app_ The FirebaseApp to use.\n * @param region_ The region to call functions in.\n */\n function Service(app_, region_) {\n if (region_ === void 0) { region_ = 'us-central1'; }\n this.app_ = app_;\n this.region_ = region_;\n this.serializer = new Serializer();\n this.contextProvider = new ContextProvider(app_);\n }\n Object.defineProperty(Service.prototype, \"app\", {\n get: function () {\n return this.app_;\n },\n enumerable: true,\n configurable: true\n });\n /**\n * Returns the URL for a callable with the given name.\n * @param name The name of the callable.\n */\n Service.prototype._url = function (name) {\n var projectId = this.app_.options.projectId;\n var region = this.region_;\n return \"https://\" + region + \"-\" + projectId + \".cloudfunctions.net/\" + name;\n };\n /**\n * Returns a reference to the callable https trigger with the given name.\n * @param name The name of the trigger.\n */\n Service.prototype.httpsCallable = function (name) {\n var _this = this;\n var callable = function (data) {\n return _this.call(name, data);\n };\n return callable;\n };\n /**\n * Does an HTTP POST and returns the completed response.\n * @param url The url to post to.\n * @param body The JSON body of the post.\n * @param headers The HTTP headers to include in the request.\n * @return A Promise that will succeed when the request finishes.\n */\n Service.prototype.postJSON = function (url, body, headers) {\n return tslib_1.__awaiter(this, void 0, void 0, function () {\n var response, e_1, json, e_2;\n return tslib_1.__generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n headers.append('Content-Type', 'application/json');\n _a.label = 1;\n case 1:\n _a.trys.push([1, 3, , 4]);\n return [4 /*yield*/, fetch(url, {\n method: 'POST',\n body: JSON.stringify(body),\n headers: headers\n })];\n case 2:\n response = _a.sent();\n return [3 /*break*/, 4];\n case 3:\n e_1 = _a.sent();\n // This could be an unhandled error on the backend, or it could be a\n // network error. There's no way to no, since an unhandled error on the\n // backend will fail to set the proper CORS header, and thus will be\n // treated as a network error by fetch.\n return [2 /*return*/, {\n status: 0,\n json: null\n }];\n case 4:\n json = null;\n _a.label = 5;\n case 5:\n _a.trys.push([5, 7, , 8]);\n return [4 /*yield*/, response.json()];\n case 6:\n json = _a.sent();\n return [3 /*break*/, 8];\n case 7:\n e_2 = _a.sent();\n return [3 /*break*/, 8];\n case 8: return [2 /*return*/, {\n status: response.status,\n json: json\n }];\n }\n });\n });\n };\n /**\n * Calls a callable function asynchronously and returns the result.\n * @param name The name of the callable trigger.\n * @param data The data to pass as params to the function.s\n */\n Service.prototype.call = function (name, data) {\n return tslib_1.__awaiter(this, void 0, void 0, function () {\n var url, body, headers, context, response, error, responseData, decodedData;\n return tslib_1.__generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n url = this._url(name);\n // Encode any special types, such as dates, in the input data.\n data = this.serializer.encode(data);\n body = { data: data };\n headers = new Headers();\n return [4 /*yield*/, this.contextProvider.getContext()];\n case 1:\n context = _a.sent();\n if (context.authToken) {\n headers.append('Authorization', 'Bearer ' + context.authToken);\n }\n if (context.instanceIdToken) {\n headers.append('Firebase-Instance-ID-Token', context.instanceIdToken);\n }\n return [4 /*yield*/, this.postJSON(url, body, headers)];\n case 2:\n response = _a.sent();\n error = _errorForResponse(response.status, response.json, this.serializer);\n if (error) {\n throw error;\n }\n if (!response.json) {\n throw new HttpsErrorImpl('internal', 'Response is not valid JSON object.');\n }\n responseData = response.json.data;\n // TODO(klimt): For right now, allow \"result\" instead of \"data\", for\n // backwards compatibility.\n if (typeof responseData === 'undefined') {\n responseData = response.json.result;\n }\n if (typeof responseData === 'undefined') {\n // Consider the response malformed.\n throw new HttpsErrorImpl('internal', 'Response is missing data field.');\n }\n decodedData = this.serializer.decode(responseData);\n return [2 /*return*/, { data: decodedData }];\n }\n });\n });\n };\n return Service;\n}());\nexport { Service };\n\n//# sourceMappingURL=service.js.map\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../functions/dist/esm/src/api/service.js\n// module id = null\n// module chunks = "],"sourceRoot":""}