├── .eslintrc.js ├── .github ├── ISSUE_TEMPLATE │ ├── feature_request.md │ ├── firestore-issue.md │ └── general-bug-report.md ├── actions │ ├── send-email │ │ ├── README.md │ │ ├── action.yml │ │ ├── dist │ │ │ └── index.js │ │ ├── index.js │ │ ├── package-lock.json │ │ └── package.json │ └── send-tweet │ │ ├── README.md │ │ ├── action.yml │ │ ├── dist │ │ └── index.js │ │ ├── index.js │ │ ├── package-lock.json │ │ └── package.json ├── dependabot.yml ├── resources │ └── integ-service-account.json.gpg ├── scripts │ ├── generate_changelog.sh │ ├── publish_package.sh │ ├── publish_preflight_check.sh │ ├── run_integration_tests.sh │ └── verify_package.sh └── workflows │ ├── ci.yml │ ├── nightly.yml │ └── release.yml ├── .gitignore ├── .opensource └── project.json ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── PULL_REQUEST_TEMPLATE.md ├── README.md ├── api-extractor.json ├── docgen ├── extras │ ├── firebase-admin.database.md │ └── firebase-admin.firestore.md └── post-process.js ├── entrypoints.json ├── etc ├── firebase-admin.api.md ├── firebase-admin.app-check.api.md ├── firebase-admin.app.api.md ├── firebase-admin.auth.api.md ├── firebase-admin.data-connect.api.md ├── firebase-admin.database.api.md ├── firebase-admin.eventarc.api.md ├── firebase-admin.extensions.api.md ├── firebase-admin.firestore.api.md ├── firebase-admin.functions.api.md ├── firebase-admin.installations.api.md ├── firebase-admin.instance-id.api.md ├── firebase-admin.machine-learning.api.md ├── firebase-admin.messaging.api.md ├── firebase-admin.project-management.api.md ├── firebase-admin.remote-config.api.md ├── firebase-admin.security-rules.api.md └── firebase-admin.storage.api.md ├── generate-esm-wrapper.js ├── generate-reports.js ├── gulpfile.js ├── package-lock.json ├── package.json ├── src ├── app-check │ ├── app-check-api-client-internal.ts │ ├── app-check-api.ts │ ├── app-check-namespace.ts │ ├── app-check.ts │ ├── index.ts │ ├── token-generator.ts │ └── token-verifier.ts ├── app │ ├── core.ts │ ├── credential-factory.ts │ ├── credential-internal.ts │ ├── credential.ts │ ├── firebase-app.ts │ ├── firebase-namespace.ts │ ├── index.ts │ └── lifecycle.ts ├── auth │ ├── action-code-settings-builder.ts │ ├── auth-api-request.ts │ ├── auth-config.ts │ ├── auth-namespace.ts │ ├── auth.ts │ ├── base-auth.ts │ ├── identifier.ts │ ├── index.ts │ ├── project-config-manager.ts │ ├── project-config.ts │ ├── tenant-manager.ts │ ├── tenant.ts │ ├── token-generator.ts │ ├── token-verifier.ts │ ├── user-import-builder.ts │ └── user-record.ts ├── credential │ └── index.ts ├── data-connect │ ├── data-connect-api-client-internal.ts │ ├── data-connect-api.ts │ ├── data-connect.ts │ └── index.ts ├── database │ ├── database-namespace.ts │ ├── database.ts │ └── index.ts ├── default-namespace.d.ts ├── default-namespace.ts ├── eventarc │ ├── cloudevent.ts │ ├── eventarc-client-internal.ts │ ├── eventarc-utils.ts │ ├── eventarc.ts │ └── index.ts ├── extensions │ ├── extensions-api-client-internal.ts │ ├── extensions-api.ts │ ├── extensions.ts │ └── index.ts ├── firebase-namespace-api.ts ├── firestore │ ├── firestore-internal.ts │ ├── firestore-namespace.ts │ └── index.ts ├── functions │ ├── functions-api-client-internal.ts │ ├── functions-api.ts │ ├── functions.ts │ └── index.ts ├── index.d.ts ├── index.ts ├── installations │ ├── index.ts │ ├── installations-namespace.ts │ ├── installations-request-handler.ts │ └── installations.ts ├── instance-id │ ├── index.ts │ ├── instance-id-namespace.ts │ └── instance-id.ts ├── machine-learning │ ├── index.ts │ ├── machine-learning-api-client.ts │ ├── machine-learning-namespace.ts │ ├── machine-learning-utils.ts │ └── machine-learning.ts ├── messaging │ ├── index.ts │ ├── messaging-api-request-internal.ts │ ├── messaging-api.ts │ ├── messaging-errors-internal.ts │ ├── messaging-internal.ts │ ├── messaging-namespace.ts │ └── messaging.ts ├── project-management │ ├── android-app.ts │ ├── app-metadata.ts │ ├── index.ts │ ├── ios-app.ts │ ├── project-management-api-request-internal.ts │ ├── project-management-namespace.ts │ └── project-management.ts ├── remote-config │ ├── condition-evaluator-internal.ts │ ├── index.ts │ ├── internal │ │ └── value-impl.ts │ ├── remote-config-api-client-internal.ts │ ├── remote-config-api.ts │ ├── remote-config-namespace.ts │ └── remote-config.ts ├── security-rules │ ├── index.ts │ ├── security-rules-api-client-internal.ts │ ├── security-rules-internal.ts │ ├── security-rules-namespace.ts │ └── security-rules.ts ├── storage │ ├── index.ts │ ├── storage-namespace.ts │ ├── storage.ts │ └── utils.ts └── utils │ ├── api-request.ts │ ├── crypto-signer.ts │ ├── deep-copy.ts │ ├── error.ts │ ├── index.ts │ ├── jwt.ts │ └── validator.ts ├── test ├── integration │ ├── app-check.spec.ts │ ├── app.spec.ts │ ├── auth.spec.ts │ ├── data-connect.spec.ts │ ├── database.spec.ts │ ├── firestore.spec.ts │ ├── functions.spec.ts │ ├── installations.spec.ts │ ├── instance-id.spec.ts │ ├── machine-learning.spec.ts │ ├── messaging.spec.ts │ ├── postcheck │ │ ├── esm │ │ │ ├── example.test.js │ │ │ └── package.json │ │ ├── package.json │ │ ├── tsconfig.json │ │ └── typescript │ │ │ ├── example-modular.test.ts │ │ │ ├── example.test.ts │ │ │ └── example.ts │ ├── project-management.spec.ts │ ├── remote-config.spec.ts │ ├── security-rules.spec.ts │ ├── setup.ts │ └── storage.spec.ts ├── resources │ ├── firebase_config.json │ ├── firebase_config_bad.json │ ├── firebase_config_bad_key.json │ ├── firebase_config_empty.json │ ├── firebase_config_partial.json │ ├── invalid_model.tflite │ ├── mock.impersonated_key.json │ ├── mock.jwks.json │ ├── mock.key.json │ ├── mocks.ts │ ├── model1.tflite │ └── unparsable.key.json └── unit │ ├── app-check │ ├── app-check-api-client-internal.spec.ts │ ├── app-check.spec.ts │ ├── token-generator.spec.ts │ └── token-verifier.spec.ts │ ├── app │ ├── credential-internal.spec.ts │ ├── firebase-app.spec.ts │ ├── firebase-namespace.spec.ts │ └── index.spec.ts │ ├── auth │ ├── action-code-settings-builder.spec.ts │ ├── auth-api-request.spec.ts │ ├── auth-config.spec.ts │ ├── auth.spec.ts │ ├── index.spec.ts │ ├── project-config-manager.spec.ts │ ├── project-config.spec.ts │ ├── tenant-manager.spec.ts │ ├── tenant.spec.ts │ ├── token-generator.spec.ts │ ├── token-verifier.spec.ts │ ├── user-import-builder.spec.ts │ └── user-record.spec.ts │ ├── data-connect │ ├── data-connect-api-client-internal.spec.ts │ └── index.spec.ts │ ├── database │ ├── database.spec.ts │ └── index.spec.ts │ ├── eventarc │ ├── eventarc-utils.spec.ts │ └── eventarc.spec.ts │ ├── extensions │ ├── extensions-api-client-internal.spec.ts │ └── extensions.spec.ts │ ├── firebase.spec.ts │ ├── firestore │ ├── firestore.spec.ts │ └── index.spec.ts │ ├── functions │ ├── functions-api-client-internal.spec.ts │ ├── functions.spec.ts │ └── index.spec.ts │ ├── index.spec.ts │ ├── installations │ ├── installations-request-handler.spec.ts │ └── installations.spec.ts │ ├── instance-id │ ├── index.spec.ts │ └── instance-id.spec.ts │ ├── machine-learning │ ├── index.spec.ts │ ├── machine-learning-api-client.spec.ts │ └── machine-learning.spec.ts │ ├── messaging │ ├── index.spec.ts │ └── messaging.spec.ts │ ├── project-management │ ├── android-app.spec.ts │ ├── index.spec.ts │ ├── ios-app.spec.ts │ ├── project-management-api-request.spec.ts │ └── project-management.spec.ts │ ├── remote-config │ ├── condition-evaluator.spec.ts │ ├── index.spec.ts │ ├── internal │ │ └── value-impl.spec.ts │ ├── remote-config-api-client.spec.ts │ └── remote-config.spec.ts │ ├── security-rules │ ├── index.spec.ts │ ├── security-rules-api-client.spec.ts │ └── security-rules.spec.ts │ ├── storage │ ├── index.spec.ts │ └── storage.spec.ts │ ├── utils.ts │ └── utils │ ├── api-request.spec.ts │ ├── crypto-signer.spec.ts │ ├── error.spec.ts │ ├── index.spec.ts │ ├── jwt.spec.ts │ └── validator.spec.ts ├── third_party └── database-license.txt └── tsconfig.json /.eslintrc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module.exports = { 18 | root: true, 19 | parser: '@typescript-eslint/parser', 20 | plugins: [ 21 | '@typescript-eslint', 22 | ], 23 | extends: [ 24 | 'eslint:recommended', 25 | 'plugin:@typescript-eslint/recommended', 26 | ], 27 | rules: { 28 | // Following checks are temporarily disabled. We shall incrementally enable them in the 29 | // future, fixing any violations as we go. 30 | '@typescript-eslint/no-non-null-assertion': 0, 31 | 32 | // Disabled checks 33 | '@typescript-eslint/no-explicit-any': 0, 34 | '@typescript-eslint/no-use-before-define': 0, 35 | '@typescript-eslint/no-var-requires': 0, 36 | 37 | // Required checks 38 | 'indent': ['error', 2], 39 | 'keyword-spacing': ['error'], 40 | 'max-len': [ 41 | 'error', 42 | { 43 | 'code': 120, 44 | 'ignoreUrls': true 45 | } 46 | ], 47 | 'object-curly-spacing': [2, 'always'], 48 | '@typescript-eslint/explicit-function-return-type': [ 49 | 'error', 50 | { 51 | 'allowExpressions': true, 52 | 'allowTypedFunctionExpressions': true, 53 | 'allowHigherOrderFunctions': true 54 | } 55 | ], 56 | 'no-unused-vars': 'off', // Must be disabled to enable the next rule 57 | '@typescript-eslint/no-unused-vars': ['error'], 58 | 'quotes': ['error', 'single', {'avoidEscape': true}], 59 | '@typescript-eslint/naming-convention': [ 60 | 'error', 61 | { 62 | "selector": "variable", 63 | "format": ["camelCase", "UPPER_CASE"] 64 | }, 65 | { 66 | "selector": "parameter", 67 | "format": ["camelCase"], 68 | "leadingUnderscore": "allow" 69 | }, 70 | 71 | { 72 | "selector": "memberLike", 73 | "format": ["camelCase"] 74 | }, 75 | 76 | { 77 | "selector": "typeLike", 78 | "format": ["PascalCase"] 79 | }, 80 | 81 | // Ignore properties that require quotes (HTTP headers, names that include spaces or dashes etc.). 82 | { 83 | "selector": [ 84 | "classProperty", 85 | "objectLiteralProperty", 86 | "typeProperty", 87 | "classMethod", 88 | "objectLiteralMethod", 89 | "typeMethod", 90 | "accessor", 91 | "enumMember" 92 | ], 93 | "format": null, 94 | "modifiers": ["requiresQuotes"] 95 | }, 96 | 97 | // Ignore destructured property names. 98 | { 99 | "selector": "variable", 100 | "modifiers": ["destructured"], 101 | "format": null 102 | }, 103 | 104 | // Following types are temporarily disabled. We shall incrementally enable them in the 105 | // future, fixing any violations as we go. 106 | { 107 | "selector": [ 108 | "classProperty", 109 | "objectLiteralProperty", 110 | "typeProperty", 111 | "enumMember" 112 | ], 113 | "format": null 114 | } 115 | ], 116 | } 117 | }; 118 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FR]" 5 | labels: 'type: feature request' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context, code samples or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/firestore-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Firestore issue 3 | about: Bug reports and feature requests related to Cloud Firestore 4 | title: "[Firestore]" 5 | labels: 'api: firestore' 6 | assignees: schmidt-sebastian 7 | 8 | --- 9 | 10 | ### [READ] Step 1: Are you in the right place? 11 | 12 | **Cloud Firestore support is provided by the [`@google-cloud/firestore`](https://npmjs.com/package/@google-cloud/firestore) library. Therefore the easiest and most efficient way to get Firestore issues resolved is by directly reporting them at the [nodejs-firestore](https://github.com/googleapis/nodejs-firestore) GitHub repo.** 13 | 14 | If you still think the problem is related to the code in this repository, then read on. 15 | 16 | * For issues or feature requests related to __the code in this repository__ 17 | file a Github issue. 18 | * For general technical questions, post a question on [StackOverflow](http://stackoverflow.com/) 19 | with the firebase tag. 20 | * For general Firebase discussion, use the [firebase-talk](https://groups.google.com/forum/#!forum/firebase-talk) 21 | google group. 22 | * For help troubleshooting your application that does not fall under one 23 | of the above categories, reach out to the personalized 24 | [Firebase support channel](https://firebase.google.com/support/). 25 | 26 | ### [REQUIRED] Step 2: Describe your environment 27 | 28 | * Operating System version: _____ 29 | * Firebase SDK version: _____ 30 | * Firebase Product: Firestore 31 | * Node.js version: _____ 32 | * NPM version: _____ 33 | 34 | ### [REQUIRED] Step 3: Describe the problem 35 | 36 | #### Steps to reproduce: 37 | 38 | What happened? How can we make the problem occur? 39 | This could be a description, log/console output, etc. 40 | 41 | You can enable logging for Firestore by including the following line in your code: 42 | 43 | ``` 44 | admin.firestore.setLogFunction(console.log); 45 | ``` 46 | 47 | This will print Firestore logs to the console. 48 | 49 | #### Relevant Code: 50 | 51 | ``` 52 | // TODO(you): code here to reproduce the problem 53 | ``` 54 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/general-bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: General Bug report 3 | about: Bug reports related to any component in this repo 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### [READ] Step 1: Are you in the right place? 11 | 12 | * For issues related to __the code in this repository__ file a Github issue. 13 | * If the issue pertains to Cloud Firestore, read the instructions in the "Firestore issue" 14 | template. 15 | * For general technical questions, post a question on [StackOverflow](http://stackoverflow.com/) 16 | with the firebase tag. 17 | * For general Firebase discussion, use the [firebase-talk](https://groups.google.com/forum/#!forum/firebase-talk) 18 | google group. 19 | * For help troubleshooting your application that does not fall under one 20 | of the above categories, reach out to the personalized 21 | [Firebase support channel](https://firebase.google.com/support/). 22 | 23 | ### [REQUIRED] Step 2: Describe your environment 24 | 25 | * Operating System version: _____ 26 | * Firebase SDK version: _____ 27 | * Firebase Product: _____ (auth, database, storage, etc) 28 | * Node.js version: _____ 29 | * NPM version: _____ 30 | 31 | ### [REQUIRED] Step 3: Describe the problem 32 | 33 | #### Steps to reproduce: 34 | 35 | What happened? How can we make the problem occur? 36 | This could be a description, log/console output, etc. 37 | 38 | #### Relevant Code: 39 | 40 | ``` 41 | // TODO(you): code here to reproduce the problem 42 | ``` 43 | -------------------------------------------------------------------------------- /.github/actions/send-email/README.md: -------------------------------------------------------------------------------- 1 | # Send Email GitHub Action 2 | 3 | This is a minimalistic GitHub Action for sending emails using the Mailgun API. 4 | Specify the Mailgun API key along with the Mailgun domain and message to 5 | be sent. 6 | 7 | ## Inputs 8 | 9 | ### `api-key` 10 | 11 | **Required** Mailgun API key. 12 | 13 | ### `domain` 14 | 15 | **Required** Mailgun domain name. 16 | 17 | ### `from` 18 | 19 | **Required** Sender's email address. Ex: 'Hello User ' (defaults to 'user@{domain}`). 20 | 21 | ### `to` 22 | 23 | **Required** Recipient's email address. You can use commas to separate multiple recipients. 24 | 25 | ### `cc` 26 | 27 | Email addresses to Cc. 28 | 29 | ### `subject` 30 | 31 | **Required** Message subject. 32 | 33 | ### `text` 34 | 35 | Text body of the message. 36 | 37 | ### `html` 38 | 39 | HTML body of the message. 40 | 41 | ## Example usage 42 | 43 | ``` 44 | - name: Send Email 45 | uses: firebase/firebase-admin-node/.github/actions/send-email 46 | with: 47 | api-key: ${{ secrets.MAILGUN_API_KEY }} 48 | domain: ${{ secrets.MAILGUN_DOMAIN }} 49 | from: 'User ' 50 | html: '

Testing some Mailgun awesomness!

' 51 | to: 'foo@example.com' 52 | ``` 53 | 54 | ## Implementation 55 | 56 | This Action uses the `mailgun.js` NPM package to send Emails. 57 | 58 | When making a code change remember to run `npm run pack` to rebuild the 59 | `dist/index.js` file which is the executable of this Action. 60 | -------------------------------------------------------------------------------- /.github/actions/send-email/action.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: 'Send email Action' 16 | description: 'Send emails using Mailgun from GitHub Actions workflows.' 17 | inputs: 18 | api-key: 19 | description: Mailgun API key. 20 | required: true 21 | domain: 22 | description: Mailgun domain name. 23 | required: true 24 | from: 25 | description: Senders name and email address. 26 | required: true 27 | to: 28 | description: Recipient's email address. You can use commas to separate multiple recipients. 29 | required: true 30 | cc: 31 | description: Email addresses to Cc. 32 | required: false 33 | subject: 34 | description: Message subject. 35 | required: true 36 | text: 37 | description: Text body of the message. 38 | required: false 39 | html: 40 | description: HTML body of the message. 41 | required: false 42 | runs: 43 | using: 'node20' 44 | main: 'dist/index.js' 45 | -------------------------------------------------------------------------------- /.github/actions/send-email/index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | const core = require('@actions/core'); 18 | const formData = require('form-data'); 19 | const Mailgun = require('mailgun.js'); 20 | 21 | const mailgun = new Mailgun(formData); 22 | const optionalFields = ['cc', 'text', 'html']; 23 | 24 | function loadConfig() { 25 | return { 26 | apiKey: core.getInput('api-key'), 27 | domain: core.getInput('domain'), 28 | to: core.getInput('to'), 29 | from: core.getInput('from'), 30 | cc: core.getInput('cc'), 31 | subject: core.getInput('subject'), 32 | text: core.getInput('text'), 33 | html: core.getInput('html'), 34 | } 35 | } 36 | 37 | function validate(config) { 38 | for (param in config) { 39 | if (optionalFields.includes(param)) { 40 | continue; 41 | } 42 | validateRequiredParameter(config[param], `'${param}'`); 43 | } 44 | } 45 | 46 | function validateRequiredParameter(value, name) { 47 | if (!isNonEmptyString(value)) { 48 | throw new Error(`${name} must be a non-empty string.`); 49 | } 50 | } 51 | 52 | function sendEmail(config) { 53 | const mg = mailgun.client({ 54 | username: 'api', 55 | key: config.apiKey, 56 | }); 57 | 58 | return mg.messages 59 | .create(config.domain, { 60 | from: config.from, 61 | to: config.to, 62 | cc: config.cc, 63 | subject: config.subject, 64 | text: config.text, 65 | html: config.html, 66 | }) 67 | .then((resp) => { 68 | core.setOutput('response', resp.message); 69 | return; 70 | }) 71 | .catch((err) => { 72 | core.setFailed(err.message); 73 | }); 74 | } 75 | 76 | function isNonEmptyString(value) { 77 | return typeof value === 'string' && value !== ''; 78 | } 79 | 80 | const config = loadConfig(); 81 | validate(config); 82 | sendEmail(config); 83 | -------------------------------------------------------------------------------- /.github/actions/send-email/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "send-email", 3 | "version": "1.0.1", 4 | "description": "Send Emails from GitHub Actions workflows using Mailgun.", 5 | "main": "index.js", 6 | "scripts": { 7 | "pack": "ncc build" 8 | }, 9 | "keywords": [ 10 | "Firebase", 11 | "Release", 12 | "Automation" 13 | ], 14 | "author": "Firebase (https://firebase.google.com/)", 15 | "license": "Apache-2.0", 16 | "dependencies": { 17 | "@actions/core": "^1.10.1", 18 | "mailgun.js": "^10.1.0" 19 | }, 20 | "devDependencies": { 21 | "@vercel/ncc": "^0.38.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.github/actions/send-tweet/README.md: -------------------------------------------------------------------------------- 1 | # Send Tweet GitHub Action 2 | 3 | This is a minimalistic GitHub Action for posting Firebase release announcements 4 | to Twitter. Simply specify the Twitter API keys along with the Tweet status to 5 | be posted. 6 | 7 | ## Inputs 8 | 9 | ### `status` 10 | 11 | **Required** Text of the Tweet to send. 12 | 13 | ### `consumer-key` 14 | 15 | **Required** Consumer API key from Twitter. 16 | 17 | ### `consumer-secret` 18 | 19 | **Required** Consumer API secret key from Twitter. 20 | 21 | ### `access-token` 22 | 23 | **Required** Twitter application access token. 24 | 25 | ### `access-token-secret` 26 | 27 | **Required** Twitter application access token secret. 28 | 29 | ## Example usage 30 | 31 | ``` 32 | - name: Send Tweet 33 | uses: firebase/firebase-admin-node/.github/actions/send-tweet 34 | with: 35 | status: > 36 | v1.2.3 of @Firebase Admin Node.js SDK is available. 37 | Release notes at https://firebase.google.com. 38 | consumer-key: ${{ secrets.TWITTER_CONSUMER_KEY }} 39 | consumer-secret: ${{ secrets.TWITTER_CONSUMER_SECRET }} 40 | access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }} 41 | access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} 42 | ``` 43 | 44 | ## Implementation 45 | 46 | This Action uses the `twitter` NPM package to send Tweets. 47 | 48 | When making a code change remember to run `npm run pack` to rebuild the 49 | `dist/index.js` file which is the executable of this Action. 50 | -------------------------------------------------------------------------------- /.github/actions/send-tweet/action.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: 'Send Tweet Action' 16 | description: 'Send Tweets from GitHub Actions workflows.' 17 | inputs: 18 | status: 19 | description: Status (Tweet) to be posted 20 | required: true 21 | consumer-key: 22 | description: Consumer API key. 23 | required: true 24 | consumer-secret: 25 | description: Consumer API secret key. 26 | required: true 27 | access-token: 28 | description: Application access token. 29 | required: true 30 | access-token-secret: 31 | description: Application access token secret. 32 | required: true 33 | runs: 34 | using: 'node12' 35 | main: 'dist/index.js' 36 | -------------------------------------------------------------------------------- /.github/actions/send-tweet/index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | const core = require('@actions/core'); 18 | const Twitter = require('twitter'); 19 | 20 | function sendTweet() { 21 | const twitter = new Twitter({ 22 | consumer_key: core.getInput('consumer-key'), 23 | consumer_secret: core.getInput('consumer-secret'), 24 | access_token_key: core.getInput('access-token'), 25 | access_token_secret: core.getInput('access-token-secret') 26 | }); 27 | 28 | return twitter.post('/statuses/update', {status: core.getInput('status')}) 29 | .then(() => { 30 | return; 31 | }) 32 | .catch((err) => { 33 | core.setFailed(err.message); 34 | }); 35 | } 36 | 37 | sendTweet(); 38 | -------------------------------------------------------------------------------- /.github/actions/send-tweet/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "send-tweet", 3 | "version": "1.0.0", 4 | "description": "Send Tweets from GitHub Actions workflows.", 5 | "main": "index.js", 6 | "scripts": { 7 | "pack": "ncc build" 8 | }, 9 | "keywords": [ 10 | "Firebase", 11 | "Release", 12 | "Automation" 13 | ], 14 | "author": "Firebase (https://firebase.google.com/)", 15 | "license": "Apache-2.0", 16 | "dependencies": { 17 | "@actions/core": "^1.9.1", 18 | "twitter": "^1.7.1" 19 | }, 20 | "devDependencies": { 21 | "@zeit/ncc": "^0.21.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | -------------------------------------------------------------------------------- /.github/resources/integ-service-account.json.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firebase/firebase-admin-node/3c2cb9f0265ae836469198a7ff18d5454f18aefd/.github/resources/integ-service-account.json.gpg -------------------------------------------------------------------------------- /.github/scripts/generate_changelog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -u 5 | 6 | function printChangelog() { 7 | local TITLE=$1 8 | shift 9 | # Skip the sentinel value. 10 | local ENTRIES=("${@:2}") 11 | if [ ${#ENTRIES[@]} -ne 0 ]; then 12 | echo "### ${TITLE}" 13 | echo "" 14 | for ((i = 0; i < ${#ENTRIES[@]}; i++)) 15 | do 16 | echo "* ${ENTRIES[$i]}" 17 | done 18 | echo "" 19 | fi 20 | } 21 | 22 | if [[ -z "${GITHUB_SHA}" ]]; then 23 | GITHUB_SHA="HEAD" 24 | fi 25 | 26 | LAST_TAG=`git describe --tags $(git rev-list --tags --max-count=1) 2> /dev/null` || true 27 | if [[ -z "${LAST_TAG}" ]]; then 28 | echo "[INFO] No tags found. Including all commits up to ${GITHUB_SHA}." 29 | VERSION_RANGE="${GITHUB_SHA}" 30 | else 31 | echo "[INFO] Last release tag: ${LAST_TAG}." 32 | COMMIT_SHA=`git show-ref -s ${LAST_TAG}` 33 | echo "[INFO] Last release commit: ${COMMIT_SHA}." 34 | VERSION_RANGE="${COMMIT_SHA}..${GITHUB_SHA}" 35 | echo "[INFO] Including all commits in the range ${VERSION_RANGE}." 36 | fi 37 | 38 | echo "" 39 | 40 | # Older versions of Bash (< 4.4) treat empty arrays as unbound variables, which triggers 41 | # errors when referencing them. Therefore we initialize each of these arrays with an empty 42 | # sentinel value, and later skip them. 43 | CHANGES=("") 44 | FIXES=("") 45 | FEATS=("") 46 | MISC=("") 47 | 48 | while read -r line 49 | do 50 | COMMIT_MSG=`echo ${line} | cut -d ' ' -f 2-` 51 | if [[ $COMMIT_MSG =~ ^change(\(.*\))?: ]]; then 52 | CHANGES+=("$COMMIT_MSG") 53 | elif [[ $COMMIT_MSG =~ ^fix(\(.*\))?: ]]; then 54 | FIXES+=("$COMMIT_MSG") 55 | elif [[ $COMMIT_MSG =~ ^feat(\(.*\))?: ]]; then 56 | FEATS+=("$COMMIT_MSG") 57 | else 58 | MISC+=("${COMMIT_MSG}") 59 | fi 60 | done < <(git log ${VERSION_RANGE} --oneline) 61 | 62 | printChangelog "Breaking Changes" "${CHANGES[@]}" 63 | printChangelog "New Features" "${FEATS[@]}" 64 | printChangelog "Bug Fixes" "${FIXES[@]}" 65 | printChangelog "Miscellaneous" "${MISC[@]}" 66 | -------------------------------------------------------------------------------- /.github/scripts/publish_package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2020 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | 20 | echo "//wombat-dressing-room.appspot.com/:_authToken=${NPM_AUTH_TOKEN}" >> .npmrc 21 | 22 | readonly UNPREFIXED_VERSION=`echo ${VERSION} | cut -c 2-` 23 | npm publish ./dist/firebase-admin-${UNPREFIXED_VERSION}.tgz --registry https://wombat-dressing-room.appspot.com 24 | -------------------------------------------------------------------------------- /.github/scripts/run_integration_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2020 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | 20 | gpg --quiet --batch --yes --decrypt --passphrase="${FIREBASE_SERVICE_ACCT_KEY}" \ 21 | --output test/resources/key.json .github/resources/integ-service-account.json.gpg 22 | 23 | echo "${FIREBASE_API_KEY}" > test/resources/apikey.txt 24 | 25 | echo "${FIREBASE_APP_ID}" > test/resources/appid.txt 26 | 27 | npm run test:integration -- --updateRules --testMultiTenancy 28 | -------------------------------------------------------------------------------- /.github/scripts/verify_package.sh: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | #!/bin/bash 16 | 17 | # This helper script installs the firebase-admin package locally as a 18 | # typical developer would, and runs some test code using the 19 | # installed package as a dependency. This ensures that the distros 20 | # built by our tools can be installed and consumed by downstream 21 | # applications. 22 | 23 | set -e 24 | set -u 25 | 26 | if [ -z "$1" ]; then 27 | echo "[ERROR] No package name provided." 28 | echo "[INFO] Usage: ./verify_package.sh " 29 | exit 1 30 | fi 31 | 32 | PKG_NAME="$1" 33 | if [ ! -f "${PKG_NAME}" ]; then 34 | echo "Package ${PKG_NAME} does not exist." 35 | exit 1 36 | fi 37 | 38 | # create a temporary directory 39 | WORK_DIR=`mktemp -d` 40 | if [[ ! "${WORK_DIR}" || ! -d "${WORK_DIR}" ]]; then 41 | echo "Could not create temp dir" 42 | exit 1 43 | fi 44 | 45 | # deletes the temp directory 46 | function cleanup { 47 | rm -rf "${WORK_DIR}" 48 | echo "Deleted temp working directory ${WORK_DIR}" 49 | } 50 | 51 | # register the cleanup function to be called on the EXIT signal 52 | trap cleanup EXIT 53 | 54 | # Copy package and test sources into working directory 55 | cp "${PKG_NAME}" "${WORK_DIR}" 56 | cp -r test/integration/postcheck/* "${WORK_DIR}" 57 | cp test/resources/mock.key.json "${WORK_DIR}" 58 | 59 | # Enter work dir 60 | pushd "${WORK_DIR}" 61 | 62 | # Install the test package 63 | npm install 64 | 65 | # Install firebase-admin package 66 | npm install -S "${PKG_NAME}" 67 | 68 | echo "> tsc -p tsconfig.json" 69 | ./node_modules/.bin/tsc -p tsconfig.json 70 | 71 | MOCHA_CLI="./node_modules/.bin/mocha" 72 | TS_MOCHA_CLI="${MOCHA_CLI} -r ts-node/register" 73 | echo "> $TS_MOCHA_CLI typescript/*.test.ts" 74 | $TS_MOCHA_CLI typescript/*.test.ts 75 | 76 | echo "> $MOCHA_CLI esm/*.js" 77 | $MOCHA_CLI esm/*.js 78 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Continuous Integration 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | strategy: 11 | matrix: 12 | node-version: [18.x, 20.x, 22.x] 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Set up Node.js ${{ matrix.node-version }} 17 | uses: actions/setup-node@v4 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | - name: Install and build 21 | run: | 22 | npm ci 23 | npm run build 24 | npm run build:tests 25 | - name: Lint and run unit tests 26 | run: npm test 27 | - name: Run api-extractor 28 | run: npm run api-extractor 29 | - name: Run emulator-based integration tests 30 | run: | 31 | npm install -g firebase-tools@11.30.0 32 | firebase emulators:exec --project fake-project-id --only auth,database,firestore \ 33 | 'npx mocha \"test/integration/{auth,database,firestore}.spec.ts\" --slow 5000 --timeout 20000 --require ts-node/register' 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | .DS_Store 4 | npm-debug.log 5 | 6 | lib/ 7 | .tmp/ 8 | temp/ 9 | typings/ 10 | coverage/ 11 | node_modules/ 12 | .nyc_output/ 13 | 14 | # Real key file should not be checked in 15 | test/resources/key.json 16 | test/resources/apikey.txt 17 | test/resources/appid.txt 18 | 19 | # Release tarballs should not be checked in 20 | firebase-admin-*.tgz 21 | 22 | docgen/markdown/ 23 | -------------------------------------------------------------------------------- /.opensource/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Firebase Admin SDK - Node", 3 | "platforms": [ 4 | "Node", 5 | "Admin" 6 | ], 7 | "content": "README.md", 8 | "pages": [], 9 | "related": [ 10 | "firebase/firebase-admin-java", 11 | "firebase/firebase-admin-go", 12 | "firebase/firebase-admin-python" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Firebase Admin Changelog 2 | 3 | For detailed version notes and breaking changes, see our release notes on GitHub: 4 | https://github.com/firebase/firebase-admin-node/releases 5 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Hey there! So you want to contribute to a Firebase SDK? 2 | Before you file this pull request, please read these guidelines: 3 | 4 | ### Discussion 5 | 6 | * Read the contribution guidelines (CONTRIBUTING.md). 7 | * If this has been discussed in an issue, make sure to link to the issue here. 8 | If not, go file an issue about this **before creating a pull request** to discuss. 9 | 10 | ### Testing 11 | 12 | * Make sure all existing tests in the repository pass after your change. 13 | * If you fixed a bug or added a feature, add a new test to cover your code. 14 | 15 | ### API Changes 16 | 17 | * At this time we cannot accept changes that affect the public API. If you'd like to help 18 | us make Firebase APIs better, please propose your change in an issue so that we 19 | can discuss it together. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://github.com/firebase/firebase-admin-node/workflows/Continuous%20Integration/badge.svg)](https://github.com/firebase/firebase-admin-node/actions) 2 | 3 | # Firebase Admin Node.js SDK 4 | 5 | 6 | ## Table of Contents 7 | 8 | * [Overview](#overview) 9 | * [Installation](#installation) 10 | * [Contributing](#contributing) 11 | * [Documentation](#documentation) 12 | * [Supported Environments](#supported-environments) 13 | * [Acknowledgments](#acknowledgments) 14 | * [License](#license) 15 | 16 | 17 | ## Overview 18 | 19 | [Firebase](https://firebase.google.com) provides the tools and infrastructure 20 | you need to develop your app, grow your user base, and earn money. The Firebase 21 | Admin Node.js SDK enables access to Firebase services from privileged environments 22 | (such as servers or cloud) in Node.js. 23 | 24 | For more information, visit the 25 | [Firebase Admin SDK setup guide](https://firebase.google.com/docs/admin/setup/). 26 | 27 | 28 | ## Installation 29 | 30 | The Firebase Admin Node.js SDK is available on npm as `firebase-admin`: 31 | 32 | ```bash 33 | $ npm install --save firebase-admin 34 | ``` 35 | 36 | To use the module in your application, `require` it from any JavaScript file: 37 | 38 | ```js 39 | const { initializeApp } = require("firebase-admin/app"); 40 | 41 | initializeApp(); 42 | ``` 43 | 44 | If you are using ES2015, you can `import` the module instead: 45 | 46 | ```js 47 | import { initializeApp } from "firebase-admin/app"; 48 | 49 | initializeApp(); 50 | ``` 51 | 52 | 53 | ## Contributing 54 | 55 | Please refer to the [CONTRIBUTING page](./CONTRIBUTING.md) for more information 56 | about how you can contribute to this project. We welcome bug reports, feature 57 | requests, code review feedback, and also pull requests. 58 | 59 | 60 | ## Supported Environments 61 | 62 | We support Node.js 18 and higher. 63 | 64 | Please also note that the Admin SDK should only 65 | be used in server-side/back-end environments controlled by the app developer. 66 | This includes most server and serverless platforms (both on-premise and in 67 | the cloud). It is not recommended to use the Admin SDK in client-side 68 | environments. 69 | 70 | 71 | ## Documentation 72 | 73 | * [Setup Guide](https://firebase.google.com/docs/admin/setup/) 74 | * [Database Guide](https://firebase.google.com/docs/database/admin/start/) 75 | * [Authentication Guide](https://firebase.google.com/docs/auth/admin/) 76 | * [Cloud Messaging Guide](https://firebase.google.com/docs/cloud-messaging/admin/) 77 | * [API Reference](https://firebase.google.com/docs/reference/admin/node/) 78 | * [Release Notes](https://firebase.google.com/support/release-notes/admin/node/) 79 | 80 | 81 | ## Acknowledgments 82 | 83 | Thanks to the team at [Casetext](https://casetext.com/) for transferring 84 | ownership of the `firebase-admin` npm module over to the Firebase team 85 | and for their longtime use and support of the Firebase platform. 86 | 87 | 88 | ## License 89 | 90 | Firebase Admin Node.js SDK is licensed under the 91 | [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). 92 | 93 | Your use of Firebase is governed by the 94 | [Terms of Service for Firebase Services](https://firebase.google.com/terms/). 95 | -------------------------------------------------------------------------------- /api-extractor.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 3 | "mainEntryPointFilePath": "/lib/default-namespace.d.ts", 4 | "bundledPackages": [], 5 | "compiler": { 6 | 7 | }, 8 | "apiReport": { 9 | "enabled": true, 10 | "reportFileName": "" 11 | }, 12 | "docModel": { 13 | "enabled": true 14 | }, 15 | "dtsRollup": { 16 | "enabled": false 17 | }, 18 | "tsdocMetadata": { 19 | "enabled": false 20 | }, 21 | "messages": { 22 | "compilerMessageReporting": { 23 | "default": { 24 | "logLevel": "warning" 25 | } 26 | }, 27 | "extractorMessageReporting": { 28 | "default": { 29 | "logLevel": "warning" 30 | }, 31 | 32 | "ae-missing-release-tag": { 33 | "logLevel": "none" 34 | }, 35 | 36 | "ae-unresolved-link": { 37 | "logLevel": "error" 38 | } 39 | }, 40 | "tsdocMessageReporting": { 41 | "default": { 42 | "logLevel": "error" 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /docgen/extras/firebase-admin.database.md: -------------------------------------------------------------------------------- 1 | ## External API Re-exports 2 | 3 | The following externally defined APIs are re-exported from this module entry point for convenience. 4 | 5 | | Symbol | Description | 6 | | --- | --- | 7 | | [DataSnapshot](https://firebase.google.com/docs/reference/js/v8/firebase.database.DataSnapshot) | `DataSnapshot` type from the `@firebase/database-compat` package. | 8 | | [EventType](https://firebase.google.com/docs/reference/js/v8/firebase.database#eventtype) | `EventType` type from the `@firebase/database-compat` package. | 9 | | [OnDisconnect](https://firebase.google.com/docs/reference/js/v8/firebase.database.OnDisconnect) | `OnDisconnect` type from the `@firebase/database-compat` package. | 10 | | [Query](https://firebase.google.com/docs/reference/js/v8/firebase.database.Query) | `Query` type from the `@firebase/database-compat` package. | 11 | | [Reference](https://firebase.google.com/docs/reference/js/v8/firebase.database.Reference) | `Reference` type from the `@firebase/database-compat` package. | 12 | | [ThenableReference](https://firebase.google.com/docs/reference/js/v8/firebase.database.ThenableReference) | `ThenableReference` type from the `@firebase/database-compat` package. | 13 | -------------------------------------------------------------------------------- /entrypoints.json: -------------------------------------------------------------------------------- 1 | { 2 | "firebase-admin": { 3 | "legacy": true, 4 | "typings": "./lib/default-namespace.d.ts", 5 | "dist": "./lib/index.js" 6 | }, 7 | "firebase-admin/app": { 8 | "typings": "./lib/app/index.d.ts", 9 | "dist": "./lib/app/index.js" 10 | }, 11 | "firebase-admin/app-check": { 12 | "typings": "./lib/app-check/index.d.ts", 13 | "dist": "./lib/app-check/index.js" 14 | }, 15 | "firebase-admin/auth": { 16 | "typings": "./lib/auth/index.d.ts", 17 | "dist": "./lib/auth/index.js" 18 | }, 19 | "firebase-admin/database": { 20 | "typings": "./lib/database/index.d.ts", 21 | "dist": "./lib/database/index.js" 22 | }, 23 | "firebase-admin/data-connect": { 24 | "typings": "./lib/data-connect/index.d.ts", 25 | "dist": "./lib/data-connect/index.js" 26 | }, 27 | "firebase-admin/extensions": { 28 | "typings": "./lib/extensions/index.d.ts", 29 | "dist": "./lib/extensions/index.js" 30 | }, 31 | "firebase-admin/firestore": { 32 | "typings": "./lib/firestore/index.d.ts", 33 | "dist": "./lib/firestore/index.js" 34 | }, 35 | "firebase-admin/functions": { 36 | "typings": "./lib/functions/index.d.ts", 37 | "dist": "./lib/functions/index.js" 38 | }, 39 | "firebase-admin/installations": { 40 | "typings": "./lib/installations/index.d.ts", 41 | "dist": "./lib/installations/index.js" 42 | }, 43 | "firebase-admin/instance-id": { 44 | "typings": "./lib/instance-id/index.d.ts", 45 | "dist": "./lib/instance-id/index.js" 46 | }, 47 | "firebase-admin/messaging": { 48 | "typings": "./lib/messaging/index.d.ts", 49 | "dist": "./lib/messaging/index.js" 50 | }, 51 | "firebase-admin/machine-learning": { 52 | "typings": "./lib/machine-learning/index.d.ts", 53 | "dist": "./lib/machine-learning/index.js" 54 | }, 55 | "firebase-admin/project-management": { 56 | "typings": "./lib/project-management/index.d.ts", 57 | "dist": "./lib/project-management/index.js" 58 | }, 59 | "firebase-admin/security-rules": { 60 | "typings": "./lib/security-rules/index.d.ts", 61 | "dist": "./lib/security-rules/index.js" 62 | }, 63 | "firebase-admin/storage": { 64 | "typings": "./lib/storage/index.d.ts", 65 | "dist": "./lib/storage/index.js" 66 | }, 67 | "firebase-admin/remote-config": { 68 | "typings": "./lib/remote-config/index.d.ts", 69 | "dist": "./lib/remote-config/index.js" 70 | }, 71 | "firebase-admin/eventarc": { 72 | "typings": "./lib/eventarc/index.d.ts", 73 | "dist": "./lib/eventarc/index.js" 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /etc/firebase-admin.app-check.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.app-check" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | 9 | // @public 10 | export class AppCheck { 11 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 12 | // 13 | // (undocumented) 14 | readonly app: App; 15 | createToken(appId: string, options?: AppCheckTokenOptions): Promise; 16 | verifyToken(appCheckToken: string, options?: VerifyAppCheckTokenOptions): Promise; 17 | } 18 | 19 | // @public 20 | export interface AppCheckToken { 21 | token: string; 22 | ttlMillis: number; 23 | } 24 | 25 | // @public 26 | export interface AppCheckTokenOptions { 27 | ttlMillis?: number; 28 | } 29 | 30 | // @public 31 | export interface DecodedAppCheckToken { 32 | // (undocumented) 33 | [key: string]: any; 34 | app_id: string; 35 | aud: string[]; 36 | exp: number; 37 | iat: number; 38 | iss: string; 39 | sub: string; 40 | } 41 | 42 | // @public 43 | export function getAppCheck(app?: App): AppCheck; 44 | 45 | // @public 46 | export interface VerifyAppCheckTokenOptions { 47 | consume?: boolean; 48 | } 49 | 50 | // @public 51 | export interface VerifyAppCheckTokenResponse { 52 | alreadyConsumed?: boolean; 53 | appId: string; 54 | token: DecodedAppCheckToken; 55 | } 56 | 57 | ``` 58 | -------------------------------------------------------------------------------- /etc/firebase-admin.app.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.app" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | 9 | // @public 10 | export interface App { 11 | name: string; 12 | options: AppOptions; 13 | } 14 | 15 | // @public 16 | export class AppErrorCodes { 17 | // (undocumented) 18 | static APP_DELETED: string; 19 | // (undocumented) 20 | static DUPLICATE_APP: string; 21 | // (undocumented) 22 | static INTERNAL_ERROR: string; 23 | // (undocumented) 24 | static INVALID_APP_NAME: string; 25 | // (undocumented) 26 | static INVALID_APP_OPTIONS: string; 27 | // (undocumented) 28 | static INVALID_ARGUMENT: string; 29 | // (undocumented) 30 | static INVALID_CREDENTIAL: string; 31 | // (undocumented) 32 | static NETWORK_ERROR: string; 33 | // (undocumented) 34 | static NETWORK_TIMEOUT: string; 35 | // (undocumented) 36 | static NO_APP: string; 37 | // (undocumented) 38 | static UNABLE_TO_PARSE_RESPONSE: string; 39 | } 40 | 41 | // @public 42 | export function applicationDefault(httpAgent?: Agent): Credential; 43 | 44 | // @public 45 | export interface AppOptions { 46 | credential?: Credential; 47 | databaseAuthVariableOverride?: object | null; 48 | databaseURL?: string; 49 | httpAgent?: Agent; 50 | projectId?: string; 51 | serviceAccountId?: string; 52 | storageBucket?: string; 53 | } 54 | 55 | // @public 56 | export function cert(serviceAccountPathOrObject: string | ServiceAccount, httpAgent?: Agent): Credential; 57 | 58 | // @public 59 | export interface Credential { 60 | getAccessToken(): Promise; 61 | } 62 | 63 | // @public 64 | export function deleteApp(app: App): Promise; 65 | 66 | // Warning: (ae-forgotten-export) The symbol "PrefixedFirebaseError" needs to be exported by the entry point index.d.ts 67 | // 68 | // @public 69 | export class FirebaseAppError extends PrefixedFirebaseError { 70 | } 71 | 72 | // @public 73 | export interface FirebaseArrayIndexError { 74 | error: FirebaseError; 75 | index: number; 76 | } 77 | 78 | // @public 79 | export interface FirebaseError { 80 | code: string; 81 | message: string; 82 | stack?: string; 83 | toJSON(): object; 84 | } 85 | 86 | // @public (undocumented) 87 | export function getApp(appName?: string): App; 88 | 89 | // @public (undocumented) 90 | export function getApps(): App[]; 91 | 92 | // @public 93 | export interface GoogleOAuthAccessToken { 94 | // (undocumented) 95 | access_token: string; 96 | // (undocumented) 97 | expires_in: number; 98 | } 99 | 100 | // @public (undocumented) 101 | export function initializeApp(options?: AppOptions, appName?: string): App; 102 | 103 | // @public 104 | export function refreshToken(refreshTokenPathOrObject: string | object, httpAgent?: Agent): Credential; 105 | 106 | // @public (undocumented) 107 | export const SDK_VERSION: string; 108 | 109 | // @public (undocumented) 110 | export interface ServiceAccount { 111 | // (undocumented) 112 | clientEmail?: string; 113 | // (undocumented) 114 | privateKey?: string; 115 | // (undocumented) 116 | projectId?: string; 117 | } 118 | 119 | ``` 120 | -------------------------------------------------------------------------------- /etc/firebase-admin.data-connect.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.data-connect" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | 9 | // Warning: (ae-forgotten-export) The symbol "DecodedIdToken" needs to be exported by the entry point index.d.ts 10 | // 11 | // @public 12 | export type AuthClaims = Partial; 13 | 14 | // @public 15 | export interface ConnectorConfig { 16 | location: string; 17 | serviceId: string; 18 | } 19 | 20 | // @public 21 | export class DataConnect { 22 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 23 | // 24 | // (undocumented) 25 | readonly app: App; 26 | // (undocumented) 27 | readonly connectorConfig: ConnectorConfig; 28 | executeGraphql(query: string, options?: GraphqlOptions): Promise>; 29 | executeGraphqlRead(query: string, options?: GraphqlOptions): Promise>; 30 | insert(tableName: string, variables: Variables): Promise>; 31 | insertMany>(tableName: string, variables: Variables): Promise>; 32 | upsert(tableName: string, variables: Variables): Promise>; 33 | upsertMany>(tableName: string, variables: Variables): Promise>; 34 | } 35 | 36 | // @public 37 | export interface ExecuteGraphqlResponse { 38 | data: GraphqlResponse; 39 | } 40 | 41 | // @public 42 | export function getDataConnect(connectorConfig: ConnectorConfig, app?: App): DataConnect; 43 | 44 | // @public 45 | export interface GraphqlOptions { 46 | impersonate?: ImpersonateAuthenticated | ImpersonateUnauthenticated; 47 | operationName?: string; 48 | variables?: Variables; 49 | } 50 | 51 | // @public 52 | export interface ImpersonateAuthenticated { 53 | authClaims: AuthClaims; 54 | unauthenticated?: never; 55 | } 56 | 57 | // @public 58 | export interface ImpersonateUnauthenticated { 59 | authClaims?: never; 60 | unauthenticated: true; 61 | } 62 | 63 | ``` 64 | -------------------------------------------------------------------------------- /etc/firebase-admin.database.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.database" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | import { DataSnapshot } from '@firebase/database-types'; 9 | import { EventType } from '@firebase/database-types'; 10 | import { FirebaseDatabase } from '@firebase/database-types'; 11 | import { OnDisconnect } from '@firebase/database-types'; 12 | import { Query } from '@firebase/database-types'; 13 | import { Reference } from '@firebase/database-types'; 14 | import * as rtdb from '@firebase/database-types'; 15 | import { ThenableReference } from '@firebase/database-types'; 16 | 17 | // @public 18 | export interface Database extends FirebaseDatabase { 19 | getRules(): Promise; 20 | getRulesJSON(): Promise; 21 | setRules(source: string | Buffer | object): Promise; 22 | } 23 | 24 | export { DataSnapshot } 25 | 26 | // @public 27 | export const enableLogging: typeof rtdb.enableLogging; 28 | 29 | export { EventType } 30 | 31 | // Warning: (ae-forgotten-export) The symbol "FirebaseError" needs to be exported by the entry point index.d.ts 32 | // 33 | // @public 34 | export class FirebaseDatabaseError extends FirebaseError { 35 | } 36 | 37 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 38 | // 39 | // @public 40 | export function getDatabase(app?: App): Database; 41 | 42 | // @public 43 | export function getDatabaseWithUrl(url: string, app?: App): Database; 44 | 45 | export { OnDisconnect } 46 | 47 | export { Query } 48 | 49 | export { Reference } 50 | 51 | // @public 52 | export const ServerValue: rtdb.ServerValue; 53 | 54 | export { ThenableReference } 55 | 56 | ``` 57 | -------------------------------------------------------------------------------- /etc/firebase-admin.eventarc.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.eventarc" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | 9 | // @public 10 | export class Channel { 11 | readonly allowedEventTypes?: string[]; 12 | get eventarc(): Eventarc; 13 | get name(): string; 14 | publish(events: CloudEvent | CloudEvent[]): Promise; 15 | } 16 | 17 | // @public 18 | export interface ChannelOptions { 19 | allowedEventTypes?: string[] | string | undefined; 20 | } 21 | 22 | // @public 23 | export interface CloudEvent { 24 | [key: string]: any; 25 | data?: object | string; 26 | datacontenttype?: string; 27 | id?: string; 28 | source?: string; 29 | specversion?: CloudEventVersion; 30 | subject?: string; 31 | time?: string; 32 | type: string; 33 | } 34 | 35 | // @public 36 | export type CloudEventVersion = '1.0'; 37 | 38 | // @public 39 | export class Eventarc { 40 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 41 | get app(): App; 42 | channel(name: string, options?: ChannelOptions): Channel; 43 | channel(options?: ChannelOptions): Channel; 44 | } 45 | 46 | // @public 47 | export function getEventarc(app?: App): Eventarc; 48 | 49 | ``` 50 | -------------------------------------------------------------------------------- /etc/firebase-admin.extensions.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.extensions" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | 9 | // @public 10 | export class Extensions { 11 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 12 | // 13 | // (undocumented) 14 | readonly app: App; 15 | runtime(): Runtime; 16 | } 17 | 18 | // @public 19 | export function getExtensions(app?: App): Extensions; 20 | 21 | // @public 22 | export class Runtime { 23 | setFatalError(errorMessage: string): Promise; 24 | setProcessingState(state: SettableProcessingState, detailMessage: string): Promise; 25 | } 26 | 27 | // @public 28 | export type SettableProcessingState = 'NONE' | 'PROCESSING_COMPLETE' | 'PROCESSING_WARNING' | 'PROCESSING_FAILED'; 29 | 30 | ``` 31 | -------------------------------------------------------------------------------- /etc/firebase-admin.functions.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.functions" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | 9 | // @public 10 | export interface AbsoluteDelivery { 11 | // @alpha (undocumented) 12 | scheduleDelaySeconds?: never; 13 | scheduleTime?: Date; 14 | } 15 | 16 | // @public 17 | export interface DelayDelivery { 18 | scheduleDelaySeconds?: number; 19 | // @alpha (undocumented) 20 | scheduleTime?: never; 21 | } 22 | 23 | // @public 24 | export type DeliverySchedule = DelayDelivery | AbsoluteDelivery; 25 | 26 | // @public 27 | export class Functions { 28 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 29 | // 30 | // (undocumented) 31 | readonly app: App; 32 | taskQueue>(functionName: string, extensionId?: string): TaskQueue; 33 | } 34 | 35 | // @public 36 | export function getFunctions(app?: App): Functions; 37 | 38 | // @public 39 | export type TaskOptions = DeliverySchedule & TaskOptionsExperimental & { 40 | dispatchDeadlineSeconds?: number; 41 | id?: string; 42 | headers?: Record; 43 | }; 44 | 45 | // @public 46 | export interface TaskOptionsExperimental { 47 | // @beta 48 | uri?: string; 49 | } 50 | 51 | // @public 52 | export class TaskQueue> { 53 | delete(id: string): Promise; 54 | enqueue(data: Args, opts?: TaskOptions): Promise; 55 | } 56 | 57 | ``` 58 | -------------------------------------------------------------------------------- /etc/firebase-admin.installations.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.installations" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | 9 | // Warning: (ae-forgotten-export) The symbol "FirebaseError" needs to be exported by the entry point index.d.ts 10 | // 11 | // @public 12 | export class FirebaseInstallationsError extends FirebaseError { 13 | } 14 | 15 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 16 | // 17 | // @public 18 | export function getInstallations(app?: App): Installations; 19 | 20 | // @public 21 | export class Installations { 22 | get app(): App; 23 | deleteInstallation(fid: string): Promise; 24 | } 25 | 26 | // @public (undocumented) 27 | export class InstallationsClientErrorCode { 28 | // (undocumented) 29 | static API_ERROR: { 30 | code: string; 31 | message: string; 32 | }; 33 | // (undocumented) 34 | static INVALID_ARGUMENT: { 35 | code: string; 36 | message: string; 37 | }; 38 | // (undocumented) 39 | static INVALID_INSTALLATION_ID: { 40 | code: string; 41 | message: string; 42 | }; 43 | // (undocumented) 44 | static INVALID_PROJECT_ID: { 45 | code: string; 46 | message: string; 47 | }; 48 | } 49 | 50 | ``` 51 | -------------------------------------------------------------------------------- /etc/firebase-admin.instance-id.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.instance-id" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | 9 | // Warning: (ae-forgotten-export) The symbol "FirebaseError" needs to be exported by the entry point index.d.ts 10 | // 11 | // @public 12 | export class FirebaseInstanceIdError extends FirebaseError { 13 | } 14 | 15 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 16 | // 17 | // @public @deprecated 18 | export function getInstanceId(app?: App): InstanceId; 19 | 20 | // @public @deprecated 21 | export class InstanceId { 22 | get app(): App; 23 | deleteInstanceId(instanceId: string): Promise; 24 | } 25 | 26 | // Warning: (ae-forgotten-export) The symbol "InstallationsClientErrorCode" needs to be exported by the entry point index.d.ts 27 | // 28 | // @public (undocumented) 29 | export class InstanceIdClientErrorCode extends InstallationsClientErrorCode { 30 | // (undocumented) 31 | static INVALID_INSTANCE_ID: { 32 | code: string; 33 | message: string; 34 | }; 35 | } 36 | 37 | ``` 38 | -------------------------------------------------------------------------------- /etc/firebase-admin.machine-learning.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.machine-learning" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | 9 | // @public (undocumented) 10 | export interface GcsTfliteModelOptions extends ModelOptionsBase { 11 | // (undocumented) 12 | tfliteModel: { 13 | gcsTfliteUri: string; 14 | }; 15 | } 16 | 17 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 18 | // 19 | // @public 20 | export function getMachineLearning(app?: App): MachineLearning; 21 | 22 | // @public 23 | export interface ListModelsOptions { 24 | filter?: string; 25 | pageSize?: number; 26 | pageToken?: string; 27 | } 28 | 29 | // @public 30 | export interface ListModelsResult { 31 | readonly models: Model[]; 32 | readonly pageToken?: string; 33 | } 34 | 35 | // @public 36 | export class MachineLearning { 37 | get app(): App; 38 | createModel(model: ModelOptions): Promise; 39 | deleteModel(modelId: string): Promise; 40 | getModel(modelId: string): Promise; 41 | listModels(options?: ListModelsOptions): Promise; 42 | publishModel(modelId: string): Promise; 43 | unpublishModel(modelId: string): Promise; 44 | updateModel(modelId: string, model: ModelOptions): Promise; 45 | } 46 | 47 | // @public 48 | export class Model { 49 | get createTime(): string; 50 | get displayName(): string; 51 | get etag(): string; 52 | get locked(): boolean; 53 | get modelHash(): string | undefined; 54 | get modelId(): string; 55 | get published(): boolean; 56 | get tags(): string[]; 57 | get tfliteModel(): TFLiteModel | undefined; 58 | toJSON(): { 59 | [key: string]: any; 60 | }; 61 | get updateTime(): string; 62 | get validationError(): string | undefined; 63 | waitForUnlocked(maxTimeMillis?: number): Promise; 64 | } 65 | 66 | // @public (undocumented) 67 | export type ModelOptions = ModelOptionsBase | GcsTfliteModelOptions; 68 | 69 | // @public 70 | export interface ModelOptionsBase { 71 | // (undocumented) 72 | displayName?: string; 73 | // (undocumented) 74 | tags?: string[]; 75 | } 76 | 77 | // @public 78 | export interface TFLiteModel { 79 | readonly gcsTfliteUri?: string; 80 | readonly sizeBytes: number; 81 | } 82 | 83 | ``` 84 | -------------------------------------------------------------------------------- /etc/firebase-admin.project-management.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.project-management" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | 9 | // @public 10 | export class AndroidApp { 11 | addShaCertificate(certificateToAdd: ShaCertificate): Promise; 12 | // (undocumented) 13 | readonly appId: string; 14 | deleteShaCertificate(certificateToDelete: ShaCertificate): Promise; 15 | getConfig(): Promise; 16 | getMetadata(): Promise; 17 | getShaCertificates(): Promise; 18 | setDisplayName(newDisplayName: string): Promise; 19 | } 20 | 21 | // @public 22 | export interface AndroidAppMetadata extends AppMetadata { 23 | packageName: string; 24 | // (undocumented) 25 | platform: AppPlatform.ANDROID; 26 | } 27 | 28 | // @public 29 | export interface AppMetadata { 30 | appId: string; 31 | displayName?: string; 32 | platform: AppPlatform; 33 | projectId: string; 34 | resourceName: string; 35 | } 36 | 37 | // @public 38 | export enum AppPlatform { 39 | ANDROID = "ANDROID", 40 | IOS = "IOS", 41 | PLATFORM_UNKNOWN = "PLATFORM_UNKNOWN" 42 | } 43 | 44 | // Warning: (ae-forgotten-export) The symbol "PrefixedFirebaseError" needs to be exported by the entry point index.d.ts 45 | // 46 | // @public 47 | export class FirebaseProjectManagementError extends PrefixedFirebaseError { 48 | } 49 | 50 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 51 | // 52 | // @public 53 | export function getProjectManagement(app?: App): ProjectManagement; 54 | 55 | // @public 56 | export class IosApp { 57 | // (undocumented) 58 | readonly appId: string; 59 | getConfig(): Promise; 60 | getMetadata(): Promise; 61 | setDisplayName(newDisplayName: string): Promise; 62 | } 63 | 64 | // @public 65 | export interface IosAppMetadata extends AppMetadata { 66 | bundleId: string; 67 | // (undocumented) 68 | platform: AppPlatform.IOS; 69 | } 70 | 71 | // @public 72 | export class ProjectManagement { 73 | androidApp(appId: string): AndroidApp; 74 | // (undocumented) 75 | readonly app: App; 76 | createAndroidApp(packageName: string, displayName?: string): Promise; 77 | createIosApp(bundleId: string, displayName?: string): Promise; 78 | iosApp(appId: string): IosApp; 79 | listAndroidApps(): Promise; 80 | listAppMetadata(): Promise; 81 | listIosApps(): Promise; 82 | setDisplayName(newDisplayName: string): Promise; 83 | shaCertificate(shaHash: string): ShaCertificate; 84 | } 85 | 86 | // @public (undocumented) 87 | export type ProjectManagementErrorCode = 'already-exists' | 'authentication-error' | 'internal-error' | 'invalid-argument' | 'invalid-project-id' | 'invalid-server-response' | 'not-found' | 'service-unavailable' | 'unknown-error'; 88 | 89 | // @public 90 | export class ShaCertificate { 91 | readonly certType: ('sha1' | 'sha256'); 92 | // (undocumented) 93 | readonly resourceName?: string | undefined; 94 | // (undocumented) 95 | readonly shaHash: string; 96 | } 97 | 98 | ``` 99 | -------------------------------------------------------------------------------- /etc/firebase-admin.security-rules.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.security-rules" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | 9 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 10 | // 11 | // @public 12 | export function getSecurityRules(app?: App): SecurityRules; 13 | 14 | // @public 15 | export class Ruleset implements RulesetMetadata { 16 | readonly createTime: string; 17 | readonly name: string; 18 | // (undocumented) 19 | readonly source: RulesFile[]; 20 | } 21 | 22 | // @public 23 | export interface RulesetMetadata { 24 | readonly createTime: string; 25 | readonly name: string; 26 | } 27 | 28 | // @public 29 | export class RulesetMetadataList { 30 | readonly nextPageToken?: string; 31 | readonly rulesets: RulesetMetadata[]; 32 | } 33 | 34 | // @public 35 | export interface RulesFile { 36 | // (undocumented) 37 | readonly content: string; 38 | // (undocumented) 39 | readonly name: string; 40 | } 41 | 42 | // @public 43 | export class SecurityRules { 44 | // (undocumented) 45 | readonly app: App; 46 | createRuleset(file: RulesFile): Promise; 47 | createRulesFileFromSource(name: string, source: string | Buffer): RulesFile; 48 | deleteRuleset(name: string): Promise; 49 | getFirestoreRuleset(): Promise; 50 | getRuleset(name: string): Promise; 51 | getStorageRuleset(bucket?: string): Promise; 52 | listRulesetMetadata(pageSize?: number, nextPageToken?: string): Promise; 53 | releaseFirestoreRuleset(ruleset: string | RulesetMetadata): Promise; 54 | releaseFirestoreRulesetFromSource(source: string | Buffer): Promise; 55 | releaseStorageRuleset(ruleset: string | RulesetMetadata, bucket?: string): Promise; 56 | releaseStorageRulesetFromSource(source: string | Buffer, bucket?: string): Promise; 57 | } 58 | 59 | ``` 60 | -------------------------------------------------------------------------------- /etc/firebase-admin.storage.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "firebase-admin.storage" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import { Agent } from 'http'; 8 | import { Bucket } from '@google-cloud/storage'; 9 | import { File as File_2 } from '@google-cloud/storage'; 10 | 11 | // @public 12 | export function getDownloadURL(file: File_2): Promise; 13 | 14 | // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts 15 | // 16 | // @public 17 | export function getStorage(app?: App): Storage_2; 18 | 19 | // @public 20 | class Storage_2 { 21 | get app(): App; 22 | bucket(name?: string): Bucket; 23 | } 24 | export { Storage_2 as Storage } 25 | 26 | ``` 27 | -------------------------------------------------------------------------------- /generate-esm-wrapper.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | const path = require('path'); 19 | const fs = require('mz/fs'); 20 | 21 | async function main() { 22 | const entryPoints = require('./entrypoints.json'); 23 | for (const entryPoint in entryPoints) { 24 | const info = entryPoints[entryPoint]; 25 | if (info.legacy) { 26 | continue; 27 | } 28 | 29 | await generateEsmWrapper(entryPoint, info.dist); 30 | } 31 | } 32 | 33 | async function generateEsmWrapper(entryPoint, source) { 34 | console.log(`Generating ESM wrapper for ${entryPoint}`); 35 | const target = getTarget(entryPoint); 36 | const output = getEsmOutput(source, target); 37 | await fs.mkdir(path.dirname(target), { recursive: true }); 38 | await fs.writeFile(target, output); 39 | await fs.writeFile('./lib/esm/package.json', JSON.stringify({type: 'module'})); 40 | } 41 | 42 | function getTarget(entryPoint) { 43 | const child = entryPoint.replace('firebase-admin/', ''); 44 | return `./lib/esm/${child}/index.js`; 45 | } 46 | 47 | function getEsmOutput(source, target) { 48 | const sourcePath = path.resolve(source); 49 | const cjsSource = require.resolve(sourcePath); 50 | const keys = getExports(cjsSource); 51 | const targetPath = path.resolve(target); 52 | const importPath = getImportPath(targetPath, cjsSource); 53 | 54 | let output = `import mod from ${JSON.stringify(importPath)};`; 55 | output += '\n\n'; 56 | for (const key of keys) { 57 | output += `export const ${key} = mod.${key};\n`; 58 | } 59 | 60 | return output; 61 | } 62 | 63 | function getImportPath(from, to) { 64 | const fromDir = path.dirname(from); 65 | return path.relative(fromDir, to).replace(/\\/g, '/'); 66 | } 67 | 68 | function getExports(cjsSource) { 69 | const mod = require(cjsSource); 70 | const keys = new Set(Object.getOwnPropertyNames(mod)); 71 | keys.delete('__esModule'); 72 | return [...keys].sort(); 73 | } 74 | 75 | (async () => { 76 | try { 77 | await main(); 78 | } catch (err) { 79 | console.log(err); 80 | process.exit(1); 81 | } 82 | })(); 83 | -------------------------------------------------------------------------------- /generate-reports.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | const path = require('path'); 19 | const fs = require('mz/fs'); 20 | const yargs = require('yargs'); 21 | const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor'); 22 | 23 | const { local: localMode } = yargs 24 | .option('local', { 25 | boolean: true, 26 | description: 'Run API Extractor with --local flag', 27 | }) 28 | .version(false) 29 | .help().argv; 30 | 31 | // API Extractor configuration file. 32 | const config = require('./api-extractor.json'); 33 | 34 | const tempConfigFile = 'api-extractor.tmp'; 35 | 36 | async function generateReports() { 37 | const entryPoints = require('./entrypoints.json'); 38 | for (const entryPoint in entryPoints) { 39 | const filePath = entryPoints[entryPoint].typings; 40 | await generateReportForEntryPoint(entryPoint, filePath); 41 | } 42 | } 43 | 44 | async function generateReportForEntryPoint(entryPoint, filePath) { 45 | console.log(`\nGenerating API report for ${entryPoint}`) 46 | console.log('========================================================\n'); 47 | 48 | const safeName = entryPoint.replace('/', '.'); 49 | console.log('Updating configuration for entry point...'); 50 | config.apiReport.reportFileName = `${safeName}.api.md`; 51 | config.mainEntryPointFilePath = filePath; 52 | console.log(`Report file name: ${config.apiReport.reportFileName}`); 53 | console.log(`Entry point declaration: ${config.mainEntryPointFilePath}`); 54 | await fs.writeFile(tempConfigFile, JSON.stringify(config)); 55 | 56 | try { 57 | const configFile = ExtractorConfig.loadFile(tempConfigFile); 58 | const extractorConfig = ExtractorConfig.prepare({ 59 | configObject: configFile, 60 | configObjectFullPath: path.resolve(tempConfigFile), 61 | packageJson: { 62 | name: safeName, 63 | }, 64 | packageJsonFullPath: path.resolve('package.json'), 65 | }); 66 | const extractorResult = Extractor.invoke(extractorConfig, { 67 | localBuild: localMode, 68 | showVerboseMessages: true 69 | }); 70 | if (!extractorResult.succeeded) { 71 | throw new Error(`API Extractor completed with ${extractorResult.errorCount} errors` 72 | + ` and ${extractorResult.warningCount} warnings`); 73 | } 74 | 75 | console.error(`API Extractor completed successfully`); 76 | } finally { 77 | await fs.unlink(tempConfigFile); 78 | } 79 | } 80 | 81 | (async () => { 82 | try { 83 | await generateReports(); 84 | } catch (err) { 85 | console.log(err); 86 | process.exit(1); 87 | } 88 | })(); 89 | -------------------------------------------------------------------------------- /src/app-check/app-check-namespace.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { App } from '../app'; 18 | import { 19 | AppCheckToken as TAppCheckToken, 20 | AppCheckTokenOptions as TAppCheckTokenOptions, 21 | DecodedAppCheckToken as TDecodedAppCheckToken, 22 | VerifyAppCheckTokenOptions as TVerifyAppCheckTokenOptions, 23 | VerifyAppCheckTokenResponse as TVerifyAppCheckTokenResponse, 24 | } from './app-check-api'; 25 | import { AppCheck as TAppCheck } from './app-check'; 26 | 27 | /** 28 | * Gets the {@link firebase-admin.app-check#AppCheck} service for the default app or a given app. 29 | * 30 | * `admin.appCheck()` can be called with no arguments to access the default 31 | * app's `AppCheck` service or as `admin.appCheck(app)` to access the 32 | * `AppCheck` service associated with a specific app. 33 | * 34 | * @example 35 | * ```javascript 36 | * // Get the `AppCheck` service for the default app 37 | * var defaultAppCheck = admin.appCheck(); 38 | * ``` 39 | * 40 | * @example 41 | * ```javascript 42 | * // Get the `AppCheck` service for a given app 43 | * var otherAppCheck = admin.appCheck(otherApp); 44 | * ``` 45 | * 46 | * @param app - Optional app for which to return the `AppCheck` service. 47 | * If not provided, the default `AppCheck` service is returned. 48 | * 49 | * @returns The default `AppCheck` service if no 50 | * app is provided, or the `AppCheck` service associated with the provided 51 | * app. 52 | */ 53 | export declare function appCheck(app?: App): appCheck.AppCheck; 54 | 55 | /* eslint-disable @typescript-eslint/no-namespace */ 56 | export namespace appCheck { 57 | /** 58 | * Type alias to {@link firebase-admin.app-check#AppCheck}. 59 | */ 60 | export type AppCheck = TAppCheck; 61 | 62 | /** 63 | * Type alias to {@link firebase-admin.app-check#AppCheckToken}. 64 | */ 65 | export type AppCheckToken = TAppCheckToken; 66 | 67 | /** 68 | * Type alias to {@link firebase-admin.app-check#DecodedAppCheckToken}. 69 | */ 70 | export type DecodedAppCheckToken = TDecodedAppCheckToken; 71 | 72 | /** 73 | * Type alias to {@link firebase-admin.app-check#VerifyAppCheckTokenResponse}. 74 | */ 75 | export type VerifyAppCheckTokenResponse = TVerifyAppCheckTokenResponse; 76 | 77 | /** 78 | * Type alias to {@link firebase-admin.app-check#AppCheckTokenOptions}. 79 | */ 80 | export type AppCheckTokenOptions = TAppCheckTokenOptions; 81 | 82 | /** 83 | * Type alias to {@link firebase-admin.app-check#VerifyAppCheckTokenOptions}. 84 | */ 85 | export type VerifyAppCheckTokenOptions = TVerifyAppCheckTokenOptions; 86 | } 87 | -------------------------------------------------------------------------------- /src/app-check/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Firebase App Check. 20 | * 21 | * @packageDocumentation 22 | */ 23 | 24 | import { App, getApp } from '../app'; 25 | import { FirebaseApp } from '../app/firebase-app'; 26 | import { AppCheck } from './app-check'; 27 | 28 | export { 29 | AppCheckToken, 30 | AppCheckTokenOptions, 31 | DecodedAppCheckToken, 32 | VerifyAppCheckTokenOptions, 33 | VerifyAppCheckTokenResponse, 34 | } from './app-check-api'; 35 | export { AppCheck } from './app-check'; 36 | 37 | /** 38 | * Gets the {@link AppCheck} service for the default app or a given app. 39 | * 40 | * `getAppCheck()` can be called with no arguments to access the default 41 | * app's `AppCheck` service or as `getAppCheck(app)` to access the 42 | * `AppCheck` service associated with a specific app. 43 | * 44 | * @example 45 | * ```javascript 46 | * // Get the `AppCheck` service for the default app 47 | * const defaultAppCheck = getAppCheck(); 48 | * ``` 49 | * 50 | * @example 51 | * ```javascript 52 | * // Get the `AppCheck` service for a given app 53 | * const otherAppCheck = getAppCheck(otherApp); 54 | * ``` 55 | * 56 | * @param app - Optional app for which to return the `AppCheck` service. 57 | * If not provided, the default `AppCheck` service is returned. 58 | * 59 | * @returns The default `AppCheck` service if no 60 | * app is provided, or the `AppCheck` service associated with the provided 61 | * app. 62 | */ 63 | export function getAppCheck(app?: App): AppCheck { 64 | if (typeof app === 'undefined') { 65 | app = getApp(); 66 | } 67 | 68 | const firebaseApp: FirebaseApp = app as FirebaseApp; 69 | return firebaseApp.getOrInitService('appCheck', (app) => new AppCheck(app)); 70 | } 71 | -------------------------------------------------------------------------------- /src/app/credential.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | export interface ServiceAccount { 19 | projectId?: string; 20 | clientEmail?: string; 21 | privateKey?: string; 22 | } 23 | 24 | /** 25 | * Interface for Google OAuth 2.0 access tokens. 26 | */ 27 | export interface GoogleOAuthAccessToken { 28 | access_token: string; 29 | expires_in: number; 30 | } 31 | 32 | /** 33 | * Interface that provides Google OAuth2 access tokens used to authenticate 34 | * with Firebase services. 35 | * 36 | * In most cases, you will not need to implement this yourself and can instead 37 | * use the default implementations provided by the `firebase-admin/app` module. 38 | */ 39 | export interface Credential { 40 | /** 41 | * Returns a Google OAuth2 access token object used to authenticate with 42 | * Firebase services. 43 | * 44 | * @returns A Google OAuth2 access token object. 45 | */ 46 | getAccessToken(): Promise; 47 | } -------------------------------------------------------------------------------- /src/app/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { getSdkVersion } from '../utils'; 19 | 20 | /** 21 | * Firebase App and SDK initialization. 22 | * 23 | * @packageDocumentation 24 | */ 25 | 26 | export { App, AppOptions, FirebaseArrayIndexError, FirebaseError } from './core' 27 | export { initializeApp, getApp, getApps, deleteApp } from './lifecycle'; 28 | 29 | export { Credential, ServiceAccount, GoogleOAuthAccessToken } from './credential'; 30 | export { applicationDefault, cert, refreshToken } from './credential-factory'; 31 | 32 | export { FirebaseAppError, AppErrorCodes } from '../utils/error'; 33 | 34 | export const SDK_VERSION = getSdkVersion(); 35 | -------------------------------------------------------------------------------- /src/auth/auth.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2017 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { App } from '../app/index'; 19 | import { AuthRequestHandler } from './auth-api-request'; 20 | import { TenantManager } from './tenant-manager'; 21 | import { BaseAuth } from './base-auth'; 22 | import { ProjectConfigManager } from './project-config-manager'; 23 | 24 | /** 25 | * Auth service bound to the provided app. 26 | * An Auth instance can have multiple tenants. 27 | */ 28 | export class Auth extends BaseAuth { 29 | 30 | private readonly tenantManager_: TenantManager; 31 | private readonly projectConfigManager_: ProjectConfigManager; 32 | private readonly app_: App; 33 | 34 | /** 35 | * @param app - The app for this Auth service. 36 | * @constructor 37 | * @internal 38 | */ 39 | constructor(app: App) { 40 | super(app, new AuthRequestHandler(app)); 41 | this.app_ = app; 42 | this.tenantManager_ = new TenantManager(app); 43 | this.projectConfigManager_ = new ProjectConfigManager(app); 44 | } 45 | 46 | /** 47 | * Returns the app associated with this Auth instance. 48 | * 49 | * @returns The app associated with this Auth instance. 50 | */ 51 | get app(): App { 52 | return this.app_; 53 | } 54 | 55 | /** 56 | * Returns the tenant manager instance associated with the current project. 57 | * 58 | * @returns The tenant manager instance associated with the current project. 59 | */ 60 | public tenantManager(): TenantManager { 61 | return this.tenantManager_; 62 | } 63 | 64 | /** 65 | * Returns the project config manager instance associated with the current project. 66 | * 67 | * @returns The project config manager instance associated with the current project. 68 | */ 69 | public projectConfigManager(): ProjectConfigManager { 70 | return this.projectConfigManager_; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/auth/identifier.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Used for looking up an account by uid. 19 | * 20 | * See {@link BaseAuth.getUsers}. 21 | */ 22 | export interface UidIdentifier { 23 | uid: string; 24 | } 25 | 26 | /** 27 | * Used for looking up an account by email. 28 | * 29 | * See {@link BaseAuth.getUsers}. 30 | */ 31 | export interface EmailIdentifier { 32 | email: string; 33 | } 34 | 35 | /** 36 | * Used for looking up an account by phone number. 37 | * 38 | * See {@link BaseAuth.getUsers}. 39 | */ 40 | export interface PhoneIdentifier { 41 | phoneNumber: string; 42 | } 43 | 44 | /** 45 | * Used for looking up an account by federated provider. 46 | * 47 | * See {@link BaseAuth.getUsers}. 48 | */ 49 | export interface ProviderIdentifier { 50 | providerId: string; 51 | providerUid: string; 52 | } 53 | 54 | /** 55 | * Identifies a user to be looked up. 56 | */ 57 | export type UserIdentifier = 58 | UidIdentifier | EmailIdentifier | PhoneIdentifier | ProviderIdentifier; 59 | 60 | /* 61 | * User defined type guards. See 62 | * https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards 63 | */ 64 | 65 | export function isUidIdentifier(id: UserIdentifier): id is UidIdentifier { 66 | return (id as UidIdentifier).uid !== undefined; 67 | } 68 | 69 | export function isEmailIdentifier(id: UserIdentifier): id is EmailIdentifier { 70 | return (id as EmailIdentifier).email !== undefined; 71 | } 72 | 73 | export function isPhoneIdentifier(id: UserIdentifier): id is PhoneIdentifier { 74 | return (id as PhoneIdentifier).phoneNumber !== undefined; 75 | } 76 | 77 | export function isProviderIdentifier(id: ProviderIdentifier): id is ProviderIdentifier { 78 | const pid = id as ProviderIdentifier; 79 | return pid.providerId !== undefined && pid.providerUid !== undefined; 80 | } 81 | -------------------------------------------------------------------------------- /src/auth/project-config-manager.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import { App } from '../app'; 17 | import { ProjectConfig, ProjectConfigServerResponse, UpdateProjectConfigRequest } from './project-config'; 18 | import { 19 | AuthRequestHandler, 20 | } from './auth-api-request'; 21 | 22 | /** 23 | * Manages (gets and updates) the current project config. 24 | */ 25 | export class ProjectConfigManager { 26 | private readonly authRequestHandler: AuthRequestHandler; 27 | /** 28 | * Initializes a ProjectConfigManager instance for a specified FirebaseApp. 29 | * 30 | * @param app - The app for this ProjectConfigManager instance. 31 | * 32 | * @constructor 33 | * @internal 34 | */ 35 | constructor(app: App) { 36 | this.authRequestHandler = new AuthRequestHandler(app); 37 | } 38 | 39 | /** 40 | * Get the project configuration. 41 | * 42 | * @returns A promise fulfilled with the project configuration. 43 | */ 44 | public getProjectConfig(): Promise { 45 | return this.authRequestHandler.getProjectConfig() 46 | .then((response: ProjectConfigServerResponse) => { 47 | return new ProjectConfig(response); 48 | }) 49 | } 50 | /** 51 | * Updates an existing project configuration. 52 | * 53 | * @param projectConfigOptions - The properties to update on the project. 54 | * 55 | * @returns A promise fulfilled with the updated project config. 56 | */ 57 | public updateProjectConfig(projectConfigOptions: UpdateProjectConfigRequest): Promise { 58 | return this.authRequestHandler.updateProjectConfig(projectConfigOptions) 59 | .then((response: ProjectConfigServerResponse) => { 60 | return new ProjectConfig(response); 61 | }) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/data-connect/data-connect-api.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2024 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { DecodedIdToken } from '../auth/token-verifier'; 19 | 20 | /** 21 | * Interface representing a Data Connect connector configuration. 22 | */ 23 | export interface ConnectorConfig { 24 | /** 25 | * Location ID of the Data Connect service. 26 | */ 27 | location: string; 28 | 29 | /** 30 | * Service ID of the Data Connect service. 31 | */ 32 | serviceId: string; 33 | } 34 | 35 | /** 36 | * Interface representing GraphQL response. 37 | */ 38 | export interface ExecuteGraphqlResponse { 39 | /** 40 | * Data payload of the GraphQL response. 41 | */ 42 | data: GraphqlResponse; 43 | } 44 | 45 | /** 46 | * Interface representing GraphQL options. 47 | */ 48 | export interface GraphqlOptions { 49 | /** 50 | * Values for GraphQL variables provided in this query or mutation. 51 | */ 52 | variables?: Variables; 53 | 54 | /** 55 | * The name of the GraphQL operation. Required only if `query` contains multiple operations. 56 | */ 57 | operationName?: string; 58 | 59 | /** 60 | * If set, impersonate a request with given Firebase Auth context and evaluate the auth 61 | * policies on the operation. If omitted, bypass any defined auth policies. 62 | */ 63 | impersonate?: ImpersonateAuthenticated | ImpersonateUnauthenticated; 64 | } 65 | 66 | /** 67 | * Type representing the partial claims of a Firebase Auth token used to evaluate the 68 | * Data Connect auth policy. 69 | */ 70 | export type AuthClaims = Partial; 71 | 72 | /** 73 | * Interface representing the impersonation of an authenticated user. 74 | */ 75 | export interface ImpersonateAuthenticated { 76 | /** 77 | * Evaluate the auth policy with a customized JWT auth token. Should follow the Firebase Auth token format. 78 | * https://firebase.google.com/docs/data-connect/cel-reference#auth-token-contents 79 | * 80 | * @example A verified user may have the following `authClaims`: 81 | * ```json 82 | * { "sub": "uid", "email_verified": true } 83 | * ``` 84 | */ 85 | authClaims: AuthClaims; 86 | 87 | /** 88 | * Both `authClaims` and `unauthenticated` are mutually exclusive fields and should not be both set. 89 | */ 90 | unauthenticated?: never; 91 | } 92 | 93 | /** 94 | * Interface representing the impersonation of an unauthenticated user. 95 | */ 96 | export interface ImpersonateUnauthenticated { 97 | /** 98 | * Both `authClaims` and `unauthenticated` are mutually exclusive fields and should not be both set. 99 | */ 100 | authClaims?: never; 101 | 102 | /** 103 | * Evaluates the auth policy as an unauthenticated request. Can only be set to true. 104 | */ 105 | unauthenticated: true; 106 | } 107 | -------------------------------------------------------------------------------- /src/data-connect/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2024 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Firebase Data Connect service. 20 | * 21 | * @packageDocumentation 22 | */ 23 | 24 | import { App, getApp } from '../app'; 25 | import { FirebaseApp } from '../app/firebase-app'; 26 | import { DataConnect, DataConnectService } from './data-connect'; 27 | import { ConnectorConfig } from './data-connect-api'; 28 | 29 | export { 30 | GraphqlOptions, 31 | ExecuteGraphqlResponse, 32 | ConnectorConfig, 33 | ImpersonateAuthenticated, 34 | ImpersonateUnauthenticated, 35 | AuthClaims 36 | } from './data-connect-api' 37 | export { 38 | DataConnect, 39 | } from './data-connect' 40 | 41 | /** 42 | * Gets the {@link DataConnect} service with the provided connector configuration 43 | * for the default app or a given app. 44 | * 45 | * `getDataConnect(connectorConfig)` can be called with no app argument to access the default 46 | * app's `DataConnect` service or as `getDataConnect(connectorConfig, app)` to access the 47 | * `DataConnect` service associated with a specific app. 48 | * 49 | * @example 50 | * ```javascript 51 | * const connectorConfig: ConnectorConfig = { 52 | * location: 'us-west2', 53 | * serviceId: 'my-service', 54 | * }; 55 | * 56 | * // Get the `DataConnect` service for the default app 57 | * const defaultDataConnect = getDataConnect(connectorConfig); 58 | * ``` 59 | * 60 | * @example 61 | * ```javascript 62 | * // Get the `DataConnect` service for a given app 63 | * const otherDataConnect = getDataConnect(connectorConfig, otherApp); 64 | * ``` 65 | * 66 | * @param connectorConfig - Connector configuration for the `DataConnect` service. 67 | * 68 | * @param app - Optional app for which to return the `DataConnect` service. 69 | * If not provided, the default `DataConnect` service is returned. 70 | * 71 | * @returns The default `DataConnect` service with the provided connector configuration 72 | * if no app is provided, or the `DataConnect` service associated with the provided app. 73 | */ 74 | export function getDataConnect(connectorConfig: ConnectorConfig, app?: App): DataConnect { 75 | if (typeof app === 'undefined') { 76 | app = getApp(); 77 | } 78 | 79 | const firebaseApp: FirebaseApp = app as FirebaseApp; 80 | const dataConnectService = firebaseApp.getOrInitService('dataConnect', (app) => new DataConnectService(app)); 81 | return dataConnectService.getDataConnect(connectorConfig); 82 | } 83 | -------------------------------------------------------------------------------- /src/default-namespace.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Firebase namespaced API (legacy). 19 | * 20 | * @packageDocumentation 21 | */ 22 | 23 | export * from './firebase-namespace-api'; 24 | -------------------------------------------------------------------------------- /src/default-namespace.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2017 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { defaultNamespace as firebaseAdmin } from './app/firebase-namespace'; 19 | 20 | // Inject a circular default export to allow users to use both: 21 | // 22 | // import firebaseAdmin from 'firebase-admin'; 23 | // which becomes: var firebaseAdmin = require('firebase-admin').default; 24 | // 25 | // as well as the more correct: 26 | // 27 | // import * as firebaseAdmin from 'firebase-admin'; 28 | // which becomes: var firebaseAdmin = require('firebase-admin'); 29 | (firebaseAdmin as any).default = firebaseAdmin; 30 | 31 | export = firebaseAdmin; 32 | -------------------------------------------------------------------------------- /src/eventarc/cloudevent.ts: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * @license 4 | * Copyright 2022 Google Inc. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * A CloudEvent version. 21 | */ 22 | export type CloudEventVersion = '1.0'; 23 | 24 | /** 25 | * A CloudEvent describes event data. 26 | * 27 | * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md 28 | */ 29 | export interface CloudEvent { 30 | 31 | /** 32 | * Identifier for the event. If not provided, it is auto-populated with a UUID. 33 | * 34 | * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#id 35 | */ 36 | id?: string; 37 | 38 | /** 39 | * Identifies the context in which an event happened. If not provided, the value of `EVENTARC_CLOUD_EVENT_SOURCE` 40 | * environment variable is used and if that is not set, a validation error is thrown. 41 | * 42 | * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#source-1 43 | */ 44 | source?: string; 45 | 46 | /** 47 | * The version of the CloudEvents specification which the event uses. If not provided, is set to `1.0` -- 48 | * the only supported value. 49 | * 50 | * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#specversion 51 | */ 52 | specversion?: CloudEventVersion; 53 | 54 | /** 55 | * Type of the event. Should be prefixed with a reverse-DNS name (`com.my-org.v1.something.happended`). 56 | * 57 | * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#type 58 | */ 59 | type: string; 60 | 61 | /** 62 | * Subject (context) of the event in the context of the event producer. 63 | * 64 | * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject 65 | */ 66 | subject?: string; 67 | 68 | /** 69 | * MIME type of the data being sent with the event in the `data` field. Only `application/json` and `text/plain` 70 | * are currently supported. If not specified, it is automatically inferred from the type of provided data. 71 | * 72 | * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#datacontenttype 73 | */ 74 | datacontenttype?: string; 75 | 76 | /** 77 | * Timestamp of the event. Must be in ISO time format. If not specified, current time (at the moment of publishing) 78 | * is used. 79 | * 80 | * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#time 81 | */ 82 | time?: string; 83 | 84 | /** 85 | * Data payload of the event. Objects are stringified with JSON and strings are be passed along as-is. 86 | */ 87 | data?: object | string; 88 | 89 | /** 90 | * Custom attributes/extensions. Must be strings. Added to the event as is. 91 | * 92 | * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#extension-context-attributes 93 | */ 94 | [key: string]: any; 95 | } 96 | -------------------------------------------------------------------------------- /src/eventarc/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2022 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Firebase Eventarc. 20 | * 21 | * @packageDocumentation 22 | */ 23 | 24 | import { App, getApp } from '../app'; 25 | import { FirebaseApp } from '../app/firebase-app'; 26 | 27 | import { Eventarc } from './eventarc'; 28 | 29 | export { CloudEvent, CloudEventVersion } from './cloudevent'; 30 | export { Eventarc, Channel, ChannelOptions } from './eventarc'; 31 | 32 | /** 33 | * Gets the {@link Eventarc} service for the default app or a given app. 34 | * 35 | * `getEventarc()` can be called with no arguments to access the default 36 | * app's `Eventarc` service or as `getEventarc(app)` to access the 37 | * `Eventarc` service associated with specific app. 38 | * 39 | * @example 40 | * ```javascript 41 | * // Get the Eventarc service for the default app 42 | * const defaultEventarc = getEventarc(); 43 | * ``` 44 | * 45 | * @example 46 | * ```javascript 47 | * // Get the Eventarc service for a given app 48 | * const otherEventarc = getEventarc(otherApp); 49 | * ``` 50 | * 51 | * @param app - Optional app whose `Eventarc` service will be returned. 52 | * If not provided, the default `Eventarc` service will be returned. 53 | * 54 | * @returns The default `Eventarc` service if no 55 | * app is provided or the `Eventarc` service associated with the provided 56 | * app. 57 | */ 58 | export function getEventarc(app?: App): Eventarc { 59 | if (typeof app === 'undefined') { 60 | app = getApp(); 61 | } 62 | 63 | const firebaseApp: FirebaseApp = app as FirebaseApp; 64 | return firebaseApp.getOrInitService('eventarc', (app) => new Eventarc(app)); 65 | } 66 | -------------------------------------------------------------------------------- /src/extensions/extensions-api.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2022 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * `SettableProcessingState` represents all the processing states that can be set 20 | * on an Extension instance's runtime data. 21 | * 22 | * @remarks 23 | * You can set the following states: 24 | * 25 | * - `NONE`: No relevant lifecycle event work has been done. 26 | * Set this to clear out old statuses. 27 | * 28 | * - `PROCESSING_COMPLETE`: Lifecycle event work completed with no errors. 29 | * 30 | * - `PROCESSING_WARNING`: Lifecycle event work succeeded partially, or 31 | * something happened that the user should be warned about. 32 | * 33 | * - `PROCESSING_FAILED`: Lifecycle event work failed completely, but the 34 | * instance will still work correctly going forward. 35 | * 36 | * If the extension instance is in a broken state due to errors, instead call 37 | * {@link Runtime.setFatalError}. 38 | * 39 | * The "processing" state gets set automatically when a lifecycle event handler 40 | * starts; you can't set it explicitly. 41 | * To report the ongoing status of an extension's function, use `console.log` 42 | * or the Cloud Functions logger SDK. 43 | */ 44 | export type SettableProcessingState = 'NONE' | 'PROCESSING_COMPLETE' | 'PROCESSING_WARNING' | 'PROCESSING_FAILED'; 45 | -------------------------------------------------------------------------------- /src/extensions/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Firebase Extensions service. 20 | * 21 | * @packageDocumentation 22 | */ 23 | 24 | import { App, getApp } from '../app'; 25 | import { FirebaseApp } from '../app/firebase-app'; 26 | import { Extensions } from './extensions'; 27 | 28 | export { Extensions, Runtime } from './extensions'; 29 | export { SettableProcessingState } from './extensions-api'; 30 | 31 | /** 32 | * Gets the {@link Extensions} service for the default app 33 | * or a given app. 34 | * 35 | * `getExtensions()` can be called with no arguments to access the default 36 | * app's `Extensions` service or as `getExtensions(app)` to access the 37 | * `Extensions` service associated with a specific app. 38 | * 39 | * @example 40 | * ```javascript 41 | * // Get the `Extensions` service for the default app 42 | * const defaultExtensions = getExtensions(); 43 | * ``` 44 | * 45 | * @example 46 | * ```javascript 47 | * // Get the `Extensions` service for a given app 48 | * const otherExtensions = getExtensions(otherApp); 49 | * ``` 50 | * 51 | * @param app - Optional app for which to return the `Extensions` service. 52 | * If not provided, the default `Extensions` service is returned. 53 | * 54 | * @returns The default `Extensions` service if no app is provided, or the `Extensions` 55 | * service associated with the provided app. 56 | */ 57 | export function getExtensions(app?: App): Extensions { 58 | if (typeof app === 'undefined') { 59 | app = getApp(); 60 | } 61 | 62 | const firebaseApp: FirebaseApp = app as FirebaseApp; 63 | return firebaseApp.getOrInitService('extensions', (app) => new Extensions(app)); 64 | } 65 | -------------------------------------------------------------------------------- /src/functions/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Firebase Functions service. 20 | * 21 | * @packageDocumentation 22 | */ 23 | 24 | import { App, getApp } from '../app'; 25 | import { FirebaseApp } from '../app/firebase-app'; 26 | import { Functions } from './functions'; 27 | 28 | export { 29 | DelayDelivery, 30 | AbsoluteDelivery, 31 | DeliverySchedule, 32 | TaskOptions, 33 | TaskOptionsExperimental, 34 | } from './functions-api'; 35 | export { 36 | Functions, 37 | TaskQueue 38 | } from './functions'; 39 | 40 | /** 41 | * Gets the {@link Functions} service for the default app 42 | * or a given app. 43 | * 44 | * `getFunctions()` can be called with no arguments to access the default 45 | * app's `Functions` service or as `getFunctions(app)` to access the 46 | * `Functions` service associated with a specific app. 47 | * 48 | * @example 49 | * ```javascript 50 | * // Get the `Functions` service for the default app 51 | * const defaultFunctions = getFunctions(); 52 | * ``` 53 | * 54 | * @example 55 | * ```javascript 56 | * // Get the `Functions` service for a given app 57 | * const otherFunctions = getFunctions(otherApp); 58 | * ``` 59 | * 60 | * @param app - Optional app for which to return the `Functions` service. 61 | * If not provided, the default `Functions` service is returned. 62 | * 63 | * @returns The default `Functions` service if no app is provided, or the `Functions` 64 | * service associated with the provided app. 65 | */ 66 | export function getFunctions(app?: App): Functions { 67 | if (typeof app === 'undefined') { 68 | app = getApp(); 69 | } 70 | 71 | const firebaseApp: FirebaseApp = app as FirebaseApp; 72 | return firebaseApp.getOrInitService('functions', (app) => new Functions(app)); 73 | } 74 | -------------------------------------------------------------------------------- /src/index.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2017 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import * as admin from './default-namespace'; 19 | 20 | declare module 'firebase-admin' { 21 | } 22 | 23 | export = admin; 24 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2017 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import * as firebase from './default-namespace'; 19 | 20 | // Only Node.js has a process variable that is of [[Class]] process 21 | const processGlobal = typeof process !== 'undefined' ? process : 0; 22 | if (Object.prototype.toString.call(processGlobal) !== '[object process]') { 23 | const message = ` 24 | ======== WARNING! ======== 25 | 26 | firebase-admin appears to have been installed in an unsupported environment. 27 | This package should only be used in server-side or backend Node.js environments, 28 | and should not be used in web browsers or other client-side environments. 29 | 30 | Use the Firebase JS SDK for client-side Firebase integrations: 31 | 32 | https://firebase.google.com/docs/web/setup 33 | `; 34 | // tslint:disable-next-line:no-console 35 | console.error(message); 36 | } 37 | 38 | export = firebase; 39 | -------------------------------------------------------------------------------- /src/installations/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Firebase Instance ID service. 19 | * 20 | * @packageDocumentation 21 | */ 22 | 23 | import { App, getApp } from '../app/index'; 24 | import { Installations } from './installations'; 25 | import { FirebaseApp } from '../app/firebase-app'; 26 | 27 | export { Installations }; 28 | 29 | /** 30 | * Gets the {@link Installations} service for the default app or a given app. 31 | * 32 | * `getInstallations()` can be called with no arguments to access the default 33 | * app's `Installations` service or as `getInstallations(app)` to access the 34 | * `Installations` service associated with a specific app. 35 | * 36 | * @example 37 | * ```javascript 38 | * // Get the Installations service for the default app 39 | * const defaultInstallations = getInstallations(); 40 | * ``` 41 | * 42 | * @example 43 | * ```javascript 44 | * // Get the Installations service for a given app 45 | * const otherInstallations = getInstallations(otherApp); 46 | *``` 47 | * 48 | * @param app - Optional app whose `Installations` service to 49 | * return. If not provided, the default `Installations` service will be 50 | * returned. 51 | * 52 | * @returns The default `Installations` service if 53 | * no app is provided or the `Installations` service associated with the 54 | * provided app. 55 | */ 56 | export function getInstallations(app?: App): Installations { 57 | if (typeof app === 'undefined') { 58 | app = getApp(); 59 | } 60 | 61 | const firebaseApp: FirebaseApp = app as FirebaseApp; 62 | return firebaseApp.getOrInitService('installations', (app) => new Installations(app)); 63 | } 64 | 65 | export { FirebaseInstallationsError, InstallationsClientErrorCode } from '../utils/error'; 66 | -------------------------------------------------------------------------------- /src/installations/installations-namespace.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { App } from '../app/index'; 18 | import { Installations as TInstallations } from './installations'; 19 | 20 | /** 21 | * Gets the {@link firebase-admin.installations#Installations} service for the 22 | * default app or a given app. 23 | * 24 | * `admin.installations()` can be called with no arguments to access the default 25 | * app's {@link firebase-admin.installations#Installations} service or as 26 | * `admin.installations(app)` to access the 27 | * {@link firebase-admin.installations#Installations} service associated with a 28 | * specific app. 29 | * 30 | * @example 31 | * ```javascript 32 | * // Get the Installations service for the default app 33 | * var defaultInstallations = admin.installations(); 34 | * ``` 35 | * 36 | * @example 37 | * ```javascript 38 | * // Get the Installations service for a given app 39 | * var otherInstallations = admin.installations(otherApp); 40 | *``` 41 | * 42 | * @param app - Optional app whose `Installations` service to 43 | * return. If not provided, the default `Installations` service is 44 | * returned. 45 | * 46 | * @returns The default `Installations` service if 47 | * no app is provided or the `Installations` service associated with the 48 | * provided app. 49 | */ 50 | export declare function installations(app?: App): installations.Installations; 51 | 52 | /* eslint-disable @typescript-eslint/no-namespace */ 53 | export namespace installations { 54 | /** 55 | * Type alias to {@link firebase-admin.installations#Installations}. 56 | */ 57 | export type Installations = TInstallations; 58 | } 59 | -------------------------------------------------------------------------------- /src/installations/installations.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { App } from '../app/index'; 18 | import { FirebaseInstallationsError, InstallationsClientErrorCode } from '../utils/error'; 19 | import { FirebaseInstallationsRequestHandler } from './installations-request-handler'; 20 | import * as validator from '../utils/validator'; 21 | 22 | /** 23 | * The `Installations` service for the current app. 24 | */ 25 | export class Installations { 26 | 27 | private app_: App; 28 | private requestHandler: FirebaseInstallationsRequestHandler; 29 | 30 | /** 31 | * @param app - The app for this Installations service. 32 | * @constructor 33 | * @internal 34 | */ 35 | constructor(app: App) { 36 | if (!validator.isNonNullObject(app) || !('options' in app)) { 37 | throw new FirebaseInstallationsError( 38 | InstallationsClientErrorCode.INVALID_ARGUMENT, 39 | 'First argument passed to admin.installations() must be a valid Firebase app instance.', 40 | ); 41 | } 42 | 43 | this.app_ = app; 44 | this.requestHandler = new FirebaseInstallationsRequestHandler(app); 45 | } 46 | 47 | /** 48 | * Deletes the specified installation ID and the associated data from Firebase. 49 | * 50 | * @param fid - The Firebase installation ID to be deleted. 51 | * 52 | * @returns A promise fulfilled when the installation ID is deleted. 53 | */ 54 | public deleteInstallation(fid: string): Promise { 55 | return this.requestHandler.deleteInstallation(fid); 56 | } 57 | 58 | /** 59 | * Returns the app associated with this Installations instance. 60 | * 61 | * @returns The app associated with this Installations instance. 62 | */ 63 | get app(): App { 64 | return this.app_; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/instance-id/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Firebase Instance ID service. 19 | * 20 | * @packageDocumentation 21 | */ 22 | 23 | import { App, getApp } from '../app/index'; 24 | import { InstanceId } from './instance-id'; 25 | import { FirebaseApp } from '../app/firebase-app'; 26 | 27 | export { InstanceId }; 28 | 29 | /** 30 | * Gets the {@link InstanceId} service for the default app or a given app. 31 | * 32 | * This API is deprecated. Developers are advised to use the 33 | * {@link firebase-admin.installations#getInstallations} 34 | * API to delete their instance IDs and Firebase installation IDs. 35 | * 36 | * `getInstanceId()` can be called with no arguments to access the default 37 | * app's `InstanceId` service or as `getInstanceId(app)` to access the 38 | * `InstanceId` service associated with a specific app. 39 | * 40 | * @example 41 | * ```javascript 42 | * // Get the Instance ID service for the default app 43 | * const defaultInstanceId = getInstanceId(); 44 | * ``` 45 | * 46 | * @example 47 | * ```javascript 48 | * // Get the Instance ID service for a given app 49 | * const otherInstanceId = getInstanceId(otherApp); 50 | *``` 51 | * 52 | * This API is deprecated. Developers are advised to use the `admin.installations()` 53 | * API to delete their instance IDs and Firebase installation IDs. 54 | * 55 | * @param app - Optional app whose `InstanceId` service to 56 | * return. If not provided, the default `InstanceId` service will be 57 | * returned. 58 | * 59 | * @returns The default `InstanceId` service if 60 | * no app is provided or the `InstanceId` service associated with the 61 | * provided app. 62 | * 63 | * @deprecated Use {@link firebase-admin.installations#getInstallations} instead. 64 | */ 65 | export function getInstanceId(app?: App): InstanceId { 66 | if (typeof app === 'undefined') { 67 | app = getApp(); 68 | } 69 | 70 | const firebaseApp: FirebaseApp = app as FirebaseApp; 71 | return firebaseApp.getOrInitService('instanceId', (app) => new InstanceId(app)); 72 | } 73 | 74 | export { FirebaseInstanceIdError, InstanceIdClientErrorCode } from '../utils/error'; 75 | -------------------------------------------------------------------------------- /src/instance-id/instance-id-namespace.ts: -------------------------------------------------------------------------------- 1 | import { App } from '../app/index'; 2 | import { InstanceId as TInstanceId } from './instance-id'; 3 | 4 | /** 5 | * Gets the {@link firebase-admin.instance-id#InstanceId} service for the 6 | * default app or a given app. 7 | * 8 | * `admin.instanceId()` can be called with no arguments to access the default 9 | * app's `InstanceId` service or as `admin.instanceId(app)` to access the 10 | * `InstanceId` service associated with a specific app. 11 | * 12 | * @example 13 | * ```javascript 14 | * // Get the Instance ID service for the default app 15 | * var defaultInstanceId = admin.instanceId(); 16 | * ``` 17 | * 18 | * @example 19 | * ```javascript 20 | * // Get the Instance ID service for a given app 21 | * var otherInstanceId = admin.instanceId(otherApp); 22 | *``` 23 | * 24 | * @param app - Optional app whose `InstanceId` service to 25 | * return. If not provided, the default `InstanceId` service will be 26 | * returned. 27 | * 28 | * @returns The default `InstanceId` service if 29 | * no app is provided or the `InstanceId` service associated with the 30 | * provided app. 31 | */ 32 | export declare function instanceId(app?: App): instanceId.InstanceId; 33 | 34 | /* eslint-disable @typescript-eslint/no-namespace */ 35 | export namespace instanceId { 36 | /** 37 | * Type alias to {@link firebase-admin.instance-id#InstanceId}. 38 | */ 39 | export type InstanceId = TInstanceId; 40 | } 41 | -------------------------------------------------------------------------------- /src/instance-id/instance-id.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { getInstallations } from '../installations'; 18 | import { App } from '../app/index'; 19 | import { 20 | FirebaseInstallationsError, FirebaseInstanceIdError, 21 | InstallationsClientErrorCode, InstanceIdClientErrorCode, 22 | } from '../utils/error'; 23 | import * as validator from '../utils/validator'; 24 | 25 | /** 26 | * The `InstanceId` service enables deleting the Firebase instance IDs 27 | * associated with Firebase client app instances. 28 | * 29 | * @deprecated Use {@link firebase-admin.installations#Installations} instead. 30 | */ 31 | export class InstanceId { 32 | 33 | private app_: App; 34 | 35 | /** 36 | * @param app - The app for this InstanceId service. 37 | * @constructor 38 | * @internal 39 | */ 40 | constructor(app: App) { 41 | if (!validator.isNonNullObject(app) || !('options' in app)) { 42 | throw new FirebaseInstanceIdError( 43 | InstanceIdClientErrorCode.INVALID_ARGUMENT, 44 | 'First argument passed to instanceId() must be a valid Firebase app instance.', 45 | ); 46 | } 47 | 48 | this.app_ = app; 49 | } 50 | 51 | /** 52 | * Deletes the specified instance ID and the associated data from Firebase. 53 | * 54 | * Note that Google Analytics for Firebase uses its own form of Instance ID to 55 | * keep track of analytics data. Therefore deleting a Firebase Instance ID does 56 | * not delete Analytics data. See 57 | * {@link https://firebase.google.com/support/privacy/manage-iids#delete_an_instance_id | 58 | * Delete an Instance ID} 59 | * for more information. 60 | * 61 | * @param instanceId - The instance ID to be deleted. 62 | * 63 | * @returns A promise fulfilled when the instance ID is deleted. 64 | */ 65 | public deleteInstanceId(instanceId: string): Promise { 66 | return getInstallations(this.app).deleteInstallation(instanceId) 67 | .catch((err) => { 68 | if (err instanceof FirebaseInstallationsError) { 69 | let code = err.code.replace('installations/', ''); 70 | if (code === InstallationsClientErrorCode.INVALID_INSTALLATION_ID.code) { 71 | code = InstanceIdClientErrorCode.INVALID_INSTANCE_ID.code; 72 | } 73 | 74 | throw new FirebaseInstanceIdError({ code, message: err.message }); 75 | } 76 | 77 | throw err; 78 | }); 79 | } 80 | 81 | /** 82 | * Returns the app associated with this InstanceId instance. 83 | * 84 | * @returns The app associated with this InstanceId instance. 85 | */ 86 | get app(): App { 87 | return this.app_; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/machine-learning/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Firebase Machine Learning. 19 | * 20 | * @packageDocumentation 21 | */ 22 | 23 | import { App, getApp } from '../app'; 24 | import { FirebaseApp } from '../app/firebase-app'; 25 | import { MachineLearning } from './machine-learning'; 26 | 27 | export { 28 | MachineLearning, 29 | ListModelsResult, 30 | Model, 31 | TFLiteModel, 32 | } from './machine-learning'; 33 | export { 34 | GcsTfliteModelOptions, 35 | ListModelsOptions, 36 | ModelOptions, 37 | ModelOptionsBase, 38 | } from './machine-learning-api-client'; 39 | 40 | /** 41 | * Gets the {@link MachineLearning} service for the default app or a given app. 42 | * 43 | * `getMachineLearning()` can be called with no arguments to access the 44 | * default app's `MachineLearning` service or as `getMachineLearning(app)` to access 45 | * the `MachineLearning` service associated with a specific app. 46 | * 47 | * @example 48 | * ```javascript 49 | * // Get the MachineLearning service for the default app 50 | * const defaultMachineLearning = getMachineLearning(); 51 | * ``` 52 | * 53 | * @example 54 | * ```javascript 55 | * // Get the MachineLearning service for a given app 56 | * const otherMachineLearning = getMachineLearning(otherApp); 57 | * ``` 58 | * 59 | * @param app - Optional app whose `MachineLearning` service to 60 | * return. If not provided, the default `MachineLearning` service 61 | * will be returned. 62 | * 63 | * @returns The default `MachineLearning` service if no app is provided or the 64 | * `MachineLearning` service associated with the provided app. 65 | */ 66 | export function getMachineLearning(app?: App): MachineLearning { 67 | if (typeof app === 'undefined') { 68 | app = getApp(); 69 | } 70 | 71 | const firebaseApp: FirebaseApp = app as FirebaseApp; 72 | return firebaseApp.getOrInitService('machineLearning', (app) => new MachineLearning(app)); 73 | } 74 | -------------------------------------------------------------------------------- /src/machine-learning/machine-learning-namespace.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { App } from '../app'; 18 | import { 19 | ListModelsResult as TListModelsResult, 20 | MachineLearning as TMachineLearning, 21 | Model as TModel, 22 | TFLiteModel as TTFLiteModel, 23 | } from './machine-learning'; 24 | import { 25 | GcsTfliteModelOptions as TGcsTfliteModelOptions, 26 | ListModelsOptions as TListModelsOptions, 27 | ModelOptions as TModelOptions, 28 | ModelOptionsBase as TModelOptionsBase, 29 | } from './machine-learning-api-client'; 30 | 31 | /** 32 | * Gets the {@link firebase-admin.machine-learning#MachineLearning} service for the 33 | * default app or a given app. 34 | * 35 | * `admin.machineLearning()` can be called with no arguments to access the 36 | * default app's `MachineLearning` service or as `admin.machineLearning(app)` to access 37 | * the `MachineLearning` service associated with a specific app. 38 | * 39 | * @example 40 | * ```javascript 41 | * // Get the MachineLearning service for the default app 42 | * var defaultMachineLearning = admin.machineLearning(); 43 | * ``` 44 | * 45 | * @example 46 | * ```javascript 47 | * // Get the MachineLearning service for a given app 48 | * var otherMachineLearning = admin.machineLearning(otherApp); 49 | * ``` 50 | * 51 | * @param app - Optional app whose `MachineLearning` service to 52 | * return. If not provided, the default `MachineLearning` service 53 | * will be returned. 54 | * 55 | * @returns The default `MachineLearning` service if no app is provided or the 56 | * `MachineLearning` service associated with the provided app. 57 | */ 58 | export declare function machineLearning(app?: App): machineLearning.MachineLearning; 59 | 60 | /* eslint-disable @typescript-eslint/no-namespace */ 61 | export namespace machineLearning { 62 | /** 63 | * Type alias to {@link firebase-admin.machine-learning#ListModelsResult}. 64 | */ 65 | export type ListModelsResult = TListModelsResult; 66 | 67 | /** 68 | * Type alias to {@link firebase-admin.machine-learning#MachineLearning}. 69 | */ 70 | export type MachineLearning = TMachineLearning; 71 | 72 | /** 73 | * Type alias to {@link firebase-admin.machine-learning#Model}. 74 | */ 75 | export type Model = TModel; 76 | 77 | /** 78 | * Type alias to {@link firebase-admin.machine-learning#TFLiteModel}. 79 | */ 80 | export type TFLiteModel = TTFLiteModel; 81 | 82 | /** 83 | * Type alias to {@link firebase-admin.machine-learning#GcsTfliteModelOptions}. 84 | */ 85 | export type GcsTfliteModelOptions = TGcsTfliteModelOptions; 86 | 87 | /** 88 | * Type alias to {@link firebase-admin.machine-learning#ListModelsOptions}. 89 | */ 90 | export type ListModelsOptions = TListModelsOptions; 91 | 92 | /** 93 | * Type alias to {@link firebase-admin.machine-learning#ModelOptions}. 94 | */ 95 | export type ModelOptions = TModelOptions; 96 | 97 | /** 98 | * Type alias to {@link firebase-admin.machine-learning#ModelOptionsBase}. 99 | */ 100 | export type ModelOptionsBase = TModelOptionsBase; 101 | } 102 | -------------------------------------------------------------------------------- /src/machine-learning/machine-learning-utils.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { PrefixedFirebaseError } from '../utils/error'; 18 | 19 | export type MachineLearningErrorCode = 20 | 'already-exists' 21 | | 'authentication-error' 22 | | 'internal-error' 23 | | 'invalid-argument' 24 | | 'invalid-server-response' 25 | | 'not-found' 26 | | 'resource-exhausted' 27 | | 'service-unavailable' 28 | | 'unknown-error' 29 | | 'cancelled' 30 | | 'deadline-exceeded' 31 | | 'permission-denied' 32 | | 'failed-precondition' 33 | | 'aborted' 34 | | 'out-of-range' 35 | | 'data-loss' 36 | | 'unauthenticated'; 37 | 38 | export class FirebaseMachineLearningError extends PrefixedFirebaseError { 39 | public static fromOperationError(code: number, message: string): FirebaseMachineLearningError { 40 | switch (code) { 41 | case 1: return new FirebaseMachineLearningError('cancelled', message); 42 | case 2: return new FirebaseMachineLearningError('unknown-error', message); 43 | case 3: return new FirebaseMachineLearningError('invalid-argument', message); 44 | case 4: return new FirebaseMachineLearningError('deadline-exceeded', message); 45 | case 5: return new FirebaseMachineLearningError('not-found', message); 46 | case 6: return new FirebaseMachineLearningError('already-exists', message); 47 | case 7: return new FirebaseMachineLearningError('permission-denied', message); 48 | case 8: return new FirebaseMachineLearningError('resource-exhausted', message); 49 | case 9: return new FirebaseMachineLearningError('failed-precondition', message); 50 | case 10: return new FirebaseMachineLearningError('aborted', message); 51 | case 11: return new FirebaseMachineLearningError('out-of-range', message); 52 | case 13: return new FirebaseMachineLearningError('internal-error', message); 53 | case 14: return new FirebaseMachineLearningError('service-unavailable', message); 54 | case 15: return new FirebaseMachineLearningError('data-loss', message); 55 | case 16: return new FirebaseMachineLearningError('unauthenticated', message); 56 | default: 57 | return new FirebaseMachineLearningError('unknown-error', message); 58 | } 59 | } 60 | 61 | constructor(code: MachineLearningErrorCode, message: string) { 62 | super('machine-learning', code, message); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/messaging/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Firebase Cloud Messaging (FCM). 19 | * 20 | * @packageDocumentation 21 | */ 22 | 23 | import { App, getApp } from '../app'; 24 | import { FirebaseApp } from '../app/firebase-app'; 25 | import { Messaging } from './messaging'; 26 | 27 | export { 28 | Messaging, 29 | } from './messaging'; 30 | 31 | export { 32 | AndroidConfig, 33 | AndroidFcmOptions, 34 | AndroidNotification, 35 | ApnsConfig, 36 | ApnsFcmOptions, 37 | ApnsPayload, 38 | Aps, 39 | ApsAlert, 40 | BaseMessage, 41 | BatchResponse, 42 | CriticalSound, 43 | ConditionMessage, 44 | FcmOptions, 45 | LightSettings, 46 | Message, 47 | MessagingTopicManagementResponse, 48 | MulticastMessage, 49 | Notification, 50 | SendResponse, 51 | TokenMessage, 52 | TopicMessage, 53 | WebpushConfig, 54 | WebpushFcmOptions, 55 | WebpushNotification, 56 | 57 | // Legacy APIs 58 | DataMessagePayload, 59 | MessagingOptions, 60 | MessagingPayload, 61 | NotificationMessagePayload, 62 | } from './messaging-api'; 63 | 64 | /** 65 | * Gets the {@link Messaging} service for the default app or a given app. 66 | * 67 | * `admin.messaging()` can be called with no arguments to access the default 68 | * app's `Messaging` service or as `admin.messaging(app)` to access the 69 | * `Messaging` service associated with aspecific app. 70 | * 71 | * @example 72 | * ```javascript 73 | * // Get the Messaging service for the default app 74 | * const defaultMessaging = getMessaging(); 75 | * ``` 76 | * 77 | * @example 78 | * ```javascript 79 | * // Get the Messaging service for a given app 80 | * const otherMessaging = getMessaging(otherApp); 81 | * ``` 82 | * 83 | * @param app - Optional app whose `Messaging` service to 84 | * return. If not provided, the default `Messaging` service will be returned. 85 | * 86 | * @returns The default `Messaging` service if no 87 | * app is provided or the `Messaging` service associated with the provided 88 | * app. 89 | */ 90 | export function getMessaging(app?: App): Messaging { 91 | if (typeof app === 'undefined') { 92 | app = getApp(); 93 | } 94 | 95 | const firebaseApp: FirebaseApp = app as FirebaseApp; 96 | return firebaseApp.getOrInitService('messaging', (app) => new Messaging(app)); 97 | } 98 | 99 | export { FirebaseMessagingError, MessagingClientErrorCode } from '../utils/error'; 100 | -------------------------------------------------------------------------------- /src/messaging/messaging-errors-internal.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { RequestResponseError } from '../utils/api-request'; 18 | import { FirebaseMessagingError, MessagingClientErrorCode } from '../utils/error'; 19 | import * as validator from '../utils/validator'; 20 | 21 | /** 22 | * Creates a new `FirebaseMessagingError` by extracting the error code, message and other relevant 23 | * details from a `RequestResponseError` response. 24 | * 25 | * @param err - The `RequestResponseError` to convert into a Firebase error 26 | * @returns A Firebase error that can be returned to the user. 27 | */ 28 | export function createFirebaseError(err: RequestResponseError): FirebaseMessagingError { 29 | if (err.response.isJson()) { 30 | // For JSON responses, map the server response to a client-side error. 31 | const json = err.response.data; 32 | const errorCode = getErrorCode(json); 33 | const errorMessage = getErrorMessage(json); 34 | return FirebaseMessagingError.fromServerError(errorCode, errorMessage, json); 35 | } 36 | 37 | // Non-JSON response 38 | let error: {code: string; message: string}; 39 | switch (err.response.status) { 40 | case 400: 41 | error = MessagingClientErrorCode.INVALID_ARGUMENT; 42 | break; 43 | case 401: 44 | case 403: 45 | error = MessagingClientErrorCode.AUTHENTICATION_ERROR; 46 | break; 47 | case 500: 48 | error = MessagingClientErrorCode.INTERNAL_ERROR; 49 | break; 50 | case 503: 51 | error = MessagingClientErrorCode.SERVER_UNAVAILABLE; 52 | break; 53 | default: 54 | // Treat non-JSON responses with unexpected status codes as unknown errors. 55 | error = MessagingClientErrorCode.UNKNOWN_ERROR; 56 | } 57 | return new FirebaseMessagingError({ 58 | code: error.code, 59 | message: `${ error.message } Raw server response: "${ err.response.text }". Status code: ` + 60 | `${ err.response.status }.`, 61 | }); 62 | } 63 | 64 | /** 65 | * @param response - The response to check for errors. 66 | * @returns The error code if present; null otherwise. 67 | */ 68 | export function getErrorCode(response: any): string | null { 69 | if (validator.isNonNullObject(response) && 'error' in response) { 70 | const error = response.error; 71 | if (validator.isString(error)) { 72 | return error; 73 | } 74 | if (validator.isArray(error.details)) { 75 | const fcmErrorType = 'type.googleapis.com/google.firebase.fcm.v1.FcmError'; 76 | for (const element of error.details) { 77 | if (element['@type'] === fcmErrorType) { 78 | return element.errorCode; 79 | } 80 | } 81 | } 82 | if ('status' in error) { 83 | return error.status; 84 | } else { 85 | return error.message; 86 | } 87 | } 88 | 89 | return null; 90 | } 91 | 92 | /** 93 | * Extracts error message from the given response object. 94 | * 95 | * @param response - The response to check for errors. 96 | * @returns The error message if present; null otherwise. 97 | */ 98 | function getErrorMessage(response: any): string | null { 99 | if (validator.isNonNullObject(response) && 100 | 'error' in response && 101 | validator.isNonEmptyString((response as any).error.message)) { 102 | return (response as any).error.message; 103 | } 104 | return null; 105 | } 106 | -------------------------------------------------------------------------------- /src/project-management/app-metadata.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Platforms with which a Firebase App can be associated. 19 | */ 20 | export enum AppPlatform { 21 | /** 22 | * Unknown state. This is only used for distinguishing unset values. 23 | */ 24 | PLATFORM_UNKNOWN = 'PLATFORM_UNKNOWN', 25 | 26 | /** 27 | * The Firebase App is associated with iOS. 28 | */ 29 | IOS = 'IOS', 30 | 31 | /** 32 | * The Firebase App is associated with Android. 33 | */ 34 | ANDROID = 'ANDROID', 35 | } 36 | 37 | /** 38 | * Metadata about a Firebase app. 39 | */ 40 | export interface AppMetadata { 41 | /** 42 | * The globally unique, Firebase-assigned identifier of the app. 43 | * 44 | * @example 45 | * ```javascript 46 | * var appId = appMetadata.appId; 47 | * ``` 48 | */ 49 | appId: string; 50 | 51 | /** 52 | * The optional user-assigned display name of the app. 53 | * 54 | * @example 55 | * ```javascript 56 | * var displayName = appMetadata.displayName; 57 | * ``` 58 | */ 59 | displayName?: string; 60 | 61 | /** 62 | * The development platform of the app. Supporting Android and iOS app platforms. 63 | * 64 | * @example 65 | * ```javascript 66 | * var platform = AppPlatform.ANDROID; 67 | * ``` 68 | */ 69 | platform: AppPlatform; 70 | 71 | /** 72 | * The globally unique, user-assigned ID of the parent project for the app. 73 | * 74 | * @example 75 | * ```javascript 76 | * var projectId = appMetadata.projectId; 77 | * ``` 78 | */ 79 | projectId: string; 80 | 81 | /** 82 | * The fully-qualified resource name that identifies this app. 83 | * 84 | * This is useful when manually constructing requests for Firebase's public API. 85 | * 86 | * @example 87 | * ```javascript 88 | * var resourceName = androidAppMetadata.resourceName; 89 | * ``` 90 | */ 91 | resourceName: string; 92 | } 93 | -------------------------------------------------------------------------------- /src/project-management/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Firebase project management. 19 | * 20 | * @packageDocumentation 21 | */ 22 | 23 | import { App, getApp } from '../app'; 24 | import { FirebaseApp } from '../app/firebase-app'; 25 | import { ProjectManagement } from './project-management'; 26 | 27 | export { AppMetadata, AppPlatform } from './app-metadata'; 28 | export { ProjectManagement } from './project-management'; 29 | export { AndroidApp, AndroidAppMetadata, ShaCertificate } from './android-app'; 30 | export { IosApp, IosAppMetadata } from './ios-app'; 31 | 32 | /** 33 | * Gets the {@link ProjectManagement} service for the default app or a given app. 34 | * 35 | * `getProjectManagement()` can be called with no arguments to access the 36 | * default app's `ProjectManagement` service, or as `getProjectManagement(app)` to access 37 | * the `ProjectManagement` service associated with a specific app. 38 | * 39 | * @example 40 | * ```javascript 41 | * // Get the ProjectManagement service for the default app 42 | * const defaultProjectManagement = getProjectManagement(); 43 | * ``` 44 | * 45 | * @example 46 | * ```javascript 47 | * // Get the ProjectManagement service for a given app 48 | * const otherProjectManagement = getProjectManagement(otherApp); 49 | * ``` 50 | * 51 | * @param app - Optional app whose `ProjectManagement` service 52 | * to return. If not provided, the default `ProjectManagement` service will 53 | * be returned. * 54 | * @returns The default `ProjectManagement` service if no app is provided or the 55 | * `ProjectManagement` service associated with the provided app. 56 | */ 57 | export function getProjectManagement(app?: App): ProjectManagement { 58 | if (typeof app === 'undefined') { 59 | app = getApp(); 60 | } 61 | 62 | const firebaseApp: FirebaseApp = app as FirebaseApp; 63 | return firebaseApp.getOrInitService('projectManagement', (app) => new ProjectManagement(app)); 64 | } 65 | 66 | export { FirebaseProjectManagementError, ProjectManagementErrorCode } from '../utils/error'; 67 | -------------------------------------------------------------------------------- /src/project-management/project-management-namespace.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { App } from '../app'; 18 | import { 19 | AppMetadata as TAppMetadata, 20 | AppPlatform as TAppPlatform, 21 | } from './app-metadata'; 22 | import { ProjectManagement as TProjectManagement } from './project-management'; 23 | import { 24 | AndroidApp as TAndroidApp, 25 | AndroidAppMetadata as TAndroidAppMetadata, 26 | ShaCertificate as TShaCertificate, 27 | } from './android-app'; 28 | import { 29 | IosApp as TIosApp, 30 | IosAppMetadata as TIosAppMetadata, 31 | } from './ios-app'; 32 | 33 | /** 34 | * Gets the {@link firebase-admin.project-management#ProjectManagement} service for the 35 | * default app or a given app. 36 | * 37 | * `admin.projectManagement()` can be called with no arguments to access the 38 | * default app's `ProjectManagement` service, or as `admin.projectManagement(app)` to access 39 | * the `ProjectManagement` service associated with a specific app. 40 | * 41 | * @example 42 | * ```javascript 43 | * // Get the ProjectManagement service for the default app 44 | * var defaultProjectManagement = admin.projectManagement(); 45 | * ``` 46 | * 47 | * @example 48 | * ```javascript 49 | * // Get the ProjectManagement service for a given app 50 | * var otherProjectManagement = admin.projectManagement(otherApp); 51 | * ``` 52 | * 53 | * @param app - Optional app whose `ProjectManagement` service 54 | * to return. If not provided, the default `ProjectManagement` service will 55 | * be returned. * 56 | * @returns The default `ProjectManagement` service if no app is provided or the 57 | * `ProjectManagement` service associated with the provided app. 58 | */ 59 | export declare function projectManagement(app?: App): projectManagement.ProjectManagement; 60 | 61 | /* eslint-disable @typescript-eslint/no-namespace */ 62 | export namespace projectManagement { 63 | /** 64 | * Type alias to {@link firebase-admin.project-management#AppMetadata}. 65 | */ 66 | export type AppMetadata = TAppMetadata; 67 | 68 | /** 69 | * Type alias to {@link firebase-admin.project-management#AppPlatform}. 70 | */ 71 | export type AppPlatform = TAppPlatform; 72 | 73 | /** 74 | * Type alias to {@link firebase-admin.project-management#ProjectManagement}. 75 | */ 76 | export type ProjectManagement = TProjectManagement; 77 | 78 | /** 79 | * Type alias to {@link firebase-admin.project-management#IosApp}. 80 | */ 81 | export type IosApp = TIosApp; 82 | 83 | /** 84 | * Type alias to {@link firebase-admin.project-management#IosAppMetadata}. 85 | */ 86 | export type IosAppMetadata = TIosAppMetadata; 87 | 88 | /** 89 | * Type alias to {@link firebase-admin.project-management#AndroidApp}. 90 | */ 91 | export type AndroidApp = TAndroidApp; 92 | 93 | /** 94 | * Type alias to {@link firebase-admin.project-management#AndroidAppMetadata}. 95 | */ 96 | export type AndroidAppMetadata = TAndroidAppMetadata; 97 | 98 | /** 99 | * Type alias to {@link firebase-admin.project-management#ShaCertificate}. 100 | */ 101 | export type ShaCertificate = TShaCertificate; 102 | } 103 | -------------------------------------------------------------------------------- /src/remote-config/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Firebase Remote Config. 19 | * 20 | * @packageDocumentation 21 | */ 22 | 23 | import { App, getApp } from '../app'; 24 | import { FirebaseApp } from '../app/firebase-app'; 25 | import { RemoteConfig } from './remote-config'; 26 | 27 | export { 28 | AndCondition, 29 | CustomSignalCondition, 30 | CustomSignalOperator, 31 | DefaultConfig, 32 | EvaluationContext, 33 | ExplicitParameterValue, 34 | FetchResponseData, 35 | GetServerTemplateOptions, 36 | InAppDefaultValue, 37 | InitServerTemplateOptions, 38 | ListVersionsOptions, 39 | ListVersionsResult, 40 | MicroPercentRange, 41 | NamedCondition, 42 | OneOfCondition, 43 | OrCondition, 44 | ParameterValueType, 45 | PercentConditionOperator, 46 | PercentCondition, 47 | PredefinedSignals, 48 | RemoteConfigCondition, 49 | RemoteConfigParameter, 50 | RemoteConfigParameterGroup, 51 | RemoteConfigParameterValue, 52 | RemoteConfigTemplate, 53 | RemoteConfigUser, 54 | ServerConfig, 55 | ServerTemplate, 56 | ServerTemplateData, 57 | ServerTemplateDataType, 58 | TagColor, 59 | UserProvidedSignals, 60 | Value, 61 | ValueSource, 62 | Version, 63 | } from './remote-config-api'; 64 | export { RemoteConfig, RemoteConfigFetchResponse } from './remote-config'; 65 | 66 | /** 67 | * Gets the {@link RemoteConfig} service for the default app or a given app. 68 | * 69 | * `getRemoteConfig()` can be called with no arguments to access the default 70 | * app's `RemoteConfig` service or as `getRemoteConfig(app)` to access the 71 | * `RemoteConfig` service associated with a specific app. 72 | * 73 | * @example 74 | * ```javascript 75 | * // Get the `RemoteConfig` service for the default app 76 | * const defaultRemoteConfig = getRemoteConfig(); 77 | * ``` 78 | * 79 | * @example 80 | * ```javascript 81 | * // Get the `RemoteConfig` service for a given app 82 | * const otherRemoteConfig = getRemoteConfig(otherApp); 83 | * ``` 84 | * 85 | * @param app - Optional app for which to return the `RemoteConfig` service. 86 | * If not provided, the default `RemoteConfig` service is returned. 87 | * 88 | * @returns The default `RemoteConfig` service if no 89 | * app is provided, or the `RemoteConfig` service associated with the provided 90 | * app. 91 | */ 92 | export function getRemoteConfig(app?: App): RemoteConfig { 93 | if (typeof app === 'undefined') { 94 | app = getApp(); 95 | } 96 | 97 | const firebaseApp: FirebaseApp = app as FirebaseApp; 98 | return firebaseApp.getOrInitService('remoteConfig', (app) => new RemoteConfig(app)); 99 | } 100 | -------------------------------------------------------------------------------- /src/remote-config/internal/value-impl.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2024 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 'use strict'; 18 | 19 | import { 20 | Value, 21 | ValueSource, 22 | } from '../remote-config-api'; 23 | 24 | /** 25 | * Implements type-safe getters for parameter values. 26 | * 27 | * Visible for testing. 28 | * 29 | * @internal 30 | */ 31 | export class ValueImpl implements Value { 32 | public static readonly DEFAULT_VALUE_FOR_BOOLEAN = false; 33 | public static readonly DEFAULT_VALUE_FOR_STRING = ''; 34 | public static readonly DEFAULT_VALUE_FOR_NUMBER = 0; 35 | public static readonly BOOLEAN_TRUTHY_VALUES = ['1', 'true', 't', 'yes', 'y', 'on']; 36 | constructor( 37 | private readonly source: ValueSource, 38 | private readonly value = ValueImpl.DEFAULT_VALUE_FOR_STRING) { } 39 | asString(): string { 40 | return this.value; 41 | } 42 | asBoolean(): boolean { 43 | if (this.source === 'static') { 44 | return ValueImpl.DEFAULT_VALUE_FOR_BOOLEAN; 45 | } 46 | return ValueImpl.BOOLEAN_TRUTHY_VALUES.indexOf(this.value.toLowerCase()) >= 0; 47 | } 48 | asNumber(): number { 49 | if (this.source === 'static') { 50 | return ValueImpl.DEFAULT_VALUE_FOR_NUMBER; 51 | } 52 | const num = Number(this.value); 53 | if (isNaN(num)) { 54 | return ValueImpl.DEFAULT_VALUE_FOR_NUMBER; 55 | } 56 | return num; 57 | } 58 | getSource(): ValueSource { 59 | return this.source; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/security-rules/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Security Rules for Cloud Firestore and Cloud Storage. 19 | * 20 | * @packageDocumentation 21 | */ 22 | 23 | import { App, getApp } from '../app'; 24 | import { FirebaseApp } from '../app/firebase-app'; 25 | import { SecurityRules } from './security-rules'; 26 | 27 | export { 28 | RulesFile, 29 | Ruleset, 30 | RulesetMetadata, 31 | RulesetMetadataList, 32 | SecurityRules, 33 | } from './security-rules'; 34 | 35 | /** 36 | * Gets the {@link SecurityRules} service for the default app or a given app. 37 | * 38 | * `admin.securityRules()` can be called with no arguments to access the 39 | * default app's `SecurityRules` service, or as `admin.securityRules(app)` to access 40 | * the `SecurityRules` service associated with a specific app. 41 | * 42 | * @example 43 | * ```javascript 44 | * // Get the SecurityRules service for the default app 45 | * const defaultSecurityRules = getSecurityRules(); 46 | * ``` 47 | * 48 | * @example 49 | * ```javascript 50 | * // Get the SecurityRules service for a given app 51 | * const otherSecurityRules = getSecurityRules(otherApp); 52 | * ``` 53 | * 54 | * @param app - Optional app to return the `SecurityRules` service 55 | * for. If not provided, the default `SecurityRules` service 56 | * is returned. 57 | * @returns The default `SecurityRules` service if no app is provided, or the 58 | * `SecurityRules` service associated with the provided app. 59 | */ 60 | export function getSecurityRules(app?: App): SecurityRules { 61 | if (typeof app === 'undefined') { 62 | app = getApp(); 63 | } 64 | 65 | const firebaseApp: FirebaseApp = app as FirebaseApp; 66 | return firebaseApp.getOrInitService('securityRules', (app) => new SecurityRules(app)); 67 | } 68 | -------------------------------------------------------------------------------- /src/security-rules/security-rules-internal.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { PrefixedFirebaseError } from '../utils/error'; 18 | 19 | export type SecurityRulesErrorCode = 20 | 'already-exists' 21 | | 'authentication-error' 22 | | 'internal-error' 23 | | 'invalid-argument' 24 | | 'invalid-server-response' 25 | | 'not-found' 26 | | 'resource-exhausted' 27 | | 'service-unavailable' 28 | | 'unknown-error'; 29 | 30 | export class FirebaseSecurityRulesError extends PrefixedFirebaseError { 31 | constructor(code: SecurityRulesErrorCode, message: string) { 32 | super('security-rules', code, message); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/security-rules/security-rules-namespace.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { App } from '../app'; 18 | import { 19 | RulesFile as TRulesFile, 20 | Ruleset as TRuleset, 21 | RulesetMetadata as TRulesetMetadata, 22 | RulesetMetadataList as TRulesetMetadataList, 23 | SecurityRules as TSecurityRules, 24 | } from './security-rules'; 25 | 26 | /** 27 | * Gets the {@link firebase-admin.security-rules#SecurityRules} service for the default 28 | * app or a given app. 29 | * 30 | * `admin.securityRules()` can be called with no arguments to access the 31 | * default app's {@link firebase-admin.security-rules#SecurityRules} 32 | * service, or as `admin.securityRules(app)` to access 33 | * the {@link firebase-admin.security-rules#SecurityRules} 34 | * service associated with a specific app. 35 | * 36 | * @example 37 | * ```javascript 38 | * // Get the SecurityRules service for the default app 39 | * var defaultSecurityRules = admin.securityRules(); 40 | * ``` 41 | * 42 | * @example 43 | * ```javascript 44 | * // Get the SecurityRules service for a given app 45 | * var otherSecurityRules = admin.securityRules(otherApp); 46 | * ``` 47 | * 48 | * @param app - Optional app to return the `SecurityRules` service 49 | * for. If not provided, the default `SecurityRules` service 50 | * is returned. 51 | * @returns The default `SecurityRules` service if no app is provided, or the 52 | * `SecurityRules` service associated with the provided app. 53 | */ 54 | export declare function securityRules(app?: App): securityRules.SecurityRules; 55 | 56 | /* eslint-disable @typescript-eslint/no-namespace */ 57 | export namespace securityRules { 58 | /** 59 | * Type alias to {@link firebase-admin.security-rules#RulesFile}. 60 | */ 61 | export type RulesFile = TRulesFile; 62 | 63 | /** 64 | * Type alias to {@link firebase-admin.security-rules#Ruleset}. 65 | */ 66 | export type Ruleset = TRuleset; 67 | 68 | /** 69 | * Type alias to {@link firebase-admin.security-rules#RulesetMetadata}. 70 | */ 71 | export type RulesetMetadata = TRulesetMetadata; 72 | 73 | /** 74 | * Type alias to {@link firebase-admin.security-rules#RulesetMetadataList}. 75 | */ 76 | export type RulesetMetadataList = TRulesetMetadataList; 77 | 78 | /** 79 | * Type alias to {@link firebase-admin.security-rules#SecurityRules}. 80 | */ 81 | export type SecurityRules = TSecurityRules; 82 | } 83 | -------------------------------------------------------------------------------- /src/storage/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Cloud Storage for Firebase. 19 | * 20 | * @packageDocumentation 21 | */ 22 | 23 | import { File } from '@google-cloud/storage'; 24 | import { App, getApp } from '../app'; 25 | import { FirebaseApp } from '../app/firebase-app'; 26 | import { Storage } from './storage'; 27 | import { FirebaseError } from '../utils/error'; 28 | import { getFirebaseMetadata } from './utils'; 29 | 30 | export { Storage } from './storage'; 31 | 32 | 33 | /** 34 | * Gets the {@link Storage} service for the default app or a given app. 35 | * 36 | * `getStorage()` can be called with no arguments to access the default 37 | * app's `Storage` service or as `getStorage(app)` to access the 38 | * `Storage` service associated with a specific app. 39 | * 40 | * @example 41 | * ```javascript 42 | * // Get the Storage service for the default app 43 | * const defaultStorage = getStorage(); 44 | * ``` 45 | * 46 | * @example 47 | * ```javascript 48 | * // Get the Storage service for a given app 49 | * const otherStorage = getStorage(otherApp); 50 | * ``` 51 | */ 52 | export function getStorage(app?: App): Storage { 53 | if (typeof app === 'undefined') { 54 | app = getApp(); 55 | } 56 | 57 | const firebaseApp: FirebaseApp = app as FirebaseApp; 58 | return firebaseApp.getOrInitService('storage', (app) => new Storage(app)); 59 | } 60 | 61 | 62 | 63 | /** 64 | * Gets the download URL for the given {@link https://cloud.google.com/nodejs/docs/reference/storage/latest/storage/file | File}. 65 | * 66 | * @example 67 | * ```javascript 68 | * // Get the downloadUrl for a given file ref 69 | * const storage = getStorage(); 70 | * const myRef = ref(storage, 'images/mountains.jpg'); 71 | * const downloadUrl = await getDownloadURL(myRef); 72 | * ``` 73 | */ 74 | export async function getDownloadURL(file: File): Promise { 75 | const endpoint = 76 | (process.env.STORAGE_EMULATOR_HOST || 77 | 'https://firebasestorage.googleapis.com') + '/v0'; 78 | const { downloadTokens } = await getFirebaseMetadata(endpoint, file); 79 | if (!downloadTokens) { 80 | throw new FirebaseError({ 81 | code: 'storage/no-download-token', 82 | message: 83 | 'No download token available. Please create one in the Firebase Console.', 84 | }); 85 | } 86 | const [token] = downloadTokens.split(','); 87 | return `${endpoint}/b/${file.bucket.name}/o/${encodeURIComponent( 88 | file.name 89 | )}?alt=media&token=${token}`; 90 | } 91 | -------------------------------------------------------------------------------- /src/storage/storage-namespace.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { App } from '../app'; 18 | import { Storage as TStorage } from './storage'; 19 | 20 | /** 21 | * Gets the {@link firebase-admin.storage#Storage} service for the 22 | * default app or a given app. 23 | * 24 | * `admin.storage()` can be called with no arguments to access the default 25 | * app's `Storage` service or as `admin.storage(app)` to access the 26 | * `Storage` service associated with a specific app. 27 | * 28 | * @example 29 | * ```javascript 30 | * // Get the Storage service for the default app 31 | * var defaultStorage = admin.storage(); 32 | * ``` 33 | * 34 | * @example 35 | * ```javascript 36 | * // Get the Storage service for a given app 37 | * var otherStorage = admin.storage(otherApp); 38 | * ``` 39 | */ 40 | export declare function storage(app?: App): storage.Storage; 41 | 42 | /* eslint-disable @typescript-eslint/no-namespace */ 43 | export namespace storage { 44 | /** 45 | * Type alias to {@link firebase-admin.storage#Storage}. 46 | */ 47 | export type Storage = TStorage; 48 | } 49 | -------------------------------------------------------------------------------- /src/storage/utils.ts: -------------------------------------------------------------------------------- 1 | import { File } from '@google-cloud/storage'; 2 | export interface FirebaseMetadata { 3 | name: string; 4 | bucket: string; 5 | generation: string; 6 | metageneration: string; 7 | contentType: string; 8 | timeCreated: string; 9 | updated: string; 10 | storageClass: string; 11 | size: string; 12 | md5Hash: string; 13 | contentEncoding: string; 14 | contentDisposition: string; 15 | crc32c: string; 16 | etag: string; 17 | downloadTokens?: string; 18 | } 19 | 20 | export function getFirebaseMetadata( 21 | endpoint: string, 22 | file: File 23 | ): Promise { 24 | const uri = `${endpoint}/b/${file.bucket.name}/o/${encodeURIComponent( 25 | file.name 26 | )}`; 27 | 28 | return new Promise((resolve, reject) => { 29 | file.storage.makeAuthenticatedRequest( 30 | { 31 | method: 'GET', 32 | uri, 33 | }, 34 | (err, body) => { 35 | if (err) { 36 | reject(err); 37 | } else { 38 | resolve(body); 39 | } 40 | } 41 | ); 42 | }); 43 | } 44 | -------------------------------------------------------------------------------- /src/utils/deep-copy.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2017 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Returns a deep copy of an object or array. 20 | * 21 | * @param value - The object or array to deep copy. 22 | * @returns A deep copy of the provided object or array. 23 | */ 24 | export function deepCopy(value: T): T { 25 | return deepExtend(undefined, value); 26 | } 27 | 28 | 29 | /** 30 | * Copies properties from source to target (recursively allows extension of objects and arrays). 31 | * Scalar values in the target are over-written. If target is undefined, an object of the 32 | * appropriate type will be created (and returned). 33 | * 34 | * We recursively copy all child properties of plain objects in the source - so that namespace-like 35 | * objects are merged. 36 | * 37 | * Note that the target can be a function, in which case the properties in the source object are 38 | * copied onto it as static properties of the function. 39 | * 40 | * @param target - The value which is being extended. 41 | * @param source - The value whose properties are extending the target. 42 | * @returns The target value. 43 | */ 44 | export function deepExtend(target: any, source: any): any { 45 | if (!(source instanceof Object)) { 46 | return source; 47 | } 48 | 49 | switch (source.constructor) { 50 | case Date: { 51 | // Treat Dates like scalars; if the target date object had any child 52 | // properties - they will be lost! 53 | const dateValue = (source as any) as Date; 54 | return new Date(dateValue.getTime()); 55 | } 56 | case Object: 57 | if (target === undefined) { 58 | target = {}; 59 | } 60 | break; 61 | 62 | case Array: 63 | // Always copy the array source and overwrite the target. 64 | target = []; 65 | break; 66 | 67 | default: 68 | // Not a plain Object - treat it as a scalar. 69 | return source; 70 | } 71 | 72 | for (const prop in source) { 73 | if (!Object.prototype.hasOwnProperty.call(source, prop)) { 74 | continue; 75 | } 76 | target[prop] = deepExtend(target[prop], source[prop]); 77 | } 78 | 79 | return target; 80 | } 81 | -------------------------------------------------------------------------------- /test/integration/functions.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as chai from 'chai'; 18 | import * as chaiAsPromised from 'chai-as-promised'; 19 | import { getFunctions } from '../../lib/functions/index'; 20 | 21 | chai.should(); 22 | chai.use(chaiAsPromised); 23 | 24 | const expect = chai.expect; 25 | 26 | describe('getFunctions()', () => { 27 | 28 | describe('taskQueue()', () => { 29 | it('successfully returns a taskQueue', () => { 30 | const factorizeQueue = getFunctions().taskQueue('queue-name'); 31 | expect(factorizeQueue).to.be.not.undefined; 32 | expect(typeof factorizeQueue.enqueue).to.equal('function'); 33 | }); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /test/integration/installations.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { getInstallations } from '../../lib/installations/index'; 18 | import * as chai from 'chai'; 19 | import * as chaiAsPromised from 'chai-as-promised'; 20 | 21 | chai.should(); 22 | chai.use(chaiAsPromised); 23 | 24 | describe('admin.installations', () => { 25 | it('deleteInstallation() fails when called with fictive-ID0 instance ID', () => { 26 | // instance ids have to conform to /[cdef][A-Za-z0-9_-]{9}[AEIMQUYcgkosw048]/ 27 | return getInstallations().deleteInstallation('fictive-ID0') 28 | .should.eventually.be 29 | .rejectedWith('Installation ID "fictive-ID0": Failed to find the installation ID.'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /test/integration/instance-id.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2018 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as chai from 'chai'; 18 | import * as chaiAsPromised from 'chai-as-promised'; 19 | import { getInstanceId } from '../../lib/instance-id/index'; 20 | 21 | chai.should(); 22 | chai.use(chaiAsPromised); 23 | 24 | describe('admin.instanceId', () => { 25 | it('deleteInstanceId() fails when called with fictive-ID0 instance ID', () => { 26 | // instance ids have to conform to /[cdef][A-Za-z0-9_-]{9}[AEIMQUYcgkosw048]/ 27 | return getInstanceId().deleteInstanceId('fictive-ID0') 28 | .should.eventually.be 29 | .rejectedWith('Installation ID "fictive-ID0": Failed to find the installation ID.'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /test/integration/postcheck/esm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } 4 | -------------------------------------------------------------------------------- /test/integration/postcheck/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firebase-admin-postcheck", 3 | "version": "1.0.0", 4 | "description": "Firebase Admin SDK post package test cases", 5 | "license": "Apache-2.0", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/firebase/firebase-admin-node" 9 | }, 10 | "devDependencies": { 11 | "@types/chai": "^4.0.0", 12 | "@types/mocha": "^2.2.48", 13 | "@types/node": ">=14.0.0", 14 | "chai": "^4.2.0", 15 | "mocha": "^8.0.0", 16 | "ts-node": "^10.8.1", 17 | "typescript": "^5.5.4" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/integration/postcheck/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "target": "es2020", 6 | "noImplicitAny": false, 7 | "lib": ["es2020"], 8 | "outDir": "lib", 9 | "typeRoots": [ 10 | "node_modules/@types" 11 | ] 12 | }, 13 | "files": [ 14 | "./typescript/example.ts" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /test/integration/postcheck/typescript/example.test.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2017 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import initApp from './example'; 19 | import { expect } from 'chai'; 20 | import { Bucket } from '@google-cloud/storage'; 21 | import { Firestore } from '@google-cloud/firestore'; 22 | 23 | import * as admin from 'firebase-admin'; 24 | 25 | // eslint-disable-next-line @typescript-eslint/no-var-requires 26 | const serviceAccount = require('../mock.key.json'); 27 | 28 | describe('Legacy API', () => { 29 | let app: admin.app.App; 30 | 31 | before(() => { 32 | app = initApp(serviceAccount, 'TestApp'); 33 | }); 34 | 35 | after(() => { 36 | return app.delete(); 37 | }); 38 | 39 | it('Should return an initialized App', () => { 40 | expect(app.name).to.equal('TestApp'); 41 | }); 42 | 43 | it('Should return an Auth client', () => { 44 | const client = admin.auth(app); 45 | expect(client).to.be.instanceOf((admin.auth as any).Auth); 46 | }); 47 | 48 | it('Should return a Messaging client', () => { 49 | const client = admin.messaging(app); 50 | expect(client).to.be.instanceOf((admin.messaging as any).Messaging); 51 | }); 52 | 53 | it('Should return a ProjectManagement client', () => { 54 | const client = admin.projectManagement(app); 55 | expect(client).to.be.instanceOf((admin.projectManagement as any).ProjectManagement); 56 | }); 57 | 58 | it('Should return a SecurityRules client', () => { 59 | const client = admin.securityRules(app); 60 | expect(client).to.be.instanceOf((admin.securityRules as any).SecurityRules); 61 | }); 62 | 63 | it('Should return a Database client', () => { 64 | const db = admin.database(app); 65 | expect(db).to.be.instanceOf((admin.database as any).Database); 66 | }); 67 | 68 | it('Should return a Database client for URL', () => { 69 | const db = app.database('https://other-mock.firebaseio.com'); 70 | expect(db).to.be.instanceOf((admin.database as any).Database); 71 | }); 72 | 73 | it('Should return a Database ServerValue', () => { 74 | const serverValue = admin.database.ServerValue; 75 | expect(serverValue).to.not.be.null; 76 | }); 77 | 78 | it('Should return a Cloud Storage client', () => { 79 | const storage: admin.storage.Storage = app.storage(); 80 | const bucket: Bucket = storage.bucket('TestBucket'); 81 | expect(bucket.name).to.equal('TestBucket'); 82 | }); 83 | 84 | it('Should return a Firestore client from the app', () => { 85 | const firestore: Firestore = app.firestore(); 86 | expect(firestore).to.be.instanceOf(admin.firestore.Firestore); 87 | }); 88 | 89 | it('Should return a Firestore client', () => { 90 | const firestore: Firestore = admin.firestore(app); 91 | expect(firestore).to.be.instanceOf(admin.firestore.Firestore); 92 | }); 93 | 94 | it('Should return a Firestore FieldValue', () => { 95 | const fieldValue = admin.firestore.FieldValue; 96 | expect(fieldValue).to.not.be.null; 97 | }); 98 | 99 | it('Should return a DocumentReference', () => { 100 | const ref: admin.firestore.DocumentReference = admin.firestore(app).collection('test').doc(); 101 | expect(ref).to.not.be.null; 102 | }); 103 | }); 104 | -------------------------------------------------------------------------------- /test/integration/postcheck/typescript/example.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2017 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import * as firebase from 'firebase-admin'; 19 | 20 | export function initApp(serviceAcct: any, name: string): firebase.app.App { 21 | return firebase.initializeApp({ 22 | credential: firebase.credential.cert(serviceAcct), 23 | databaseURL: 'https://mock.firebaseio.com' 24 | }, name); 25 | } 26 | 27 | export function addValueEventListener( 28 | // Check for type compilation 29 | db: firebase.database.Database, 30 | callback: (s: firebase.database.DataSnapshot) => any): void { 31 | const eventType: firebase.database.EventType = 'value'; 32 | db.ref().on(eventType, callback); 33 | } 34 | 35 | export default initApp; 36 | -------------------------------------------------------------------------------- /test/resources/firebase_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "databaseAuthVariableOverride": { "some#key": "some#val" }, 3 | "databaseURL": "https://hipster-chat.firebaseio.mock", 4 | "projectId": "hipster-chat-mock", 5 | "storageBucket": "hipster-chat.appspot.mock" 6 | } 7 | -------------------------------------------------------------------------------- /test/resources/firebase_config_bad.json: -------------------------------------------------------------------------------- 1 | baaaaad 2 | -------------------------------------------------------------------------------- /test/resources/firebase_config_bad_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "notAValidKeyValue": "The key value here is not valid.", 3 | "projectId": "hipster-chat-mock" 4 | } 5 | -------------------------------------------------------------------------------- /test/resources/firebase_config_empty.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firebase/firebase-admin-node/3c2cb9f0265ae836469198a7ff18d5454f18aefd/test/resources/firebase_config_empty.json -------------------------------------------------------------------------------- /test/resources/firebase_config_partial.json: -------------------------------------------------------------------------------- 1 | { 2 | "databaseURL": "https://hipster-chat.firebaseio.mock", 3 | "projectId": "hipster-chat-mock" 4 | } 5 | -------------------------------------------------------------------------------- /test/resources/invalid_model.tflite: -------------------------------------------------------------------------------- 1 | This is not a tflite file. 2 | -------------------------------------------------------------------------------- /test/resources/mock.impersonated_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "delegates": [], 3 | "service_account_impersonation_url": "", 4 | "source_credentials": { 5 | "client_id": "client_id", 6 | "client_secret": "client_secret", 7 | "refresh_token": "refresh_token", 8 | "type": "authorized_user" 9 | }, 10 | "type": "impersonated_service_account" 11 | } 12 | -------------------------------------------------------------------------------- /test/resources/mock.jwks.json: -------------------------------------------------------------------------------- 1 | { 2 | "keys": [ 3 | { 4 | "kty": "RSA", 5 | "e": "AQAB", 6 | "use": "sig", 7 | "kid": "FGQdnRlzAmKyKr6-Hg_kMQrBkj_H6i6ADnBQz4OI6BU", 8 | "alg": "RS256", 9 | "n": "rFYQyEdjj43mnpXwj-3WgAE01TSYe1-XFE9mxUDShysFwtVZOHFSMm6kl-B3Y_O8NcPt5osntLlH6KHvygExAE0tDmFYq8aKt7LQQF8rTv0rI6MP92ezyCEp4MPmAPFD_tY160XGrkqApuY2_-L8eEXdkRyH2H7lCYypFC0u3DIY25Vlq-ZDkxB2kGykGgb1zVazCDDViqV1p9hSltmm4el9AyF08FsMCpk_NvwKOY4pJ_sm99CDKxMhQBaT9lrIQt0B1VqTpEwlOoiFiyXASRXp9ZTeL4mrLPqSeozwPvspD81wbgecd62F640scKBr3ko73L8M8UWcwgd-moKCJw" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /test/resources/mock.key.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "service_account", 3 | "project_id": "project_id", 4 | "private_key_id": "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd", 5 | "private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAwJENcRev+eXZKvhhWLiV3Lz2MvO+naQRHo59g3vaNQnbgyduN/L4krlr\nJ5c6FiikXdtJNb/QrsAHSyJWCu8j3T9CruiwbidGAk2W0RuViTVspjHUTsIHExx9euWM0Uom\nGvYkoqXahdhPL/zViVSJt+Rt8bHLsMvpb8RquTIb9iKY3SMV2tCofNmyCSgVbghq/y7lKORt\nV/IRguWs6R22fbkb0r2MCYoNAbZ9dqnbRIFNZBC7itYtUoTEresRWcyFMh0zfAIJycWOJlVL\nDLqkY2SmIx8u7fuysCg1wcoSZoStuDq02nZEMw1dx8HGzE0hynpHlloRLByuIuOAfMCCYwID\nAQABAoIBADFtihu7TspAO0wSUTpqttzgC/nsIsNn95T2UjVLtyjiDNxPZLUrwq42tdCFur0x\nVW9Z+CK5x6DzXWvltlw8IeKKeF1ZEOBVaFzy+YFXKTz835SROcO1fgdjyrme7lRSShGlmKW/\nGKY+baUNquoDLw5qreXaE0SgMp0jt5ktyYuVxvhLDeV4omw2u6waoGkifsGm8lYivg5l3VR7\nw2IVOvYZTt4BuSYVwOM+qjwaS1vtL7gv0SUjrj85Ja6zERRdFiITDhZw6nsvacr9/+/aut9E\naL/koSSb62g5fntQMEwoT4hRnjPnAedmorM9Rhddh2TB3ZKTBbMN1tUk3fJxOuECgYEA+z6l\neSaAcZ3qvwpntcXSpwwJ0SSmzLTH2RJNf+Ld3eBHiSvLTG53dWB7lJtF4R1KcIwf+KGcOFJv\nsnepzcZBylRvT8RrAAkV0s9OiVm1lXZyaepbLg4GGFJBPi8A6VIAj7zYknToRApdW0s1x/XX\nChewfJDckqsevTMovdbg8YkCgYEAxDYX+3mfvv/opo6HNNY3SfVunM+4vVJL+n8gWZ2w9kz3\nQ9Ub9YbRmI7iQaiVkO5xNuoG1n9bM+3Mnm84aQ1YeNT01YqeyQsipP5Wi+um0PzYTaBw9RO+\n8Gh6992OwlJiRtFk5WjalNWOxY4MU0ImnJwIfKQlUODvLmcixm68NYsCgYEAuAqI3jkk55Vd\nKvotREsX5wP7gPePM+7NYiZ1HNQL4Ab1f/bTojZdTV8Sx6YCR0fUiqMqnE+OBvfkGGBtw22S\nLesx6sWf99Ov58+x4Q0U5dpxL0Lb7d2Z+2Dtp+Z4jXFjNeeI4ae/qG/LOR/b0pE0J5F415ap\n7Mpq5v89vepUtrkCgYAjMXytu4v+q1Ikhc4UmRPDrUUQ1WVSd+9u19yKlnFGTFnRjej86hiw\nH3jPxBhHra0a53EgiilmsBGSnWpl1WH4EmJz5vBCKUAmjgQiBrueIqv9iHiaTNdjsanUyaWw\njyxXfXl2eI80QPXh02+8g1H/pzESgjK7Rg1AqnkfVH9nrwKBgQDJVxKBPTw9pigYMVt9iHrR\niCl9zQVjRMbWiPOc0J56+/5FZYm/AOGl9rfhQ9vGxXZYZiOP5FsNkwt05Y1UoAAH4B4VQwbL\nqod71qOcI0ywgZiIR87CYw40gzRfjWnN+YEEW1qfyoNLilEwJB8iB/T+ZePHGmJ4MmQ/cTn9\nxpdLXA==\n-----END RSA PRIVATE KEY-----\n", 6 | "client_email": "foo@project_id.iam.gserviceaccount.com" 7 | } 8 | -------------------------------------------------------------------------------- /test/resources/model1.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firebase/firebase-admin-node/3c2cb9f0265ae836469198a7ff18d5454f18aefd/test/resources/model1.tflite -------------------------------------------------------------------------------- /test/resources/unparsable.key.json: -------------------------------------------------------------------------------- 1 | { 2 | foo: bar 3 | } 4 | -------------------------------------------------------------------------------- /test/unit/auth/index.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 'use strict'; 19 | 20 | import * as chai from 'chai'; 21 | import * as sinonChai from 'sinon-chai'; 22 | import * as chaiAsPromised from 'chai-as-promised'; 23 | 24 | import * as mocks from '../../resources/mocks'; 25 | import { App } from '../../../src/app/index'; 26 | import { getAuth, Auth } from '../../../src/auth/index'; 27 | 28 | chai.should(); 29 | chai.use(sinonChai); 30 | chai.use(chaiAsPromised); 31 | 32 | const expect = chai.expect; 33 | 34 | describe('Auth', () => { 35 | let mockApp: App; 36 | let mockCredentialApp: App; 37 | 38 | const noProjectIdError = 'Failed to determine project ID for Auth. Initialize the SDK ' 39 | + 'with service account credentials or set project ID as an app option. Alternatively set the ' 40 | + 'GOOGLE_CLOUD_PROJECT environment variable.'; 41 | 42 | beforeEach(() => { 43 | mockApp = mocks.app(); 44 | mockCredentialApp = mocks.mockCredentialApp(); 45 | }); 46 | 47 | describe('getAuth()', () => { 48 | it('should throw when default app is not available', () => { 49 | expect(() => { 50 | return getAuth(); 51 | }).to.throw('The default Firebase app does not exist.'); 52 | }); 53 | 54 | it('should reject given an invalid credential without project ID', () => { 55 | // Project ID not set in the environment. 56 | delete process.env.GOOGLE_CLOUD_PROJECT; 57 | delete process.env.GCLOUD_PROJECT; 58 | const auth = getAuth(mockCredentialApp); 59 | return auth.getUser('uid') 60 | .should.eventually.rejectedWith(noProjectIdError); 61 | }); 62 | 63 | it('should not throw given a valid app', () => { 64 | expect(() => { 65 | return getAuth(mockApp); 66 | }).not.to.throw(); 67 | }); 68 | 69 | it('should return the same instance for a given app instance', () => { 70 | const auth1: Auth = getAuth(mockApp); 71 | const auth2: Auth = getAuth(mockApp); 72 | expect(auth1).to.equal(auth2); 73 | }); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /test/unit/database/index.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 'use strict'; 19 | 20 | import * as chai from 'chai'; 21 | import * as sinonChai from 'sinon-chai'; 22 | import * as chaiAsPromised from 'chai-as-promised'; 23 | 24 | import * as mocks from '../../resources/mocks'; 25 | import { App } from '../../../src/app/index'; 26 | import { 27 | getDatabase, getDatabaseWithUrl, Database, ServerValue, enableLogging , 28 | } from '../../../src/database/index'; 29 | import { FirebaseApp } from '../../../src/app/firebase-app'; 30 | 31 | chai.should(); 32 | chai.use(sinonChai); 33 | chai.use(chaiAsPromised); 34 | 35 | const expect = chai.expect; 36 | 37 | describe('Database', () => { 38 | let mockApp: App; 39 | 40 | beforeEach(() => { 41 | mockApp = mocks.app(); 42 | }); 43 | 44 | afterEach(() => { 45 | return (mockApp as FirebaseApp).delete(); 46 | }); 47 | 48 | describe('getDatabase()', () => { 49 | it('should throw when default app is not available', () => { 50 | expect(() => { 51 | return getDatabase(); 52 | }).to.throw('The default Firebase app does not exist.'); 53 | }); 54 | 55 | it('should not throw given a valid app', () => { 56 | expect(() => { 57 | return getDatabase(mockApp); 58 | }).not.to.throw(); 59 | }); 60 | 61 | it('should return the same instance for a given app instance', () => { 62 | const db1: Database = getDatabase(mockApp); 63 | const db2: Database = getDatabase(mockApp); 64 | expect(db1).to.equal(db2); 65 | }); 66 | }); 67 | 68 | describe('getDatabaseWithUrl()', () => { 69 | it('should throw when default app is not available', () => { 70 | expect(() => { 71 | return getDatabaseWithUrl('https://test.firebaseio.com'); 72 | }).to.throw('The default Firebase app does not exist.'); 73 | }); 74 | 75 | it('should not throw given a valid app', () => { 76 | expect(() => { 77 | return getDatabaseWithUrl('https://test.firebaseio.com', mockApp); 78 | }).not.to.throw(); 79 | }); 80 | 81 | it('should return the same instance for a given app instance', () => { 82 | const db1: Database = getDatabaseWithUrl('https://test.firebaseio.com', mockApp); 83 | const db2: Database = getDatabaseWithUrl('https://test.firebaseio.com', mockApp); 84 | const db3: Database = getDatabaseWithUrl('https://other.firebaseio.com', mockApp); 85 | expect(db1).to.equal(db2); 86 | expect(db1).to.not.equal(db3); 87 | }); 88 | }); 89 | 90 | it('should expose ServerValue sentinel', () => { 91 | expect(() => ServerValue.increment(1)).to.not.throw(); 92 | }); 93 | 94 | it('should expose enableLogging global function', () => { 95 | expect(() => { 96 | enableLogging(console.log); 97 | enableLogging(false); 98 | }).to.not.throw(); 99 | }); 100 | }); 101 | -------------------------------------------------------------------------------- /test/unit/extensions/extensions-api-client-internal.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2022 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { expect } from 'chai'; 19 | import * as sinon from 'sinon'; 20 | 21 | import * as utils from '../utils'; 22 | import * as mocks from '../../resources/mocks'; 23 | import { FirebaseApp } from '../../../src/app/firebase-app'; 24 | import { ExtensionsApiClient, FirebaseExtensionsError } from '../../../src/extensions/extensions-api-client-internal'; 25 | import { HttpClient } from '../../../src/utils/api-request'; 26 | import { SettableProcessingState } from '../../../src/extensions/extensions-api'; 27 | import { getMetricsHeader, getSdkVersion } from '../../../src/utils'; 28 | 29 | const testProjectId = 'test-project'; 30 | const testInstanceId = 'test-instance'; 31 | 32 | describe('Extension API client', () => { 33 | let app: FirebaseApp; 34 | let apiClient: ExtensionsApiClient; 35 | 36 | let httpClientStub: sinon.SinonStub; 37 | const mockOptions = { 38 | credential: new mocks.MockCredential(), 39 | projectId: 'test-project', 40 | serviceAccountId: 'service-acct@email.com' 41 | }; 42 | 43 | const EXPECTED_HEADERS = { 44 | 'Authorization': 'Bearer mock-token', 45 | 'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`, 46 | 'X-Goog-Api-Client': getMetricsHeader(), 47 | } 48 | 49 | before(() => { 50 | app = mocks.appWithOptions(mockOptions); 51 | apiClient = new ExtensionsApiClient(app); 52 | }); 53 | 54 | after(() => { 55 | return app.delete(); 56 | }); 57 | 58 | beforeEach(() => { 59 | httpClientStub = sinon.stub(HttpClient.prototype, 'send'); 60 | }); 61 | 62 | afterEach(() => { 63 | httpClientStub.restore(); 64 | }); 65 | 66 | describe('Constructor', () => { 67 | it('should reject when the app is null', () => { 68 | expect(() => new ExtensionsApiClient(null as unknown as FirebaseApp)) 69 | .to.throw('First argument passed to getExtensions() must be a valid Firebase app instance.'); 70 | }); 71 | }); 72 | 73 | describe('updateRuntimeData', () => { 74 | it('should updateRuntimeData', async () => { 75 | const testRuntimeData = { 76 | processingState: { 77 | state: 'PROCESSING_COMPLETE' as SettableProcessingState, 78 | detailMessage: 'done processing', 79 | }, 80 | } 81 | const url = 'https://firebaseextensions.googleapis.com/' + 82 | 'v1beta/projects/test-project/instances/test-instance/runtimeData'; 83 | httpClientStub = httpClientStub.resolves(utils.responseFrom(testRuntimeData, 200)); 84 | return apiClient.updateRuntimeData(testProjectId, testInstanceId, testRuntimeData) 85 | .then((runtimeData) => { 86 | expect(runtimeData).to.deep.equal(testRuntimeData) 87 | expect(httpClientStub).to.have.been.calledOnce.and.calledWith({ 88 | method: 'PATCH', 89 | url: url, 90 | headers: EXPECTED_HEADERS, 91 | data: testRuntimeData 92 | }) 93 | }) 94 | }); 95 | 96 | it('should convert errors in FirebaseErrors', async () => { 97 | httpClientStub.rejects(utils.errorFrom('Something went wrong', 404)); 98 | await expect(apiClient.updateRuntimeData(testProjectId, testInstanceId, {})) 99 | .to.eventually.be.rejectedWith(FirebaseExtensionsError); 100 | }); 101 | }); 102 | }); 103 | -------------------------------------------------------------------------------- /test/unit/functions/index.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 'use strict'; 19 | 20 | import * as chai from 'chai'; 21 | import * as sinonChai from 'sinon-chai'; 22 | import * as chaiAsPromised from 'chai-as-promised'; 23 | 24 | import * as mocks from '../../resources/mocks'; 25 | import { App } from '../../../src/app/index'; 26 | import { getFunctions, Functions } from '../../../src/functions/index'; 27 | 28 | chai.should(); 29 | chai.use(sinonChai); 30 | chai.use(chaiAsPromised); 31 | 32 | const expect = chai.expect; 33 | 34 | describe('Functions', () => { 35 | let mockApp: App; 36 | let mockCredentialApp: App; 37 | 38 | const noProjectIdError = 'Failed to determine project ID. Initialize the SDK ' 39 | + 'with service account credentials or set project ID as an app option. Alternatively, set the ' 40 | + 'GOOGLE_CLOUD_PROJECT environment variable.'; 41 | 42 | beforeEach(() => { 43 | mockApp = mocks.app(); 44 | mockCredentialApp = mocks.mockCredentialApp(); 45 | }); 46 | 47 | describe('getFunctions()', () => { 48 | it('should throw when default app is not available', () => { 49 | expect(() => { 50 | return getFunctions(); 51 | }).to.throw('The default Firebase app does not exist.'); 52 | }); 53 | 54 | it('should reject given an invalid credential without project ID', () => { 55 | // Project ID not set in the environment. 56 | delete process.env.GOOGLE_CLOUD_PROJECT; 57 | delete process.env.GCLOUD_PROJECT; 58 | const functions = getFunctions(mockCredentialApp); 59 | const factorizedQueue = functions.taskQueue('task-name'); 60 | return factorizedQueue.enqueue({}) 61 | .should.eventually.rejectedWith(noProjectIdError); 62 | }); 63 | 64 | it('should not throw given a valid app', () => { 65 | expect(() => { 66 | return getFunctions(mockApp); 67 | }).not.to.throw(); 68 | }); 69 | 70 | it('should return the same instance for a given app instance', () => { 71 | const fn1: Functions = getFunctions(mockApp); 72 | const fn2: Functions = getFunctions(mockApp); 73 | expect(fn1).to.equal(fn2); 74 | }); 75 | }); 76 | }); 77 | -------------------------------------------------------------------------------- /test/unit/instance-id/index.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 'use strict'; 19 | 20 | import * as chai from 'chai'; 21 | import * as sinonChai from 'sinon-chai'; 22 | import * as chaiAsPromised from 'chai-as-promised'; 23 | 24 | import * as mocks from '../../resources/mocks'; 25 | import { App } from '../../../src/app/index'; 26 | import { getInstanceId, InstanceId } from '../../../src/instance-id/index'; 27 | 28 | chai.should(); 29 | chai.use(sinonChai); 30 | chai.use(chaiAsPromised); 31 | 32 | const expect = chai.expect; 33 | 34 | describe('InstanceId', () => { 35 | let mockApp: App; 36 | let mockCredentialApp: App; 37 | 38 | const noProjectIdError = 'Failed to determine project ID for Installations. Initialize the SDK ' 39 | + 'with service account credentials or set project ID as an app option. Alternatively set the ' 40 | + 'GOOGLE_CLOUD_PROJECT environment variable.'; 41 | 42 | beforeEach(() => { 43 | mockApp = mocks.app(); 44 | mockCredentialApp = mocks.mockCredentialApp(); 45 | }); 46 | 47 | describe('getInstanceId()', () => { 48 | it('should throw when default app is not available', () => { 49 | expect(() => { 50 | return getInstanceId(); 51 | }).to.throw('The default Firebase app does not exist.'); 52 | }); 53 | 54 | it('should reject given an invalid credential without project ID', () => { 55 | // Project ID not set in the environment. 56 | delete process.env.GOOGLE_CLOUD_PROJECT; 57 | delete process.env.GCLOUD_PROJECT; 58 | const iid = getInstanceId(mockCredentialApp); 59 | return iid.deleteInstanceId('iid') 60 | .should.eventually.rejectedWith(noProjectIdError); 61 | }); 62 | 63 | it('should not throw given a valid app', () => { 64 | expect(() => { 65 | return getInstanceId(mockApp); 66 | }).not.to.throw(); 67 | }); 68 | 69 | it('should return the same instance for a given app instance', () => { 70 | const iid1: InstanceId = getInstanceId(mockApp); 71 | const iid2: InstanceId = getInstanceId(mockApp); 72 | expect(iid1).to.equal(iid2); 73 | }); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /test/unit/machine-learning/index.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 'use strict'; 19 | 20 | import * as chai from 'chai'; 21 | import * as sinonChai from 'sinon-chai'; 22 | import * as chaiAsPromised from 'chai-as-promised'; 23 | 24 | import * as mocks from '../../resources/mocks'; 25 | import { App } from '../../../src/app/index'; 26 | import { getMachineLearning, MachineLearning } from '../../../src/machine-learning/index'; 27 | 28 | chai.should(); 29 | chai.use(sinonChai); 30 | chai.use(chaiAsPromised); 31 | 32 | const expect = chai.expect; 33 | 34 | describe('MachineLearning', () => { 35 | let mockApp: App; 36 | let mockCredentialApp: App; 37 | 38 | const noProjectIdError = 'Failed to determine project ID. Initialize the SDK ' 39 | + 'with service account credentials, or set project ID as an app option. Alternatively, set the ' 40 | + 'GOOGLE_CLOUD_PROJECT environment variable.'; 41 | 42 | beforeEach(() => { 43 | mockApp = mocks.app(); 44 | mockCredentialApp = mocks.mockCredentialApp(); 45 | }); 46 | 47 | describe('getMachineLearning()', () => { 48 | it('should throw when default app is not available', () => { 49 | expect(() => { 50 | return getMachineLearning(); 51 | }).to.throw('The default Firebase app does not exist.'); 52 | }); 53 | 54 | it('should reject given an invalid credential without project ID', () => { 55 | // Project ID not set in the environment. 56 | delete process.env.GOOGLE_CLOUD_PROJECT; 57 | delete process.env.GCLOUD_PROJECT; 58 | const client = getMachineLearning(mockCredentialApp); 59 | return client.getModel('test') 60 | .should.eventually.rejectedWith(noProjectIdError); 61 | }); 62 | 63 | it('should not throw given a valid app', () => { 64 | expect(() => { 65 | return getMachineLearning(mockApp); 66 | }).not.to.throw(); 67 | }); 68 | 69 | it('should return the same instance for a given app instance', () => { 70 | const client1: MachineLearning = getMachineLearning(mockApp); 71 | const client2: MachineLearning = getMachineLearning(mockApp); 72 | expect(client1).to.equal(client2); 73 | }); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /test/unit/messaging/index.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 'use strict'; 19 | 20 | import * as chai from 'chai'; 21 | import * as sinonChai from 'sinon-chai'; 22 | import * as chaiAsPromised from 'chai-as-promised'; 23 | 24 | import * as mocks from '../../resources/mocks'; 25 | import { App } from '../../../src/app/index'; 26 | import { getMessaging, Messaging } from '../../../src/messaging/index'; 27 | 28 | chai.should(); 29 | chai.use(sinonChai); 30 | chai.use(chaiAsPromised); 31 | 32 | const expect = chai.expect; 33 | 34 | describe('Messaging', () => { 35 | let mockApp: App; 36 | let mockCredentialApp: App; 37 | 38 | const noProjectIdError = 'Failed to determine project ID for Messaging. Initialize the SDK ' 39 | + 'with service account credentials or set project ID as an app option. Alternatively set the ' 40 | + 'GOOGLE_CLOUD_PROJECT environment variable.'; 41 | 42 | beforeEach(() => { 43 | mockApp = mocks.app(); 44 | mockCredentialApp = mocks.mockCredentialApp(); 45 | }); 46 | 47 | describe('getMessaging()', () => { 48 | it('should throw when default app is not available', () => { 49 | expect(() => { 50 | return getMessaging(); 51 | }).to.throw('The default Firebase app does not exist.'); 52 | }); 53 | 54 | it('should reject given an invalid credential without project ID', () => { 55 | // Project ID not set in the environment. 56 | delete process.env.GOOGLE_CLOUD_PROJECT; 57 | delete process.env.GCLOUD_PROJECT; 58 | const messaging = getMessaging(mockCredentialApp); 59 | return messaging.send({ topic: 'test' }) 60 | .should.eventually.rejectedWith(noProjectIdError); 61 | }); 62 | 63 | it('should not throw given a valid app', () => { 64 | expect(() => { 65 | return getMessaging(mockApp); 66 | }).not.to.throw(); 67 | }); 68 | 69 | it('should return the same instance for a given app instance', () => { 70 | const fcm1: Messaging = getMessaging(mockApp); 71 | const fcm2: Messaging = getMessaging(mockApp); 72 | expect(fcm1).to.equal(fcm2); 73 | }); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /test/unit/project-management/index.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 'use strict'; 19 | 20 | import * as chai from 'chai'; 21 | import * as sinonChai from 'sinon-chai'; 22 | import * as chaiAsPromised from 'chai-as-promised'; 23 | 24 | import * as mocks from '../../resources/mocks'; 25 | import { App } from '../../../src/app/index'; 26 | import { getProjectManagement, ProjectManagement } from '../../../src/project-management/index'; 27 | 28 | chai.should(); 29 | chai.use(sinonChai); 30 | chai.use(chaiAsPromised); 31 | 32 | const expect = chai.expect; 33 | 34 | describe('ProjectManagement', () => { 35 | let mockApp: App; 36 | let mockCredentialApp: App; 37 | 38 | const noProjectIdError = 'Failed to determine project ID. Initialize the SDK ' 39 | + 'with service account credentials, or set project ID as an app option. Alternatively, set the ' 40 | + 'GOOGLE_CLOUD_PROJECT environment variable.'; 41 | 42 | beforeEach(() => { 43 | mockApp = mocks.app(); 44 | mockCredentialApp = mocks.mockCredentialApp(); 45 | }); 46 | 47 | describe('getProjectManagement()', () => { 48 | it('should throw when default app is not available', () => { 49 | expect(() => { 50 | return getProjectManagement(); 51 | }).to.throw('The default Firebase app does not exist.'); 52 | }); 53 | 54 | it('should reject given an invalid credential without project ID', () => { 55 | // Project ID not set in the environment. 56 | delete process.env.GOOGLE_CLOUD_PROJECT; 57 | delete process.env.GCLOUD_PROJECT; 58 | const client = getProjectManagement(mockCredentialApp); 59 | return client.listAndroidApps() 60 | .should.eventually.rejectedWith(noProjectIdError); 61 | }); 62 | 63 | it('should not throw given a valid app', () => { 64 | expect(() => { 65 | return getProjectManagement(mockApp); 66 | }).not.to.throw(); 67 | }); 68 | 69 | it('should return the same instance for a given app instance', () => { 70 | const client1: ProjectManagement = getProjectManagement(mockApp); 71 | const client2: ProjectManagement = getProjectManagement(mockApp); 72 | expect(client1).to.equal(client2); 73 | }); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /test/unit/remote-config/index.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 'use strict'; 19 | 20 | import * as chai from 'chai'; 21 | import * as sinonChai from 'sinon-chai'; 22 | import * as chaiAsPromised from 'chai-as-promised'; 23 | 24 | import * as mocks from '../../resources/mocks'; 25 | import { App } from '../../../src/app/index'; 26 | import { getRemoteConfig, RemoteConfig } from '../../../src/remote-config/index'; 27 | 28 | chai.should(); 29 | chai.use(sinonChai); 30 | chai.use(chaiAsPromised); 31 | 32 | const expect = chai.expect; 33 | 34 | describe('RemoteConfig', () => { 35 | let mockApp: App; 36 | let mockCredentialApp: App; 37 | 38 | const noProjectIdError = 'Failed to determine project ID. Initialize the SDK ' 39 | + 'with service account credentials, or set project ID as an app option. Alternatively, set the ' 40 | + 'GOOGLE_CLOUD_PROJECT environment variable.'; 41 | 42 | beforeEach(() => { 43 | mockApp = mocks.app(); 44 | mockCredentialApp = mocks.mockCredentialApp(); 45 | }); 46 | 47 | describe('getRemoteConfig()', () => { 48 | it('should throw when default app is not available', () => { 49 | expect(() => { 50 | return getRemoteConfig(); 51 | }).to.throw('The default Firebase app does not exist.'); 52 | }); 53 | 54 | it('should reject given an invalid credential without project ID', () => { 55 | // Project ID not set in the environment. 56 | delete process.env.GOOGLE_CLOUD_PROJECT; 57 | delete process.env.GCLOUD_PROJECT; 58 | const remoteConfig = getRemoteConfig(mockCredentialApp); 59 | return remoteConfig.getTemplate() 60 | .should.eventually.rejectedWith(noProjectIdError); 61 | }); 62 | 63 | it('should not throw given a valid app', () => { 64 | expect(() => { 65 | return getRemoteConfig(mockApp); 66 | }).not.to.throw(); 67 | }); 68 | 69 | it('should return the same instance for a given app instance', () => { 70 | const rc1: RemoteConfig = getRemoteConfig(mockApp); 71 | const rc2: RemoteConfig = getRemoteConfig(mockApp); 72 | expect(rc1).to.equal(rc2); 73 | }); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /test/unit/remote-config/internal/value-impl.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2024 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 'use strict'; 18 | 19 | import * as chai from 'chai'; 20 | import { ValueImpl } from '../../../../src/remote-config/internal/value-impl'; 21 | 22 | const expect = chai.expect; 23 | 24 | describe('ValueImpl', () => { 25 | describe('getSource', () => { 26 | it('returns the source string', () => { 27 | const value = new ValueImpl('static'); 28 | expect(value.getSource()).to.equal('static'); 29 | }); 30 | }); 31 | 32 | describe('asString', () => { 33 | it('returns string value as a string', () => { 34 | const value = new ValueImpl('default', 'shiba'); 35 | expect(value.asString()).to.equal('shiba'); 36 | }); 37 | 38 | it('defaults to empty string', () => { 39 | const value = new ValueImpl('static'); 40 | expect(value.asString()).to.equal(ValueImpl.DEFAULT_VALUE_FOR_STRING); 41 | }); 42 | }); 43 | 44 | describe('asNumber', () => { 45 | it('returns numeric value as a number', () => { 46 | const value = new ValueImpl('default', '123'); 47 | expect(value.asNumber()).to.equal(123); 48 | }); 49 | 50 | it('defaults to zero for non-numeric value', () => { 51 | const value = new ValueImpl('default', 'Hi, NaN!'); 52 | expect(value.asNumber()).to.equal(ValueImpl.DEFAULT_VALUE_FOR_NUMBER); 53 | }); 54 | }); 55 | 56 | describe('asBoolean', () => { 57 | it("returns true for any value in RC's list of truthy values", () => { 58 | for (const truthyValue of ValueImpl.BOOLEAN_TRUTHY_VALUES) { 59 | const value = new ValueImpl('default', truthyValue); 60 | expect(value.asBoolean()).to.be.true; 61 | } 62 | }); 63 | 64 | it('is case-insensitive', () => { 65 | const value = new ValueImpl('default', 'TRUE'); 66 | expect(value.asBoolean()).to.be.true; 67 | }); 68 | 69 | it("returns false for any value not in RC's list of truthy values", () => { 70 | const value = new ValueImpl('default', "I'm falsy"); 71 | expect(value.asBoolean()).to.be.false; 72 | }); 73 | }); 74 | }); 75 | 76 | -------------------------------------------------------------------------------- /test/unit/security-rules/index.spec.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2021 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 'use strict'; 19 | 20 | import * as chai from 'chai'; 21 | import * as sinonChai from 'sinon-chai'; 22 | import * as chaiAsPromised from 'chai-as-promised'; 23 | 24 | import * as mocks from '../../resources/mocks'; 25 | import { App } from '../../../src/app/index'; 26 | import { getSecurityRules, SecurityRules } from '../../../src/security-rules/index'; 27 | 28 | chai.should(); 29 | chai.use(sinonChai); 30 | chai.use(chaiAsPromised); 31 | 32 | const expect = chai.expect; 33 | 34 | describe('SecurityRules', () => { 35 | let mockApp: App; 36 | let mockCredentialApp: App; 37 | 38 | const noProjectIdError = 'Failed to determine project ID. Initialize the SDK ' 39 | + 'with service account credentials, or set project ID as an app option. Alternatively, set the ' 40 | + 'GOOGLE_CLOUD_PROJECT environment variable.'; 41 | 42 | beforeEach(() => { 43 | mockApp = mocks.app(); 44 | mockCredentialApp = mocks.mockCredentialApp(); 45 | }); 46 | 47 | describe('getSecurityRules()', () => { 48 | it('should throw when default app is not available', () => { 49 | expect(() => { 50 | return getSecurityRules(); 51 | }).to.throw('The default Firebase app does not exist.'); 52 | }); 53 | 54 | it('should reject given an invalid credential without project ID', () => { 55 | // Project ID not set in the environment. 56 | delete process.env.GOOGLE_CLOUD_PROJECT; 57 | delete process.env.GCLOUD_PROJECT; 58 | const rules = getSecurityRules(mockCredentialApp); 59 | return rules.getFirestoreRuleset() 60 | .should.eventually.rejectedWith(noProjectIdError); 61 | }); 62 | 63 | it('should not throw given a valid app', () => { 64 | expect(() => { 65 | return getSecurityRules(mockApp); 66 | }).not.to.throw(); 67 | }); 68 | 69 | it('should return the same instance for a given app instance', () => { 70 | const rules1: SecurityRules = getSecurityRules(mockApp); 71 | const rules2: SecurityRules = getSecurityRules(mockApp); 72 | expect(rules1).to.equal(rules2); 73 | }); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /test/unit/utils.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license 3 | * Copyright 2017 Google Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import * as _ from 'lodash'; 19 | import * as sinon from 'sinon'; 20 | import * as mocks from '../resources/mocks'; 21 | import { AppOptions } from '../../src/firebase-namespace-api'; 22 | import { FirebaseApp, FirebaseAppInternals, FirebaseAccessToken } from '../../src/app/firebase-app'; 23 | import { RequestResponseError, RequestResponse } from '../../src/utils/api-request'; 24 | 25 | /** 26 | * Returns a new `FirebaseApp` instance with the provided options. 27 | * 28 | * @param options The options for the `FirebaseApp` instance to create. 29 | * @return A new `FirebaseApp` instance with the provided options. 30 | */ 31 | export function createAppWithOptions(options: object): FirebaseApp { 32 | return new FirebaseApp(options as AppOptions, mocks.appName); 33 | } 34 | 35 | 36 | /** @return {string} A randomly generated access token string. */ 37 | export function generateRandomAccessToken(): string { 38 | return 'access_token_' + _.random(999999999); 39 | } 40 | 41 | /** 42 | * Creates a stub for retrieving an access token from a `FirebaseApp`. All services should use this 43 | * method for stubbing the OAuth2 flow during unit tests. 44 | * 45 | * @param {string} accessToken The access token string to return. 46 | * @param {FirebaseApp} app The app instance to stub. If not specified, the stub will affect all apps. 47 | * @return {sinon.SinonStub} A Sinon stub. 48 | */ 49 | export function stubGetAccessToken(accessToken?: string, app?: FirebaseApp): sinon.SinonStub { 50 | if (typeof accessToken === 'undefined') { 51 | accessToken = generateRandomAccessToken(); 52 | } 53 | const result: FirebaseAccessToken = { 54 | accessToken, 55 | expirationTime: Date.now() + 3600, 56 | }; 57 | if (app) { 58 | return sinon.stub(app.INTERNAL, 'getToken').resolves(result); 59 | } else { 60 | return sinon.stub(FirebaseAppInternals.prototype, 'getToken').resolves(result); 61 | } 62 | } 63 | 64 | /** 65 | * Creates a mock HTTP response from the given data and parameters. 66 | * 67 | * @param {object | string} data Data to be included in the response body. 68 | * @param {number=} status HTTP status code (defaults to 200). 69 | * @param {*=} headers HTTP headers to be included in the ersponse. 70 | * @return {HttpResponse} An HTTP response object. 71 | */ 72 | export function responseFrom(data: object | string, status = 200, headers: any = {}): RequestResponse { 73 | let responseData: any; 74 | let responseText: string; 75 | if (typeof data === 'object') { 76 | responseData = data; 77 | responseText = JSON.stringify(data); 78 | } else { 79 | try { 80 | responseData = JSON.parse(data); 81 | } catch (error) { 82 | responseData = null; 83 | } 84 | responseText = data as string; 85 | } 86 | return { 87 | status, 88 | headers, 89 | data: responseData, 90 | text: responseText, 91 | isJson: () => responseData != null, 92 | }; 93 | } 94 | 95 | export function errorFrom(data: any, status = 500): RequestResponseError { 96 | return new RequestResponseError(responseFrom(data, status)); 97 | } 98 | -------------------------------------------------------------------------------- /third_party/database-license.txt: -------------------------------------------------------------------------------- 1 | /*! typedarray.js 2 | Copyright (c) 2010, Linden Research, Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. */ 21 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es2020", 5 | "declaration": true, 6 | "sourceMap": true, 7 | "noImplicitAny": true, 8 | "noUnusedLocals": true, 9 | // TODO(rsgowman): enable `"strict": true,` and remove explicit setting of: noImplicitAny, noImplicitThis, alwaysStrict, strictBindCallApply, strictNullChecks, strictFunctionTypes, strictPropertyInitialization. 10 | "noImplicitThis": true, 11 | "alwaysStrict": true, 12 | "strictBindCallApply": true, 13 | "strictNullChecks": true, 14 | "strictFunctionTypes": true, 15 | //"strictPropertyInitialization": true, 16 | "lib": ["es2020"], 17 | "outDir": "lib", 18 | "stripInternal": true, 19 | "rootDir": "." 20 | }, 21 | "files": [ 22 | "src/index.ts" 23 | ] 24 | } 25 | --------------------------------------------------------------------------------