naro-js 0.6.1 → 0.7.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.
@@ -0,0 +1,19 @@
1
+ export type PreparedBody = {
2
+ body: BodyInit | undefined;
3
+ /** The content-type to send when the caller gave none; null: the runtime's. */
4
+ contentType: string | null;
5
+ };
6
+ /** The body as it goes, or null when JSON cannot hold it (a BigInt, a cycle). */
7
+ export declare function prepareBody(body: unknown): PreparedBody | null;
8
+ export type ReadAnswer = {
9
+ data: unknown;
10
+ } | {
11
+ unreadable: unknown;
12
+ };
13
+ /**
14
+ * A 2xx answer's data by its content-type: JSON (empty is null), a Blob for
15
+ * octet-stream and PDF, the Response itself for an event stream (read as it
16
+ * comes), FormData for multipart, text otherwise; nothing is read for 204
17
+ * or HEAD.
18
+ */
19
+ export declare function readAnswer(response: Response, method: string): Promise<ReadAnswer>;
@@ -0,0 +1,52 @@
1
+ import type { AuthClient } from "../auth/client.js";
2
+ import { type HttpConfig } from "../http.js";
3
+ import { type FunctionsError } from "./errors.js";
4
+ export type FunctionInvokeOptions = {
5
+ /**
6
+ * An object or array goes as JSON, a string as text, a Blob or bytes as
7
+ * `application/octet-stream`; FormData, URLSearchParams and a
8
+ * ReadableStream go as they are. Your own `content-type` wins.
9
+ */
10
+ body?: string | number | boolean | object | null;
11
+ /** `apikey` is always the client's; an `authorization` of yours is sent instead of the user's. */
12
+ headers?: Record<string, string> | Headers;
13
+ /** Default POST. */
14
+ method?: "GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE";
15
+ /**
16
+ * `timeout` (ms) counts the whole call — the wait for a sign-in the page
17
+ * URL carried, a token renewal and one retry included — until the final
18
+ * answer's headers arrive. The body is not timed. `signal` stops the
19
+ * call at any of these waits; the sign-in and the renewal go on for the
20
+ * rest of the page.
21
+ */
22
+ timeout?: number;
23
+ signal?: AbortSignal;
24
+ /** Taken and ignored, as supabase-js callers pass it: Naro runs a function where Cloudflare does. */
25
+ region?: string;
26
+ };
27
+ /** Like every call's: `{ data, error }`, with the Response when one came. */
28
+ export type FunctionsResponse<T> = {
29
+ data: T;
30
+ error: null;
31
+ response: Response;
32
+ } | {
33
+ data: null;
34
+ error: FunctionsError;
35
+ response?: Response;
36
+ };
37
+ /**
38
+ * `/functions/` + the name, encoded, + whatever path and query follow it,
39
+ * as they are (plan P4): an encoded subpath is not encoded twice.
40
+ */
41
+ export declare function functionPath(name: string): string;
42
+ /**
43
+ * `naro.functions` (original spec §12.1, design §9): calls the project's
44
+ * functions at `/_naro/v1/functions/<name>` with the anon key and the
45
+ * signed-in user's access token — the one Data API and Storage send,
46
+ * renewed the same way. Resolves in every case.
47
+ */
48
+ export declare class FunctionsClient {
49
+ #private;
50
+ constructor(http: HttpConfig, auth: AuthClient);
51
+ invoke<T = unknown>(name: string, options?: FunctionInvokeOptions): Promise<FunctionsResponse<T>>;
52
+ }
@@ -0,0 +1,38 @@
1
+ export declare class FunctionsError<Context = unknown> extends Error {
2
+ readonly code: string;
3
+ readonly details?: unknown;
4
+ readonly context: Context;
5
+ constructor(code: string, message: string, context: Context, details?: unknown);
6
+ }
7
+ /** The function answered 4xx or 5xx — its own answer, wrapper errors included. */
8
+ export declare class FunctionsHttpError extends FunctionsError<Response> {
9
+ constructor(response: Response);
10
+ }
11
+ /** Naro answered instead of the function (`x-relay-error: true`): the dispatcher or the gate. */
12
+ export declare class FunctionsRelayError extends FunctionsError<Response> {
13
+ constructor(code: string, message: string, response: Response, details?: unknown);
14
+ }
15
+ /**
16
+ * No answer came back, `invoke` could not send what it was given, or a 2xx
17
+ * body could not be read as its content type says (INVALID_RESPONSE — the
18
+ * response is beside it).
19
+ */
20
+ export declare class FunctionsFetchError extends FunctionsError<unknown> {
21
+ constructor(code: string, message: string, cause: unknown, details?: unknown);
22
+ }
23
+ /** The SDK's own words for what never reached a function (plan P5). */
24
+ export declare const FUNCTIONS_MESSAGES: {
25
+ readonly timeout: (ms: number) => string;
26
+ readonly aborted: "The function call was stopped before the function answered.";
27
+ readonly invalidBody: "functions.invoke could not send this body: JSON cannot hold it (a BigInt or a cycle). Pass a string, a Blob, bytes, FormData, URLSearchParams or a stream instead.";
28
+ readonly invalidTimeout: "functions.invoke's timeout is whole milliseconds from 1 to 2147483647.";
29
+ readonly invalidHeaders: "functions.invoke's headers are not valid HTTP header names and values.";
30
+ readonly invalidName: "functions.invoke's name is a string: the function's name, then any path and query.";
31
+ readonly unencodableName: "functions.invoke's name is not well-formed Unicode: it has a lone surrogate.";
32
+ readonly dotSegments: 'functions.invoke\'s name cannot be "." or "..", and ".." in its path cannot leave /functions/.';
33
+ readonly invalidSignal: "functions.invoke's signal is not an AbortSignal.";
34
+ readonly bodyWithGetOrHead: "functions.invoke cannot send a body with GET or HEAD.";
35
+ /** `RELAY_ERROR`: a HEAD answer has no body, so Naro's code is not in it. */
36
+ readonly headRelay: (status: number) => string;
37
+ readonly unreadable: (status: number) => string;
38
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naro-js",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Auth, data and files for your Naro project, from the browser or the server.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -8,10 +8,21 @@
8
8
  "dist"
9
9
  ],
10
10
  "types": "./dist/index.d.ts",
11
+ "typesVersions": {
12
+ "*": {
13
+ "functions": [
14
+ "./dist/functions.d.ts"
15
+ ]
16
+ }
17
+ },
11
18
  "exports": {
12
19
  ".": {
13
20
  "types": "./dist/index.d.ts",
14
21
  "default": "./dist/index.js"
22
+ },
23
+ "./functions": {
24
+ "types": "./dist/functions.d.ts",
25
+ "default": "./dist/functions.js"
15
26
  }
16
27
  },
17
28
  "publishConfig": {
@@ -25,8 +36,9 @@
25
36
  "vitest": "3.2.7",
26
37
  "@next-deploy/config": "0.1.0",
27
38
  "@next-deploy/data-core": "0.1.0",
28
- "@next-deploy/backend-worker": "0.1.0",
29
- "@next-deploy/sdk": "0.1.0"
39
+ "@next-deploy/sdk": "0.1.0",
40
+ "@next-deploy/functions-runtime": "0.1.0",
41
+ "@next-deploy/backend-worker": "0.1.0"
30
42
  },
31
43
  "scripts": {
32
44
  "build": "tsup && pnpm build:types",