prostgles-server 4.2.590 → 4.2.592
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/Auth/AuthHandler.d.ts +3 -5
- package/dist/Auth/AuthHandler.d.ts.map +1 -1
- package/dist/Auth/AuthHandler.js +16 -15
- package/dist/Auth/AuthHandler.js.map +1 -1
- package/dist/Auth/AuthTypes.d.ts +5 -1
- package/dist/Auth/AuthTypes.d.ts.map +1 -1
- package/dist/Auth/AuthTypes.js.map +1 -1
- package/dist/Auth/endpoints/setCatchAllRequestHandler.d.ts +2 -1
- package/dist/Auth/endpoints/setCatchAllRequestHandler.d.ts.map +1 -1
- package/dist/Auth/endpoints/setCatchAllRequestHandler.js +5 -4
- package/dist/Auth/endpoints/setCatchAllRequestHandler.js.map +1 -1
- package/dist/Auth/endpoints/setLogoutRequestHandler.d.ts +2 -1
- package/dist/Auth/endpoints/setLogoutRequestHandler.d.ts.map +1 -1
- package/dist/Auth/endpoints/setLogoutRequestHandler.js +2 -2
- package/dist/Auth/endpoints/setLogoutRequestHandler.js.map +1 -1
- package/dist/Auth/endpoints/setMagicLinkOrOTPRequestHandler.js +1 -1
- package/dist/Auth/endpoints/setRegisterRequestHandler.js +1 -1
- package/dist/Auth/endpoints/setRegisterRequestHandler.js.map +1 -1
- package/dist/Auth/getClientAuth.js +1 -1
- package/dist/Auth/getClientAuth.js.map +1 -1
- package/dist/Auth/login.d.ts.map +1 -1
- package/dist/Auth/login.js +8 -4
- package/dist/Auth/login.js.map +1 -1
- package/dist/Auth/setupAuthRoutes.d.ts +2 -1
- package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
- package/dist/Auth/setupAuthRoutes.js +5 -5
- package/dist/Auth/setupAuthRoutes.js.map +1 -1
- package/dist/Auth/utils/handleGetUser.d.ts.map +1 -1
- package/dist/Auth/utils/handleGetUser.js +9 -10
- package/dist/Auth/utils/handleGetUser.js.map +1 -1
- package/dist/Auth/utils/{setCookieAndGoToReturnURLIFSet.d.ts → setCookieAndGoToReturnURLIfSet.d.ts} +2 -2
- package/dist/Auth/utils/{setCookieAndGoToReturnURLIFSet.d.ts.map → setCookieAndGoToReturnURLIfSet.d.ts.map} +1 -1
- package/dist/Auth/utils/{setCookieAndGoToReturnURLIFSet.js → setCookieAndGoToReturnURLIfSet.js} +8 -5
- package/dist/Auth/utils/setCookieAndGoToReturnURLIfSet.js.map +1 -0
- package/dist/DBSchemaBuilder/DBSchemaBuilder.spec.js +3 -0
- package/dist/DBSchemaBuilder/DBSchemaBuilder.spec.js.map +1 -1
- package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.d.ts +38 -0
- package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.d.ts.map +1 -1
- package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.js +22 -18
- package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.js.map +1 -1
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +6 -5
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/defineServerFunction.d.ts +1 -1
- package/dist/PublishParser/defineServerFunction.d.ts.map +1 -1
- package/dist/PublishParser/defineServerFunction.js.map +1 -1
- package/lib/Auth/AuthHandler.ts +16 -17
- package/lib/Auth/AuthTypes.ts +9 -0
- package/lib/Auth/endpoints/setCatchAllRequestHandler.ts +5 -5
- package/lib/Auth/endpoints/setLogoutRequestHandler.ts +3 -2
- package/lib/Auth/endpoints/setMagicLinkOrOTPRequestHandler.ts +1 -1
- package/lib/Auth/endpoints/setRegisterRequestHandler.ts +2 -2
- package/lib/Auth/getClientAuth.ts +1 -1
- package/lib/Auth/login.ts +10 -4
- package/lib/Auth/setupAuthRoutes.ts +6 -5
- package/lib/Auth/utils/handleGetUser.ts +11 -10
- package/lib/Auth/utils/{setCookieAndGoToReturnURLIFSet.ts → setCookieAndGoToReturnURLIfSet.ts} +6 -3
- package/lib/DBSchemaBuilder/DBSchemaBuilder.spec.ts +3 -0
- package/lib/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.ts +23 -19
- package/lib/PublishParser/PublishParser.ts +12 -5
- package/lib/PublishParser/defineServerFunction.ts +4 -1
- package/package.json +1 -1
- package/dist/Auth/utils/setCookieAndGoToReturnURLIFSet.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import prostgles, { defineFunction } from "..";
|
|
1
|
+
import prostgles, { defineFunction, type ServerFunctionDefinitions } from "..";
|
|
2
2
|
|
|
3
3
|
type RecursiveResult = {
|
|
4
4
|
value: string;
|
|
@@ -11,25 +11,29 @@ type FixtureSchema = {
|
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
export const stateServerFunctions = {
|
|
15
|
+
public: {
|
|
16
|
+
userFilter: { type: "public" },
|
|
17
|
+
functions: {
|
|
18
|
+
recursiveResult: defineFunction({
|
|
19
|
+
run: (): RecursiveResult => ({ value: "ok" }),
|
|
20
|
+
}),
|
|
21
|
+
scalarResult: defineFunction({
|
|
22
|
+
input: { value: "number" },
|
|
23
|
+
run: ({ value }, { dbo }) => {
|
|
24
|
+
value satisfies number;
|
|
25
|
+
void dbo.orders.find();
|
|
26
|
+
// @ts-expect-error The schema must reach a function defined in another object.
|
|
27
|
+
void dbo.missingTable;
|
|
28
|
+
return value;
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
} as const satisfies ServerFunctionDefinitions<FixtureSchema>;
|
|
34
|
+
|
|
14
35
|
void prostgles<FixtureSchema>({
|
|
15
36
|
dbConnection: "",
|
|
16
37
|
onReady: () => {},
|
|
17
|
-
functions:
|
|
18
|
-
public: {
|
|
19
|
-
userFilter: { type: "public" },
|
|
20
|
-
functions: {
|
|
21
|
-
recursiveResult: defineFunction({
|
|
22
|
-
run: (): RecursiveResult => ({ value: "ok" }),
|
|
23
|
-
}),
|
|
24
|
-
scalarResult: defineFunction({
|
|
25
|
-
run: (_args, { dbo }) => {
|
|
26
|
-
void dbo.orders.find();
|
|
27
|
-
// @ts-expect-error The surrounding prostgles schema must reach defineFunction.
|
|
28
|
-
void dbo.missingTable;
|
|
29
|
-
return 42;
|
|
30
|
-
},
|
|
31
|
-
}),
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
38
|
+
functions: stateServerFunctions,
|
|
35
39
|
});
|
|
@@ -71,9 +71,13 @@ export class PublishParser {
|
|
|
71
71
|
if (!functionGroups || !publishParams.user) {
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
+
const { findUser } = this.prostgles.opts.auth ?? {};
|
|
75
|
+
if (!findUser) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
"findUser function is missing in auth config. It is required for functions to work.",
|
|
78
|
+
);
|
|
79
|
+
}
|
|
74
80
|
const user = publishParams.user;
|
|
75
|
-
const users = publishParams.dbo.users;
|
|
76
|
-
if (!users?.findOne) return;
|
|
77
81
|
const userId = user.id;
|
|
78
82
|
if (!userId || typeof userId !== "string") {
|
|
79
83
|
throw "User ID is missing or invalid";
|
|
@@ -81,9 +85,12 @@ export class PublishParser {
|
|
|
81
85
|
const allowedFunctionsMap = new Map<string, ServerFunctionDefinition>();
|
|
82
86
|
|
|
83
87
|
for (const group of Object.values(functionGroups)) {
|
|
84
|
-
const matchingUser = await
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
const matchingUser = await findUser(
|
|
89
|
+
{
|
|
90
|
+
$and: [group.userFilter, { id: userId }],
|
|
91
|
+
},
|
|
92
|
+
publishParams.dbo,
|
|
93
|
+
);
|
|
87
94
|
if (!matchingUser) continue;
|
|
88
95
|
|
|
89
96
|
for (const [name, method] of Object.entries(group.functions)) {
|
|
@@ -48,7 +48,10 @@ export type ServerFunctionDefinition = {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
declare const serverFunctionContext: unique symbol;
|
|
51
|
-
type ServerFunctionContextMarker<
|
|
51
|
+
export type ServerFunctionContextMarker<
|
|
52
|
+
S,
|
|
53
|
+
SUser extends SessionUser,
|
|
54
|
+
> = {
|
|
52
55
|
[serverFunctionContext]?: [S, SUser];
|
|
53
56
|
};
|
|
54
57
|
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setCookieAndGoToReturnURLIFSet.js","sourceRoot":"","sources":["../../../lib/Auth/utils/setCookieAndGoToReturnURLIFSet.ts"],"names":[],"mappings":";;AAQA,kEAcC;AAED,wEA8CC;AAtED,gDAA+F;AAG/F,oCAAoD;AACpD,2EAAwE;AACxE,yDAAsD;AACtD,iDAA8C;AAE9C,SAAgB,2BAA2B,CAEzC,MAAwC,EACxC,cAA8D;IAE9D,MAAM,gBAAgB,GAAG,IAAA,gCAAwB,EAAC,MAAM,CAAC,CAAC;IAC1D,IAAI,gBAAgB,EAAE,CAAC;QACrB,MAAM,EAAE,GAAG,EAAE,GAAG,cAAc,CAAC;QAC/B,OAAO,GAAG,CAAC,MAAM,CAAC,6BAAe,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC;YACnD,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,gBAAgB;SACvB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC,8BAA8B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AACrE,CAAC;AAED,SAAgB,8BAA8B,CAE5C,MAAwC,EACxC,cAA8D;IAE9D,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAChC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,cAAc,CAAC;IACpC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,YAAY,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,YAAY;IAE/C,IAAI,cAAc,GAA4B;QAC5C,MAAM,EAAE,YAAY;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