@townco/apiclient 0.0.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 +32 -0
- package/src/index.ts +45 -0
- package/src/library-types.ts +74 -0
- package/src/server.ts +165 -0
- package/tsconfig.json +6 -0
- package/turbo.json +7 -0
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@townco/apiclient",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.2",
|
|
5
|
+
"description": "apiclient",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"repository": "github:townco/town",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@supabase/storage-js": "^2.87.1",
|
|
18
|
+
"@townco/tsconfig": "0.1.80",
|
|
19
|
+
"@trpc/server": "^11.7.2",
|
|
20
|
+
"@typescript/native-preview": "^7.0.0-dev.20251207.1"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsgo",
|
|
24
|
+
"check": "tsgo --noEmit"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@supabase/supabase-js": "^2.87.1",
|
|
28
|
+
"@trpc/client": "^11.7.2",
|
|
29
|
+
"eventsource": "^4.1.0",
|
|
30
|
+
"superjson": "^2.2.6"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createTRPCClient,
|
|
3
|
+
httpLink,
|
|
4
|
+
httpSubscriptionLink,
|
|
5
|
+
loggerLink,
|
|
6
|
+
splitLink,
|
|
7
|
+
} from "@trpc/client";
|
|
8
|
+
import { EventSource } from "eventsource";
|
|
9
|
+
import superjson from "superjson";
|
|
10
|
+
import type { AppRouter } from "./server";
|
|
11
|
+
|
|
12
|
+
export const createClient = ({
|
|
13
|
+
shedUrl,
|
|
14
|
+
accessToken,
|
|
15
|
+
debug = true,
|
|
16
|
+
}: {
|
|
17
|
+
shedUrl: string;
|
|
18
|
+
accessToken: string;
|
|
19
|
+
debug?: boolean;
|
|
20
|
+
}) => {
|
|
21
|
+
const authHeader = { Authorization: `Bearer ${accessToken}` };
|
|
22
|
+
const url = `${shedUrl}/api/trpc`;
|
|
23
|
+
const baseLinkOpts = { url, transformer: superjson };
|
|
24
|
+
|
|
25
|
+
return createTRPCClient<AppRouter>({
|
|
26
|
+
links: [
|
|
27
|
+
loggerLink({ enabled: (_) => debug }),
|
|
28
|
+
splitLink({
|
|
29
|
+
condition: (op) => op.type === "subscription",
|
|
30
|
+
true: httpSubscriptionLink({
|
|
31
|
+
...baseLinkOpts,
|
|
32
|
+
EventSource,
|
|
33
|
+
eventSourceOptions: {
|
|
34
|
+
fetch: async (url, init) =>
|
|
35
|
+
fetch(url, {
|
|
36
|
+
...init,
|
|
37
|
+
headers: { ...init.headers, ...authHeader },
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
false: httpLink({ ...baseLinkOpts, headers: authHeader }),
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export interface OrganizationCreateRequest {
|
|
2
|
+
name: string;
|
|
3
|
+
description?: string | null;
|
|
4
|
+
}
|
|
5
|
+
export interface OrganizationResponse {
|
|
6
|
+
id: number;
|
|
7
|
+
name: string;
|
|
8
|
+
description: string | null;
|
|
9
|
+
external_agent_url: string | null;
|
|
10
|
+
user_count: number;
|
|
11
|
+
created_at: string;
|
|
12
|
+
updated_at: string;
|
|
13
|
+
}
|
|
14
|
+
export interface UserCreateRequest {
|
|
15
|
+
email: string;
|
|
16
|
+
role: "ADMIN" | "MEMBER";
|
|
17
|
+
organization_id: number;
|
|
18
|
+
}
|
|
19
|
+
export interface UserResponse {
|
|
20
|
+
id: number;
|
|
21
|
+
email: string;
|
|
22
|
+
role: "ADMIN" | "MEMBER";
|
|
23
|
+
organization_id: number;
|
|
24
|
+
created_at: string;
|
|
25
|
+
updated_at: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ApiKeyCreateRequest {
|
|
28
|
+
user_id: number;
|
|
29
|
+
expires_at?: string | null;
|
|
30
|
+
description?: string | null;
|
|
31
|
+
}
|
|
32
|
+
export interface ApiKeyCreateResponse {
|
|
33
|
+
id: number;
|
|
34
|
+
key: string;
|
|
35
|
+
key_prefix: string;
|
|
36
|
+
user_id: number;
|
|
37
|
+
organization_id: number;
|
|
38
|
+
expires_at: string | null;
|
|
39
|
+
description: string | null;
|
|
40
|
+
created_at: string;
|
|
41
|
+
updated_at: string;
|
|
42
|
+
}
|
|
43
|
+
export type CreateCollectionResult =
|
|
44
|
+
| {
|
|
45
|
+
collectionId: string;
|
|
46
|
+
error?: never;
|
|
47
|
+
}
|
|
48
|
+
| {
|
|
49
|
+
collectionId?: never;
|
|
50
|
+
error: string;
|
|
51
|
+
};
|
|
52
|
+
export interface CollectionListItem {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
created_at: string;
|
|
56
|
+
}
|
|
57
|
+
export type ListCollectionsResult =
|
|
58
|
+
| {
|
|
59
|
+
collections: CollectionListItem[];
|
|
60
|
+
error?: never;
|
|
61
|
+
}
|
|
62
|
+
| {
|
|
63
|
+
collections?: never;
|
|
64
|
+
error: string;
|
|
65
|
+
};
|
|
66
|
+
export type DeleteCollectionResult =
|
|
67
|
+
| {
|
|
68
|
+
success: true;
|
|
69
|
+
error?: never;
|
|
70
|
+
}
|
|
71
|
+
| {
|
|
72
|
+
success?: never;
|
|
73
|
+
error: string;
|
|
74
|
+
};
|
package/src/server.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { FileObject } from "@supabase/storage-js";
|
|
2
|
+
export declare const createContext: ({ req }: { req: Request }) => Promise<
|
|
3
|
+
| {
|
|
4
|
+
user: null;
|
|
5
|
+
token?: never;
|
|
6
|
+
}
|
|
7
|
+
| {
|
|
8
|
+
user: import("@supabase/supabase-js").User | null;
|
|
9
|
+
token: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
>;
|
|
12
|
+
export type Context = Awaited<ReturnType<typeof createContext>>;
|
|
13
|
+
export declare const publicProcedure: import("@trpc/server").TRPCProcedureBuilder<
|
|
14
|
+
| {
|
|
15
|
+
user: null;
|
|
16
|
+
token?: never;
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
user: import("@supabase/supabase-js").User | null;
|
|
20
|
+
token: string | undefined;
|
|
21
|
+
},
|
|
22
|
+
object,
|
|
23
|
+
object,
|
|
24
|
+
import("@trpc/server").TRPCUnsetMarker,
|
|
25
|
+
import("@trpc/server").TRPCUnsetMarker,
|
|
26
|
+
import("@trpc/server").TRPCUnsetMarker,
|
|
27
|
+
import("@trpc/server").TRPCUnsetMarker,
|
|
28
|
+
false
|
|
29
|
+
>;
|
|
30
|
+
export declare const authedProcedure: import("@trpc/server").TRPCProcedureBuilder<
|
|
31
|
+
| {
|
|
32
|
+
user: null;
|
|
33
|
+
token?: never;
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
user: import("@supabase/supabase-js").User | null;
|
|
37
|
+
token: string | undefined;
|
|
38
|
+
},
|
|
39
|
+
object,
|
|
40
|
+
{},
|
|
41
|
+
import("@trpc/server").TRPCUnsetMarker,
|
|
42
|
+
import("@trpc/server").TRPCUnsetMarker,
|
|
43
|
+
import("@trpc/server").TRPCUnsetMarker,
|
|
44
|
+
import("@trpc/server").TRPCUnsetMarker,
|
|
45
|
+
false
|
|
46
|
+
>;
|
|
47
|
+
export declare const routerBuilder: import("@trpc/server").TRPCRouterBuilder<{
|
|
48
|
+
ctx:
|
|
49
|
+
| {
|
|
50
|
+
user: null;
|
|
51
|
+
token?: never;
|
|
52
|
+
}
|
|
53
|
+
| {
|
|
54
|
+
user: import("@supabase/supabase-js").User | null;
|
|
55
|
+
token: string | undefined;
|
|
56
|
+
};
|
|
57
|
+
meta: object;
|
|
58
|
+
errorShape: import("@trpc/server").TRPCDefaultErrorShape;
|
|
59
|
+
transformer: true;
|
|
60
|
+
}>;
|
|
61
|
+
export declare const router: import("@trpc/server").TRPCBuiltRouter<
|
|
62
|
+
{
|
|
63
|
+
ctx:
|
|
64
|
+
| {
|
|
65
|
+
user: null;
|
|
66
|
+
token?: never;
|
|
67
|
+
}
|
|
68
|
+
| {
|
|
69
|
+
user: import("@supabase/supabase-js").User | null;
|
|
70
|
+
token: string | undefined;
|
|
71
|
+
};
|
|
72
|
+
meta: object;
|
|
73
|
+
errorShape: import("@trpc/server").TRPCDefaultErrorShape;
|
|
74
|
+
transformer: true;
|
|
75
|
+
},
|
|
76
|
+
import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
77
|
+
greet: import("@trpc/server").TRPCQueryProcedure<{
|
|
78
|
+
input: void;
|
|
79
|
+
output: string;
|
|
80
|
+
meta: object;
|
|
81
|
+
}>;
|
|
82
|
+
listArtifacts: import("@trpc/server").TRPCQueryProcedure<{
|
|
83
|
+
input: {
|
|
84
|
+
key: string;
|
|
85
|
+
recursive?: boolean | undefined;
|
|
86
|
+
kind: "agent" | "user";
|
|
87
|
+
};
|
|
88
|
+
output: FileObject[];
|
|
89
|
+
meta: object;
|
|
90
|
+
}>;
|
|
91
|
+
getArtifactUrl: import("@trpc/server").TRPCQueryProcedure<{
|
|
92
|
+
input: {
|
|
93
|
+
key: string;
|
|
94
|
+
upload?: boolean | undefined;
|
|
95
|
+
kind: "agent" | "user";
|
|
96
|
+
};
|
|
97
|
+
output: string;
|
|
98
|
+
meta: object;
|
|
99
|
+
}>;
|
|
100
|
+
deleteArtifact: import("@trpc/server").TRPCMutationProcedure<{
|
|
101
|
+
input: {
|
|
102
|
+
kind: "agent" | "user";
|
|
103
|
+
key: string;
|
|
104
|
+
};
|
|
105
|
+
output: {
|
|
106
|
+
success: boolean;
|
|
107
|
+
};
|
|
108
|
+
meta: object;
|
|
109
|
+
}>;
|
|
110
|
+
uploadArchive: import("@trpc/server").TRPCMutationProcedure<{
|
|
111
|
+
input: import("@trpc/server/http").OctetInput;
|
|
112
|
+
output: {
|
|
113
|
+
sha256: string;
|
|
114
|
+
cached: boolean;
|
|
115
|
+
};
|
|
116
|
+
meta: object;
|
|
117
|
+
}>;
|
|
118
|
+
deploy: import("@trpc/server").TRPCSubscriptionProcedure<{
|
|
119
|
+
input: {
|
|
120
|
+
sha256: string;
|
|
121
|
+
agent: string;
|
|
122
|
+
shedUrl: string;
|
|
123
|
+
};
|
|
124
|
+
output: AsyncIterable<
|
|
125
|
+
| {
|
|
126
|
+
status: string;
|
|
127
|
+
error?: never;
|
|
128
|
+
}
|
|
129
|
+
| {
|
|
130
|
+
status?: never;
|
|
131
|
+
error: unknown;
|
|
132
|
+
},
|
|
133
|
+
void,
|
|
134
|
+
any
|
|
135
|
+
>;
|
|
136
|
+
meta: object;
|
|
137
|
+
}>;
|
|
138
|
+
"library.create": import("@trpc/server").TRPCMutationProcedure<{
|
|
139
|
+
input: {
|
|
140
|
+
name: string;
|
|
141
|
+
};
|
|
142
|
+
output: {
|
|
143
|
+
collectionId: string | undefined;
|
|
144
|
+
};
|
|
145
|
+
meta: object;
|
|
146
|
+
}>;
|
|
147
|
+
"library.list": import("@trpc/server").TRPCQueryProcedure<{
|
|
148
|
+
input: void;
|
|
149
|
+
output: {
|
|
150
|
+
collections: import("./library-types").CollectionListItem[] | undefined;
|
|
151
|
+
};
|
|
152
|
+
meta: object;
|
|
153
|
+
}>;
|
|
154
|
+
"library.delete": import("@trpc/server").TRPCMutationProcedure<{
|
|
155
|
+
input: {
|
|
156
|
+
id: string;
|
|
157
|
+
};
|
|
158
|
+
output: {
|
|
159
|
+
success: boolean;
|
|
160
|
+
};
|
|
161
|
+
meta: object;
|
|
162
|
+
}>;
|
|
163
|
+
}>
|
|
164
|
+
>;
|
|
165
|
+
export type AppRouter = typeof router;
|
package/tsconfig.json
ADDED