@aurabase/aurabase-js 0.3.1 → 0.4.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.
Files changed (86) hide show
  1. package/README.md +26 -795
  2. package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.ts → dist/AuraClient-BcFE8u1v.d.cts} +1 -1
  3. package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.cts → dist/AuraClient-BcFE8u1v.d.ts} +1 -1
  4. package/{packages/aurabase/dist → dist}/index.d.cts +1 -1
  5. package/{packages/aurabase/dist → dist}/index.d.ts +1 -1
  6. package/{packages/aurabase/dist → dist}/ssr.d.cts +1 -1
  7. package/{packages/aurabase/dist → dist}/ssr.d.ts +1 -1
  8. package/package.json +72 -82
  9. package/.changeset/config.json +0 -11
  10. package/CHANGELOG.md +0 -30
  11. package/packages/ai/LICENSE +0 -21
  12. package/packages/ai/README.md +0 -106
  13. package/packages/ai/dist/index.cjs +0 -229
  14. package/packages/ai/dist/index.d.cts +0 -139
  15. package/packages/ai/dist/index.d.ts +0 -139
  16. package/packages/ai/dist/index.js +0 -226
  17. package/packages/ai/package.json +0 -61
  18. package/packages/aurabase/LICENSE +0 -21
  19. package/packages/aurabase/README.md +0 -64
  20. package/packages/aurabase/package.json +0 -80
  21. package/packages/aurabase/vitest.e2e.config.ts +0 -9
  22. package/packages/auth/LICENSE +0 -21
  23. package/packages/auth/README.md +0 -215
  24. package/packages/auth/dist/index.cjs +0 -1175
  25. package/packages/auth/dist/index.d.cts +0 -397
  26. package/packages/auth/dist/index.d.ts +0 -397
  27. package/packages/auth/dist/index.js +0 -1170
  28. package/packages/auth/package.json +0 -61
  29. package/packages/core/LICENSE +0 -21
  30. package/packages/core/README.md +0 -132
  31. package/packages/core/dist/index.cjs +0 -695
  32. package/packages/core/dist/index.d.cts +0 -1137
  33. package/packages/core/dist/index.d.ts +0 -1137
  34. package/packages/core/dist/index.js +0 -673
  35. package/packages/core/package.json +0 -57
  36. package/packages/db/LICENSE +0 -21
  37. package/packages/db/README.md +0 -152
  38. package/packages/db/VENDORED.md +0 -93
  39. package/packages/db/dist/index.cjs +0 -544
  40. package/packages/db/dist/index.d.cts +0 -1111
  41. package/packages/db/dist/index.d.ts +0 -1111
  42. package/packages/db/dist/index.js +0 -541
  43. package/packages/db/package.json +0 -62
  44. package/packages/functions/LICENSE +0 -21
  45. package/packages/functions/README.md +0 -96
  46. package/packages/functions/dist/index.cjs +0 -173
  47. package/packages/functions/dist/index.d.cts +0 -81
  48. package/packages/functions/dist/index.d.ts +0 -81
  49. package/packages/functions/dist/index.js +0 -168
  50. package/packages/functions/package.json +0 -60
  51. package/packages/gen/LICENSE +0 -21
  52. package/packages/gen/README.md +0 -84
  53. package/packages/gen/dist/cli.cjs +0 -334
  54. package/packages/gen/dist/cli.d.cts +0 -1
  55. package/packages/gen/dist/cli.d.ts +0 -1
  56. package/packages/gen/dist/cli.js +0 -332
  57. package/packages/gen/dist/index.cjs +0 -257
  58. package/packages/gen/dist/index.d.cts +0 -12
  59. package/packages/gen/dist/index.d.ts +0 -12
  60. package/packages/gen/dist/index.js +0 -255
  61. package/packages/gen/package.json +0 -66
  62. package/packages/notifications/LICENSE +0 -21
  63. package/packages/notifications/README.md +0 -134
  64. package/packages/notifications/dist/index.cjs +0 -128
  65. package/packages/notifications/dist/index.d.cts +0 -81
  66. package/packages/notifications/dist/index.d.ts +0 -81
  67. package/packages/notifications/dist/index.js +0 -125
  68. package/packages/notifications/package.json +0 -60
  69. package/packages/realtime/LICENSE +0 -21
  70. package/packages/realtime/README.md +0 -183
  71. package/packages/realtime/dist/index.cjs +0 -977
  72. package/packages/realtime/dist/index.d.cts +0 -259
  73. package/packages/realtime/dist/index.d.ts +0 -259
  74. package/packages/realtime/dist/index.js +0 -973
  75. package/packages/realtime/package.json +0 -60
  76. package/packages/storage/LICENSE +0 -21
  77. package/packages/storage/README.md +0 -141
  78. package/packages/storage/dist/index.cjs +0 -333
  79. package/packages/storage/dist/index.d.cts +0 -185
  80. package/packages/storage/dist/index.d.ts +0 -185
  81. package/packages/storage/dist/index.js +0 -329
  82. package/packages/storage/package.json +0 -60
  83. /package/{packages/aurabase/dist → dist}/index.cjs +0 -0
  84. /package/{packages/aurabase/dist → dist}/index.js +0 -0
  85. /package/{packages/aurabase/dist → dist}/ssr.cjs +0 -0
  86. /package/{packages/aurabase/dist → dist}/ssr.js +0 -0
@@ -1,81 +0,0 @@
1
- import { BaseService, AuraClientLike, AuraResponse, NotificationSettings, NotificationStats, NotificationQueueStats, NotificationAttempt, NotificationDeadLetter, Notification, NotificationEvent, NotificationProviderLog, NotificationTemplatePreview, NotificationRule, SendNotificationRequest, BatchSendResponse, NotificationTemplate } from '@aurabase/core';
2
- export { AuraResponse, BatchSendResponse, Notification, NotificationAttempt, NotificationDeadLetter, NotificationEvent, NotificationProviderLog, NotificationQueueStats, NotificationRule, NotificationSettings, NotificationStats, NotificationTemplate, NotificationTemplatePreview, SendNotificationRequest } from '@aurabase/core';
3
-
4
- type NotificationChannel = 'email' | 'sms' | 'push' | 'webhook';
5
- type NotificationStatus = 'queued' | 'processing' | 'sent' | 'failed' | 'delivered' | 'expired' | 'dead_lettered';
6
- type CreateNotificationRuleRequest = {
7
- name: string;
8
- trigger_type: string;
9
- condition?: Record<string, unknown>;
10
- template_id?: string | null;
11
- channel: NotificationChannel;
12
- recipient_expr: string;
13
- delay_seconds?: number;
14
- };
15
- declare class NotificationsService extends BaseService {
16
- readonly admin: NotificationsAdminService;
17
- constructor(client: AuraClientLike);
18
- private get prefix();
19
- send(channel: NotificationChannel, recipient: string, body: string, options?: {
20
- subject?: string;
21
- templateId?: string;
22
- variables?: Record<string, unknown>;
23
- metadata?: Record<string, unknown>;
24
- idempotencyKey?: string;
25
- }): Promise<AuraResponse<Notification>>;
26
- sendBatch(items: SendNotificationRequest[]): Promise<AuraResponse<BatchSendResponse>>;
27
- list(options?: {
28
- channel?: NotificationChannel;
29
- status?: NotificationStatus;
30
- search?: string;
31
- sort?: 'created_at' | 'updated_at' | 'status';
32
- order?: 'asc' | 'desc';
33
- limit?: number;
34
- offset?: number;
35
- }): Promise<AuraResponse<Notification[]>>;
36
- get(id: string): Promise<AuraResponse<Notification>>;
37
- listTemplates(): Promise<AuraResponse<NotificationTemplate[]>>;
38
- getTemplate(id: string): Promise<AuraResponse<NotificationTemplate>>;
39
- createTemplate(template: Omit<NotificationTemplate, 'id' | 'created_at' | 'updated_at'>): Promise<AuraResponse<NotificationTemplate>>;
40
- updateTemplate(id: string, updates: Partial<Omit<NotificationTemplate, 'id' | 'created_at' | 'updated_at'>>): Promise<AuraResponse<NotificationTemplate>>;
41
- deleteTemplate(id: string): Promise<AuraResponse<null>>;
42
- }
43
- declare class NotificationsAdminService extends BaseService {
44
- constructor(client: AuraClientLike);
45
- private get prefix();
46
- private query;
47
- getSettings(): Promise<AuraResponse<NotificationSettings>>;
48
- updateSettings(settings: Partial<NotificationSettings>): Promise<AuraResponse<NotificationSettings>>;
49
- getStats(options?: {
50
- window?: string;
51
- channel?: NotificationChannel;
52
- }): Promise<AuraResponse<NotificationStats>>;
53
- getQueue(): Promise<AuraResponse<NotificationQueueStats>>;
54
- listAttempts(notificationId: string): Promise<AuraResponse<NotificationAttempt[]>>;
55
- listDeadLetters(options?: {
56
- channel?: NotificationChannel;
57
- search?: string;
58
- limit?: number;
59
- offset?: number;
60
- }): Promise<AuraResponse<NotificationDeadLetter[]>>;
61
- retryDeadLetter(id: string): Promise<AuraResponse<Notification>>;
62
- listEvents(options?: {
63
- status?: 'received' | 'matched' | 'ignored' | 'failed' | 'enqueued';
64
- limit?: number;
65
- offset?: number;
66
- }): Promise<AuraResponse<NotificationEvent[]>>;
67
- listProviderLogs(options?: {
68
- channel?: NotificationChannel;
69
- status?: string;
70
- limit?: number;
71
- offset?: number;
72
- }): Promise<AuraResponse<NotificationProviderLog[]>>;
73
- previewTemplate(id: string, variables: Record<string, unknown>): Promise<AuraResponse<NotificationTemplatePreview>>;
74
- listRules(): Promise<AuraResponse<NotificationRule[]>>;
75
- createRule(rule: CreateNotificationRuleRequest): Promise<AuraResponse<NotificationRule>>;
76
- getRule(id: string): Promise<AuraResponse<NotificationRule>>;
77
- updateRule(id: string, updates: Partial<Omit<NotificationRule, 'id' | 'project_id' | 'created_at' | 'updated_at'>>): Promise<AuraResponse<NotificationRule>>;
78
- deleteRule(id: string): Promise<AuraResponse<null>>;
79
- }
80
-
81
- export { NotificationsAdminService, NotificationsService };
@@ -1,125 +0,0 @@
1
- import { BaseService } from '@aurabase/core';
2
-
3
- // src/NotificationsService.ts
4
- var NotificationsService = class extends BaseService {
5
- admin;
6
- constructor(client) {
7
- super(client);
8
- this.admin = new NotificationsAdminService(client);
9
- }
10
- get prefix() {
11
- return `/v1/notifications/${this.client.projectId}`;
12
- }
13
- // -- Send -------------------------------------------------------------------
14
- async send(channel, recipient, body, options) {
15
- return this.request("POST", `${this.prefix}/send`, {
16
- channel,
17
- recipient,
18
- body,
19
- subject: options?.subject,
20
- template_id: options?.templateId,
21
- variables: options?.variables,
22
- metadata: options?.metadata,
23
- idempotency_key: options?.idempotencyKey
24
- });
25
- }
26
- async sendBatch(items) {
27
- return this.request("POST", `${this.prefix}/send/batch`, { items });
28
- }
29
- // -- Notification history ---------------------------------------------------
30
- async list(options) {
31
- const params = new URLSearchParams();
32
- if (options?.channel !== void 0) params.set("channel", options.channel);
33
- if (options?.status !== void 0) params.set("status", options.status);
34
- if (options?.search !== void 0) params.set("search", options.search);
35
- if (options?.sort !== void 0) params.set("sort", options.sort);
36
- if (options?.order !== void 0) params.set("order", options.order);
37
- if (options?.limit !== void 0) params.set("limit", String(options.limit));
38
- if (options?.offset !== void 0) params.set("offset", String(options.offset));
39
- const qs = params.toString();
40
- const sep = qs ? "?" : "";
41
- return this.request("GET", `${this.prefix}${sep}${qs}`);
42
- }
43
- async get(id) {
44
- return this.request("GET", `${this.prefix}/${id}`);
45
- }
46
- // -- Templates --------------------------------------------------------------
47
- async listTemplates() {
48
- return this.request("GET", `${this.prefix}/templates`);
49
- }
50
- async getTemplate(id) {
51
- return this.request("GET", `${this.prefix}/templates/${id}`);
52
- }
53
- async createTemplate(template) {
54
- return this.request("POST", `${this.prefix}/templates`, template);
55
- }
56
- async updateTemplate(id, updates) {
57
- return this.request("PATCH", `${this.prefix}/templates/${id}`, updates);
58
- }
59
- async deleteTemplate(id) {
60
- return this.request("DELETE", `${this.prefix}/templates/${id}`);
61
- }
62
- };
63
- var NotificationsAdminService = class extends BaseService {
64
- constructor(client) {
65
- super(client);
66
- }
67
- get prefix() {
68
- return `/v1/notifications/${this.client.projectId}`;
69
- }
70
- query(options) {
71
- const params = new URLSearchParams();
72
- for (const [key, value] of Object.entries(options ?? {})) {
73
- if (value !== void 0 && value !== null && value !== "") params.set(key, String(value));
74
- }
75
- const qs = params.toString();
76
- return qs ? `?${qs}` : "";
77
- }
78
- async getSettings() {
79
- return this.request("GET", `${this.prefix}/settings`);
80
- }
81
- async updateSettings(settings) {
82
- return this.request("PATCH", `${this.prefix}/settings`, settings);
83
- }
84
- async getStats(options) {
85
- return this.request("GET", `${this.prefix}/stats${this.query(options)}`);
86
- }
87
- async getQueue() {
88
- return this.request("GET", `${this.prefix}/queue`);
89
- }
90
- async listAttempts(notificationId) {
91
- return this.request("GET", `${this.prefix}/${notificationId}/attempts`);
92
- }
93
- async listDeadLetters(options) {
94
- return this.request("GET", `${this.prefix}/dead-letters${this.query(options)}`);
95
- }
96
- async retryDeadLetter(id) {
97
- return this.request("POST", `${this.prefix}/dead-letters/${id}/retry`);
98
- }
99
- async listEvents(options) {
100
- return this.request("GET", `${this.prefix}/events${this.query(options)}`);
101
- }
102
- async listProviderLogs(options) {
103
- return this.request("GET", `${this.prefix}/providers/logs${this.query(options)}`);
104
- }
105
- async previewTemplate(id, variables) {
106
- return this.request("POST", `${this.prefix}/templates/${id}/preview`, variables);
107
- }
108
- async listRules() {
109
- return this.request("GET", `${this.prefix}/rules`);
110
- }
111
- async createRule(rule) {
112
- return this.request("POST", `${this.prefix}/rules`, rule);
113
- }
114
- async getRule(id) {
115
- return this.request("GET", `${this.prefix}/rules/${id}`);
116
- }
117
- async updateRule(id, updates) {
118
- return this.request("PATCH", `${this.prefix}/rules/${id}`, updates);
119
- }
120
- async deleteRule(id) {
121
- return this.request("DELETE", `${this.prefix}/rules/${id}`);
122
- }
123
- };
124
-
125
- export { NotificationsAdminService, NotificationsService };
@@ -1,60 +0,0 @@
1
- {
2
- "name": "@aurabase/notifications",
3
- "version": "0.3.0",
4
- "description": "Service notifications multi-canal du SDK Aurabase (email, SMS, push, webhook, templates, règles)",
5
- "type": "module",
6
- "main": "dist/index.cjs",
7
- "module": "dist/index.js",
8
- "types": "dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "import": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/index.js"
14
- },
15
- "require": {
16
- "types": "./dist/index.d.cts",
17
- "default": "./dist/index.cjs"
18
- }
19
- }
20
- },
21
- "sideEffects": false,
22
- "files": [
23
- "dist",
24
- "README.md",
25
- "LICENSE"
26
- ],
27
- "engines": {
28
- "node": ">=20.0.0"
29
- },
30
- "license": "MIT",
31
- "author": "Aurabase",
32
- "repository": {
33
- "type": "git",
34
- "url": "git+https://github.com/daylami555/aurabase.git",
35
- "directory": "aurabase-js/packages/notifications"
36
- },
37
- "homepage": "https://github.com/daylami555/aurabase/tree/main/aurabase-js/packages/notifications#readme",
38
- "bugs": {
39
- "url": "https://github.com/daylami555/aurabase/issues"
40
- },
41
- "keywords": [
42
- "aurabase",
43
- "baas",
44
- "sdk",
45
- "notifications"
46
- ],
47
- "scripts": {
48
- "build": "tsup",
49
- "test": "vitest run --passWithNoTests",
50
- "typecheck": "tsc --noEmit"
51
- },
52
- "dependencies": {
53
- "@aurabase/core": "workspace:*"
54
- },
55
- "devDependencies": {
56
- "tsup": "catalog:",
57
- "typescript": "catalog:",
58
- "vitest": "catalog:"
59
- }
60
- }
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Aurabase
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,183 +0,0 @@
1
- # @aurabase/realtime
2
-
3
- Service temps réel du SDK Aurabase : une connexion WebSocket multiplexée sur des channels (`postgres_changes`, `broadcast`, `presence`).
4
-
5
- ![npm](https://img.shields.io/npm/v/@aurabase/realtime) ![license](https://img.shields.io/badge/license-MIT-blue)
6
-
7
- > Pre-release — pas encore publié sur npm.
8
-
9
- Fait partie du SDK **[aurabase](../aurabase)**. Installé automatiquement avec `aurabase` ; ce package est publié séparément pour un usage ciblé / tree-shaking.
10
-
11
- ## Installation
12
-
13
- ```bash
14
- npm i @aurabase/realtime
15
- ```
16
-
17
- > Dépend de `@aurabase/core`. Déjà inclus si vous utilisez le package `aurabase` — cette installation ciblée sert à composer votre propre client ou à limiter la taille du bundle. Nécessite un runtime avec `WebSocket` global (navigateur, ou Node avec un polyfill).
18
-
19
- ## Usage
20
-
21
- `RealtimeService` est exposé par le client principal sous `aura.realtime`, et `aura.channel(name)` est un raccourci pour `aura.realtime.channel(name)`.
22
-
23
- ```ts
24
- import { createClient } from 'aurabase'
25
-
26
- const aura = createClient('http://localhost:8080', 'my-project', 'aura_anon_xxx')
27
- ```
28
-
29
- ### Connexion
30
-
31
- ```ts
32
- const unsubscribe = aura.realtime.onStateChange((state) => {
33
- console.log('realtime state:', state) // 'disconnected' | 'connecting' | 'connected' | 'reconnecting'
34
- })
35
-
36
- aura.realtime.connect()
37
- console.log(aura.realtime.connectionState)
38
-
39
- // Désactive la reconnexion auto (backoff + jitter), ou borne le nombre de tentatives.
40
- aura.realtime.setAutoReconnect(true, 5)
41
-
42
- // Pousse un nouveau token sur la connexion existante (sans reconnexion).
43
- aura.realtime.refreshToken('new-access-token')
44
- ```
45
-
46
- Un heartbeat applicatif (`ping`) est envoyé toutes les **25 secondes** via un Worker dédié, pour éviter le throttling des timers par les navigateurs en arrière-plan. La reconnexion automatique utilise un backoff exponentiel avec jitter.
47
-
48
- ### `postgres_changes`
49
-
50
- ```ts
51
- const channel = aura.channel('db:public.posts')
52
- .on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'posts' }, (payload) => {
53
- console.log('insert:', payload)
54
- })
55
- .subscribe((status, err) => {
56
- console.log(status, err) // 'SUBSCRIBED' | 'CLOSED' | 'CHANNEL_ERROR' | 'TIMED_OUT'
57
- })
58
- ```
59
-
60
- ## Filtres de colonne (`postgres_changes`)
61
-
62
- `postgres_changes` accepte un champ `filter` (syntaxe PostgREST/Supabase : `"column=operator.value"`) pour ne recevoir que les events dont la ligne matche la condition :
63
-
64
- ```ts
65
- aura.channel('room')
66
- .on('postgres_changes', {
67
- event: 'INSERT',
68
- schema: 'public',
69
- table: 'messages',
70
- filter: 'room_id=eq.42',
71
- }, (e) => console.log(e))
72
- .subscribe()
73
- ```
74
-
75
- Opérateurs supportés : `eq, neq, lt, lte, gt, gte, in, like, ilike, is, match, imatch, isdistinct`.
76
-
77
- ```ts
78
- // Comparaison numérique.
79
- { event: '*', schema: 'public', table: 'items', filter: 'qty=gt.5' }
80
-
81
- // Appartenance à un ensemble — les virgules internes à `in.(...)` ne
82
- // séparent PAS des conditions AND (voir plus bas).
83
- { event: '*', schema: 'public', table: 'orders', filter: 'status=in.(open,pending)' }
84
-
85
- // Motif SQL LIKE (% / _).
86
- { event: '*', schema: 'public', table: 'users', filter: 'name=like.jo%' }
87
-
88
- // Négation — préfixe `not.` devant l'opérateur.
89
- { event: '*', schema: 'public', table: 'orders', filter: 'status=not.eq.done' }
90
-
91
- // AND par virgules — chaque condition séparée par `,` (hors `in.(...)`).
92
- { event: '*', schema: 'public', table: 'items', filter: 'room_id=eq.42,qty=gt.5' }
93
- ```
94
-
95
- À savoir :
96
-
97
- - **Le serveur `aura-realtime` est autoritaire** : il applique déjà le filtre avant d'envoyer l'event sur le socket. Le client réapplique la même logique en second rideau (defense-in-depth) — il ne peut que sur-filtrer, jamais laisser passer un event que le serveur aurait dû exclure.
98
- - **Fail-closed** : une condition non parsable (syntaxe invalide, opérateur inconnu, trop de valeurs `in`, pattern `match`/`imatch` trop long) exclut l'event plutôt que de le laisser passer.
99
- - **DELETE** : le filtre est évalué sur **l'ancienne ligne** (`old_record`), pas sur la nouvelle (qui n'existe plus). Les colonnes disponibles dans `old_record` dépendent du `REPLICA IDENTITY` de la table (`DEFAULT` : seule la clé primaire ; `FULL` : toutes les colonnes) — un filtre sur une colonne absente de `old_record` échoue à matcher (résultat non évaluable ⇒ exclusion, jamais inversée par `not.`), **sauf `is.null` et `isdistinct`** qui traitent une colonne absente comme `NULL` et peuvent donc matcher même si la colonne n'est pas présente dans `old_record`.
100
- - `schema` (et `table`) doivent correspondre exactement au schéma/table réels tels qu'envoyés par le serveur dans l'event — un `schema` incorrect exclut silencieusement tous les events de ce channel.
101
-
102
- ### Broadcast
103
-
104
- ```ts
105
- const room = aura.realtime.channel('room-1', { broadcast: { ack: true, self: true } })
106
-
107
- room
108
- .on('broadcast', { event: 'cursor-pos' }, (payload) => {
109
- console.log(payload)
110
- })
111
- .subscribe()
112
-
113
- // 'ok' | 'timeout' | 'error' — résout à l'ACK serveur si broadcast.ack est activé sur le channel.
114
- const status = await room.send({ type: 'broadcast', event: 'cursor-pos', payload: { x: 100, y: 200 } })
115
- ```
116
-
117
- #### Broadcast HTTP (sans WebSocket)
118
-
119
- Émet un broadcast via REST, sans connexion WebSocket ouverte — utile côté serveur/edge.
120
-
121
- ```ts
122
- // POST /v1/realtime/{projectId}/broadcast — pas besoin de connect().
123
- const { error } = await aura.realtime.httpBroadcast('room-1', 'cursor-pos', { x: 10, y: 20 })
124
- if (error) console.error(error) // 4xx / rate-limit surfacés proprement
125
- ```
126
-
127
- Le nom de canal est préfixé par le projet automatiquement s'il ne l'est pas déjà.
128
-
129
- ### Canaux privés (`setAuth`)
130
-
131
- Les canaux privés (`{ private: true }`) sont autorisés par les policies RLS côté serveur à
132
- partir du JWT courant. Fixez/rafraîchissez ce token via `setAuth()` **avant** de vous abonner :
133
-
134
- ```ts
135
- // Utilise le token fourni (ou, sans argument, reprend client.authStore.token).
136
- aura.realtime.setAuth(session.access_token)
137
-
138
- const secret = aura.realtime
139
- .channel('secret-room', { private: true })
140
- .on('broadcast', { event: 'msg' }, console.log)
141
- .subscribe((status, err) => {
142
- if (status === 'CHANNEL_ERROR') console.error('Refusé par la policy RLS', err)
143
- })
144
- ```
145
-
146
- `setAuth()` propage `{ type: 'access_token' }` sur une connexion ouverte (dédupliqué, sans
147
- reconnexion). Un token non autorisé par la policy provoque un `CHANNEL_ERROR` à la souscription.
148
-
149
- ### Presence
150
-
151
- ```ts
152
- const lobby = aura.channel('room-1', { config: { presence: { key: 'user-1' } } })
153
-
154
- lobby
155
- .on('presence', { event: 'sync' }, () => {
156
- console.log(lobby.presenceState())
157
- })
158
- .on('presence', { event: 'join' }, console.log)
159
- .on('presence', { event: 'leave' }, console.log)
160
- .subscribe()
161
-
162
- await lobby.track({ online_at: new Date().toISOString() })
163
- await lobby.untrack()
164
- ```
165
-
166
- ### Nettoyage
167
-
168
- ```ts
169
- aura.realtime.getChannels()
170
- aura.realtime.removeChannel('room-1')
171
- aura.realtime.removeAllChannels()
172
- aura.realtime.disconnect()
173
- unsubscribe()
174
- ```
175
-
176
- ## Limitations
177
-
178
- - Pas de limitation de débit configurable (`eventsPerSecond`) sur le broadcast (côté client).
179
- - La reconnexion réabonne les channels existants mais ne garantit pas la livraison des événements manqués pendant la coupure (au-delà du rejeu par `since_id` quand le serveur le supporte).
180
-
181
- ## Documentation
182
-
183
- Référence complète du SDK (tous les services, types partagés, SSR) : [README racine](../../README.md).