@webstudio-is/trpc-interface 0.57.0 → 0.59.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.
- package/lib/cjs/shared/client.js +14 -0
- package/lib/shared/client.js +4 -0
- package/lib/types/authorize/authorization-token.server.d.ts +21 -0
- package/lib/types/authorize/project.server.d.ts +25 -0
- package/lib/types/context/context.server.d.ts +28 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.server.d.ts +6 -0
- package/lib/types/shared/authorization-router.d.ts +276 -0
- package/lib/types/shared/client.d.ts +8 -0
- package/lib/types/shared/shared-router.d.ts +265 -0
- package/lib/types/shared/trpc.d.ts +48 -0
- package/lib/types/trpc-caller-link.d.ts +16 -0
- package/lib/types/trpc-caller-link.test.d.ts +49 -0
- package/package.json +6 -5
- package/src/shared/client.ts +4 -0
package/lib/cjs/shared/client.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,12 +17,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var client_exports = {};
|
|
20
30
|
__export(client_exports, {
|
|
21
31
|
createTrpcProxyServiceClient: () => createTrpcProxyServiceClient
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(client_exports);
|
|
34
|
+
var import_node_fetch = __toESM(require("node-fetch"), 1);
|
|
24
35
|
var import_client = require("@trpc/client");
|
|
25
36
|
var import_shared_router = require("./shared-router");
|
|
26
37
|
var import_trpc_caller_link = require("../trpc-caller-link");
|
|
@@ -29,6 +40,9 @@ const createTrpcProxyServiceClient = (options) => {
|
|
|
29
40
|
const remoteClient = (0, import_client.createTRPCProxyClient)({
|
|
30
41
|
links: [
|
|
31
42
|
(0, import_client.httpBatchLink)({
|
|
43
|
+
// httpBatchLink uses lib.dom.d.ts's fetch type
|
|
44
|
+
// which is incompatible with node fetch type.
|
|
45
|
+
fetch: import_node_fetch.default,
|
|
32
46
|
url: options.url,
|
|
33
47
|
headers: () => ({
|
|
34
48
|
Authorization: options.token,
|
package/lib/shared/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fetch from "node-fetch";
|
|
1
2
|
import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
|
|
2
3
|
import {
|
|
3
4
|
sharedRouter
|
|
@@ -8,6 +9,9 @@ const createTrpcProxyServiceClient = (options) => {
|
|
|
8
9
|
const remoteClient = createTRPCProxyClient({
|
|
9
10
|
links: [
|
|
10
11
|
httpBatchLink({
|
|
12
|
+
// httpBatchLink uses lib.dom.d.ts's fetch type
|
|
13
|
+
// which is incompatible with node fetch type.
|
|
14
|
+
fetch,
|
|
11
15
|
url: options.url,
|
|
12
16
|
headers: () => ({
|
|
13
17
|
Authorization: options.token,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AppContext } from "../context/context.server";
|
|
2
|
+
/**
|
|
3
|
+
* For 3rd party authorization systems like Ory we need to register token for the project.
|
|
4
|
+
*
|
|
5
|
+
* We do that before the authorizationToken create (and out of the transaction),
|
|
6
|
+
* so in case of an error we will have just stale records of non existed projects in authorization system.
|
|
7
|
+
*/
|
|
8
|
+
export declare const registerToken: (props: {
|
|
9
|
+
projectId: string;
|
|
10
|
+
tokenId: string;
|
|
11
|
+
relation: "viewers" | "editors" | "builders";
|
|
12
|
+
}, context: AppContext) => Promise<void>;
|
|
13
|
+
export declare const patchToken: (props: {
|
|
14
|
+
projectId: string;
|
|
15
|
+
tokenId: string;
|
|
16
|
+
}, prevRelation: "viewers" | "editors" | "builders", nextRelation: "viewers" | "editors" | "builders", context: AppContext) => Promise<void>;
|
|
17
|
+
export declare const unregisterToken: (props: {
|
|
18
|
+
projectId: string;
|
|
19
|
+
tokenId: string;
|
|
20
|
+
relation: "viewers" | "editors";
|
|
21
|
+
}, context: AppContext) => Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Project } from "@webstudio-is/prisma-client";
|
|
2
|
+
import type { AuthPermit } from "../shared/authorization-router";
|
|
3
|
+
import type { AppContext } from "../context/context.server";
|
|
4
|
+
/**
|
|
5
|
+
* For 3rd party authorization systems like Ory we need to register the project owner.
|
|
6
|
+
*
|
|
7
|
+
* We do that before the project create (and out of the transaction),
|
|
8
|
+
* so in case of an error we will have just stale records of non existed projects in authorization system.
|
|
9
|
+
*/
|
|
10
|
+
export declare const registerProjectOwner: (props: {
|
|
11
|
+
projectId: string;
|
|
12
|
+
}, context: AppContext) => Promise<void>;
|
|
13
|
+
export declare const hasProjectPermit: (props: {
|
|
14
|
+
projectId: Project["id"];
|
|
15
|
+
permit: AuthPermit;
|
|
16
|
+
}, context: AppContext) => Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the first allowed permit from the list or undefined if none is allowed
|
|
19
|
+
* @todo think about caching to authorizeTrpc.check.query
|
|
20
|
+
* batching check queries would help too https://github.com/ory/keto/issues/812
|
|
21
|
+
*/
|
|
22
|
+
export declare const getProjectPermit: <T extends "build" | "view" | "edit" | "own">(props: {
|
|
23
|
+
projectId: string;
|
|
24
|
+
permits: readonly T[];
|
|
25
|
+
}, context: AppContext) => Promise<T | undefined>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TrpcInterfaceClient } from "../shared/shared-router";
|
|
2
|
+
/**
|
|
3
|
+
* All necessary parameters for Authorization
|
|
4
|
+
*/
|
|
5
|
+
type AuthorizationContext = {
|
|
6
|
+
/**
|
|
7
|
+
* userId of the current authenticated user
|
|
8
|
+
*/
|
|
9
|
+
userId: string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* token URLSearchParams or hostname
|
|
12
|
+
*/
|
|
13
|
+
authToken: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* buildEnv==="prod" only if we are loading project with production build
|
|
16
|
+
*/
|
|
17
|
+
buildEnv: "dev" | "prod";
|
|
18
|
+
authorizeTrpc: TrpcInterfaceClient["authorize"];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* AppContext is a global context that is passed to all trpc/api queries/mutations
|
|
22
|
+
* "authorization" is made inside the namespace because eventually there will be
|
|
23
|
+
* logging parameters, potentially "request" cache, etc.
|
|
24
|
+
*/
|
|
25
|
+
export type AppContext = {
|
|
26
|
+
authorization: AuthorizationContext;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./index.server";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { SharedRouter } from "./shared/shared-router";
|
|
2
|
+
export { createTrpcProxyServiceClient } from "./shared/client";
|
|
3
|
+
export type { AppContext } from "./context/context.server";
|
|
4
|
+
export * as authorizeProject from "./authorize/project.server";
|
|
5
|
+
export * as authorizeAuthorizationToken from "./authorize/authorization-token.server";
|
|
6
|
+
export type { AuthPermit } from "./shared/authorization-router";
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const AuthPermit: z.ZodEnum<["view", "edit", "build", "own"]>;
|
|
3
|
+
export type AuthPermit = z.infer<typeof AuthPermit>;
|
|
4
|
+
export declare const authorizationRouter: import("@trpc/server").CreateRouterInner<import("@trpc/server").RootConfig<{
|
|
5
|
+
ctx: {};
|
|
6
|
+
meta: object;
|
|
7
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
8
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
9
|
+
}>, {
|
|
10
|
+
/**
|
|
11
|
+
* Relation expansion in authorize looks like a tree
|
|
12
|
+
*
|
|
13
|
+
* :#@Project:AliceProjectUUID#viewers
|
|
14
|
+
* :#@Email:bob@bob.com#owner
|
|
15
|
+
* :#@User:BobUUID️
|
|
16
|
+
* :#@Token:LinkRandomSequence️
|
|
17
|
+
*
|
|
18
|
+
* We don't need the whole tree in UI and need only the leaf nodes.
|
|
19
|
+
* i.e. @User:BobUUID️, @Token:LinkRandomSequence️ and the root relation i.e "viewers"
|
|
20
|
+
*/
|
|
21
|
+
expandLeafNodes: import("@trpc/server").BuildProcedure<"query", {
|
|
22
|
+
_config: import("@trpc/server").RootConfig<{
|
|
23
|
+
ctx: {};
|
|
24
|
+
meta: object;
|
|
25
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
26
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
27
|
+
}>;
|
|
28
|
+
_meta: object;
|
|
29
|
+
_ctx_out: {};
|
|
30
|
+
_input_in: {
|
|
31
|
+
id: string;
|
|
32
|
+
namespace: "Project";
|
|
33
|
+
};
|
|
34
|
+
_input_out: {
|
|
35
|
+
id: string;
|
|
36
|
+
namespace: "Project";
|
|
37
|
+
};
|
|
38
|
+
_output_in: {
|
|
39
|
+
id: string;
|
|
40
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
41
|
+
namespace: "User" | "Token" | "Email";
|
|
42
|
+
}[];
|
|
43
|
+
_output_out: {
|
|
44
|
+
id: string;
|
|
45
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
46
|
+
namespace: "User" | "Token" | "Email";
|
|
47
|
+
}[];
|
|
48
|
+
}, unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* Check if subject has permit on the resource
|
|
51
|
+
*/
|
|
52
|
+
check: import("@trpc/server").BuildProcedure<"query", {
|
|
53
|
+
_config: import("@trpc/server").RootConfig<{
|
|
54
|
+
ctx: {};
|
|
55
|
+
meta: object;
|
|
56
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
57
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
58
|
+
}>;
|
|
59
|
+
_meta: object;
|
|
60
|
+
_ctx_out: {};
|
|
61
|
+
_input_in: {
|
|
62
|
+
id: string;
|
|
63
|
+
namespace: "Project";
|
|
64
|
+
subjectSet: {
|
|
65
|
+
id: string;
|
|
66
|
+
namespace: "User" | "Token";
|
|
67
|
+
};
|
|
68
|
+
permit: "build" | "view" | "edit" | "own";
|
|
69
|
+
};
|
|
70
|
+
_input_out: {
|
|
71
|
+
id: string;
|
|
72
|
+
namespace: "Project";
|
|
73
|
+
subjectSet: {
|
|
74
|
+
id: string;
|
|
75
|
+
namespace: "User" | "Token";
|
|
76
|
+
};
|
|
77
|
+
permit: "build" | "view" | "edit" | "own";
|
|
78
|
+
};
|
|
79
|
+
_output_in: {
|
|
80
|
+
allowed: boolean;
|
|
81
|
+
};
|
|
82
|
+
_output_out: {
|
|
83
|
+
allowed: boolean;
|
|
84
|
+
};
|
|
85
|
+
}, unknown>;
|
|
86
|
+
/**
|
|
87
|
+
* In OSS we extract owner relation from the Project table, and the rest from the authorizationToken table
|
|
88
|
+
*/
|
|
89
|
+
create: import("@trpc/server").BuildProcedure<"mutation", {
|
|
90
|
+
_config: import("@trpc/server").RootConfig<{
|
|
91
|
+
ctx: {};
|
|
92
|
+
meta: object;
|
|
93
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
94
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
95
|
+
}>;
|
|
96
|
+
_meta: object;
|
|
97
|
+
_ctx_out: {};
|
|
98
|
+
_input_in: {
|
|
99
|
+
id: string;
|
|
100
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
101
|
+
namespace: "Project";
|
|
102
|
+
subjectSet: {
|
|
103
|
+
id: string;
|
|
104
|
+
namespace: "User";
|
|
105
|
+
} | {
|
|
106
|
+
id: string;
|
|
107
|
+
namespace: "Token";
|
|
108
|
+
} | {
|
|
109
|
+
id: string;
|
|
110
|
+
relation: "owners";
|
|
111
|
+
namespace: "Email";
|
|
112
|
+
};
|
|
113
|
+
} | {
|
|
114
|
+
id: string;
|
|
115
|
+
relation: "owners";
|
|
116
|
+
namespace: "Email";
|
|
117
|
+
subjectSet: {
|
|
118
|
+
id: string;
|
|
119
|
+
namespace: "User";
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
_input_out: {
|
|
123
|
+
id: string;
|
|
124
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
125
|
+
namespace: "Project";
|
|
126
|
+
subjectSet: {
|
|
127
|
+
id: string;
|
|
128
|
+
namespace: "User";
|
|
129
|
+
} | {
|
|
130
|
+
id: string;
|
|
131
|
+
namespace: "Token";
|
|
132
|
+
} | {
|
|
133
|
+
id: string;
|
|
134
|
+
relation: "owners";
|
|
135
|
+
namespace: "Email";
|
|
136
|
+
};
|
|
137
|
+
} | {
|
|
138
|
+
id: string;
|
|
139
|
+
relation: "owners";
|
|
140
|
+
namespace: "Email";
|
|
141
|
+
subjectSet: {
|
|
142
|
+
id: string;
|
|
143
|
+
namespace: "User";
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
147
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
148
|
+
}, void>;
|
|
149
|
+
delete: import("@trpc/server").BuildProcedure<"mutation", {
|
|
150
|
+
_config: import("@trpc/server").RootConfig<{
|
|
151
|
+
ctx: {};
|
|
152
|
+
meta: object;
|
|
153
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
154
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
155
|
+
}>;
|
|
156
|
+
_meta: object;
|
|
157
|
+
_ctx_out: {};
|
|
158
|
+
_input_in: {
|
|
159
|
+
id: string;
|
|
160
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
161
|
+
namespace: "Project";
|
|
162
|
+
subjectSet: {
|
|
163
|
+
id: string;
|
|
164
|
+
namespace: "User";
|
|
165
|
+
} | {
|
|
166
|
+
id: string;
|
|
167
|
+
namespace: "Token";
|
|
168
|
+
} | {
|
|
169
|
+
id: string;
|
|
170
|
+
relation: "owners";
|
|
171
|
+
namespace: "Email";
|
|
172
|
+
};
|
|
173
|
+
} | {
|
|
174
|
+
id: string;
|
|
175
|
+
relation: "owners";
|
|
176
|
+
namespace: "Email";
|
|
177
|
+
subjectSet: {
|
|
178
|
+
id: string;
|
|
179
|
+
namespace: "User";
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
_input_out: {
|
|
183
|
+
id: string;
|
|
184
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
185
|
+
namespace: "Project";
|
|
186
|
+
subjectSet: {
|
|
187
|
+
id: string;
|
|
188
|
+
namespace: "User";
|
|
189
|
+
} | {
|
|
190
|
+
id: string;
|
|
191
|
+
namespace: "Token";
|
|
192
|
+
} | {
|
|
193
|
+
id: string;
|
|
194
|
+
relation: "owners";
|
|
195
|
+
namespace: "Email";
|
|
196
|
+
};
|
|
197
|
+
} | {
|
|
198
|
+
id: string;
|
|
199
|
+
relation: "owners";
|
|
200
|
+
namespace: "Email";
|
|
201
|
+
subjectSet: {
|
|
202
|
+
id: string;
|
|
203
|
+
namespace: "User";
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
207
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
208
|
+
}, void>;
|
|
209
|
+
patch: import("@trpc/server").BuildProcedure<"mutation", {
|
|
210
|
+
_config: import("@trpc/server").RootConfig<{
|
|
211
|
+
ctx: {};
|
|
212
|
+
meta: object;
|
|
213
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
214
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
215
|
+
}>;
|
|
216
|
+
_meta: object;
|
|
217
|
+
_ctx_out: {};
|
|
218
|
+
_input_in: {
|
|
219
|
+
action: "delete" | "insert";
|
|
220
|
+
relationTuple: {
|
|
221
|
+
id: string;
|
|
222
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
223
|
+
namespace: "Project";
|
|
224
|
+
subjectSet: {
|
|
225
|
+
id: string;
|
|
226
|
+
namespace: "User";
|
|
227
|
+
} | {
|
|
228
|
+
id: string;
|
|
229
|
+
namespace: "Token";
|
|
230
|
+
} | {
|
|
231
|
+
id: string;
|
|
232
|
+
relation: "owners";
|
|
233
|
+
namespace: "Email";
|
|
234
|
+
};
|
|
235
|
+
} | {
|
|
236
|
+
id: string;
|
|
237
|
+
relation: "owners";
|
|
238
|
+
namespace: "Email";
|
|
239
|
+
subjectSet: {
|
|
240
|
+
id: string;
|
|
241
|
+
namespace: "User";
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
}[];
|
|
245
|
+
_input_out: {
|
|
246
|
+
action: "delete" | "insert";
|
|
247
|
+
relationTuple: {
|
|
248
|
+
id: string;
|
|
249
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
250
|
+
namespace: "Project";
|
|
251
|
+
subjectSet: {
|
|
252
|
+
id: string;
|
|
253
|
+
namespace: "User";
|
|
254
|
+
} | {
|
|
255
|
+
id: string;
|
|
256
|
+
namespace: "Token";
|
|
257
|
+
} | {
|
|
258
|
+
id: string;
|
|
259
|
+
relation: "owners";
|
|
260
|
+
namespace: "Email";
|
|
261
|
+
};
|
|
262
|
+
} | {
|
|
263
|
+
id: string;
|
|
264
|
+
relation: "owners";
|
|
265
|
+
namespace: "Email";
|
|
266
|
+
subjectSet: {
|
|
267
|
+
id: string;
|
|
268
|
+
namespace: "User";
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
}[];
|
|
272
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
273
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
274
|
+
}, void>;
|
|
275
|
+
}>;
|
|
276
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type TrpcInterfaceClient } from "./shared-router";
|
|
2
|
+
type SharedClientOptions = {
|
|
3
|
+
url: string;
|
|
4
|
+
token: string;
|
|
5
|
+
branchName: string | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare const createTrpcProxyServiceClient: (options?: SharedClientOptions | undefined) => TrpcInterfaceClient;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import type { createTRPCProxyClient } from "@trpc/client";
|
|
2
|
+
export declare const sharedRouter: import("@trpc/server").CreateRouterInner<import("@trpc/server").RootConfig<{
|
|
3
|
+
ctx: {};
|
|
4
|
+
meta: object;
|
|
5
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
6
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
7
|
+
}>, {
|
|
8
|
+
authorize: import("@trpc/server").CreateRouterInner<import("@trpc/server").RootConfig<{
|
|
9
|
+
ctx: {};
|
|
10
|
+
meta: object;
|
|
11
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
12
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
13
|
+
}>, {
|
|
14
|
+
expandLeafNodes: import("@trpc/server").BuildProcedure<"query", {
|
|
15
|
+
_config: import("@trpc/server").RootConfig<{
|
|
16
|
+
ctx: {};
|
|
17
|
+
meta: object;
|
|
18
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
19
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
20
|
+
}>;
|
|
21
|
+
_meta: object;
|
|
22
|
+
_ctx_out: {};
|
|
23
|
+
_input_in: {
|
|
24
|
+
id: string;
|
|
25
|
+
namespace: "Project";
|
|
26
|
+
};
|
|
27
|
+
_input_out: {
|
|
28
|
+
id: string;
|
|
29
|
+
namespace: "Project";
|
|
30
|
+
};
|
|
31
|
+
_output_in: {
|
|
32
|
+
id: string;
|
|
33
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
34
|
+
namespace: "User" | "Token" | "Email";
|
|
35
|
+
}[];
|
|
36
|
+
_output_out: {
|
|
37
|
+
id: string;
|
|
38
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
39
|
+
namespace: "User" | "Token" | "Email";
|
|
40
|
+
}[];
|
|
41
|
+
}, unknown>;
|
|
42
|
+
check: import("@trpc/server").BuildProcedure<"query", {
|
|
43
|
+
_config: import("@trpc/server").RootConfig<{
|
|
44
|
+
ctx: {};
|
|
45
|
+
meta: object;
|
|
46
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
47
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
48
|
+
}>;
|
|
49
|
+
_meta: object;
|
|
50
|
+
_ctx_out: {};
|
|
51
|
+
_input_in: {
|
|
52
|
+
id: string;
|
|
53
|
+
namespace: "Project";
|
|
54
|
+
subjectSet: {
|
|
55
|
+
id: string;
|
|
56
|
+
namespace: "User" | "Token";
|
|
57
|
+
};
|
|
58
|
+
permit: "build" | "view" | "edit" | "own";
|
|
59
|
+
};
|
|
60
|
+
_input_out: {
|
|
61
|
+
id: string;
|
|
62
|
+
namespace: "Project";
|
|
63
|
+
subjectSet: {
|
|
64
|
+
id: string;
|
|
65
|
+
namespace: "User" | "Token";
|
|
66
|
+
};
|
|
67
|
+
permit: "build" | "view" | "edit" | "own";
|
|
68
|
+
};
|
|
69
|
+
_output_in: {
|
|
70
|
+
allowed: boolean;
|
|
71
|
+
};
|
|
72
|
+
_output_out: {
|
|
73
|
+
allowed: boolean;
|
|
74
|
+
};
|
|
75
|
+
}, unknown>;
|
|
76
|
+
create: import("@trpc/server").BuildProcedure<"mutation", {
|
|
77
|
+
_config: import("@trpc/server").RootConfig<{
|
|
78
|
+
ctx: {};
|
|
79
|
+
meta: object;
|
|
80
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
81
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
82
|
+
}>;
|
|
83
|
+
_meta: object;
|
|
84
|
+
_ctx_out: {};
|
|
85
|
+
_input_in: {
|
|
86
|
+
id: string;
|
|
87
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
88
|
+
namespace: "Project";
|
|
89
|
+
subjectSet: {
|
|
90
|
+
id: string;
|
|
91
|
+
namespace: "User";
|
|
92
|
+
} | {
|
|
93
|
+
id: string;
|
|
94
|
+
namespace: "Token";
|
|
95
|
+
} | {
|
|
96
|
+
id: string;
|
|
97
|
+
relation: "owners";
|
|
98
|
+
namespace: "Email";
|
|
99
|
+
};
|
|
100
|
+
} | {
|
|
101
|
+
id: string;
|
|
102
|
+
relation: "owners";
|
|
103
|
+
namespace: "Email";
|
|
104
|
+
subjectSet: {
|
|
105
|
+
id: string;
|
|
106
|
+
namespace: "User";
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
_input_out: {
|
|
110
|
+
id: string;
|
|
111
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
112
|
+
namespace: "Project";
|
|
113
|
+
subjectSet: {
|
|
114
|
+
id: string;
|
|
115
|
+
namespace: "User";
|
|
116
|
+
} | {
|
|
117
|
+
id: string;
|
|
118
|
+
namespace: "Token";
|
|
119
|
+
} | {
|
|
120
|
+
id: string;
|
|
121
|
+
relation: "owners";
|
|
122
|
+
namespace: "Email";
|
|
123
|
+
};
|
|
124
|
+
} | {
|
|
125
|
+
id: string;
|
|
126
|
+
relation: "owners";
|
|
127
|
+
namespace: "Email";
|
|
128
|
+
subjectSet: {
|
|
129
|
+
id: string;
|
|
130
|
+
namespace: "User";
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
134
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
135
|
+
}, void>;
|
|
136
|
+
delete: import("@trpc/server").BuildProcedure<"mutation", {
|
|
137
|
+
_config: import("@trpc/server").RootConfig<{
|
|
138
|
+
ctx: {};
|
|
139
|
+
meta: object;
|
|
140
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
141
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
142
|
+
}>;
|
|
143
|
+
_meta: object;
|
|
144
|
+
_ctx_out: {};
|
|
145
|
+
_input_in: {
|
|
146
|
+
id: string;
|
|
147
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
148
|
+
namespace: "Project";
|
|
149
|
+
subjectSet: {
|
|
150
|
+
id: string;
|
|
151
|
+
namespace: "User";
|
|
152
|
+
} | {
|
|
153
|
+
id: string;
|
|
154
|
+
namespace: "Token";
|
|
155
|
+
} | {
|
|
156
|
+
id: string;
|
|
157
|
+
relation: "owners";
|
|
158
|
+
namespace: "Email";
|
|
159
|
+
};
|
|
160
|
+
} | {
|
|
161
|
+
id: string;
|
|
162
|
+
relation: "owners";
|
|
163
|
+
namespace: "Email";
|
|
164
|
+
subjectSet: {
|
|
165
|
+
id: string;
|
|
166
|
+
namespace: "User";
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
_input_out: {
|
|
170
|
+
id: string;
|
|
171
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
172
|
+
namespace: "Project";
|
|
173
|
+
subjectSet: {
|
|
174
|
+
id: string;
|
|
175
|
+
namespace: "User";
|
|
176
|
+
} | {
|
|
177
|
+
id: string;
|
|
178
|
+
namespace: "Token";
|
|
179
|
+
} | {
|
|
180
|
+
id: string;
|
|
181
|
+
relation: "owners";
|
|
182
|
+
namespace: "Email";
|
|
183
|
+
};
|
|
184
|
+
} | {
|
|
185
|
+
id: string;
|
|
186
|
+
relation: "owners";
|
|
187
|
+
namespace: "Email";
|
|
188
|
+
subjectSet: {
|
|
189
|
+
id: string;
|
|
190
|
+
namespace: "User";
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
194
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
195
|
+
}, void>;
|
|
196
|
+
patch: import("@trpc/server").BuildProcedure<"mutation", {
|
|
197
|
+
_config: import("@trpc/server").RootConfig<{
|
|
198
|
+
ctx: {};
|
|
199
|
+
meta: object;
|
|
200
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
201
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
202
|
+
}>;
|
|
203
|
+
_meta: object;
|
|
204
|
+
_ctx_out: {};
|
|
205
|
+
_input_in: {
|
|
206
|
+
action: "delete" | "insert";
|
|
207
|
+
relationTuple: {
|
|
208
|
+
id: string;
|
|
209
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
210
|
+
namespace: "Project";
|
|
211
|
+
subjectSet: {
|
|
212
|
+
id: string;
|
|
213
|
+
namespace: "User";
|
|
214
|
+
} | {
|
|
215
|
+
id: string;
|
|
216
|
+
namespace: "Token";
|
|
217
|
+
} | {
|
|
218
|
+
id: string;
|
|
219
|
+
relation: "owners";
|
|
220
|
+
namespace: "Email";
|
|
221
|
+
};
|
|
222
|
+
} | {
|
|
223
|
+
id: string;
|
|
224
|
+
relation: "owners";
|
|
225
|
+
namespace: "Email";
|
|
226
|
+
subjectSet: {
|
|
227
|
+
id: string;
|
|
228
|
+
namespace: "User";
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
}[];
|
|
232
|
+
_input_out: {
|
|
233
|
+
action: "delete" | "insert";
|
|
234
|
+
relationTuple: {
|
|
235
|
+
id: string;
|
|
236
|
+
relation: "viewers" | "editors" | "builders" | "owners";
|
|
237
|
+
namespace: "Project";
|
|
238
|
+
subjectSet: {
|
|
239
|
+
id: string;
|
|
240
|
+
namespace: "User";
|
|
241
|
+
} | {
|
|
242
|
+
id: string;
|
|
243
|
+
namespace: "Token";
|
|
244
|
+
} | {
|
|
245
|
+
id: string;
|
|
246
|
+
relation: "owners";
|
|
247
|
+
namespace: "Email";
|
|
248
|
+
};
|
|
249
|
+
} | {
|
|
250
|
+
id: string;
|
|
251
|
+
relation: "owners";
|
|
252
|
+
namespace: "Email";
|
|
253
|
+
subjectSet: {
|
|
254
|
+
id: string;
|
|
255
|
+
namespace: "User";
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
}[];
|
|
259
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
260
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
261
|
+
}, void>;
|
|
262
|
+
}>;
|
|
263
|
+
}>;
|
|
264
|
+
export type SharedRouter = typeof sharedRouter;
|
|
265
|
+
export type TrpcInterfaceClient = ReturnType<typeof createTRPCProxyClient<SharedRouter>>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type inferAsyncReturnType } from "@trpc/server";
|
|
2
|
+
export declare const createContext: () => Promise<{}>;
|
|
3
|
+
export type Context = inferAsyncReturnType<typeof createContext>;
|
|
4
|
+
export declare const router: <TProcRouterRecord extends import("@trpc/server").ProcedureRouterRecord>(procedures: TProcRouterRecord) => import("@trpc/server").CreateRouterInner<import("@trpc/server").RootConfig<{
|
|
5
|
+
ctx: {};
|
|
6
|
+
meta: object;
|
|
7
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
8
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
9
|
+
}>, TProcRouterRecord>, procedure: import("@trpc/server").ProcedureBuilder<{
|
|
10
|
+
_config: import("@trpc/server").RootConfig<{
|
|
11
|
+
ctx: {};
|
|
12
|
+
meta: object;
|
|
13
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
14
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
15
|
+
}>;
|
|
16
|
+
_ctx_out: {};
|
|
17
|
+
_input_in: typeof import("@trpc/server").unsetMarker;
|
|
18
|
+
_input_out: typeof import("@trpc/server").unsetMarker;
|
|
19
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
20
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
21
|
+
_meta: object;
|
|
22
|
+
}>, middleware: <TNewParams extends import("@trpc/server").ProcedureParams<import("@trpc/server").AnyRootConfig, unknown, unknown, unknown, unknown, unknown, unknown>>(fn: import("@trpc/server").MiddlewareFunction<{
|
|
23
|
+
_config: import("@trpc/server").RootConfig<{
|
|
24
|
+
ctx: {};
|
|
25
|
+
meta: object;
|
|
26
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
27
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
28
|
+
}>;
|
|
29
|
+
_ctx_out: {};
|
|
30
|
+
_input_out: unknown;
|
|
31
|
+
_input_in: unknown;
|
|
32
|
+
_output_in: unknown;
|
|
33
|
+
_output_out: unknown;
|
|
34
|
+
_meta: object;
|
|
35
|
+
}, TNewParams>) => import("@trpc/server").MiddlewareFunction<{
|
|
36
|
+
_config: import("@trpc/server").RootConfig<{
|
|
37
|
+
ctx: {};
|
|
38
|
+
meta: object;
|
|
39
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
40
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
41
|
+
}>;
|
|
42
|
+
_ctx_out: {};
|
|
43
|
+
_input_out: unknown;
|
|
44
|
+
_input_in: unknown;
|
|
45
|
+
_output_in: unknown;
|
|
46
|
+
_output_out: unknown;
|
|
47
|
+
_meta: object;
|
|
48
|
+
}, TNewParams>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AnyRouter } from "@trpc/server";
|
|
2
|
+
import { type TRPCLink } from "@trpc/client";
|
|
3
|
+
type MemoryLinkOptions<TemplateRouter extends AnyRouter> = {
|
|
4
|
+
appRouter: TemplateRouter;
|
|
5
|
+
createContext?: () => TemplateRouter["_def"]["_config"]["$types"]["ctx"];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* https://github.com/trpc/trpc/issues/3335
|
|
9
|
+
*
|
|
10
|
+
* createCaller and createTRPCProxyClient provides different interfaces,
|
|
11
|
+
* here we provide callerLink which can be used as a [trpc client link](https://trpc.io/docs/links)
|
|
12
|
+
* Allowing us to call router api without http but through createTRPCProxyClient interface
|
|
13
|
+
* See trpc-caller-link.test.ts for details
|
|
14
|
+
**/
|
|
15
|
+
export declare const callerLink: <TemplateRouter extends AnyRouter>(opts: MemoryLinkOptions<TemplateRouter>) => TRPCLink<TemplateRouter>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
type Context = {
|
|
2
|
+
someCtx: string;
|
|
3
|
+
};
|
|
4
|
+
export declare const router: <TProcRouterRecord extends import("@trpc/server").ProcedureRouterRecord>(procedures: TProcRouterRecord) => import("@trpc/server").CreateRouterInner<import("@trpc/server").RootConfig<{
|
|
5
|
+
ctx: Context;
|
|
6
|
+
meta: object;
|
|
7
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
8
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
9
|
+
}>, TProcRouterRecord>, procedure: import("@trpc/server").ProcedureBuilder<{
|
|
10
|
+
_config: import("@trpc/server").RootConfig<{
|
|
11
|
+
ctx: Context;
|
|
12
|
+
meta: object;
|
|
13
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
14
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
15
|
+
}>;
|
|
16
|
+
_ctx_out: Context;
|
|
17
|
+
_input_in: typeof import("@trpc/server").unsetMarker;
|
|
18
|
+
_input_out: typeof import("@trpc/server").unsetMarker;
|
|
19
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
20
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
21
|
+
_meta: object;
|
|
22
|
+
}>, middleware: <TNewParams extends import("@trpc/server").ProcedureParams<import("@trpc/server").AnyRootConfig, unknown, unknown, unknown, unknown, unknown, unknown>>(fn: import("@trpc/server").MiddlewareFunction<{
|
|
23
|
+
_config: import("@trpc/server").RootConfig<{
|
|
24
|
+
ctx: Context;
|
|
25
|
+
meta: object;
|
|
26
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
27
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
28
|
+
}>;
|
|
29
|
+
_ctx_out: Context;
|
|
30
|
+
_input_out: unknown;
|
|
31
|
+
_input_in: unknown;
|
|
32
|
+
_output_in: unknown;
|
|
33
|
+
_output_out: unknown;
|
|
34
|
+
_meta: object;
|
|
35
|
+
}, TNewParams>) => import("@trpc/server").MiddlewareFunction<{
|
|
36
|
+
_config: import("@trpc/server").RootConfig<{
|
|
37
|
+
ctx: Context;
|
|
38
|
+
meta: object;
|
|
39
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
40
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
41
|
+
}>;
|
|
42
|
+
_ctx_out: Context;
|
|
43
|
+
_input_out: unknown;
|
|
44
|
+
_input_in: unknown;
|
|
45
|
+
_output_in: unknown;
|
|
46
|
+
_output_out: unknown;
|
|
47
|
+
_meta: object;
|
|
48
|
+
}, TNewParams>;
|
|
49
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/trpc-interface",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.0",
|
|
4
4
|
"description": "Webstudio TRPC Interface",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -8,16 +8,17 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@trpc/client": "^10.9.0",
|
|
10
10
|
"@trpc/server": "^10.9.0",
|
|
11
|
+
"node-fetch": "2",
|
|
11
12
|
"uuid": "^9.0.0",
|
|
12
13
|
"zod": "^3.19.1",
|
|
13
|
-
"@webstudio-is/prisma-client": "^0.
|
|
14
|
+
"@webstudio-is/prisma-client": "^0.59.0"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
17
|
"@types/node": "^18.11.18",
|
|
17
18
|
"typescript": "5.0.3",
|
|
18
|
-
"@webstudio-is/jest-config": "^1.0.
|
|
19
|
+
"@webstudio-is/jest-config": "^1.0.5",
|
|
19
20
|
"@webstudio-is/scripts": "^0.0.0",
|
|
20
|
-
"@webstudio-is/tsconfig": "^1.0.
|
|
21
|
+
"@webstudio-is/tsconfig": "^1.0.5"
|
|
21
22
|
},
|
|
22
23
|
"exports": {
|
|
23
24
|
"./server": {
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"checks": "pnpm typecheck && pnpm lint",
|
|
40
41
|
"dev": "build-package --watch",
|
|
41
42
|
"build": "build-package",
|
|
42
|
-
"dts": "tsc",
|
|
43
|
+
"dts": "tsc --declarationDir lib/types",
|
|
43
44
|
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0"
|
|
44
45
|
}
|
|
45
46
|
}
|
package/src/shared/client.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fetch from "node-fetch";
|
|
1
2
|
import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
|
|
2
3
|
import {
|
|
3
4
|
sharedRouter,
|
|
@@ -19,6 +20,9 @@ export const createTrpcProxyServiceClient = (
|
|
|
19
20
|
const remoteClient = createTRPCProxyClient<SharedRouter>({
|
|
20
21
|
links: [
|
|
21
22
|
httpBatchLink({
|
|
23
|
+
// httpBatchLink uses lib.dom.d.ts's fetch type
|
|
24
|
+
// which is incompatible with node fetch type.
|
|
25
|
+
fetch: fetch as never,
|
|
22
26
|
url: options.url,
|
|
23
27
|
headers: () => ({
|
|
24
28
|
Authorization: options.token,
|