@kuckit/api 1.0.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.
@@ -0,0 +1,46 @@
1
+ import { AwilixContainer } from "awilix";
2
+ import { Request } from "express";
3
+
4
+ //#region src/context.d.ts
5
+ declare global {
6
+ namespace Express {
7
+ interface Request {
8
+ scope?: AwilixContainer;
9
+ }
10
+ }
11
+ }
12
+ interface CreateContextOptions {
13
+ req: Request;
14
+ }
15
+ /**
16
+ * Create per-request context with DI container
17
+ * Injects logger with requestId for structured tracing
18
+ */
19
+ declare function createContext(opts: CreateContextOptions): Promise<{
20
+ session: {
21
+ session: {
22
+ id: string;
23
+ createdAt: Date;
24
+ updatedAt: Date;
25
+ userId: string;
26
+ expiresAt: Date;
27
+ token: string;
28
+ ipAddress?: string | null | undefined | undefined;
29
+ userAgent?: string | null | undefined | undefined;
30
+ };
31
+ user: {
32
+ id: string;
33
+ createdAt: Date;
34
+ updatedAt: Date;
35
+ email: string;
36
+ emailVerified: boolean;
37
+ name: string;
38
+ image?: string | null | undefined | undefined;
39
+ };
40
+ } | null;
41
+ di: AwilixContainer<any>;
42
+ }>;
43
+ type Context = Awaited<ReturnType<typeof createContext>>;
44
+ //#endregion
45
+ export { Context, CreateContextOptions, createContext };
46
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","names":[],"sources":["../src/context.ts"],"sourcesContent":[],"mappings":";;;;;;IAGsD,UAAA,OAAA,CAAA;MAAA,KAAA,CAAA,EAM3C,eAN2C;IAM3C;EAAe;;AAKT,UAAA,oBAAA,CACX;EAOgB,GAAA,EAPhB,OAOgB;;;;;;iBAAA,aAAA,OAAoB,uBAAoB;;IAAA,OAAA,EAAA;MAAA,EAAA,EAAA,MAAA;MA8ClD,SAAO,MAAA;MAA6B,SAAA,MAAA;MAAlB,MAAA,EAAA,MAAA;MAAR,SAAA,MAAA;MAAO,KAAA,EAAA,MAAA;;;;;;;;;;;;;;;;KAAjB,OAAA,GAAU,QAAQ,kBAAkB"}
@@ -0,0 +1,44 @@
1
+ import { fromNodeHeaders } from "better-auth/node";
2
+ import { auth } from "@kuckit/auth";
3
+ import { asValue } from "awilix";
4
+
5
+ //#region src/context.ts
6
+ /**
7
+ * Create per-request context with DI container
8
+ * Injects logger with requestId for structured tracing
9
+ */
10
+ async function createContext(opts) {
11
+ let session;
12
+ try {
13
+ session = await auth.api.getSession({ headers: fromNodeHeaders(opts.req.headers) });
14
+ } catch (error) {
15
+ console.error("[Auth] Failed to get session:", error, "Headers:", opts.req.headers);
16
+ session = null;
17
+ }
18
+ const requestId = crypto.randomUUID();
19
+ if (opts.req.scope) opts.req.scope.register({
20
+ session: asValue(session),
21
+ requestId: asValue(requestId)
22
+ });
23
+ const logger = opts.req.scope?.cradle.logger;
24
+ if (logger) logger.info("request_start", {
25
+ requestId,
26
+ userId: session?.user?.id,
27
+ method: opts.req.method,
28
+ path: opts.req.path
29
+ });
30
+ opts.req.on("end", () => {
31
+ if (logger) logger.info("request_end", {
32
+ requestId,
33
+ userId: session?.user?.id
34
+ });
35
+ });
36
+ return {
37
+ session,
38
+ di: opts.req.scope
39
+ };
40
+ }
41
+
42
+ //#endregion
43
+ export { createContext };
44
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type { Request } from 'express'\nimport { fromNodeHeaders } from 'better-auth/node'\nimport { auth } from '@kuckit/auth'\nimport { asValue, type AwilixContainer } from 'awilix'\n\ndeclare global {\n\t// eslint-disable-next-line @typescript-eslint/no-namespace\n\tnamespace Express {\n\t\tinterface Request {\n\t\t\tscope?: AwilixContainer\n\t\t}\n\t}\n}\n\nexport interface CreateContextOptions {\n\treq: Request\n}\n\n/**\n * Create per-request context with DI container\n * Injects logger with requestId for structured tracing\n */\nexport async function createContext(opts: CreateContextOptions) {\n\tlet session\n\ttry {\n\t\tsession = await auth.api.getSession({\n\t\t\theaders: fromNodeHeaders(opts.req.headers),\n\t\t})\n\t} catch (error) {\n\t\tconsole.error('[Auth] Failed to get session:', error, 'Headers:', opts.req.headers)\n\t\tsession = null\n\t}\n\n\tconst requestId = crypto.randomUUID()\n\n\tif (opts.req.scope) {\n\t\topts.req.scope.register({\n\t\t\tsession: asValue(session),\n\t\t\trequestId: asValue(requestId),\n\t\t})\n\t}\n\n\tconst logger = opts.req.scope?.cradle.logger\n\tif (logger) {\n\t\tlogger.info('request_start', {\n\t\t\trequestId,\n\t\t\tuserId: session?.user?.id,\n\t\t\tmethod: opts.req.method,\n\t\t\tpath: opts.req.path,\n\t\t})\n\t}\n\n\t// Log request end on response finish\n\topts.req.on('end', () => {\n\t\tif (logger) {\n\t\t\tlogger.info('request_end', {\n\t\t\t\trequestId,\n\t\t\t\tuserId: session?.user?.id,\n\t\t\t})\n\t\t}\n\t})\n\n\treturn {\n\t\tsession,\n\t\tdi: opts.req.scope!,\n\t}\n}\n\nexport type Context = Awaited<ReturnType<typeof createContext>>\n"],"mappings":";;;;;;;;;AAsBA,eAAsB,cAAc,MAA4B;CAC/D,IAAI;AACJ,KAAI;AACH,YAAU,MAAM,KAAK,IAAI,WAAW,EACnC,SAAS,gBAAgB,KAAK,IAAI,QAAQ,EAC1C,CAAC;UACM,OAAO;AACf,UAAQ,MAAM,iCAAiC,OAAO,YAAY,KAAK,IAAI,QAAQ;AACnF,YAAU;;CAGX,MAAM,YAAY,OAAO,YAAY;AAErC,KAAI,KAAK,IAAI,MACZ,MAAK,IAAI,MAAM,SAAS;EACvB,SAAS,QAAQ,QAAQ;EACzB,WAAW,QAAQ,UAAU;EAC7B,CAAC;CAGH,MAAM,SAAS,KAAK,IAAI,OAAO,OAAO;AACtC,KAAI,OACH,QAAO,KAAK,iBAAiB;EAC5B;EACA,QAAQ,SAAS,MAAM;EACvB,QAAQ,KAAK,IAAI;EACjB,MAAM,KAAK,IAAI;EACf,CAAC;AAIH,MAAK,IAAI,GAAG,aAAa;AACxB,MAAI,OACH,QAAO,KAAK,eAAe;GAC1B;GACA,QAAQ,SAAS,MAAM;GACvB,CAAC;GAEF;AAEF,QAAO;EACN;EACA,IAAI,KAAK,IAAI;EACb"}
@@ -0,0 +1,12 @@
1
+ import { ORPCError } from "@orpc/server";
2
+
3
+ //#region src/error-handler.d.ts
4
+
5
+ /**
6
+ * Map AppError to oRPC errors
7
+ * Preserves error details for logging while providing proper HTTP status codes
8
+ */
9
+ declare const mapAppErrorToORPC: (error: unknown) => ORPCError;
10
+ //#endregion
11
+ export { mapAppErrorToORPC };
12
+ //# sourceMappingURL=error-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.d.ts","names":[],"sources":["../src/error-handler.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;;cAAa,uCAAsC"}
@@ -0,0 +1,30 @@
1
+ import { ORPCError } from "@orpc/server";
2
+
3
+ //#region src/error-handler.ts
4
+ /**
5
+ * Map AppError to oRPC errors
6
+ * Preserves error details for logging while providing proper HTTP status codes
7
+ */
8
+ const mapAppErrorToORPC = (error) => {
9
+ const appError = error;
10
+ if (!appError?.code) return new ORPCError("INTERNAL_SERVER_ERROR", {
11
+ message: error instanceof Error ? error.message : "Unknown error",
12
+ code: "INTERNAL_SERVER_ERROR"
13
+ });
14
+ return new ORPCError({
15
+ 400: "BAD_REQUEST",
16
+ 401: "UNAUTHORIZED",
17
+ 403: "FORBIDDEN",
18
+ 404: "NOT_FOUND",
19
+ 409: "CONFLICT",
20
+ 500: "INTERNAL_SERVER_ERROR"
21
+ }[appError.statusCode] || "INTERNAL_SERVER_ERROR", {
22
+ message: appError.message,
23
+ code: appError.code,
24
+ meta: appError.meta
25
+ });
26
+ };
27
+
28
+ //#endregion
29
+ export { mapAppErrorToORPC };
30
+ //# sourceMappingURL=error-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.js","names":[],"sources":["../src/error-handler.ts"],"sourcesContent":["import { ORPCError } from '@orpc/server'\nimport type { AppError } from '@kuckit/domain'\n\n/**\n * Map AppError to oRPC errors\n * Preserves error details for logging while providing proper HTTP status codes\n */\nexport const mapAppErrorToORPC = (error: unknown): ORPCError => {\n\tconst appError = error as AppError\n\n\tif (!appError?.code) {\n\t\t// Not an AppError, wrap as internal server error\n\t\treturn new ORPCError('INTERNAL_SERVER_ERROR', {\n\t\t\tmessage: error instanceof Error ? error.message : 'Unknown error',\n\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t})\n\t}\n\n\t// Map status codes to oRPC error codes\n\tconst statusCodeMap: Record<number, string> = {\n\t\t400: 'BAD_REQUEST',\n\t\t401: 'UNAUTHORIZED',\n\t\t403: 'FORBIDDEN',\n\t\t404: 'NOT_FOUND',\n\t\t409: 'CONFLICT',\n\t\t500: 'INTERNAL_SERVER_ERROR',\n\t}\n\n\tconst orpcCode = statusCodeMap[appError.statusCode] || 'INTERNAL_SERVER_ERROR'\n\n\treturn new ORPCError(orpcCode, {\n\t\tmessage: appError.message,\n\t\tcode: appError.code,\n\t\tmeta: appError.meta,\n\t})\n}\n"],"mappings":";;;;;;;AAOA,MAAa,qBAAqB,UAA8B;CAC/D,MAAM,WAAW;AAEjB,KAAI,CAAC,UAAU,KAEd,QAAO,IAAI,UAAU,yBAAyB;EAC7C,SAAS,iBAAiB,QAAQ,MAAM,UAAU;EAClD,MAAM;EACN,CAAC;AAeH,QAAO,IAAI,UAXmC;EAC7C,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,CAE8B,SAAS,eAAe,yBAExB;EAC9B,SAAS,SAAS;EAClB,MAAM,SAAS;EACf,MAAM,SAAS;EACf,CAAC"}
@@ -0,0 +1,216 @@
1
+ import * as awilix0 from "awilix";
2
+ import * as _orpc_server0 from "@orpc/server";
3
+
4
+ //#region src/index.d.ts
5
+ declare const o: _orpc_server0.Builder<{
6
+ session: {
7
+ session: {
8
+ id: string;
9
+ createdAt: Date;
10
+ updatedAt: Date;
11
+ userId: string;
12
+ expiresAt: Date;
13
+ token: string;
14
+ ipAddress?: string | null | undefined | undefined;
15
+ userAgent?: string | null | undefined | undefined;
16
+ };
17
+ user: {
18
+ id: string;
19
+ createdAt: Date;
20
+ updatedAt: Date;
21
+ email: string;
22
+ emailVerified: boolean;
23
+ name: string;
24
+ image?: string | null | undefined | undefined;
25
+ };
26
+ } | null;
27
+ di: awilix0.AwilixContainer<any>;
28
+ } & Record<never, never>, {
29
+ session: {
30
+ session: {
31
+ id: string;
32
+ createdAt: Date;
33
+ updatedAt: Date;
34
+ userId: string;
35
+ expiresAt: Date;
36
+ token: string;
37
+ ipAddress?: string | null | undefined | undefined;
38
+ userAgent?: string | null | undefined | undefined;
39
+ };
40
+ user: {
41
+ id: string;
42
+ createdAt: Date;
43
+ updatedAt: Date;
44
+ email: string;
45
+ emailVerified: boolean;
46
+ name: string;
47
+ image?: string | null | undefined | undefined;
48
+ };
49
+ } | null;
50
+ di: awilix0.AwilixContainer<any>;
51
+ }, _orpc_server0.Schema<unknown, unknown>, _orpc_server0.Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
52
+ declare const publicProcedure: _orpc_server0.Builder<{
53
+ session: {
54
+ session: {
55
+ id: string;
56
+ createdAt: Date;
57
+ updatedAt: Date;
58
+ userId: string;
59
+ expiresAt: Date;
60
+ token: string;
61
+ ipAddress?: string | null | undefined | undefined;
62
+ userAgent?: string | null | undefined | undefined;
63
+ };
64
+ user: {
65
+ id: string;
66
+ createdAt: Date;
67
+ updatedAt: Date;
68
+ email: string;
69
+ emailVerified: boolean;
70
+ name: string;
71
+ image?: string | null | undefined | undefined;
72
+ };
73
+ } | null;
74
+ di: awilix0.AwilixContainer<any>;
75
+ } & Record<never, never>, {
76
+ session: {
77
+ session: {
78
+ id: string;
79
+ createdAt: Date;
80
+ updatedAt: Date;
81
+ userId: string;
82
+ expiresAt: Date;
83
+ token: string;
84
+ ipAddress?: string | null | undefined | undefined;
85
+ userAgent?: string | null | undefined | undefined;
86
+ };
87
+ user: {
88
+ id: string;
89
+ createdAt: Date;
90
+ updatedAt: Date;
91
+ email: string;
92
+ emailVerified: boolean;
93
+ name: string;
94
+ image?: string | null | undefined | undefined;
95
+ };
96
+ } | null;
97
+ di: awilix0.AwilixContainer<any>;
98
+ }, _orpc_server0.Schema<unknown, unknown>, _orpc_server0.Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
99
+ declare const protectedProcedure: _orpc_server0.BuilderWithMiddlewares<_orpc_server0.MergedInitialContext<{
100
+ session: {
101
+ session: {
102
+ id: string;
103
+ createdAt: Date;
104
+ updatedAt: Date;
105
+ userId: string;
106
+ expiresAt: Date;
107
+ token: string;
108
+ ipAddress?: string | null | undefined | undefined;
109
+ userAgent?: string | null | undefined | undefined;
110
+ };
111
+ user: {
112
+ id: string;
113
+ createdAt: Date;
114
+ updatedAt: Date;
115
+ email: string;
116
+ emailVerified: boolean;
117
+ name: string;
118
+ image?: string | null | undefined | undefined;
119
+ };
120
+ } | null;
121
+ di: awilix0.AwilixContainer<any>;
122
+ } & Record<never, never>, {
123
+ session: {
124
+ session: {
125
+ id: string;
126
+ createdAt: Date;
127
+ updatedAt: Date;
128
+ userId: string;
129
+ expiresAt: Date;
130
+ token: string;
131
+ ipAddress?: string | null | undefined | undefined;
132
+ userAgent?: string | null | undefined | undefined;
133
+ };
134
+ user: {
135
+ id: string;
136
+ createdAt: Date;
137
+ updatedAt: Date;
138
+ email: string;
139
+ emailVerified: boolean;
140
+ name: string;
141
+ image?: string | null | undefined | undefined;
142
+ };
143
+ } | null;
144
+ di: awilix0.AwilixContainer<any>;
145
+ } & Record<never, never>, {
146
+ session: {
147
+ session: {
148
+ id: string;
149
+ createdAt: Date;
150
+ updatedAt: Date;
151
+ userId: string;
152
+ expiresAt: Date;
153
+ token: string;
154
+ ipAddress?: string | null | undefined | undefined;
155
+ userAgent?: string | null | undefined | undefined;
156
+ };
157
+ user: {
158
+ id: string;
159
+ createdAt: Date;
160
+ updatedAt: Date;
161
+ email: string;
162
+ emailVerified: boolean;
163
+ name: string;
164
+ image?: string | null | undefined | undefined;
165
+ };
166
+ } | null;
167
+ di: awilix0.AwilixContainer<any>;
168
+ }>, _orpc_server0.MergedCurrentContext<{
169
+ session: {
170
+ session: {
171
+ id: string;
172
+ createdAt: Date;
173
+ updatedAt: Date;
174
+ userId: string;
175
+ expiresAt: Date;
176
+ token: string;
177
+ ipAddress?: string | null | undefined | undefined;
178
+ userAgent?: string | null | undefined | undefined;
179
+ };
180
+ user: {
181
+ id: string;
182
+ createdAt: Date;
183
+ updatedAt: Date;
184
+ email: string;
185
+ emailVerified: boolean;
186
+ name: string;
187
+ image?: string | null | undefined | undefined;
188
+ };
189
+ } | null;
190
+ di: awilix0.AwilixContainer<any>;
191
+ }, {
192
+ session: {
193
+ session: {
194
+ id: string;
195
+ createdAt: Date;
196
+ updatedAt: Date;
197
+ userId: string;
198
+ expiresAt: Date;
199
+ token: string;
200
+ ipAddress?: string | null | undefined | undefined;
201
+ userAgent?: string | null | undefined | undefined;
202
+ };
203
+ user: {
204
+ id: string;
205
+ createdAt: Date;
206
+ updatedAt: Date;
207
+ email: string;
208
+ emailVerified: boolean;
209
+ name: string;
210
+ image?: string | null | undefined | undefined;
211
+ };
212
+ };
213
+ }>, _orpc_server0.Schema<unknown, unknown>, _orpc_server0.Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
214
+ //#endregion
215
+ export { o, protectedProcedure, publicProcedure };
216
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;cAGa,iBAAC;;;;MAAyB,SAAA,MAAA;;;;;;;;;;;;;;;;;;6BAAzB,CAAA,GAAA,CAAA;CAAA,SAAA,CAAA,KAAA,EAAA,KAAA,CAAA,EAAA;EAED,OAAA,EAAA;;;;;;;;;;;;;;;;;;WAAe,CAAA,EAAA,MAAA,GAAA,IAAA,GAAA,SAAA,GAAA,SAAA;IAAA,CAAA;EAaf,CAAA,GAAA,IAAA;;;cAbA,+BAAe;;;;;;;;;;;;;;;;;;UAaG,EAAA,MAAA;;;;;;;;;;;;;;;;;;MAAA,EAAA,EAAA,MAAA;;;;;;;;;;;cAAlB,kCAAkB,qCAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { n as protectedProcedure, r as publicProcedure, t as o } from "./src-Bygw2c19.js";
2
+
3
+ export { o, protectedProcedure, publicProcedure };
@@ -0,0 +1,12 @@
1
+ import { n as protectedProcedure } from "./src-Bygw2c19.js";
2
+ import { toUserDTO, zUserDTO } from "@kuckit/contracts";
3
+
4
+ //#region src/routers/profile.ts
5
+ const profileRouter = { me: protectedProcedure.output(zUserDTO).handler(async ({ context }) => {
6
+ const { getUserProfile } = context.di.cradle;
7
+ return toUserDTO(await getUserProfile({ userId: context.session.user.id }));
8
+ }) };
9
+
10
+ //#endregion
11
+ export { profileRouter as t };
12
+ //# sourceMappingURL=profile-Ydyv98wV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile-Ydyv98wV.js","names":[],"sources":["../src/routers/profile.ts"],"sourcesContent":["import { protectedProcedure } from '../index'\nimport { zUserDTO, toUserDTO } from '@kuckit/contracts'\n\nexport const profileRouter = {\n\t/**\n\t * Get current user's profile\n\t */\n\tme: protectedProcedure.output(zUserDTO).handler(async ({ context }) => {\n\t\tconst { getUserProfile } = context.di.cradle as any\n\n\t\tconst user = await getUserProfile({\n\t\t\tuserId: context.session!.user.id,\n\t\t})\n\n\t\treturn toUserDTO(user)\n\t}),\n}\n"],"mappings":";;;;AAGA,MAAa,gBAAgB,EAI5B,IAAI,mBAAmB,OAAO,SAAS,CAAC,QAAQ,OAAO,EAAE,cAAc;CACtE,MAAM,EAAE,mBAAmB,QAAQ,GAAG;AAMtC,QAAO,UAJM,MAAM,eAAe,EACjC,QAAQ,QAAQ,QAAS,KAAK,IAC9B,CAAC,CAEoB;EACrB,EACF"}
@@ -0,0 +1,322 @@
1
+ import * as awilix7 from "awilix";
2
+ import * as _orpc_server10 from "@orpc/server";
3
+ import { RouterClient } from "@orpc/server";
4
+ import * as zod0 from "zod";
5
+ import * as better_auth0 from "better-auth";
6
+
7
+ //#region src/routers/index.d.ts
8
+ declare const appRouter: {
9
+ healthCheck: _orpc_server10.DecoratedProcedure<{
10
+ session: {
11
+ session: {
12
+ id: string;
13
+ createdAt: Date;
14
+ updatedAt: Date;
15
+ userId: string;
16
+ expiresAt: Date;
17
+ token: string;
18
+ ipAddress?: string | null | undefined | undefined;
19
+ userAgent?: string | null | undefined | undefined;
20
+ };
21
+ user: {
22
+ id: string;
23
+ createdAt: Date;
24
+ updatedAt: Date;
25
+ email: string;
26
+ emailVerified: boolean;
27
+ name: string;
28
+ image?: string | null | undefined | undefined;
29
+ };
30
+ } | null;
31
+ di: awilix7.AwilixContainer<any>;
32
+ } & Record<never, never>, {
33
+ session: {
34
+ session: {
35
+ id: string;
36
+ createdAt: Date;
37
+ updatedAt: Date;
38
+ userId: string;
39
+ expiresAt: Date;
40
+ token: string;
41
+ ipAddress?: string | null | undefined | undefined;
42
+ userAgent?: string | null | undefined | undefined;
43
+ };
44
+ user: {
45
+ id: string;
46
+ createdAt: Date;
47
+ updatedAt: Date;
48
+ email: string;
49
+ emailVerified: boolean;
50
+ name: string;
51
+ image?: string | null | undefined | undefined;
52
+ };
53
+ } | null;
54
+ di: awilix7.AwilixContainer<any>;
55
+ }, _orpc_server10.Schema<unknown, unknown>, _orpc_server10.Schema<string, string>, Record<never, never>, Record<never, never>>;
56
+ privateData: _orpc_server10.DecoratedProcedure<_orpc_server10.MergedInitialContext<{
57
+ session: {
58
+ session: {
59
+ id: string;
60
+ createdAt: Date;
61
+ updatedAt: Date;
62
+ userId: string;
63
+ expiresAt: Date;
64
+ token: string;
65
+ ipAddress?: string | null | undefined | undefined;
66
+ userAgent?: string | null | undefined | undefined;
67
+ };
68
+ user: {
69
+ id: string;
70
+ createdAt: Date;
71
+ updatedAt: Date;
72
+ email: string;
73
+ emailVerified: boolean;
74
+ name: string;
75
+ image?: string | null | undefined | undefined;
76
+ };
77
+ } | null;
78
+ di: awilix7.AwilixContainer<any>;
79
+ } & Record<never, never>, {
80
+ session: {
81
+ session: {
82
+ id: string;
83
+ createdAt: Date;
84
+ updatedAt: Date;
85
+ userId: string;
86
+ expiresAt: Date;
87
+ token: string;
88
+ ipAddress?: string | null | undefined | undefined;
89
+ userAgent?: string | null | undefined | undefined;
90
+ };
91
+ user: {
92
+ id: string;
93
+ createdAt: Date;
94
+ updatedAt: Date;
95
+ email: string;
96
+ emailVerified: boolean;
97
+ name: string;
98
+ image?: string | null | undefined | undefined;
99
+ };
100
+ } | null;
101
+ di: awilix7.AwilixContainer<any>;
102
+ } & Record<never, never>, {
103
+ session: {
104
+ session: {
105
+ id: string;
106
+ createdAt: Date;
107
+ updatedAt: Date;
108
+ userId: string;
109
+ expiresAt: Date;
110
+ token: string;
111
+ ipAddress?: string | null | undefined | undefined;
112
+ userAgent?: string | null | undefined | undefined;
113
+ };
114
+ user: {
115
+ id: string;
116
+ createdAt: Date;
117
+ updatedAt: Date;
118
+ email: string;
119
+ emailVerified: boolean;
120
+ name: string;
121
+ image?: string | null | undefined | undefined;
122
+ };
123
+ } | null;
124
+ di: awilix7.AwilixContainer<any>;
125
+ }>, _orpc_server10.MergedCurrentContext<{
126
+ session: {
127
+ session: {
128
+ id: string;
129
+ createdAt: Date;
130
+ updatedAt: Date;
131
+ userId: string;
132
+ expiresAt: Date;
133
+ token: string;
134
+ ipAddress?: string | null | undefined | undefined;
135
+ userAgent?: string | null | undefined | undefined;
136
+ };
137
+ user: {
138
+ id: string;
139
+ createdAt: Date;
140
+ updatedAt: Date;
141
+ email: string;
142
+ emailVerified: boolean;
143
+ name: string;
144
+ image?: string | null | undefined | undefined;
145
+ };
146
+ } | null;
147
+ di: awilix7.AwilixContainer<any>;
148
+ }, {
149
+ session: {
150
+ session: {
151
+ id: string;
152
+ createdAt: Date;
153
+ updatedAt: Date;
154
+ userId: string;
155
+ expiresAt: Date;
156
+ token: string;
157
+ ipAddress?: string | null | undefined | undefined;
158
+ userAgent?: string | null | undefined | undefined;
159
+ };
160
+ user: {
161
+ id: string;
162
+ createdAt: Date;
163
+ updatedAt: Date;
164
+ email: string;
165
+ emailVerified: boolean;
166
+ name: string;
167
+ image?: string | null | undefined | undefined;
168
+ };
169
+ };
170
+ }>, _orpc_server10.Schema<unknown, unknown>, _orpc_server10.Schema<{
171
+ message: string;
172
+ user: {
173
+ id: string;
174
+ createdAt: Date;
175
+ updatedAt: Date;
176
+ email: string;
177
+ emailVerified: boolean;
178
+ name: string;
179
+ image?: string | null | undefined | undefined;
180
+ };
181
+ }, {
182
+ message: string;
183
+ user: {
184
+ id: string;
185
+ createdAt: Date;
186
+ updatedAt: Date;
187
+ email: string;
188
+ emailVerified: boolean;
189
+ name: string;
190
+ image?: string | null | undefined | undefined;
191
+ };
192
+ }>, Record<never, never>, Record<never, never>>;
193
+ profile: {
194
+ me: _orpc_server10.DecoratedProcedure<_orpc_server10.MergedInitialContext<{
195
+ session: {
196
+ session: {
197
+ id: string;
198
+ createdAt: Date;
199
+ updatedAt: Date;
200
+ userId: string;
201
+ expiresAt: Date;
202
+ token: string;
203
+ ipAddress?: string | null | undefined | undefined;
204
+ userAgent?: string | null | undefined | undefined;
205
+ };
206
+ user: {
207
+ id: string;
208
+ createdAt: Date;
209
+ updatedAt: Date;
210
+ email: string;
211
+ emailVerified: boolean;
212
+ name: string;
213
+ image?: string | null | undefined | undefined;
214
+ };
215
+ } | null;
216
+ di: awilix7.AwilixContainer<any>;
217
+ } & Record<never, never>, {
218
+ session: {
219
+ session: {
220
+ id: string;
221
+ createdAt: Date;
222
+ updatedAt: Date;
223
+ userId: string;
224
+ expiresAt: Date;
225
+ token: string;
226
+ ipAddress?: string | null | undefined | undefined;
227
+ userAgent?: string | null | undefined | undefined;
228
+ };
229
+ user: {
230
+ id: string;
231
+ createdAt: Date;
232
+ updatedAt: Date;
233
+ email: string;
234
+ emailVerified: boolean;
235
+ name: string;
236
+ image?: string | null | undefined | undefined;
237
+ };
238
+ } | null;
239
+ di: awilix7.AwilixContainer<any>;
240
+ } & Record<never, never>, {
241
+ session: {
242
+ session: {
243
+ id: string;
244
+ createdAt: Date;
245
+ updatedAt: Date;
246
+ userId: string;
247
+ expiresAt: Date;
248
+ token: string;
249
+ ipAddress?: string | null | undefined | undefined;
250
+ userAgent?: string | null | undefined | undefined;
251
+ };
252
+ user: {
253
+ id: string;
254
+ createdAt: Date;
255
+ updatedAt: Date;
256
+ email: string;
257
+ emailVerified: boolean;
258
+ name: string;
259
+ image?: string | null | undefined | undefined;
260
+ };
261
+ } | null;
262
+ di: awilix7.AwilixContainer<any>;
263
+ }>, _orpc_server10.MergedCurrentContext<{
264
+ session: {
265
+ session: {
266
+ id: string;
267
+ createdAt: Date;
268
+ updatedAt: Date;
269
+ userId: string;
270
+ expiresAt: Date;
271
+ token: string;
272
+ ipAddress?: string | null | undefined | undefined;
273
+ userAgent?: string | null | undefined | undefined;
274
+ };
275
+ user: {
276
+ id: string;
277
+ createdAt: Date;
278
+ updatedAt: Date;
279
+ email: string;
280
+ emailVerified: boolean;
281
+ name: string;
282
+ image?: string | null | undefined | undefined;
283
+ };
284
+ } | null;
285
+ di: awilix7.AwilixContainer<any>;
286
+ }, {
287
+ session: {
288
+ session: {
289
+ id: string;
290
+ createdAt: Date;
291
+ updatedAt: Date;
292
+ userId: string;
293
+ expiresAt: Date;
294
+ token: string;
295
+ ipAddress?: string | null | undefined | undefined;
296
+ userAgent?: string | null | undefined | undefined;
297
+ };
298
+ user: {
299
+ id: string;
300
+ createdAt: Date;
301
+ updatedAt: Date;
302
+ email: string;
303
+ emailVerified: boolean;
304
+ name: string;
305
+ image?: string | null | undefined | undefined;
306
+ };
307
+ };
308
+ }>, _orpc_server10.Schema<unknown, unknown>, zod0.ZodObject<{
309
+ id: zod0.ZodString;
310
+ name: zod0.ZodString;
311
+ email: zod0.ZodString;
312
+ emailVerified: zod0.ZodBoolean;
313
+ createdAt: zod0.ZodString;
314
+ updatedAt: zod0.ZodString;
315
+ }, better_auth0.$strip>, Record<never, never>, Record<never, never>>;
316
+ };
317
+ };
318
+ type AppRouter = typeof appRouter;
319
+ type AppRouterClient = RouterClient<typeof appRouter>;
320
+ //#endregion
321
+ export { AppRouter, AppRouterClient, appRouter };
322
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/routers/index.ts"],"sourcesContent":[],"mappings":";;;;;;;cAIa;;;;;;QAWZ,SAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QACoB,KAAA,CAAA,EAAA,MAAU,GAAA,IAAS,GAAA,SAAA,GAAA,SAAA;MAC5B,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KADA,SAAA,UAAmB;KACnB,eAAA,GAAkB,oBAAoB"}
@@ -0,0 +1,20 @@
1
+ import { n as protectedProcedure, r as publicProcedure } from "../src-Bygw2c19.js";
2
+ import { t as profileRouter } from "../profile-Ydyv98wV.js";
3
+
4
+ //#region src/routers/index.ts
5
+ const appRouter = {
6
+ healthCheck: publicProcedure.handler(() => {
7
+ return "OK";
8
+ }),
9
+ privateData: protectedProcedure.handler(({ context }) => {
10
+ return {
11
+ message: "This is private",
12
+ user: context.session?.user
13
+ };
14
+ }),
15
+ profile: profileRouter
16
+ };
17
+
18
+ //#endregion
19
+ export { appRouter };
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/routers/index.ts"],"sourcesContent":["import { protectedProcedure, publicProcedure } from '../index'\nimport type { RouterClient } from '@orpc/server'\nimport { profileRouter } from './profile'\n\nexport const appRouter = {\n\thealthCheck: publicProcedure.handler(() => {\n\t\treturn 'OK'\n\t}),\n\tprivateData: protectedProcedure.handler(({ context }) => {\n\t\treturn {\n\t\t\tmessage: 'This is private',\n\t\t\tuser: context.session?.user,\n\t\t}\n\t}),\n\tprofile: profileRouter,\n}\nexport type AppRouter = typeof appRouter\nexport type AppRouterClient = RouterClient<typeof appRouter>\n"],"mappings":";;;;AAIA,MAAa,YAAY;CACxB,aAAa,gBAAgB,cAAc;AAC1C,SAAO;GACN;CACF,aAAa,mBAAmB,SAAS,EAAE,cAAc;AACxD,SAAO;GACN,SAAS;GACT,MAAM,QAAQ,SAAS;GACvB;GACA;CACF,SAAS;CACT"}
@@ -0,0 +1,136 @@
1
+ import * as awilix17 from "awilix";
2
+ import * as _orpc_server22 from "@orpc/server";
3
+ import * as zod6 from "zod";
4
+ import * as better_auth0 from "better-auth";
5
+
6
+ //#region src/routers/profile.d.ts
7
+ declare const profileRouter: {
8
+ /**
9
+ * Get current user's profile
10
+ */
11
+ me: _orpc_server22.DecoratedProcedure<_orpc_server22.MergedInitialContext<{
12
+ session: {
13
+ session: {
14
+ id: string;
15
+ createdAt: Date;
16
+ updatedAt: Date;
17
+ userId: string;
18
+ expiresAt: Date;
19
+ token: string;
20
+ ipAddress?: string | null | undefined | undefined;
21
+ userAgent?: string | null | undefined | undefined;
22
+ };
23
+ user: {
24
+ id: string;
25
+ createdAt: Date;
26
+ updatedAt: Date;
27
+ email: string;
28
+ emailVerified: boolean;
29
+ name: string;
30
+ image?: string | null | undefined | undefined;
31
+ };
32
+ } | null;
33
+ di: awilix17.AwilixContainer<any>;
34
+ } & Record<never, never>, {
35
+ session: {
36
+ session: {
37
+ id: string;
38
+ createdAt: Date;
39
+ updatedAt: Date;
40
+ userId: string;
41
+ expiresAt: Date;
42
+ token: string;
43
+ ipAddress?: string | null | undefined | undefined;
44
+ userAgent?: string | null | undefined | undefined;
45
+ };
46
+ user: {
47
+ id: string;
48
+ createdAt: Date;
49
+ updatedAt: Date;
50
+ email: string;
51
+ emailVerified: boolean;
52
+ name: string;
53
+ image?: string | null | undefined | undefined;
54
+ };
55
+ } | null;
56
+ di: awilix17.AwilixContainer<any>;
57
+ } & Record<never, never>, {
58
+ session: {
59
+ session: {
60
+ id: string;
61
+ createdAt: Date;
62
+ updatedAt: Date;
63
+ userId: string;
64
+ expiresAt: Date;
65
+ token: string;
66
+ ipAddress?: string | null | undefined | undefined;
67
+ userAgent?: string | null | undefined | undefined;
68
+ };
69
+ user: {
70
+ id: string;
71
+ createdAt: Date;
72
+ updatedAt: Date;
73
+ email: string;
74
+ emailVerified: boolean;
75
+ name: string;
76
+ image?: string | null | undefined | undefined;
77
+ };
78
+ } | null;
79
+ di: awilix17.AwilixContainer<any>;
80
+ }>, _orpc_server22.MergedCurrentContext<{
81
+ session: {
82
+ session: {
83
+ id: string;
84
+ createdAt: Date;
85
+ updatedAt: Date;
86
+ userId: string;
87
+ expiresAt: Date;
88
+ token: string;
89
+ ipAddress?: string | null | undefined | undefined;
90
+ userAgent?: string | null | undefined | undefined;
91
+ };
92
+ user: {
93
+ id: string;
94
+ createdAt: Date;
95
+ updatedAt: Date;
96
+ email: string;
97
+ emailVerified: boolean;
98
+ name: string;
99
+ image?: string | null | undefined | undefined;
100
+ };
101
+ } | null;
102
+ di: awilix17.AwilixContainer<any>;
103
+ }, {
104
+ session: {
105
+ session: {
106
+ id: string;
107
+ createdAt: Date;
108
+ updatedAt: Date;
109
+ userId: string;
110
+ expiresAt: Date;
111
+ token: string;
112
+ ipAddress?: string | null | undefined | undefined;
113
+ userAgent?: string | null | undefined | undefined;
114
+ };
115
+ user: {
116
+ id: string;
117
+ createdAt: Date;
118
+ updatedAt: Date;
119
+ email: string;
120
+ emailVerified: boolean;
121
+ name: string;
122
+ image?: string | null | undefined | undefined;
123
+ };
124
+ };
125
+ }>, _orpc_server22.Schema<unknown, unknown>, zod6.ZodObject<{
126
+ id: zod6.ZodString;
127
+ name: zod6.ZodString;
128
+ email: zod6.ZodString;
129
+ emailVerified: zod6.ZodBoolean;
130
+ createdAt: zod6.ZodString;
131
+ updatedAt: zod6.ZodString;
132
+ }, better_auth0.$strip>, Record<never, never>, Record<never, never>>;
133
+ };
134
+ //#endregion
135
+ export { profileRouter };
136
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.d.ts","names":[],"sources":["../../src/routers/profile.ts"],"sourcesContent":[],"mappings":";;;;;;cAGa;;;;;;MAAA,OAAA,EAaZ"}
@@ -0,0 +1,4 @@
1
+ import "../src-Bygw2c19.js";
2
+ import { t as profileRouter } from "../profile-Ydyv98wV.js";
3
+
4
+ export { profileRouter };
@@ -0,0 +1,14 @@
1
+ import { ORPCError, os } from "@orpc/server";
2
+
3
+ //#region src/index.ts
4
+ const o = os.$context();
5
+ const publicProcedure = o;
6
+ const requireAuth = o.middleware(async ({ context, next }) => {
7
+ if (!context.session?.user) throw new ORPCError("UNAUTHORIZED");
8
+ return next({ context: { session: context.session } });
9
+ });
10
+ const protectedProcedure = publicProcedure.use(requireAuth);
11
+
12
+ //#endregion
13
+ export { protectedProcedure as n, publicProcedure as r, o as t };
14
+ //# sourceMappingURL=src-Bygw2c19.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-Bygw2c19.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { ORPCError, os } from '@orpc/server'\nimport type { Context } from './context'\n\nexport const o = os.$context<Context>()\n\nexport const publicProcedure = o\n\nconst requireAuth = o.middleware(async ({ context, next }) => {\n\tif (!context.session?.user) {\n\t\tthrow new ORPCError('UNAUTHORIZED')\n\t}\n\treturn next({\n\t\tcontext: {\n\t\t\tsession: context.session,\n\t\t},\n\t})\n})\n\nexport const protectedProcedure = publicProcedure.use(requireAuth)\n"],"mappings":";;;AAGA,MAAa,IAAI,GAAG,UAAmB;AAEvC,MAAa,kBAAkB;AAE/B,MAAM,cAAc,EAAE,WAAW,OAAO,EAAE,SAAS,WAAW;AAC7D,KAAI,CAAC,QAAQ,SAAS,KACrB,OAAM,IAAI,UAAU,eAAe;AAEpC,QAAO,KAAK,EACX,SAAS,EACR,SAAS,QAAQ,SACjB,EACD,CAAC;EACD;AAEF,MAAa,qBAAqB,gBAAgB,IAAI,YAAY"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@kuckit/api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "types": "./src/index.ts",
13
+ "default": "./src/index.ts"
14
+ },
15
+ "./*": {
16
+ "types": "./src/*.ts",
17
+ "default": "./src/*.ts"
18
+ }
19
+ },
20
+ "publishConfig": {
21
+ "main": "dist/index.js",
22
+ "types": "dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "./*": {
29
+ "types": "./dist/*.d.ts",
30
+ "default": "./dist/*.js"
31
+ }
32
+ }
33
+ },
34
+ "scripts": {
35
+ "build": "tsdown"
36
+ },
37
+ "devDependencies": {
38
+ "@types/express": "catalog:",
39
+ "tsdown": "catalog:"
40
+ },
41
+ "peerDependencies": {
42
+ "typescript": "^5"
43
+ },
44
+ "dependencies": {
45
+ "@orpc/server": "catalog:",
46
+ "@orpc/client": "catalog:",
47
+ "@orpc/openapi": "catalog:",
48
+ "@orpc/zod": "catalog:",
49
+ "better-auth": "catalog:",
50
+ "drizzle-orm": "catalog:",
51
+ "ai": "catalog:",
52
+ "@ai-sdk/google": "catalog:",
53
+ "dotenv": "catalog:",
54
+ "zod": "catalog:",
55
+ "awilix": "^12.0.5",
56
+ "@kuckit/auth": "workspace:*",
57
+ "@kuckit/db": "workspace:*",
58
+ "@kuckit/contracts": "workspace:*"
59
+ }
60
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { ORPCError, os } from '@orpc/server'
2
+ import type { Context } from './context'
3
+
4
+ export const o = os.$context<Context>()
5
+
6
+ export const publicProcedure = o
7
+
8
+ const requireAuth = o.middleware(async ({ context, next }) => {
9
+ if (!context.session?.user) {
10
+ throw new ORPCError('UNAUTHORIZED')
11
+ }
12
+ return next({
13
+ context: {
14
+ session: context.session,
15
+ },
16
+ })
17
+ })
18
+
19
+ export const protectedProcedure = publicProcedure.use(requireAuth)