@protobase/client 0.3.3 → 0.3.5

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.d.ts CHANGED
@@ -5,4 +5,5 @@ import { Client, createClient } from "./client.js";
5
5
  import { ApiError, PreconditionFailedError, ProblemDetails, ProblemError, isApiError } from "./problem.js";
6
6
  import { AuthError, AuthSession, AuthSessionOptions, AuthUser, SetupStatus, createAuthSession, createStaticSession, tokenExpiry } from "./auth.js";
7
7
  import { AssistantClient, AssistantClientOptions, AssistantConnection, createAssistantClient } from "./assistant.js";
8
- export { ApiError, type AssistantClient, type AssistantClientOptions, type AssistantConnection, AuthError, type AuthSession, type AuthSessionOptions, type AuthUser, type BatchOp, type BatchRef, type BatchResult, type Client, type ClientOptions, type Facet, type FilterInput, type Histogram, type HistogramBucket, type ListPage, type ListParams, type Meta, type MetaResult, PreconditionFailedError, type ProblemDetails, type ProblemError, type RecordOf, type RecordPermissions, type ResourcePermissions, type ResourceRef, type Series, type SeriesParams, type SeriesPoint, type SetupStatus, type Stored, createAssistantClient, createAuthSession, createClient, createStaticSession, filterText, isApiError, listWire, tokenExpiry };
8
+ import { RuntimeClient, RuntimeClientOptions, RuntimePolicy, RuntimeStatus, createRuntimeClient } from "./runtime.js";
9
+ export { ApiError, type AssistantClient, type AssistantClientOptions, type AssistantConnection, AuthError, type AuthSession, type AuthSessionOptions, type AuthUser, type BatchOp, type BatchRef, type BatchResult, type Client, type ClientOptions, type Facet, type FilterInput, type Histogram, type HistogramBucket, type ListPage, type ListParams, type Meta, type MetaResult, PreconditionFailedError, type ProblemDetails, type ProblemError, type RecordOf, type RecordPermissions, type ResourcePermissions, type ResourceRef, type RuntimeClient, type RuntimeClientOptions, type RuntimePolicy, type RuntimeStatus, type Series, type SeriesParams, type SeriesPoint, type SetupStatus, type Stored, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, filterText, isApiError, listWire, tokenExpiry };
package/dist/index.js CHANGED
@@ -3,4 +3,5 @@ import { ApiError, PreconditionFailedError, isApiError } from "./problem.js";
3
3
  import { createClient } from "./client.js";
4
4
  import { AuthError, createAuthSession, createStaticSession, tokenExpiry } from "./auth.js";
5
5
  import { createAssistantClient } from "./assistant.js";
6
- export { ApiError, AuthError, PreconditionFailedError, createAssistantClient, createAuthSession, createClient, createStaticSession, filterText, isApiError, listWire, tokenExpiry };
6
+ import { createRuntimeClient } from "./runtime.js";
7
+ export { ApiError, AuthError, PreconditionFailedError, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, filterText, isApiError, listWire, tokenExpiry };
@@ -0,0 +1,32 @@
1
+ //#region src/runtime.d.ts
2
+ export type RuntimePolicy = 'immediate' | 'weekly' | 'scheduled' | 'manual';
3
+ /**
4
+ * What the runtime endpoint answers: the app's pinned `version`, the `latest` release, whether to show that an update
5
+ * is available (`indicator`), when the `policy` applies `latest` (`nextUpdateAt`, null when it never will or nothing
6
+ * is pending) and whether an update is running.
7
+ */
8
+ export type RuntimeStatus = {
9
+ version: string;
10
+ latest: string;
11
+ updateAvailable: boolean;
12
+ indicator: boolean;
13
+ policy: RuntimePolicy;
14
+ nextUpdateAt: string | null;
15
+ updating: boolean;
16
+ };
17
+ export type RuntimeClientOptions = {
18
+ /** The runtime endpoint, as `/api/meta` names it. */
19
+ url: string;
20
+ /** The signed-in user's API token, sent as the bearer token of every request. */
21
+ token: () => string | undefined | Promise<string | undefined>;
22
+ fetch?: typeof fetch;
23
+ };
24
+ export type RuntimeClient = {
25
+ /** `GET {url}`. Rejects with `ApiError`. */
26
+ status: () => Promise<RuntimeStatus>;
27
+ /** `POST {url}/update`: applies the latest version now. Rejects with `ApiError`, status 409 when already on it or an update is running. */
28
+ update: () => Promise<RuntimeStatus>;
29
+ };
30
+ /** A client of the runtime endpoint, with the user's token. */
31
+ export declare const createRuntimeClient: (options: RuntimeClientOptions) => RuntimeClient;
32
+ //#endregion
@@ -0,0 +1,25 @@
1
+ import { readProblem } from "./problem.js";
2
+ //#region src/runtime.ts
3
+ /** A client of the runtime endpoint, with the user's token. */
4
+ const createRuntimeClient = (options) => {
5
+ const base = options.url.replace(/\/+$/, "");
6
+ const doFetch = options.fetch ?? ((input, init) => fetch(input, init));
7
+ const request = async (path, method) => {
8
+ const token = await options.token();
9
+ const response = await doFetch(`${base}${path}`, {
10
+ method,
11
+ headers: {
12
+ accept: "application/json",
13
+ ...token && { authorization: `Bearer ${token}` }
14
+ }
15
+ });
16
+ if (!response.ok) throw await readProblem(response);
17
+ return await response.json();
18
+ };
19
+ return {
20
+ status: () => request("", "GET"),
21
+ update: () => request("/update", "POST")
22
+ };
23
+ };
24
+ //#endregion
25
+ export { createRuntimeClient };
package/dist/types.d.ts CHANGED
@@ -62,7 +62,10 @@ export type ResourcePermissions = {
62
62
  delete: boolean;
63
63
  conditional: Array<'create' | 'update' | 'delete'>;
64
64
  };
65
- /** `assistant`: the assistant backend, for a caller with the `admin` or `ai` role when the app has one. */
65
+ /**
66
+ * `assistant`: the assistant backend, for a caller with the `admin` or `ai` role when the app has one.
67
+ * `runtime`: the runtime updates endpoint, for a caller with the `admin` role when the app has one.
68
+ */
66
69
  export type Meta = {
67
70
  resources: ResourceModel[];
68
71
  views: ViewModel[];
@@ -72,6 +75,9 @@ export type Meta = {
72
75
  assistant?: {
73
76
  url: string;
74
77
  };
78
+ runtime?: {
79
+ url: string;
80
+ };
75
81
  };
76
82
  export type MetaResult = {
77
83
  status: 'modified';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/client",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Typed fetch client for the Protobase REST API.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -21,15 +21,16 @@
21
21
  "files": [
22
22
  "dist"
23
23
  ],
24
+ "scripts": {
25
+ "build": "tsdown",
26
+ "prepack": "tsdown"
27
+ },
24
28
  "publishConfig": {
25
29
  "access": "public"
26
30
  },
27
31
  "dependencies": {
28
- "better-auth": "^1.7.7",
29
- "@protobase/layout": "0.3.3",
30
- "@protobase/schema": "0.3.3"
31
- },
32
- "scripts": {
33
- "build": "tsdown"
32
+ "@protobase/layout": "0.3.5",
33
+ "@protobase/schema": "0.3.5",
34
+ "better-auth": "^1.7.7"
34
35
  }
35
- }
36
+ }