firebase-tools 10.9.2 → 11.1.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 +15 -9
- package/lib/accountImporter.js +92 -93
- package/lib/api.js +77 -218
- package/lib/apiv2.js +5 -4
- package/lib/appdistribution/client.js +16 -25
- package/lib/auth.js +69 -47
- package/lib/bin/firebase.js +42 -47
- package/lib/checkValidTargetFilters.js +13 -12
- package/lib/commands/appdistribution-distribute.js +2 -1
- package/lib/commands/appdistribution-testers-add.js +2 -1
- package/lib/commands/appdistribution-testers-remove.js +2 -1
- package/lib/commands/apps-android-sha-create.js +2 -1
- package/lib/commands/apps-android-sha-delete.js +2 -1
- package/lib/commands/apps-android-sha-list.js +2 -1
- package/lib/commands/apps-create.js +2 -1
- package/lib/commands/apps-list.js +2 -1
- package/lib/commands/apps-sdkconfig.js +8 -3
- package/lib/commands/auth-export.js +2 -1
- package/lib/commands/auth-import.js +7 -10
- package/lib/commands/crashlytics-symbols-upload.js +2 -1
- package/lib/commands/database-get.js +4 -3
- package/lib/commands/database-instances-create.js +2 -1
- package/lib/commands/database-instances-list.js +3 -3
- package/lib/commands/database-profile.js +2 -1
- package/lib/commands/database-push.js +2 -1
- package/lib/commands/database-remove.js +2 -1
- package/lib/commands/database-rules-canary.js +2 -1
- package/lib/commands/database-rules-get.js +2 -1
- package/lib/commands/database-rules-list.js +2 -1
- package/lib/commands/database-rules-release.js +2 -1
- package/lib/commands/database-rules-stage.js +2 -1
- package/lib/commands/database-set.js +2 -1
- package/lib/commands/database-settings-get.js +2 -1
- package/lib/commands/database-settings-set.js +2 -1
- package/lib/commands/database-update.js +2 -1
- package/lib/commands/deploy.js +23 -21
- package/lib/commands/emulators-exec.js +2 -1
- package/lib/commands/emulators-export.js +2 -1
- package/lib/commands/emulators-start.js +2 -1
- package/lib/commands/experimental-functions-shell.js +10 -8
- package/lib/commands/ext-configure.js +56 -120
- package/lib/commands/ext-dev-deprecate.js +2 -1
- package/lib/commands/ext-dev-emulators-exec.js +13 -7
- package/lib/commands/ext-dev-emulators-start.js +12 -27
- package/lib/commands/ext-dev-extension-delete.js +2 -1
- package/lib/commands/ext-dev-init.js +2 -1
- package/lib/commands/ext-dev-list.js +2 -1
- package/lib/commands/ext-dev-publish.js +2 -1
- package/lib/commands/ext-dev-register.js +2 -1
- package/lib/commands/ext-dev-undeprecate.js +2 -1
- package/lib/commands/ext-dev-unpublish.js +2 -1
- package/lib/commands/ext-dev-usage.js +2 -1
- package/lib/commands/ext-export.js +2 -1
- package/lib/commands/ext-info.js +2 -1
- package/lib/commands/ext-install.js +14 -198
- package/lib/commands/ext-list.js +2 -1
- package/lib/commands/ext-sources-create.js +2 -1
- package/lib/commands/ext-uninstall.js +9 -92
- package/lib/commands/ext-update.js +67 -225
- package/lib/commands/ext.js +2 -1
- package/lib/commands/firestore-delete.js +2 -1
- package/lib/commands/firestore-indexes-list.js +2 -1
- package/lib/commands/functions-config-clone.js +4 -3
- package/lib/commands/functions-config-export.js +2 -1
- package/lib/commands/functions-config-get.js +2 -1
- package/lib/commands/functions-config-set.js +2 -1
- package/lib/commands/functions-config-unset.js +2 -1
- package/lib/commands/functions-delete.js +2 -1
- package/lib/commands/functions-deletegcfartifacts.js +2 -1
- package/lib/commands/functions-list.js +2 -1
- package/lib/commands/functions-log.js +2 -1
- package/lib/commands/functions-secrets-access.js +2 -1
- package/lib/commands/functions-secrets-destroy.js +2 -1
- package/lib/commands/functions-secrets-get.js +2 -1
- package/lib/commands/functions-secrets-prune.js +2 -1
- package/lib/commands/functions-secrets-set.js +2 -1
- package/lib/commands/functions-shell.js +12 -10
- package/lib/commands/help.js +2 -1
- package/lib/commands/hosting-channel-create.js +2 -1
- package/lib/commands/hosting-channel-delete.js +2 -1
- package/lib/commands/hosting-channel-deploy.js +2 -1
- package/lib/commands/hosting-channel-list.js +2 -1
- package/lib/commands/hosting-channel-open.js +2 -1
- package/lib/commands/hosting-clone.js +2 -1
- package/lib/commands/hosting-disable.js +2 -1
- package/lib/commands/hosting-sites-create.js +2 -1
- package/lib/commands/hosting-sites-delete.js +2 -1
- package/lib/commands/hosting-sites-get.js +2 -1
- package/lib/commands/hosting-sites-list.js +2 -1
- package/lib/commands/index.js +23 -13
- package/lib/commands/init.js +47 -43
- package/lib/commands/login-add.js +2 -1
- package/lib/commands/login-ci.js +2 -1
- package/lib/commands/login-list.js +2 -1
- package/lib/commands/login-use.js +2 -1
- package/lib/commands/login.js +2 -1
- package/lib/commands/logout.js +2 -1
- package/lib/commands/open.js +2 -1
- package/lib/commands/projects-addfirebase.js +2 -1
- package/lib/commands/projects-create.js +2 -1
- package/lib/commands/projects-list.js +2 -1
- package/lib/commands/remoteconfig-get.js +2 -1
- package/lib/commands/remoteconfig-rollback.js +2 -1
- package/lib/commands/remoteconfig-versions-list.js +2 -1
- package/lib/commands/serve.js +29 -27
- package/lib/commands/setup-emulators-database.js +2 -1
- package/lib/commands/setup-emulators-firestore.js +2 -1
- package/lib/commands/setup-emulators-pubsub.js +2 -1
- package/lib/commands/setup-emulators-storage.js +2 -1
- package/lib/commands/setup-emulators-ui.js +2 -1
- package/lib/commands/target-apply.js +2 -1
- package/lib/commands/target-clear.js +2 -1
- package/lib/commands/target-remove.js +2 -1
- package/lib/commands/target.js +2 -1
- package/lib/commands/use.js +54 -52
- package/lib/config.js +3 -3
- package/lib/deploy/database/deploy.js +3 -2
- package/lib/deploy/database/index.js +8 -5
- package/lib/deploy/database/prepare.js +22 -19
- package/lib/deploy/database/release.js +12 -9
- package/lib/deploy/firestore/prepare.js +2 -2
- package/lib/deploy/functions/build.js +32 -20
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +187 -54
- package/lib/deploy/functions/runtimes/node/parseTriggers.js +14 -2
- package/lib/deploy/functions/services/database.js +14 -0
- package/lib/deploy/functions/services/index.js +14 -0
- package/lib/deploy/index.js +3 -3
- package/lib/deploy/lifecycleHooks.js +23 -20
- package/lib/deploy/remoteconfig/functions.js +18 -14
- package/lib/deploy/remoteconfig/prepare.js +2 -2
- package/lib/emulator/auth/apiSpec.js +14 -46
- package/lib/emulator/auth/operations.js +6 -29
- package/lib/emulator/auth/state.js +2 -25
- package/lib/emulator/commandUtils.js +1 -1
- package/lib/emulator/controller.js +3 -3
- package/lib/emulator/databaseEmulator.js +9 -7
- package/lib/emulator/downloadableEmulators.js +6 -6
- package/lib/emulator/extensionsEmulator.js +7 -3
- package/lib/emulator/firestoreEmulator.js +10 -12
- package/lib/emulator/functionsEmulator.js +39 -42
- package/lib/emulator/hubClient.js +11 -22
- package/lib/emulator/hubExport.js +26 -16
- package/lib/emulator/portUtils.js +2 -0
- package/lib/emulator/storage/crc.js +3 -0
- package/lib/emulator/storage/rules/runtime.js +1 -1
- package/lib/errorOut.js +2 -2
- package/lib/extensions/extensionsHelper.js +4 -5
- package/lib/extensions/manifest.js +5 -11
- package/lib/firebaseConfigValidate.js +1 -1
- package/lib/firestore/checkDatabaseType.js +4 -5
- package/lib/firestore/indexes.js +17 -34
- package/lib/functions/events/v2.js +7 -1
- package/lib/functionsConfigClone.js +43 -41
- package/lib/gcp/cloudfunctionsv2.js +17 -2
- package/lib/gcp/iam.js +1 -1
- package/lib/gcp/index.js +10 -10
- package/lib/gcp/runtimeconfig.js +45 -47
- package/lib/gcp/storage.js +2 -4
- package/lib/hosting/cloudRunProxy.js +19 -15
- package/lib/index.js +29 -28
- package/lib/init/features/database.js +11 -5
- package/lib/init/features/functions/index.js +1 -1
- package/lib/init/features/functions/javascript.js +23 -20
- package/lib/init/features/functions/npm-dependencies.js +17 -14
- package/lib/init/features/functions/typescript.js +27 -24
- package/lib/init/features/hosting/github.js +5 -4
- package/lib/loadCJSON.js +9 -6
- package/lib/logError.js +15 -12
- package/lib/management/apps.js +47 -43
- package/lib/management/database.js +33 -31
- package/lib/management/projects.js +13 -7
- package/lib/parseBoltRules.js +15 -14
- package/lib/profileReport.js +503 -511
- package/lib/profiler.js +4 -4
- package/lib/requireAuth.js +0 -1
- package/lib/responseToError.js +8 -5
- package/lib/rtdb.js +31 -29
- package/lib/scopes.js +9 -9
- package/npm-shrinkwrap.json +1485 -670
- package/package.json +21 -22
- package/standalone/package.json +1 -1
package/README.md
CHANGED
|
@@ -136,15 +136,21 @@ Detailed doc is [here](https://firebase.google.com/docs/cli/auth).
|
|
|
136
136
|
|
|
137
137
|
### Cloud Functions Commands
|
|
138
138
|
|
|
139
|
-
| Command
|
|
140
|
-
|
|
|
141
|
-
| **functions:log**
|
|
142
|
-
| **functions:
|
|
143
|
-
| **functions:config:
|
|
144
|
-
| **functions:config:
|
|
145
|
-
| **functions:config:
|
|
146
|
-
| **functions:
|
|
147
|
-
| **functions:
|
|
139
|
+
| Command | Description |
|
|
140
|
+
| ----------------------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
141
|
+
| **functions:log** | Read logs from deployed Cloud Functions. |
|
|
142
|
+
| **functions:list** | List all deployed functions in your Firebase project. |
|
|
143
|
+
| **functions:config:set** | Store runtime configuration values for the current project's Cloud Functions. |
|
|
144
|
+
| **functions:config:get** | Retrieve existing configuration values for the current project's Cloud Functions. |
|
|
145
|
+
| **functions:config:unset** | Remove values from the current project's runtime configuration. |
|
|
146
|
+
| **functions:config:clone** | Copy runtime configuration from one project environment to another. |
|
|
147
|
+
| **functions:secrets:set** | Create or update a secret for use in Cloud Functions for Firebase. |
|
|
148
|
+
| **functions:secrets:get** | Get metadata for secret and its versions. |
|
|
149
|
+
| **functions:secrets:access** | Access secret value given secret and its version. Defaults to accessing the latest version. |
|
|
150
|
+
| **functions:secrets:prune** | Destroys unused secrets. |
|
|
151
|
+
| **functions:secrets:destroy** | Destroy a secret. Defaults to destroying the latest version. |
|
|
152
|
+
| **functions:delete** | Delete one or more Cloud Functions by name or group name. |
|
|
153
|
+
| **functions:shell** | Locally emulate functions and start Node.js shell where these local functions can be invoked with test data. |
|
|
148
154
|
|
|
149
155
|
### Hosting Commands
|
|
150
156
|
|
package/lib/accountImporter.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serialImportUsers = exports.validateUserJson = exports.validateOptions = exports.transArrayToUser = void 0;
|
|
4
|
+
const clc = require("cli-color");
|
|
5
|
+
const _ = require("lodash");
|
|
6
|
+
const apiv2_1 = require("./apiv2");
|
|
7
|
+
const api_1 = require("./api");
|
|
8
|
+
const logger_1 = require("./logger");
|
|
9
|
+
const error_1 = require("./error");
|
|
10
|
+
const utils = require("./utils");
|
|
11
|
+
const apiClient = new apiv2_1.Client({
|
|
12
|
+
urlPrefix: api_1.googleOrigin,
|
|
11
13
|
});
|
|
12
|
-
|
|
14
|
+
const ALLOWED_JSON_KEYS = [
|
|
13
15
|
"localId",
|
|
14
16
|
"email",
|
|
15
17
|
"emailVerified",
|
|
@@ -24,22 +26,22 @@ var ALLOWED_JSON_KEYS = [
|
|
|
24
26
|
"disabled",
|
|
25
27
|
"customAttributes",
|
|
26
28
|
];
|
|
27
|
-
|
|
29
|
+
const ALLOWED_JSON_KEYS_RENAMING = {
|
|
28
30
|
lastSignedInAt: "lastLoginAt",
|
|
29
31
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (str.length < expected.length && str.
|
|
32
|
+
const ALLOWED_PROVIDER_USER_INFO_KEYS = ["providerId", "rawId", "email", "displayName", "photoUrl"];
|
|
33
|
+
const ALLOWED_PROVIDER_IDS = ["google.com", "facebook.com", "twitter.com", "github.com"];
|
|
34
|
+
function isValidBase64(str) {
|
|
35
|
+
const expected = Buffer.from(str, "base64").toString("base64");
|
|
36
|
+
if (str.length < expected.length && !str.endsWith("=")) {
|
|
35
37
|
str += "=".repeat(expected.length - str.length);
|
|
36
38
|
}
|
|
37
39
|
return expected === str;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return data.
|
|
41
|
-
}
|
|
42
|
-
|
|
40
|
+
}
|
|
41
|
+
function toWebSafeBase64(data) {
|
|
42
|
+
return data.replace(/\//g, "_").replace(/\+/g, "-");
|
|
43
|
+
}
|
|
44
|
+
function addProviderUserInfo(user, providerId, arr) {
|
|
43
45
|
if (arr[0]) {
|
|
44
46
|
user.providerUserInfo.push({
|
|
45
47
|
providerId: providerId,
|
|
@@ -49,17 +51,17 @@ var _addProviderUserInfo = function (user, providerId, arr) {
|
|
|
49
51
|
photoUrl: arr[3],
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
users: accounts.map(
|
|
54
|
+
}
|
|
55
|
+
function genUploadAccountPostBody(projectId, accounts, hashOptions) {
|
|
56
|
+
const postBody = {
|
|
57
|
+
users: accounts.map((account) => {
|
|
56
58
|
if (account.passwordHash) {
|
|
57
|
-
account.passwordHash =
|
|
59
|
+
account.passwordHash = toWebSafeBase64(account.passwordHash);
|
|
58
60
|
}
|
|
59
61
|
if (account.salt) {
|
|
60
|
-
account.salt =
|
|
62
|
+
account.salt = toWebSafeBase64(account.salt);
|
|
61
63
|
}
|
|
62
|
-
_.each(ALLOWED_JSON_KEYS_RENAMING,
|
|
64
|
+
_.each(ALLOWED_JSON_KEYS_RENAMING, (value, key) => {
|
|
63
65
|
if (account[key]) {
|
|
64
66
|
account[value] = account[key];
|
|
65
67
|
delete account[key];
|
|
@@ -72,10 +74,10 @@ var _genUploadAccountPostBody = function (projectId, accounts, hashOptions) {
|
|
|
72
74
|
postBody.hashAlgorithm = hashOptions.hashAlgo;
|
|
73
75
|
}
|
|
74
76
|
if (hashOptions.hashKey) {
|
|
75
|
-
postBody.signerKey =
|
|
77
|
+
postBody.signerKey = toWebSafeBase64(hashOptions.hashKey);
|
|
76
78
|
}
|
|
77
79
|
if (hashOptions.saltSeparator) {
|
|
78
|
-
postBody.saltSeparator =
|
|
80
|
+
postBody.saltSeparator = toWebSafeBase64(hashOptions.saltSeparator);
|
|
79
81
|
}
|
|
80
82
|
if (hashOptions.rounds) {
|
|
81
83
|
postBody.rounds = hashOptions.rounds;
|
|
@@ -100,9 +102,9 @@ var _genUploadAccountPostBody = function (projectId, accounts, hashOptions) {
|
|
|
100
102
|
}
|
|
101
103
|
postBody.targetProjectId = projectId;
|
|
102
104
|
return postBody;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
}
|
|
106
|
+
function transArrayToUser(arr) {
|
|
107
|
+
const user = {
|
|
106
108
|
localId: arr[0],
|
|
107
109
|
email: arr[1],
|
|
108
110
|
emailVerified: arr[2] === "true",
|
|
@@ -117,45 +119,47 @@ var transArrayToUser = function (arr) {
|
|
|
117
119
|
disabled: arr[26],
|
|
118
120
|
customAttributes: arr[27],
|
|
119
121
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (user.passwordHash && !
|
|
122
|
+
addProviderUserInfo(user, "google.com", arr.slice(7, 11));
|
|
123
|
+
addProviderUserInfo(user, "facebook.com", arr.slice(11, 15));
|
|
124
|
+
addProviderUserInfo(user, "twitter.com", arr.slice(15, 19));
|
|
125
|
+
addProviderUserInfo(user, "github.com", arr.slice(19, 23));
|
|
126
|
+
if (user.passwordHash && !isValidBase64(user.passwordHash)) {
|
|
125
127
|
return {
|
|
126
128
|
error: "Password hash should be base64 encoded.",
|
|
127
129
|
};
|
|
128
130
|
}
|
|
129
|
-
if (user.salt && !
|
|
131
|
+
if (user.salt && !isValidBase64(user.salt)) {
|
|
130
132
|
return {
|
|
131
133
|
error: "Password salt should be base64 encoded.",
|
|
132
134
|
};
|
|
133
135
|
}
|
|
134
136
|
return user;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
}
|
|
138
|
+
exports.transArrayToUser = transArrayToUser;
|
|
139
|
+
function validateOptions(options) {
|
|
140
|
+
const hashOptions = validateRequiredParameters(options);
|
|
138
141
|
if (!hashOptions.valid) {
|
|
139
142
|
return hashOptions;
|
|
140
143
|
}
|
|
141
|
-
|
|
144
|
+
const hashInputOrder = options.hashInputOrder ? options.hashInputOrder.toUpperCase() : undefined;
|
|
142
145
|
if (hashInputOrder) {
|
|
143
|
-
if (hashInputOrder
|
|
144
|
-
throw new FirebaseError("Unknown password hash order flag"
|
|
146
|
+
if (hashInputOrder !== "SALT_FIRST" && hashInputOrder !== "PASSWORD_FIRST") {
|
|
147
|
+
throw new error_1.FirebaseError("Unknown password hash order flag");
|
|
145
148
|
}
|
|
146
149
|
else {
|
|
147
150
|
hashOptions["passwordHashOrder"] =
|
|
148
|
-
hashInputOrder
|
|
151
|
+
hashInputOrder === "SALT_FIRST" ? "SALT_AND_PASSWORD" : "PASSWORD_AND_SALT";
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
return hashOptions;
|
|
152
|
-
}
|
|
153
|
-
|
|
155
|
+
}
|
|
156
|
+
exports.validateOptions = validateOptions;
|
|
157
|
+
function validateRequiredParameters(options) {
|
|
154
158
|
if (!options.hashAlgo) {
|
|
155
159
|
utils.logWarning("No hash algorithm specified. Password users cannot be imported.");
|
|
156
160
|
return { valid: true };
|
|
157
161
|
}
|
|
158
|
-
|
|
162
|
+
const hashAlgo = options.hashAlgo.toUpperCase();
|
|
159
163
|
let roundsNum;
|
|
160
164
|
switch (hashAlgo) {
|
|
161
165
|
case "HMAC_SHA512":
|
|
@@ -163,7 +167,7 @@ var _validateRequiredParameters = function (options) {
|
|
|
163
167
|
case "HMAC_SHA1":
|
|
164
168
|
case "HMAC_MD5":
|
|
165
169
|
if (!options.hashKey || options.hashKey === "") {
|
|
166
|
-
throw new FirebaseError("Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo
|
|
170
|
+
throw new error_1.FirebaseError("Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo);
|
|
167
171
|
}
|
|
168
172
|
return { hashAlgo: hashAlgo, hashKey: options.hashKey, valid: true };
|
|
169
173
|
case "MD5":
|
|
@@ -171,31 +175,31 @@ var _validateRequiredParameters = function (options) {
|
|
|
171
175
|
case "SHA256":
|
|
172
176
|
case "SHA512":
|
|
173
177
|
roundsNum = parseInt(options.rounds, 10);
|
|
174
|
-
|
|
178
|
+
const minRounds = hashAlgo === "MD5" ? 0 : 1;
|
|
175
179
|
if (isNaN(roundsNum) || roundsNum < minRounds || roundsNum > 8192) {
|
|
176
|
-
throw new FirebaseError(`Must provide valid rounds(${minRounds}..8192) for hash algorithm ${options.hashAlgo}
|
|
180
|
+
throw new error_1.FirebaseError(`Must provide valid rounds(${minRounds}..8192) for hash algorithm ${options.hashAlgo}`);
|
|
177
181
|
}
|
|
178
182
|
return { hashAlgo: hashAlgo, rounds: options.rounds, valid: true };
|
|
179
183
|
case "PBKDF_SHA1":
|
|
180
184
|
case "PBKDF2_SHA256":
|
|
181
185
|
roundsNum = parseInt(options.rounds, 10);
|
|
182
186
|
if (isNaN(roundsNum) || roundsNum < 0 || roundsNum > 120000) {
|
|
183
|
-
throw new FirebaseError("Must provide valid rounds(0..120000) for hash algorithm " + options.hashAlgo
|
|
187
|
+
throw new error_1.FirebaseError("Must provide valid rounds(0..120000) for hash algorithm " + options.hashAlgo);
|
|
184
188
|
}
|
|
185
189
|
return { hashAlgo: hashAlgo, rounds: options.rounds, valid: true };
|
|
186
190
|
case "SCRYPT":
|
|
187
191
|
if (!options.hashKey || options.hashKey === "") {
|
|
188
|
-
throw new FirebaseError("Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo
|
|
192
|
+
throw new error_1.FirebaseError("Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo);
|
|
189
193
|
}
|
|
190
194
|
roundsNum = parseInt(options.rounds, 10);
|
|
191
195
|
if (isNaN(roundsNum) || roundsNum <= 0 || roundsNum > 8) {
|
|
192
|
-
throw new FirebaseError("Must provide valid rounds(1..8) for hash algorithm " + options.hashAlgo
|
|
196
|
+
throw new error_1.FirebaseError("Must provide valid rounds(1..8) for hash algorithm " + options.hashAlgo);
|
|
193
197
|
}
|
|
194
|
-
|
|
198
|
+
const memCost = parseInt(options.memCost, 10);
|
|
195
199
|
if (isNaN(memCost) || memCost <= 0 || memCost > 14) {
|
|
196
|
-
throw new FirebaseError("Must provide valid memory cost(1..14) for hash algorithm " + options.hashAlgo
|
|
200
|
+
throw new error_1.FirebaseError("Must provide valid memory cost(1..14) for hash algorithm " + options.hashAlgo);
|
|
197
201
|
}
|
|
198
|
-
|
|
202
|
+
let saltSeparator = "";
|
|
199
203
|
if (options.saltSeparator) {
|
|
200
204
|
saltSeparator = options.saltSeparator;
|
|
201
205
|
}
|
|
@@ -210,10 +214,10 @@ var _validateRequiredParameters = function (options) {
|
|
|
210
214
|
case "BCRYPT":
|
|
211
215
|
return { hashAlgo: hashAlgo, valid: true };
|
|
212
216
|
case "STANDARD_SCRYPT":
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
+
const cpuMemCost = parseInt(options.memCost, 10);
|
|
218
|
+
const parallelization = parseInt(options.parallelization, 10);
|
|
219
|
+
const blockSize = parseInt(options.blockSize, 10);
|
|
220
|
+
const dkLen = parseInt(options.dkLen, 10);
|
|
217
221
|
return {
|
|
218
222
|
hashAlgo: hashAlgo,
|
|
219
223
|
valid: true,
|
|
@@ -223,62 +227,63 @@ var _validateRequiredParameters = function (options) {
|
|
|
223
227
|
dkLen: dkLen,
|
|
224
228
|
};
|
|
225
229
|
default:
|
|
226
|
-
throw new FirebaseError("Unsupported hash algorithm " + clc.bold(options.hashAlgo));
|
|
230
|
+
throw new error_1.FirebaseError("Unsupported hash algorithm " + clc.bold(options.hashAlgo));
|
|
227
231
|
}
|
|
228
|
-
}
|
|
229
|
-
|
|
232
|
+
}
|
|
233
|
+
function validateProviderUserInfo(providerUserInfo) {
|
|
230
234
|
if (!_.includes(ALLOWED_PROVIDER_IDS, providerUserInfo.providerId)) {
|
|
231
235
|
return {
|
|
232
236
|
error: JSON.stringify(providerUserInfo, null, 2) + " has unsupported providerId",
|
|
233
237
|
};
|
|
234
238
|
}
|
|
235
|
-
|
|
239
|
+
const keydiff = _.difference(_.keys(providerUserInfo), ALLOWED_PROVIDER_USER_INFO_KEYS);
|
|
236
240
|
if (keydiff.length) {
|
|
237
241
|
return {
|
|
238
242
|
error: JSON.stringify(providerUserInfo, null, 2) + " has unsupported keys: " + keydiff.join(","),
|
|
239
243
|
};
|
|
240
244
|
}
|
|
241
245
|
return {};
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
246
|
+
}
|
|
247
|
+
function validateUserJson(userJson) {
|
|
248
|
+
const keydiff = _.difference(_.keys(userJson), ALLOWED_JSON_KEYS);
|
|
245
249
|
if (keydiff.length) {
|
|
246
250
|
return {
|
|
247
251
|
error: JSON.stringify(userJson, null, 2) + " has unsupported keys: " + keydiff.join(","),
|
|
248
252
|
};
|
|
249
253
|
}
|
|
250
254
|
if (userJson.providerUserInfo) {
|
|
251
|
-
for (
|
|
252
|
-
|
|
255
|
+
for (let i = 0; i < userJson.providerUserInfo.length; i++) {
|
|
256
|
+
const res = validateProviderUserInfo(userJson.providerUserInfo[i]);
|
|
253
257
|
if (res.error) {
|
|
254
258
|
return res;
|
|
255
259
|
}
|
|
256
260
|
}
|
|
257
261
|
}
|
|
258
|
-
|
|
259
|
-
if (userJson.passwordHash && !
|
|
262
|
+
const badFormat = JSON.stringify(userJson, null, 2) + " has invalid data format: ";
|
|
263
|
+
if (userJson.passwordHash && !isValidBase64(userJson.passwordHash)) {
|
|
260
264
|
return {
|
|
261
265
|
error: badFormat + "Password hash should be base64 encoded.",
|
|
262
266
|
};
|
|
263
267
|
}
|
|
264
|
-
if (userJson.salt && !
|
|
268
|
+
if (userJson.salt && !isValidBase64(userJson.salt)) {
|
|
265
269
|
return {
|
|
266
270
|
error: badFormat + "Password salt should be base64 encoded.",
|
|
267
271
|
};
|
|
268
272
|
}
|
|
269
273
|
return {};
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
+
}
|
|
275
|
+
exports.validateUserJson = validateUserJson;
|
|
276
|
+
async function sendRequest(projectId, userList, hashOptions) {
|
|
277
|
+
logger_1.logger.info("Starting importing " + userList.length + " account(s).");
|
|
278
|
+
const postData = genUploadAccountPostBody(projectId, userList, hashOptions);
|
|
274
279
|
return apiClient
|
|
275
280
|
.post("/identitytoolkit/v3/relyingparty/uploadAccount", postData, {
|
|
276
281
|
skipLog: { body: true },
|
|
277
282
|
})
|
|
278
|
-
.then(
|
|
283
|
+
.then((ret) => {
|
|
279
284
|
if (ret.body.error) {
|
|
280
|
-
logger.info("Encountered problems while importing accounts. Details:");
|
|
281
|
-
logger.info(ret.body.error.map(
|
|
285
|
+
logger_1.logger.info("Encountered problems while importing accounts. Details:");
|
|
286
|
+
logger_1.logger.info(ret.body.error.map((rawInfo) => {
|
|
282
287
|
return {
|
|
283
288
|
account: JSON.stringify(userList[parseInt(rawInfo.index, 10)], null, 2),
|
|
284
289
|
reason: rawInfo.message,
|
|
@@ -288,20 +293,14 @@ var _sendRequest = function (projectId, userList, hashOptions) {
|
|
|
288
293
|
else {
|
|
289
294
|
utils.logSuccess("Imported successfully.");
|
|
290
295
|
}
|
|
291
|
-
logger.info();
|
|
296
|
+
logger_1.logger.info();
|
|
292
297
|
});
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
return
|
|
298
|
+
}
|
|
299
|
+
function serialImportUsers(projectId, hashOptions, userListArr, index) {
|
|
300
|
+
return sendRequest(projectId, userListArr[index], hashOptions).then(() => {
|
|
296
301
|
if (index < userListArr.length - 1) {
|
|
297
302
|
return serialImportUsers(projectId, hashOptions, userListArr, index + 1);
|
|
298
303
|
}
|
|
299
304
|
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
validateOptions: validateOptions,
|
|
303
|
-
validateUserJson: validateUserJson,
|
|
304
|
-
transArrayToUser: transArrayToUser,
|
|
305
|
-
serialImportUsers: serialImportUsers,
|
|
306
|
-
};
|
|
307
|
-
module.exports = accountImporter;
|
|
305
|
+
}
|
|
306
|
+
exports.serialImportUsers = serialImportUsers;
|