firebase-admin 10.0.2 → 10.3.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.
- package/README.md +2 -1
- package/lib/app/core.d.ts +1 -1
- package/lib/app/core.js +1 -1
- package/lib/app/credential-factory.d.ts +1 -1
- package/lib/app/credential-factory.js +1 -1
- package/lib/app/credential-internal.d.ts +3 -1
- package/lib/app/credential-internal.js +18 -1
- package/lib/app/credential.d.ts +1 -1
- package/lib/app/credential.js +1 -1
- package/lib/app/firebase-app.d.ts +1 -1
- package/lib/app/firebase-app.js +1 -1
- package/lib/app/firebase-namespace.d.ts +1 -1
- package/lib/app/firebase-namespace.js +1 -1
- package/lib/app/index.d.ts +1 -1
- package/lib/app/index.js +1 -1
- package/lib/app/lifecycle.d.ts +1 -1
- package/lib/app/lifecycle.js +1 -1
- package/lib/app-check/app-check-api-client-internal.d.ts +1 -1
- package/lib/app-check/app-check-api-client-internal.js +3 -3
- package/lib/app-check/app-check-api.d.ts +1 -1
- package/lib/app-check/app-check-api.js +1 -1
- package/lib/app-check/app-check-namespace.d.ts +1 -1
- package/lib/app-check/app-check-namespace.js +1 -1
- package/lib/app-check/app-check.d.ts +1 -1
- package/lib/app-check/app-check.js +1 -1
- package/lib/app-check/index.d.ts +1 -1
- package/lib/app-check/index.js +1 -1
- package/lib/app-check/token-generator.d.ts +1 -1
- package/lib/app-check/token-generator.js +2 -2
- package/lib/app-check/token-verifier.d.ts +1 -1
- package/lib/app-check/token-verifier.js +2 -2
- package/lib/auth/action-code-settings-builder.d.ts +1 -1
- package/lib/auth/action-code-settings-builder.js +1 -1
- package/lib/auth/auth-api-request.d.ts +1 -1
- package/lib/auth/auth-api-request.js +24 -4
- package/lib/auth/auth-config.d.ts +1 -1
- package/lib/auth/auth-config.js +1 -1
- package/lib/auth/auth-namespace.d.ts +4 -2
- package/lib/auth/auth-namespace.js +1 -1
- package/lib/auth/auth.d.ts +1 -1
- package/lib/auth/auth.js +1 -1
- package/lib/auth/base-auth.d.ts +29 -2
- package/lib/auth/base-auth.js +38 -1
- package/lib/auth/identifier.d.ts +1 -1
- package/lib/auth/identifier.js +1 -1
- package/lib/auth/index.d.ts +2 -2
- package/lib/auth/index.js +1 -1
- package/lib/auth/tenant-manager.d.ts +1 -1
- package/lib/auth/tenant-manager.js +1 -1
- package/lib/auth/tenant.d.ts +1 -1
- package/lib/auth/tenant.js +1 -1
- package/lib/auth/token-generator.d.ts +1 -1
- package/lib/auth/token-generator.js +1 -1
- package/lib/auth/token-verifier.d.ts +70 -1
- package/lib/auth/token-verifier.js +54 -7
- package/lib/auth/user-import-builder.d.ts +1 -1
- package/lib/auth/user-import-builder.js +1 -1
- package/lib/auth/user-record.d.ts +1 -1
- package/lib/auth/user-record.js +1 -1
- package/lib/credential/index.d.ts +1 -1
- package/lib/credential/index.js +1 -1
- package/lib/database/database-namespace.d.ts +1 -1
- package/lib/database/database-namespace.js +1 -1
- package/lib/database/database.d.ts +1 -1
- package/lib/database/database.js +1 -1
- package/lib/database/index.d.ts +1 -1
- package/lib/database/index.js +1 -1
- package/lib/default-namespace.d.ts +1 -1
- package/lib/default-namespace.js +1 -1
- package/lib/esm/eventarc/index.js +5 -0
- package/lib/esm/functions/index.js +5 -0
- package/lib/eventarc/cloudevent.d.ts +84 -0
- package/lib/eventarc/cloudevent.js +19 -0
- package/lib/eventarc/eventarc-client-internal.d.ts +18 -0
- package/lib/eventarc/eventarc-client-internal.js +205 -0
- package/lib/eventarc/eventarc-utils.d.ts +31 -0
- package/lib/eventarc/eventarc-utils.js +141 -0
- package/lib/eventarc/eventarc.d.ts +107 -0
- package/lib/eventarc/eventarc.js +139 -0
- package/lib/eventarc/index.d.ts +53 -0
- package/lib/eventarc/index.js +64 -0
- package/lib/firebase-namespace-api.d.ts +1 -1
- package/lib/firebase-namespace-api.js +1 -1
- package/lib/firestore/firestore-internal.d.ts +1 -1
- package/lib/firestore/firestore-internal.js +1 -1
- package/lib/firestore/firestore-namespace.d.ts +1 -1
- package/lib/firestore/firestore-namespace.js +1 -1
- package/lib/firestore/index.d.ts +1 -1
- package/lib/firestore/index.js +1 -1
- package/lib/functions/functions-api-client-internal.d.ts +32 -0
- package/lib/functions/functions-api-client-internal.js +279 -0
- package/lib/functions/functions-api.d.ts +67 -0
- package/lib/functions/functions-api.js +19 -0
- package/lib/functions/functions.d.ts +63 -0
- package/lib/functions/functions.js +99 -0
- package/lib/functions/index.d.ts +53 -0
- package/lib/functions/index.js +64 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/installations/index.d.ts +1 -1
- package/lib/installations/index.js +1 -1
- package/lib/installations/installations-namespace.d.ts +1 -1
- package/lib/installations/installations-namespace.js +1 -1
- package/lib/installations/installations-request-handler.d.ts +1 -1
- package/lib/installations/installations-request-handler.js +1 -1
- package/lib/installations/installations.d.ts +1 -1
- package/lib/installations/installations.js +1 -1
- package/lib/instance-id/index.d.ts +1 -1
- package/lib/instance-id/index.js +1 -1
- package/lib/instance-id/instance-id-namespace.d.ts +1 -1
- package/lib/instance-id/instance-id-namespace.js +1 -1
- package/lib/instance-id/instance-id.d.ts +1 -1
- package/lib/instance-id/instance-id.js +1 -1
- package/lib/machine-learning/index.d.ts +1 -1
- package/lib/machine-learning/index.js +1 -1
- package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
- package/lib/machine-learning/machine-learning-api-client.js +1 -1
- package/lib/machine-learning/machine-learning-namespace.d.ts +1 -1
- package/lib/machine-learning/machine-learning-namespace.js +1 -1
- package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
- package/lib/machine-learning/machine-learning-utils.js +1 -1
- package/lib/machine-learning/machine-learning.d.ts +1 -1
- package/lib/machine-learning/machine-learning.js +1 -1
- package/lib/messaging/batch-request-internal.d.ts +1 -1
- package/lib/messaging/batch-request-internal.js +1 -1
- package/lib/messaging/index.d.ts +1 -1
- package/lib/messaging/index.js +1 -1
- package/lib/messaging/messaging-api-request-internal.d.ts +1 -1
- package/lib/messaging/messaging-api-request-internal.js +1 -1
- package/lib/messaging/messaging-api.d.ts +1 -1
- package/lib/messaging/messaging-api.js +1 -1
- package/lib/messaging/messaging-errors-internal.d.ts +1 -1
- package/lib/messaging/messaging-errors-internal.js +1 -1
- package/lib/messaging/messaging-internal.d.ts +1 -1
- package/lib/messaging/messaging-internal.js +1 -1
- package/lib/messaging/messaging-namespace.d.ts +1 -1
- package/lib/messaging/messaging-namespace.js +1 -1
- package/lib/messaging/messaging.d.ts +1 -1
- package/lib/messaging/messaging.js +1 -1
- package/lib/project-management/android-app.d.ts +1 -1
- package/lib/project-management/android-app.js +1 -1
- package/lib/project-management/app-metadata.d.ts +1 -1
- package/lib/project-management/app-metadata.js +1 -1
- package/lib/project-management/index.d.ts +1 -1
- package/lib/project-management/index.js +1 -1
- package/lib/project-management/ios-app.d.ts +1 -1
- package/lib/project-management/ios-app.js +1 -1
- package/lib/project-management/project-management-api-request-internal.d.ts +1 -1
- package/lib/project-management/project-management-api-request-internal.js +1 -1
- package/lib/project-management/project-management-namespace.d.ts +1 -1
- package/lib/project-management/project-management-namespace.js +1 -1
- package/lib/project-management/project-management.d.ts +1 -1
- package/lib/project-management/project-management.js +1 -1
- package/lib/remote-config/index.d.ts +1 -1
- package/lib/remote-config/index.js +1 -1
- package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
- package/lib/remote-config/remote-config-api-client-internal.js +1 -1
- package/lib/remote-config/remote-config-api.d.ts +1 -1
- package/lib/remote-config/remote-config-api.js +1 -1
- package/lib/remote-config/remote-config-namespace.d.ts +1 -1
- package/lib/remote-config/remote-config-namespace.js +1 -1
- package/lib/remote-config/remote-config.d.ts +1 -1
- package/lib/remote-config/remote-config.js +1 -1
- package/lib/security-rules/index.d.ts +1 -1
- package/lib/security-rules/index.js +1 -1
- package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
- package/lib/security-rules/security-rules-api-client-internal.js +1 -1
- package/lib/security-rules/security-rules-internal.d.ts +1 -1
- package/lib/security-rules/security-rules-internal.js +1 -1
- package/lib/security-rules/security-rules-namespace.d.ts +1 -1
- package/lib/security-rules/security-rules-namespace.js +1 -1
- package/lib/security-rules/security-rules.d.ts +1 -1
- package/lib/security-rules/security-rules.js +1 -1
- package/lib/storage/index.d.ts +1 -1
- package/lib/storage/index.js +1 -1
- package/lib/storage/storage-namespace.d.ts +1 -1
- package/lib/storage/storage-namespace.js +1 -1
- package/lib/storage/storage.d.ts +1 -1
- package/lib/storage/storage.js +1 -1
- package/lib/utils/api-request.d.ts +1 -1
- package/lib/utils/api-request.js +3 -3
- package/lib/utils/crypto-signer.d.ts +1 -1
- package/lib/utils/crypto-signer.js +1 -1
- package/lib/utils/deep-copy.d.ts +1 -1
- package/lib/utils/deep-copy.js +1 -1
- package/lib/utils/error.d.ts +9 -1
- package/lib/utils/error.js +11 -1
- package/lib/utils/index.d.ts +43 -1
- package/lib/utils/index.js +72 -2
- package/lib/utils/jwt.d.ts +1 -1
- package/lib/utils/jwt.js +1 -1
- package/lib/utils/validator.d.ts +1 -1
- package/lib/utils/validator.js +1 -1
- package/package.json +44 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin v10.0
|
|
1
|
+
/*! firebase-admin v10.3.0 */
|
|
2
2
|
/*!
|
|
3
3
|
* Copyright 2018 Google Inc.
|
|
4
4
|
*
|
|
@@ -148,3 +148,72 @@ export interface DecodedIdToken {
|
|
|
148
148
|
*/
|
|
149
149
|
[key: string]: any;
|
|
150
150
|
}
|
|
151
|
+
/** @alpha */
|
|
152
|
+
export interface DecodedAuthBlockingSharedUserInfo {
|
|
153
|
+
uid: string;
|
|
154
|
+
display_name?: string;
|
|
155
|
+
email?: string;
|
|
156
|
+
photo_url?: string;
|
|
157
|
+
phone_number?: string;
|
|
158
|
+
}
|
|
159
|
+
/** @alpha */
|
|
160
|
+
export interface DecodedAuthBlockingMetadata {
|
|
161
|
+
creation_time?: number;
|
|
162
|
+
last_sign_in_time?: number;
|
|
163
|
+
}
|
|
164
|
+
/** @alpha */
|
|
165
|
+
export interface DecodedAuthBlockingUserInfo extends DecodedAuthBlockingSharedUserInfo {
|
|
166
|
+
provider_id: string;
|
|
167
|
+
}
|
|
168
|
+
/** @alpha */
|
|
169
|
+
export interface DecodedAuthBlockingMfaInfo {
|
|
170
|
+
uid: string;
|
|
171
|
+
display_name?: string;
|
|
172
|
+
phone_number?: string;
|
|
173
|
+
enrollment_time?: string;
|
|
174
|
+
factor_id?: string;
|
|
175
|
+
}
|
|
176
|
+
/** @alpha */
|
|
177
|
+
export interface DecodedAuthBlockingEnrolledFactors {
|
|
178
|
+
enrolled_factors?: DecodedAuthBlockingMfaInfo[];
|
|
179
|
+
}
|
|
180
|
+
/** @alpha */
|
|
181
|
+
export interface DecodedAuthBlockingUserRecord extends DecodedAuthBlockingSharedUserInfo {
|
|
182
|
+
email_verified?: boolean;
|
|
183
|
+
disabled?: boolean;
|
|
184
|
+
metadata?: DecodedAuthBlockingMetadata;
|
|
185
|
+
password_hash?: string;
|
|
186
|
+
password_salt?: string;
|
|
187
|
+
provider_data?: DecodedAuthBlockingUserInfo[];
|
|
188
|
+
multi_factor?: DecodedAuthBlockingEnrolledFactors;
|
|
189
|
+
custom_claims?: any;
|
|
190
|
+
tokens_valid_after_time?: number;
|
|
191
|
+
tenant_id?: string;
|
|
192
|
+
[key: string]: any;
|
|
193
|
+
}
|
|
194
|
+
/** @alpha */
|
|
195
|
+
export interface DecodedAuthBlockingToken {
|
|
196
|
+
aud: string;
|
|
197
|
+
exp: number;
|
|
198
|
+
iat: number;
|
|
199
|
+
iss: string;
|
|
200
|
+
sub: string;
|
|
201
|
+
event_id: string;
|
|
202
|
+
event_type: string;
|
|
203
|
+
ip_address: string;
|
|
204
|
+
user_agent?: string;
|
|
205
|
+
locale?: string;
|
|
206
|
+
sign_in_method?: string;
|
|
207
|
+
user_record?: DecodedAuthBlockingUserRecord;
|
|
208
|
+
tenant_id?: string;
|
|
209
|
+
raw_user_info?: string;
|
|
210
|
+
sign_in_attributes?: {
|
|
211
|
+
[key: string]: any;
|
|
212
|
+
};
|
|
213
|
+
oauth_id_token?: string;
|
|
214
|
+
oauth_access_token?: string;
|
|
215
|
+
oauth_refresh_token?: string;
|
|
216
|
+
oauth_token_secret?: string;
|
|
217
|
+
oauth_expires_in?: number;
|
|
218
|
+
[key: string]: any;
|
|
219
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin v10.0
|
|
1
|
+
/*! firebase-admin v10.3.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2018 Google Inc.
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.createSessionCookieVerifier = exports.createIdTokenVerifier = exports.FirebaseTokenVerifier = exports.SESSION_COOKIE_INFO = exports.ID_TOKEN_INFO = void 0;
|
|
19
|
+
exports.createSessionCookieVerifier = exports.createAuthBlockingTokenVerifier = exports.createIdTokenVerifier = exports.FirebaseTokenVerifier = exports.SESSION_COOKIE_INFO = exports.AUTH_BLOCKING_TOKEN_INFO = exports.ID_TOKEN_INFO = void 0;
|
|
20
20
|
var error_1 = require("../utils/error");
|
|
21
21
|
var util = require("../utils/index");
|
|
22
22
|
var validator = require("../utils/validator");
|
|
@@ -41,6 +41,18 @@ exports.ID_TOKEN_INFO = {
|
|
|
41
41
|
shortName: 'ID token',
|
|
42
42
|
expiredErrorCode: error_1.AuthClientErrorCode.ID_TOKEN_EXPIRED,
|
|
43
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* User facing token information related to the Firebase Auth Blocking token.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
exports.AUTH_BLOCKING_TOKEN_INFO = {
|
|
50
|
+
url: 'https://cloud.google.com/identity-platform/docs/blocking-functions',
|
|
51
|
+
verifyApiName: '_verifyAuthBlockingToken()',
|
|
52
|
+
jwtName: 'Firebase Auth Blocking token',
|
|
53
|
+
shortName: 'Auth Blocking token',
|
|
54
|
+
expiredErrorCode: error_1.AuthClientErrorCode.AUTH_BLOCKING_TOKEN_EXPIRED,
|
|
55
|
+
};
|
|
44
56
|
/**
|
|
45
57
|
* User facing token information related to the Firebase session cookie.
|
|
46
58
|
*
|
|
@@ -115,6 +127,26 @@ var FirebaseTokenVerifier = /** @class */ (function () {
|
|
|
115
127
|
return decodedIdToken;
|
|
116
128
|
});
|
|
117
129
|
};
|
|
130
|
+
/** @alpha */
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
132
|
+
FirebaseTokenVerifier.prototype._verifyAuthBlockingToken = function (jwtToken, isEmulator, audience) {
|
|
133
|
+
var _this = this;
|
|
134
|
+
if (!validator.isString(jwtToken)) {
|
|
135
|
+
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, "First argument to " + this.tokenInfo.verifyApiName + " must be a " + this.tokenInfo.jwtName + " string.");
|
|
136
|
+
}
|
|
137
|
+
return this.ensureProjectId()
|
|
138
|
+
.then(function (projectId) {
|
|
139
|
+
if (typeof audience === 'undefined') {
|
|
140
|
+
audience = projectId + ".cloudfunctions.net/";
|
|
141
|
+
}
|
|
142
|
+
return _this.decodeAndVerify(jwtToken, projectId, isEmulator, audience);
|
|
143
|
+
})
|
|
144
|
+
.then(function (decoded) {
|
|
145
|
+
var decodedAuthBlockingToken = decoded.payload;
|
|
146
|
+
decodedAuthBlockingToken.uid = decodedAuthBlockingToken.sub;
|
|
147
|
+
return decodedAuthBlockingToken;
|
|
148
|
+
});
|
|
149
|
+
};
|
|
118
150
|
FirebaseTokenVerifier.prototype.ensureProjectId = function () {
|
|
119
151
|
var _this = this;
|
|
120
152
|
return util.findProjectId(this.app)
|
|
@@ -126,11 +158,11 @@ var FirebaseTokenVerifier = /** @class */ (function () {
|
|
|
126
158
|
return Promise.resolve(projectId);
|
|
127
159
|
});
|
|
128
160
|
};
|
|
129
|
-
FirebaseTokenVerifier.prototype.decodeAndVerify = function (token, projectId, isEmulator) {
|
|
161
|
+
FirebaseTokenVerifier.prototype.decodeAndVerify = function (token, projectId, isEmulator, audience) {
|
|
130
162
|
var _this = this;
|
|
131
163
|
return this.safeDecode(token)
|
|
132
164
|
.then(function (decodedToken) {
|
|
133
|
-
_this.verifyContent(decodedToken, projectId, isEmulator);
|
|
165
|
+
_this.verifyContent(decodedToken, projectId, isEmulator, audience);
|
|
134
166
|
return _this.verifySignature(token, isEmulator)
|
|
135
167
|
.then(function () { return decodedToken; });
|
|
136
168
|
});
|
|
@@ -157,7 +189,7 @@ var FirebaseTokenVerifier = /** @class */ (function () {
|
|
|
157
189
|
* @param projectId - The Firebase Project Id.
|
|
158
190
|
* @param isEmulator - Whether the token is an Emulator token.
|
|
159
191
|
*/
|
|
160
|
-
FirebaseTokenVerifier.prototype.verifyContent = function (fullDecodedToken, projectId, isEmulator) {
|
|
192
|
+
FirebaseTokenVerifier.prototype.verifyContent = function (fullDecodedToken, projectId, isEmulator, audience) {
|
|
161
193
|
var header = fullDecodedToken && fullDecodedToken.header;
|
|
162
194
|
var payload = fullDecodedToken && fullDecodedToken.payload;
|
|
163
195
|
var projectIdMatchMessage = " Make sure the " + this.tokenInfo.shortName + " comes from the same " +
|
|
@@ -177,7 +209,7 @@ var FirebaseTokenVerifier = /** @class */ (function () {
|
|
|
177
209
|
(this.tokenInfo.shortName + ", but was given a legacy custom token.");
|
|
178
210
|
}
|
|
179
211
|
else {
|
|
180
|
-
errorMessage =
|
|
212
|
+
errorMessage = this.tokenInfo.jwtName + " has no \"kid\" claim.";
|
|
181
213
|
}
|
|
182
214
|
errorMessage += verifyJwtTokenDocsMessage;
|
|
183
215
|
}
|
|
@@ -185,7 +217,11 @@ var FirebaseTokenVerifier = /** @class */ (function () {
|
|
|
185
217
|
errorMessage = this.tokenInfo.jwtName + " has incorrect algorithm. Expected \"" + jwt_1.ALGORITHM_RS256 + '" but got ' +
|
|
186
218
|
'"' + header.alg + '".' + verifyJwtTokenDocsMessage;
|
|
187
219
|
}
|
|
188
|
-
else if (payload.aud
|
|
220
|
+
else if (typeof audience !== 'undefined' && !payload.aud.includes(audience)) {
|
|
221
|
+
errorMessage = this.tokenInfo.jwtName + " has incorrect \"aud\" (audience) claim. Expected \"" +
|
|
222
|
+
audience + '" but got "' + payload.aud + '".' + verifyJwtTokenDocsMessage;
|
|
223
|
+
}
|
|
224
|
+
else if (typeof audience === 'undefined' && payload.aud !== projectId) {
|
|
189
225
|
errorMessage = this.tokenInfo.jwtName + " has incorrect \"aud\" (audience) claim. Expected \"" +
|
|
190
226
|
projectId + '" but got "' + payload.aud + '".' + projectIdMatchMessage +
|
|
191
227
|
verifyJwtTokenDocsMessage;
|
|
@@ -258,6 +294,17 @@ function createIdTokenVerifier(app) {
|
|
|
258
294
|
return new FirebaseTokenVerifier(CLIENT_CERT_URL, 'https://securetoken.google.com/', exports.ID_TOKEN_INFO, app);
|
|
259
295
|
}
|
|
260
296
|
exports.createIdTokenVerifier = createIdTokenVerifier;
|
|
297
|
+
/**
|
|
298
|
+
* Creates a new FirebaseTokenVerifier to verify Firebase Auth Blocking tokens.
|
|
299
|
+
*
|
|
300
|
+
* @internal
|
|
301
|
+
* @param app - Firebase app instance.
|
|
302
|
+
* @returns FirebaseTokenVerifier
|
|
303
|
+
*/
|
|
304
|
+
function createAuthBlockingTokenVerifier(app) {
|
|
305
|
+
return new FirebaseTokenVerifier(CLIENT_CERT_URL, 'https://securetoken.google.com/', exports.AUTH_BLOCKING_TOKEN_INFO, app);
|
|
306
|
+
}
|
|
307
|
+
exports.createAuthBlockingTokenVerifier = createAuthBlockingTokenVerifier;
|
|
261
308
|
/**
|
|
262
309
|
* Creates a new FirebaseTokenVerifier to verify Firebase session cookies.
|
|
263
310
|
*
|
package/lib/auth/user-record.js
CHANGED
package/lib/credential/index.js
CHANGED
package/lib/database/database.js
CHANGED
package/lib/database/index.d.ts
CHANGED
package/lib/database/index.js
CHANGED
package/lib/default-namespace.js
CHANGED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*! firebase-admin v10.3.0 */
|
|
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
|
+
* A CloudEvent version.
|
|
20
|
+
*/
|
|
21
|
+
export declare type CloudEventVersion = '1.0';
|
|
22
|
+
/**
|
|
23
|
+
* A CloudEvent describes event data.
|
|
24
|
+
*
|
|
25
|
+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
|
|
26
|
+
*/
|
|
27
|
+
export interface CloudEvent {
|
|
28
|
+
/**
|
|
29
|
+
* Identifier for the event. If not provided, it is auto-populated with a UUID.
|
|
30
|
+
*
|
|
31
|
+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#id
|
|
32
|
+
*/
|
|
33
|
+
id?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Identifies the context in which an event happened. If not provided, the value of `EVENTARC_CLOUD_EVENT_SOURCE`
|
|
36
|
+
* environment variable is used and if that is not set, a validation error is thrown.
|
|
37
|
+
*
|
|
38
|
+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#source-1
|
|
39
|
+
*/
|
|
40
|
+
source?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The version of the CloudEvents specification which the event uses. If not provided, is set to `1.0` --
|
|
43
|
+
* the only supported value.
|
|
44
|
+
*
|
|
45
|
+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#specversion
|
|
46
|
+
*/
|
|
47
|
+
specversion?: CloudEventVersion;
|
|
48
|
+
/**
|
|
49
|
+
* Type of the event. Should be prefixed with a reverse-DNS name (`com.my-org.v1.something.happended`).
|
|
50
|
+
*
|
|
51
|
+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#type
|
|
52
|
+
*/
|
|
53
|
+
type: string;
|
|
54
|
+
/**
|
|
55
|
+
* Subject (context) of the event in the context of the event producer.
|
|
56
|
+
*
|
|
57
|
+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject
|
|
58
|
+
*/
|
|
59
|
+
subject?: string;
|
|
60
|
+
/**
|
|
61
|
+
* MIME type of the data being sent with the event in the `data` field. Only `application/json` and `text/plain`
|
|
62
|
+
* are currently supported. If not specified, it is automatically inferred from the type of provided data.
|
|
63
|
+
*
|
|
64
|
+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#datacontenttype
|
|
65
|
+
*/
|
|
66
|
+
datacontenttype?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Timestamp of the event. Must be in ISO time format. If not specified, current time (at the moment of publishing)
|
|
69
|
+
* is used.
|
|
70
|
+
*
|
|
71
|
+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#time
|
|
72
|
+
*/
|
|
73
|
+
time?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Data payload of the event. Objects are stringified with JSON and strings are be passed along as-is.
|
|
76
|
+
*/
|
|
77
|
+
data?: object | string;
|
|
78
|
+
/**
|
|
79
|
+
* Custom attributes/extensions. Must be strings. Added to the event as is.
|
|
80
|
+
*
|
|
81
|
+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#extension-context-attributes
|
|
82
|
+
*/
|
|
83
|
+
[key: string]: any;
|
|
84
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*! firebase-admin v10.3.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
/*!
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2022 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,18 @@
|
|
|
1
|
+
/*! firebase-admin v10.3.0 */
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/*! firebase-admin v10.3.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
/*!
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2022 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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
29
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
30
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
31
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
32
|
+
function step(op) {
|
|
33
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
34
|
+
while (_) try {
|
|
35
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
36
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
37
|
+
switch (op[0]) {
|
|
38
|
+
case 0: case 1: t = op; break;
|
|
39
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
40
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
41
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
42
|
+
default:
|
|
43
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
44
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
45
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
46
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
47
|
+
if (t[2]) _.ops.pop();
|
|
48
|
+
_.trys.pop(); continue;
|
|
49
|
+
}
|
|
50
|
+
op = body.call(thisArg, _);
|
|
51
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
52
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
|
+
exports.EventarcApiClient = void 0;
|
|
57
|
+
var validator = require("../utils/validator");
|
|
58
|
+
var eventarc_utils_1 = require("./eventarc-utils");
|
|
59
|
+
var api_request_1 = require("../utils/api-request");
|
|
60
|
+
var utils = require("../utils");
|
|
61
|
+
var error_1 = require("../utils/error");
|
|
62
|
+
var EVENTARC_API = 'https://eventarcpublishing.googleapis.com/v1';
|
|
63
|
+
var FIREBASE_VERSION_HEADER = {
|
|
64
|
+
'X-Firebase-Client': "fire-admin-node/" + utils.getSdkVersion(),
|
|
65
|
+
};
|
|
66
|
+
var CHANNEL_NAME_REGEX = /^(projects\/([^/]+)\/)?locations\/([^/]+)\/channels\/([^/]+)$/;
|
|
67
|
+
var DEFAULT_CHANNEL_REGION = 'us-central1';
|
|
68
|
+
/**
|
|
69
|
+
* Class that facilitates sending requests to the Eventarc backend API.
|
|
70
|
+
*
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
var EventarcApiClient = /** @class */ (function () {
|
|
74
|
+
function EventarcApiClient(app, channel) {
|
|
75
|
+
this.app = app;
|
|
76
|
+
this.channel = channel;
|
|
77
|
+
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
|
78
|
+
throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'First argument passed to Channel() must be a valid Eventarc service instance.');
|
|
79
|
+
}
|
|
80
|
+
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
|
81
|
+
this.resolvedChannelName = this.resolveChannelName(channel.name);
|
|
82
|
+
}
|
|
83
|
+
EventarcApiClient.prototype.getProjectId = function () {
|
|
84
|
+
var _this = this;
|
|
85
|
+
if (this.projectId) {
|
|
86
|
+
return Promise.resolve(this.projectId);
|
|
87
|
+
}
|
|
88
|
+
return utils.findProjectId(this.app)
|
|
89
|
+
.then(function (projectId) {
|
|
90
|
+
if (!validator.isNonEmptyString(projectId)) {
|
|
91
|
+
throw new eventarc_utils_1.FirebaseEventarcError('unknown-error', 'Failed to determine project ID. Initialize the '
|
|
92
|
+
+ 'SDK with service account credentials or set project ID as an app option. '
|
|
93
|
+
+ 'Alternatively, set the GOOGLE_CLOUD_PROJECT environment variable.');
|
|
94
|
+
}
|
|
95
|
+
_this.projectId = projectId;
|
|
96
|
+
return projectId;
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Publishes provided events to this channel. If channel was created with `allowedEventsTypes` and event type
|
|
101
|
+
* is not on that list, the event is ignored.
|
|
102
|
+
*
|
|
103
|
+
* The following CloudEvent fields are auto-populated if not set:
|
|
104
|
+
* * specversion - `1.0`
|
|
105
|
+
* * id - uuidv4()
|
|
106
|
+
* * source - populated with `process.env.EVENTARC_CLOUD_EVENT_SOURCE` and
|
|
107
|
+
* if not set an error is thrown.
|
|
108
|
+
*
|
|
109
|
+
* @param events - CloudEvent to publish to the channel.
|
|
110
|
+
*/
|
|
111
|
+
EventarcApiClient.prototype.publish = function (events) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
+
var _a;
|
|
114
|
+
var _this = this;
|
|
115
|
+
return __generator(this, function (_b) {
|
|
116
|
+
switch (_b.label) {
|
|
117
|
+
case 0:
|
|
118
|
+
if (!Array.isArray(events)) {
|
|
119
|
+
events = [events];
|
|
120
|
+
}
|
|
121
|
+
_a = this.publishToEventarcApi;
|
|
122
|
+
return [4 /*yield*/, this.resolvedChannelName];
|
|
123
|
+
case 1: return [2 /*return*/, _a.apply(this, [_b.sent(),
|
|
124
|
+
events
|
|
125
|
+
.filter(function (e) { return typeof _this.channel.allowedEventTypes === 'undefined' ||
|
|
126
|
+
_this.channel.allowedEventTypes.includes(e.type); })
|
|
127
|
+
.map(eventarc_utils_1.toCloudEventProtoFormat)])];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
EventarcApiClient.prototype.publishToEventarcApi = function (channel, events) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
var request;
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
if (events.length === 0) {
|
|
137
|
+
return [2 /*return*/];
|
|
138
|
+
}
|
|
139
|
+
request = {
|
|
140
|
+
method: 'POST',
|
|
141
|
+
url: this.getEventarcHost() + "/" + channel + ":publishEvents",
|
|
142
|
+
data: JSON.stringify({ events: events }),
|
|
143
|
+
};
|
|
144
|
+
return [2 /*return*/, this.sendRequest(request)];
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
EventarcApiClient.prototype.sendRequest = function (request) {
|
|
149
|
+
var _this = this;
|
|
150
|
+
request.headers = FIREBASE_VERSION_HEADER;
|
|
151
|
+
return this.httpClient.send(request)
|
|
152
|
+
.then(function () { return undefined; })
|
|
153
|
+
.catch(function (err) {
|
|
154
|
+
throw _this.toFirebaseError(err);
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
EventarcApiClient.prototype.toFirebaseError = function (err) {
|
|
158
|
+
if (err instanceof error_1.PrefixedFirebaseError) {
|
|
159
|
+
return err;
|
|
160
|
+
}
|
|
161
|
+
var response = err.response;
|
|
162
|
+
return new eventarc_utils_1.FirebaseEventarcError('unknown-error', "Unexpected response with status: " + response.status + " and body: " + response.text);
|
|
163
|
+
};
|
|
164
|
+
EventarcApiClient.prototype.resolveChannelName = function (name) {
|
|
165
|
+
if (!name.includes('/')) {
|
|
166
|
+
var location = DEFAULT_CHANNEL_REGION;
|
|
167
|
+
var channelId = name;
|
|
168
|
+
return this.resolveChannelNameProjectId(location, channelId);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
var match = CHANNEL_NAME_REGEX.exec(name);
|
|
172
|
+
if (match === null || match.length < 4) {
|
|
173
|
+
throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'Invalid channel name format.');
|
|
174
|
+
}
|
|
175
|
+
var projectId = match[2];
|
|
176
|
+
var location = match[3];
|
|
177
|
+
var channelId = match[4];
|
|
178
|
+
if (validator.isNonEmptyString(projectId)) {
|
|
179
|
+
return Promise.resolve("projects/" + projectId + "/locations/" + location + "/channels/" + channelId);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
return this.resolveChannelNameProjectId(location, channelId);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
EventarcApiClient.prototype.resolveChannelNameProjectId = function (location, channelId) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
188
|
+
var projectId;
|
|
189
|
+
return __generator(this, function (_a) {
|
|
190
|
+
switch (_a.label) {
|
|
191
|
+
case 0: return [4 /*yield*/, this.getProjectId()];
|
|
192
|
+
case 1:
|
|
193
|
+
projectId = _a.sent();
|
|
194
|
+
return [2 /*return*/, "projects/" + projectId + "/locations/" + location + "/channels/" + channelId];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
EventarcApiClient.prototype.getEventarcHost = function () {
|
|
200
|
+
var _a;
|
|
201
|
+
return (_a = process.env.CLOUD_EVENTARC_EMULATOR_HOST) !== null && _a !== void 0 ? _a : EVENTARC_API;
|
|
202
|
+
};
|
|
203
|
+
return EventarcApiClient;
|
|
204
|
+
}());
|
|
205
|
+
exports.EventarcApiClient = EventarcApiClient;
|