@webstudio-is/trpc-interface 0.91.0 → 0.260.2
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/package.json +26 -25
- package/src/authorize/project.server.test.ts +443 -0
- package/src/authorize/project.server.ts +309 -121
- package/src/authorize/role.ts +18 -0
- package/src/context/context.server.ts +59 -24
- package/src/context/errors.server.ts +16 -0
- package/src/context/router.server.ts +19 -0
- package/src/index.server.ts +15 -3
- package/src/shared/client.ts +0 -2
- package/src/shared/deployment.ts +23 -6
- package/src/shared/domain.ts +3 -3
- package/src/shared/plan-client.server.ts +7 -0
- package/src/shared/plan-features.ts +7 -0
- package/src/shared/shared-router.ts +0 -2
- package/src/shared/trpc.ts +5 -1
- package/src/trpc-caller-link.test.ts +1 -1
- package/src/trpc-caller-link.ts +1 -2
- package/tsconfig.json +3 -0
- package/lib/authorize/authorization-token.server.js +0 -72
- package/lib/authorize/project.server.js +0 -103
- package/lib/cjs/authorize/authorization-token.server.js +0 -92
- package/lib/cjs/authorize/project.server.js +0 -123
- package/lib/cjs/context/context.server.js +0 -16
- package/lib/cjs/context/errors.server.js +0 -29
- package/lib/cjs/index.js +0 -18
- package/lib/cjs/index.server.js +0 -40
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/shared/authorization-router.js +0 -184
- package/lib/cjs/shared/client.js +0 -63
- package/lib/cjs/shared/deployment.js +0 -51
- package/lib/cjs/shared/domain.js +0 -98
- package/lib/cjs/shared/shared-router.js +0 -32
- package/lib/cjs/shared/trpc.js +0 -31
- package/lib/cjs/trpc-caller-link.js +0 -46
- package/lib/context/context.server.js +0 -0
- package/lib/context/errors.server.js +0 -9
- package/lib/index.js +0 -1
- package/lib/index.server.js +0 -10
- package/lib/shared/authorization-router.js +0 -164
- package/lib/shared/client.js +0 -35
- package/lib/shared/deployment.js +0 -31
- package/lib/shared/domain.js +0 -78
- package/lib/shared/shared-router.js +0 -12
- package/lib/shared/trpc.js +0 -11
- package/lib/trpc-caller-link.js +0 -26
- package/lib/types/authorize/authorization-token.server.d.ts +0 -21
- package/lib/types/authorize/project.server.d.ts +0 -25
- package/lib/types/context/context.server.d.ts +0 -53
- package/lib/types/context/errors.server.d.ts +0 -1
- package/lib/types/index.d.ts +0 -1
- package/lib/types/index.server.d.ts +0 -7
- package/lib/types/shared/authorization-router.d.ts +0 -276
- package/lib/types/shared/client.d.ts +0 -8
- package/lib/types/shared/deployment.d.ts +0 -45
- package/lib/types/shared/domain.d.ts +0 -119
- package/lib/types/shared/shared-router.d.ts +0 -415
- package/lib/types/shared/trpc.d.ts +0 -48
- package/lib/types/trpc-caller-link.d.ts +0 -16
- package/lib/types/trpc-caller-link.test.d.ts +0 -49
- package/src/authorize/authorization-token.server.ts +0 -106
- package/src/shared/authorization-router.ts +0 -198
package/src/shared/deployment.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { router, procedure } from "./trpc";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// Has corresponding type in saas
|
|
5
|
+
export const PublishInput = z.object({
|
|
5
6
|
// used to load build data from the builder see routes/rest.build.$buildId.ts
|
|
6
7
|
buildId: z.string(),
|
|
7
|
-
|
|
8
|
+
builderOrigin: z.string(),
|
|
9
|
+
githubSha: z.string().optional(),
|
|
10
|
+
|
|
11
|
+
destination: z.enum(["saas", "static"]),
|
|
8
12
|
// preview support
|
|
9
13
|
branchName: z.string(),
|
|
10
14
|
// action log helper (not used for deployment, but for action logs readablity)
|
|
11
|
-
|
|
15
|
+
logProjectName: z.string(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const UnpublishInput = z.object({
|
|
19
|
+
domain: z.string(),
|
|
12
20
|
});
|
|
13
21
|
|
|
14
|
-
const Output = z.discriminatedUnion("success", [
|
|
22
|
+
export const Output = z.discriminatedUnion("success", [
|
|
15
23
|
z.object({
|
|
16
24
|
success: z.literal(true),
|
|
17
25
|
}),
|
|
@@ -29,10 +37,19 @@ export const deploymentRouter = router({
|
|
|
29
37
|
publish: procedure
|
|
30
38
|
.input(PublishInput)
|
|
31
39
|
.output(Output)
|
|
32
|
-
.mutation(
|
|
40
|
+
.mutation(() => {
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
error: "NOT_IMPLEMENTED",
|
|
44
|
+
};
|
|
45
|
+
}),
|
|
46
|
+
unpublish: procedure
|
|
47
|
+
.input(UnpublishInput)
|
|
48
|
+
.output(Output)
|
|
49
|
+
.mutation(() => {
|
|
33
50
|
return {
|
|
34
51
|
success: false,
|
|
35
|
-
error:
|
|
52
|
+
error: "NOT_IMPLEMENTED",
|
|
36
53
|
};
|
|
37
54
|
}),
|
|
38
55
|
});
|
package/src/shared/domain.ts
CHANGED
|
@@ -35,7 +35,7 @@ export const domainRouter = router({
|
|
|
35
35
|
create: procedure
|
|
36
36
|
.input(CreateInput)
|
|
37
37
|
.output(createOutput(z.optional(z.undefined())))
|
|
38
|
-
.mutation(async ({ input
|
|
38
|
+
.mutation(async ({ input }) => {
|
|
39
39
|
const record = dnsTxtEntries.get(input.domain);
|
|
40
40
|
if (record !== input.txtRecord) {
|
|
41
41
|
// Return an error once then update the record
|
|
@@ -57,7 +57,7 @@ export const domainRouter = router({
|
|
|
57
57
|
refresh: procedure
|
|
58
58
|
.input(Input)
|
|
59
59
|
.output(createOutput(z.optional(z.undefined())))
|
|
60
|
-
.mutation(async (
|
|
60
|
+
.mutation(async () => {
|
|
61
61
|
return { success: true };
|
|
62
62
|
}),
|
|
63
63
|
/**
|
|
@@ -73,7 +73,7 @@ export const domainRouter = router({
|
|
|
73
73
|
])
|
|
74
74
|
)
|
|
75
75
|
)
|
|
76
|
-
.query(async ({ input
|
|
76
|
+
.query(async ({ input }) => {
|
|
77
77
|
const domainState = domainStates.get(input.domain);
|
|
78
78
|
|
|
79
79
|
if (domainState === undefined) {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { createTRPCProxyClient } from "@trpc/client";
|
|
2
2
|
import { router } from "./trpc";
|
|
3
|
-
import { authorizationRouter } from "./authorization-router";
|
|
4
3
|
import { domainRouter } from "./domain";
|
|
5
4
|
import { deploymentRouter } from "./deployment";
|
|
6
5
|
|
|
7
6
|
export const sharedRouter = router({
|
|
8
|
-
authorize: authorizationRouter,
|
|
9
7
|
domain: domainRouter,
|
|
10
8
|
deployment: deploymentRouter,
|
|
11
9
|
});
|
package/src/shared/trpc.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { initTRPC, type inferAsyncReturnType } from "@trpc/server";
|
|
2
2
|
|
|
3
3
|
export const createContext = async () => {
|
|
4
|
-
|
|
4
|
+
// Use any for typecheck at saas to not use ctx router types in satisfies constraints
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
return {} as any;
|
|
5
7
|
};
|
|
6
8
|
|
|
7
9
|
export type Context = inferAsyncReturnType<typeof createContext>;
|
|
8
10
|
|
|
11
|
+
// Here is different router and trpc types not the same as in ../context/router.server.ts
|
|
12
|
+
// And used only for saas shared routers
|
|
9
13
|
export const { router, procedure, middleware } = initTRPC
|
|
10
14
|
.context<Context>()
|
|
11
15
|
.create();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { initTRPC } from "@trpc/server";
|
|
2
|
-
import { describe, test, expect } from "
|
|
2
|
+
import { describe, test, expect } from "vitest";
|
|
3
3
|
import { callerLink } from "./trpc-caller-link";
|
|
4
4
|
import { createTRPCProxyClient } from "@trpc/client";
|
|
5
5
|
import { z } from "zod";
|
package/src/trpc-caller-link.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AnyRouter } from "@trpc/server";
|
|
2
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
3
2
|
import { observable } from "@trpc/server/observable";
|
|
4
3
|
import { TRPCClientError, type TRPCLink } from "@trpc/client";
|
|
5
4
|
|
|
@@ -21,7 +20,7 @@ export const callerLink = <TemplateRouter extends AnyRouter>(
|
|
|
21
20
|
): TRPCLink<TemplateRouter> => {
|
|
22
21
|
const { appRouter, createContext } = opts;
|
|
23
22
|
|
|
24
|
-
return (
|
|
23
|
+
return (_runtime) =>
|
|
25
24
|
({ op }) =>
|
|
26
25
|
observable((observer) => {
|
|
27
26
|
const caller = appRouter.createCaller(createContext?.() ?? {});
|
package/tsconfig.json
ADDED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
const registerToken = async (props, context) => {
|
|
2
|
-
const { authorization } = context;
|
|
3
|
-
const { userId, authorizeTrpc } = authorization;
|
|
4
|
-
if (userId === void 0) {
|
|
5
|
-
throw new Error("The user must be authenticated to create a token");
|
|
6
|
-
}
|
|
7
|
-
await authorizeTrpc.create.mutate({
|
|
8
|
-
namespace: "Project",
|
|
9
|
-
id: props.projectId,
|
|
10
|
-
relation: props.relation,
|
|
11
|
-
subjectSet: {
|
|
12
|
-
namespace: "Token",
|
|
13
|
-
id: props.tokenId
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
const patchToken = async (props, prevRelation, nextRelation, context) => {
|
|
18
|
-
const { authorization } = context;
|
|
19
|
-
const { userId, authorizeTrpc } = authorization;
|
|
20
|
-
if (userId === void 0) {
|
|
21
|
-
throw new Error("The user must be authenticated to delete a token");
|
|
22
|
-
}
|
|
23
|
-
if (prevRelation !== nextRelation) {
|
|
24
|
-
await authorizeTrpc.patch.mutate([
|
|
25
|
-
{
|
|
26
|
-
action: "delete",
|
|
27
|
-
relationTuple: {
|
|
28
|
-
namespace: "Project",
|
|
29
|
-
id: props.projectId,
|
|
30
|
-
relation: prevRelation,
|
|
31
|
-
subjectSet: {
|
|
32
|
-
namespace: "Token",
|
|
33
|
-
id: props.tokenId
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
action: "insert",
|
|
39
|
-
relationTuple: {
|
|
40
|
-
namespace: "Project",
|
|
41
|
-
id: props.projectId,
|
|
42
|
-
relation: nextRelation,
|
|
43
|
-
subjectSet: {
|
|
44
|
-
namespace: "Token",
|
|
45
|
-
id: props.tokenId
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
]);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const unregisterToken = async (props, context) => {
|
|
53
|
-
const { authorization } = context;
|
|
54
|
-
const { userId, authorizeTrpc } = authorization;
|
|
55
|
-
if (userId === void 0) {
|
|
56
|
-
throw new Error("The user must be authenticated to delete a token");
|
|
57
|
-
}
|
|
58
|
-
await authorizeTrpc.delete.mutate({
|
|
59
|
-
namespace: "Project",
|
|
60
|
-
id: props.projectId,
|
|
61
|
-
relation: props.relation,
|
|
62
|
-
subjectSet: {
|
|
63
|
-
namespace: "Token",
|
|
64
|
-
id: props.tokenId
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
export {
|
|
69
|
-
patchToken,
|
|
70
|
-
registerToken,
|
|
71
|
-
unregisterToken
|
|
72
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
const registerProjectOwner = async (props, context) => {
|
|
2
|
-
const { authorization } = context;
|
|
3
|
-
const { userId, authorizeTrpc } = authorization;
|
|
4
|
-
if (userId === void 0) {
|
|
5
|
-
throw new Error("The user must be authenticated to create a project");
|
|
6
|
-
}
|
|
7
|
-
await authorizeTrpc.create.mutate({
|
|
8
|
-
namespace: "Project",
|
|
9
|
-
id: props.projectId,
|
|
10
|
-
relation: "owners",
|
|
11
|
-
subjectSet: {
|
|
12
|
-
namespace: "User",
|
|
13
|
-
id: userId
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
const hasProjectPermit = async (props, context) => {
|
|
18
|
-
const start = Date.now();
|
|
19
|
-
try {
|
|
20
|
-
const { authorization } = context;
|
|
21
|
-
const { authorizeTrpc } = authorization;
|
|
22
|
-
const checks = [];
|
|
23
|
-
const namespace = "Project";
|
|
24
|
-
if (props.permit === "view" && context.authorization.isServiceCall) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
if (props.permit === "view" && props.projectId === "62154aaef0cb0860ccf85d6e") {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
if (props.permit === "view" && context.authorization.projectTemplates.includes(props.projectId)) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
if (authorization.userId !== void 0) {
|
|
34
|
-
checks.push(
|
|
35
|
-
authorizeTrpc.check.query({
|
|
36
|
-
subjectSet: {
|
|
37
|
-
namespace: "User",
|
|
38
|
-
id: authorization.userId
|
|
39
|
-
},
|
|
40
|
-
namespace,
|
|
41
|
-
id: props.projectId,
|
|
42
|
-
permit: props.permit
|
|
43
|
-
})
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
if (authorization.authToken !== void 0 && props.permit !== "own") {
|
|
47
|
-
checks.push(
|
|
48
|
-
authorizeTrpc.check.query({
|
|
49
|
-
namespace,
|
|
50
|
-
id: props.projectId,
|
|
51
|
-
subjectSet: {
|
|
52
|
-
id: authorization.authToken,
|
|
53
|
-
namespace: "Token"
|
|
54
|
-
},
|
|
55
|
-
permit: props.permit
|
|
56
|
-
})
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
if (checks.length === 0) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
const authResults = await Promise.allSettled(checks);
|
|
63
|
-
for (const authResult of authResults) {
|
|
64
|
-
if (authResult.status === "rejected") {
|
|
65
|
-
throw new Error(`Authorization call failed ${authResult.reason}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const allowed = authResults.some(
|
|
69
|
-
(authResult) => authResult.status === "fulfilled" && authResult.value.allowed
|
|
70
|
-
);
|
|
71
|
-
return allowed;
|
|
72
|
-
} finally {
|
|
73
|
-
const diff = Date.now() - start;
|
|
74
|
-
console.log(`hasProjectPermit execution ${diff}ms`);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const getProjectPermit = async (props, context) => {
|
|
78
|
-
const start = Date.now();
|
|
79
|
-
try {
|
|
80
|
-
const permitToCheck = props.permits;
|
|
81
|
-
const permits = await Promise.allSettled(
|
|
82
|
-
permitToCheck.map(
|
|
83
|
-
(permit) => hasProjectPermit({ projectId: props.projectId, permit }, context)
|
|
84
|
-
)
|
|
85
|
-
);
|
|
86
|
-
for (const permit of permits) {
|
|
87
|
-
if (permit.status === "rejected") {
|
|
88
|
-
throw new Error(`Authorization call failed ${permit.reason}`);
|
|
89
|
-
}
|
|
90
|
-
if (permit.value === true) {
|
|
91
|
-
return permitToCheck[permits.indexOf(permit)];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
} finally {
|
|
95
|
-
const diff = Date.now() - start;
|
|
96
|
-
console.log(`getProjectPermit execution ${diff}ms`);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
export {
|
|
100
|
-
getProjectPermit,
|
|
101
|
-
hasProjectPermit,
|
|
102
|
-
registerProjectOwner
|
|
103
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var authorization_token_server_exports = {};
|
|
20
|
-
__export(authorization_token_server_exports, {
|
|
21
|
-
patchToken: () => patchToken,
|
|
22
|
-
registerToken: () => registerToken,
|
|
23
|
-
unregisterToken: () => unregisterToken
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(authorization_token_server_exports);
|
|
26
|
-
const registerToken = async (props, context) => {
|
|
27
|
-
const { authorization } = context;
|
|
28
|
-
const { userId, authorizeTrpc } = authorization;
|
|
29
|
-
if (userId === void 0) {
|
|
30
|
-
throw new Error("The user must be authenticated to create a token");
|
|
31
|
-
}
|
|
32
|
-
await authorizeTrpc.create.mutate({
|
|
33
|
-
namespace: "Project",
|
|
34
|
-
id: props.projectId,
|
|
35
|
-
relation: props.relation,
|
|
36
|
-
subjectSet: {
|
|
37
|
-
namespace: "Token",
|
|
38
|
-
id: props.tokenId
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
const patchToken = async (props, prevRelation, nextRelation, context) => {
|
|
43
|
-
const { authorization } = context;
|
|
44
|
-
const { userId, authorizeTrpc } = authorization;
|
|
45
|
-
if (userId === void 0) {
|
|
46
|
-
throw new Error("The user must be authenticated to delete a token");
|
|
47
|
-
}
|
|
48
|
-
if (prevRelation !== nextRelation) {
|
|
49
|
-
await authorizeTrpc.patch.mutate([
|
|
50
|
-
{
|
|
51
|
-
action: "delete",
|
|
52
|
-
relationTuple: {
|
|
53
|
-
namespace: "Project",
|
|
54
|
-
id: props.projectId,
|
|
55
|
-
relation: prevRelation,
|
|
56
|
-
subjectSet: {
|
|
57
|
-
namespace: "Token",
|
|
58
|
-
id: props.tokenId
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
action: "insert",
|
|
64
|
-
relationTuple: {
|
|
65
|
-
namespace: "Project",
|
|
66
|
-
id: props.projectId,
|
|
67
|
-
relation: nextRelation,
|
|
68
|
-
subjectSet: {
|
|
69
|
-
namespace: "Token",
|
|
70
|
-
id: props.tokenId
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
]);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const unregisterToken = async (props, context) => {
|
|
78
|
-
const { authorization } = context;
|
|
79
|
-
const { userId, authorizeTrpc } = authorization;
|
|
80
|
-
if (userId === void 0) {
|
|
81
|
-
throw new Error("The user must be authenticated to delete a token");
|
|
82
|
-
}
|
|
83
|
-
await authorizeTrpc.delete.mutate({
|
|
84
|
-
namespace: "Project",
|
|
85
|
-
id: props.projectId,
|
|
86
|
-
relation: props.relation,
|
|
87
|
-
subjectSet: {
|
|
88
|
-
namespace: "Token",
|
|
89
|
-
id: props.tokenId
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var project_server_exports = {};
|
|
20
|
-
__export(project_server_exports, {
|
|
21
|
-
getProjectPermit: () => getProjectPermit,
|
|
22
|
-
hasProjectPermit: () => hasProjectPermit,
|
|
23
|
-
registerProjectOwner: () => registerProjectOwner
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(project_server_exports);
|
|
26
|
-
const registerProjectOwner = async (props, context) => {
|
|
27
|
-
const { authorization } = context;
|
|
28
|
-
const { userId, authorizeTrpc } = authorization;
|
|
29
|
-
if (userId === void 0) {
|
|
30
|
-
throw new Error("The user must be authenticated to create a project");
|
|
31
|
-
}
|
|
32
|
-
await authorizeTrpc.create.mutate({
|
|
33
|
-
namespace: "Project",
|
|
34
|
-
id: props.projectId,
|
|
35
|
-
relation: "owners",
|
|
36
|
-
subjectSet: {
|
|
37
|
-
namespace: "User",
|
|
38
|
-
id: userId
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
const hasProjectPermit = async (props, context) => {
|
|
43
|
-
const start = Date.now();
|
|
44
|
-
try {
|
|
45
|
-
const { authorization } = context;
|
|
46
|
-
const { authorizeTrpc } = authorization;
|
|
47
|
-
const checks = [];
|
|
48
|
-
const namespace = "Project";
|
|
49
|
-
if (props.permit === "view" && context.authorization.isServiceCall) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
if (props.permit === "view" && props.projectId === "62154aaef0cb0860ccf85d6e") {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
if (props.permit === "view" && context.authorization.projectTemplates.includes(props.projectId)) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
if (authorization.userId !== void 0) {
|
|
59
|
-
checks.push(
|
|
60
|
-
authorizeTrpc.check.query({
|
|
61
|
-
subjectSet: {
|
|
62
|
-
namespace: "User",
|
|
63
|
-
id: authorization.userId
|
|
64
|
-
},
|
|
65
|
-
namespace,
|
|
66
|
-
id: props.projectId,
|
|
67
|
-
permit: props.permit
|
|
68
|
-
})
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
if (authorization.authToken !== void 0 && props.permit !== "own") {
|
|
72
|
-
checks.push(
|
|
73
|
-
authorizeTrpc.check.query({
|
|
74
|
-
namespace,
|
|
75
|
-
id: props.projectId,
|
|
76
|
-
subjectSet: {
|
|
77
|
-
id: authorization.authToken,
|
|
78
|
-
namespace: "Token"
|
|
79
|
-
},
|
|
80
|
-
permit: props.permit
|
|
81
|
-
})
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
if (checks.length === 0) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const authResults = await Promise.allSettled(checks);
|
|
88
|
-
for (const authResult of authResults) {
|
|
89
|
-
if (authResult.status === "rejected") {
|
|
90
|
-
throw new Error(`Authorization call failed ${authResult.reason}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
const allowed = authResults.some(
|
|
94
|
-
(authResult) => authResult.status === "fulfilled" && authResult.value.allowed
|
|
95
|
-
);
|
|
96
|
-
return allowed;
|
|
97
|
-
} finally {
|
|
98
|
-
const diff = Date.now() - start;
|
|
99
|
-
console.log(`hasProjectPermit execution ${diff}ms`);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
const getProjectPermit = async (props, context) => {
|
|
103
|
-
const start = Date.now();
|
|
104
|
-
try {
|
|
105
|
-
const permitToCheck = props.permits;
|
|
106
|
-
const permits = await Promise.allSettled(
|
|
107
|
-
permitToCheck.map(
|
|
108
|
-
(permit) => hasProjectPermit({ projectId: props.projectId, permit }, context)
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
for (const permit of permits) {
|
|
112
|
-
if (permit.status === "rejected") {
|
|
113
|
-
throw new Error(`Authorization call failed ${permit.reason}`);
|
|
114
|
-
}
|
|
115
|
-
if (permit.value === true) {
|
|
116
|
-
return permitToCheck[permits.indexOf(permit)];
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
} finally {
|
|
120
|
-
const diff = Date.now() - start;
|
|
121
|
-
console.log(`getProjectPermit execution ${diff}ms`);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var context_server_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(context_server_exports);
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var errors_server_exports = {};
|
|
20
|
-
__export(errors_server_exports, {
|
|
21
|
-
AuthorizationError: () => AuthorizationError
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(errors_server_exports);
|
|
24
|
-
var import_ts_custom_error = require("ts-custom-error");
|
|
25
|
-
const AuthorizationError = (0, import_ts_custom_error.customErrorFactory)(
|
|
26
|
-
function AuthorizationError2(message) {
|
|
27
|
-
this.message = message;
|
|
28
|
-
}
|
|
29
|
-
);
|
package/lib/cjs/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var src_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(src_exports);
|
|
18
|
-
__reExport(src_exports, require("./index.server"), module.exports);
|
package/lib/cjs/index.server.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var index_server_exports = {};
|
|
30
|
-
__export(index_server_exports, {
|
|
31
|
-
AuthorizationError: () => import_errors.AuthorizationError,
|
|
32
|
-
authorizeAuthorizationToken: () => authorizeAuthorizationToken,
|
|
33
|
-
authorizeProject: () => authorizeProject,
|
|
34
|
-
createTrpcProxyServiceClient: () => import_client.createTrpcProxyServiceClient
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_server_exports);
|
|
37
|
-
var import_client = require("./shared/client");
|
|
38
|
-
var import_errors = require("./context/errors.server");
|
|
39
|
-
var authorizeProject = __toESM(require("./authorize/project.server"), 1);
|
|
40
|
-
var authorizeAuthorizationToken = __toESM(require("./authorize/authorization-token.server"), 1);
|
package/lib/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|