firebase-tools-with-isolate 13.15.0-0 → 13.26.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 (235) hide show
  1. package/lib/api.js +3 -1
  2. package/lib/apiv2.js +10 -3
  3. package/lib/appdistribution/client.js +62 -8
  4. package/lib/appdistribution/distribution.js +1 -1
  5. package/lib/apphosting/backend.js +299 -0
  6. package/lib/apphosting/config.js +31 -8
  7. package/lib/apphosting/githubConnections.js +70 -22
  8. package/lib/apphosting/index.js +3 -312
  9. package/lib/apphosting/rollout.js +138 -0
  10. package/lib/apphosting/secrets/index.js +70 -5
  11. package/lib/apphosting/utils.js +41 -0
  12. package/lib/apphosting/yaml.js +82 -0
  13. package/lib/archiveDirectory.js +1 -1
  14. package/lib/auth.js +31 -5
  15. package/lib/bin/firebase.js +2 -2
  16. package/lib/command.js +18 -4
  17. package/lib/commands/appdistribution-distribute.js +4 -4
  18. package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
  19. package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
  20. package/lib/commands/appdistribution-groups-list.js +55 -0
  21. package/lib/commands/appdistribution-testers-list.js +52 -0
  22. package/lib/commands/appdistribution-testers-remove.js +1 -1
  23. package/lib/commands/apphosting-backends-create.js +4 -4
  24. package/lib/commands/apphosting-backends-delete.js +7 -15
  25. package/lib/commands/apphosting-backends-get.js +1 -1
  26. package/lib/commands/apphosting-config-export.js +51 -0
  27. package/lib/commands/apphosting-repos-create.js +23 -0
  28. package/lib/commands/apphosting-rollouts-create.js +14 -15
  29. package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
  30. package/lib/commands/database-import.js +4 -2
  31. package/lib/commands/database-push.js +4 -2
  32. package/lib/commands/database-set.js +4 -2
  33. package/lib/commands/database-settings-get.js +1 -1
  34. package/lib/commands/database-settings-set.js +1 -1
  35. package/lib/commands/dataconnect-sdk-generate.js +4 -1
  36. package/lib/commands/dataconnect-services-list.js +4 -3
  37. package/lib/commands/dataconnect-sql-diff.js +1 -1
  38. package/lib/commands/dataconnect-sql-grant.js +37 -0
  39. package/lib/commands/dataconnect-sql-migrate.js +1 -1
  40. package/lib/commands/dataconnect-sql-shell.js +115 -0
  41. package/lib/commands/deploy.js +5 -1
  42. package/lib/commands/emulators-start.js +4 -1
  43. package/lib/commands/ext-dev-init.js +2 -2
  44. package/lib/commands/ext-dev-list.js +1 -1
  45. package/lib/commands/ext-dev-register.js +2 -2
  46. package/lib/commands/ext-dev-upload.js +2 -2
  47. package/lib/commands/ext-dev-usage.js +2 -2
  48. package/lib/commands/ext-info.js +3 -1
  49. package/lib/commands/ext-install.js +2 -2
  50. package/lib/commands/ext-sdk-install.js +88 -0
  51. package/lib/commands/ext.js +1 -0
  52. package/lib/commands/firestore-databases-restore.js +39 -1
  53. package/lib/commands/functions-secrets-access.js +2 -4
  54. package/lib/commands/index.js +15 -2
  55. package/lib/commands/init.js +25 -15
  56. package/lib/commands/setup-emulators-dataconnect.js +0 -13
  57. package/lib/commands/use.js +1 -1
  58. package/lib/config.js +14 -4
  59. package/lib/crashlytics/buildToolsJarHelper.js +2 -2
  60. package/lib/dataconnect/client.js +3 -2
  61. package/lib/dataconnect/dataplaneClient.js +12 -9
  62. package/lib/dataconnect/ensureApis.js +6 -1
  63. package/lib/dataconnect/fileUtils.js +29 -12
  64. package/lib/dataconnect/freeTrial.js +45 -9
  65. package/lib/dataconnect/load.js +3 -1
  66. package/lib/dataconnect/provisionCloudSql.js +41 -24
  67. package/lib/dataconnect/schemaMigration.js +215 -74
  68. package/lib/dataconnect/types.js +4 -1
  69. package/lib/dataconnect/webhook.js +32 -0
  70. package/lib/deploy/dataconnect/deploy.js +18 -15
  71. package/lib/deploy/dataconnect/prepare.js +41 -0
  72. package/lib/deploy/dataconnect/release.js +16 -7
  73. package/lib/deploy/extensions/deploy.js +3 -1
  74. package/lib/deploy/extensions/deploymentSummary.js +7 -3
  75. package/lib/deploy/extensions/planner.js +95 -5
  76. package/lib/deploy/extensions/prepare.js +89 -42
  77. package/lib/deploy/extensions/release.js +17 -10
  78. package/lib/deploy/extensions/tasks.js +32 -21
  79. package/lib/deploy/firestore/prepare.js +9 -0
  80. package/lib/deploy/firestore/release.js +3 -6
  81. package/lib/deploy/functions/build.js +5 -5
  82. package/lib/deploy/functions/checkIam.js +7 -2
  83. package/lib/deploy/functions/deploy.js +12 -12
  84. package/lib/deploy/functions/ensure.js +11 -3
  85. package/lib/deploy/functions/params.js +5 -3
  86. package/lib/deploy/functions/prepare.js +18 -3
  87. package/lib/deploy/functions/release/index.js +4 -0
  88. package/lib/deploy/functions/release/planner.js +2 -1
  89. package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
  90. package/lib/deploy/functions/runtimes/discovery/parsing.js +1 -1
  91. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +46 -0
  92. package/lib/deploy/functions/runtimes/node/index.js +5 -0
  93. package/lib/deploy/functions/services/auth.js +34 -3
  94. package/lib/deploy/functions/services/index.js +2 -0
  95. package/lib/deploy/index.js +8 -5
  96. package/lib/deploy/lifecycleHooks.js +2 -1
  97. package/lib/emulator/apphosting/config.js +27 -0
  98. package/lib/emulator/apphosting/index.js +38 -0
  99. package/lib/emulator/apphosting/serve.js +50 -0
  100. package/lib/emulator/apphosting/utils.js +18 -0
  101. package/lib/emulator/auth/handlers.js +27 -0
  102. package/lib/emulator/auth/operations.js +41 -2
  103. package/lib/emulator/auth/state.js +2 -1
  104. package/lib/emulator/commandUtils.js +8 -3
  105. package/lib/emulator/constants.js +11 -1
  106. package/lib/emulator/controller.js +59 -6
  107. package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
  108. package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
  109. package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
  110. package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
  111. package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
  112. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
  113. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
  114. package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
  115. package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
  116. package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
  117. package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
  118. package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
  119. package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
  120. package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
  121. package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
  122. package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
  123. package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
  124. package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
  125. package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
  126. package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
  127. package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
  128. package/lib/emulator/dataconnect/pgliteServer.js +95 -0
  129. package/lib/emulator/dataconnectEmulator.js +58 -75
  130. package/lib/emulator/dataconnectToolkitController.js +44 -0
  131. package/lib/emulator/downloadableEmulators.js +30 -19
  132. package/lib/emulator/emulatorLogger.js +3 -0
  133. package/lib/emulator/env.js +3 -0
  134. package/lib/emulator/eventarcEmulator.js +1 -1
  135. package/lib/emulator/extensionsEmulator.js +38 -6
  136. package/lib/emulator/functionsEmulator.js +115 -42
  137. package/lib/emulator/functionsEmulatorShared.js +18 -1
  138. package/lib/emulator/functionsRuntimeWorker.js +2 -1
  139. package/lib/emulator/hub.js +13 -9
  140. package/lib/emulator/hubExport.js +10 -3
  141. package/lib/emulator/loggingEmulator.js +2 -2
  142. package/lib/emulator/portUtils.js +11 -11
  143. package/lib/emulator/registry.js +2 -0
  144. package/lib/emulator/storage/persistence.js +2 -2
  145. package/lib/emulator/storage/rules/runtime.js +1 -1
  146. package/lib/emulator/taskQueue.js +348 -0
  147. package/lib/emulator/tasksEmulator.js +240 -0
  148. package/lib/emulator/types.js +6 -0
  149. package/lib/emulator/ui.js +51 -25
  150. package/lib/error.js +31 -1
  151. package/lib/experiments.js +5 -0
  152. package/lib/extensions/askUserForEventsConfig.js +18 -8
  153. package/lib/extensions/askUserForParam.js +2 -1
  154. package/lib/extensions/displayExtensionInfo.js +5 -5
  155. package/lib/extensions/emulator/triggerHelper.js +1 -1
  156. package/lib/extensions/extensionsApi.js +15 -11
  157. package/lib/extensions/extensionsHelper.js +39 -8
  158. package/lib/extensions/localHelper.js +32 -1
  159. package/lib/extensions/refs.js +26 -11
  160. package/lib/extensions/runtimes/common.js +215 -0
  161. package/lib/extensions/runtimes/node.js +401 -0
  162. package/lib/extensions/types.js +67 -1
  163. package/lib/extensions/warnings.js +5 -2
  164. package/lib/firestore/api.js +2 -1
  165. package/lib/firestore/checkDatabaseType.js +10 -3
  166. package/lib/firestore/delete.js +11 -0
  167. package/lib/firestore/options.js +7 -0
  168. package/lib/frameworks/angular/index.js +15 -3
  169. package/lib/frameworks/constants.js +2 -2
  170. package/lib/frameworks/flutter/index.js +6 -6
  171. package/lib/frameworks/flutter/utils.js +34 -1
  172. package/lib/frameworks/next/constants.js +1 -1
  173. package/lib/frameworks/next/index.js +45 -17
  174. package/lib/frameworks/next/utils.js +57 -4
  175. package/lib/frameworks/vite/index.js +2 -2
  176. package/lib/fsutils.js +13 -1
  177. package/lib/functions/constants.js +4 -0
  178. package/lib/functions/events/v1.js +9 -2
  179. package/lib/gcp/apphosting.js +1 -1
  180. package/lib/gcp/cloudmonitoring.js +3 -3
  181. package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
  182. package/lib/gcp/cloudsql/connect.js +49 -37
  183. package/lib/gcp/cloudsql/interactive.js +49 -0
  184. package/lib/gcp/cloudsql/permissions.js +165 -0
  185. package/lib/gcp/devConnect.js +38 -1
  186. package/lib/gcp/firestore.js +5 -1
  187. package/lib/gcp/secretManager.js +12 -5
  188. package/lib/getProjectNumber.js +1 -1
  189. package/lib/init/features/apphosting.js +15 -0
  190. package/lib/init/features/dataconnect/index.js +166 -121
  191. package/lib/init/features/dataconnect/sdk.js +90 -81
  192. package/lib/init/features/emulators.js +2 -15
  193. package/lib/init/features/firestore/index.js +20 -1
  194. package/lib/init/features/firestore/indexes.js +4 -4
  195. package/lib/init/features/genkit/index.js +444 -0
  196. package/lib/init/features/hosting/index.js +2 -2
  197. package/lib/init/features/index.js +1 -1
  198. package/lib/init/features/project.js +6 -6
  199. package/lib/init/features/storage.js +0 -2
  200. package/lib/init/index.js +1 -0
  201. package/lib/init/spawn.js +23 -2
  202. package/lib/logger.js +2 -2
  203. package/lib/management/projects.js +24 -4
  204. package/lib/projectUtils.js +1 -1
  205. package/lib/prompt.js +22 -1
  206. package/lib/rc.js +1 -8
  207. package/lib/requireAuth.js +19 -5
  208. package/lib/requireDatabaseInstance.js +1 -1
  209. package/lib/requirePermissions.js +1 -1
  210. package/lib/responseToError.js +5 -2
  211. package/lib/rulesDeploy.js +1 -1
  212. package/lib/templates.js +2 -2
  213. package/lib/utils.js +16 -11
  214. package/lib/vsCodeUtils.js +8 -0
  215. package/package.json +8 -7
  216. package/schema/connector-yaml.json +57 -17
  217. package/schema/firebase-config.json +36 -0
  218. package/templates/extensions/javascript/package.lint.json +2 -2
  219. package/templates/extensions/javascript/package.nolint.json +2 -2
  220. package/templates/extensions/typescript/package.lint.json +2 -2
  221. package/templates/extensions/typescript/package.nolint.json +2 -2
  222. package/templates/genkit/firebase.0.9.0.template +57 -0
  223. package/templates/init/apphosting/apphosting.yaml +23 -0
  224. package/templates/init/dataconnect/connector.yaml +4 -3
  225. package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
  226. package/templates/init/dataconnect/dataconnect.yaml +6 -6
  227. package/templates/init/dataconnect/mutations.gql +44 -29
  228. package/templates/init/dataconnect/queries.gql +65 -38
  229. package/templates/init/dataconnect/schema.gql +38 -21
  230. package/templates/init/functions/javascript/package.lint.json +2 -2
  231. package/templates/init/functions/javascript/package.nolint.json +2 -2
  232. package/templates/init/functions/typescript/package.lint.json +2 -2
  233. package/templates/init/functions/typescript/package.nolint.json +2 -2
  234. package/lib/ensureCloudResourceLocation.js +0 -12
  235. package/lib/init/features/genkit.js +0 -53
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SaslMechanism = void 0;
4
+ const message_codes_1 = require("../../message-codes");
5
+ const SaslMessageCode = {
6
+ AuthenticationSASL: 10,
7
+ AuthenticationSASLContinue: 11,
8
+ AuthenticationSASLFinal: 12,
9
+ };
10
+ class SaslMechanism {
11
+ constructor(params) {
12
+ this.writer = params.writer;
13
+ }
14
+ createAuthenticationSASL() {
15
+ const mechanisms = ['SCRAM-SHA-256'];
16
+ this.writer.addInt32(SaslMessageCode.AuthenticationSASL);
17
+ for (const mechanism of mechanisms) {
18
+ this.writer.addCString(mechanism);
19
+ }
20
+ this.writer.addCString('');
21
+ return this.writer.flush(message_codes_1.BackendMessageCode.AuthenticationResponse);
22
+ }
23
+ createAuthenticationSASLContinue(message) {
24
+ this.writer.addInt32(SaslMessageCode.AuthenticationSASLContinue);
25
+ this.writer.addString(message);
26
+ return this.writer.flush(message_codes_1.BackendMessageCode.AuthenticationResponse);
27
+ }
28
+ createAuthenticationSASLFinal(message) {
29
+ this.writer.addInt32(SaslMessageCode.AuthenticationSASLFinal);
30
+ this.writer.addString(message);
31
+ return this.writer.flush(message_codes_1.BackendMessageCode.AuthenticationResponse);
32
+ }
33
+ }
34
+ exports.SaslMechanism = SaslMechanism;
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeBase64 = exports.encodeBase64 = exports.ScramSha256AuthFlow = exports.verifyScramSha256Password = exports.createScramSha256Data = void 0;
4
+ const backend_error_1 = require("../../backend-error");
5
+ const connection_1 = require("../../connection");
6
+ const crypto_1 = require("../../crypto");
7
+ const sasl_mechanism_1 = require("./sasl-mechanism");
8
+ async function createScramSha256Data(password, iterations = 4096) {
9
+ const salt = new Uint8Array(16);
10
+ crypto.getRandomValues(salt);
11
+ const saltedPassword = await (0, crypto_1.pbkdf2)(password, salt, iterations, 32, 'SHA-256');
12
+ const clientKey = await (0, crypto_1.createHmacKey)(saltedPassword, 'Client Key', 'SHA-256');
13
+ const storedKey = await (0, crypto_1.createHashKey)(clientKey, 'SHA-256');
14
+ const serverKey = await (0, crypto_1.createHmacKey)(saltedPassword, 'Server Key', 'SHA-256');
15
+ return {
16
+ salt: encodeBase64(salt),
17
+ iterations,
18
+ storedKey: encodeBase64(storedKey),
19
+ serverKey: encodeBase64(serverKey),
20
+ };
21
+ }
22
+ exports.createScramSha256Data = createScramSha256Data;
23
+ async function verifyScramSha256Password(params) {
24
+ const { authMessage, clientProof, storedKey } = params;
25
+ const clientProofBuffer = decodeBase64(clientProof);
26
+ const storedKeyBuffer = decodeBase64(storedKey);
27
+ const clientSignature = await (0, crypto_1.createHmacKey)(storedKeyBuffer, authMessage, 'SHA-256');
28
+ const clientSignatureView = new Uint8Array(clientSignature);
29
+ const clientKey = new Uint8Array(clientProofBuffer.length);
30
+ for (let i = 0; i < clientProofBuffer.length; i++) {
31
+ clientKey[i] = clientProofBuffer[i] ^ clientSignatureView[i];
32
+ }
33
+ const computedStoredKey = await (0, crypto_1.createHashKey)(clientKey, 'SHA-256');
34
+ return await (0, crypto_1.timingSafeEqual)(storedKeyBuffer, computedStoredKey);
35
+ }
36
+ exports.verifyScramSha256Password = verifyScramSha256Password;
37
+ const ScramSha256Step = {
38
+ Initial: 'Initial',
39
+ ServerFirstMessage: 'ServerFirstMessage',
40
+ ServerFinalMessage: 'ServerFinalMessage',
41
+ Completed: 'Completed',
42
+ };
43
+ class ScramSha256AuthFlow extends sasl_mechanism_1.SaslMechanism {
44
+ constructor(params) {
45
+ super({ writer: params.writer });
46
+ this.step = ScramSha256Step.Initial;
47
+ this.username = params.username;
48
+ this.auth = {
49
+ ...params.auth,
50
+ validateCredentials: params.auth.validateCredentials ??
51
+ (async ({ authMessage, clientProof, scramSha256Data }) => {
52
+ return verifyScramSha256Password({
53
+ authMessage,
54
+ clientProof,
55
+ storedKey: scramSha256Data.storedKey,
56
+ });
57
+ }),
58
+ };
59
+ this.reader = params.reader;
60
+ this.connectionState = params.connectionState;
61
+ }
62
+ async getScramSha256Data(params) {
63
+ if (!this.scramSha256Data) {
64
+ this.scramSha256Data = await this.auth.getScramSha256Data(params, this.connectionState);
65
+ }
66
+ return this.scramSha256Data;
67
+ }
68
+ createInitialAuthMessage() {
69
+ return this.createAuthenticationSASL();
70
+ }
71
+ async *handleClientMessage(message) {
72
+ switch (this.step) {
73
+ case ScramSha256Step.Initial:
74
+ return yield* this.handleClientFirstMessage(message);
75
+ case ScramSha256Step.ServerFirstMessage:
76
+ return yield* this.handleClientFinalMessage(message);
77
+ default:
78
+ throw new Error('Unexpected SCRAM-SHA-256 authentication step');
79
+ }
80
+ }
81
+ async *handleClientFirstMessage(message) {
82
+ const length = this.reader.int32();
83
+ const saslMechanism = this.reader.cstring();
84
+ if (saslMechanism !== 'SCRAM-SHA-256') {
85
+ yield (0, backend_error_1.createBackendErrorMessage)({
86
+ severity: 'FATAL',
87
+ code: '28000',
88
+ message: 'Unsupported SASL authentication mechanism',
89
+ });
90
+ yield connection_1.closeSignal;
91
+ return;
92
+ }
93
+ const responseLength = this.reader.int32();
94
+ const clientFirstMessage = this.reader.string(responseLength);
95
+ const serverFirstMessage = await this.createServerFirstMessage(clientFirstMessage);
96
+ this.step = ScramSha256Step.ServerFirstMessage;
97
+ yield this.createAuthenticationSASLContinue(serverFirstMessage);
98
+ }
99
+ async createServerFirstMessage(clientFirstMessage) {
100
+ const clientFirstMessageParts = clientFirstMessage.split(',');
101
+ this.clientFirstMessageBare = clientFirstMessageParts.slice(2).join(',');
102
+ const clientNonce = clientFirstMessageParts.find((part) => part.startsWith('r='))?.substring(2) || '';
103
+ const serverNoncePart = new Uint8Array(18);
104
+ crypto.getRandomValues(serverNoncePart);
105
+ this.serverNonce = clientNonce + encodeBase64(serverNoncePart);
106
+ const { salt, iterations } = await this.getScramSha256Data({
107
+ username: this.username,
108
+ });
109
+ this.serverFirstMessage = `r=${this.serverNonce},s=${salt},i=${iterations}`;
110
+ return this.serverFirstMessage;
111
+ }
112
+ async *handleClientFinalMessage(message) {
113
+ try {
114
+ const serverFinalMessage = await this.createServerFinalMessage(message);
115
+ this.step = ScramSha256Step.Completed;
116
+ yield this.createAuthenticationSASLFinal(serverFinalMessage);
117
+ }
118
+ catch (error) {
119
+ yield (0, backend_error_1.createBackendErrorMessage)({
120
+ severity: 'FATAL',
121
+ code: '28000',
122
+ message: error.message,
123
+ });
124
+ yield connection_1.closeSignal;
125
+ return;
126
+ }
127
+ }
128
+ get isCompleted() {
129
+ return this.step === ScramSha256Step.Completed;
130
+ }
131
+ async createServerFinalMessage(message) {
132
+ const length = this.reader.int32();
133
+ const stringLength = length - 4;
134
+ const clientFinalMessage = this.reader.string(stringLength);
135
+ const clientFinalMessageParts = clientFinalMessage.split(',');
136
+ const channelBinding = clientFinalMessageParts
137
+ .find((part) => part.startsWith('c='))
138
+ ?.substring(2);
139
+ const fullNonce = clientFinalMessageParts.find((part) => part.startsWith('r='))?.substring(2);
140
+ const clientProof = clientFinalMessageParts.find((part) => part.startsWith('p='))?.substring(2);
141
+ if (!channelBinding || !fullNonce || !clientProof) {
142
+ throw new Error('Invalid client final message');
143
+ }
144
+ if (fullNonce !== this.serverNonce) {
145
+ throw new Error('Nonce mismatch');
146
+ }
147
+ const clientFinalMessageWithoutProof = `c=${channelBinding},r=${fullNonce}`;
148
+ const authMessage = `${this.clientFirstMessageBare},${this.serverFirstMessage},${clientFinalMessageWithoutProof}`;
149
+ const data = await this.getScramSha256Data({
150
+ username: this.username,
151
+ });
152
+ const isValid = await this.auth.validateCredentials({
153
+ authMessage,
154
+ clientProof,
155
+ username: this.username,
156
+ scramSha256Data: data,
157
+ }, this.connectionState);
158
+ if (!isValid) {
159
+ throw new Error(`password authentication failed for user "${this.username}"`);
160
+ }
161
+ const serverKeyBuffer = decodeBase64(data.serverKey);
162
+ const serverSignature = await (0, crypto_1.createHmacKey)(serverKeyBuffer, authMessage, 'SHA-256');
163
+ return `v=${encodeBase64(serverSignature)}`;
164
+ }
165
+ }
166
+ exports.ScramSha256AuthFlow = ScramSha256AuthFlow;
167
+ function encodeBase64(data) {
168
+ const uint8 = data;
169
+ let result = "";
170
+ let i;
171
+ const l = uint8.length;
172
+ for (i = 2; i < l; i += 3) {
173
+ result += base64abc[(uint8[i - 2]) >> 2];
174
+ result += base64abc[(((uint8[i - 2]) & 0x03) << 4) |
175
+ ((uint8[i - 1]) >> 4)];
176
+ result += base64abc[(((uint8[i - 1]) & 0x0f) << 2) |
177
+ ((uint8[i]) >> 6)];
178
+ result += base64abc[(uint8[i]) & 0x3f];
179
+ }
180
+ if (i === l + 1) {
181
+ result += base64abc[(uint8[i - 2]) >> 2];
182
+ result += base64abc[((uint8[i - 2]) & 0x03) << 4];
183
+ result += "==";
184
+ }
185
+ if (i === l) {
186
+ result += base64abc[(uint8[i - 2]) >> 2];
187
+ result += base64abc[(((uint8[i - 2]) & 0x03) << 4) |
188
+ ((uint8[i - 1]) >> 4)];
189
+ result += base64abc[((uint8[i - 1]) & 0x0f) << 2];
190
+ result += "=";
191
+ }
192
+ return result;
193
+ }
194
+ exports.encodeBase64 = encodeBase64;
195
+ function decodeBase64(b64) {
196
+ const binString = atob(b64);
197
+ const size = binString.length;
198
+ const bytes = new Uint8Array(size);
199
+ for (let i = 0; i < size; i++) {
200
+ bytes[i] = binString.charCodeAt(i);
201
+ }
202
+ return bytes;
203
+ }
204
+ exports.decodeBase64 = decodeBase64;
205
+ const base64abc = [
206
+ "A",
207
+ "B",
208
+ "C",
209
+ "D",
210
+ "E",
211
+ "F",
212
+ "G",
213
+ "H",
214
+ "I",
215
+ "J",
216
+ "K",
217
+ "L",
218
+ "M",
219
+ "N",
220
+ "O",
221
+ "P",
222
+ "Q",
223
+ "R",
224
+ "S",
225
+ "T",
226
+ "U",
227
+ "V",
228
+ "W",
229
+ "X",
230
+ "Y",
231
+ "Z",
232
+ "a",
233
+ "b",
234
+ "c",
235
+ "d",
236
+ "e",
237
+ "f",
238
+ "g",
239
+ "h",
240
+ "i",
241
+ "j",
242
+ "k",
243
+ "l",
244
+ "m",
245
+ "n",
246
+ "o",
247
+ "p",
248
+ "q",
249
+ "r",
250
+ "s",
251
+ "t",
252
+ "u",
253
+ "v",
254
+ "w",
255
+ "x",
256
+ "y",
257
+ "z",
258
+ "0",
259
+ "1",
260
+ "2",
261
+ "3",
262
+ "4",
263
+ "5",
264
+ "6",
265
+ "7",
266
+ "8",
267
+ "9",
268
+ "+",
269
+ "/",
270
+ ];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createBackendErrorMessage = void 0;
4
+ const buffer_writer_1 = require("./buffer-writer");
5
+ const message_codes_1 = require("./message-codes");
6
+ function createBackendErrorMessage(error) {
7
+ const writer = new buffer_writer_1.BufferWriter();
8
+ writer.addString('S');
9
+ writer.addCString(error.severity);
10
+ writer.addString('V');
11
+ writer.addCString(error.severity);
12
+ writer.addString('C');
13
+ writer.addCString(error.code);
14
+ writer.addString('M');
15
+ writer.addCString(error.message);
16
+ if (error.detail !== undefined) {
17
+ writer.addString('D');
18
+ writer.addCString(error.detail);
19
+ }
20
+ if (error.hint !== undefined) {
21
+ writer.addString('H');
22
+ writer.addCString(error.hint);
23
+ }
24
+ if (error.position !== undefined) {
25
+ writer.addString('P');
26
+ writer.addCString(error.position);
27
+ }
28
+ if (error.internalPosition !== undefined) {
29
+ writer.addString('p');
30
+ writer.addCString(error.internalPosition);
31
+ }
32
+ if (error.internalQuery !== undefined) {
33
+ writer.addString('q');
34
+ writer.addCString(error.internalQuery);
35
+ }
36
+ if (error.where !== undefined) {
37
+ writer.addString('W');
38
+ writer.addCString(error.where);
39
+ }
40
+ if (error.schema !== undefined) {
41
+ writer.addString('s');
42
+ writer.addCString(error.schema);
43
+ }
44
+ if (error.table !== undefined) {
45
+ writer.addString('t');
46
+ writer.addCString(error.table);
47
+ }
48
+ if (error.column !== undefined) {
49
+ writer.addString('c');
50
+ writer.addCString(error.column);
51
+ }
52
+ if (error.dataType !== undefined) {
53
+ writer.addString('d');
54
+ writer.addCString(error.dataType);
55
+ }
56
+ if (error.constraint !== undefined) {
57
+ writer.addString('n');
58
+ writer.addCString(error.constraint);
59
+ }
60
+ if (error.file !== undefined) {
61
+ writer.addString('F');
62
+ writer.addCString(error.file);
63
+ }
64
+ if (error.line !== undefined) {
65
+ writer.addString('L');
66
+ writer.addCString(error.line);
67
+ }
68
+ if (error.routine !== undefined) {
69
+ writer.addString('R');
70
+ writer.addCString(error.routine);
71
+ }
72
+ writer.addCString('');
73
+ return writer.flush(message_codes_1.BackendMessageCode.ErrorMessage);
74
+ }
75
+ exports.createBackendErrorMessage = createBackendErrorMessage;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BufferReader = void 0;
4
+ class BufferReader {
5
+ constructor(offset = 0) {
6
+ this.offset = offset;
7
+ this.buffer = new Uint8Array();
8
+ this.decoder = new TextDecoder();
9
+ }
10
+ setBuffer(buffer, offset = 0) {
11
+ this.buffer = buffer;
12
+ this.offset = offset;
13
+ }
14
+ int16() {
15
+ const dataView = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
16
+ const result = dataView.getInt16(this.offset);
17
+ this.offset += 2;
18
+ return result;
19
+ }
20
+ byte() {
21
+ const dataView = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
22
+ const result = dataView.getUint8(this.offset);
23
+ this.offset++;
24
+ return result;
25
+ }
26
+ int32() {
27
+ const dataView = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
28
+ const result = dataView.getInt32(this.offset);
29
+ this.offset += 4;
30
+ return result;
31
+ }
32
+ string(length) {
33
+ const dataView = new DataView(this.buffer.buffer, this.offset, length);
34
+ this.offset += length;
35
+ return this.decoder.decode(dataView);
36
+ }
37
+ cstring() {
38
+ const start = this.offset;
39
+ let end = start;
40
+ while ((this.buffer[end++] ?? 0) !== 0) { }
41
+ if (this.buffer[end - 1] === undefined) {
42
+ throw new Error('Reached end of buffer before null character found for PG String');
43
+ }
44
+ const dataView = new DataView(this.buffer.buffer, start, end - start - 1);
45
+ this.offset = end;
46
+ return this.decoder.decode(dataView);
47
+ }
48
+ bytes(length) {
49
+ const result = this.buffer.slice(this.offset, this.offset + length);
50
+ this.offset += length;
51
+ return result;
52
+ }
53
+ }
54
+ exports.BufferReader = BufferReader;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BufferWriter = void 0;
4
+ const utils_1 = require("./utils");
5
+ class BufferWriter {
6
+ constructor(size = 256) {
7
+ this.size = size;
8
+ this.offset = 5;
9
+ this.headerPosition = 0;
10
+ this.encoder = new TextEncoder();
11
+ this.buffer = new Uint8Array(size);
12
+ }
13
+ ensure(size) {
14
+ const remaining = this.buffer.length - this.offset;
15
+ if (remaining < size) {
16
+ const oldBuffer = this.buffer;
17
+ const newSize = oldBuffer.length + (oldBuffer.length >> 1) + size;
18
+ this.buffer = new Uint8Array(newSize);
19
+ (0, utils_1.copy)(oldBuffer, this.buffer);
20
+ }
21
+ }
22
+ addInt32(num) {
23
+ this.ensure(4);
24
+ this.buffer[this.offset++] = (num >>> 24) & 0xff;
25
+ this.buffer[this.offset++] = (num >>> 16) & 0xff;
26
+ this.buffer[this.offset++] = (num >>> 8) & 0xff;
27
+ this.buffer[this.offset++] = (num >>> 0) & 0xff;
28
+ return this;
29
+ }
30
+ addInt16(num) {
31
+ this.ensure(2);
32
+ this.buffer[this.offset++] = (num >>> 8) & 0xff;
33
+ this.buffer[this.offset++] = (num >>> 0) & 0xff;
34
+ return this;
35
+ }
36
+ addCString(string) {
37
+ if (!string) {
38
+ this.ensure(1);
39
+ }
40
+ else {
41
+ const stringBuffer = this.encoder.encode(string);
42
+ this.ensure(stringBuffer.byteLength + 1);
43
+ this.buffer.set(stringBuffer, this.offset);
44
+ this.offset += stringBuffer.byteLength;
45
+ }
46
+ this.buffer[this.offset++] = 0;
47
+ return this;
48
+ }
49
+ addString(string = '') {
50
+ const stringBuffer = this.encoder.encode(string);
51
+ this.ensure(stringBuffer.byteLength);
52
+ this.buffer.set(stringBuffer, this.offset);
53
+ this.offset += stringBuffer.byteLength;
54
+ return this;
55
+ }
56
+ add(otherBuffer) {
57
+ this.ensure(otherBuffer.byteLength);
58
+ (0, utils_1.copy)(otherBuffer, this.buffer, this.offset);
59
+ this.offset += otherBuffer.length;
60
+ return this;
61
+ }
62
+ join(code) {
63
+ if (code) {
64
+ this.buffer[this.headerPosition] = code;
65
+ const length = this.offset - (this.headerPosition + 1);
66
+ const dataView = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
67
+ dataView.setInt32(this.headerPosition + 1, length);
68
+ }
69
+ return this.buffer.slice(code ? 0 : 5, this.offset);
70
+ }
71
+ flush(code) {
72
+ const result = this.join(code);
73
+ this.offset = 5;
74
+ this.headerPosition = 0;
75
+ this.buffer = new Uint8Array(this.size);
76
+ return result;
77
+ }
78
+ }
79
+ exports.BufferWriter = BufferWriter;