@powersync/service-core 0.0.0-dev-20250724093011 → 0.0.0-dev-20250729101933
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -4
- package/dist/api/diagnostics.js +2 -2
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/auth/KeyStore.d.ts +19 -0
- package/dist/auth/KeyStore.js +16 -4
- package/dist/auth/KeyStore.js.map +1 -1
- package/dist/auth/RemoteJWKSCollector.d.ts +3 -0
- package/dist/auth/RemoteJWKSCollector.js +3 -1
- package/dist/auth/RemoteJWKSCollector.js.map +1 -1
- package/dist/auth/StaticSupabaseKeyCollector.d.ts +2 -1
- package/dist/auth/StaticSupabaseKeyCollector.js +1 -1
- package/dist/auth/StaticSupabaseKeyCollector.js.map +1 -1
- package/dist/auth/utils.d.ts +19 -0
- package/dist/auth/utils.js +106 -3
- package/dist/auth/utils.js.map +1 -1
- package/dist/emitters/EmitterEngine.js +0 -3
- package/dist/emitters/EmitterEngine.js.map +1 -1
- package/dist/storage/BucketStorageBatch.d.ts +12 -2
- package/dist/storage/BucketStorageBatch.js.map +1 -1
- package/dist/storage/SyncRulesBucketStorage.d.ts +0 -1
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
- package/dist/util/config/compound-config-collector.js +23 -0
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/lsn.d.ts +4 -0
- package/dist/util/lsn.js +11 -0
- package/dist/util/lsn.js.map +1 -0
- package/dist/util/util-index.d.ts +1 -0
- package/dist/util/util-index.js +1 -0
- package/dist/util/util-index.js.map +1 -1
- package/package.json +4 -4
- package/src/api/diagnostics.ts +2 -2
- package/src/auth/KeyStore.ts +28 -4
- package/src/auth/RemoteJWKSCollector.ts +5 -2
- package/src/auth/StaticSupabaseKeyCollector.ts +1 -1
- package/src/auth/utils.ts +123 -3
- package/src/emitters/EmitterEngine.ts +0 -3
- package/src/storage/BucketStorageBatch.ts +13 -2
- package/src/storage/SyncRulesBucketStorage.ts +0 -2
- package/src/util/config/compound-config-collector.ts +24 -0
- package/src/util/lsn.ts +8 -0
- package/src/util/util-index.ts +1 -0
- package/test/src/auth.test.ts +323 -1
- package/tsconfig.tsbuildinfo +1 -1
package/dist/util/util-index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util-index.js","sourceRoot":"","sources":["../../src/util/util-index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAE7B,cAAc,aAAa,CAAC;AAC5B,cAAc,uCAAuC,CAAC;AACtD,cAAc,mBAAmB,CAAC;AAElC,cAAc,yCAAyC,CAAC;AACxD,cAAc,qDAAqD,CAAC;AACpE,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AAExE,cAAc,yDAAyD,CAAC;AACxE,cAAc,6DAA6D,CAAC;AAC5E,cAAc,yDAAyD,CAAC;AACxE,cAAc,uCAAuC,CAAC;AACtD,cAAc,4CAA4C,CAAC"}
|
|
1
|
+
{"version":3,"file":"util-index.js","sourceRoot":"","sources":["../../src/util/util-index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAE7B,cAAc,aAAa,CAAC;AAC5B,cAAc,uCAAuC,CAAC;AACtD,cAAc,mBAAmB,CAAC;AAElC,cAAc,yCAAyC,CAAC;AACxD,cAAc,qDAAqD,CAAC;AACpE,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AAExE,cAAc,yDAAyD,CAAC;AACxE,cAAc,6DAA6D,CAAC;AAC5E,cAAc,yDAAyD,CAAC;AACxE,cAAc,uCAAuC,CAAC;AACtD,cAAc,4CAA4C,CAAC"}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.0.0-dev-
|
|
8
|
+
"version": "0.0.0-dev-20250729101933",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"license": "FSL-1.1-Apache-2.0",
|
|
11
11
|
"type": "module",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"uuid": "^11.1.0",
|
|
33
33
|
"winston": "^3.13.0",
|
|
34
34
|
"yaml": "^2.3.2",
|
|
35
|
-
"@powersync/lib-services-framework": "0.0.0-dev-
|
|
35
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20250729101933",
|
|
36
36
|
"@powersync/service-jsonbig": "0.17.10",
|
|
37
|
-
"@powersync/service-rsocket-router": "0.0.0-dev-
|
|
37
|
+
"@powersync/service-rsocket-router": "0.0.0-dev-20250729101933",
|
|
38
38
|
"@powersync/service-sync-rules": "0.27.0",
|
|
39
|
-
"@powersync/service-types": "0.0.0-dev-
|
|
39
|
+
"@powersync/service-types": "0.0.0-dev-20250729101933"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/async": "^3.2.24",
|
package/src/api/diagnostics.ts
CHANGED
|
@@ -149,7 +149,7 @@ export async function getSyncRulesStatus(
|
|
|
149
149
|
);
|
|
150
150
|
const lagSeconds = Math.round((Date.now() - lastTime) / 1000);
|
|
151
151
|
// On idle instances, keepalive messages are only persisted every 60 seconds.
|
|
152
|
-
// So we use
|
|
152
|
+
// So we use 5 minutes as a threshold for warnings, and 15 minutes for critical.
|
|
153
153
|
// The replication lag metric should give a more granular value, but that is not available directly
|
|
154
154
|
// in the API containers used for diagnostics, and this should give a good enough indication.
|
|
155
155
|
if (lagSeconds > 15 * 60) {
|
|
@@ -157,7 +157,7 @@ export async function getSyncRulesStatus(
|
|
|
157
157
|
level: 'fatal',
|
|
158
158
|
message: `No replicated commit in more than ${lagSeconds}s`
|
|
159
159
|
});
|
|
160
|
-
} else if (lagSeconds >
|
|
160
|
+
} else if (lagSeconds > 5 * 60) {
|
|
161
161
|
errors.push({
|
|
162
162
|
level: 'warning',
|
|
163
163
|
message: `No replicated commit in more than ${lagSeconds}s`
|
package/src/auth/KeyStore.ts
CHANGED
|
@@ -4,7 +4,7 @@ import secs from '../util/secs.js';
|
|
|
4
4
|
import { JwtPayload } from './JwtPayload.js';
|
|
5
5
|
import { KeyCollector } from './KeyCollector.js';
|
|
6
6
|
import { KeyOptions, KeySpec, SUPPORTED_ALGORITHMS } from './KeySpec.js';
|
|
7
|
-
import { mapAuthError } from './utils.js';
|
|
7
|
+
import { debugKeyNotFound, mapAuthError, SupabaseAuthDetails, tokenDebugDetails } from './utils.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* KeyStore to get keys and verify tokens.
|
|
@@ -39,6 +39,29 @@ export class KeyStore<Collector extends KeyCollector = KeyCollector> {
|
|
|
39
39
|
*/
|
|
40
40
|
collector: Collector;
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* For debug purposes only.
|
|
44
|
+
*
|
|
45
|
+
* This is very Supabase-specific, but we need the info on this level. For example,
|
|
46
|
+
* we want to detect cases where a Supabase token is used, but Supabase auth is not enabled
|
|
47
|
+
* (no Supabase collector configured).
|
|
48
|
+
*/
|
|
49
|
+
supabaseAuthDebug: {
|
|
50
|
+
/**
|
|
51
|
+
* This can be populated without jwksEnabled, but not the other way around.
|
|
52
|
+
*/
|
|
53
|
+
jwksDetails: SupabaseAuthDetails | null;
|
|
54
|
+
jwksEnabled: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* This can be enabled without jwksDetails populated.
|
|
57
|
+
*/
|
|
58
|
+
sharedSecretEnabled: boolean;
|
|
59
|
+
} = {
|
|
60
|
+
jwksDetails: null,
|
|
61
|
+
jwksEnabled: false,
|
|
62
|
+
sharedSecretEnabled: false
|
|
63
|
+
};
|
|
64
|
+
|
|
42
65
|
constructor(collector: Collector) {
|
|
43
66
|
this.collector = collector;
|
|
44
67
|
}
|
|
@@ -131,7 +154,7 @@ export class KeyStore<Collector extends KeyCollector = KeyCollector> {
|
|
|
131
154
|
if (!key.matchesAlgorithm(header.alg)) {
|
|
132
155
|
throw new AuthorizationError(ErrorCode.PSYNC_S2101, `Unexpected token algorithm ${header.alg}`, {
|
|
133
156
|
configurationDetails: `Key kid: ${key.source.kid}, alg: ${key.source.alg}, kty: ${key.source.kty}`
|
|
134
|
-
//
|
|
157
|
+
// tokenDetails automatically populated higher up the stack
|
|
135
158
|
});
|
|
136
159
|
}
|
|
137
160
|
return key;
|
|
@@ -165,12 +188,13 @@ export class KeyStore<Collector extends KeyCollector = KeyCollector> {
|
|
|
165
188
|
logger.error(`Failed to refresh keys`, e);
|
|
166
189
|
});
|
|
167
190
|
|
|
191
|
+
const details = debugKeyNotFound(this, keys, token);
|
|
192
|
+
|
|
168
193
|
throw new AuthorizationError(
|
|
169
194
|
ErrorCode.PSYNC_S2101,
|
|
170
195
|
'Could not find an appropriate key in the keystore. The key is missing or no key matched the token KID',
|
|
171
196
|
{
|
|
172
|
-
|
|
173
|
-
// tokenDetails automatically populated later
|
|
197
|
+
...details
|
|
174
198
|
}
|
|
175
199
|
);
|
|
176
200
|
}
|
|
@@ -12,10 +12,11 @@ import {
|
|
|
12
12
|
ServiceError
|
|
13
13
|
} from '@powersync/lib-services-framework';
|
|
14
14
|
import { KeyCollector, KeyResult } from './KeyCollector.js';
|
|
15
|
-
import { KeySpec } from './KeySpec.js';
|
|
15
|
+
import { KeyOptions, KeySpec } from './KeySpec.js';
|
|
16
16
|
|
|
17
17
|
export type RemoteJWKSCollectorOptions = {
|
|
18
18
|
lookupOptions?: LookupOptions;
|
|
19
|
+
keyOptions?: KeyOptions;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -24,6 +25,7 @@ export type RemoteJWKSCollectorOptions = {
|
|
|
24
25
|
export class RemoteJWKSCollector implements KeyCollector {
|
|
25
26
|
private url: URL;
|
|
26
27
|
private agent: http.Agent;
|
|
28
|
+
private keyOptions: KeyOptions;
|
|
27
29
|
|
|
28
30
|
constructor(
|
|
29
31
|
url: string,
|
|
@@ -34,6 +36,7 @@ export class RemoteJWKSCollector implements KeyCollector {
|
|
|
34
36
|
} catch (e: any) {
|
|
35
37
|
throw new ServiceError(ErrorCode.PSYNC_S3102, `Invalid jwks_uri: ${JSON.stringify(url)} Details: ${e.message}`);
|
|
36
38
|
}
|
|
39
|
+
this.keyOptions = options?.keyOptions ?? {};
|
|
37
40
|
|
|
38
41
|
// We do support http here for self-hosting use cases.
|
|
39
42
|
// Management service restricts this to https for hosted versions.
|
|
@@ -123,7 +126,7 @@ export class RemoteJWKSCollector implements KeyCollector {
|
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
|
|
126
|
-
const key = await KeySpec.importKey(keyData);
|
|
129
|
+
const key = await KeySpec.importKey(keyData, this.keyOptions);
|
|
127
130
|
keys.push(key);
|
|
128
131
|
}
|
|
129
132
|
|
|
@@ -2,7 +2,7 @@ import * as jose from 'jose';
|
|
|
2
2
|
import { KeySpec, KeyOptions } from './KeySpec.js';
|
|
3
3
|
import { KeyCollector, KeyResult } from './KeyCollector.js';
|
|
4
4
|
|
|
5
|
-
const SUPABASE_KEY_OPTIONS: KeyOptions = {
|
|
5
|
+
export const SUPABASE_KEY_OPTIONS: KeyOptions = {
|
|
6
6
|
requiresAudience: ['authenticated'],
|
|
7
7
|
maxLifetimeSeconds: 86400 * 7 + 1200 // 1 week + 20 minutes margin
|
|
8
8
|
};
|
package/src/auth/utils.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { AuthorizationError, ErrorCode } from '@powersync/lib-services-framework';
|
|
2
2
|
import * as jose from 'jose';
|
|
3
|
+
import * as urijs from 'uri-js';
|
|
4
|
+
import * as uuid from 'uuid';
|
|
5
|
+
import { KeySpec } from './KeySpec.js';
|
|
6
|
+
import { KeyStore } from './KeyStore.js';
|
|
3
7
|
|
|
4
8
|
export function mapJoseError(error: jose.errors.JOSEError, token: string): AuthorizationError {
|
|
5
9
|
const tokenDetails = tokenDebugDetails(token);
|
|
@@ -61,15 +65,28 @@ export function mapAuthConfigError(error: any): AuthorizationError {
|
|
|
61
65
|
* We use this to add details to our logs. We don't log the entire token, since it may for example
|
|
62
66
|
* a password incorrectly used as a token.
|
|
63
67
|
*/
|
|
64
|
-
function tokenDebugDetails(token: string): string {
|
|
68
|
+
export function tokenDebugDetails(token: string): string {
|
|
69
|
+
return parseTokenDebug(token).description;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function parseTokenDebug(token: string) {
|
|
65
73
|
try {
|
|
66
74
|
// For valid tokens, we return the header and payload
|
|
67
75
|
const header = jose.decodeProtectedHeader(token);
|
|
68
76
|
const payload = jose.decodeJwt(token);
|
|
69
|
-
|
|
77
|
+
const isSupabase = typeof payload.iss == 'string' && payload.iss.includes('supabase.co');
|
|
78
|
+
const isSharedSecret = isSupabase && header.alg === 'HS256';
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
header,
|
|
82
|
+
payload,
|
|
83
|
+
isSupabase,
|
|
84
|
+
isSharedSecret: isSharedSecret,
|
|
85
|
+
description: `<header: ${JSON.stringify(header)} payload: ${JSON.stringify(payload)}>`
|
|
86
|
+
};
|
|
70
87
|
} catch (e) {
|
|
71
88
|
// Token fails to parse. Return some details.
|
|
72
|
-
return invalidTokenDetails(token);
|
|
89
|
+
return { description: invalidTokenDetails(token) };
|
|
73
90
|
}
|
|
74
91
|
}
|
|
75
92
|
|
|
@@ -100,3 +117,106 @@ function invalidTokenDetails(token: string): string {
|
|
|
100
117
|
|
|
101
118
|
return `<invalid JWT, length=${token.length}>`;
|
|
102
119
|
}
|
|
120
|
+
|
|
121
|
+
export interface SupabaseAuthDetails {
|
|
122
|
+
projectId: string;
|
|
123
|
+
url: string;
|
|
124
|
+
hostname: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function getSupabaseJwksUrl(connection: any): SupabaseAuthDetails | null {
|
|
128
|
+
if (connection == null) {
|
|
129
|
+
return null;
|
|
130
|
+
} else if (connection.type != 'postgresql') {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let hostname: string | undefined = connection.hostname;
|
|
135
|
+
if (hostname == null && typeof connection.uri == 'string') {
|
|
136
|
+
hostname = urijs.parse(connection.uri).host;
|
|
137
|
+
}
|
|
138
|
+
if (hostname == null) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const match = /db.(\w+).supabase.co/.exec(hostname);
|
|
143
|
+
if (match == null) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const projectId = match[1];
|
|
147
|
+
|
|
148
|
+
return { projectId, hostname, url: `https://${projectId}.supabase.co/auth/v1/.well-known/jwks.json` };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function debugKeyNotFound(
|
|
152
|
+
keyStore: KeyStore,
|
|
153
|
+
keys: KeySpec[],
|
|
154
|
+
token: string
|
|
155
|
+
): { configurationDetails: string; tokenDetails: string } {
|
|
156
|
+
const knownKeys = keys.map((key) => key.description).join(', ');
|
|
157
|
+
const td = parseTokenDebug(token);
|
|
158
|
+
const tokenDetails = td.description;
|
|
159
|
+
const configuredSupabase = keyStore.supabaseAuthDebug;
|
|
160
|
+
|
|
161
|
+
// Cases to check:
|
|
162
|
+
// 1. Is Supabase token, but supabase auth not enabled.
|
|
163
|
+
// 2. Is Supabase HS256 token, but no secret configured.
|
|
164
|
+
// 3. Is Supabase singing key token, but no Supabase signing keys configured.
|
|
165
|
+
// 4. Supabase project id mismatch.
|
|
166
|
+
|
|
167
|
+
if (td.isSharedSecret) {
|
|
168
|
+
// Supabase HS256 token
|
|
169
|
+
// UUID: HS256 (Shared Secret)
|
|
170
|
+
// Other: Legacy HS256 (Shared Secret)
|
|
171
|
+
// Not a big difference between the two other than terminology used on Supabase.
|
|
172
|
+
const isLegacy = uuid.validate(td.header.kid) ? false : true;
|
|
173
|
+
const addMessage =
|
|
174
|
+
configuredSupabase.jwksEnabled && !isLegacy
|
|
175
|
+
? ' Use asymmetric keys on Supabase (RSA or ECC) to allow automatic key retrieval.'
|
|
176
|
+
: '';
|
|
177
|
+
if (!configuredSupabase.sharedSecretEnabled) {
|
|
178
|
+
return {
|
|
179
|
+
configurationDetails: `Token is a Supabase ${isLegacy ? 'Legacy ' : ''}HS256 (Shared Secret) token, but Supabase JWT secret is not configured.${addMessage}`,
|
|
180
|
+
tokenDetails
|
|
181
|
+
};
|
|
182
|
+
} else {
|
|
183
|
+
return {
|
|
184
|
+
// This is an educated guess
|
|
185
|
+
configurationDetails: `Token is a Supabase ${isLegacy ? 'Legacy ' : ''}HS256 (Shared Secret) token, but configured Supabase JWT secret does not match.${addMessage}`,
|
|
186
|
+
tokenDetails
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
} else if (td.isSupabase) {
|
|
190
|
+
// Supabase JWT Signing Keys
|
|
191
|
+
if (!configuredSupabase.jwksEnabled) {
|
|
192
|
+
if (configuredSupabase.jwksDetails != null) {
|
|
193
|
+
return {
|
|
194
|
+
configurationDetails: `Token uses Supabase JWT Signing Keys, but Supabase Auth is not enabled`,
|
|
195
|
+
tokenDetails
|
|
196
|
+
};
|
|
197
|
+
} else {
|
|
198
|
+
return {
|
|
199
|
+
configurationDetails: `Token uses Supabase JWT Signing Keys, but no Supabase connection is configured`,
|
|
200
|
+
tokenDetails
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
} else if (configuredSupabase.jwksDetails != null) {
|
|
204
|
+
const configuredProjectId = configuredSupabase.jwksDetails.projectId;
|
|
205
|
+
const issuer = td.payload.iss as string; // Is a string since since isSupabase is true
|
|
206
|
+
if (!issuer.includes(configuredProjectId)) {
|
|
207
|
+
return {
|
|
208
|
+
configurationDetails: `Supabase project id mismatch. Expected project: ${configuredProjectId}, got issuer: ${issuer}`,
|
|
209
|
+
tokenDetails
|
|
210
|
+
};
|
|
211
|
+
} else {
|
|
212
|
+
// Project id matches, but no matching keys found
|
|
213
|
+
return {
|
|
214
|
+
configurationDetails: `Supabase signing keys configured, but no matching keys found. Known keys: ${knownKeys}`,
|
|
215
|
+
tokenDetails
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return { configurationDetails: `Known keys: ${knownKeys}`, tokenDetails: tokenDebugDetails(token) };
|
|
222
|
+
}
|
|
@@ -29,9 +29,6 @@ export class EmitterEngine implements BaseEmitterEngine {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
emit<K extends keyof event_types.SubscribeEvents>(event: K, data: event_types.SubscribeEvents[K]): void {
|
|
32
|
-
if (!this.events.has(event) || this.countListeners(event) === 0) {
|
|
33
|
-
logger.warn(`${event} has no listener registered.`);
|
|
34
|
-
}
|
|
35
32
|
this.emitter.emit(event, data);
|
|
36
33
|
}
|
|
37
34
|
|
|
@@ -60,18 +60,29 @@ export interface BucketStorageBatch extends ObserverClient<BucketBatchStorageLis
|
|
|
60
60
|
keepalive(lsn: string): Promise<boolean>;
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
* Set the LSN
|
|
63
|
+
* Set the LSN that replication should resume from.
|
|
64
|
+
*
|
|
65
|
+
* This can be used for:
|
|
66
|
+
* 1. Setting the LSN for a snapshot, before starting replication.
|
|
67
|
+
* 2. Setting the LSN to resume from after a replication restart, without advancing the checkpoint LSN via a commit.
|
|
64
68
|
*
|
|
65
69
|
* Not required if the source database keeps track of this, for example with
|
|
66
70
|
* PostgreSQL logical replication slots.
|
|
67
71
|
*/
|
|
68
|
-
|
|
72
|
+
setResumeLsn(lsn: string): Promise<void>;
|
|
69
73
|
|
|
70
74
|
/**
|
|
71
75
|
* Get the last checkpoint LSN, from either commit or keepalive.
|
|
72
76
|
*/
|
|
73
77
|
lastCheckpointLsn: string | null;
|
|
74
78
|
|
|
79
|
+
/**
|
|
80
|
+
* LSN to resume from.
|
|
81
|
+
*
|
|
82
|
+
* Not relevant for streams where the source keeps track of replication progress, such as Postgres.
|
|
83
|
+
*/
|
|
84
|
+
resumeFromLsn: string | null;
|
|
85
|
+
|
|
75
86
|
markSnapshotDone(tables: SourceTable[], no_checkpoint_before_lsn: string): Promise<SourceTable[]>;
|
|
76
87
|
|
|
77
88
|
updateTableProgress(table: SourceTable, progress: Partial<TableSnapshotStatus>): Promise<SourceTable>;
|
|
@@ -89,6 +89,7 @@ export class CompoundConfigCollector {
|
|
|
89
89
|
}
|
|
90
90
|
])
|
|
91
91
|
);
|
|
92
|
+
keyStore.supabaseAuthDebug.sharedSecretEnabled = true;
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
let jwks_uris = baseConfig.client_auth?.jwks_uri ?? [];
|
|
@@ -114,6 +115,29 @@ export class CompoundConfigCollector {
|
|
|
114
115
|
for (let uri of jwks_uris) {
|
|
115
116
|
collectors.add(new auth.CachedKeyCollector(new auth.RemoteJWKSCollector(uri, { lookupOptions: jwksLookup })));
|
|
116
117
|
}
|
|
118
|
+
const supabaseAuthDetails = auth.getSupabaseJwksUrl(baseConfig.replication?.connections?.[0]);
|
|
119
|
+
keyStore.supabaseAuthDebug.jwksDetails = supabaseAuthDetails;
|
|
120
|
+
|
|
121
|
+
if (baseConfig.client_auth?.supabase) {
|
|
122
|
+
// Automatic support for Supabase signing keys:
|
|
123
|
+
// https://supabase.com/docs/guides/auth/signing-keys
|
|
124
|
+
if (supabaseAuthDetails != null) {
|
|
125
|
+
const collector = new auth.RemoteJWKSCollector(supabaseAuthDetails.url, {
|
|
126
|
+
lookupOptions: jwksLookup,
|
|
127
|
+
// Special case aud and max lifetime for Supabase keys
|
|
128
|
+
keyOptions: auth.SUPABASE_KEY_OPTIONS
|
|
129
|
+
});
|
|
130
|
+
collectors.add(new auth.CachedKeyCollector(collector));
|
|
131
|
+
keyStore.supabaseAuthDebug.jwksEnabled = true;
|
|
132
|
+
logger.info(`Configured Supabase Auth with ${supabaseAuthDetails.url}`);
|
|
133
|
+
} else {
|
|
134
|
+
logger.warn(
|
|
135
|
+
'Supabase Auth is enabled, but no Supabase connection string found. Skipping Supabase JWKS URL configuration.'
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
} else if (supabaseAuthDetails != null) {
|
|
139
|
+
logger.warn(`Supabase connection string found, but Supabase Auth is not enabled in the config.`);
|
|
140
|
+
}
|
|
117
141
|
|
|
118
142
|
const sync_rules = await this.collectSyncRules(baseConfig, runnerConfig);
|
|
119
143
|
|
package/src/util/lsn.ts
ADDED