firebase-admin 9.12.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/README.md +7 -3
  2. package/lib/app/core.d.ts +188 -0
  3. package/lib/app/core.js +19 -0
  4. package/lib/app/credential-factory.d.ts +123 -0
  5. package/lib/app/credential-factory.js +150 -0
  6. package/lib/app/credential-internal.d.ts +90 -0
  7. package/lib/{credential → app}/credential-internal.js +15 -13
  8. package/lib/app/credential.d.ts +45 -0
  9. package/lib/app/credential.js +19 -0
  10. package/lib/app/firebase-app.d.ts +51 -0
  11. package/lib/{firebase-app.js → app/firebase-app.js} +26 -156
  12. package/lib/app/firebase-namespace.d.ts +163 -0
  13. package/lib/{firebase-namespace.js → app/firebase-namespace.js} +99 -111
  14. package/lib/app/index.d.ts +27 -0
  15. package/lib/app/index.js +31 -0
  16. package/lib/app/lifecycle.d.ts +60 -0
  17. package/lib/app/lifecycle.js +165 -0
  18. package/lib/app-check/app-check-api-client-internal.d.ts +32 -0
  19. package/lib/app-check/app-check-api-client-internal.js +10 -10
  20. package/lib/app-check/app-check-api.d.ts +95 -0
  21. package/lib/app-check/app-check-api.js +19 -0
  22. package/lib/app-check/app-check-namespace.d.ts +65 -0
  23. package/lib/app-check/app-check-namespace.js +18 -0
  24. package/lib/app-check/app-check.d.ts +49 -0
  25. package/lib/app-check/app-check.js +13 -10
  26. package/lib/app-check/index.d.ts +19 -126
  27. package/lib/app-check/index.js +45 -1
  28. package/lib/app-check/token-generator.d.ts +25 -0
  29. package/lib/app-check/token-generator.js +9 -9
  30. package/lib/app-check/token-verifier.d.ts +17 -0
  31. package/lib/app-check/token-verifier.js +6 -6
  32. package/lib/auth/action-code-settings-builder.d.ts +87 -0
  33. package/lib/auth/action-code-settings-builder.js +4 -2
  34. package/lib/auth/auth-api-request.d.ts +174 -0
  35. package/lib/auth/auth-api-request.js +197 -124
  36. package/lib/auth/auth-config.d.ts +575 -0
  37. package/lib/auth/auth-config.js +43 -34
  38. package/lib/auth/auth-namespace.d.ts +255 -0
  39. package/lib/auth/auth-namespace.js +18 -0
  40. package/lib/auth/auth.d.ts +40 -0
  41. package/lib/auth/auth.js +12 -772
  42. package/lib/auth/base-auth.d.ts +613 -0
  43. package/lib/auth/base-auth.js +951 -0
  44. package/lib/auth/identifier.d.ts +57 -0
  45. package/lib/auth/identifier.js +1 -1
  46. package/lib/auth/index.d.ts +25 -1897
  47. package/lib/auth/index.js +54 -1
  48. package/lib/auth/tenant-manager.d.ts +146 -0
  49. package/lib/auth/tenant-manager.js +151 -39
  50. package/lib/auth/tenant.d.ts +130 -0
  51. package/lib/auth/tenant.js +62 -16
  52. package/lib/auth/token-generator.d.ts +44 -0
  53. package/lib/auth/token-generator.js +11 -9
  54. package/lib/auth/token-verifier.d.ts +150 -0
  55. package/lib/auth/token-verifier.js +27 -15
  56. package/lib/auth/user-import-builder.d.ts +322 -0
  57. package/lib/auth/user-import-builder.js +9 -9
  58. package/lib/auth/user-record.d.ts +265 -0
  59. package/lib/auth/user-record.js +80 -45
  60. package/lib/credential/index.d.ts +24 -66
  61. package/lib/credential/index.js +101 -1
  62. package/lib/database/database-namespace.d.ts +95 -0
  63. package/lib/database/database-namespace.js +23 -0
  64. package/lib/database/database.d.ts +66 -0
  65. package/lib/database/{database-internal.js → database.js} +16 -9
  66. package/lib/database/index.d.ts +55 -54
  67. package/lib/database/index.js +84 -13
  68. package/lib/{firebase-namespace.d.ts → default-namespace.d.ts} +7 -14
  69. package/lib/default-namespace.js +4 -5
  70. package/lib/esm/app/index.js +10 -0
  71. package/lib/esm/app-check/index.js +4 -0
  72. package/lib/esm/auth/index.js +14 -0
  73. package/lib/esm/database/index.js +6 -0
  74. package/lib/esm/firestore/index.js +23 -0
  75. package/lib/esm/installations/index.js +4 -0
  76. package/lib/esm/instance-id/index.js +4 -0
  77. package/lib/esm/machine-learning/index.js +5 -0
  78. package/lib/esm/messaging/index.js +4 -0
  79. package/lib/esm/package.json +1 -0
  80. package/lib/esm/project-management/index.js +8 -0
  81. package/lib/esm/remote-config/index.js +4 -0
  82. package/lib/esm/security-rules/index.js +6 -0
  83. package/lib/esm/storage/index.js +4 -0
  84. package/lib/firebase-namespace-api.d.ts +34 -186
  85. package/lib/firebase-namespace-api.js +37 -2
  86. package/lib/firestore/firestore-internal.d.ts +32 -0
  87. package/lib/firestore/firestore-internal.js +3 -3
  88. package/lib/firestore/firestore-namespace.d.ts +50 -0
  89. package/lib/firestore/firestore-namespace.js +47 -0
  90. package/lib/firestore/index.d.ts +37 -35
  91. package/lib/firestore/index.js +61 -30
  92. package/lib/index.d.ts +2 -2
  93. package/lib/index.js +1 -1
  94. package/lib/installations/index.d.ts +34 -63
  95. package/lib/installations/index.js +45 -1
  96. package/lib/installations/installations-namespace.d.ts +55 -0
  97. package/lib/installations/installations-namespace.js +18 -0
  98. package/lib/installations/installations-request-handler.d.ts +43 -0
  99. package/lib/installations/installations-request-handler.js +4 -4
  100. package/lib/installations/installations.d.ts +38 -0
  101. package/lib/installations/installations.js +6 -5
  102. package/lib/instance-id/index.d.ts +23 -45
  103. package/lib/instance-id/index.js +54 -1
  104. package/lib/instance-id/instance-id-namespace.d.ts +38 -0
  105. package/lib/instance-id/instance-id-namespace.js +3 -0
  106. package/lib/instance-id/instance-id.d.ts +47 -0
  107. package/lib/instance-id/instance-id.js +14 -19
  108. package/lib/machine-learning/index.d.ts +19 -216
  109. package/lib/machine-learning/index.js +46 -1
  110. package/lib/machine-learning/machine-learning-api-client.d.ts +102 -0
  111. package/lib/machine-learning/machine-learning-api-client.js +6 -6
  112. package/lib/machine-learning/machine-learning-namespace.d.ts +85 -0
  113. package/lib/machine-learning/machine-learning-namespace.js +18 -0
  114. package/lib/machine-learning/machine-learning-utils.d.ts +22 -0
  115. package/lib/machine-learning/machine-learning-utils.js +1 -1
  116. package/lib/machine-learning/machine-learning.d.ts +181 -0
  117. package/lib/machine-learning/machine-learning.js +72 -37
  118. package/lib/messaging/batch-request-internal.d.ts +55 -0
  119. package/lib/messaging/batch-request-internal.js +9 -9
  120. package/lib/messaging/index.d.ts +18 -1140
  121. package/lib/messaging/index.js +45 -1
  122. package/lib/messaging/messaging-api-request-internal.d.ts +50 -0
  123. package/lib/messaging/messaging-api-request-internal.js +8 -8
  124. package/lib/messaging/messaging-api.d.ts +980 -0
  125. package/lib/messaging/messaging-api.js +19 -0
  126. package/lib/messaging/messaging-errors-internal.d.ts +31 -0
  127. package/lib/messaging/messaging-errors-internal.js +7 -7
  128. package/lib/messaging/messaging-internal.d.ts +27 -0
  129. package/lib/messaging/messaging-internal.js +2 -2
  130. package/lib/messaging/messaging-namespace.d.ts +181 -0
  131. package/lib/messaging/messaging-namespace.js +18 -0
  132. package/lib/messaging/messaging.d.ts +269 -0
  133. package/lib/messaging/messaging.js +83 -91
  134. package/lib/project-management/android-app.d.ts +110 -0
  135. package/lib/project-management/android-app.js +24 -15
  136. package/lib/project-management/app-metadata.d.ts +85 -0
  137. package/lib/project-management/app-metadata.js +37 -0
  138. package/lib/project-management/index.d.ts +21 -331
  139. package/lib/project-management/index.js +51 -24
  140. package/lib/project-management/ios-app.d.ts +66 -0
  141. package/lib/project-management/ios-app.js +15 -8
  142. package/lib/project-management/project-management-api-request-internal.d.ts +17 -0
  143. package/lib/project-management/project-management-api-request-internal.js +15 -15
  144. package/lib/project-management/project-management-namespace.d.ts +82 -0
  145. package/lib/project-management/project-management-namespace.js +18 -0
  146. package/lib/project-management/project-management.d.ts +115 -0
  147. package/lib/project-management/project-management.js +22 -25
  148. package/lib/remote-config/index.d.ts +19 -336
  149. package/lib/remote-config/index.js +45 -1
  150. package/lib/remote-config/remote-config-api-client-internal.d.ts +28 -0
  151. package/lib/remote-config/remote-config-api-client-internal.js +3 -3
  152. package/lib/remote-config/remote-config-api.d.ts +258 -0
  153. package/lib/remote-config/remote-config-api.js +18 -0
  154. package/lib/remote-config/remote-config-namespace.d.ts +105 -0
  155. package/lib/remote-config/remote-config-namespace.js +18 -0
  156. package/lib/remote-config/remote-config.d.ts +94 -0
  157. package/lib/remote-config/remote-config.js +27 -26
  158. package/lib/security-rules/index.d.ts +18 -184
  159. package/lib/security-rules/index.js +46 -1
  160. package/lib/security-rules/security-rules-api-client-internal.d.ts +73 -0
  161. package/lib/security-rules/security-rules-api-client-internal.js +1 -1
  162. package/lib/security-rules/security-rules-internal.d.ts +21 -0
  163. package/lib/security-rules/security-rules-internal.js +1 -1
  164. package/lib/security-rules/security-rules-namespace.d.ts +69 -0
  165. package/lib/security-rules/security-rules-namespace.js +18 -0
  166. package/lib/security-rules/security-rules.d.ts +196 -0
  167. package/lib/security-rules/security-rules.js +73 -55
  168. package/lib/storage/index.d.ts +16 -32
  169. package/lib/storage/index.js +38 -1
  170. package/lib/storage/storage-namespace.d.ts +45 -0
  171. package/lib/storage/storage-namespace.js +18 -0
  172. package/lib/storage/storage.d.ts +42 -0
  173. package/lib/storage/storage.js +9 -6
  174. package/lib/utils/api-request.d.ts +230 -0
  175. package/lib/utils/api-request.js +25 -25
  176. package/lib/utils/crypto-signer.d.ts +128 -0
  177. package/lib/utils/crypto-signer.js +9 -9
  178. package/lib/utils/deep-copy.d.ts +40 -0
  179. package/lib/utils/deep-copy.js +6 -6
  180. package/lib/utils/error.d.ts +650 -0
  181. package/lib/utils/error.js +34 -34
  182. package/lib/utils/index.d.ts +105 -0
  183. package/lib/utils/index.js +22 -21
  184. package/lib/utils/jwt.d.ts +131 -0
  185. package/lib/utils/jwt.js +11 -11
  186. package/lib/utils/validator.d.ts +144 -0
  187. package/lib/utils/validator.js +37 -37
  188. package/package.json +110 -8
  189. package/lib/credential/credential.js +0 -44
package/README.md CHANGED
@@ -36,13 +36,17 @@ $ npm install --save firebase-admin
36
36
  To use the module in your application, `require` it from any JavaScript file:
37
37
 
38
38
  ```js
39
- var admin = require("firebase-admin");
39
+ const { initializeApp } = require("firebase-admin/app");
40
+
41
+ initializeApp();
40
42
  ```
41
43
 
42
44
  If you are using ES2015, you can `import` the module instead:
43
45
 
44
46
  ```js
45
- import * as admin from "firebase-admin";
47
+ import { initializeApp } from "firebase-admin/app";
48
+
49
+ initializeApp();
46
50
  ```
47
51
 
48
52
 
@@ -55,7 +59,7 @@ requests, code review feedback, and also pull requests.
55
59
 
56
60
  ## Supported Environments
57
61
 
58
- We support Node.js 10.13.0 and higher.
62
+ We support Node.js 12 and higher.
59
63
 
60
64
  Please also note that the Admin SDK should only
61
65
  be used in server-side/back-end environments controlled by the app developer.
@@ -0,0 +1,188 @@
1
+ /*! firebase-admin v10.0.0 */
2
+ /*!
3
+ * @license
4
+ * Copyright 2021 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
+ /// <reference types="node" />
19
+ import { Agent } from 'http';
20
+ import { Credential } from './credential';
21
+ /**
22
+ * Available options to pass to {@link firebase-admin.app#initializeApp}.
23
+ */
24
+ export interface AppOptions {
25
+ /**
26
+ * A {@link firebase-admin.app#Credential} object used to
27
+ * authenticate the Admin SDK.
28
+ *
29
+ * See {@link https://firebase.google.com/docs/admin/setup#initialize_the_sdk | Initialize the SDK}
30
+ * for detailed documentation and code samples.
31
+ */
32
+ credential?: Credential;
33
+ /**
34
+ * The object to use as the {@link https://firebase.google.com/docs/reference/security/database/#auth | auth}
35
+ * variable in your Realtime Database Rules when the Admin SDK reads from or
36
+ * writes to the Realtime Database. This allows you to downscope the Admin SDK
37
+ * from its default full read and write privileges.
38
+ *
39
+ * You can pass `null` to act as an unauthenticated client.
40
+ *
41
+ * See
42
+ * {@link https://firebase.google.com/docs/database/admin/start#authenticate-with-limited-privileges |
43
+ * Authenticate with limited privileges}
44
+ * for detailed documentation and code samples.
45
+ */
46
+ databaseAuthVariableOverride?: object | null;
47
+ /**
48
+ * The URL of the Realtime Database from which to read and write data.
49
+ */
50
+ databaseURL?: string;
51
+ /**
52
+ * The ID of the service account to be used for signing custom tokens. This
53
+ * can be found in the `client_email` field of a service account JSON file.
54
+ */
55
+ serviceAccountId?: string;
56
+ /**
57
+ * The name of the Google Cloud Storage bucket used for storing application data.
58
+ * Use only the bucket name without any prefixes or additions (do *not* prefix
59
+ * the name with "gs://").
60
+ */
61
+ storageBucket?: string;
62
+ /**
63
+ * The ID of the Google Cloud project associated with the App.
64
+ */
65
+ projectId?: string;
66
+ /**
67
+ * An {@link https://nodejs.org/api/http.html#http_class_http_agent | HTTP Agent}
68
+ * to be used when making outgoing HTTP calls. This Agent instance is used
69
+ * by all services that make REST calls (e.g. `auth`, `messaging`,
70
+ * `projectManagement`).
71
+ *
72
+ * Realtime Database and Firestore use other means of communicating with
73
+ * the backend servers, so they do not use this HTTP Agent. `Credential`
74
+ * instances also do not use this HTTP Agent, but instead support
75
+ * specifying an HTTP Agent in the corresponding factory methods.
76
+ */
77
+ httpAgent?: Agent;
78
+ }
79
+ /**
80
+ * A Firebase app holds the initialization information for a collection of
81
+ * services.
82
+ */
83
+ export interface App {
84
+ /**
85
+ * The (read-only) name for this app.
86
+ *
87
+ * The default app's name is `"[DEFAULT]"`.
88
+ *
89
+ * @example
90
+ * ```javascript
91
+ * // The default app's name is "[DEFAULT]"
92
+ * initializeApp(defaultAppConfig);
93
+ * console.log(admin.app().name); // "[DEFAULT]"
94
+ * ```
95
+ *
96
+ * @example
97
+ * ```javascript
98
+ * // A named app's name is what you provide to initializeApp()
99
+ * const otherApp = initializeApp(otherAppConfig, "other");
100
+ * console.log(otherApp.name); // "other"
101
+ * ```
102
+ */
103
+ name: string;
104
+ /**
105
+ * The (read-only) configuration options for this app. These are the original
106
+ * parameters given in {@link firebase-admin.app#initializeApp}.
107
+ *
108
+ * @example
109
+ * ```javascript
110
+ * const app = initializeApp(config);
111
+ * console.log(app.options.credential === config.credential); // true
112
+ * console.log(app.options.databaseURL === config.databaseURL); // true
113
+ * ```
114
+ */
115
+ options: AppOptions;
116
+ }
117
+ /**
118
+ * `FirebaseError` is a subclass of the standard JavaScript `Error` object. In
119
+ * addition to a message string and stack trace, it contains a string code.
120
+ */
121
+ export interface FirebaseError {
122
+ /**
123
+ * Error codes are strings using the following format: `"service/string-code"`.
124
+ * Some examples include `"auth/invalid-uid"` and
125
+ * `"messaging/invalid-recipient"`.
126
+ *
127
+ * While the message for a given error can change, the code will remain the same
128
+ * between backward-compatible versions of the Firebase SDK.
129
+ */
130
+ code: string;
131
+ /**
132
+ * An explanatory message for the error that just occurred.
133
+ *
134
+ * This message is designed to be helpful to you, the developer. Because
135
+ * it generally does not convey meaningful information to end users,
136
+ * this message should not be displayed in your application.
137
+ */
138
+ message: string;
139
+ /**
140
+ * A string value containing the execution backtrace when the error originally
141
+ * occurred.
142
+ *
143
+ * This information can be useful for troubleshooting the cause of the error with
144
+ * {@link https://firebase.google.com/support | Firebase Support}.
145
+ */
146
+ stack?: string;
147
+ /**
148
+ * Returns a JSON-serializable object representation of this error.
149
+ *
150
+ * @returns A JSON-serializable representation of this object.
151
+ */
152
+ toJSON(): object;
153
+ }
154
+ /**
155
+ * Composite type which includes both a `FirebaseError` object and an index
156
+ * which can be used to get the errored item.
157
+ *
158
+ * @example
159
+ * ```javascript
160
+ * var registrationTokens = [token1, token2, token3];
161
+ * admin.messaging().subscribeToTopic(registrationTokens, 'topic-name')
162
+ * .then(function(response) {
163
+ * if (response.failureCount > 0) {
164
+ * console.log("Following devices unsucessfully subscribed to topic:");
165
+ * response.errors.forEach(function(error) {
166
+ * var invalidToken = registrationTokens[error.index];
167
+ * console.log(invalidToken, error.error);
168
+ * });
169
+ * } else {
170
+ * console.log("All devices successfully subscribed to topic:", response);
171
+ * }
172
+ * })
173
+ * .catch(function(error) {
174
+ * console.log("Error subscribing to topic:", error);
175
+ * });
176
+ *```
177
+ */
178
+ export interface FirebaseArrayIndexError {
179
+ /**
180
+ * The index of the errored item within the original array passed as part of the
181
+ * called API method.
182
+ */
183
+ index: number;
184
+ /**
185
+ * The error object.
186
+ */
187
+ error: FirebaseError;
188
+ }
@@ -0,0 +1,19 @@
1
+ /*! firebase-admin v10.0.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2021 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,123 @@
1
+ /*! firebase-admin v10.0.0 */
2
+ /*!
3
+ * @license
4
+ * Copyright 2021 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
+ /// <reference types="node" />
19
+ import { Agent } from 'http';
20
+ import { Credential, ServiceAccount } from './credential';
21
+ /**
22
+ * Returns a credential created from the
23
+ * {@link https://developers.google.com/identity/protocols/application-default-credentials |
24
+ * Google Application Default Credentials}
25
+ * that grants admin access to Firebase services. This credential can be used
26
+ * in the call to {@link firebase-admin.app#initializeApp}.
27
+ *
28
+ * Google Application Default Credentials are available on any Google
29
+ * infrastructure, such as Google App Engine and Google Compute Engine.
30
+ *
31
+ * See
32
+ * {@link https://firebase.google.com/docs/admin/setup#initialize_the_sdk | Initialize the SDK}
33
+ * for more details.
34
+ *
35
+ * @example
36
+ * ```javascript
37
+ * initializeApp({
38
+ * credential: applicationDefault(),
39
+ * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
40
+ * });
41
+ * ```
42
+ *
43
+ * @param httpAgent - Optional {@link https://nodejs.org/api/http.html#http_class_http_agent | HTTP Agent}
44
+ * to be used when retrieving access tokens from Google token servers.
45
+ *
46
+ * @returns A credential authenticated via Google
47
+ * Application Default Credentials that can be used to initialize an app.
48
+ */
49
+ export declare function applicationDefault(httpAgent?: Agent): Credential;
50
+ /**
51
+ * Returns a credential created from the provided service account that grants
52
+ * admin access to Firebase services. This credential can be used in the call
53
+ * to {@link firebase-admin.app#initializeApp}.
54
+ *
55
+ * See
56
+ * {@link https://firebase.google.com/docs/admin/setup#initialize_the_sdk | Initialize the SDK}
57
+ * for more details.
58
+ *
59
+ * @example
60
+ * ```javascript
61
+ * // Providing a path to a service account key JSON file
62
+ * const serviceAccount = require("path/to/serviceAccountKey.json");
63
+ * initializeApp({
64
+ * credential: cert(serviceAccount),
65
+ * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
66
+ * });
67
+ * ```
68
+ *
69
+ * @example
70
+ * ```javascript
71
+ * // Providing a service account object inline
72
+ * initializeApp({
73
+ * credential: cert({
74
+ * projectId: "<PROJECT_ID>",
75
+ * clientEmail: "foo@<PROJECT_ID>.iam.gserviceaccount.com",
76
+ * privateKey: "-----BEGIN PRIVATE KEY-----<KEY>-----END PRIVATE KEY-----\n"
77
+ * }),
78
+ * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
79
+ * });
80
+ * ```
81
+ *
82
+ * @param serviceAccountPathOrObject - The path to a service
83
+ * account key JSON file or an object representing a service account key.
84
+ * @param httpAgent - Optional {@link https://nodejs.org/api/http.html#http_class_http_agent | HTTP Agent}
85
+ * to be used when retrieving access tokens from Google token servers.
86
+ *
87
+ * @returns A credential authenticated via the
88
+ * provided service account that can be used to initialize an app.
89
+ */
90
+ export declare function cert(serviceAccountPathOrObject: string | ServiceAccount, httpAgent?: Agent): Credential;
91
+ /**
92
+ * Returns a credential created from the provided refresh token that grants
93
+ * admin access to Firebase services. This credential can be used in the call
94
+ * to {@link firebase-admin.app#initializeApp}.
95
+ *
96
+ * See
97
+ * {@link https://firebase.google.com/docs/admin/setup#initialize_the_sdk | Initialize the SDK}
98
+ * for more details.
99
+ *
100
+ * @example
101
+ * ```javascript
102
+ * // Providing a path to a refresh token JSON file
103
+ * const refreshToken = require("path/to/refreshToken.json");
104
+ * initializeApp({
105
+ * credential: refreshToken(refreshToken),
106
+ * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
107
+ * });
108
+ * ```
109
+ *
110
+ * @param refreshTokenPathOrObject - The path to a Google
111
+ * OAuth2 refresh token JSON file or an object representing a Google OAuth2
112
+ * refresh token.
113
+ * @param httpAgent - Optional {@link https://nodejs.org/api/http.html#http_class_http_agent | HTTP Agent}
114
+ * to be used when retrieving access tokens from Google token servers.
115
+ *
116
+ * @returns A credential authenticated via the
117
+ * provided service account that can be used to initialize an app.
118
+ */
119
+ export declare function refreshToken(refreshTokenPathOrObject: string | object, httpAgent?: Agent): Credential;
120
+ /**
121
+ * Clears the global ADC cache. Exported for testing.
122
+ */
123
+ export declare function clearGlobalAppDefaultCred(): void;
@@ -0,0 +1,150 @@
1
+ /*! firebase-admin v10.0.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2021 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.clearGlobalAppDefaultCred = exports.refreshToken = exports.cert = exports.applicationDefault = void 0;
21
+ var credential_internal_1 = require("./credential-internal");
22
+ var globalAppDefaultCred;
23
+ var globalCertCreds = {};
24
+ var globalRefreshTokenCreds = {};
25
+ /**
26
+ * Returns a credential created from the
27
+ * {@link https://developers.google.com/identity/protocols/application-default-credentials |
28
+ * Google Application Default Credentials}
29
+ * that grants admin access to Firebase services. This credential can be used
30
+ * in the call to {@link firebase-admin.app#initializeApp}.
31
+ *
32
+ * Google Application Default Credentials are available on any Google
33
+ * infrastructure, such as Google App Engine and Google Compute Engine.
34
+ *
35
+ * See
36
+ * {@link https://firebase.google.com/docs/admin/setup#initialize_the_sdk | Initialize the SDK}
37
+ * for more details.
38
+ *
39
+ * @example
40
+ * ```javascript
41
+ * initializeApp({
42
+ * credential: applicationDefault(),
43
+ * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
44
+ * });
45
+ * ```
46
+ *
47
+ * @param httpAgent - Optional {@link https://nodejs.org/api/http.html#http_class_http_agent | HTTP Agent}
48
+ * to be used when retrieving access tokens from Google token servers.
49
+ *
50
+ * @returns A credential authenticated via Google
51
+ * Application Default Credentials that can be used to initialize an app.
52
+ */
53
+ function applicationDefault(httpAgent) {
54
+ if (typeof globalAppDefaultCred === 'undefined') {
55
+ globalAppDefaultCred = credential_internal_1.getApplicationDefault(httpAgent);
56
+ }
57
+ return globalAppDefaultCred;
58
+ }
59
+ exports.applicationDefault = applicationDefault;
60
+ /**
61
+ * Returns a credential created from the provided service account that grants
62
+ * admin access to Firebase services. This credential can be used in the call
63
+ * to {@link firebase-admin.app#initializeApp}.
64
+ *
65
+ * See
66
+ * {@link https://firebase.google.com/docs/admin/setup#initialize_the_sdk | Initialize the SDK}
67
+ * for more details.
68
+ *
69
+ * @example
70
+ * ```javascript
71
+ * // Providing a path to a service account key JSON file
72
+ * const serviceAccount = require("path/to/serviceAccountKey.json");
73
+ * initializeApp({
74
+ * credential: cert(serviceAccount),
75
+ * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
76
+ * });
77
+ * ```
78
+ *
79
+ * @example
80
+ * ```javascript
81
+ * // Providing a service account object inline
82
+ * initializeApp({
83
+ * credential: cert({
84
+ * projectId: "<PROJECT_ID>",
85
+ * clientEmail: "foo@<PROJECT_ID>.iam.gserviceaccount.com",
86
+ * privateKey: "-----BEGIN PRIVATE KEY-----<KEY>-----END PRIVATE KEY-----\n"
87
+ * }),
88
+ * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
89
+ * });
90
+ * ```
91
+ *
92
+ * @param serviceAccountPathOrObject - The path to a service
93
+ * account key JSON file or an object representing a service account key.
94
+ * @param httpAgent - Optional {@link https://nodejs.org/api/http.html#http_class_http_agent | HTTP Agent}
95
+ * to be used when retrieving access tokens from Google token servers.
96
+ *
97
+ * @returns A credential authenticated via the
98
+ * provided service account that can be used to initialize an app.
99
+ */
100
+ function cert(serviceAccountPathOrObject, httpAgent) {
101
+ var stringifiedServiceAccount = JSON.stringify(serviceAccountPathOrObject);
102
+ if (!(stringifiedServiceAccount in globalCertCreds)) {
103
+ globalCertCreds[stringifiedServiceAccount] = new credential_internal_1.ServiceAccountCredential(serviceAccountPathOrObject, httpAgent);
104
+ }
105
+ return globalCertCreds[stringifiedServiceAccount];
106
+ }
107
+ exports.cert = cert;
108
+ /**
109
+ * Returns a credential created from the provided refresh token that grants
110
+ * admin access to Firebase services. This credential can be used in the call
111
+ * to {@link firebase-admin.app#initializeApp}.
112
+ *
113
+ * See
114
+ * {@link https://firebase.google.com/docs/admin/setup#initialize_the_sdk | Initialize the SDK}
115
+ * for more details.
116
+ *
117
+ * @example
118
+ * ```javascript
119
+ * // Providing a path to a refresh token JSON file
120
+ * const refreshToken = require("path/to/refreshToken.json");
121
+ * initializeApp({
122
+ * credential: refreshToken(refreshToken),
123
+ * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
124
+ * });
125
+ * ```
126
+ *
127
+ * @param refreshTokenPathOrObject - The path to a Google
128
+ * OAuth2 refresh token JSON file or an object representing a Google OAuth2
129
+ * refresh token.
130
+ * @param httpAgent - Optional {@link https://nodejs.org/api/http.html#http_class_http_agent | HTTP Agent}
131
+ * to be used when retrieving access tokens from Google token servers.
132
+ *
133
+ * @returns A credential authenticated via the
134
+ * provided service account that can be used to initialize an app.
135
+ */
136
+ function refreshToken(refreshTokenPathOrObject, httpAgent) {
137
+ var stringifiedRefreshToken = JSON.stringify(refreshTokenPathOrObject);
138
+ if (!(stringifiedRefreshToken in globalRefreshTokenCreds)) {
139
+ globalRefreshTokenCreds[stringifiedRefreshToken] = new credential_internal_1.RefreshTokenCredential(refreshTokenPathOrObject, httpAgent);
140
+ }
141
+ return globalRefreshTokenCreds[stringifiedRefreshToken];
142
+ }
143
+ exports.refreshToken = refreshToken;
144
+ /**
145
+ * Clears the global ADC cache. Exported for testing.
146
+ */
147
+ function clearGlobalAppDefaultCred() {
148
+ globalAppDefaultCred = undefined;
149
+ }
150
+ exports.clearGlobalAppDefaultCred = clearGlobalAppDefaultCred;
@@ -0,0 +1,90 @@
1
+ /*! firebase-admin v10.0.0 */
2
+ /*!
3
+ * @license
4
+ * Copyright 2020 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
+ /// <reference types="node" />
19
+ import { Agent } from 'http';
20
+ import { Credential, GoogleOAuthAccessToken } from './credential';
21
+ /**
22
+ * Implementation of Credential that uses a service account.
23
+ */
24
+ export declare class ServiceAccountCredential implements Credential {
25
+ private readonly httpAgent?;
26
+ readonly implicit: boolean;
27
+ readonly projectId: string;
28
+ readonly privateKey: string;
29
+ readonly clientEmail: string;
30
+ private readonly httpClient;
31
+ /**
32
+ * Creates a new ServiceAccountCredential from the given parameters.
33
+ *
34
+ * @param serviceAccountPathOrObject - Service account json object or path to a service account json file.
35
+ * @param httpAgent - Optional http.Agent to use when calling the remote token server.
36
+ * @param implicit - An optinal boolean indicating whether this credential was implicitly discovered from the
37
+ * environment, as opposed to being explicitly specified by the developer.
38
+ *
39
+ * @constructor
40
+ */
41
+ constructor(serviceAccountPathOrObject: string | object, httpAgent?: Agent | undefined, implicit?: boolean);
42
+ getAccessToken(): Promise<GoogleOAuthAccessToken>;
43
+ private createAuthJwt_;
44
+ }
45
+ /**
46
+ * Implementation of Credential that gets access tokens from the metadata service available
47
+ * in the Google Cloud Platform. This authenticates the process as the default service account
48
+ * of an App Engine instance or Google Compute Engine machine.
49
+ */
50
+ export declare class ComputeEngineCredential implements Credential {
51
+ private readonly httpClient;
52
+ private readonly httpAgent?;
53
+ private projectId?;
54
+ constructor(httpAgent?: Agent);
55
+ getAccessToken(): Promise<GoogleOAuthAccessToken>;
56
+ getProjectId(): Promise<string>;
57
+ private buildRequest;
58
+ }
59
+ /**
60
+ * Implementation of Credential that gets access tokens from refresh tokens.
61
+ */
62
+ export declare class RefreshTokenCredential implements Credential {
63
+ private readonly httpAgent?;
64
+ readonly implicit: boolean;
65
+ private readonly refreshToken;
66
+ private readonly httpClient;
67
+ /**
68
+ * Creates a new RefreshTokenCredential from the given parameters.
69
+ *
70
+ * @param refreshTokenPathOrObject - Refresh token json object or path to a refresh token
71
+ * (user credentials) json file.
72
+ * @param httpAgent - Optional http.Agent to use when calling the remote token server.
73
+ * @param implicit - An optinal boolean indicating whether this credential was implicitly
74
+ * discovered from the environment, as opposed to being explicitly specified by the developer.
75
+ *
76
+ * @constructor
77
+ */
78
+ constructor(refreshTokenPathOrObject: string | object, httpAgent?: Agent | undefined, implicit?: boolean);
79
+ getAccessToken(): Promise<GoogleOAuthAccessToken>;
80
+ }
81
+ /**
82
+ * Checks if the given credential was loaded via the application default credentials mechanism. This
83
+ * includes all ComputeEngineCredential instances, and the ServiceAccountCredential and RefreshTokenCredential
84
+ * instances that were loaded from well-known files or environment variables, rather than being explicitly
85
+ * instantiated.
86
+ *
87
+ * @param credential - The credential instance to check.
88
+ */
89
+ export declare function isApplicationDefault(credential?: Credential): boolean;
90
+ export declare function getApplicationDefault(httpAgent?: Agent): Credential;
@@ -1,6 +1,7 @@
1
- /*! firebase-admin v9.12.0 */
1
+ /*! firebase-admin v10.0.0 */
2
2
  "use strict";
3
3
  /*!
4
+ * @license
4
5
  * Copyright 2020 Google Inc.
5
6
  *
6
7
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -52,9 +53,9 @@ var ServiceAccountCredential = /** @class */ (function () {
52
53
  /**
53
54
  * Creates a new ServiceAccountCredential from the given parameters.
54
55
  *
55
- * @param serviceAccountPathOrObject Service account json object or path to a service account json file.
56
- * @param httpAgent Optional http.Agent to use when calling the remote token server.
57
- * @param implicit An optinal boolean indicating whether this credential was implicitly discovered from the
56
+ * @param serviceAccountPathOrObject - Service account json object or path to a service account json file.
57
+ * @param httpAgent - Optional http.Agent to use when calling the remote token server.
58
+ * @param implicit - An optinal boolean indicating whether this credential was implicitly discovered from the
58
59
  * environment, as opposed to being explicitly specified by the developer.
59
60
  *
60
61
  * @constructor
@@ -203,10 +204,11 @@ var RefreshTokenCredential = /** @class */ (function () {
203
204
  /**
204
205
  * Creates a new RefreshTokenCredential from the given parameters.
205
206
  *
206
- * @param refreshTokenPathOrObject Refresh token json object or path to a refresh token (user credentials) json file.
207
- * @param httpAgent Optional http.Agent to use when calling the remote token server.
208
- * @param implicit An optinal boolean indicating whether this credential was implicitly discovered from the
209
- * environment, as opposed to being explicitly specified by the developer.
207
+ * @param refreshTokenPathOrObject - Refresh token json object or path to a refresh token
208
+ * (user credentials) json file.
209
+ * @param httpAgent - Optional http.Agent to use when calling the remote token server.
210
+ * @param implicit - An optinal boolean indicating whether this credential was implicitly
211
+ * discovered from the environment, as opposed to being explicitly specified by the developer.
210
212
  *
211
213
  * @constructor
212
214
  */
@@ -282,7 +284,7 @@ var RefreshToken = /** @class */ (function () {
282
284
  * instances that were loaded from well-known files or environment variables, rather than being explicitly
283
285
  * instantiated.
284
286
  *
285
- * @param credential The credential instance to check.
287
+ * @param credential - The credential instance to check.
286
288
  */
287
289
  function isApplicationDefault(credential) {
288
290
  return credential instanceof ComputeEngineCredential ||
@@ -310,10 +312,10 @@ exports.getApplicationDefault = getApplicationDefault;
310
312
  * If no property exists by the given "key", looks for a property identified by "alt", and copies it instead.
311
313
  * This can be used to implement behaviors such as "copy property myKey or my_key".
312
314
  *
313
- * @param to Target object to copy the property into.
314
- * @param from Source object to copy the property from.
315
- * @param key Name of the property to copy.
316
- * @param alt Alternative name of the property to copy.
315
+ * @param to - Target object to copy the property into.
316
+ * @param from - Source object to copy the property from.
317
+ * @param key - Name of the property to copy.
318
+ * @param alt - Alternative name of the property to copy.
317
319
  */
318
320
  function copyAttr(to, from, key, alt) {
319
321
  var tmp = from[key] || from[alt];