firebase-tools 11.0.0 → 11.2.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/lib/accountExporter.js +11 -4
- package/lib/accountImporter.js +93 -95
- package/lib/api.js +77 -218
- package/lib/apiv2.js +5 -4
- package/lib/appdistribution/client.js +23 -34
- package/lib/auth.js +72 -52
- package/lib/bin/firebase.js +42 -47
- package/lib/checkValidTargetFilters.js +36 -25
- 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 +2 -1
- 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 +4 -4
- package/lib/commands/database-push.js +4 -4
- package/lib/commands/database-remove.js +3 -3
- 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 +3 -3
- 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 +26 -25
- 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 +6 -1
- package/lib/commands/ext-dev-deprecate.js +2 -1
- package/lib/commands/ext-dev-emulators-exec.js +3 -2
- package/lib/commands/ext-dev-emulators-start.js +3 -2
- 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 +8 -8
- 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 +14 -14
- package/lib/commands/ext-install.js +6 -1
- package/lib/commands/ext-list.js +2 -1
- package/lib/commands/ext-sources-create.js +2 -1
- package/lib/commands/ext-uninstall.js +7 -1
- package/lib/commands/ext-update.js +6 -1
- package/lib/commands/ext.js +4 -4
- 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 +3 -8
- 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 +7 -7
- 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 +30 -30
- 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 -53
- package/lib/config.js +7 -6
- package/lib/deploy/database/deploy.js +3 -2
- package/lib/deploy/database/index.js +8 -5
- package/lib/deploy/database/prepare.js +22 -20
- package/lib/deploy/database/release.js +12 -9
- package/lib/deploy/extensions/secrets.js +3 -3
- package/lib/deploy/firestore/prepare.js +2 -2
- package/lib/deploy/functions/build.js +33 -20
- package/lib/deploy/functions/ensure.js +1 -11
- package/lib/deploy/functions/prepare.js +3 -13
- package/lib/deploy/functions/prepareFunctionsUpload.js +2 -3
- package/lib/deploy/functions/release/fabricator.js +0 -1
- package/lib/deploy/functions/release/index.js +1 -5
- package/lib/deploy/functions/runtimes/discovery/index.js +18 -3
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +188 -54
- package/lib/deploy/functions/runtimes/golang/index.js +2 -22
- package/lib/deploy/functions/runtimes/node/index.js +3 -7
- package/lib/deploy/functions/runtimes/node/parseTriggers.js +15 -3
- 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 +27 -27
- package/lib/deploy/remoteconfig/functions.js +18 -14
- package/lib/deploy/remoteconfig/prepare.js +2 -2
- package/lib/deploy/storage/prepare.js +1 -1
- package/lib/emulator/auth/apiSpec.js +14 -46
- package/lib/emulator/auth/index.js +1 -1
- package/lib/emulator/auth/operations.js +342 -93
- package/lib/emulator/auth/server.js +2 -2
- package/lib/emulator/auth/state.js +34 -32
- package/lib/emulator/commandUtils.js +1 -1
- package/lib/emulator/constants.js +1 -1
- package/lib/emulator/controller.js +7 -6
- package/lib/emulator/databaseEmulator.js +11 -9
- package/lib/emulator/download.js +1 -1
- package/lib/emulator/events/types.js +2 -3
- package/lib/emulator/firestoreEmulator.js +12 -14
- package/lib/emulator/functionsEmulator.js +65 -77
- package/lib/emulator/functionsEmulatorRuntime.js +7 -7
- package/lib/emulator/hostingEmulator.js +1 -1
- package/lib/emulator/hub.js +1 -1
- package/lib/emulator/hubClient.js +11 -22
- package/lib/emulator/hubExport.js +26 -16
- package/lib/emulator/loggingEmulator.js +1 -1
- package/lib/emulator/pubsubEmulator.js +1 -1
- package/lib/emulator/storage/crc.js +4 -4
- package/lib/emulator/storage/index.js +1 -1
- package/lib/emulator/types.js +1 -1
- package/lib/errorOut.js +2 -2
- package/lib/extensions/askUserForConsent.js +1 -2
- package/lib/extensions/askUserForParam.js +15 -18
- package/lib/extensions/emulator/optionsHelper.js +4 -4
- package/lib/extensions/extensionsApi.js +1 -22
- package/lib/extensions/extensionsHelper.js +6 -6
- package/lib/extensions/listExtensions.js +9 -10
- package/lib/extensions/manifest.js +2 -2
- package/lib/extensions/resolveSource.js +11 -7
- package/lib/extensions/secretsUtils.js +3 -3
- package/lib/extensions/types.js +24 -0
- package/lib/extensions/updateHelper.js +1 -1
- package/lib/extensions/utils.js +1 -2
- package/lib/extensions/warnings.js +3 -3
- package/lib/firestore/checkDatabaseType.js +4 -5
- package/lib/firestore/encodeFirestoreValue.js +11 -8
- package/lib/firestore/indexes.js +17 -34
- package/lib/fsAsync.js +3 -3
- package/lib/functions/events/v2.js +7 -1
- package/lib/functionsConfig.js +17 -14
- package/lib/functionsConfigClone.js +46 -46
- package/lib/gcp/cloudfunctions.js +2 -15
- package/lib/gcp/cloudfunctionsv2.js +17 -2
- package/lib/gcp/iam.js +1 -1
- package/lib/gcp/index.js +10 -10
- package/lib/gcp/rules.js +1 -1
- package/lib/gcp/runtimeconfig.js +45 -47
- package/lib/gcp/storage.js +2 -4
- package/lib/hosting/cloudRunProxy.js +19 -15
- package/lib/hosting/proxy.js +1 -1
- 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 +6 -5
- package/lib/init/features/hosting/index.js +2 -2
- package/lib/loadCJSON.js +9 -6
- package/lib/localFunction.js +4 -4
- 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/previews.js +1 -1
- package/lib/profileReport.js +504 -512
- package/lib/profiler.js +4 -4
- package/lib/prompt.js +1 -2
- package/lib/rc.js +1 -1
- package/lib/requireAuth.js +0 -1
- package/lib/responseToError.js +8 -5
- package/lib/rtdb.js +31 -29
- package/lib/rulesDeploy.js +2 -2
- package/lib/scopes.js +9 -9
- package/lib/serve/index.js +4 -5
- package/lib/utils.js +30 -6
- package/npm-shrinkwrap.json +877 -279
- package/package.json +19 -16
- package/standalone/package.json +1 -1
package/lib/accountExporter.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serialExportUsers = exports.validateOptions = void 0;
|
|
4
|
-
const _ = require("lodash");
|
|
5
4
|
const os = require("os");
|
|
6
5
|
const path = require("path");
|
|
7
6
|
const apiv2_1 = require("./apiv2");
|
|
@@ -83,10 +82,14 @@ function transUserToArray(user) {
|
|
|
83
82
|
}
|
|
84
83
|
function transUserJson(user) {
|
|
85
84
|
const newUser = {};
|
|
86
|
-
|
|
85
|
+
const pickedUser = {};
|
|
86
|
+
for (const k of EXPORTED_JSON_KEYS) {
|
|
87
|
+
pickedUser[k] = user[k];
|
|
88
|
+
}
|
|
89
|
+
for (const [key, value] of Object.entries(pickedUser)) {
|
|
87
90
|
const newKey = EXPORTED_JSON_KEYS_RENAMING[key] || key;
|
|
88
91
|
newUser[newKey] = value;
|
|
89
|
-
}
|
|
92
|
+
}
|
|
90
93
|
if (newUser.passwordHash) {
|
|
91
94
|
newUser.passwordHash = convertToNormalBase64(newUser.passwordHash);
|
|
92
95
|
}
|
|
@@ -97,7 +100,11 @@ function transUserJson(user) {
|
|
|
97
100
|
newUser.providerUserInfo = [];
|
|
98
101
|
for (const providerInfo of user.providerUserInfo) {
|
|
99
102
|
if (PROVIDER_ID_INDEX_MAP.has(providerInfo.providerId)) {
|
|
100
|
-
|
|
103
|
+
const picked = {};
|
|
104
|
+
for (const k of EXPORTED_PROVIDER_USER_INFO_KEYS) {
|
|
105
|
+
picked[k] = providerInfo[k];
|
|
106
|
+
}
|
|
107
|
+
newUser.providerUserInfo.push(picked);
|
|
101
108
|
}
|
|
102
109
|
}
|
|
103
110
|
}
|
package/lib/accountImporter.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
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 apiv2_1 = require("./apiv2");
|
|
6
|
+
const api_1 = require("./api");
|
|
7
|
+
const logger_1 = require("./logger");
|
|
8
|
+
const error_1 = require("./error");
|
|
9
|
+
const utils = require("./utils");
|
|
10
|
+
const apiClient = new apiv2_1.Client({
|
|
11
|
+
urlPrefix: api_1.googleOrigin,
|
|
11
12
|
});
|
|
12
|
-
|
|
13
|
+
const ALLOWED_JSON_KEYS = [
|
|
13
14
|
"localId",
|
|
14
15
|
"email",
|
|
15
16
|
"emailVerified",
|
|
@@ -24,22 +25,22 @@ var ALLOWED_JSON_KEYS = [
|
|
|
24
25
|
"disabled",
|
|
25
26
|
"customAttributes",
|
|
26
27
|
];
|
|
27
|
-
|
|
28
|
+
const ALLOWED_JSON_KEYS_RENAMING = {
|
|
28
29
|
lastSignedInAt: "lastLoginAt",
|
|
29
30
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (str.length < expected.length && str.
|
|
31
|
+
const ALLOWED_PROVIDER_USER_INFO_KEYS = ["providerId", "rawId", "email", "displayName", "photoUrl"];
|
|
32
|
+
const ALLOWED_PROVIDER_IDS = ["google.com", "facebook.com", "twitter.com", "github.com"];
|
|
33
|
+
function isValidBase64(str) {
|
|
34
|
+
const expected = Buffer.from(str, "base64").toString("base64");
|
|
35
|
+
if (str.length < expected.length && !str.endsWith("=")) {
|
|
35
36
|
str += "=".repeat(expected.length - str.length);
|
|
36
37
|
}
|
|
37
38
|
return expected === str;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return data.
|
|
41
|
-
}
|
|
42
|
-
|
|
39
|
+
}
|
|
40
|
+
function toWebSafeBase64(data) {
|
|
41
|
+
return data.replace(/\//g, "_").replace(/\+/g, "-");
|
|
42
|
+
}
|
|
43
|
+
function addProviderUserInfo(user, providerId, arr) {
|
|
43
44
|
if (arr[0]) {
|
|
44
45
|
user.providerUserInfo.push({
|
|
45
46
|
providerId: providerId,
|
|
@@ -49,22 +50,22 @@ var _addProviderUserInfo = function (user, providerId, arr) {
|
|
|
49
50
|
photoUrl: arr[3],
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
users: accounts.map(
|
|
53
|
+
}
|
|
54
|
+
function genUploadAccountPostBody(projectId, accounts, hashOptions) {
|
|
55
|
+
const postBody = {
|
|
56
|
+
users: accounts.map((account) => {
|
|
56
57
|
if (account.passwordHash) {
|
|
57
|
-
account.passwordHash =
|
|
58
|
+
account.passwordHash = toWebSafeBase64(account.passwordHash);
|
|
58
59
|
}
|
|
59
60
|
if (account.salt) {
|
|
60
|
-
account.salt =
|
|
61
|
+
account.salt = toWebSafeBase64(account.salt);
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
+
for (const [key, value] of Object.entries(ALLOWED_JSON_KEYS_RENAMING)) {
|
|
63
64
|
if (account[key]) {
|
|
64
65
|
account[value] = account[key];
|
|
65
66
|
delete account[key];
|
|
66
67
|
}
|
|
67
|
-
}
|
|
68
|
+
}
|
|
68
69
|
return account;
|
|
69
70
|
}),
|
|
70
71
|
};
|
|
@@ -72,10 +73,10 @@ var _genUploadAccountPostBody = function (projectId, accounts, hashOptions) {
|
|
|
72
73
|
postBody.hashAlgorithm = hashOptions.hashAlgo;
|
|
73
74
|
}
|
|
74
75
|
if (hashOptions.hashKey) {
|
|
75
|
-
postBody.signerKey =
|
|
76
|
+
postBody.signerKey = toWebSafeBase64(hashOptions.hashKey);
|
|
76
77
|
}
|
|
77
78
|
if (hashOptions.saltSeparator) {
|
|
78
|
-
postBody.saltSeparator =
|
|
79
|
+
postBody.saltSeparator = toWebSafeBase64(hashOptions.saltSeparator);
|
|
79
80
|
}
|
|
80
81
|
if (hashOptions.rounds) {
|
|
81
82
|
postBody.rounds = hashOptions.rounds;
|
|
@@ -100,9 +101,9 @@ var _genUploadAccountPostBody = function (projectId, accounts, hashOptions) {
|
|
|
100
101
|
}
|
|
101
102
|
postBody.targetProjectId = projectId;
|
|
102
103
|
return postBody;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
}
|
|
105
|
+
function transArrayToUser(arr) {
|
|
106
|
+
const user = {
|
|
106
107
|
localId: arr[0],
|
|
107
108
|
email: arr[1],
|
|
108
109
|
emailVerified: arr[2] === "true",
|
|
@@ -117,45 +118,47 @@ var transArrayToUser = function (arr) {
|
|
|
117
118
|
disabled: arr[26],
|
|
118
119
|
customAttributes: arr[27],
|
|
119
120
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (user.passwordHash && !
|
|
121
|
+
addProviderUserInfo(user, "google.com", arr.slice(7, 11));
|
|
122
|
+
addProviderUserInfo(user, "facebook.com", arr.slice(11, 15));
|
|
123
|
+
addProviderUserInfo(user, "twitter.com", arr.slice(15, 19));
|
|
124
|
+
addProviderUserInfo(user, "github.com", arr.slice(19, 23));
|
|
125
|
+
if (user.passwordHash && !isValidBase64(user.passwordHash)) {
|
|
125
126
|
return {
|
|
126
127
|
error: "Password hash should be base64 encoded.",
|
|
127
128
|
};
|
|
128
129
|
}
|
|
129
|
-
if (user.salt && !
|
|
130
|
+
if (user.salt && !isValidBase64(user.salt)) {
|
|
130
131
|
return {
|
|
131
132
|
error: "Password salt should be base64 encoded.",
|
|
132
133
|
};
|
|
133
134
|
}
|
|
134
135
|
return user;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
}
|
|
137
|
+
exports.transArrayToUser = transArrayToUser;
|
|
138
|
+
function validateOptions(options) {
|
|
139
|
+
const hashOptions = validateRequiredParameters(options);
|
|
138
140
|
if (!hashOptions.valid) {
|
|
139
141
|
return hashOptions;
|
|
140
142
|
}
|
|
141
|
-
|
|
143
|
+
const hashInputOrder = options.hashInputOrder ? options.hashInputOrder.toUpperCase() : undefined;
|
|
142
144
|
if (hashInputOrder) {
|
|
143
|
-
if (hashInputOrder
|
|
144
|
-
throw new FirebaseError("Unknown password hash order flag"
|
|
145
|
+
if (hashInputOrder !== "SALT_FIRST" && hashInputOrder !== "PASSWORD_FIRST") {
|
|
146
|
+
throw new error_1.FirebaseError("Unknown password hash order flag");
|
|
145
147
|
}
|
|
146
148
|
else {
|
|
147
149
|
hashOptions["passwordHashOrder"] =
|
|
148
|
-
hashInputOrder
|
|
150
|
+
hashInputOrder === "SALT_FIRST" ? "SALT_AND_PASSWORD" : "PASSWORD_AND_SALT";
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
153
|
return hashOptions;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
+
}
|
|
155
|
+
exports.validateOptions = validateOptions;
|
|
156
|
+
function validateRequiredParameters(options) {
|
|
154
157
|
if (!options.hashAlgo) {
|
|
155
158
|
utils.logWarning("No hash algorithm specified. Password users cannot be imported.");
|
|
156
159
|
return { valid: true };
|
|
157
160
|
}
|
|
158
|
-
|
|
161
|
+
const hashAlgo = options.hashAlgo.toUpperCase();
|
|
159
162
|
let roundsNum;
|
|
160
163
|
switch (hashAlgo) {
|
|
161
164
|
case "HMAC_SHA512":
|
|
@@ -163,7 +166,7 @@ var _validateRequiredParameters = function (options) {
|
|
|
163
166
|
case "HMAC_SHA1":
|
|
164
167
|
case "HMAC_MD5":
|
|
165
168
|
if (!options.hashKey || options.hashKey === "") {
|
|
166
|
-
throw new FirebaseError("Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo
|
|
169
|
+
throw new error_1.FirebaseError("Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo);
|
|
167
170
|
}
|
|
168
171
|
return { hashAlgo: hashAlgo, hashKey: options.hashKey, valid: true };
|
|
169
172
|
case "MD5":
|
|
@@ -171,31 +174,31 @@ var _validateRequiredParameters = function (options) {
|
|
|
171
174
|
case "SHA256":
|
|
172
175
|
case "SHA512":
|
|
173
176
|
roundsNum = parseInt(options.rounds, 10);
|
|
174
|
-
|
|
177
|
+
const minRounds = hashAlgo === "MD5" ? 0 : 1;
|
|
175
178
|
if (isNaN(roundsNum) || roundsNum < minRounds || roundsNum > 8192) {
|
|
176
|
-
throw new FirebaseError(`Must provide valid rounds(${minRounds}..8192) for hash algorithm ${options.hashAlgo}
|
|
179
|
+
throw new error_1.FirebaseError(`Must provide valid rounds(${minRounds}..8192) for hash algorithm ${options.hashAlgo}`);
|
|
177
180
|
}
|
|
178
181
|
return { hashAlgo: hashAlgo, rounds: options.rounds, valid: true };
|
|
179
182
|
case "PBKDF_SHA1":
|
|
180
183
|
case "PBKDF2_SHA256":
|
|
181
184
|
roundsNum = parseInt(options.rounds, 10);
|
|
182
185
|
if (isNaN(roundsNum) || roundsNum < 0 || roundsNum > 120000) {
|
|
183
|
-
throw new FirebaseError("Must provide valid rounds(0..120000) for hash algorithm " + options.hashAlgo
|
|
186
|
+
throw new error_1.FirebaseError("Must provide valid rounds(0..120000) for hash algorithm " + options.hashAlgo);
|
|
184
187
|
}
|
|
185
188
|
return { hashAlgo: hashAlgo, rounds: options.rounds, valid: true };
|
|
186
189
|
case "SCRYPT":
|
|
187
190
|
if (!options.hashKey || options.hashKey === "") {
|
|
188
|
-
throw new FirebaseError("Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo
|
|
191
|
+
throw new error_1.FirebaseError("Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo);
|
|
189
192
|
}
|
|
190
193
|
roundsNum = parseInt(options.rounds, 10);
|
|
191
194
|
if (isNaN(roundsNum) || roundsNum <= 0 || roundsNum > 8) {
|
|
192
|
-
throw new FirebaseError("Must provide valid rounds(1..8) for hash algorithm " + options.hashAlgo
|
|
195
|
+
throw new error_1.FirebaseError("Must provide valid rounds(1..8) for hash algorithm " + options.hashAlgo);
|
|
193
196
|
}
|
|
194
|
-
|
|
197
|
+
const memCost = parseInt(options.memCost, 10);
|
|
195
198
|
if (isNaN(memCost) || memCost <= 0 || memCost > 14) {
|
|
196
|
-
throw new FirebaseError("Must provide valid memory cost(1..14) for hash algorithm " + options.hashAlgo
|
|
199
|
+
throw new error_1.FirebaseError("Must provide valid memory cost(1..14) for hash algorithm " + options.hashAlgo);
|
|
197
200
|
}
|
|
198
|
-
|
|
201
|
+
let saltSeparator = "";
|
|
199
202
|
if (options.saltSeparator) {
|
|
200
203
|
saltSeparator = options.saltSeparator;
|
|
201
204
|
}
|
|
@@ -210,10 +213,10 @@ var _validateRequiredParameters = function (options) {
|
|
|
210
213
|
case "BCRYPT":
|
|
211
214
|
return { hashAlgo: hashAlgo, valid: true };
|
|
212
215
|
case "STANDARD_SCRYPT":
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
216
|
+
const cpuMemCost = parseInt(options.memCost, 10);
|
|
217
|
+
const parallelization = parseInt(options.parallelization, 10);
|
|
218
|
+
const blockSize = parseInt(options.blockSize, 10);
|
|
219
|
+
const dkLen = parseInt(options.dkLen, 10);
|
|
217
220
|
return {
|
|
218
221
|
hashAlgo: hashAlgo,
|
|
219
222
|
valid: true,
|
|
@@ -223,62 +226,63 @@ var _validateRequiredParameters = function (options) {
|
|
|
223
226
|
dkLen: dkLen,
|
|
224
227
|
};
|
|
225
228
|
default:
|
|
226
|
-
throw new FirebaseError("Unsupported hash algorithm " + clc.bold(options.hashAlgo));
|
|
229
|
+
throw new error_1.FirebaseError("Unsupported hash algorithm " + clc.bold(options.hashAlgo));
|
|
227
230
|
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (!
|
|
231
|
+
}
|
|
232
|
+
function validateProviderUserInfo(providerUserInfo) {
|
|
233
|
+
if (!ALLOWED_PROVIDER_IDS.includes(providerUserInfo.providerId)) {
|
|
231
234
|
return {
|
|
232
235
|
error: JSON.stringify(providerUserInfo, null, 2) + " has unsupported providerId",
|
|
233
236
|
};
|
|
234
237
|
}
|
|
235
|
-
|
|
238
|
+
const keydiff = Object.keys(providerUserInfo).filter((k) => !ALLOWED_PROVIDER_USER_INFO_KEYS.includes(k));
|
|
236
239
|
if (keydiff.length) {
|
|
237
240
|
return {
|
|
238
241
|
error: JSON.stringify(providerUserInfo, null, 2) + " has unsupported keys: " + keydiff.join(","),
|
|
239
242
|
};
|
|
240
243
|
}
|
|
241
244
|
return {};
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
+
}
|
|
246
|
+
function validateUserJson(userJson) {
|
|
247
|
+
const keydiff = Object.keys(userJson).filter((k) => !ALLOWED_JSON_KEYS.includes(k));
|
|
245
248
|
if (keydiff.length) {
|
|
246
249
|
return {
|
|
247
250
|
error: JSON.stringify(userJson, null, 2) + " has unsupported keys: " + keydiff.join(","),
|
|
248
251
|
};
|
|
249
252
|
}
|
|
250
253
|
if (userJson.providerUserInfo) {
|
|
251
|
-
for (
|
|
252
|
-
|
|
254
|
+
for (let i = 0; i < userJson.providerUserInfo.length; i++) {
|
|
255
|
+
const res = validateProviderUserInfo(userJson.providerUserInfo[i]);
|
|
253
256
|
if (res.error) {
|
|
254
257
|
return res;
|
|
255
258
|
}
|
|
256
259
|
}
|
|
257
260
|
}
|
|
258
|
-
|
|
259
|
-
if (userJson.passwordHash && !
|
|
261
|
+
const badFormat = JSON.stringify(userJson, null, 2) + " has invalid data format: ";
|
|
262
|
+
if (userJson.passwordHash && !isValidBase64(userJson.passwordHash)) {
|
|
260
263
|
return {
|
|
261
264
|
error: badFormat + "Password hash should be base64 encoded.",
|
|
262
265
|
};
|
|
263
266
|
}
|
|
264
|
-
if (userJson.salt && !
|
|
267
|
+
if (userJson.salt && !isValidBase64(userJson.salt)) {
|
|
265
268
|
return {
|
|
266
269
|
error: badFormat + "Password salt should be base64 encoded.",
|
|
267
270
|
};
|
|
268
271
|
}
|
|
269
272
|
return {};
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
273
|
+
}
|
|
274
|
+
exports.validateUserJson = validateUserJson;
|
|
275
|
+
async function sendRequest(projectId, userList, hashOptions) {
|
|
276
|
+
logger_1.logger.info("Starting importing " + userList.length + " account(s).");
|
|
277
|
+
const postData = genUploadAccountPostBody(projectId, userList, hashOptions);
|
|
274
278
|
return apiClient
|
|
275
279
|
.post("/identitytoolkit/v3/relyingparty/uploadAccount", postData, {
|
|
276
280
|
skipLog: { body: true },
|
|
277
281
|
})
|
|
278
|
-
.then(
|
|
282
|
+
.then((ret) => {
|
|
279
283
|
if (ret.body.error) {
|
|
280
|
-
logger.info("Encountered problems while importing accounts. Details:");
|
|
281
|
-
logger.info(ret.body.error.map(
|
|
284
|
+
logger_1.logger.info("Encountered problems while importing accounts. Details:");
|
|
285
|
+
logger_1.logger.info(ret.body.error.map((rawInfo) => {
|
|
282
286
|
return {
|
|
283
287
|
account: JSON.stringify(userList[parseInt(rawInfo.index, 10)], null, 2),
|
|
284
288
|
reason: rawInfo.message,
|
|
@@ -288,20 +292,14 @@ var _sendRequest = function (projectId, userList, hashOptions) {
|
|
|
288
292
|
else {
|
|
289
293
|
utils.logSuccess("Imported successfully.");
|
|
290
294
|
}
|
|
291
|
-
logger.info();
|
|
295
|
+
logger_1.logger.info();
|
|
292
296
|
});
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
return
|
|
297
|
+
}
|
|
298
|
+
function serialImportUsers(projectId, hashOptions, userListArr, index) {
|
|
299
|
+
return sendRequest(projectId, userListArr[index], hashOptions).then(() => {
|
|
296
300
|
if (index < userListArr.length - 1) {
|
|
297
301
|
return serialImportUsers(projectId, hashOptions, userListArr, index + 1);
|
|
298
302
|
}
|
|
299
303
|
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
validateOptions: validateOptions,
|
|
303
|
-
validateUserJson: validateUserJson,
|
|
304
|
-
transArrayToUser: transArrayToUser,
|
|
305
|
-
serialImportUsers: serialImportUsers,
|
|
306
|
-
};
|
|
307
|
-
module.exports = accountImporter;
|
|
304
|
+
}
|
|
305
|
+
exports.serialImportUsers = serialImportUsers;
|