@aurabase/aurabase-js 0.4.1 → 0.5.1

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/README.md CHANGED
@@ -1,10 +1,12 @@
1
- # aurabase
1
+ # @aurabase/aurabase-js
2
2
 
3
- Client JavaScript/TypeScript officiel d'Aurabase : point d'entrée principal du SDK, agrégeant les 8 packages de service (`@aurabase/*`) derrière `createClient`/`createAdminClient` et l'export `aurabase/ssr`.
3
+ Client JavaScript/TypeScript officiel pour [Aurabase](https://aurabase.cloud) : la plateforme Backend-as-a-Service open-source haute performance propulsée par Rust.
4
4
 
5
- ![npm](https://img.shields.io/npm/v/aurabase) ![license](https://img.shields.io/badge/license-MIT-blue)
5
+ [![npm version](https://img.shields.io/npm/v/@aurabase/aurabase-js)](https://www.npmjs.com/package/@aurabase/aurabase-js) [![license](https://img.shields.io/badge/license-MIT-blue)](https://github.com/daylami555/aurabase/blob/main/LICENSE)
6
6
 
7
- > Pre-release — pas encore publié sur npm.
7
+ 🌐 **Site officiel** : [https://aurabase.cloud](https://aurabase.cloud)
8
+ 📖 **Documentation** : [https://aurabase.cloud/docs](https://aurabase.cloud)
9
+ 🐙 **GitHub** : [daylami555/aurabase](https://github.com/daylami555/aurabase)
8
10
 
9
11
  ## Installation
10
12
 
@@ -16,8 +18,8 @@ npm i @aurabase/aurabase-js
16
18
 
17
19
  Ce package ne réimplémente aucune logique de service : il compose `AuthService`, `DatabaseService`, `StorageService`, `RealtimeService`, `FunctionsService`, `AiService` et `NotificationsService` (chacun dans son propre package `@aurabase/*`) derrière un seul client.
18
20
 
19
- - `createClient(baseUrl, projectId, apiKey, options?)` — client applicatif standard.
20
- - `createAdminClient(baseUrl, projectId, serviceRoleKey, options?)` — client serveur avec `authAdmin` (clé `service_role`, jamais côté navigateur).
21
+ - `createClient(projectUrl, apiKey, options?)` — client applicatif standard. **L'URL est le projet** : chaque projet est servi sur son propre sous-domaine (`https://<slug>.aurabase.cloud`) et la passerelle injecte elle-même le `project_id` dans le chemin. Aucun identifiant de projet dans le code client.
22
+ - `createAdminClient(projectUrl, serviceRoleKey, options?)` — client serveur avec `authAdmin` (clé `service_role`, jamais côté navigateur).
21
23
  - `aurabase/ssr` — `createServerClient`/`createBrowserClient` pour Next.js et frameworks SSR (cookies, session partagée serveur/navigateur).
22
24
 
23
25
  ## Quick Start
@@ -25,11 +27,7 @@ Ce package ne réimplémente aucune logique de service : il compose `AuthService
25
27
  ```ts
26
28
  import { createClient } from '@aurabase/aurabase-js'
27
29
 
28
- const aura = createClient(
29
- 'http://localhost:8080',
30
- '00000000-0000-0000-0000-000000000001',
31
- 'aura_anon_xxx',
32
- )
30
+ const aura = createClient('https://mon-projet.aurabase.cloud', 'aura_anon_xxx')
33
31
 
34
32
  const { data, error } = await aura.db
35
33
  .from('posts')
@@ -1,25 +1,31 @@
1
- import { AuraClientLike, BaseAuthStore, AuraObservabilityEvent, AuraClientOptions, ChannelConfig } from '@aurabase/core';
1
+ import { AiService } from '@aurabase/ai';
2
2
  import { AuthService, AuthAdminService } from '@aurabase/auth';
3
+ import { AuraClientLike, BaseAuthStore, AuraObservabilityEvent, AuraClientOptions, ChannelConfig } from '@aurabase/core';
3
4
  import { DatabaseService } from '@aurabase/db';
4
- import { StorageService } from '@aurabase/storage';
5
- import { RealtimeService, AuraChannel } from '@aurabase/realtime';
6
5
  import { FunctionsService } from '@aurabase/functions';
7
- import { AiService } from '@aurabase/ai';
8
6
  import { NotificationsService } from '@aurabase/notifications';
7
+ import { RealtimeService, AuraChannel } from '@aurabase/realtime';
8
+ import { StorageService } from '@aurabase/storage';
9
9
 
10
10
  /**
11
11
  * Main Aurabase client.
12
12
  *
13
+ * L'URL EST le projet : chaque projet est servi sur son propre sous-domaine
14
+ * (`https://<slug>.aurabase.cloud`), et la passerelle résout le tenant depuis l'hôte puis
15
+ * injecte le `project_id` dans le chemin (`inject_project_id`,
16
+ * `services/aura-gateway/src/middleware/project_subdomain.rs`). Aucun identifiant de projet
17
+ * n'est donc écrit ni transporté par le client.
18
+ *
13
19
  * @example
14
20
  * ```ts
15
21
  * import { createClient } from '@aurabase/aurabase-js'
16
- * const aura = createClient('http://localhost:8080', 'my-project-id')
22
+ * const aura = createClient('https://mon-projet.aurabase.cloud', 'aura_anon_xxx')
17
23
  * const { data } = await aura.db.from('posts').eq('published', true)
18
24
  * ```
19
25
  */
20
26
  declare class AuraClient<Database = any> implements AuraClientLike {
27
+ /** URL du projet (`https://<slug>.aurabase.cloud`), sans barre finale. */
21
28
  readonly baseUrl: string;
22
- readonly projectId: string;
23
29
  readonly apiKey: string | null;
24
30
  readonly fetchFn: typeof globalThis.fetch;
25
31
  readonly authStore: BaseAuthStore;
@@ -45,7 +51,11 @@ declare class AuraClient<Database = any> implements AuraClientLike {
45
51
  private readonly _persistSession;
46
52
  private readonly _autoRefresh;
47
53
  private readonly _detectSessionInUrl;
48
- constructor(baseUrl: string, projectId: string, apiKeyOrOptions?: string | AuraClientOptions, options?: AuraClientOptions);
54
+ /**
55
+ * @param baseUrl URL du projet (`https://<slug>.aurabase.cloud`).
56
+ * @param apiKey Clé API du projet (`aura_anon_…`, `aura_auth_…`, `aura_sk_…`).
57
+ */
58
+ constructor(baseUrl: string, apiKey: string, options?: AuraClientOptions);
49
59
  /**
50
60
  * Démonte le client : arrête le refresh proactif (ticker + visibilité + BroadcastChannel),
51
61
  * déconnecte le realtime, vide les listeners d'auth. Idempotent. À appeler en teardown
@@ -72,6 +82,21 @@ declare class AuraClient<Database = any> implements AuraClientLike {
72
82
  * ```
73
83
  */
74
84
  channel(name: string, options?: ChannelConfig): AuraChannel;
85
+ /**
86
+ * Shortcut: remove a realtime channel by name or AuraChannel instance.
87
+ * Equivalent to `aura.realtime.removeChannel(channel)`.
88
+ */
89
+ removeChannel(channel: string | AuraChannel): void;
90
+ /**
91
+ * Shortcut: remove all realtime channels and unsubscribe.
92
+ * Equivalent to `aura.realtime.removeAllChannels()`.
93
+ */
94
+ removeAllChannels(): void;
95
+ /**
96
+ * Shortcut: list all active realtime channels.
97
+ * Equivalent to `aura.realtime.getChannels()`.
98
+ */
99
+ getChannels(): AuraChannel[];
75
100
  }
76
101
 
77
102
  export { AuraClient as A };
@@ -1,25 +1,31 @@
1
- import { AuraClientLike, BaseAuthStore, AuraObservabilityEvent, AuraClientOptions, ChannelConfig } from '@aurabase/core';
1
+ import { AiService } from '@aurabase/ai';
2
2
  import { AuthService, AuthAdminService } from '@aurabase/auth';
3
+ import { AuraClientLike, BaseAuthStore, AuraObservabilityEvent, AuraClientOptions, ChannelConfig } from '@aurabase/core';
3
4
  import { DatabaseService } from '@aurabase/db';
4
- import { StorageService } from '@aurabase/storage';
5
- import { RealtimeService, AuraChannel } from '@aurabase/realtime';
6
5
  import { FunctionsService } from '@aurabase/functions';
7
- import { AiService } from '@aurabase/ai';
8
6
  import { NotificationsService } from '@aurabase/notifications';
7
+ import { RealtimeService, AuraChannel } from '@aurabase/realtime';
8
+ import { StorageService } from '@aurabase/storage';
9
9
 
10
10
  /**
11
11
  * Main Aurabase client.
12
12
  *
13
+ * L'URL EST le projet : chaque projet est servi sur son propre sous-domaine
14
+ * (`https://<slug>.aurabase.cloud`), et la passerelle résout le tenant depuis l'hôte puis
15
+ * injecte le `project_id` dans le chemin (`inject_project_id`,
16
+ * `services/aura-gateway/src/middleware/project_subdomain.rs`). Aucun identifiant de projet
17
+ * n'est donc écrit ni transporté par le client.
18
+ *
13
19
  * @example
14
20
  * ```ts
15
21
  * import { createClient } from '@aurabase/aurabase-js'
16
- * const aura = createClient('http://localhost:8080', 'my-project-id')
22
+ * const aura = createClient('https://mon-projet.aurabase.cloud', 'aura_anon_xxx')
17
23
  * const { data } = await aura.db.from('posts').eq('published', true)
18
24
  * ```
19
25
  */
20
26
  declare class AuraClient<Database = any> implements AuraClientLike {
27
+ /** URL du projet (`https://<slug>.aurabase.cloud`), sans barre finale. */
21
28
  readonly baseUrl: string;
22
- readonly projectId: string;
23
29
  readonly apiKey: string | null;
24
30
  readonly fetchFn: typeof globalThis.fetch;
25
31
  readonly authStore: BaseAuthStore;
@@ -45,7 +51,11 @@ declare class AuraClient<Database = any> implements AuraClientLike {
45
51
  private readonly _persistSession;
46
52
  private readonly _autoRefresh;
47
53
  private readonly _detectSessionInUrl;
48
- constructor(baseUrl: string, projectId: string, apiKeyOrOptions?: string | AuraClientOptions, options?: AuraClientOptions);
54
+ /**
55
+ * @param baseUrl URL du projet (`https://<slug>.aurabase.cloud`).
56
+ * @param apiKey Clé API du projet (`aura_anon_…`, `aura_auth_…`, `aura_sk_…`).
57
+ */
58
+ constructor(baseUrl: string, apiKey: string, options?: AuraClientOptions);
49
59
  /**
50
60
  * Démonte le client : arrête le refresh proactif (ticker + visibilité + BroadcastChannel),
51
61
  * déconnecte le realtime, vide les listeners d'auth. Idempotent. À appeler en teardown
@@ -72,6 +82,21 @@ declare class AuraClient<Database = any> implements AuraClientLike {
72
82
  * ```
73
83
  */
74
84
  channel(name: string, options?: ChannelConfig): AuraChannel;
85
+ /**
86
+ * Shortcut: remove a realtime channel by name or AuraChannel instance.
87
+ * Equivalent to `aura.realtime.removeChannel(channel)`.
88
+ */
89
+ removeChannel(channel: string | AuraChannel): void;
90
+ /**
91
+ * Shortcut: remove all realtime channels and unsubscribe.
92
+ * Equivalent to `aura.realtime.removeAllChannels()`.
93
+ */
94
+ removeAllChannels(): void;
95
+ /**
96
+ * Shortcut: list all active realtime channels.
97
+ * Equivalent to `aura.realtime.getChannels()`.
98
+ */
99
+ getChannels(): AuraChannel[];
75
100
  }
76
101
 
77
102
  export { AuraClient as A };
package/dist/index.cjs CHANGED
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var core = require('@aurabase/core');
3
+ var ai = require('@aurabase/ai');
4
4
  var auth = require('@aurabase/auth');
5
+ var core = require('@aurabase/core');
5
6
  var db = require('@aurabase/db');
6
- var storage = require('@aurabase/storage');
7
- var realtime = require('@aurabase/realtime');
8
7
  var functions = require('@aurabase/functions');
9
- var ai = require('@aurabase/ai');
10
8
  var notifications = require('@aurabase/notifications');
9
+ var realtime = require('@aurabase/realtime');
10
+ var storage = require('@aurabase/storage');
11
11
 
12
- // src/AuraClient.ts
12
+ // src/index.ts
13
13
  function isBrowserContext() {
14
14
  if (typeof window !== "undefined") return true;
15
15
  const g = globalThis;
@@ -19,8 +19,8 @@ function isBrowserContext() {
19
19
  }
20
20
  var SERVICE_ROLE_KEY_PREFIX = "aura_sk_";
21
21
  var AuraClient = class {
22
+ /** URL du projet (`https://<slug>.aurabase.cloud`), sans barre finale. */
22
23
  baseUrl;
23
- projectId;
24
24
  apiKey;
25
25
  fetchFn;
26
26
  authStore;
@@ -44,11 +44,14 @@ var AuraClient = class {
44
44
  _persistSession;
45
45
  _autoRefresh;
46
46
  _detectSessionInUrl;
47
- constructor(baseUrl, projectId, apiKeyOrOptions, options) {
47
+ /**
48
+ * @param baseUrl URL du projet (`https://<slug>.aurabase.cloud`).
49
+ * @param apiKey Clé API du projet (`aura_anon_…`, `aura_auth_…`, `aura_sk_…`).
50
+ */
51
+ constructor(baseUrl, apiKey, options) {
48
52
  this.baseUrl = baseUrl.replace(/\/+$/, "");
49
- this.projectId = projectId;
50
- const resolvedOptions = typeof apiKeyOrOptions === "string" ? options : apiKeyOrOptions;
51
- this.apiKey = typeof apiKeyOrOptions === "string" ? apiKeyOrOptions : apiKeyOrOptions?.apiKey ?? null;
53
+ const resolvedOptions = options;
54
+ this.apiKey = apiKey || null;
52
55
  this.fetchFn = resolvedOptions?.fetch ?? globalThis.fetch.bind(globalThis);
53
56
  const r = resolvedOptions?.retry;
54
57
  this.retryConfig = r === false ? { enabled: false, maxRetries: 0 } : r === void 0 || r === true ? { enabled: true, maxRetries: core.DEFAULT_MAX_RETRIES } : { enabled: r.enabled ?? true, maxRetries: r.maxRetries ?? core.DEFAULT_MAX_RETRIES };
@@ -74,7 +77,7 @@ var AuraClient = class {
74
77
  } else if (resolvedOptions?.auth?.persistSession === false) {
75
78
  this.authStore = new core.BaseAuthStore();
76
79
  } else if (typeof localStorage !== "undefined") {
77
- this.authStore = new core.LocalAuthStore();
80
+ this.authStore = new core.LocalAuthStore(`aura-${core.clientScope(this.baseUrl)}-auth`);
78
81
  } else {
79
82
  this.authStore = new core.BaseAuthStore();
80
83
  }
@@ -105,6 +108,15 @@ var AuraClient = class {
105
108
  persistSession: this._persistSession,
106
109
  detectSessionInUrl: this._detectSessionInUrl
107
110
  });
111
+ this._auth.onAuthStateChange(({ event, accessToken }) => {
112
+ if (this._realtime) {
113
+ if (accessToken) {
114
+ this._realtime.setAuth(accessToken);
115
+ } else if (event === "SIGNED_OUT") {
116
+ this._realtime.setAuth("");
117
+ }
118
+ }
119
+ });
108
120
  }
109
121
  return this._auth;
110
122
  }
@@ -155,34 +167,45 @@ var AuraClient = class {
155
167
  channel(name, options) {
156
168
  return this.realtime.channel(name, options);
157
169
  }
170
+ /**
171
+ * Shortcut: remove a realtime channel by name or AuraChannel instance.
172
+ * Equivalent to `aura.realtime.removeChannel(channel)`.
173
+ */
174
+ removeChannel(channel) {
175
+ return this.realtime.removeChannel(channel);
176
+ }
177
+ /**
178
+ * Shortcut: remove all realtime channels and unsubscribe.
179
+ * Equivalent to `aura.realtime.removeAllChannels()`.
180
+ */
181
+ removeAllChannels() {
182
+ return this.realtime.removeAllChannels();
183
+ }
184
+ /**
185
+ * Shortcut: list all active realtime channels.
186
+ * Equivalent to `aura.realtime.getChannels()`.
187
+ */
188
+ getChannels() {
189
+ return this.realtime.getChannels();
190
+ }
158
191
  };
159
- function createClient(baseUrl, projectId, apiKeyOrOptions, options) {
160
- return new AuraClient(baseUrl, projectId, apiKeyOrOptions, options);
192
+
193
+ // src/index.ts
194
+ function createClient(baseUrl, apiKey, options) {
195
+ return new AuraClient(baseUrl, apiKey, options);
161
196
  }
162
- function createAdminClient(baseUrl, projectId, serviceRoleKey, options) {
197
+ function createAdminClient(baseUrl, serviceRoleKey, options) {
163
198
  if (isBrowserContext()) {
164
199
  throw new Error(
165
200
  "[aurabase] createAdminClient() ne doit jamais \xEAtre appel\xE9 c\xF4t\xE9 navigateur : la cl\xE9 service_role serait expos\xE9e dans le bundle. \xC0 utiliser uniquement c\xF4t\xE9 serveur."
166
201
  );
167
202
  }
168
- return new AuraClient(baseUrl, projectId, serviceRoleKey, options);
203
+ return new AuraClient(baseUrl, serviceRoleKey, options);
169
204
  }
170
205
 
171
- Object.defineProperty(exports, "AuraError", {
172
- enumerable: true,
173
- get: function () { return core.AuraError; }
174
- });
175
- Object.defineProperty(exports, "BaseAuthStore", {
176
- enumerable: true,
177
- get: function () { return core.BaseAuthStore; }
178
- });
179
- Object.defineProperty(exports, "LocalAuthStore", {
180
- enumerable: true,
181
- get: function () { return core.LocalAuthStore; }
182
- });
183
- Object.defineProperty(exports, "isAuraError", {
206
+ Object.defineProperty(exports, "AiService", {
184
207
  enumerable: true,
185
- get: function () { return core.isAuraError; }
208
+ get: function () { return ai.AiService; }
186
209
  });
187
210
  Object.defineProperty(exports, "AuthAdminService", {
188
211
  enumerable: true,
@@ -196,33 +219,33 @@ Object.defineProperty(exports, "isMfaChallenge", {
196
219
  enumerable: true,
197
220
  get: function () { return auth.isMfaChallenge; }
198
221
  });
199
- Object.defineProperty(exports, "DatabaseService", {
222
+ Object.defineProperty(exports, "AuraError", {
200
223
  enumerable: true,
201
- get: function () { return db.DatabaseService; }
224
+ get: function () { return core.AuraError; }
202
225
  });
203
- Object.defineProperty(exports, "QueryBuilder", {
226
+ Object.defineProperty(exports, "BaseAuthStore", {
204
227
  enumerable: true,
205
- get: function () { return db.QueryBuilder; }
228
+ get: function () { return core.BaseAuthStore; }
206
229
  });
207
- Object.defineProperty(exports, "StorageService", {
230
+ Object.defineProperty(exports, "LocalAuthStore", {
208
231
  enumerable: true,
209
- get: function () { return storage.StorageService; }
232
+ get: function () { return core.LocalAuthStore; }
210
233
  });
211
- Object.defineProperty(exports, "AuraChannel", {
234
+ Object.defineProperty(exports, "isAuraError", {
212
235
  enumerable: true,
213
- get: function () { return realtime.AuraChannel; }
236
+ get: function () { return core.isAuraError; }
214
237
  });
215
- Object.defineProperty(exports, "RealtimeService", {
238
+ Object.defineProperty(exports, "DatabaseService", {
216
239
  enumerable: true,
217
- get: function () { return realtime.RealtimeService; }
240
+ get: function () { return db.DatabaseService; }
218
241
  });
219
- Object.defineProperty(exports, "FunctionsService", {
242
+ Object.defineProperty(exports, "QueryBuilder", {
220
243
  enumerable: true,
221
- get: function () { return functions.FunctionsService; }
244
+ get: function () { return db.QueryBuilder; }
222
245
  });
223
- Object.defineProperty(exports, "AiService", {
246
+ Object.defineProperty(exports, "FunctionsService", {
224
247
  enumerable: true,
225
- get: function () { return ai.AiService; }
248
+ get: function () { return functions.FunctionsService; }
226
249
  });
227
250
  Object.defineProperty(exports, "NotificationsAdminService", {
228
251
  enumerable: true,
@@ -232,6 +255,18 @@ Object.defineProperty(exports, "NotificationsService", {
232
255
  enumerable: true,
233
256
  get: function () { return notifications.NotificationsService; }
234
257
  });
258
+ Object.defineProperty(exports, "AuraChannel", {
259
+ enumerable: true,
260
+ get: function () { return realtime.AuraChannel; }
261
+ });
262
+ Object.defineProperty(exports, "RealtimeService", {
263
+ enumerable: true,
264
+ get: function () { return realtime.RealtimeService; }
265
+ });
266
+ Object.defineProperty(exports, "StorageService", {
267
+ enumerable: true,
268
+ get: function () { return storage.StorageService; }
269
+ });
235
270
  exports.AuraClient = AuraClient;
236
271
  exports.createAdminClient = createAdminClient;
237
272
  exports.createClient = createClient;
package/dist/index.d.cts CHANGED
@@ -1,32 +1,33 @@
1
- import { A as AuraClient } from './AuraClient-BcFE8u1v.cjs';
1
+ export { AiService } from '@aurabase/ai';
2
+ export { AuthAdminService, AuthService, isMfaChallenge } from '@aurabase/auth';
2
3
  import { AuraClientOptions } from '@aurabase/core';
3
- export { AdminCreateUserRequest, AdminUpdateUserRequest, AdminUser, AuditLogEntry, AuraClientOptions, AuraError, AuraErrorCode, AuraObservabilityEvent, AuraResponse, AuthChangePayload, AuthEvent, AuthSettings, BaseAuthStore, BatchSendResponse, BroadcastFilter, BroadcastPayload, ChannelConfig, ChatMessage, ChatResponse, CountMode, CronJob, EmailTemplateUpdate, EmbedRequest, EmbedResponse, FileEntry, FilterOp, FunctionDef, IdentityInfo, Job, LocalAuthStore, LoginResponse, MagicLinkRequest, Meta, MfaChallenge, MfaEnrollResponse, MfaVerifyRequest, Notification, NotificationAttempt, NotificationDeadLetter, NotificationEvent, NotificationProviderLog, NotificationQueueStats, NotificationRule, NotificationSettings, NotificationStats, NotificationTemplate, NotificationTemplatePreview, OAuthSignInOptions, PasswordResetRequest, PostgresChangesFilter, PresenceFilter, PresenceInfo, PresenceState, QueryFilter, QueryOptions, RagIngestRequest, RagIngestResponse, RagRequest, RagResponse, RealtimeEvent, RealtimeListenType, RealtimeSubscribeStatus, SchemaColumn, SchemaTable, SemanticSearchResult, SendNotificationRequest, SessionInfo, SignInRequest, SignUpRequest, StorageBucket, TokenPair, UpdateUserRequest, UploadResult, User, isAuraError } from '@aurabase/core';
4
+ export { AdminCreateUserRequest, AdminUpdateUserRequest, AdminUser, AuditLogEntry, AuraClientOptions, AuraError, AuraErrorCode, AuraObservabilityEvent, AuraResponse, AuthChangePayload, AuthEvent, AuthSettings, AuthSettingsUpdate, BaseAuthStore, BatchSendResponse, BroadcastFilter, BroadcastPayload, BroadcastSendStatus, ChannelConfig, ChatMessage, ChatResponse, CountMode, CreatePgFunctionRequest, CreatePgTriggerRequest, CronJob, EmailTemplateUpdate, EmbedRequest, EmbedResponse, FileEntry, FilterOp, FunctionDef, IdentityInfo, Job, LocalAuthStore, LoginResponse, MagicLinkRequest, Meta, MfaChallenge, MfaEnrollResponse, MfaVerifyRequest, Notification, NotificationAttempt, NotificationDeadLetter, NotificationEvent, NotificationProviderLog, NotificationQueueStats, NotificationRule, NotificationSettings, NotificationStats, NotificationTemplate, NotificationTemplatePreview, OAuthProviderSetting, OAuthSignInOptions, PasswordResetRequest, PgExecutableRole, PgFunctionInfo, PgTriggerInfo, PostgresChangesFilter, PresenceFilter, PresenceInfo, PresenceState, QueryFilter, QueryOptions, RagIngestRequest, RagIngestResponse, RagRequest, RagResponse, RealtimeEvent, RealtimeListenType, RealtimeSubscribeStatus, SchemaColumn, SchemaEnum, SchemaFunction, SchemaFunctionArg, SchemaTable, SemanticSearchResult, SendNotificationRequest, SessionInfo, SignInRequest, SignUpRequest, StorageBucket, TokenPair, UpdateUserRequest, UploadResult, User, isAuraError } from '@aurabase/core';
4
5
  export { DatabaseService, QueryBuilder } from '@aurabase/db';
5
- export { AuthAdminService, AuthService, isMfaChallenge } from '@aurabase/auth';
6
- export { StorageService } from '@aurabase/storage';
7
- export { AuraChannel, RealtimeService } from '@aurabase/realtime';
8
6
  export { FunctionsService } from '@aurabase/functions';
9
- export { AiService } from '@aurabase/ai';
10
7
  export { NotificationsAdminService, NotificationsService } from '@aurabase/notifications';
8
+ export { AuraChannel, RealtimeService } from '@aurabase/realtime';
9
+ export { StorageService } from '@aurabase/storage';
10
+ import { A as AuraClient } from './AuraClient-DL7mqfNu.cjs';
11
11
 
12
12
  /**
13
13
  * Create a new Aurabase client instance.
14
14
  *
15
+ * **L'URL est le projet.** Chaque projet est servi sur son propre sous-domaine
16
+ * (`https://<slug>.aurabase.cloud`) : la passerelle résout le tenant depuis l'hôte et
17
+ * injecte elle-même le `project_id` dans le chemin. Aucun identifiant de projet ne figure
18
+ * donc dans le code client — l'URL de connexion du projet suffit, avec sa clé.
19
+ *
15
20
  * @example
16
21
  * ```ts
17
- * // With API key (recommended — like Supabase)
18
- * const aura = createClient('http://localhost:8080', 'project-uuid', 'aura_anon_xxx')
22
+ * const aura = createClient('https://mon-projet.aurabase.cloud', 'aura_anon_xxx')
19
23
  *
20
- * // With options
21
- * const aura = createClient('http://localhost:8080', 'project-uuid', 'aura_anon_xxx', {
24
+ * // Avec options
25
+ * const aura = createClient('https://mon-projet.aurabase.cloud', 'aura_anon_xxx', {
22
26
  * auth: { persistSession: true }
23
27
  * })
24
- *
25
- * // Without API key (backward compatible)
26
- * const aura = createClient('http://localhost:8080', 'project-uuid')
27
28
  * ```
28
29
  */
29
- declare function createClient<Database = any>(baseUrl: string, projectId: string, apiKeyOrOptions?: string | AuraClientOptions, options?: AuraClientOptions): AuraClient<Database>;
30
+ declare function createClient<Database = any>(baseUrl: string, apiKey: string, options?: AuraClientOptions): AuraClient<Database>;
30
31
  /**
31
32
  * Crée un client à usage **SERVEUR uniquement** pour les opérations d'administration
32
33
  * (`client.authAdmin` : lister/créer/bannir des utilisateurs, lire l'audit). Exige une
@@ -37,10 +38,10 @@ declare function createClient<Database = any>(baseUrl: string, projectId: string
37
38
  * @example
38
39
  * ```ts
39
40
  * // server-side only (API route, edge function, backend)
40
- * const admin = createAdminClient(url, projectId, process.env.SERVICE_ROLE_KEY!)
41
+ * const admin = createAdminClient(projectUrl, process.env.SERVICE_ROLE_KEY!)
41
42
  * await admin.authAdmin.listUsers()
42
43
  * ```
43
44
  */
44
- declare function createAdminClient<Database = any>(baseUrl: string, projectId: string, serviceRoleKey: string, options?: AuraClientOptions): AuraClient<Database>;
45
+ declare function createAdminClient<Database = any>(baseUrl: string, serviceRoleKey: string, options?: AuraClientOptions): AuraClient<Database>;
45
46
 
46
47
  export { AuraClient, createAdminClient, createClient };
package/dist/index.d.ts CHANGED
@@ -1,32 +1,33 @@
1
- import { A as AuraClient } from './AuraClient-BcFE8u1v.js';
1
+ export { AiService } from '@aurabase/ai';
2
+ export { AuthAdminService, AuthService, isMfaChallenge } from '@aurabase/auth';
2
3
  import { AuraClientOptions } from '@aurabase/core';
3
- export { AdminCreateUserRequest, AdminUpdateUserRequest, AdminUser, AuditLogEntry, AuraClientOptions, AuraError, AuraErrorCode, AuraObservabilityEvent, AuraResponse, AuthChangePayload, AuthEvent, AuthSettings, BaseAuthStore, BatchSendResponse, BroadcastFilter, BroadcastPayload, ChannelConfig, ChatMessage, ChatResponse, CountMode, CronJob, EmailTemplateUpdate, EmbedRequest, EmbedResponse, FileEntry, FilterOp, FunctionDef, IdentityInfo, Job, LocalAuthStore, LoginResponse, MagicLinkRequest, Meta, MfaChallenge, MfaEnrollResponse, MfaVerifyRequest, Notification, NotificationAttempt, NotificationDeadLetter, NotificationEvent, NotificationProviderLog, NotificationQueueStats, NotificationRule, NotificationSettings, NotificationStats, NotificationTemplate, NotificationTemplatePreview, OAuthSignInOptions, PasswordResetRequest, PostgresChangesFilter, PresenceFilter, PresenceInfo, PresenceState, QueryFilter, QueryOptions, RagIngestRequest, RagIngestResponse, RagRequest, RagResponse, RealtimeEvent, RealtimeListenType, RealtimeSubscribeStatus, SchemaColumn, SchemaTable, SemanticSearchResult, SendNotificationRequest, SessionInfo, SignInRequest, SignUpRequest, StorageBucket, TokenPair, UpdateUserRequest, UploadResult, User, isAuraError } from '@aurabase/core';
4
+ export { AdminCreateUserRequest, AdminUpdateUserRequest, AdminUser, AuditLogEntry, AuraClientOptions, AuraError, AuraErrorCode, AuraObservabilityEvent, AuraResponse, AuthChangePayload, AuthEvent, AuthSettings, AuthSettingsUpdate, BaseAuthStore, BatchSendResponse, BroadcastFilter, BroadcastPayload, BroadcastSendStatus, ChannelConfig, ChatMessage, ChatResponse, CountMode, CreatePgFunctionRequest, CreatePgTriggerRequest, CronJob, EmailTemplateUpdate, EmbedRequest, EmbedResponse, FileEntry, FilterOp, FunctionDef, IdentityInfo, Job, LocalAuthStore, LoginResponse, MagicLinkRequest, Meta, MfaChallenge, MfaEnrollResponse, MfaVerifyRequest, Notification, NotificationAttempt, NotificationDeadLetter, NotificationEvent, NotificationProviderLog, NotificationQueueStats, NotificationRule, NotificationSettings, NotificationStats, NotificationTemplate, NotificationTemplatePreview, OAuthProviderSetting, OAuthSignInOptions, PasswordResetRequest, PgExecutableRole, PgFunctionInfo, PgTriggerInfo, PostgresChangesFilter, PresenceFilter, PresenceInfo, PresenceState, QueryFilter, QueryOptions, RagIngestRequest, RagIngestResponse, RagRequest, RagResponse, RealtimeEvent, RealtimeListenType, RealtimeSubscribeStatus, SchemaColumn, SchemaEnum, SchemaFunction, SchemaFunctionArg, SchemaTable, SemanticSearchResult, SendNotificationRequest, SessionInfo, SignInRequest, SignUpRequest, StorageBucket, TokenPair, UpdateUserRequest, UploadResult, User, isAuraError } from '@aurabase/core';
4
5
  export { DatabaseService, QueryBuilder } from '@aurabase/db';
5
- export { AuthAdminService, AuthService, isMfaChallenge } from '@aurabase/auth';
6
- export { StorageService } from '@aurabase/storage';
7
- export { AuraChannel, RealtimeService } from '@aurabase/realtime';
8
6
  export { FunctionsService } from '@aurabase/functions';
9
- export { AiService } from '@aurabase/ai';
10
7
  export { NotificationsAdminService, NotificationsService } from '@aurabase/notifications';
8
+ export { AuraChannel, RealtimeService } from '@aurabase/realtime';
9
+ export { StorageService } from '@aurabase/storage';
10
+ import { A as AuraClient } from './AuraClient-DL7mqfNu.js';
11
11
 
12
12
  /**
13
13
  * Create a new Aurabase client instance.
14
14
  *
15
+ * **L'URL est le projet.** Chaque projet est servi sur son propre sous-domaine
16
+ * (`https://<slug>.aurabase.cloud`) : la passerelle résout le tenant depuis l'hôte et
17
+ * injecte elle-même le `project_id` dans le chemin. Aucun identifiant de projet ne figure
18
+ * donc dans le code client — l'URL de connexion du projet suffit, avec sa clé.
19
+ *
15
20
  * @example
16
21
  * ```ts
17
- * // With API key (recommended — like Supabase)
18
- * const aura = createClient('http://localhost:8080', 'project-uuid', 'aura_anon_xxx')
22
+ * const aura = createClient('https://mon-projet.aurabase.cloud', 'aura_anon_xxx')
19
23
  *
20
- * // With options
21
- * const aura = createClient('http://localhost:8080', 'project-uuid', 'aura_anon_xxx', {
24
+ * // Avec options
25
+ * const aura = createClient('https://mon-projet.aurabase.cloud', 'aura_anon_xxx', {
22
26
  * auth: { persistSession: true }
23
27
  * })
24
- *
25
- * // Without API key (backward compatible)
26
- * const aura = createClient('http://localhost:8080', 'project-uuid')
27
28
  * ```
28
29
  */
29
- declare function createClient<Database = any>(baseUrl: string, projectId: string, apiKeyOrOptions?: string | AuraClientOptions, options?: AuraClientOptions): AuraClient<Database>;
30
+ declare function createClient<Database = any>(baseUrl: string, apiKey: string, options?: AuraClientOptions): AuraClient<Database>;
30
31
  /**
31
32
  * Crée un client à usage **SERVEUR uniquement** pour les opérations d'administration
32
33
  * (`client.authAdmin` : lister/créer/bannir des utilisateurs, lire l'audit). Exige une
@@ -37,10 +38,10 @@ declare function createClient<Database = any>(baseUrl: string, projectId: string
37
38
  * @example
38
39
  * ```ts
39
40
  * // server-side only (API route, edge function, backend)
40
- * const admin = createAdminClient(url, projectId, process.env.SERVICE_ROLE_KEY!)
41
+ * const admin = createAdminClient(projectUrl, process.env.SERVICE_ROLE_KEY!)
41
42
  * await admin.authAdmin.listUsers()
42
43
  * ```
43
44
  */
44
- declare function createAdminClient<Database = any>(baseUrl: string, projectId: string, serviceRoleKey: string, options?: AuraClientOptions): AuraClient<Database>;
45
+ declare function createAdminClient<Database = any>(baseUrl: string, serviceRoleKey: string, options?: AuraClientOptions): AuraClient<Database>;
45
46
 
46
47
  export { AuraClient, createAdminClient, createClient };
package/dist/index.js CHANGED
@@ -1,21 +1,21 @@
1
- import { DEFAULT_MAX_RETRIES, BaseAuthStore, LocalAuthStore } from '@aurabase/core';
2
- export { AuraError, BaseAuthStore, LocalAuthStore, isAuraError } from '@aurabase/core';
1
+ import { AiService } from '@aurabase/ai';
2
+ export { AiService } from '@aurabase/ai';
3
3
  import { AuthService, AuthAdminService } from '@aurabase/auth';
4
4
  export { AuthAdminService, AuthService, isMfaChallenge } from '@aurabase/auth';
5
+ import { DEFAULT_MAX_RETRIES, BaseAuthStore, LocalAuthStore, clientScope } from '@aurabase/core';
6
+ export { AuraError, BaseAuthStore, LocalAuthStore, isAuraError } from '@aurabase/core';
5
7
  import { DatabaseService } from '@aurabase/db';
6
8
  export { DatabaseService, QueryBuilder } from '@aurabase/db';
7
- import { StorageService } from '@aurabase/storage';
8
- export { StorageService } from '@aurabase/storage';
9
- import { RealtimeService } from '@aurabase/realtime';
10
- export { AuraChannel, RealtimeService } from '@aurabase/realtime';
11
9
  import { FunctionsService } from '@aurabase/functions';
12
10
  export { FunctionsService } from '@aurabase/functions';
13
- import { AiService } from '@aurabase/ai';
14
- export { AiService } from '@aurabase/ai';
15
11
  import { NotificationsService } from '@aurabase/notifications';
16
12
  export { NotificationsAdminService, NotificationsService } from '@aurabase/notifications';
13
+ import { RealtimeService } from '@aurabase/realtime';
14
+ export { AuraChannel, RealtimeService } from '@aurabase/realtime';
15
+ import { StorageService } from '@aurabase/storage';
16
+ export { StorageService } from '@aurabase/storage';
17
17
 
18
- // src/AuraClient.ts
18
+ // src/index.ts
19
19
  function isBrowserContext() {
20
20
  if (typeof window !== "undefined") return true;
21
21
  const g = globalThis;
@@ -25,8 +25,8 @@ function isBrowserContext() {
25
25
  }
26
26
  var SERVICE_ROLE_KEY_PREFIX = "aura_sk_";
27
27
  var AuraClient = class {
28
+ /** URL du projet (`https://<slug>.aurabase.cloud`), sans barre finale. */
28
29
  baseUrl;
29
- projectId;
30
30
  apiKey;
31
31
  fetchFn;
32
32
  authStore;
@@ -50,11 +50,14 @@ var AuraClient = class {
50
50
  _persistSession;
51
51
  _autoRefresh;
52
52
  _detectSessionInUrl;
53
- constructor(baseUrl, projectId, apiKeyOrOptions, options) {
53
+ /**
54
+ * @param baseUrl URL du projet (`https://<slug>.aurabase.cloud`).
55
+ * @param apiKey Clé API du projet (`aura_anon_…`, `aura_auth_…`, `aura_sk_…`).
56
+ */
57
+ constructor(baseUrl, apiKey, options) {
54
58
  this.baseUrl = baseUrl.replace(/\/+$/, "");
55
- this.projectId = projectId;
56
- const resolvedOptions = typeof apiKeyOrOptions === "string" ? options : apiKeyOrOptions;
57
- this.apiKey = typeof apiKeyOrOptions === "string" ? apiKeyOrOptions : apiKeyOrOptions?.apiKey ?? null;
59
+ const resolvedOptions = options;
60
+ this.apiKey = apiKey || null;
58
61
  this.fetchFn = resolvedOptions?.fetch ?? globalThis.fetch.bind(globalThis);
59
62
  const r = resolvedOptions?.retry;
60
63
  this.retryConfig = r === false ? { enabled: false, maxRetries: 0 } : r === void 0 || r === true ? { enabled: true, maxRetries: DEFAULT_MAX_RETRIES } : { enabled: r.enabled ?? true, maxRetries: r.maxRetries ?? DEFAULT_MAX_RETRIES };
@@ -80,7 +83,7 @@ var AuraClient = class {
80
83
  } else if (resolvedOptions?.auth?.persistSession === false) {
81
84
  this.authStore = new BaseAuthStore();
82
85
  } else if (typeof localStorage !== "undefined") {
83
- this.authStore = new LocalAuthStore();
86
+ this.authStore = new LocalAuthStore(`aura-${clientScope(this.baseUrl)}-auth`);
84
87
  } else {
85
88
  this.authStore = new BaseAuthStore();
86
89
  }
@@ -111,6 +114,15 @@ var AuraClient = class {
111
114
  persistSession: this._persistSession,
112
115
  detectSessionInUrl: this._detectSessionInUrl
113
116
  });
117
+ this._auth.onAuthStateChange(({ event, accessToken }) => {
118
+ if (this._realtime) {
119
+ if (accessToken) {
120
+ this._realtime.setAuth(accessToken);
121
+ } else if (event === "SIGNED_OUT") {
122
+ this._realtime.setAuth("");
123
+ }
124
+ }
125
+ });
114
126
  }
115
127
  return this._auth;
116
128
  }
@@ -161,17 +173,40 @@ var AuraClient = class {
161
173
  channel(name, options) {
162
174
  return this.realtime.channel(name, options);
163
175
  }
176
+ /**
177
+ * Shortcut: remove a realtime channel by name or AuraChannel instance.
178
+ * Equivalent to `aura.realtime.removeChannel(channel)`.
179
+ */
180
+ removeChannel(channel) {
181
+ return this.realtime.removeChannel(channel);
182
+ }
183
+ /**
184
+ * Shortcut: remove all realtime channels and unsubscribe.
185
+ * Equivalent to `aura.realtime.removeAllChannels()`.
186
+ */
187
+ removeAllChannels() {
188
+ return this.realtime.removeAllChannels();
189
+ }
190
+ /**
191
+ * Shortcut: list all active realtime channels.
192
+ * Equivalent to `aura.realtime.getChannels()`.
193
+ */
194
+ getChannels() {
195
+ return this.realtime.getChannels();
196
+ }
164
197
  };
165
- function createClient(baseUrl, projectId, apiKeyOrOptions, options) {
166
- return new AuraClient(baseUrl, projectId, apiKeyOrOptions, options);
198
+
199
+ // src/index.ts
200
+ function createClient(baseUrl, apiKey, options) {
201
+ return new AuraClient(baseUrl, apiKey, options);
167
202
  }
168
- function createAdminClient(baseUrl, projectId, serviceRoleKey, options) {
203
+ function createAdminClient(baseUrl, serviceRoleKey, options) {
169
204
  if (isBrowserContext()) {
170
205
  throw new Error(
171
206
  "[aurabase] createAdminClient() ne doit jamais \xEAtre appel\xE9 c\xF4t\xE9 navigateur : la cl\xE9 service_role serait expos\xE9e dans le bundle. \xC0 utiliser uniquement c\xF4t\xE9 serveur."
172
207
  );
173
208
  }
174
- return new AuraClient(baseUrl, projectId, serviceRoleKey, options);
209
+ return new AuraClient(baseUrl, serviceRoleKey, options);
175
210
  }
176
211
 
177
212
  export { AuraClient, createAdminClient, createClient };
package/dist/ssr.cjs CHANGED
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@aurabase/core');
4
+ var ai = require('@aurabase/ai');
4
5
  var auth = require('@aurabase/auth');
5
6
  var db = require('@aurabase/db');
6
- var storage = require('@aurabase/storage');
7
- var realtime = require('@aurabase/realtime');
8
7
  var functions = require('@aurabase/functions');
9
- var ai = require('@aurabase/ai');
10
8
  var notifications = require('@aurabase/notifications');
9
+ var realtime = require('@aurabase/realtime');
10
+ var storage = require('@aurabase/storage');
11
11
 
12
- // src/AuraClient.ts
12
+ // src/ssr.ts
13
13
  function isBrowserContext() {
14
14
  if (typeof window !== "undefined") return true;
15
15
  const g = globalThis;
@@ -19,8 +19,8 @@ function isBrowserContext() {
19
19
  }
20
20
  var SERVICE_ROLE_KEY_PREFIX = "aura_sk_";
21
21
  var AuraClient = class {
22
+ /** URL du projet (`https://<slug>.aurabase.cloud`), sans barre finale. */
22
23
  baseUrl;
23
- projectId;
24
24
  apiKey;
25
25
  fetchFn;
26
26
  authStore;
@@ -44,11 +44,14 @@ var AuraClient = class {
44
44
  _persistSession;
45
45
  _autoRefresh;
46
46
  _detectSessionInUrl;
47
- constructor(baseUrl, projectId, apiKeyOrOptions, options) {
47
+ /**
48
+ * @param baseUrl URL du projet (`https://<slug>.aurabase.cloud`).
49
+ * @param apiKey Clé API du projet (`aura_anon_…`, `aura_auth_…`, `aura_sk_…`).
50
+ */
51
+ constructor(baseUrl, apiKey, options) {
48
52
  this.baseUrl = baseUrl.replace(/\/+$/, "");
49
- this.projectId = projectId;
50
- const resolvedOptions = typeof apiKeyOrOptions === "string" ? options : apiKeyOrOptions;
51
- this.apiKey = typeof apiKeyOrOptions === "string" ? apiKeyOrOptions : apiKeyOrOptions?.apiKey ?? null;
53
+ const resolvedOptions = options;
54
+ this.apiKey = apiKey || null;
52
55
  this.fetchFn = resolvedOptions?.fetch ?? globalThis.fetch.bind(globalThis);
53
56
  const r = resolvedOptions?.retry;
54
57
  this.retryConfig = r === false ? { enabled: false, maxRetries: 0 } : r === void 0 || r === true ? { enabled: true, maxRetries: core.DEFAULT_MAX_RETRIES } : { enabled: r.enabled ?? true, maxRetries: r.maxRetries ?? core.DEFAULT_MAX_RETRIES };
@@ -74,7 +77,7 @@ var AuraClient = class {
74
77
  } else if (resolvedOptions?.auth?.persistSession === false) {
75
78
  this.authStore = new core.BaseAuthStore();
76
79
  } else if (typeof localStorage !== "undefined") {
77
- this.authStore = new core.LocalAuthStore();
80
+ this.authStore = new core.LocalAuthStore(`aura-${core.clientScope(this.baseUrl)}-auth`);
78
81
  } else {
79
82
  this.authStore = new core.BaseAuthStore();
80
83
  }
@@ -105,6 +108,15 @@ var AuraClient = class {
105
108
  persistSession: this._persistSession,
106
109
  detectSessionInUrl: this._detectSessionInUrl
107
110
  });
111
+ this._auth.onAuthStateChange(({ event, accessToken }) => {
112
+ if (this._realtime) {
113
+ if (accessToken) {
114
+ this._realtime.setAuth(accessToken);
115
+ } else if (event === "SIGNED_OUT") {
116
+ this._realtime.setAuth("");
117
+ }
118
+ }
119
+ });
108
120
  }
109
121
  return this._auth;
110
122
  }
@@ -155,10 +167,31 @@ var AuraClient = class {
155
167
  channel(name, options) {
156
168
  return this.realtime.channel(name, options);
157
169
  }
170
+ /**
171
+ * Shortcut: remove a realtime channel by name or AuraChannel instance.
172
+ * Equivalent to `aura.realtime.removeChannel(channel)`.
173
+ */
174
+ removeChannel(channel) {
175
+ return this.realtime.removeChannel(channel);
176
+ }
177
+ /**
178
+ * Shortcut: remove all realtime channels and unsubscribe.
179
+ * Equivalent to `aura.realtime.removeAllChannels()`.
180
+ */
181
+ removeAllChannels() {
182
+ return this.realtime.removeAllChannels();
183
+ }
184
+ /**
185
+ * Shortcut: list all active realtime channels.
186
+ * Equivalent to `aura.realtime.getChannels()`.
187
+ */
188
+ getChannels() {
189
+ return this.realtime.getChannels();
190
+ }
158
191
  };
159
192
  var MAX_CHUNK_SIZE = 3600;
160
- function createServerClient(baseUrl, projectId, options) {
161
- const cookieName = `aura-${projectId}-auth`;
193
+ function createServerClient(baseUrl, apiKey, options) {
194
+ const cookieName = `aura-${core.clientScope(baseUrl)}-auth`;
162
195
  const store = new core.LocalAuthStore(cookieName);
163
196
  const idxRe = new RegExp(`^${cookieName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\.(\\d+)$`);
164
197
  const incoming = options.cookies.getAll();
@@ -193,7 +226,11 @@ function createServerClient(baseUrl, projectId, options) {
193
226
  let idx = 0;
194
227
  for (let i = 0; i < decoded.length; i += MAX_CHUNK_SIZE, idx++) {
195
228
  const name = `${cookieName}.${idx}`;
196
- toSet.push({ name, value: decoded.slice(i, i + MAX_CHUNK_SIZE), options: defaultCookieOpts });
229
+ toSet.push({
230
+ name,
231
+ value: decoded.slice(i, i + MAX_CHUNK_SIZE),
232
+ options: defaultCookieOpts
233
+ });
197
234
  used.add(name);
198
235
  }
199
236
  }
@@ -204,12 +241,12 @@ function createServerClient(baseUrl, projectId, options) {
204
241
  }
205
242
  if (toSet.length > 0) options.cookies.setAll(toSet);
206
243
  });
207
- return new AuraClient(baseUrl, projectId, options.apiKey, {
244
+ return new AuraClient(baseUrl, apiKey, {
208
245
  auth: { persistSession: false, storage: store }
209
246
  });
210
247
  }
211
- function createBrowserClient(baseUrl, projectId, apiKey, options) {
212
- return new AuraClient(baseUrl, projectId, apiKey, options);
248
+ function createBrowserClient(baseUrl, apiKey, options) {
249
+ return new AuraClient(baseUrl, apiKey, options);
213
250
  }
214
251
 
215
252
  Object.defineProperty(exports, "parseCookieHeader", {
package/dist/ssr.d.cts CHANGED
@@ -1,13 +1,13 @@
1
- import { A as AuraClient } from './AuraClient-BcFE8u1v.cjs';
2
1
  import { SerializeCookieOptions, AuraClientOptions } from '@aurabase/core';
3
2
  export { SerializeCookieOptions, parseCookieHeader, serializeCookieHeader } from '@aurabase/core';
3
+ import { A as AuraClient } from './AuraClient-DL7mqfNu.cjs';
4
+ import '@aurabase/ai';
4
5
  import '@aurabase/auth';
5
6
  import '@aurabase/db';
6
- import '@aurabase/storage';
7
- import '@aurabase/realtime';
8
7
  import '@aurabase/functions';
9
- import '@aurabase/ai';
10
8
  import '@aurabase/notifications';
9
+ import '@aurabase/realtime';
10
+ import '@aurabase/storage';
11
11
 
12
12
  /**
13
13
  * Server-side rendering helpers for Aurabase.
@@ -18,7 +18,7 @@ import '@aurabase/notifications';
18
18
  *
19
19
  * export async function middleware(request) {
20
20
  * let response = NextResponse.next({ request })
21
- * const client = createServerClient(URL, PROJECT_ID, {
21
+ * const client = createServerClient(PROJECT_URL, ANON_KEY, {
22
22
  * cookies: {
23
23
  * getAll: () => request.cookies.getAll(),
24
24
  * setAll: (cookies) => {
@@ -51,15 +51,14 @@ interface CookieHandler {
51
51
  }>): void;
52
52
  }
53
53
  interface ServerClientOptions {
54
- apiKey?: string;
55
54
  cookies: CookieHandler;
56
55
  cookieOptions?: SerializeCookieOptions;
57
56
  }
58
- declare function createServerClient<Database = any>(baseUrl: string, projectId: string, options: ServerClientOptions): AuraClient<Database>;
57
+ declare function createServerClient<Database = any>(baseUrl: string, apiKey: string, options: ServerClientOptions): AuraClient<Database>;
59
58
  /**
60
59
  * Create an Aurabase client for browser usage.
61
60
  * Thin wrapper around AuraClient with sensible browser defaults.
62
61
  */
63
- declare function createBrowserClient<Database = any>(baseUrl: string, projectId: string, apiKey?: string, options?: AuraClientOptions): AuraClient<Database>;
62
+ declare function createBrowserClient<Database = any>(baseUrl: string, apiKey: string, options?: AuraClientOptions): AuraClient<Database>;
64
63
 
65
64
  export { type CookieHandler, type ServerClientOptions, createBrowserClient, createServerClient };
package/dist/ssr.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { A as AuraClient } from './AuraClient-BcFE8u1v.js';
2
1
  import { SerializeCookieOptions, AuraClientOptions } from '@aurabase/core';
3
2
  export { SerializeCookieOptions, parseCookieHeader, serializeCookieHeader } from '@aurabase/core';
3
+ import { A as AuraClient } from './AuraClient-DL7mqfNu.js';
4
+ import '@aurabase/ai';
4
5
  import '@aurabase/auth';
5
6
  import '@aurabase/db';
6
- import '@aurabase/storage';
7
- import '@aurabase/realtime';
8
7
  import '@aurabase/functions';
9
- import '@aurabase/ai';
10
8
  import '@aurabase/notifications';
9
+ import '@aurabase/realtime';
10
+ import '@aurabase/storage';
11
11
 
12
12
  /**
13
13
  * Server-side rendering helpers for Aurabase.
@@ -18,7 +18,7 @@ import '@aurabase/notifications';
18
18
  *
19
19
  * export async function middleware(request) {
20
20
  * let response = NextResponse.next({ request })
21
- * const client = createServerClient(URL, PROJECT_ID, {
21
+ * const client = createServerClient(PROJECT_URL, ANON_KEY, {
22
22
  * cookies: {
23
23
  * getAll: () => request.cookies.getAll(),
24
24
  * setAll: (cookies) => {
@@ -51,15 +51,14 @@ interface CookieHandler {
51
51
  }>): void;
52
52
  }
53
53
  interface ServerClientOptions {
54
- apiKey?: string;
55
54
  cookies: CookieHandler;
56
55
  cookieOptions?: SerializeCookieOptions;
57
56
  }
58
- declare function createServerClient<Database = any>(baseUrl: string, projectId: string, options: ServerClientOptions): AuraClient<Database>;
57
+ declare function createServerClient<Database = any>(baseUrl: string, apiKey: string, options: ServerClientOptions): AuraClient<Database>;
59
58
  /**
60
59
  * Create an Aurabase client for browser usage.
61
60
  * Thin wrapper around AuraClient with sensible browser defaults.
62
61
  */
63
- declare function createBrowserClient<Database = any>(baseUrl: string, projectId: string, apiKey?: string, options?: AuraClientOptions): AuraClient<Database>;
62
+ declare function createBrowserClient<Database = any>(baseUrl: string, apiKey: string, options?: AuraClientOptions): AuraClient<Database>;
64
63
 
65
64
  export { type CookieHandler, type ServerClientOptions, createBrowserClient, createServerClient };
package/dist/ssr.js CHANGED
@@ -1,14 +1,14 @@
1
- import { LocalAuthStore, DEFAULT_MAX_RETRIES, BaseAuthStore } from '@aurabase/core';
1
+ import { clientScope, LocalAuthStore, DEFAULT_MAX_RETRIES, BaseAuthStore } from '@aurabase/core';
2
2
  export { parseCookieHeader, serializeCookieHeader } from '@aurabase/core';
3
+ import { AiService } from '@aurabase/ai';
3
4
  import { AuthService, AuthAdminService } from '@aurabase/auth';
4
5
  import { DatabaseService } from '@aurabase/db';
5
- import { StorageService } from '@aurabase/storage';
6
- import { RealtimeService } from '@aurabase/realtime';
7
6
  import { FunctionsService } from '@aurabase/functions';
8
- import { AiService } from '@aurabase/ai';
9
7
  import { NotificationsService } from '@aurabase/notifications';
8
+ import { RealtimeService } from '@aurabase/realtime';
9
+ import { StorageService } from '@aurabase/storage';
10
10
 
11
- // src/AuraClient.ts
11
+ // src/ssr.ts
12
12
  function isBrowserContext() {
13
13
  if (typeof window !== "undefined") return true;
14
14
  const g = globalThis;
@@ -18,8 +18,8 @@ function isBrowserContext() {
18
18
  }
19
19
  var SERVICE_ROLE_KEY_PREFIX = "aura_sk_";
20
20
  var AuraClient = class {
21
+ /** URL du projet (`https://<slug>.aurabase.cloud`), sans barre finale. */
21
22
  baseUrl;
22
- projectId;
23
23
  apiKey;
24
24
  fetchFn;
25
25
  authStore;
@@ -43,11 +43,14 @@ var AuraClient = class {
43
43
  _persistSession;
44
44
  _autoRefresh;
45
45
  _detectSessionInUrl;
46
- constructor(baseUrl, projectId, apiKeyOrOptions, options) {
46
+ /**
47
+ * @param baseUrl URL du projet (`https://<slug>.aurabase.cloud`).
48
+ * @param apiKey Clé API du projet (`aura_anon_…`, `aura_auth_…`, `aura_sk_…`).
49
+ */
50
+ constructor(baseUrl, apiKey, options) {
47
51
  this.baseUrl = baseUrl.replace(/\/+$/, "");
48
- this.projectId = projectId;
49
- const resolvedOptions = typeof apiKeyOrOptions === "string" ? options : apiKeyOrOptions;
50
- this.apiKey = typeof apiKeyOrOptions === "string" ? apiKeyOrOptions : apiKeyOrOptions?.apiKey ?? null;
52
+ const resolvedOptions = options;
53
+ this.apiKey = apiKey || null;
51
54
  this.fetchFn = resolvedOptions?.fetch ?? globalThis.fetch.bind(globalThis);
52
55
  const r = resolvedOptions?.retry;
53
56
  this.retryConfig = r === false ? { enabled: false, maxRetries: 0 } : r === void 0 || r === true ? { enabled: true, maxRetries: DEFAULT_MAX_RETRIES } : { enabled: r.enabled ?? true, maxRetries: r.maxRetries ?? DEFAULT_MAX_RETRIES };
@@ -73,7 +76,7 @@ var AuraClient = class {
73
76
  } else if (resolvedOptions?.auth?.persistSession === false) {
74
77
  this.authStore = new BaseAuthStore();
75
78
  } else if (typeof localStorage !== "undefined") {
76
- this.authStore = new LocalAuthStore();
79
+ this.authStore = new LocalAuthStore(`aura-${clientScope(this.baseUrl)}-auth`);
77
80
  } else {
78
81
  this.authStore = new BaseAuthStore();
79
82
  }
@@ -104,6 +107,15 @@ var AuraClient = class {
104
107
  persistSession: this._persistSession,
105
108
  detectSessionInUrl: this._detectSessionInUrl
106
109
  });
110
+ this._auth.onAuthStateChange(({ event, accessToken }) => {
111
+ if (this._realtime) {
112
+ if (accessToken) {
113
+ this._realtime.setAuth(accessToken);
114
+ } else if (event === "SIGNED_OUT") {
115
+ this._realtime.setAuth("");
116
+ }
117
+ }
118
+ });
107
119
  }
108
120
  return this._auth;
109
121
  }
@@ -154,10 +166,31 @@ var AuraClient = class {
154
166
  channel(name, options) {
155
167
  return this.realtime.channel(name, options);
156
168
  }
169
+ /**
170
+ * Shortcut: remove a realtime channel by name or AuraChannel instance.
171
+ * Equivalent to `aura.realtime.removeChannel(channel)`.
172
+ */
173
+ removeChannel(channel) {
174
+ return this.realtime.removeChannel(channel);
175
+ }
176
+ /**
177
+ * Shortcut: remove all realtime channels and unsubscribe.
178
+ * Equivalent to `aura.realtime.removeAllChannels()`.
179
+ */
180
+ removeAllChannels() {
181
+ return this.realtime.removeAllChannels();
182
+ }
183
+ /**
184
+ * Shortcut: list all active realtime channels.
185
+ * Equivalent to `aura.realtime.getChannels()`.
186
+ */
187
+ getChannels() {
188
+ return this.realtime.getChannels();
189
+ }
157
190
  };
158
191
  var MAX_CHUNK_SIZE = 3600;
159
- function createServerClient(baseUrl, projectId, options) {
160
- const cookieName = `aura-${projectId}-auth`;
192
+ function createServerClient(baseUrl, apiKey, options) {
193
+ const cookieName = `aura-${clientScope(baseUrl)}-auth`;
161
194
  const store = new LocalAuthStore(cookieName);
162
195
  const idxRe = new RegExp(`^${cookieName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\.(\\d+)$`);
163
196
  const incoming = options.cookies.getAll();
@@ -192,7 +225,11 @@ function createServerClient(baseUrl, projectId, options) {
192
225
  let idx = 0;
193
226
  for (let i = 0; i < decoded.length; i += MAX_CHUNK_SIZE, idx++) {
194
227
  const name = `${cookieName}.${idx}`;
195
- toSet.push({ name, value: decoded.slice(i, i + MAX_CHUNK_SIZE), options: defaultCookieOpts });
228
+ toSet.push({
229
+ name,
230
+ value: decoded.slice(i, i + MAX_CHUNK_SIZE),
231
+ options: defaultCookieOpts
232
+ });
196
233
  used.add(name);
197
234
  }
198
235
  }
@@ -203,12 +240,12 @@ function createServerClient(baseUrl, projectId, options) {
203
240
  }
204
241
  if (toSet.length > 0) options.cookies.setAll(toSet);
205
242
  });
206
- return new AuraClient(baseUrl, projectId, options.apiKey, {
243
+ return new AuraClient(baseUrl, apiKey, {
207
244
  auth: { persistSession: false, storage: store }
208
245
  });
209
246
  }
210
- function createBrowserClient(baseUrl, projectId, apiKey, options) {
211
- return new AuraClient(baseUrl, projectId, apiKey, options);
247
+ function createBrowserClient(baseUrl, apiKey, options) {
248
+ return new AuraClient(baseUrl, apiKey, options);
212
249
  }
213
250
 
214
251
  export { createBrowserClient, createServerClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aurabase/aurabase-js",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Official JavaScript/TypeScript client for Aurabase BaaS",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -44,7 +44,7 @@
44
44
  "url": "git+https://github.com/daylami555/aurabase.git",
45
45
  "directory": "aurabase-js/packages/aurabase"
46
46
  },
47
- "homepage": "https://github.com/daylami555/aurabase/tree/main/aurabase-js/packages/aurabase#readme",
47
+ "homepage": "https://aurabase.cloud",
48
48
  "bugs": {
49
49
  "url": "https://github.com/daylami555/aurabase/issues"
50
50
  },
@@ -55,28 +55,29 @@
55
55
  "sdk",
56
56
  "client"
57
57
  ],
58
- "dependencies": {
59
- "@aurabase/core": "0.4.1",
60
- "@aurabase/auth": "0.4.1",
61
- "@aurabase/realtime": "0.4.1",
62
- "@aurabase/functions": "0.4.1",
63
- "@aurabase/ai": "0.4.1",
64
- "@aurabase/notifications": "0.4.1",
65
- "@aurabase/db": "0.4.1",
66
- "@aurabase/storage": "0.4.1"
67
- },
68
- "devDependencies": {
69
- "@types/node": "20.14.15",
70
- "tsup": "^8.0.0",
71
- "typescript": "^5.5.0",
72
- "vitest": "^4.1.6"
73
- },
74
58
  "scripts": {
75
59
  "build": "tsup",
76
60
  "test": "vitest run && tsc --noEmit -p tsconfig.test-d.json",
77
61
  "test:types": "tsc --noEmit -p tsconfig.test-d.json",
78
62
  "test:e2e": "RUN_E2E=true vitest run --config vitest.e2e.config.ts tests/integration.test.ts",
79
63
  "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
64
+ "prepack": "pnpm build",
80
65
  "typecheck:tests": "tsc --noEmit -p tsconfig.test.json"
66
+ },
67
+ "dependencies": {
68
+ "@aurabase/core": "workspace:*",
69
+ "@aurabase/auth": "workspace:*",
70
+ "@aurabase/db": "workspace:*",
71
+ "@aurabase/storage": "workspace:*",
72
+ "@aurabase/realtime": "workspace:*",
73
+ "@aurabase/functions": "workspace:*",
74
+ "@aurabase/ai": "workspace:*",
75
+ "@aurabase/notifications": "workspace:*"
76
+ },
77
+ "devDependencies": {
78
+ "@types/node": "catalog:",
79
+ "tsup": "catalog:",
80
+ "typescript": "catalog:",
81
+ "vitest": "catalog:"
81
82
  }
82
- }
83
+ }