@inflector/aura 0.4.2 → 0.4.4

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/dist/auth.d.ts CHANGED
@@ -1172,36 +1172,13 @@ export declare const AuraAuth: (url: string, workspace: string) => {
1172
1172
  };
1173
1173
  }>;
1174
1174
  };
1175
- Signal: import("nanostores").ReadableAtom<{
1176
- data: {
1177
- user: {
1178
- id: string;
1179
- createdAt: Date;
1180
- updatedAt: Date;
1181
- email: string;
1182
- emailVerified: boolean;
1183
- name: string;
1184
- image?: string | null | undefined;
1185
- isAnonymous: boolean | null | undefined;
1186
- };
1187
- session: {
1188
- id: string;
1189
- createdAt: Date;
1190
- updatedAt: Date;
1191
- userId: string;
1192
- expiresAt: Date;
1193
- token: string;
1194
- ipAddress?: string | null | undefined;
1195
- userAgent?: string | null | undefined;
1196
- };
1197
- } | null;
1198
- error: import("@better-fetch/fetch").BetterFetchError | null;
1175
+ Signal: import("nanostores").PreinitializedWritableAtom<{
1176
+ data: any;
1177
+ error: any;
1199
1178
  isPending: boolean;
1200
1179
  isRefetching: boolean;
1201
- refetch: (queryParams?: {
1202
- query?: import("better-auth").SessionQueryParams;
1203
- } | undefined) => Promise<void>;
1204
- }>;
1180
+ refetch: () => Promise<void>;
1181
+ }> & object;
1205
1182
  Anonymous: {
1206
1183
  SignUp: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth").Prettify<{
1207
1184
  query?: Record<string, any> | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,WAAW,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAwD3B,MAAM,IAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA5F9C,GAAG;eACF,GAAG;mBACC,OAAO;sBACJ,OAAO;iBACZ,MAAM,OAAO,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;qBAoB5B,CAAJ;;;;;;;;;;;;;;;;CA2IC,CAAC"}
package/dist/auth.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createAuthClient } from "better-auth/client";
2
2
  import { anonymousClient } from "better-auth/client/plugins";
3
- import { computed } from "nanostores";
3
+ import { atom } from "nanostores";
4
4
  // export const AuraAuth = (workspace: string) => {
5
5
  export const AuraAuth = (url, workspace) => {
6
6
  const _onUserLoadedCallbacks = [];
@@ -15,47 +15,75 @@ export const AuraAuth = (url, workspace) => {
15
15
  credentials: "include"
16
16
  },
17
17
  });
18
- const Session = computed(authClient.useSession, (session) => {
19
- if (!session?.data?.user)
20
- return session;
21
- return {
22
- ...session,
23
- data: {
24
- ...session.data,
25
- user: {
26
- ...session.data.user,
27
- image: session.data.user.image ? session.data.user.image : null,
28
- },
29
- },
30
- };
18
+ const Session = atom({
19
+ data: null,
20
+ error: null,
21
+ isPending: true,
22
+ isRefetching: false,
23
+ refetch: async () => {
24
+ await syncSession(true);
25
+ },
31
26
  });
32
27
  const triggerCallbacks = async (callbacks) => {
33
28
  for (const fn of callbacks)
34
29
  await fn();
35
30
  };
36
- const initialize = async () => {
31
+ const syncSession = async (isRefetch = false) => {
32
+ const current = Session.get();
33
+ Session.set({
34
+ ...current,
35
+ isPending: !isRefetch,
36
+ isRefetching: isRefetch,
37
+ });
37
38
  try {
38
- // Refetch so the session store (useSession) is updated; getSession() alone doesn't update the atom
39
- const sessionState = authClient.useSession.get?.();
40
- await sessionState?.refetch?.();
41
- const sessionFromStore = authClient.useSession.get?.();
42
- const data = sessionFromStore?.data ?? (await authClient.getSession())?.data;
43
- if (data?.user) {
44
- User = data.user;
39
+ const { data, error } = await authClient.getSession();
40
+ const normalizedData = data?.user
41
+ ? {
42
+ ...data,
43
+ user: {
44
+ ...data.user,
45
+ image: data.user.image ? data.user.image : null,
46
+ },
47
+ }
48
+ : data;
49
+ if (normalizedData?.user) {
50
+ User = normalizedData.user;
45
51
  await triggerCallbacks(_onUserLoadedCallbacks);
46
52
  }
47
53
  else {
48
54
  await triggerCallbacks(_onUserNotFoundCallbacks);
49
55
  }
56
+ Session.set({
57
+ ...Session.get(),
58
+ data: normalizedData ?? null,
59
+ error: error ?? null,
60
+ isPending: false,
61
+ isRefetching: false,
62
+ // keep the same refetch signature
63
+ refetch: Session.get().refetch,
64
+ });
50
65
  }
51
66
  catch (err) {
52
67
  console.error("Error initializing auth:", err);
53
68
  await triggerCallbacks(_onUserNotFoundCallbacks);
69
+ Session.set({
70
+ ...Session.get(),
71
+ error: err,
72
+ isPending: false,
73
+ isRefetching: false,
74
+ refetch: Session.get().refetch,
75
+ });
54
76
  }
55
77
  finally {
56
78
  _initialized = true;
57
79
  }
58
80
  };
81
+ const initialize = () => {
82
+ // Fire-and-forget initial session sync
83
+ syncSession(false).catch((err) => {
84
+ console.error("Error syncing session:", err);
85
+ });
86
+ };
59
87
  const OnUserLoaded = (fn) => {
60
88
  if (_initialized && User) {
61
89
  Promise.resolve(fn()).catch(console.error);
package/dist/bin.js CHANGED
@@ -626,6 +626,7 @@ async function start() {
626
626
  const targetUrl = `${upstreamUrl}${url.pathname}${url.search}`;
627
627
  const headers = new Headers(req.headers);
628
628
  headers.delete("host");
629
+ headers.delete("accept-encoding");
629
630
  headers.set("x-forwarded-host", req.headers.get("x-forwarded-host") ?? req.headers.get("host"));
630
631
  const forwardedProto = req.headers.get("x-forwarded-proto") ??
631
632
  req.headers.get("x-forwarded-scheme") ??
@@ -635,13 +636,21 @@ async function start() {
635
636
  if (AURA_KEY)
636
637
  headers.set("Authorization", `Bearer ${AURA_KEY}`);
637
638
  try {
638
- return await fetch(targetUrl, {
639
+ const proxiedResp = await fetch(targetUrl, {
639
640
  method: req.method,
640
641
  headers,
641
642
  body: req.method === "GET" || req.method === "HEAD"
642
643
  ? undefined
643
644
  : req.body,
644
645
  });
646
+ const proxyHeaders = new Headers(proxiedResp.headers);
647
+ proxyHeaders.delete("content-encoding");
648
+ proxyHeaders.delete("content-length");
649
+ return new Response(proxiedResp.body, {
650
+ status: proxiedResp.status,
651
+ statusText: proxiedResp.statusText,
652
+ headers: proxyHeaders,
653
+ });
645
654
  }
646
655
  catch {
647
656
  return new Response(JSON.stringify({ error: "Upstream Proxy Failed" }), { status: 502, headers: { "Content-Type": "application/json" } });
@@ -6,16 +6,7 @@ export declare function useTable<TDef extends ValueOf<Awaited<ReturnType<typeof
6
6
  export declare function useRecord<TDef extends ValueOf<Awaited<ReturnType<typeof CreateAura<any, any>>>['Database']>>(table: TDef, Options: {
7
7
  where: Parameters<Awaited<ReturnType<TDef['GetOne']>['where']>>[0];
8
8
  }): Awaited<ReturnType<TDef["GetOne"]>>;
9
- export declare const useUser: (provider: Awaited<ReturnType<typeof CreateAura<any, any>>>) => {
10
- id: string;
11
- createdAt: Date;
12
- updatedAt: Date;
13
- email: string;
14
- emailVerified: boolean;
15
- name: string;
16
- image?: string | null | undefined;
17
- isAnonymous: boolean | null | undefined;
18
- } | undefined;
9
+ export declare const useUser: (provider: Awaited<ReturnType<typeof CreateAura<any, any>>>) => any;
19
10
  export declare const useSession: (provider: any) => any;
20
11
  export {};
21
12
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/hooks/react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAIpC,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;AAkB5B,wBAAgB,QAAQ,CACtB,IAAI,SAAS,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,EAElF,KAAK,EAAE,IAAI,EACX,OAAO,CAAC,EAAE;IACR,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;CACnE,GAsEc,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAChD;AAED,wBAAgB,SAAS,CACvB,IAAI,SAAS,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,EAElF,KAAK,EAAE,IAAI,EACX,OAAO,EAAE;IACP,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC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CAAC,CAAA;CACnE,GA0Dc,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CACnD;AAED,eAAO,MAAM,OAAO,GAAI,UAAU,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,QAGjF,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,UAAU,GAAG,QAGvC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inflector/aura",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",