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.
Files changed (181) hide show
  1. package/README.md +15 -9
  2. package/lib/accountImporter.js +92 -93
  3. package/lib/api.js +77 -218
  4. package/lib/apiv2.js +5 -4
  5. package/lib/appdistribution/client.js +16 -25
  6. package/lib/auth.js +69 -47
  7. package/lib/bin/firebase.js +42 -47
  8. package/lib/checkValidTargetFilters.js +13 -12
  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 +8 -3
  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 +2 -1
  25. package/lib/commands/database-push.js +2 -1
  26. package/lib/commands/database-remove.js +2 -1
  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 +2 -1
  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 +23 -21
  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 +56 -120
  42. package/lib/commands/ext-dev-deprecate.js +2 -1
  43. package/lib/commands/ext-dev-emulators-exec.js +13 -7
  44. package/lib/commands/ext-dev-emulators-start.js +12 -27
  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 +2 -1
  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 +2 -1
  55. package/lib/commands/ext-install.js +14 -198
  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 +9 -92
  59. package/lib/commands/ext-update.js +67 -225
  60. package/lib/commands/ext.js +2 -1
  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 +2 -1
  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 +2 -1
  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 +29 -27
  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 -52
  116. package/lib/config.js +3 -3
  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 -19
  120. package/lib/deploy/database/release.js +12 -9
  121. package/lib/deploy/firestore/prepare.js +2 -2
  122. package/lib/deploy/functions/build.js +32 -20
  123. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +187 -54
  124. package/lib/deploy/functions/runtimes/node/parseTriggers.js +14 -2
  125. package/lib/deploy/functions/services/database.js +14 -0
  126. package/lib/deploy/functions/services/index.js +14 -0
  127. package/lib/deploy/index.js +3 -3
  128. package/lib/deploy/lifecycleHooks.js +23 -20
  129. package/lib/deploy/remoteconfig/functions.js +18 -14
  130. package/lib/deploy/remoteconfig/prepare.js +2 -2
  131. package/lib/emulator/auth/apiSpec.js +14 -46
  132. package/lib/emulator/auth/operations.js +6 -29
  133. package/lib/emulator/auth/state.js +2 -25
  134. package/lib/emulator/commandUtils.js +1 -1
  135. package/lib/emulator/controller.js +3 -3
  136. package/lib/emulator/databaseEmulator.js +9 -7
  137. package/lib/emulator/downloadableEmulators.js +6 -6
  138. package/lib/emulator/extensionsEmulator.js +7 -3
  139. package/lib/emulator/firestoreEmulator.js +10 -12
  140. package/lib/emulator/functionsEmulator.js +39 -42
  141. package/lib/emulator/hubClient.js +11 -22
  142. package/lib/emulator/hubExport.js +26 -16
  143. package/lib/emulator/portUtils.js +2 -0
  144. package/lib/emulator/storage/crc.js +3 -0
  145. package/lib/emulator/storage/rules/runtime.js +1 -1
  146. package/lib/errorOut.js +2 -2
  147. package/lib/extensions/extensionsHelper.js +4 -5
  148. package/lib/extensions/manifest.js +5 -11
  149. package/lib/firebaseConfigValidate.js +1 -1
  150. package/lib/firestore/checkDatabaseType.js +4 -5
  151. package/lib/firestore/indexes.js +17 -34
  152. package/lib/functions/events/v2.js +7 -1
  153. package/lib/functionsConfigClone.js +43 -41
  154. package/lib/gcp/cloudfunctionsv2.js +17 -2
  155. package/lib/gcp/iam.js +1 -1
  156. package/lib/gcp/index.js +10 -10
  157. package/lib/gcp/runtimeconfig.js +45 -47
  158. package/lib/gcp/storage.js +2 -4
  159. package/lib/hosting/cloudRunProxy.js +19 -15
  160. package/lib/index.js +29 -28
  161. package/lib/init/features/database.js +11 -5
  162. package/lib/init/features/functions/index.js +1 -1
  163. package/lib/init/features/functions/javascript.js +23 -20
  164. package/lib/init/features/functions/npm-dependencies.js +17 -14
  165. package/lib/init/features/functions/typescript.js +27 -24
  166. package/lib/init/features/hosting/github.js +5 -4
  167. package/lib/loadCJSON.js +9 -6
  168. package/lib/logError.js +15 -12
  169. package/lib/management/apps.js +47 -43
  170. package/lib/management/database.js +33 -31
  171. package/lib/management/projects.js +13 -7
  172. package/lib/parseBoltRules.js +15 -14
  173. package/lib/profileReport.js +503 -511
  174. package/lib/profiler.js +4 -4
  175. package/lib/requireAuth.js +0 -1
  176. package/lib/responseToError.js +8 -5
  177. package/lib/rtdb.js +31 -29
  178. package/lib/scopes.js +9 -9
  179. package/npm-shrinkwrap.json +1485 -670
  180. package/package.json +21 -22
  181. 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 | Description |
140
- | -------------------------- | ------------------------------------------------------------------------------------------------------------ |
141
- | **functions:log** | Read logs from deployed Cloud Functions. |
142
- | **functions:config:set** | Store runtime configuration values for the current project's Cloud Functions. |
143
- | **functions:config:get** | Retrieve existing configuration values for the current project's Cloud Functions. |
144
- | **functions:config:unset** | Remove values from the current project's runtime configuration. |
145
- | **functions:config:clone** | Copy runtime configuration from one project environment to another. |
146
- | **functions:delete** | Delete one or more Cloud Functions by name or group name. |
147
- | **functions:shell** | Locally emulate functions and start Node.js shell where these local functions can be invoked with test data. |
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
 
@@ -1,15 +1,17 @@
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 _ = 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
- var ALLOWED_JSON_KEYS = [
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
- var ALLOWED_JSON_KEYS_RENAMING = {
29
+ const ALLOWED_JSON_KEYS_RENAMING = {
28
30
  lastSignedInAt: "lastLoginAt",
29
31
  };
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) !== "=") {
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
- var _toWebSafeBase64 = function (data) {
40
- return data.toString("base64").replace(/\//g, "_").replace(/\+/g, "-");
41
- };
42
- var _addProviderUserInfo = function (user, providerId, arr) {
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
- var _genUploadAccountPostBody = function (projectId, accounts, hashOptions) {
54
- var postBody = {
55
- users: accounts.map(function (account) {
54
+ }
55
+ function genUploadAccountPostBody(projectId, accounts, hashOptions) {
56
+ const postBody = {
57
+ users: accounts.map((account) => {
56
58
  if (account.passwordHash) {
57
- account.passwordHash = _toWebSafeBase64(account.passwordHash);
59
+ account.passwordHash = toWebSafeBase64(account.passwordHash);
58
60
  }
59
61
  if (account.salt) {
60
- account.salt = _toWebSafeBase64(account.salt);
62
+ account.salt = toWebSafeBase64(account.salt);
61
63
  }
62
- _.each(ALLOWED_JSON_KEYS_RENAMING, function (value, key) {
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 = _toWebSafeBase64(hashOptions.hashKey);
77
+ postBody.signerKey = toWebSafeBase64(hashOptions.hashKey);
76
78
  }
77
79
  if (hashOptions.saltSeparator) {
78
- postBody.saltSeparator = _toWebSafeBase64(hashOptions.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
- var transArrayToUser = function (arr) {
105
- var user = {
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
- _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)) {
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 && !_isValidBase64(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
- var validateOptions = function (options) {
137
- var hashOptions = _validateRequiredParameters(options);
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
- var hashInputOrder = options.hashInputOrder ? options.hashInputOrder.toUpperCase() : undefined;
144
+ const hashInputOrder = options.hashInputOrder ? options.hashInputOrder.toUpperCase() : undefined;
142
145
  if (hashInputOrder) {
143
- if (hashInputOrder != "SALT_FIRST" && hashInputOrder != "PASSWORD_FIRST") {
144
- throw new FirebaseError("Unknown password hash order flag", { exit: 1 });
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 == "SALT_FIRST" ? "SALT_AND_PASSWORD" : "PASSWORD_AND_SALT";
151
+ hashInputOrder === "SALT_FIRST" ? "SALT_AND_PASSWORD" : "PASSWORD_AND_SALT";
149
152
  }
150
153
  }
151
154
  return hashOptions;
152
- };
153
- var _validateRequiredParameters = function (options) {
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
- var hashAlgo = options.hashAlgo.toUpperCase();
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, { exit: 1 });
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
- var minRounds = hashAlgo === "MD5" ? 0 : 1;
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}`, { exit: 1 });
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, { exit: 1 });
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, { exit: 1 });
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, { exit: 1 });
196
+ throw new error_1.FirebaseError("Must provide valid rounds(1..8) for hash algorithm " + options.hashAlgo);
193
197
  }
194
- var memCost = parseInt(options.memCost, 10);
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, { exit: 1 });
200
+ throw new error_1.FirebaseError("Must provide valid memory cost(1..14) for hash algorithm " + options.hashAlgo);
197
201
  }
198
- var saltSeparator = "";
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
- 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);
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
- var _validateProviderUserInfo = function (providerUserInfo) {
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
- var keydiff = _.difference(_.keys(providerUserInfo), ALLOWED_PROVIDER_USER_INFO_KEYS);
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
- var validateUserJson = function (userJson) {
244
- var keydiff = _.difference(_.keys(userJson), ALLOWED_JSON_KEYS);
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 (var i = 0; i < userJson.providerUserInfo.length; i++) {
252
- var res = _validateProviderUserInfo(userJson.providerUserInfo[i]);
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
- var badFormat = JSON.stringify(userJson, null, 2) + " has invalid data format: ";
259
- if (userJson.passwordHash && !_isValidBase64(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 && !_isValidBase64(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
- var _sendRequest = function (projectId, userList, hashOptions) {
272
- logger.info("Starting importing " + userList.length + " account(s).");
273
- const postData = _genUploadAccountPostBody(projectId, userList, hashOptions);
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(function (ret) {
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(function (rawInfo) {
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
- var serialImportUsers = function (projectId, hashOptions, userListArr, index) {
295
- return _sendRequest(projectId, userListArr[index], hashOptions).then(function () {
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
- var accountImporter = {
302
- validateOptions: validateOptions,
303
- validateUserJson: validateUserJson,
304
- transArrayToUser: transArrayToUser,
305
- serialImportUsers: serialImportUsers,
306
- };
307
- module.exports = accountImporter;
305
+ }
306
+ exports.serialImportUsers = serialImportUsers;