firebase-tools 11.0.1 → 11.2.1

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 (214) hide show
  1. package/lib/accountExporter.js +11 -4
  2. package/lib/accountImporter.js +93 -95
  3. package/lib/api.js +77 -218
  4. package/lib/apiv2.js +5 -4
  5. package/lib/appdistribution/client.js +7 -9
  6. package/lib/auth.js +72 -52
  7. package/lib/bin/firebase.js +42 -47
  8. package/lib/checkValidTargetFilters.js +36 -25
  9. package/lib/commands/appdistribution-distribute.js +2 -1
  10. package/lib/commands/appdistribution-testers-add.js +2 -1
  11. package/lib/commands/appdistribution-testers-remove.js +2 -1
  12. package/lib/commands/apps-android-sha-create.js +2 -1
  13. package/lib/commands/apps-android-sha-delete.js +2 -1
  14. package/lib/commands/apps-android-sha-list.js +2 -1
  15. package/lib/commands/apps-create.js +2 -1
  16. package/lib/commands/apps-list.js +2 -1
  17. package/lib/commands/apps-sdkconfig.js +2 -1
  18. package/lib/commands/auth-export.js +2 -1
  19. package/lib/commands/auth-import.js +7 -10
  20. package/lib/commands/crashlytics-symbols-upload.js +2 -1
  21. package/lib/commands/database-get.js +4 -3
  22. package/lib/commands/database-instances-create.js +2 -1
  23. package/lib/commands/database-instances-list.js +3 -3
  24. package/lib/commands/database-profile.js +4 -4
  25. package/lib/commands/database-push.js +4 -4
  26. package/lib/commands/database-remove.js +3 -3
  27. package/lib/commands/database-rules-canary.js +2 -1
  28. package/lib/commands/database-rules-get.js +2 -1
  29. package/lib/commands/database-rules-list.js +2 -1
  30. package/lib/commands/database-rules-release.js +2 -1
  31. package/lib/commands/database-rules-stage.js +2 -1
  32. package/lib/commands/database-set.js +3 -3
  33. package/lib/commands/database-settings-get.js +2 -1
  34. package/lib/commands/database-settings-set.js +2 -1
  35. package/lib/commands/database-update.js +2 -1
  36. package/lib/commands/deploy.js +26 -25
  37. package/lib/commands/emulators-exec.js +2 -1
  38. package/lib/commands/emulators-export.js +2 -1
  39. package/lib/commands/emulators-start.js +2 -1
  40. package/lib/commands/experimental-functions-shell.js +10 -8
  41. package/lib/commands/ext-configure.js +2 -1
  42. package/lib/commands/ext-dev-deprecate.js +2 -1
  43. package/lib/commands/ext-dev-emulators-exec.js +3 -2
  44. package/lib/commands/ext-dev-emulators-start.js +3 -2
  45. package/lib/commands/ext-dev-extension-delete.js +2 -1
  46. package/lib/commands/ext-dev-init.js +2 -1
  47. package/lib/commands/ext-dev-list.js +8 -8
  48. package/lib/commands/ext-dev-publish.js +2 -1
  49. package/lib/commands/ext-dev-register.js +2 -1
  50. package/lib/commands/ext-dev-undeprecate.js +2 -1
  51. package/lib/commands/ext-dev-unpublish.js +2 -1
  52. package/lib/commands/ext-dev-usage.js +2 -1
  53. package/lib/commands/ext-export.js +2 -1
  54. package/lib/commands/ext-info.js +14 -14
  55. package/lib/commands/ext-install.js +2 -1
  56. package/lib/commands/ext-list.js +2 -1
  57. package/lib/commands/ext-sources-create.js +2 -1
  58. package/lib/commands/ext-uninstall.js +2 -1
  59. package/lib/commands/ext-update.js +2 -1
  60. package/lib/commands/ext.js +4 -4
  61. package/lib/commands/firestore-delete.js +2 -1
  62. package/lib/commands/firestore-indexes-list.js +2 -1
  63. package/lib/commands/functions-config-clone.js +4 -3
  64. package/lib/commands/functions-config-export.js +2 -1
  65. package/lib/commands/functions-config-get.js +2 -1
  66. package/lib/commands/functions-config-set.js +2 -1
  67. package/lib/commands/functions-config-unset.js +2 -1
  68. package/lib/commands/functions-delete.js +3 -8
  69. package/lib/commands/functions-deletegcfartifacts.js +2 -1
  70. package/lib/commands/functions-list.js +2 -1
  71. package/lib/commands/functions-log.js +2 -1
  72. package/lib/commands/functions-secrets-access.js +2 -1
  73. package/lib/commands/functions-secrets-destroy.js +2 -1
  74. package/lib/commands/functions-secrets-get.js +2 -1
  75. package/lib/commands/functions-secrets-prune.js +2 -1
  76. package/lib/commands/functions-secrets-set.js +2 -1
  77. package/lib/commands/functions-shell.js +12 -10
  78. package/lib/commands/help.js +2 -1
  79. package/lib/commands/hosting-channel-create.js +2 -1
  80. package/lib/commands/hosting-channel-delete.js +2 -1
  81. package/lib/commands/hosting-channel-deploy.js +2 -1
  82. package/lib/commands/hosting-channel-list.js +2 -1
  83. package/lib/commands/hosting-channel-open.js +2 -1
  84. package/lib/commands/hosting-clone.js +2 -1
  85. package/lib/commands/hosting-disable.js +2 -1
  86. package/lib/commands/hosting-sites-create.js +2 -1
  87. package/lib/commands/hosting-sites-delete.js +2 -1
  88. package/lib/commands/hosting-sites-get.js +2 -1
  89. package/lib/commands/hosting-sites-list.js +2 -1
  90. package/lib/commands/index.js +23 -13
  91. package/lib/commands/init.js +47 -43
  92. package/lib/commands/login-add.js +2 -1
  93. package/lib/commands/login-ci.js +2 -1
  94. package/lib/commands/login-list.js +2 -1
  95. package/lib/commands/login-use.js +2 -1
  96. package/lib/commands/login.js +2 -1
  97. package/lib/commands/logout.js +2 -1
  98. package/lib/commands/open.js +7 -7
  99. package/lib/commands/projects-addfirebase.js +2 -1
  100. package/lib/commands/projects-create.js +2 -1
  101. package/lib/commands/projects-list.js +2 -1
  102. package/lib/commands/remoteconfig-get.js +2 -1
  103. package/lib/commands/remoteconfig-rollback.js +2 -1
  104. package/lib/commands/remoteconfig-versions-list.js +2 -1
  105. package/lib/commands/serve.js +30 -30
  106. package/lib/commands/setup-emulators-database.js +2 -1
  107. package/lib/commands/setup-emulators-firestore.js +2 -1
  108. package/lib/commands/setup-emulators-pubsub.js +2 -1
  109. package/lib/commands/setup-emulators-storage.js +2 -1
  110. package/lib/commands/setup-emulators-ui.js +2 -1
  111. package/lib/commands/target-apply.js +2 -1
  112. package/lib/commands/target-clear.js +2 -1
  113. package/lib/commands/target-remove.js +2 -1
  114. package/lib/commands/target.js +2 -1
  115. package/lib/commands/use.js +54 -53
  116. package/lib/config.js +7 -6
  117. package/lib/deploy/database/deploy.js +3 -2
  118. package/lib/deploy/database/index.js +8 -5
  119. package/lib/deploy/database/prepare.js +22 -20
  120. package/lib/deploy/database/release.js +12 -9
  121. package/lib/deploy/extensions/secrets.js +3 -3
  122. package/lib/deploy/firestore/prepare.js +2 -2
  123. package/lib/deploy/functions/build.js +33 -20
  124. package/lib/deploy/functions/ensure.js +1 -11
  125. package/lib/deploy/functions/prepare.js +3 -13
  126. package/lib/deploy/functions/prepareFunctionsUpload.js +2 -3
  127. package/lib/deploy/functions/release/fabricator.js +0 -1
  128. package/lib/deploy/functions/release/index.js +1 -5
  129. package/lib/deploy/functions/runtimes/discovery/index.js +18 -3
  130. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +188 -54
  131. package/lib/deploy/functions/runtimes/golang/index.js +2 -22
  132. package/lib/deploy/functions/runtimes/node/index.js +3 -7
  133. package/lib/deploy/functions/runtimes/node/parseTriggers.js +16 -4
  134. package/lib/deploy/functions/services/database.js +14 -0
  135. package/lib/deploy/functions/services/index.js +14 -0
  136. package/lib/deploy/index.js +3 -3
  137. package/lib/deploy/lifecycleHooks.js +27 -27
  138. package/lib/deploy/remoteconfig/prepare.js +2 -2
  139. package/lib/deploy/storage/prepare.js +1 -1
  140. package/lib/emulator/auth/apiSpec.js +14 -46
  141. package/lib/emulator/auth/index.js +1 -1
  142. package/lib/emulator/auth/operations.js +342 -93
  143. package/lib/emulator/auth/server.js +2 -2
  144. package/lib/emulator/auth/state.js +34 -32
  145. package/lib/emulator/commandUtils.js +1 -1
  146. package/lib/emulator/constants.js +1 -1
  147. package/lib/emulator/controller.js +7 -6
  148. package/lib/emulator/databaseEmulator.js +4 -4
  149. package/lib/emulator/download.js +1 -1
  150. package/lib/emulator/downloadableEmulators.js +5 -5
  151. package/lib/emulator/events/types.js +2 -3
  152. package/lib/emulator/firestoreEmulator.js +2 -2
  153. package/lib/emulator/functionsEmulator.js +31 -45
  154. package/lib/emulator/functionsEmulatorRuntime.js +12 -16
  155. package/lib/emulator/functionsEmulatorShared.js +7 -5
  156. package/lib/emulator/functionsRuntimeWorker.js +0 -6
  157. package/lib/emulator/hostingEmulator.js +1 -1
  158. package/lib/emulator/hub.js +1 -1
  159. package/lib/emulator/loggingEmulator.js +1 -1
  160. package/lib/emulator/pubsubEmulator.js +1 -1
  161. package/lib/emulator/storage/crc.js +4 -4
  162. package/lib/emulator/storage/index.js +1 -1
  163. package/lib/emulator/types.js +1 -1
  164. package/lib/errorOut.js +2 -2
  165. package/lib/extensions/askUserForConsent.js +1 -2
  166. package/lib/extensions/askUserForParam.js +15 -18
  167. package/lib/extensions/emulator/optionsHelper.js +4 -4
  168. package/lib/extensions/extensionsApi.js +1 -22
  169. package/lib/extensions/extensionsHelper.js +6 -6
  170. package/lib/extensions/listExtensions.js +9 -10
  171. package/lib/extensions/manifest.js +2 -2
  172. package/lib/extensions/resolveSource.js +11 -7
  173. package/lib/extensions/secretsUtils.js +3 -3
  174. package/lib/extensions/types.js +24 -0
  175. package/lib/extensions/updateHelper.js +1 -1
  176. package/lib/extensions/utils.js +1 -2
  177. package/lib/extensions/warnings.js +3 -3
  178. package/lib/firestore/encodeFirestoreValue.js +11 -8
  179. package/lib/fsAsync.js +3 -3
  180. package/lib/functions/events/v2.js +7 -1
  181. package/lib/functionsConfig.js +17 -14
  182. package/lib/functionsConfigClone.js +46 -46
  183. package/lib/gcp/cloudfunctions.js +2 -15
  184. package/lib/gcp/cloudfunctionsv2.js +17 -2
  185. package/lib/gcp/iam.js +1 -1
  186. package/lib/gcp/index.js +10 -10
  187. package/lib/gcp/rules.js +1 -1
  188. package/lib/gcp/runtimeconfig.js +45 -47
  189. package/lib/hosting/proxy.js +1 -1
  190. package/lib/index.js +29 -28
  191. package/lib/init/features/database.js +10 -2
  192. package/lib/init/features/functions/index.js +1 -1
  193. package/lib/init/features/functions/javascript.js +23 -20
  194. package/lib/init/features/functions/npm-dependencies.js +17 -14
  195. package/lib/init/features/functions/typescript.js +27 -24
  196. package/lib/init/features/hosting/github.js +6 -5
  197. package/lib/init/features/hosting/index.js +2 -2
  198. package/lib/loadCJSON.js +9 -6
  199. package/lib/localFunction.js +4 -4
  200. package/lib/logError.js +15 -12
  201. package/lib/parseBoltRules.js +15 -14
  202. package/lib/previews.js +1 -1
  203. package/lib/profileReport.js +504 -512
  204. package/lib/profiler.js +4 -4
  205. package/lib/prompt.js +1 -2
  206. package/lib/rc.js +1 -1
  207. package/lib/requireAuth.js +0 -1
  208. package/lib/responseToError.js +8 -5
  209. package/lib/rulesDeploy.js +2 -2
  210. package/lib/scopes.js +9 -9
  211. package/lib/serve/index.js +4 -5
  212. package/lib/utils.js +30 -6
  213. package/npm-shrinkwrap.json +537 -193
  214. package/package.json +17 -14
@@ -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
- _.each(_.pick(user, EXPORTED_JSON_KEYS), (value, key) => {
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
- newUser.providerUserInfo.push(_.pick(providerInfo, EXPORTED_PROVIDER_USER_INFO_KEYS));
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
  }
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
- var clc = require("cli-color");
3
- var _ = require("lodash");
4
- const { Client } = require("./apiv2");
5
- const { googleOrigin } = require("./api");
6
- const { logger } = require("./logger");
7
- var { FirebaseError } = require("./error");
8
- var utils = require("./utils");
9
- const apiClient = new Client({
10
- urlPrefix: googleOrigin,
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
- var ALLOWED_JSON_KEYS = [
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
- var ALLOWED_JSON_KEYS_RENAMING = {
28
+ const ALLOWED_JSON_KEYS_RENAMING = {
28
29
  lastSignedInAt: "lastLoginAt",
29
30
  };
30
- var ALLOWED_PROVIDER_USER_INFO_KEYS = ["providerId", "rawId", "email", "displayName", "photoUrl"];
31
- var ALLOWED_PROVIDER_IDS = ["google.com", "facebook.com", "twitter.com", "github.com"];
32
- var _isValidBase64 = function (str) {
33
- var expected = Buffer.from(str, "base64").toString("base64");
34
- if (str.length < expected.length && str.slice(-1) !== "=") {
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
- var _toWebSafeBase64 = function (data) {
40
- return data.toString("base64").replace(/\//g, "_").replace(/\+/g, "-");
41
- };
42
- var _addProviderUserInfo = function (user, providerId, arr) {
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
- var _genUploadAccountPostBody = function (projectId, accounts, hashOptions) {
54
- var postBody = {
55
- users: accounts.map(function (account) {
53
+ }
54
+ function genUploadAccountPostBody(projectId, accounts, hashOptions) {
55
+ const postBody = {
56
+ users: accounts.map((account) => {
56
57
  if (account.passwordHash) {
57
- account.passwordHash = _toWebSafeBase64(account.passwordHash);
58
+ account.passwordHash = toWebSafeBase64(account.passwordHash);
58
59
  }
59
60
  if (account.salt) {
60
- account.salt = _toWebSafeBase64(account.salt);
61
+ account.salt = toWebSafeBase64(account.salt);
61
62
  }
62
- _.each(ALLOWED_JSON_KEYS_RENAMING, function (value, key) {
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 = _toWebSafeBase64(hashOptions.hashKey);
76
+ postBody.signerKey = toWebSafeBase64(hashOptions.hashKey);
76
77
  }
77
78
  if (hashOptions.saltSeparator) {
78
- postBody.saltSeparator = _toWebSafeBase64(hashOptions.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
- var transArrayToUser = function (arr) {
105
- var user = {
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
- _addProviderUserInfo(user, "google.com", arr.slice(7, 11));
121
- _addProviderUserInfo(user, "facebook.com", arr.slice(11, 15));
122
- _addProviderUserInfo(user, "twitter.com", arr.slice(15, 19));
123
- _addProviderUserInfo(user, "github.com", arr.slice(19, 23));
124
- if (user.passwordHash && !_isValidBase64(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 && !_isValidBase64(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
- var validateOptions = function (options) {
137
- var hashOptions = _validateRequiredParameters(options);
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
- var hashInputOrder = options.hashInputOrder ? options.hashInputOrder.toUpperCase() : undefined;
143
+ const hashInputOrder = options.hashInputOrder ? options.hashInputOrder.toUpperCase() : undefined;
142
144
  if (hashInputOrder) {
143
- if (hashInputOrder != "SALT_FIRST" && hashInputOrder != "PASSWORD_FIRST") {
144
- throw new FirebaseError("Unknown password hash order flag", { exit: 1 });
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 == "SALT_FIRST" ? "SALT_AND_PASSWORD" : "PASSWORD_AND_SALT";
150
+ hashInputOrder === "SALT_FIRST" ? "SALT_AND_PASSWORD" : "PASSWORD_AND_SALT";
149
151
  }
150
152
  }
151
153
  return hashOptions;
152
- };
153
- var _validateRequiredParameters = function (options) {
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
- var hashAlgo = options.hashAlgo.toUpperCase();
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, { exit: 1 });
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
- var minRounds = hashAlgo === "MD5" ? 0 : 1;
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}`, { exit: 1 });
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, { exit: 1 });
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, { exit: 1 });
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, { exit: 1 });
195
+ throw new error_1.FirebaseError("Must provide valid rounds(1..8) for hash algorithm " + options.hashAlgo);
193
196
  }
194
- var memCost = parseInt(options.memCost, 10);
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, { exit: 1 });
199
+ throw new error_1.FirebaseError("Must provide valid memory cost(1..14) for hash algorithm " + options.hashAlgo);
197
200
  }
198
- var saltSeparator = "";
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
- var cpuMemCost = parseInt(options.memCost, 10);
214
- var parallelization = parseInt(options.parallelization, 10);
215
- var blockSize = parseInt(options.blockSize, 10);
216
- var dkLen = parseInt(options.dkLen, 10);
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
- var _validateProviderUserInfo = function (providerUserInfo) {
230
- if (!_.includes(ALLOWED_PROVIDER_IDS, providerUserInfo.providerId)) {
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
- var keydiff = _.difference(_.keys(providerUserInfo), ALLOWED_PROVIDER_USER_INFO_KEYS);
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
- var validateUserJson = function (userJson) {
244
- var keydiff = _.difference(_.keys(userJson), ALLOWED_JSON_KEYS);
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 (var i = 0; i < userJson.providerUserInfo.length; i++) {
252
- var res = _validateProviderUserInfo(userJson.providerUserInfo[i]);
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
- var badFormat = JSON.stringify(userJson, null, 2) + " has invalid data format: ";
259
- if (userJson.passwordHash && !_isValidBase64(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 && !_isValidBase64(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
- var _sendRequest = function (projectId, userList, hashOptions) {
272
- logger.info("Starting importing " + userList.length + " account(s).");
273
- const postData = _genUploadAccountPostBody(projectId, userList, hashOptions);
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(function (ret) {
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(function (rawInfo) {
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
- var serialImportUsers = function (projectId, hashOptions, userListArr, index) {
295
- return _sendRequest(projectId, userListArr[index], hashOptions).then(function () {
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
- var accountImporter = {
302
- validateOptions: validateOptions,
303
- validateUserJson: validateUserJson,
304
- transArrayToUser: transArrayToUser,
305
- serialImportUsers: serialImportUsers,
306
- };
307
- module.exports = accountImporter;
304
+ }
305
+ exports.serialImportUsers = serialImportUsers;