@aurabase/aurabase-js 0.3.1 → 0.4.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.
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 +74 -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,96 +0,0 @@
1
- # @aurabase/functions
2
-
3
- Service d'invocation d'edge functions du SDK Aurabase : appel de fonctions avec enveloppe routée (méthode/chemin/headers), jobs asynchrones et cron.
4
-
5
- ![npm](https://img.shields.io/npm/v/@aurabase/functions) ![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/functions
15
- ```
16
-
17
- > Ce package dépend de `@aurabase/core` (`workspace:*` en interne, résolu en semver côté npm). Si vous utilisez déjà le package `aurabase`, `@aurabase/functions` est déjà inclus — cette installation ciblée n'est utile que pour composer votre propre client ou limiter la taille du bundle.
18
-
19
- ## Usage
20
-
21
- Dans l'usage courant, `FunctionsService` n'est jamais instancié directement : il est exposé par le client principal sous `aura.functions`.
22
-
23
- ```ts
24
- import { createClient } from 'aurabase'
25
-
26
- const aura = createClient('http://localhost:8080', 'my-project', 'aura_anon_xxx')
27
- ```
28
-
29
- ### Invocation
30
-
31
- `invoke<T>()` enveloppe la requête (`{ method, path, headers, body }`) et dé-wrap la réponse JSON du backend — tout est bufferisé, pas de streaming (voir Limitations).
32
-
33
- ```ts
34
- const { data, error } = await aura.functions.invoke<{ ok: boolean }>('hello-world', {
35
- body: { name: 'Ada' },
36
- })
37
-
38
- if (error) throw error
39
- console.log(data!.ok)
40
- ```
41
-
42
- Options complètes : `method`, `path` (sous-route à l'intérieur de la fonction), `headers` (transmis à la fonction elle-même, pas des headers de transport), `signal`, `timeout`.
43
-
44
- ```ts
45
- const controller = new AbortController()
46
-
47
- const { error } = await aura.functions.invoke('slow-job', {
48
- method: 'POST',
49
- path: '/process',
50
- headers: { 'x-request-source': 'studio' },
51
- timeout: 5000, // ms — annule automatiquement au-delà
52
- signal: controller.signal, // ou : annulation manuelle via controller.abort()
53
- })
54
-
55
- // Une annulation (timeout ou signal) remonte toujours en AuraError code 'timeout'.
56
- if (error?.code === 'timeout') {
57
- console.warn('invocation annulée ou trop lente')
58
- }
59
- ```
60
-
61
- ### Fonctions (métadonnées)
62
-
63
- ```ts
64
- const { data: fns } = await aura.functions.list()
65
- const { data: fn } = await aura.functions.get(fns![0]!.id)
66
- ```
67
-
68
- ### Jobs asynchrones (extra vs `@supabase/functions-js`)
69
-
70
- ```ts
71
- const { data: jobs } = await aura.functions.listJobs({ status: 'pending', limit: 20 })
72
- const { data: job } = await aura.functions.getJob(jobs![0]!.id)
73
- ```
74
-
75
- ### Cron (extra vs `@supabase/functions-js`)
76
-
77
- ```ts
78
- await aura.functions.createCronJob('nightly-cleanup', '0 3 * * *', 'cleanup-fn', {
79
- payload: { dryRun: false },
80
- })
81
-
82
- const { data: crons } = await aura.functions.listCronJobs()
83
- await aura.functions.deleteCronJob('nightly-cleanup')
84
- ```
85
-
86
- ## Limitations
87
-
88
- - Pas de streaming de réponse : `invoke()` bufferise toujours l'intégralité du corps JSON avant de résoudre (pas de lecture incrémentale, pas de réponse SSE/chunked exploitable).
89
- - Pas de `responseType` (`json`/`text`/`blob`) : la réponse est toujours parsée comme JSON puis dé-wrappée (`{data}` → contenu).
90
- - Pas de sélection de région d'exécution.
91
- - `headers` est transmis tel quel à la fonction invoquée — ce ne sont pas des headers de transport HTTP (pas de contrôle sur ceux injectés par le pipeline : `apikey`, `Authorization`, `Content-Type`).
92
- - Pas de `getCronJob()` ni `updateCronJob()` : seuls `listCronJobs`, `createCronJob` et `deleteCronJob` sont exposés.
93
-
94
- ## Documentation
95
-
96
- Référence complète du SDK (tous les services, types partagés, SSR) : [README racine](../../README.md).
@@ -1,173 +0,0 @@
1
- 'use strict';
2
-
3
- var core = require('@aurabase/core');
4
-
5
- // src/FunctionsService.ts
6
- var RELAY_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
7
- function isRelayStatus(status) {
8
- return status === 0 || RELAY_STATUSES.has(status);
9
- }
10
- var FunctionsHttpError = class _FunctionsHttpError extends core.AuraError {
11
- context;
12
- constructor(status, body, context) {
13
- super(status, body);
14
- this.name = "FunctionsHttpError";
15
- this.context = context;
16
- Object.setPrototypeOf(this, _FunctionsHttpError.prototype);
17
- }
18
- };
19
- var FunctionsRelayError = class _FunctionsRelayError extends core.AuraError {
20
- context;
21
- constructor(status, body, context) {
22
- super(status, body);
23
- this.name = "FunctionsRelayError";
24
- this.context = context;
25
- Object.setPrototypeOf(this, _FunctionsRelayError.prototype);
26
- }
27
- };
28
- function toFunctionsError(err, context) {
29
- const body = err.details != null ? err.details : { error: { code: err.code, message: err.message } };
30
- return isRelayStatus(err.status) ? new FunctionsRelayError(err.status, body, err.details) : new FunctionsHttpError(err.status, body, err.details);
31
- }
32
-
33
- // src/FunctionsService.ts
34
- var FunctionsService = class extends core.BaseService {
35
- constructor(client) {
36
- super(client);
37
- }
38
- get prefix() {
39
- return `/v1/functions/${this.client.projectId}`;
40
- }
41
- // -- Function invocation ----------------------------------------------------
42
- /**
43
- * Invoque une edge function.
44
- *
45
- * `responseType` (parité `@supabase/functions-js`, défaut `'json'`) :
46
- * - `'json'` : chemin PIPELINE inchangé (refresh proactif centralisé, injection
47
- * apikey/Authorization, dé-wrapping `{data,meta}`, retryConfig). Non-régression.
48
- * - `'text' | 'blob' | 'arrayBuffer'` : chemin TRANSPORT BRUT `client.fetchFn`
49
- * (patron `StorageService`, SANS toucher `core/fetch.ts`) — refresh proactif
50
- * manuel, pose de `Authorization`/`apikey`, puis `res.text()/blob()/arrayBuffer()`
51
- * sans dé-wrapping (le corps HTTP est renvoyé tel quel).
52
- *
53
- * Erreurs typées (parité) : une réponse HTTP non-2xx → `FunctionsHttpError`, une
54
- * panne de relais/infra (réseau, 502/503/504) → `FunctionsRelayError` ; les deux
55
- * sous-classent `AuraError` (rétrocompat `isAuraError`/champ `error`). `timeout`/
56
- * `signal` continuent de produire le code `timeout`.
57
- */
58
- async invoke(slug, options) {
59
- const controller = new AbortController();
60
- let timeoutId;
61
- const userSignal = options?.signal;
62
- const onAbort = () => controller.abort();
63
- if (options?.timeout) timeoutId = setTimeout(() => controller.abort(), options.timeout);
64
- if (userSignal) {
65
- if (userSignal.aborted) controller.abort();
66
- else userSignal.addEventListener("abort", onAbort, { once: true });
67
- }
68
- const cleanup = () => {
69
- if (timeoutId) clearTimeout(timeoutId);
70
- if (userSignal) userSignal.removeEventListener("abort", onAbort);
71
- };
72
- const envelope = { method: options?.method, path: options?.path, headers: options?.headers, body: options?.body };
73
- const responseType = options?.responseType ?? "json";
74
- const timeoutError = () => ({
75
- data: null,
76
- error: new core.AuraError(0, {
77
- error: { code: "timeout", message: "Function invocation aborted or timed out" }
78
- })
79
- });
80
- try {
81
- if (responseType === "json") {
82
- const res2 = await this.request("POST", `${this.prefix}/${slug}/invoke`, envelope, {
83
- signal: controller.signal
84
- });
85
- if (res2.error && controller.signal.aborted) return timeoutError();
86
- if (res2.error) return { data: null, error: toFunctionsError(res2.error) };
87
- return res2;
88
- }
89
- const client = this.client;
90
- const store = client.authStore;
91
- if (store.token && store.refreshToken && core.isTokenExpired(store.token, 30)) {
92
- await core.refreshOnce(client);
93
- }
94
- const headers = {
95
- "Content-Type": "application/json",
96
- // Négocie le mode passthrough côté backend : réponse HTTP BRUTE (statut réel de la
97
- // fonction + content-type réel + corps brut) au lieu de l'enveloppe `{data,meta}`.
98
- // Indispensable pour que `res.text()/blob()/arrayBuffer()` reçoive le corps de la
99
- // fonction (et non l'enveloppe JSON) et que `res.status` porte le statut fonction.
100
- "X-Aurabase-Invoke-Mode": "raw"
101
- };
102
- if (store.token) headers["Authorization"] = `Bearer ${store.token}`;
103
- if (client.apiKey) headers["apikey"] = client.apiKey;
104
- const res = await client.fetchFn(this.url(`${this.prefix}/${slug}/invoke`), {
105
- method: "POST",
106
- headers,
107
- body: JSON.stringify(envelope),
108
- signal: controller.signal
109
- });
110
- if (!res.ok) {
111
- let parsed = null;
112
- try {
113
- parsed = await res.json();
114
- } catch {
115
- }
116
- return { data: null, error: toFunctionsError(new core.AuraError(res.status, parsed)) };
117
- }
118
- let data;
119
- if (responseType === "text") data = await res.text();
120
- else if (responseType === "blob") data = await res.blob();
121
- else data = await res.arrayBuffer();
122
- return { data, error: null };
123
- } catch (err) {
124
- if (controller.signal.aborted || core.isAbortError(err)) return timeoutError();
125
- return {
126
- data: null,
127
- error: new FunctionsRelayError(0, {
128
- error: { code: "network_error", message: err instanceof Error ? err.message : "Function relay error" }
129
- })
130
- };
131
- } finally {
132
- cleanup();
133
- }
134
- }
135
- // -- Function CRUD ----------------------------------------------------------
136
- async list() {
137
- return this.request("GET", `${this.prefix}`);
138
- }
139
- async get(id) {
140
- return this.request("GET", `${this.prefix}/${id}`);
141
- }
142
- // -- Jobs -------------------------------------------------------------------
143
- async listJobs(options) {
144
- const params = new URLSearchParams();
145
- if (options?.status) params.set("status", options.status);
146
- if (options?.limit !== void 0) params.set("limit", String(options.limit));
147
- const qs = params.toString() ? `?${params.toString()}` : "";
148
- return this.request("GET", `${this.prefix}/jobs${qs}`);
149
- }
150
- async getJob(jobId) {
151
- return this.request("GET", `${this.prefix}/jobs/${jobId}`);
152
- }
153
- // -- Cron -------------------------------------------------------------------
154
- async listCronJobs() {
155
- return this.request("GET", `${this.prefix}/cron`);
156
- }
157
- async createCronJob(name, schedule, functionName, options) {
158
- return this.request("POST", `${this.prefix}/cron`, {
159
- name,
160
- schedule,
161
- function_name: functionName,
162
- payload: options?.payload
163
- });
164
- }
165
- async deleteCronJob(name) {
166
- return this.request("DELETE", `${this.prefix}/cron/${name}`);
167
- }
168
- };
169
-
170
- exports.FunctionsHttpError = FunctionsHttpError;
171
- exports.FunctionsRelayError = FunctionsRelayError;
172
- exports.FunctionsService = FunctionsService;
173
- exports.isRelayStatus = isRelayStatus;
@@ -1,81 +0,0 @@
1
- import { BaseService, AuraClientLike, AuraResponse, FunctionDef, Job, CronJob, AuraError } from '@aurabase/core';
2
- export { AuraResponse, CronJob, FunctionDef, Job } from '@aurabase/core';
3
-
4
- /** Type de réponse attendu de l'invocation (parité `@supabase/functions-js`). */
5
- type FunctionsResponseType = 'json' | 'text' | 'blob' | 'arrayBuffer';
6
- declare class FunctionsService extends BaseService {
7
- constructor(client: AuraClientLike);
8
- private get prefix();
9
- /**
10
- * Invoque une edge function.
11
- *
12
- * `responseType` (parité `@supabase/functions-js`, défaut `'json'`) :
13
- * - `'json'` : chemin PIPELINE inchangé (refresh proactif centralisé, injection
14
- * apikey/Authorization, dé-wrapping `{data,meta}`, retryConfig). Non-régression.
15
- * - `'text' | 'blob' | 'arrayBuffer'` : chemin TRANSPORT BRUT `client.fetchFn`
16
- * (patron `StorageService`, SANS toucher `core/fetch.ts`) — refresh proactif
17
- * manuel, pose de `Authorization`/`apikey`, puis `res.text()/blob()/arrayBuffer()`
18
- * sans dé-wrapping (le corps HTTP est renvoyé tel quel).
19
- *
20
- * Erreurs typées (parité) : une réponse HTTP non-2xx → `FunctionsHttpError`, une
21
- * panne de relais/infra (réseau, 502/503/504) → `FunctionsRelayError` ; les deux
22
- * sous-classent `AuraError` (rétrocompat `isAuraError`/champ `error`). `timeout`/
23
- * `signal` continuent de produire le code `timeout`.
24
- */
25
- invoke<T = unknown>(slug: string, options?: {
26
- body?: unknown;
27
- method?: string;
28
- path?: string;
29
- headers?: Record<string, string>;
30
- signal?: AbortSignal;
31
- timeout?: number;
32
- responseType?: FunctionsResponseType;
33
- }): Promise<AuraResponse<T>>;
34
- list(): Promise<AuraResponse<FunctionDef[]>>;
35
- get(id: string): Promise<AuraResponse<FunctionDef>>;
36
- listJobs(options?: {
37
- status?: string;
38
- limit?: number;
39
- }): Promise<AuraResponse<Job[]>>;
40
- getJob(jobId: string): Promise<AuraResponse<Job>>;
41
- listCronJobs(): Promise<AuraResponse<CronJob[]>>;
42
- createCronJob(name: string, schedule: string, functionName: string, options?: {
43
- payload?: unknown;
44
- }): Promise<AuraResponse<CronJob>>;
45
- deleteCronJob(name: string): Promise<AuraResponse<null>>;
46
- }
47
-
48
- declare function isRelayStatus(status: number): boolean;
49
- /**
50
- * Erreur HTTP APPLICATIVE renvoyée par l'invocation d'une edge function
51
- * (réponse HTTP non-2xx). Parité `FunctionsHttpError` de `@supabase/functions-js`.
52
- * Sous-classe `AuraError` → `isAuraError()` reste vrai, `status` porte le code HTTP.
53
- * `context` conserve le corps déjà lu (JSON/texte) pour inspection.
54
- */
55
- declare class FunctionsHttpError extends AuraError {
56
- readonly context: unknown;
57
- constructor(status: number, body?: {
58
- error?: {
59
- code?: string;
60
- message?: string;
61
- };
62
- message?: string;
63
- } | null, context?: unknown);
64
- }
65
- /**
66
- * Erreur de RELAIS/infra : fonction injoignable (échec réseau), 502/503/504 de la
67
- * passerelle, cold start échoué, corps non exploitable. Parité `FunctionsRelayError`
68
- * de `@supabase/functions-js`. Sous-classe `AuraError`.
69
- */
70
- declare class FunctionsRelayError extends AuraError {
71
- readonly context: unknown;
72
- constructor(status: number, body?: {
73
- error?: {
74
- code?: string;
75
- message?: string;
76
- };
77
- message?: string;
78
- } | null, context?: unknown);
79
- }
80
-
81
- export { FunctionsHttpError, FunctionsRelayError, type FunctionsResponseType, FunctionsService, isRelayStatus };
@@ -1,81 +0,0 @@
1
- import { BaseService, AuraClientLike, AuraResponse, FunctionDef, Job, CronJob, AuraError } from '@aurabase/core';
2
- export { AuraResponse, CronJob, FunctionDef, Job } from '@aurabase/core';
3
-
4
- /** Type de réponse attendu de l'invocation (parité `@supabase/functions-js`). */
5
- type FunctionsResponseType = 'json' | 'text' | 'blob' | 'arrayBuffer';
6
- declare class FunctionsService extends BaseService {
7
- constructor(client: AuraClientLike);
8
- private get prefix();
9
- /**
10
- * Invoque une edge function.
11
- *
12
- * `responseType` (parité `@supabase/functions-js`, défaut `'json'`) :
13
- * - `'json'` : chemin PIPELINE inchangé (refresh proactif centralisé, injection
14
- * apikey/Authorization, dé-wrapping `{data,meta}`, retryConfig). Non-régression.
15
- * - `'text' | 'blob' | 'arrayBuffer'` : chemin TRANSPORT BRUT `client.fetchFn`
16
- * (patron `StorageService`, SANS toucher `core/fetch.ts`) — refresh proactif
17
- * manuel, pose de `Authorization`/`apikey`, puis `res.text()/blob()/arrayBuffer()`
18
- * sans dé-wrapping (le corps HTTP est renvoyé tel quel).
19
- *
20
- * Erreurs typées (parité) : une réponse HTTP non-2xx → `FunctionsHttpError`, une
21
- * panne de relais/infra (réseau, 502/503/504) → `FunctionsRelayError` ; les deux
22
- * sous-classent `AuraError` (rétrocompat `isAuraError`/champ `error`). `timeout`/
23
- * `signal` continuent de produire le code `timeout`.
24
- */
25
- invoke<T = unknown>(slug: string, options?: {
26
- body?: unknown;
27
- method?: string;
28
- path?: string;
29
- headers?: Record<string, string>;
30
- signal?: AbortSignal;
31
- timeout?: number;
32
- responseType?: FunctionsResponseType;
33
- }): Promise<AuraResponse<T>>;
34
- list(): Promise<AuraResponse<FunctionDef[]>>;
35
- get(id: string): Promise<AuraResponse<FunctionDef>>;
36
- listJobs(options?: {
37
- status?: string;
38
- limit?: number;
39
- }): Promise<AuraResponse<Job[]>>;
40
- getJob(jobId: string): Promise<AuraResponse<Job>>;
41
- listCronJobs(): Promise<AuraResponse<CronJob[]>>;
42
- createCronJob(name: string, schedule: string, functionName: string, options?: {
43
- payload?: unknown;
44
- }): Promise<AuraResponse<CronJob>>;
45
- deleteCronJob(name: string): Promise<AuraResponse<null>>;
46
- }
47
-
48
- declare function isRelayStatus(status: number): boolean;
49
- /**
50
- * Erreur HTTP APPLICATIVE renvoyée par l'invocation d'une edge function
51
- * (réponse HTTP non-2xx). Parité `FunctionsHttpError` de `@supabase/functions-js`.
52
- * Sous-classe `AuraError` → `isAuraError()` reste vrai, `status` porte le code HTTP.
53
- * `context` conserve le corps déjà lu (JSON/texte) pour inspection.
54
- */
55
- declare class FunctionsHttpError extends AuraError {
56
- readonly context: unknown;
57
- constructor(status: number, body?: {
58
- error?: {
59
- code?: string;
60
- message?: string;
61
- };
62
- message?: string;
63
- } | null, context?: unknown);
64
- }
65
- /**
66
- * Erreur de RELAIS/infra : fonction injoignable (échec réseau), 502/503/504 de la
67
- * passerelle, cold start échoué, corps non exploitable. Parité `FunctionsRelayError`
68
- * de `@supabase/functions-js`. Sous-classe `AuraError`.
69
- */
70
- declare class FunctionsRelayError extends AuraError {
71
- readonly context: unknown;
72
- constructor(status: number, body?: {
73
- error?: {
74
- code?: string;
75
- message?: string;
76
- };
77
- message?: string;
78
- } | null, context?: unknown);
79
- }
80
-
81
- export { FunctionsHttpError, FunctionsRelayError, type FunctionsResponseType, FunctionsService, isRelayStatus };
@@ -1,168 +0,0 @@
1
- import { AuraError, BaseService, isTokenExpired, refreshOnce, isAbortError } from '@aurabase/core';
2
-
3
- // src/FunctionsService.ts
4
- var RELAY_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
5
- function isRelayStatus(status) {
6
- return status === 0 || RELAY_STATUSES.has(status);
7
- }
8
- var FunctionsHttpError = class _FunctionsHttpError extends AuraError {
9
- context;
10
- constructor(status, body, context) {
11
- super(status, body);
12
- this.name = "FunctionsHttpError";
13
- this.context = context;
14
- Object.setPrototypeOf(this, _FunctionsHttpError.prototype);
15
- }
16
- };
17
- var FunctionsRelayError = class _FunctionsRelayError extends AuraError {
18
- context;
19
- constructor(status, body, context) {
20
- super(status, body);
21
- this.name = "FunctionsRelayError";
22
- this.context = context;
23
- Object.setPrototypeOf(this, _FunctionsRelayError.prototype);
24
- }
25
- };
26
- function toFunctionsError(err, context) {
27
- const body = err.details != null ? err.details : { error: { code: err.code, message: err.message } };
28
- return isRelayStatus(err.status) ? new FunctionsRelayError(err.status, body, err.details) : new FunctionsHttpError(err.status, body, err.details);
29
- }
30
-
31
- // src/FunctionsService.ts
32
- var FunctionsService = class extends BaseService {
33
- constructor(client) {
34
- super(client);
35
- }
36
- get prefix() {
37
- return `/v1/functions/${this.client.projectId}`;
38
- }
39
- // -- Function invocation ----------------------------------------------------
40
- /**
41
- * Invoque une edge function.
42
- *
43
- * `responseType` (parité `@supabase/functions-js`, défaut `'json'`) :
44
- * - `'json'` : chemin PIPELINE inchangé (refresh proactif centralisé, injection
45
- * apikey/Authorization, dé-wrapping `{data,meta}`, retryConfig). Non-régression.
46
- * - `'text' | 'blob' | 'arrayBuffer'` : chemin TRANSPORT BRUT `client.fetchFn`
47
- * (patron `StorageService`, SANS toucher `core/fetch.ts`) — refresh proactif
48
- * manuel, pose de `Authorization`/`apikey`, puis `res.text()/blob()/arrayBuffer()`
49
- * sans dé-wrapping (le corps HTTP est renvoyé tel quel).
50
- *
51
- * Erreurs typées (parité) : une réponse HTTP non-2xx → `FunctionsHttpError`, une
52
- * panne de relais/infra (réseau, 502/503/504) → `FunctionsRelayError` ; les deux
53
- * sous-classent `AuraError` (rétrocompat `isAuraError`/champ `error`). `timeout`/
54
- * `signal` continuent de produire le code `timeout`.
55
- */
56
- async invoke(slug, options) {
57
- const controller = new AbortController();
58
- let timeoutId;
59
- const userSignal = options?.signal;
60
- const onAbort = () => controller.abort();
61
- if (options?.timeout) timeoutId = setTimeout(() => controller.abort(), options.timeout);
62
- if (userSignal) {
63
- if (userSignal.aborted) controller.abort();
64
- else userSignal.addEventListener("abort", onAbort, { once: true });
65
- }
66
- const cleanup = () => {
67
- if (timeoutId) clearTimeout(timeoutId);
68
- if (userSignal) userSignal.removeEventListener("abort", onAbort);
69
- };
70
- const envelope = { method: options?.method, path: options?.path, headers: options?.headers, body: options?.body };
71
- const responseType = options?.responseType ?? "json";
72
- const timeoutError = () => ({
73
- data: null,
74
- error: new AuraError(0, {
75
- error: { code: "timeout", message: "Function invocation aborted or timed out" }
76
- })
77
- });
78
- try {
79
- if (responseType === "json") {
80
- const res2 = await this.request("POST", `${this.prefix}/${slug}/invoke`, envelope, {
81
- signal: controller.signal
82
- });
83
- if (res2.error && controller.signal.aborted) return timeoutError();
84
- if (res2.error) return { data: null, error: toFunctionsError(res2.error) };
85
- return res2;
86
- }
87
- const client = this.client;
88
- const store = client.authStore;
89
- if (store.token && store.refreshToken && isTokenExpired(store.token, 30)) {
90
- await refreshOnce(client);
91
- }
92
- const headers = {
93
- "Content-Type": "application/json",
94
- // Négocie le mode passthrough côté backend : réponse HTTP BRUTE (statut réel de la
95
- // fonction + content-type réel + corps brut) au lieu de l'enveloppe `{data,meta}`.
96
- // Indispensable pour que `res.text()/blob()/arrayBuffer()` reçoive le corps de la
97
- // fonction (et non l'enveloppe JSON) et que `res.status` porte le statut fonction.
98
- "X-Aurabase-Invoke-Mode": "raw"
99
- };
100
- if (store.token) headers["Authorization"] = `Bearer ${store.token}`;
101
- if (client.apiKey) headers["apikey"] = client.apiKey;
102
- const res = await client.fetchFn(this.url(`${this.prefix}/${slug}/invoke`), {
103
- method: "POST",
104
- headers,
105
- body: JSON.stringify(envelope),
106
- signal: controller.signal
107
- });
108
- if (!res.ok) {
109
- let parsed = null;
110
- try {
111
- parsed = await res.json();
112
- } catch {
113
- }
114
- return { data: null, error: toFunctionsError(new AuraError(res.status, parsed)) };
115
- }
116
- let data;
117
- if (responseType === "text") data = await res.text();
118
- else if (responseType === "blob") data = await res.blob();
119
- else data = await res.arrayBuffer();
120
- return { data, error: null };
121
- } catch (err) {
122
- if (controller.signal.aborted || isAbortError(err)) return timeoutError();
123
- return {
124
- data: null,
125
- error: new FunctionsRelayError(0, {
126
- error: { code: "network_error", message: err instanceof Error ? err.message : "Function relay error" }
127
- })
128
- };
129
- } finally {
130
- cleanup();
131
- }
132
- }
133
- // -- Function CRUD ----------------------------------------------------------
134
- async list() {
135
- return this.request("GET", `${this.prefix}`);
136
- }
137
- async get(id) {
138
- return this.request("GET", `${this.prefix}/${id}`);
139
- }
140
- // -- Jobs -------------------------------------------------------------------
141
- async listJobs(options) {
142
- const params = new URLSearchParams();
143
- if (options?.status) params.set("status", options.status);
144
- if (options?.limit !== void 0) params.set("limit", String(options.limit));
145
- const qs = params.toString() ? `?${params.toString()}` : "";
146
- return this.request("GET", `${this.prefix}/jobs${qs}`);
147
- }
148
- async getJob(jobId) {
149
- return this.request("GET", `${this.prefix}/jobs/${jobId}`);
150
- }
151
- // -- Cron -------------------------------------------------------------------
152
- async listCronJobs() {
153
- return this.request("GET", `${this.prefix}/cron`);
154
- }
155
- async createCronJob(name, schedule, functionName, options) {
156
- return this.request("POST", `${this.prefix}/cron`, {
157
- name,
158
- schedule,
159
- function_name: functionName,
160
- payload: options?.payload
161
- });
162
- }
163
- async deleteCronJob(name) {
164
- return this.request("DELETE", `${this.prefix}/cron/${name}`);
165
- }
166
- };
167
-
168
- export { FunctionsHttpError, FunctionsRelayError, FunctionsService, isRelayStatus };
@@ -1,60 +0,0 @@
1
- {
2
- "name": "@aurabase/functions",
3
- "version": "0.3.0",
4
- "description": "Service edge functions du SDK Aurabase (invoke, jobs asynchrones, cron)",
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/functions"
36
- },
37
- "homepage": "https://github.com/daylami555/aurabase/tree/main/aurabase-js/packages/functions#readme",
38
- "bugs": {
39
- "url": "https://github.com/daylami555/aurabase/issues"
40
- },
41
- "keywords": [
42
- "aurabase",
43
- "baas",
44
- "sdk",
45
- "functions"
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.