@kuckit/api 2.0.0 → 2.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.
@@ -1 +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;;;;;AA8CtB;AAAgD,iBA9C1B,aAAA,CA8C0B,IAAA,EA9CN,oBA8CM,CAAA,EA9Cc,OA8Cd,CAAA;EAAlB,OAAA,EAAA,GAAA;EAAR,EAAA,iBAAA,CAAA,GAAA,CAAA;CAAO,CAAA;KAAjB,OAAA,GAAU,QAAQ,kBAAkB"}
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;;;;;AAmDtB;AAAgD,iBAnD1B,aAAA,CAmD0B,IAAA,EAnDN,oBAmDM,CAAA,EAnDc,OAmDd,CAAA;EAAlB,OAAA,EAAA,GAAA;EAAR,EAAA,iBAAA,CAAA,GAAA,CAAA;CAAO,CAAA;KAAjB,OAAA,GAAU,QAAQ,kBAAkB"}
package/dist/context.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { fromNodeHeaders } from "better-auth/node";
2
- import { auth } from "@kuckit/auth";
3
2
  import { asValue } from "awilix";
4
3
 
5
4
  //#region src/context.ts
@@ -8,8 +7,10 @@ import { asValue } from "awilix";
8
7
  * Injects logger with requestId for structured tracing
9
8
  */
10
9
  async function createContext(opts) {
10
+ const auth = opts.req.scope?.cradle.auth;
11
11
  let session;
12
12
  try {
13
+ if (!auth) throw new Error("Auth not available in request scope");
13
14
  session = await auth.api.getSession({ headers: fromNodeHeaders(opts.req.headers) });
14
15
  } catch (error) {
15
16
  console.error("[Auth] Failed to get session:", error, "Headers:", opts.req.headers);
@@ -1 +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"}
1
+ {"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type { Request } from 'express'\nimport { fromNodeHeaders } from 'better-auth/node'\nimport type { 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\tconst auth = opts.req.scope?.cradle.auth as Auth | undefined\n\n\tlet session\n\ttry {\n\t\tif (!auth) {\n\t\t\tthrow new Error('Auth not available in request scope')\n\t\t}\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,MAAM,OAAO,KAAK,IAAI,OAAO,OAAO;CAEpC,IAAI;AACJ,KAAI;AACH,MAAI,CAAC,KACJ,OAAM,IAAI,MAAM,sCAAsC;AAEvD,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kuckit/api",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -40,8 +40,8 @@
40
40
  "dotenv": "^17.2.2",
41
41
  "zod": "^4.1.11",
42
42
  "awilix": "^12.0.5",
43
- "@kuckit/auth": "^2.0.0",
44
- "@kuckit/db": "^2.0.0",
45
- "@kuckit/contracts": "^2.0.0"
43
+ "@kuckit/auth": "^2.0.2",
44
+ "@kuckit/db": "^2.0.2",
45
+ "@kuckit/contracts": "^2.0.2"
46
46
  }
47
47
  }