@pgxsinkit/server 0.1.40 → 0.1.46
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/dist/cors-origin.d.ts +16 -0
- package/dist/cors-origin.d.ts.map +1 -0
- package/dist/electric-proxy.d.ts +4 -1
- package/dist/electric-proxy.d.ts.map +1 -1
- package/dist/index.js +229 -5849
- package/dist/index.js.map +8 -87
- package/dist/mutations/plpgsql-apply.d.ts.map +1 -1
- package/dist/router.d.ts +1 -0
- package/dist/router.d.ts.map +1 -1
- package/package.json +2 -2
- package/skills/deploying/SKILL.md +1 -1
- package/src/cors-origin.ts +21 -0
- package/src/electric-proxy.ts +7 -3
- package/src/mutations/plpgsql-apply.ts +10 -9
- package/src/router.ts +4 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plpgsql-apply.d.ts","sourceRoot":"","sources":["../../src/mutations/plpgsql-apply.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGnH,OAAO,EAOL,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EAEtB,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"plpgsql-apply.d.ts","sourceRoot":"","sources":["../../src/mutations/plpgsql-apply.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGnH,OAAO,EAOL,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EAEtB,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAkgBjD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE;IACP,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,MAAM,CAER;AAED,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE;IACP,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,MAAM,CAUR;AAED,wBAAsB,2BAA2B,CAAC,SAAS,SAAS,iBAAiB,EACnF,EAAE,EAAE,eAAe,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC,EACnE,QAAQ,EAAE,SAAS,EACnB,OAAO,GAAE;IACP,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,OAAO,CAAC,IAAI,CAAC,CAGf;AAMD,wBAAsB,oBAAoB,CAAC,SAAS,SAAS,iBAAiB,EAC5E,EAAE,EAAE,eAAe,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC,GAClE,OAAO,CAAC,IAAI,CAAC,CAef;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;AAQD,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,iBAAiB,EACrB,KAAK,EAAE,oBAAoB,EAC3B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,OAAO,EACnB,UAAU,EAAE,OAAO,EACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAKnC,mBAAmB,EAAE,MAAM,EAC3B,OAAO,GAAE;IACP,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,OAAO,CAAC,gBAAgB,EAAE,CAAC,CA0B7B"}
|
package/dist/router.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type FetchHandler = (request: Request) => Response | Promise<Response>;
|
|
2
2
|
export interface CorsConfig {
|
|
3
|
+
/** Exact origins, or a `"*"` entry to allow every origin by reflection (see {@link resolveCorsOrigin}). */
|
|
3
4
|
origins: string[];
|
|
4
5
|
allowMethods: string[];
|
|
5
6
|
allowHeaders: string[];
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE9E,MAAM,WAAW,UAAU;IACzB,2GAA2G;IAC3G,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,6FAA6F;AAC7F,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEpG,qBAAa,WAAW;;IAMtB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAE7C;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAE9C;IAED,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAOrD;IAED,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAEjD;IAED,QAAQ,CAAC,KAAK,YAAmB,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAyB1D;CAoCH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgxsinkit/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"tanstack-intent"
|
|
6
6
|
],
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"build": "bun --cwd ../.. run build:public-packages"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@pgxsinkit/contracts": "0.1.
|
|
34
|
+
"@pgxsinkit/contracts": "0.1.46"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"drizzle-orm": "1.0.0-rc.4"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve which origin (if any) a response's CORS headers should allow for this request.
|
|
3
|
+
*
|
|
4
|
+
* Entries are exact scheme+host[+port] strings (`https://app.example.com`, `http://localhost:5660`),
|
|
5
|
+
* plus one special form: a literal `"*"` entry allows EVERY origin by reflecting the request's
|
|
6
|
+
* `Origin` header back — never a literal `*` header value, which the Fetch spec rejects for
|
|
7
|
+
* credentialed requests (the toolkit's requests carry `Authorization`). Reflection is sound here
|
|
8
|
+
* because auth is a per-request bearer token, not ambient cookies: a hostile page cannot mint the
|
|
9
|
+
* header, so the origin list is deployment hygiene rather than the security boundary. Use `"*"` for
|
|
10
|
+
* dev/demo backends serving many local origins; enumerate exact origins for production.
|
|
11
|
+
*
|
|
12
|
+
* Returns `null` when the request has no `Origin` or it is not allowed — callers then omit CORS
|
|
13
|
+
* headers entirely, and the browser blocks the read.
|
|
14
|
+
*/
|
|
15
|
+
export function resolveCorsOrigin(request: Request, origins: readonly string[]): string | null {
|
|
16
|
+
const origin = request.headers.get("origin");
|
|
17
|
+
if (!origin) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return origins.includes("*") || origins.includes(origin) ? origin : null;
|
|
21
|
+
}
|
package/src/electric-proxy.ts
CHANGED
|
@@ -8,8 +8,13 @@ import {
|
|
|
8
8
|
type SyncTableRegistry,
|
|
9
9
|
} from "@pgxsinkit/contracts";
|
|
10
10
|
|
|
11
|
+
import { resolveCorsOrigin } from "./cors-origin";
|
|
12
|
+
|
|
11
13
|
export interface ElectricProxyCors {
|
|
12
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Browser origins allowed to read this shape: exact strings (e.g. a hosted SPA + localhost dev),
|
|
16
|
+
* or a `"*"` entry to allow every origin by reflection (see {@link resolveCorsOrigin}).
|
|
17
|
+
*/
|
|
13
18
|
origins: string[];
|
|
14
19
|
}
|
|
15
20
|
|
|
@@ -418,8 +423,7 @@ function isAbortError(error: unknown): boolean {
|
|
|
418
423
|
|
|
419
424
|
/** The request's `Origin` if it is on the allow-list, else `null` (so a disallowed origin gets no CORS). */
|
|
420
425
|
function allowedCorsOrigin(request: Request, cors: ElectricProxyCors): string | null {
|
|
421
|
-
|
|
422
|
-
return origin && cors.origins.includes(origin) ? origin : null;
|
|
426
|
+
return resolveCorsOrigin(request, cors.origins);
|
|
423
427
|
}
|
|
424
428
|
|
|
425
429
|
/** Answer a browser preflight: allowed origin, GET-only, the requested headers, cached for an hour. */
|
|
@@ -431,28 +431,29 @@ BEGIN
|
|
|
431
431
|
END IF;
|
|
432
432
|
|
|
433
433
|
-- Group the batch by (table, kind, payload column-set) and apply each group with one statement
|
|
434
|
-
-- (ADR-0014 Phase 4).
|
|
434
|
+
-- (ADR-0014 Phase 4). mutationSeq is table-local, so it cannot order groups across tables: parent
|
|
435
|
+
-- and child journals can both start at 1. WITH ORDINALITY preserves the submitted JSON array order
|
|
435
436
|
-- across tables (FK-safe; the batch transaction also runs SET CONSTRAINTS ALL DEFERRED).
|
|
436
437
|
FOR v_table, v_kind, v_sig, v_rows IN
|
|
437
438
|
SELECT
|
|
438
439
|
grouped.table_name,
|
|
439
440
|
grouped.kind,
|
|
440
441
|
grouped.sig,
|
|
441
|
-
jsonb_agg(grouped.mutation ORDER BY grouped.
|
|
442
|
+
jsonb_agg(grouped.mutation ORDER BY grouped.batch_position)
|
|
442
443
|
FROM (
|
|
443
444
|
SELECT
|
|
444
|
-
m->>'tableName' AS table_name,
|
|
445
|
-
m->>'kind' AS kind,
|
|
445
|
+
entries.m->>'tableName' AS table_name,
|
|
446
|
+
entries.m->>'kind' AS kind,
|
|
446
447
|
COALESCE((
|
|
447
448
|
SELECT string_agg(payload_key, ',' ORDER BY payload_key)
|
|
448
|
-
FROM jsonb_object_keys(COALESCE(m->'payload', '{}'::jsonb)) AS payload_key
|
|
449
|
+
FROM jsonb_object_keys(COALESCE(entries.m->'payload', '{}'::jsonb)) AS payload_key
|
|
449
450
|
), '') AS sig,
|
|
450
|
-
m AS mutation,
|
|
451
|
-
|
|
452
|
-
FROM jsonb_array_elements(p_batch->'mutations') AS m
|
|
451
|
+
entries.m AS mutation,
|
|
452
|
+
entries.batch_position
|
|
453
|
+
FROM jsonb_array_elements(p_batch->'mutations') WITH ORDINALITY AS entries(m, batch_position)
|
|
453
454
|
) AS grouped
|
|
454
455
|
GROUP BY grouped.table_name, grouped.kind, grouped.sig
|
|
455
|
-
ORDER BY MIN(grouped.
|
|
456
|
+
ORDER BY MIN(grouped.batch_position)
|
|
456
457
|
LOOP
|
|
457
458
|
dml_sql := NULL;
|
|
458
459
|
v_cols := NULL;
|
package/src/router.ts
CHANGED
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
// `proxyElectricShapeRequest` and the mutation handler are plain `(Request) => Response` functions, so
|
|
5
5
|
// they can equally be mounted in someone else's framework.
|
|
6
6
|
|
|
7
|
+
import { resolveCorsOrigin } from "./cors-origin";
|
|
8
|
+
|
|
7
9
|
export type FetchHandler = (request: Request) => Response | Promise<Response>;
|
|
8
10
|
|
|
9
11
|
export interface CorsConfig {
|
|
12
|
+
/** Exact origins, or a `"*"` entry to allow every origin by reflection (see {@link resolveCorsOrigin}). */
|
|
10
13
|
origins: string[];
|
|
11
14
|
allowMethods: string[];
|
|
12
15
|
allowHeaders: string[];
|
|
@@ -72,8 +75,7 @@ export class FetchRouter {
|
|
|
72
75
|
};
|
|
73
76
|
|
|
74
77
|
#allowedOrigin(request: Request): string | null {
|
|
75
|
-
|
|
76
|
-
return origin && this.#cors?.origins.includes(origin) ? origin : null;
|
|
78
|
+
return this.#cors ? resolveCorsOrigin(request, this.#cors.origins) : null;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
#preflight(request: Request): Response {
|