@powersync/service-module-postgres 0.14.4 → 0.16.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 (38) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/LICENSE +3 -3
  3. package/dist/api/PostgresRouteAPIAdapter.js +1 -1
  4. package/dist/api/PostgresRouteAPIAdapter.js.map +1 -1
  5. package/dist/module/PostgresModule.d.ts +1 -2
  6. package/dist/module/PostgresModule.js +3 -40
  7. package/dist/module/PostgresModule.js.map +1 -1
  8. package/dist/replication/PgRelation.js +1 -1
  9. package/dist/replication/PgRelation.js.map +1 -1
  10. package/dist/replication/SnapshotQuery.js +4 -4
  11. package/dist/replication/SnapshotQuery.js.map +1 -1
  12. package/dist/replication/WalStream.d.ts +3 -2
  13. package/dist/replication/WalStream.js +26 -16
  14. package/dist/replication/WalStream.js.map +1 -1
  15. package/dist/replication/replication-utils.js +10 -2
  16. package/dist/replication/replication-utils.js.map +1 -1
  17. package/dist/utils/pgwire_utils.d.ts +3 -3
  18. package/dist/utils/pgwire_utils.js.map +1 -1
  19. package/package.json +13 -13
  20. package/src/api/PostgresRouteAPIAdapter.ts +4 -1
  21. package/src/module/PostgresModule.ts +2 -43
  22. package/src/replication/PgRelation.ts +2 -2
  23. package/src/replication/SnapshotQuery.ts +4 -4
  24. package/src/replication/WalStream.ts +36 -19
  25. package/src/replication/replication-utils.ts +10 -2
  26. package/src/utils/pgwire_utils.ts +5 -3
  27. package/test/src/checkpoints.test.ts +2 -0
  28. package/test/src/large_batch.test.ts +0 -1
  29. package/test/src/pg_test.test.ts +57 -17
  30. package/test/src/slow_tests.test.ts +0 -2
  31. package/test/src/util.ts +2 -4
  32. package/test/src/wal_stream.test.ts +12 -21
  33. package/test/src/wal_stream_utils.ts +10 -1
  34. package/tsconfig.tsbuildinfo +1 -1
  35. package/dist/auth/SupabaseKeyCollector.d.ts +0 -17
  36. package/dist/auth/SupabaseKeyCollector.js +0 -71
  37. package/dist/auth/SupabaseKeyCollector.js.map +0 -1
  38. package/src/auth/SupabaseKeyCollector.ts +0 -83
@@ -1,17 +0,0 @@
1
- import { auth, KeyResult } from '@powersync/service-core';
2
- import * as types from '../types/types.js';
3
- /**
4
- * Fetches key from the Supabase database.
5
- *
6
- * Unfortunately, despite the JWTs containing a kid, we have no way to lookup that kid
7
- * before receiving a valid token.
8
- *
9
- * @deprecated Supabase is removing support for "app.settings.jwt_secret". This is likely to not function anymore, except in some self-hosted setups.
10
- */
11
- export declare class SupabaseKeyCollector implements auth.KeyCollector {
12
- private pool;
13
- private keyOptions;
14
- constructor(connectionConfig: types.ResolvedConnectionConfig);
15
- shutdown(): Promise<void>;
16
- getKeys(): Promise<KeyResult>;
17
- }
@@ -1,71 +0,0 @@
1
- import * as lib_postgres from '@powersync/lib-service-postgres';
2
- import { auth } from '@powersync/service-core';
3
- import * as pgwire from '@powersync/service-jpgwire';
4
- import { AuthorizationError, ErrorCode } from '@powersync/lib-services-framework';
5
- import { getApplicationName } from '../utils/application-name.js';
6
- /**
7
- * Fetches key from the Supabase database.
8
- *
9
- * Unfortunately, despite the JWTs containing a kid, we have no way to lookup that kid
10
- * before receiving a valid token.
11
- *
12
- * @deprecated Supabase is removing support for "app.settings.jwt_secret". This is likely to not function anymore, except in some self-hosted setups.
13
- */
14
- export class SupabaseKeyCollector {
15
- pool;
16
- keyOptions = {
17
- requiresAudience: ['authenticated'],
18
- maxLifetimeSeconds: 86400 * 7 + 1200 // 1 week + 20 minutes margin
19
- };
20
- constructor(connectionConfig) {
21
- this.pool = pgwire.connectPgWirePool(connectionConfig, {
22
- // To avoid overloading the source database with open connections,
23
- // limit to a single connection, and close the connection shortly
24
- // after using it.
25
- idleTimeout: 5_000,
26
- maxSize: 1,
27
- applicationName: getApplicationName()
28
- });
29
- }
30
- shutdown() {
31
- return this.pool.end();
32
- }
33
- async getKeys() {
34
- let row;
35
- try {
36
- const rows = pgwire.pgwireRows(await lib_postgres.retriedQuery(this.pool, `SELECT current_setting('app.settings.jwt_secret') as jwt_secret`));
37
- row = rows[0];
38
- }
39
- catch (e) {
40
- if (e.message?.includes('unrecognized configuration parameter')) {
41
- throw new AuthorizationError(ErrorCode.PSYNC_S2201, 'No JWT secret found in Supabase database. Manually configure the secret.');
42
- }
43
- else {
44
- throw e;
45
- }
46
- }
47
- const secret = row?.jwt_secret;
48
- if (secret == null) {
49
- return {
50
- keys: [],
51
- errors: [
52
- new AuthorizationError(ErrorCode.PSYNC_S2201, 'No JWT secret found in Supabase database. Manually configure the secret.')
53
- ]
54
- };
55
- }
56
- else {
57
- const key = {
58
- kty: 'oct',
59
- alg: 'HS256',
60
- // While the secret is valid base64, the base64-encoded form is the secret value.
61
- k: Buffer.from(secret, 'utf8').toString('base64url')
62
- };
63
- const imported = await auth.KeySpec.importKey(key, this.keyOptions);
64
- return {
65
- keys: [imported],
66
- errors: []
67
- };
68
- }
69
- }
70
- }
71
- //# sourceMappingURL=SupabaseKeyCollector.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SupabaseKeyCollector.js","sourceRoot":"","sources":["../../src/auth/SupabaseKeyCollector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,IAAI,EAAa,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AAIrD,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE;;;;;;;GAOG;AACH,MAAM,OAAO,oBAAoB;IACvB,IAAI,CAAkB;IAEtB,UAAU,GAAoB;QACpC,gBAAgB,EAAE,CAAC,eAAe,CAAC;QACnC,kBAAkB,EAAE,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,6BAA6B;KACnE,CAAC;IAEF,YAAY,gBAAgD;QAC1D,IAAI,CAAC,IAAI,GAAG,MAA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MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YACpE,OAAO;gBACL,IAAI,EAAE,CAAC,QAAQ,CAAC;gBAChB,MAAM,EAAE,EAAE;aACX,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -1,83 +0,0 @@
1
- import * as lib_postgres from '@powersync/lib-service-postgres';
2
- import { auth, KeyResult } from '@powersync/service-core';
3
- import * as pgwire from '@powersync/service-jpgwire';
4
- import * as jose from 'jose';
5
-
6
- import * as types from '../types/types.js';
7
- import { AuthorizationError, ErrorCode } from '@powersync/lib-services-framework';
8
- import { getApplicationName } from '../utils/application-name.js';
9
-
10
- /**
11
- * Fetches key from the Supabase database.
12
- *
13
- * Unfortunately, despite the JWTs containing a kid, we have no way to lookup that kid
14
- * before receiving a valid token.
15
- *
16
- * @deprecated Supabase is removing support for "app.settings.jwt_secret". This is likely to not function anymore, except in some self-hosted setups.
17
- */
18
- export class SupabaseKeyCollector implements auth.KeyCollector {
19
- private pool: pgwire.PgClient;
20
-
21
- private keyOptions: auth.KeyOptions = {
22
- requiresAudience: ['authenticated'],
23
- maxLifetimeSeconds: 86400 * 7 + 1200 // 1 week + 20 minutes margin
24
- };
25
-
26
- constructor(connectionConfig: types.ResolvedConnectionConfig) {
27
- this.pool = pgwire.connectPgWirePool(connectionConfig, {
28
- // To avoid overloading the source database with open connections,
29
- // limit to a single connection, and close the connection shortly
30
- // after using it.
31
- idleTimeout: 5_000,
32
- maxSize: 1,
33
- applicationName: getApplicationName()
34
- });
35
- }
36
-
37
- shutdown() {
38
- return this.pool.end();
39
- }
40
-
41
- async getKeys(): Promise<KeyResult> {
42
- let row: { jwt_secret: string };
43
- try {
44
- const rows = pgwire.pgwireRows(
45
- await lib_postgres.retriedQuery(this.pool, `SELECT current_setting('app.settings.jwt_secret') as jwt_secret`)
46
- );
47
- row = rows[0] as any;
48
- } catch (e) {
49
- if (e.message?.includes('unrecognized configuration parameter')) {
50
- throw new AuthorizationError(
51
- ErrorCode.PSYNC_S2201,
52
- 'No JWT secret found in Supabase database. Manually configure the secret.'
53
- );
54
- } else {
55
- throw e;
56
- }
57
- }
58
- const secret = row?.jwt_secret as string | undefined;
59
- if (secret == null) {
60
- return {
61
- keys: [],
62
- errors: [
63
- new AuthorizationError(
64
- ErrorCode.PSYNC_S2201,
65
- 'No JWT secret found in Supabase database. Manually configure the secret.'
66
- )
67
- ]
68
- };
69
- } else {
70
- const key: jose.JWK = {
71
- kty: 'oct',
72
- alg: 'HS256',
73
- // While the secret is valid base64, the base64-encoded form is the secret value.
74
- k: Buffer.from(secret, 'utf8').toString('base64url')
75
- };
76
- const imported = await auth.KeySpec.importKey(key, this.keyOptions);
77
- return {
78
- keys: [imported],
79
- errors: []
80
- };
81
- }
82
- }
83
- }