naro-js 0.1.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.
- package/README.md +334 -0
- package/dist/auth/client.d.ts +122 -0
- package/dist/auth/flow-errors.d.ts +4 -0
- package/dist/auth/flows.d.ts +17 -0
- package/dist/auth/pkce.d.ts +10 -0
- package/dist/auth/recovery.d.ts +15 -0
- package/dist/auth/storage.d.ts +61 -0
- package/dist/client.d.ts +61 -0
- package/dist/errors.d.ts +51 -0
- package/dist/http.d.ts +61 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1733 -0
- package/dist/query/builder.d.ts +211 -0
- package/dist/query/columns.d.ts +15 -0
- package/dist/query/filters.d.ts +63 -0
- package/dist/query/selected.d.ts +35 -0
- package/dist/runtime.d.ts +13 -0
- package/dist/types.d.ts +186 -0
- package/dist/wire.d.ts +61 -0
- package/package.json +37 -0
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every failure the SDK hands back (spec §15). The Naro worker's errors
|
|
3
|
+
* (spec §14) arrive as they are; the SDK makes its own only for what never
|
|
4
|
+
* got a readable answer from the worker, and for queries it can tell are
|
|
5
|
+
* malformed before sending them. The messages are a contract — spec §15's
|
|
6
|
+
* "(P1-4 구현 결정)" block quotes them.
|
|
7
|
+
*/
|
|
8
|
+
export type NaroError = {
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
details?: unknown;
|
|
12
|
+
};
|
|
13
|
+
/** Spec §14, word for word; `wire.test.ts` compares it with data-core's. */
|
|
14
|
+
export declare const INVALID_QUERY_MESSAGE = "The query is not a valid Naro query.";
|
|
15
|
+
/** Spec §14, word for word; `wire.test.ts` compares it with data-core's. */
|
|
16
|
+
export declare const INVALID_SESSION_MESSAGE = "The session is expired or not valid. Sign in again.";
|
|
17
|
+
/** fetch threw, or the response body broke off: nothing reached us. */
|
|
18
|
+
export declare function networkError(cause: unknown): NaroError;
|
|
19
|
+
/**
|
|
20
|
+
* A request with a deadline that passed without an answer — the sign-in
|
|
21
|
+
* code exchange a page runs on load (PR #68 review 10). It is called off.
|
|
22
|
+
*/
|
|
23
|
+
export declare function requestTimeout(ms: number): NaroError;
|
|
24
|
+
/** An answer, but not one a Naro worker gives: HTML, empty, or the wrong shape. */
|
|
25
|
+
export declare function invalidResponse(status: number): NaroError;
|
|
26
|
+
/**
|
|
27
|
+
* The worker's INVALID_QUERY, raised before sending when the builder can
|
|
28
|
+
* already tell (an empty column name, a backwards range). `path` names the
|
|
29
|
+
* AST field or the builder method, as the worker's `details.path` does.
|
|
30
|
+
*/
|
|
31
|
+
export declare function invalidQuery(path: string, reason: string): NaroError;
|
|
32
|
+
/** The worker's INVALID_SESSION, for a stored token get-session no longer knows. */
|
|
33
|
+
export declare function invalidSession(): NaroError;
|
|
34
|
+
/** A code came back to a browser that holds no verifier for it. */
|
|
35
|
+
export declare function codeVerifierMissing(): NaroError;
|
|
36
|
+
/** `updateUser({ password })` with no reset link opened. */
|
|
37
|
+
export declare function passwordRecoveryRequired(): NaroError;
|
|
38
|
+
/** `signInWithOAuth` with a provider the worker does not know. */
|
|
39
|
+
export declare function invalidProvider(): NaroError;
|
|
40
|
+
/** No `crypto.subtle`: an http page that is not localhost. */
|
|
41
|
+
export declare function cryptoUnavailable(): NaroError;
|
|
42
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* The error a response carries, or null when it carries none. Every error
|
|
45
|
+
* under `/_naro/v1` comes as `{ data: null, error: { code, message,
|
|
46
|
+
* details? } }` — the worker wraps Better Auth's too (spec §14, P1-2 리뷰
|
|
47
|
+
* 반영). Better Auth's success bodies are not wrapped, so a 2xx without an
|
|
48
|
+
* `error` is not an error; a failing status without the envelope is not a
|
|
49
|
+
* Naro answer at all (a proxy's HTML page, the app's own 404).
|
|
50
|
+
*/
|
|
51
|
+
export declare function errorFromBody(status: number, body: unknown): NaroError | null;
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { TokenStore } from "./auth/storage.js";
|
|
2
|
+
import { type NaroError } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* What the SDK needs from `fetch`. The global one fits, and so does a plain
|
|
5
|
+
* function, e.g. one that hands the request to a worker's fetch handler in a
|
|
6
|
+
* test. It is always called as a plain function, never as a method, so an
|
|
7
|
+
* unbound `window.fetch` works.
|
|
8
|
+
*/
|
|
9
|
+
export type FetchLike = (input: string, init: RequestInit) => Promise<Response>;
|
|
10
|
+
export type HttpConfig = {
|
|
11
|
+
/** The project URL without a trailing slash. */
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
apiKey: string;
|
|
14
|
+
fetch: FetchLike | undefined;
|
|
15
|
+
tokens: TokenStore;
|
|
16
|
+
};
|
|
17
|
+
export type CallOptions = {
|
|
18
|
+
method: "GET" | "POST";
|
|
19
|
+
/** Below `/_naro/v1`, e.g. `/data/query`. */
|
|
20
|
+
path: string;
|
|
21
|
+
/** Sent as JSON. */
|
|
22
|
+
body?: unknown;
|
|
23
|
+
/** Whether to send the stored session token. */
|
|
24
|
+
withToken: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Give up after this long: the request is aborted (where the runtime has
|
|
27
|
+
* AbortController) and the call answers TIMEOUT. None by default.
|
|
28
|
+
*/
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
};
|
|
31
|
+
/** A response the SDK could read: a JSON body (or none) and its headers. */
|
|
32
|
+
export type Answer = {
|
|
33
|
+
status: number;
|
|
34
|
+
headers: Headers;
|
|
35
|
+
/** The parsed JSON body; undefined when the body was empty. */
|
|
36
|
+
body: unknown;
|
|
37
|
+
/** The token this request carried, if any. */
|
|
38
|
+
token: string | null;
|
|
39
|
+
};
|
|
40
|
+
export type CallResult = {
|
|
41
|
+
error: NaroError;
|
|
42
|
+
answer: Answer | null;
|
|
43
|
+
} | {
|
|
44
|
+
error: null;
|
|
45
|
+
answer: Answer;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* One request to the Naro worker (spec §8.3): `apikey` always, `Authorization:
|
|
49
|
+
* Bearer` when signed in, never cookies. Resolves in every case — a failed
|
|
50
|
+
* fetch, an unreadable body and a worker error all come back as `error`.
|
|
51
|
+
*
|
|
52
|
+
* An INVALID_SESSION answer from any route clears the stored token (spec
|
|
53
|
+
* §11.1), but only if it is still the token this request carried.
|
|
54
|
+
*/
|
|
55
|
+
export declare function call(config: HttpConfig, options: CallOptions): Promise<CallResult>;
|
|
56
|
+
/**
|
|
57
|
+
* The worker's two 429s. `RATE_LIMITED` is Better Auth's limiter;
|
|
58
|
+
* `WRITE_QUOTA_EXCEEDED` (PR C) is the project over its daily database write
|
|
59
|
+
* limit — Data API writes and sign-up wait for 00:00 UTC, reads still work.
|
|
60
|
+
*/
|
|
61
|
+
export declare const RETRY_AFTER_CODES: ReadonlySet<string>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createClient, NaroClient, type ClientOptions } from "./client.js";
|
|
2
|
+
export type { AuthClient } from "./auth/client.js";
|
|
3
|
+
export type { AuthStorage } from "./auth/storage.js";
|
|
4
|
+
export type { NaroError } from "./errors.js";
|
|
5
|
+
export type { FetchLike } from "./http.js";
|
|
6
|
+
export type { ArrayValues, FilterGroup, FilterGroupCallback, InsertBuilder, MatchQuery, MutationBuilder, RawFilterValue, SelectBuilder, TableBuilder, } from "./query/builder.js";
|
|
7
|
+
export { quoteFilterValue, type FilterOperatorName } from "./query/filters.js";
|
|
8
|
+
export type { AuthActionResponse, AuthFlowType, AuthResponse, DatabaseShape, EmailRedirectOptions, OAuthProvider, OAuthResponse, SignInWithOAuthOptions, UrlSessionResponse, UserAttributes, GenericTable, GenericView, NaroResponse, OrderOptions, Session, SessionResponse, SignInCredentials, SignOutResponse, SignUpCredentials, UntypedDatabase, User, UserResponse, } from "./types.js";
|
|
9
|
+
export type { Filter, FilterNode, FilterOperator, Order, Query, Row, Value, } from "./wire.js";
|