@aurabase/functions 0.7.3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -26,7 +26,16 @@ var FunctionsRelayError = class _FunctionsRelayError extends core.AuraError {
26
26
  }
27
27
  };
28
28
  function toFunctionsError(err, context) {
29
- const body = err.details != null ? err.details : { error: { code: err.code, message: err.message } };
29
+ let body = err.details != null ? err.details : { error: { code: err.code, message: err.message } };
30
+ if ((!body.error || !body.error.message || body.error.message === `HTTP ${err.status}`) && body.data?.body) {
31
+ const rawBody = body.data.body;
32
+ const fallbackMsg = typeof rawBody === "string" ? rawBody : typeof rawBody.detail === "string" ? typeof rawBody.error === "string" ? `${rawBody.error}: ${rawBody.detail}` : rawBody.detail : typeof rawBody.message === "string" ? rawBody.message : typeof rawBody.error === "string" ? rawBody.error : `Function returned HTTP ${err.status}`;
33
+ body = {
34
+ ...body,
35
+ error: { code: body.error?.code || err.code || `HTTP_${err.status}`, message: fallbackMsg },
36
+ message: fallbackMsg
37
+ };
38
+ }
30
39
  return isRelayStatus(err.status) ? new FunctionsRelayError(err.status, body, err.details) : new FunctionsHttpError(err.status, body, err.details);
31
40
  }
32
41
  var INVOKE_ORIGIN_HEADER = "x-aurabase-invoke-origin";
@@ -290,6 +299,42 @@ var FunctionsService = class extends core.BaseService {
290
299
  async get(nameOrId) {
291
300
  return this.request("GET", `${this.prefix}/${seg(nameOrId)}`);
292
301
  }
302
+ /**
303
+ * Crée ou déploie une fonction Edge (TypeScript Deno ou Rust WASM). Exige une clé `service_role`.
304
+ */
305
+ async deploy(options) {
306
+ return this.request("POST", `${this.prefix}`, options);
307
+ }
308
+ /**
309
+ * Met à jour une fonction existante. Exige une clé `service_role`.
310
+ */
311
+ async update(name, options) {
312
+ return this.request("PATCH", `${this.prefix}/${seg(name)}`, options);
313
+ }
314
+ /**
315
+ * Supprime une fonction par son nom. Exige une clé `service_role`.
316
+ */
317
+ async delete(name) {
318
+ return this.request("DELETE", `${this.prefix}/${seg(name)}`);
319
+ }
320
+ /**
321
+ * Récupère le code source déployé d'une fonction. Exige une clé `service_role`.
322
+ */
323
+ async getCode(name) {
324
+ return this.request("GET", `${this.prefix}/${seg(name)}/code`);
325
+ }
326
+ /**
327
+ * Récupère les secrets déchiffrés d'une fonction. Exige une clé `service_role`.
328
+ */
329
+ async getSecrets(name) {
330
+ return this.request("GET", `${this.prefix}/${seg(name)}/env`);
331
+ }
332
+ /**
333
+ * Définit ou met à jour les secrets chiffrés d'une fonction. Exige une clé `service_role`.
334
+ */
335
+ async setSecrets(name, secrets) {
336
+ return this.request("PUT", `${this.prefix}/${seg(name)}/env`, { env_vars: secrets });
337
+ }
293
338
  // -- Jobs -------------------------------------------------------------------
294
339
  /**
295
340
  * Liste les jobs asynchrones du projet, filtrés par `status` (`pending`, `running`, `completed`,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { AuraError, BaseService, AuraClientLike, AuraResponse, FunctionDef, Job, CronJob } from '@aurabase/core';
1
+ import { AuraError, FunctionPermissions, BaseService, AuraClientLike, AuraResponse, FunctionDef, Job, CronJob } from '@aurabase/core';
2
2
  export { AuraResponse, CronJob, FunctionDef, FunctionPermissions, Job } from '@aurabase/core';
3
3
 
4
4
  declare function isRelayStatus(status: number): boolean;
@@ -36,6 +36,20 @@ declare class FunctionsRelayError extends AuraError {
36
36
 
37
37
  /** Type de réponse attendu de l'invocation (parité `@supabase/functions-js`). */
38
38
  type FunctionsResponseType = 'json' | 'text' | 'blob' | 'arrayBuffer';
39
+ interface DeployFunctionOptions {
40
+ name: string;
41
+ code: string;
42
+ runtime?: 'deno' | 'wasm';
43
+ permissions?: Partial<FunctionPermissions>;
44
+ env_vars?: Record<string, string>;
45
+ }
46
+ interface UpdateFunctionOptions {
47
+ code?: string;
48
+ runtime?: 'deno' | 'wasm';
49
+ permissions?: Partial<FunctionPermissions>;
50
+ env_vars?: Record<string, string>;
51
+ is_active?: boolean;
52
+ }
39
53
  declare class FunctionsService extends BaseService {
40
54
  constructor(client: AuraClientLike);
41
55
  /**
@@ -97,6 +111,35 @@ declare class FunctionsService extends BaseService {
97
111
  * le NOM l'emporte. Une valeur qui n'est ni l'un ni l'autre produit un 404 qui le dit.
98
112
  */
99
113
  get(nameOrId: string): Promise<AuraResponse<FunctionDef>>;
114
+ /**
115
+ * Crée ou déploie une fonction Edge (TypeScript Deno ou Rust WASM). Exige une clé `service_role`.
116
+ */
117
+ deploy(options: DeployFunctionOptions): Promise<AuraResponse<FunctionDef>>;
118
+ /**
119
+ * Met à jour une fonction existante. Exige une clé `service_role`.
120
+ */
121
+ update(name: string, options: UpdateFunctionOptions): Promise<AuraResponse<FunctionDef>>;
122
+ /**
123
+ * Supprime une fonction par son nom. Exige une clé `service_role`.
124
+ */
125
+ delete(name: string): Promise<AuraResponse<null>>;
126
+ /**
127
+ * Récupère le code source déployé d'une fonction. Exige une clé `service_role`.
128
+ */
129
+ getCode(name: string): Promise<AuraResponse<{
130
+ code: string;
131
+ }>>;
132
+ /**
133
+ * Récupère les secrets déchiffrés d'une fonction. Exige une clé `service_role`.
134
+ */
135
+ getSecrets(name: string): Promise<AuraResponse<Array<{
136
+ key: string;
137
+ value: string;
138
+ }>>>;
139
+ /**
140
+ * Définit ou met à jour les secrets chiffrés d'une fonction. Exige une clé `service_role`.
141
+ */
142
+ setSecrets(name: string, secrets: Record<string, string>): Promise<AuraResponse<null>>;
100
143
  /**
101
144
  * Liste les jobs asynchrones du projet, filtrés par `status` (`pending`, `running`, `completed`,
102
145
  * `failed`, `dead`). `limit` va de 1 à 500 (50 par défaut). Exige une clé `service_role`.
@@ -136,4 +179,4 @@ declare class FunctionsService extends BaseService {
136
179
  deleteCronJob(name: string): Promise<AuraResponse<null>>;
137
180
  }
138
181
 
139
- export { FunctionsHttpError, FunctionsRelayError, type FunctionsResponseType, FunctionsService, isRelayStatus };
182
+ export { type DeployFunctionOptions, FunctionsHttpError, FunctionsRelayError, type FunctionsResponseType, FunctionsService, type UpdateFunctionOptions, isRelayStatus };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AuraError, BaseService, AuraClientLike, AuraResponse, FunctionDef, Job, CronJob } from '@aurabase/core';
1
+ import { AuraError, FunctionPermissions, BaseService, AuraClientLike, AuraResponse, FunctionDef, Job, CronJob } from '@aurabase/core';
2
2
  export { AuraResponse, CronJob, FunctionDef, FunctionPermissions, Job } from '@aurabase/core';
3
3
 
4
4
  declare function isRelayStatus(status: number): boolean;
@@ -36,6 +36,20 @@ declare class FunctionsRelayError extends AuraError {
36
36
 
37
37
  /** Type de réponse attendu de l'invocation (parité `@supabase/functions-js`). */
38
38
  type FunctionsResponseType = 'json' | 'text' | 'blob' | 'arrayBuffer';
39
+ interface DeployFunctionOptions {
40
+ name: string;
41
+ code: string;
42
+ runtime?: 'deno' | 'wasm';
43
+ permissions?: Partial<FunctionPermissions>;
44
+ env_vars?: Record<string, string>;
45
+ }
46
+ interface UpdateFunctionOptions {
47
+ code?: string;
48
+ runtime?: 'deno' | 'wasm';
49
+ permissions?: Partial<FunctionPermissions>;
50
+ env_vars?: Record<string, string>;
51
+ is_active?: boolean;
52
+ }
39
53
  declare class FunctionsService extends BaseService {
40
54
  constructor(client: AuraClientLike);
41
55
  /**
@@ -97,6 +111,35 @@ declare class FunctionsService extends BaseService {
97
111
  * le NOM l'emporte. Une valeur qui n'est ni l'un ni l'autre produit un 404 qui le dit.
98
112
  */
99
113
  get(nameOrId: string): Promise<AuraResponse<FunctionDef>>;
114
+ /**
115
+ * Crée ou déploie une fonction Edge (TypeScript Deno ou Rust WASM). Exige une clé `service_role`.
116
+ */
117
+ deploy(options: DeployFunctionOptions): Promise<AuraResponse<FunctionDef>>;
118
+ /**
119
+ * Met à jour une fonction existante. Exige une clé `service_role`.
120
+ */
121
+ update(name: string, options: UpdateFunctionOptions): Promise<AuraResponse<FunctionDef>>;
122
+ /**
123
+ * Supprime une fonction par son nom. Exige une clé `service_role`.
124
+ */
125
+ delete(name: string): Promise<AuraResponse<null>>;
126
+ /**
127
+ * Récupère le code source déployé d'une fonction. Exige une clé `service_role`.
128
+ */
129
+ getCode(name: string): Promise<AuraResponse<{
130
+ code: string;
131
+ }>>;
132
+ /**
133
+ * Récupère les secrets déchiffrés d'une fonction. Exige une clé `service_role`.
134
+ */
135
+ getSecrets(name: string): Promise<AuraResponse<Array<{
136
+ key: string;
137
+ value: string;
138
+ }>>>;
139
+ /**
140
+ * Définit ou met à jour les secrets chiffrés d'une fonction. Exige une clé `service_role`.
141
+ */
142
+ setSecrets(name: string, secrets: Record<string, string>): Promise<AuraResponse<null>>;
100
143
  /**
101
144
  * Liste les jobs asynchrones du projet, filtrés par `status` (`pending`, `running`, `completed`,
102
145
  * `failed`, `dead`). `limit` va de 1 à 500 (50 par défaut). Exige une clé `service_role`.
@@ -136,4 +179,4 @@ declare class FunctionsService extends BaseService {
136
179
  deleteCronJob(name: string): Promise<AuraResponse<null>>;
137
180
  }
138
181
 
139
- export { FunctionsHttpError, FunctionsRelayError, type FunctionsResponseType, FunctionsService, isRelayStatus };
182
+ export { type DeployFunctionOptions, FunctionsHttpError, FunctionsRelayError, type FunctionsResponseType, FunctionsService, type UpdateFunctionOptions, isRelayStatus };
package/dist/index.js CHANGED
@@ -24,7 +24,16 @@ var FunctionsRelayError = class _FunctionsRelayError extends AuraError {
24
24
  }
25
25
  };
26
26
  function toFunctionsError(err, context) {
27
- const body = err.details != null ? err.details : { error: { code: err.code, message: err.message } };
27
+ let body = err.details != null ? err.details : { error: { code: err.code, message: err.message } };
28
+ if ((!body.error || !body.error.message || body.error.message === `HTTP ${err.status}`) && body.data?.body) {
29
+ const rawBody = body.data.body;
30
+ const fallbackMsg = typeof rawBody === "string" ? rawBody : typeof rawBody.detail === "string" ? typeof rawBody.error === "string" ? `${rawBody.error}: ${rawBody.detail}` : rawBody.detail : typeof rawBody.message === "string" ? rawBody.message : typeof rawBody.error === "string" ? rawBody.error : `Function returned HTTP ${err.status}`;
31
+ body = {
32
+ ...body,
33
+ error: { code: body.error?.code || err.code || `HTTP_${err.status}`, message: fallbackMsg },
34
+ message: fallbackMsg
35
+ };
36
+ }
28
37
  return isRelayStatus(err.status) ? new FunctionsRelayError(err.status, body, err.details) : new FunctionsHttpError(err.status, body, err.details);
29
38
  }
30
39
  var INVOKE_ORIGIN_HEADER = "x-aurabase-invoke-origin";
@@ -288,6 +297,42 @@ var FunctionsService = class extends BaseService {
288
297
  async get(nameOrId) {
289
298
  return this.request("GET", `${this.prefix}/${seg(nameOrId)}`);
290
299
  }
300
+ /**
301
+ * Crée ou déploie une fonction Edge (TypeScript Deno ou Rust WASM). Exige une clé `service_role`.
302
+ */
303
+ async deploy(options) {
304
+ return this.request("POST", `${this.prefix}`, options);
305
+ }
306
+ /**
307
+ * Met à jour une fonction existante. Exige une clé `service_role`.
308
+ */
309
+ async update(name, options) {
310
+ return this.request("PATCH", `${this.prefix}/${seg(name)}`, options);
311
+ }
312
+ /**
313
+ * Supprime une fonction par son nom. Exige une clé `service_role`.
314
+ */
315
+ async delete(name) {
316
+ return this.request("DELETE", `${this.prefix}/${seg(name)}`);
317
+ }
318
+ /**
319
+ * Récupère le code source déployé d'une fonction. Exige une clé `service_role`.
320
+ */
321
+ async getCode(name) {
322
+ return this.request("GET", `${this.prefix}/${seg(name)}/code`);
323
+ }
324
+ /**
325
+ * Récupère les secrets déchiffrés d'une fonction. Exige une clé `service_role`.
326
+ */
327
+ async getSecrets(name) {
328
+ return this.request("GET", `${this.prefix}/${seg(name)}/env`);
329
+ }
330
+ /**
331
+ * Définit ou met à jour les secrets chiffrés d'une fonction. Exige une clé `service_role`.
332
+ */
333
+ async setSecrets(name, secrets) {
334
+ return this.request("PUT", `${this.prefix}/${seg(name)}/env`, { env_vars: secrets });
335
+ }
291
336
  // -- Jobs -------------------------------------------------------------------
292
337
  /**
293
338
  * Liste les jobs asynchrones du projet, filtrés par `status` (`pending`, `running`, `completed`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aurabase/functions",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Service edge functions du SDK Aurabase (invoke, jobs asynchrones, cron)",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -45,7 +45,7 @@
45
45
  "functions"
46
46
  ],
47
47
  "dependencies": {
48
- "@aurabase/core": "0.7.3"
48
+ "@aurabase/core": "0.7.4"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "20.14.15",