@inflector/aura 0.1.14 → 0.1.16

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
@@ -3,17 +3,26 @@ interface SessionEventsType {
3
3
  on(event: SessionEvent, callback: () => void): () => void;
4
4
  emit(event: SessionEvent): void;
5
5
  }
6
+ declare const getTokenKey: (workspace: string) => string;
7
+ declare const getToken: (workspace: string) => string;
8
+ declare const setToken: (workspace: string, token: string | null) => void;
9
+ export { getToken, setToken, getTokenKey };
6
10
  export declare const SessionEvents: SessionEventsType;
7
11
  export declare const AuraAuth: (url: string, workspace: string) => {
8
- Logout: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth").Prettify<{
9
- query?: Record<string, any> | undefined;
10
- fetchOptions?: FetchOptions | undefined;
11
- }> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
12
- success: boolean;
13
- }, {
14
- code?: string | undefined;
15
- message?: string | undefined;
16
- }, FetchOptions["throw"] extends true ? true : false>>;
12
+ Logout: () => Promise<{
13
+ data: {
14
+ success: boolean;
15
+ };
16
+ error: null;
17
+ } | {
18
+ data: null;
19
+ error: {
20
+ code?: string | undefined | undefined;
21
+ message?: string | undefined | undefined;
22
+ status: number;
23
+ statusText: string;
24
+ };
25
+ }>;
17
26
  Email: {
18
27
  SignUp: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
19
28
  name: string;
@@ -1238,5 +1247,4 @@ export declare const AuraAuth: (url: string, workspace: string) => {
1238
1247
  }, FetchOptions["throw"] extends true ? true : false>>;
1239
1248
  };
1240
1249
  };
1241
- export {};
1242
1250
  //# sourceMappingURL=auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAKA,KAAK,YAAY,GAAG,OA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAtGpD,CAAD;iBAAe,CAAC;;;;;;;;;;;;;;;;qBAlB2B,CAAC;;;;;;;;;;;;;;;;CAmM9C,CAAC"}
package/dist/auth.js CHANGED
@@ -1,6 +1,26 @@
1
1
  import { createAuthClient } from "better-auth/client";
2
2
  import { anonymousClient } from "better-auth/client/plugins";
3
3
  import { computed } from "nanostores";
4
+ // Token storage key - unique per workspace to avoid conflicts
5
+ const getTokenKey = (workspace) => `aura_bearer_token_${workspace}`;
6
+ // Helper to get/set token from localStorage (with SSR safety)
7
+ const getToken = (workspace) => {
8
+ if (typeof window === 'undefined')
9
+ return '';
10
+ return localStorage.getItem(getTokenKey(workspace)) || '';
11
+ };
12
+ const setToken = (workspace, token) => {
13
+ if (typeof window === 'undefined')
14
+ return;
15
+ if (token) {
16
+ localStorage.setItem(getTokenKey(workspace), token);
17
+ }
18
+ else {
19
+ localStorage.removeItem(getTokenKey(workspace));
20
+ }
21
+ };
22
+ // Export for use in other modules
23
+ export { getToken, setToken, getTokenKey };
4
24
  // Only create once on the global object
5
25
  // Returns a no-op implementation for SSR/Node.js environments
6
26
  export const SessionEvents = (() => {
@@ -47,7 +67,18 @@ export const AuraAuth = (url, workspace) => {
47
67
  baseURL: url + "/api/auth/" + workspace,
48
68
  plugins: [anonymousClient()],
49
69
  fetchOptions: {
50
- credentials: "include",
70
+ // Use Bearer token authentication instead of cookies
71
+ auth: {
72
+ type: "Bearer",
73
+ token: () => getToken(workspace)
74
+ },
75
+ // Store the token from response headers on every successful request
76
+ onSuccess: (ctx) => {
77
+ const authToken = ctx.response.headers.get("set-auth-token");
78
+ if (authToken) {
79
+ setToken(workspace, authToken);
80
+ }
81
+ }
51
82
  },
52
83
  });
53
84
  authClient.useSession.subscribe(() => {
@@ -114,7 +145,11 @@ export const AuraAuth = (url, workspace) => {
114
145
  // Initialize auth on creation
115
146
  initialize();
116
147
  return {
117
- Logout: authClient.signOut,
148
+ Logout: async () => {
149
+ const result = await authClient.signOut();
150
+ setToken(workspace, null); // Clear token on logout
151
+ return result;
152
+ },
118
153
  Email: {
119
154
  SignUp: authClient.signUp.email,
120
155
  Login: authClient.signIn.email,
@@ -3,6 +3,7 @@ declare class RemoteTable<TDef extends Record<string, any>> {
3
3
  private URL;
4
4
  private Name;
5
5
  private WorkSpace;
6
+ private getAuthHeaders;
6
7
  constructor(url: string, name: string, workspace: string);
7
8
  Get: () => {
8
9
  where: Where<{ [K_1 in keyof TDef as K_1 extends `__${string}` ? never : TDef[K_1] extends import("@inflector/optima").ColumnBuilder<any, infer C extends import("@inflector/optima").ColumnConfig, any> ? C["notnull"] extends true ? K_1 : never : never]: TDef[K_1] extends import("@inflector/optima").ColumnBuilder<infer U, any, any> ? U : never; } & { [K_2 in keyof TDef as K_2 extends `__${string}` ? never : TDef[K_2] extends import("@inflector/optima").ColumnBuilder<any, infer C extends import("@inflector/optima").ColumnConfig, any> ? C["notnull"] extends true ? never : K_2 : never]: TDef[K_2] extends import("@inflector/optima").ColumnBuilder<infer U, any, any> ? U | null : never; } extends infer T ? { [K in keyof T]: T[K]; } : never> extends boolean ? () => {
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"A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AM,CAAC;QAAC,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,CAAA;KAAE,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,EAAE,OAAO,OAAO,gBAuE7J;CACJ;AAED,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,EACzE,KAAK,MAAM,EACX,WAAW,MAAM,EACjB,QAAQ,CAAC,QAEe,CAAC,kCAY5B,CAAA"}
package/dist/database.js CHANGED
@@ -1,9 +1,14 @@
1
1
  import { createFluentBuilder } from "./fluent";
2
2
  import axios from "axios";
3
+ import { getToken } from "./auth";
3
4
  class RemoteTable {
4
5
  URL;
5
6
  Name;
6
7
  WorkSpace;
8
+ getAuthHeaders() {
9
+ const token = getToken(this.WorkSpace);
10
+ return token ? { Authorization: `Bearer ${token}` } : {};
11
+ }
7
12
  constructor(url, name, workspace) {
8
13
  this.URL = url;
9
14
  this.Name = name;
@@ -15,7 +20,7 @@ class RemoteTable {
15
20
  operation: 'Get',
16
21
  settings: data,
17
22
  }, {
18
- withCredentials: true
23
+ headers: this.getAuthHeaders()
19
24
  })).data;
20
25
  });
21
26
  };
@@ -25,7 +30,7 @@ class RemoteTable {
25
30
  operation: 'GetOne',
26
31
  settings: data,
27
32
  }, {
28
- withCredentials: true
33
+ headers: this.getAuthHeaders()
29
34
  })).data;
30
35
  });
31
36
  };
@@ -35,7 +40,7 @@ class RemoteTable {
35
40
  operation: 'Delete',
36
41
  settings: { ...data, returning: true },
37
42
  }, {
38
- withCredentials: true
43
+ headers: this.getAuthHeaders()
39
44
  })).data;
40
45
  });
41
46
  };
@@ -48,7 +53,7 @@ class RemoteTable {
48
53
  },
49
54
  data: record
50
55
  }, {
51
- withCredentials: true
56
+ headers: this.getAuthHeaders()
52
57
  })).data;
53
58
  });
54
59
  };
@@ -61,7 +66,7 @@ class RemoteTable {
61
66
  },
62
67
  data: record
63
68
  }, {
64
- withCredentials: true
69
+ headers: this.getAuthHeaders()
65
70
  })).data;
66
71
  });
67
72
  };
@@ -72,7 +77,7 @@ class RemoteTable {
72
77
  settings: { ...data, returning: true },
73
78
  data: record
74
79
  }, {
75
- withCredentials: true
80
+ headers: this.getAuthHeaders()
76
81
  })).data;
77
82
  });
78
83
  };
@@ -82,7 +87,7 @@ class RemoteTable {
82
87
  operation: 'Count',
83
88
  settings: data,
84
89
  }, {
85
- withCredentials: true
90
+ headers: this.getAuthHeaders()
86
91
  })).data;
87
92
  });
88
93
  };
@@ -92,7 +97,7 @@ class RemoteTable {
92
97
  operation: 'Exist',
93
98
  settings: data,
94
99
  }, {
95
- withCredentials: true
100
+ headers: this.getAuthHeaders()
96
101
  })).data;
97
102
  });
98
103
  };
@@ -103,14 +108,67 @@ class RemoteTable {
103
108
  if (init)
104
109
  params.push("init=true");
105
110
  const query = params.length ? "?" + params.join("&") : "";
106
- const eventSource = new EventSource(`${this.URL}/api/db/${this.WorkSpace}/${this.Name}${query}`, {
107
- withCredentials: true
108
- });
109
- eventSource.addEventListener(this.Name, (event) => {
110
- const { op, data } = JSON.parse(event.data);
111
- callback({ action: op, data });
112
- });
113
- return () => eventSource.close();
111
+ let abortController = new AbortController();
112
+ const tableName = this.Name;
113
+ const startStream = async () => {
114
+ try {
115
+ const response = await fetch(`${this.URL}/api/db/${this.WorkSpace}/${this.Name}${query}`, {
116
+ method: 'GET',
117
+ headers: {
118
+ ...this.getAuthHeaders(),
119
+ 'Accept': 'text/event-stream',
120
+ },
121
+ signal: abortController?.signal,
122
+ });
123
+ if (!response.ok || !response.body) {
124
+ throw new Error(`SSE connection failed: ${response.status}`);
125
+ }
126
+ const reader = response.body.getReader();
127
+ const decoder = new TextDecoder();
128
+ let buffer = '';
129
+ while (true) {
130
+ const { done, value } = await reader.read();
131
+ if (done)
132
+ break;
133
+ buffer += decoder.decode(value, { stream: true });
134
+ const lines = buffer.split('\n');
135
+ buffer = lines.pop() || '';
136
+ let currentEvent = '';
137
+ let currentData = '';
138
+ for (const line of lines) {
139
+ if (line.startsWith('event:')) {
140
+ currentEvent = line.slice(6).trim();
141
+ }
142
+ else if (line.startsWith('data:')) {
143
+ currentData = line.slice(5).trim();
144
+ }
145
+ else if (line === '' && currentEvent === tableName && currentData) {
146
+ try {
147
+ const { op, data } = JSON.parse(currentData);
148
+ callback({ action: op, data });
149
+ }
150
+ catch (e) {
151
+ // Ignore parse errors
152
+ }
153
+ currentEvent = '';
154
+ currentData = '';
155
+ }
156
+ }
157
+ }
158
+ }
159
+ catch (error) {
160
+ if (error.name !== 'AbortError') {
161
+ console.error('SSE stream error:', error);
162
+ }
163
+ }
164
+ };
165
+ startStream();
166
+ return () => {
167
+ if (abortController) {
168
+ abortController.abort();
169
+ abortController = null;
170
+ }
171
+ };
114
172
  };
115
173
  }
116
174
  export const AuraDatabase = (url, workspace, tables) => {
@@ -1 +1 @@
1
- {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../src/function.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,GAAG,CAmHvG"}
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../src/function.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,GAAG,CAyHvG"}
package/dist/function.js CHANGED
@@ -1,4 +1,10 @@
1
1
  export function createFunctionHandler(baseUrl, workspace, functionsFolder) {
2
+ // Helper to get token for Bearer auth
3
+ const getToken = () => {
4
+ if (typeof window === 'undefined')
5
+ return '';
6
+ return localStorage.getItem(`aura_bearer_token_${workspace}`) || '';
7
+ };
2
8
  const handler = new Proxy({}, {
3
9
  get(_, prop) {
4
10
  return createNestedProxy([prop]);
@@ -15,17 +21,19 @@ export function createFunctionHandler(baseUrl, workspace, functionsFolder) {
15
21
  const url = [baseUrl, "api", "fn", workspace, ...path].join("/");
16
22
  const isFormData = args != null && args.length === 1 && args[0] instanceof FormData;
17
23
  const body = isFormData ? args[0] : JSON.stringify(args ?? {});
24
+ const token = getToken();
18
25
  const headers = {
19
26
  "Accept": "text/event-stream,application/json",
20
27
  };
21
28
  if (!isFormData)
22
29
  headers["Content-Type"] = "application/json";
30
+ if (token)
31
+ headers["Authorization"] = `Bearer ${token}`;
23
32
  // 2. Start the fetch properly (without await)
24
33
  const requestPromise = fetch(url, {
25
34
  method: "POST",
26
35
  body,
27
36
  headers,
28
- credentials: "include",
29
37
  });
30
38
  // 3. Return a custom "Thenable" object with full Promise interface
31
39
  const thenable = {
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,IAAI,CAAC;CACpB,CAAC;AAIF,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,WAAW,MAAM,EAAE,UAAU,GAAG;oBAG1D,IAAI,WACH;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,KAC5D,OAAO,CAAC,QAAQ,CAAC;eA6DL,MAAM;iBAGE,MAAM;cAYT,MAAM,KAAG,OAAO,CAAC,QAAQ,CAAC;gBAY1B,OAAO,CAAC,QAAQ,EAAE,CAAC;6BAYvB,IAAI,EAAE,WACN;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE;iBAmD5C,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;mBAYvB,MAAM,aAAY,OAAO,aAAoB,OAAO;;;;;CA6BhF,CAAA"}
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,IAAI,CAAC;CACpB,CAAC;AAKF,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,WAAW,MAAM,EAAE,UAAU,GAAG;oBAQ1D,IAAI,WACH;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,KAC5D,OAAO,CAAC,QAAQ,CAAC;eA6DL,MAAM;iBAGE,MAAM;cAYT,MAAM,KAAG,OAAO,CAAC,QAAQ,CAAC;gBAY1B,OAAO,CAAC,QAAQ,EAAE,CAAC;6BAYvB,IAAI,EAAE,WACN;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE;iBAmD5C,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;mBAYvB,MAAM,aAAY,OAAO,aAAoB,OAAO;;;;;CA6BhF,CAAA"}
package/dist/storage.js CHANGED
@@ -1,5 +1,11 @@
1
1
  import axios from "axios";
2
+ import { getToken } from "./auth";
2
3
  export const AuraStorage = (url, workspace, userAtom) => {
4
+ // Helper to get auth headers for Bearer token
5
+ const getAuthHeaders = () => {
6
+ const token = getToken(workspace);
7
+ return token ? { Authorization: `Bearer ${token}` } : {};
8
+ };
3
9
  const UploadFn = async (file, config = {}) => {
4
10
  if (!userAtom.get().data)
5
11
  throw new Error("User not authenticated");
@@ -31,7 +37,7 @@ export const AuraStorage = (url, workspace, userAtom) => {
31
37
  fd.set("operation", "Upload");
32
38
  fd.set("owner", userAtom.get().data.user.id);
33
39
  fd.set("file", selectedFile);
34
- const result = (await axios.post(url + "/api/storage/" + workspace, fd)).data;
40
+ const result = (await axios.post(url + "/api/storage/" + workspace, fd, { headers: getAuthHeaders() })).data;
35
41
  resolve(result);
36
42
  cleanup();
37
43
  }
@@ -54,7 +60,7 @@ export const AuraStorage = (url, workspace, userAtom) => {
54
60
  fd.set("owner", userAtom.get().data.user.id);
55
61
  fd.set("file", file);
56
62
  return (await axios.post(url + "/api/storage/" + workspace, fd, {
57
- withCredentials: true
63
+ headers: getAuthHeaders()
58
64
  })).data;
59
65
  }
60
66
  };
@@ -73,7 +79,7 @@ export const AuraStorage = (url, workspace, userAtom) => {
73
79
  Owner: userAtom.get().data.user.id
74
80
  }
75
81
  }, {
76
- withCredentials: true
82
+ headers: getAuthHeaders()
77
83
  })).data;
78
84
  },
79
85
  Get: async (id) => {
@@ -86,7 +92,7 @@ export const AuraStorage = (url, workspace, userAtom) => {
86
92
  Owner: userAtom.get().data.user.id
87
93
  }
88
94
  }, {
89
- withCredentials: true
95
+ headers: getAuthHeaders()
90
96
  })).data;
91
97
  },
92
98
  List: async () => {
@@ -98,7 +104,7 @@ export const AuraStorage = (url, workspace, userAtom) => {
98
104
  Owner: userAtom.get().data.user.id
99
105
  }
100
106
  }, {
101
- withCredentials: true
107
+ headers: getAuthHeaders()
102
108
  })).data;
103
109
  },
104
110
  UploadMultiple: async (files, config = {}) => {
@@ -160,14 +166,14 @@ export const AuraStorage = (url, workspace, userAtom) => {
160
166
  Owner: userAtom.get().data.user.id
161
167
  }
162
168
  }, {
163
- withCredentials: true
169
+ headers: getAuthHeaders()
164
170
  })).data;
165
171
  },
166
172
  Download: async (id, download = true, asBase64) => {
167
173
  try {
168
174
  const response = await axios.get(`${url}/api/storage/${workspace}/${id}?download=${download ? '1' : '0'}&base64=${asBase64 ? '1' : '0'}`, {
169
175
  responseType: "blob",
170
- withCredentials: true
176
+ headers: getAuthHeaders()
171
177
  });
172
178
  // Extract filename from content-disposition
173
179
  const contentDisposition = response.headers["content-disposition"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inflector/aura",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",