@protobase/client 0.21.6 → 0.21.7
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/client.d.ts +4 -1
- package/dist/client.js +32 -1
- package/dist/index.d.ts +2 -2
- package/dist/routed-client.d.ts +2 -2
- package/dist/routed-client.js +6 -3
- package/dist/types.d.ts +37 -0
- package/package.json +3 -3
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FilterInput, ListParams, MapParams } from "./query-string.js";
|
|
2
2
|
import { ClientOptions } from "./transport.js";
|
|
3
3
|
import { UploadProgress } from "./upload-request.js";
|
|
4
|
-
import { Aggregate, AggregateParams, BatchOp, BatchResult, Facet, Histogram, HistoryPage, ListPage, MapResult, MetaResult, RecordOf, ResourceRef, Series, SeriesParams, Stored } from "./types.js";
|
|
4
|
+
import { Aggregate, AggregateParams, BatchOp, BatchResult, Facet, FormChallenge, FormProof, Histogram, HistoryPage, ListPage, MapResult, MetaResult, PublicForm, RecordOf, ResourceRef, Series, SeriesParams, Stored } from "./types.js";
|
|
5
5
|
import { KeyValue } from "@protobase/schema";
|
|
6
6
|
//#region src/client.d.ts
|
|
7
7
|
/** How `invoke` calls a function: GET without a body, POST with one, unless `method` says otherwise. */
|
|
@@ -80,6 +80,9 @@ export declare const createClient: (options?: ClientOptions) => {
|
|
|
80
80
|
}) => Promise<MetaResult>;
|
|
81
81
|
invoke: <T = unknown>(name: string, { method, body, path, query, headers }?: InvokeOptions) => Promise<T>;
|
|
82
82
|
upload: (resource: ResourceRef, field: string, file: Blob, { onProgress, signal }?: UploadOptions) => Promise<UploadResult>;
|
|
83
|
+
form: (name: string) => Promise<PublicForm>;
|
|
84
|
+
formChallenge: (name: string) => Promise<FormChallenge>;
|
|
85
|
+
submitForm: (name: string, values: Record<string, unknown>, proof: FormProof) => Promise<void>;
|
|
83
86
|
};
|
|
84
87
|
export type Client = ReturnType<typeof createClient>;
|
|
85
88
|
//#endregion
|
package/dist/client.js
CHANGED
|
@@ -323,6 +323,34 @@ const createClient = (options = {}) => {
|
|
|
323
323
|
onProgress?.(file.size, file.size);
|
|
324
324
|
return result;
|
|
325
325
|
};
|
|
326
|
+
const formPath = (name) => `/forms/${encodeURIComponent(name)}`;
|
|
327
|
+
/** The public form `name` (`GET /api/forms/<name>`): its fields as `/meta` would give them, its title and thanks text. */
|
|
328
|
+
const form = async (name) => (await send({
|
|
329
|
+
method: "GET",
|
|
330
|
+
path: formPath(name),
|
|
331
|
+
system: true
|
|
332
|
+
})).json();
|
|
333
|
+
/** A fresh bot check for the public form `name`, to solve with `altcha-lib`'s `solveChallenge` before sending it. */
|
|
334
|
+
const formChallenge = async (name) => (await send({
|
|
335
|
+
method: "GET",
|
|
336
|
+
path: `${formPath(name)}:challenge`,
|
|
337
|
+
system: true
|
|
338
|
+
})).json();
|
|
339
|
+
/**
|
|
340
|
+
* Sends the public form `name`: creates its record from `values`, with the solved bot check. Rejects with `ApiError`
|
|
341
|
+
* as a create does, a refused check as `bot-check-failed` and too many submissions as `too-many-submissions`.
|
|
342
|
+
*/
|
|
343
|
+
const submitForm = async (name, values, proof) => {
|
|
344
|
+
await send({
|
|
345
|
+
method: "POST",
|
|
346
|
+
path: formPath(name),
|
|
347
|
+
body: {
|
|
348
|
+
values,
|
|
349
|
+
proof
|
|
350
|
+
},
|
|
351
|
+
system: true
|
|
352
|
+
});
|
|
353
|
+
};
|
|
326
354
|
return {
|
|
327
355
|
list,
|
|
328
356
|
search,
|
|
@@ -342,7 +370,10 @@ const createClient = (options = {}) => {
|
|
|
342
370
|
seek,
|
|
343
371
|
meta,
|
|
344
372
|
invoke,
|
|
345
|
-
upload
|
|
373
|
+
upload,
|
|
374
|
+
form,
|
|
375
|
+
formChallenge,
|
|
376
|
+
submitForm
|
|
346
377
|
};
|
|
347
378
|
};
|
|
348
379
|
//#endregion
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FilterInput, ListParams, MapParams, filterText, listWire } from "./query-string.js";
|
|
2
2
|
import { ClientOptions } from "./transport.js";
|
|
3
3
|
import { UploadProgress } from "./upload-request.js";
|
|
4
|
-
import { Aggregate, AggregateGroup, AggregateParams, BatchOp, BatchRef, BatchResult, Facet, Histogram, HistogramBucket, HistoryChange, HistoryPage, ListPage, MapBounds, MapBucket, MapLayerModel, MapResult, Meta, MetaResult, PluginRef, RecordOf, RecordPermissions, RecordPhotos, RelatedLabels, ResourcePermissions, ResourceRef, Series, SeriesParams, SeriesPoint, SourceRef, Stored, StoredFile, StoredFileVariant } from "./types.js";
|
|
4
|
+
import { Aggregate, AggregateGroup, AggregateParams, BatchOp, BatchRef, BatchResult, Facet, FormChallenge, FormProof, Histogram, HistogramBucket, HistoryChange, HistoryPage, ListPage, MapBounds, MapBucket, MapLayerModel, MapResult, Meta, MetaResult, PluginRef, PublicForm, RecordOf, RecordPermissions, RecordPhotos, RelatedLabels, ResourcePermissions, ResourceRef, Series, SeriesParams, SeriesPoint, SourceRef, Stored, StoredFile, StoredFileVariant } from "./types.js";
|
|
5
5
|
import { Client, InvokeOptions, UploadOptions, UploadResult, createClient } from "./client.js";
|
|
6
6
|
import { ApiError, PreconditionFailedError, ProblemDetails, ProblemError, isApiError } from "./problem.js";
|
|
7
7
|
import { fileUrl } from "./file-urls.js";
|
|
@@ -18,4 +18,4 @@ import { AuthSession, AuthSessionOptions, createAuthSession, tokenExpiry } from
|
|
|
18
18
|
import { createStaticSession } from "./static-session.js";
|
|
19
19
|
import { AssistantClient, AssistantClientOptions, AssistantConnection, createAssistantClient } from "./assistant.js";
|
|
20
20
|
import { RuntimeClient, RuntimeClientOptions, RuntimeLastUpdate, RuntimePolicy, RuntimeStatus, RuntimeUpdateStage, createRuntimeClient } from "./runtime.js";
|
|
21
|
-
export { type AccountSecurity, type AccountSignIn, type ActiveRole, type Aggregate, type AggregateGroup, type AggregateParams, ApiError, type AssistantClient, type AssistantClientOptions, type AssistantConnection, AuthError, type AuthSession, type AuthSessionOptions, type AuthUser, type AuthenticatorSetup, type BatchOp, type BatchRef, type BatchResult, type Client, type ClientOptions, type CurrentOrganization, type Facet, type FilterInput, type Histogram, type HistogramBucket, type HistoryChange, type HistoryPage, type InvitationPreview, type InvitationSent, type InvokeOptions, type ListPage, type ListParams, type MapBounds, type MapBucket, type MapLayerModel, type MapParams, type MapResult, type Meta, type MetaResult, type Organization, type OrganizationInvitation, type OrganizationMember, type OrganizationRole, type OrganizationsClient, type Passkey, type PlatformSignIn, type PluginRef, PreconditionFailedError, type ProblemDetails, type ProblemError, type RecordOf, type RecordPermissions, type RecordPhotos, type RelatedLabels, type RequiredSetup, type ResourcePermissions, type ResourceRef, type RoleLabel, type RoleOption, type RolesClient, type RuntimeClient, type RuntimeClientOptions, type RuntimeLastUpdate, type RuntimePolicy, type RuntimeStatus, type RuntimeUpdateStage, type Series, type SeriesParams, type SeriesPoint, type SetupStatus, type SignInMethod, type SignInPolicy, type SignInPolicyClient, type SignInPolicyState, type SignInResult, type SignInRule, type SourceMeta, type SourceRef, type StaffAccessRule, type StaffSignIn, type StaffSignInClient, type Stored, type StoredFile, type StoredFileVariant, type TwoFactorMethod, type UploadOptions, type UploadProgress, type UploadResult, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, fileUrl, filterText, isApiError, listWire, routedClient, sourceMeta, tokenExpiry };
|
|
21
|
+
export { type AccountSecurity, type AccountSignIn, type ActiveRole, type Aggregate, type AggregateGroup, type AggregateParams, ApiError, type AssistantClient, type AssistantClientOptions, type AssistantConnection, AuthError, type AuthSession, type AuthSessionOptions, type AuthUser, type AuthenticatorSetup, type BatchOp, type BatchRef, type BatchResult, type Client, type ClientOptions, type CurrentOrganization, type Facet, type FilterInput, type FormChallenge, type FormProof, type Histogram, type HistogramBucket, type HistoryChange, type HistoryPage, type InvitationPreview, type InvitationSent, type InvokeOptions, type ListPage, type ListParams, type MapBounds, type MapBucket, type MapLayerModel, type MapParams, type MapResult, type Meta, type MetaResult, type Organization, type OrganizationInvitation, type OrganizationMember, type OrganizationRole, type OrganizationsClient, type Passkey, type PlatformSignIn, type PluginRef, PreconditionFailedError, type ProblemDetails, type ProblemError, type PublicForm, type RecordOf, type RecordPermissions, type RecordPhotos, type RelatedLabels, type RequiredSetup, type ResourcePermissions, type ResourceRef, type RoleLabel, type RoleOption, type RolesClient, type RuntimeClient, type RuntimeClientOptions, type RuntimeLastUpdate, type RuntimePolicy, type RuntimeStatus, type RuntimeUpdateStage, type Series, type SeriesParams, type SeriesPoint, type SetupStatus, type SignInMethod, type SignInPolicy, type SignInPolicyClient, type SignInPolicyState, type SignInResult, type SignInRule, type SourceMeta, type SourceRef, type StaffAccessRule, type StaffSignIn, type StaffSignInClient, type Stored, type StoredFile, type StoredFileVariant, type TwoFactorMethod, type UploadOptions, type UploadProgress, type UploadResult, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, fileUrl, filterText, isApiError, listWire, routedClient, sourceMeta, tokenExpiry };
|
package/dist/routed-client.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { Client } from "./client.js";
|
|
|
2
2
|
//#region src/routed-client.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* One client over the app's own API and the sources it draws resources from: a call about a resource goes to the API
|
|
5
|
-
* that serves it (`sourceOf` gives a source's client, or `undefined` for the app's own), and `meta
|
|
6
|
-
* the app's own. A batch goes to the one API all its writes are for; one that writes to two cannot be atomic, so it is
|
|
5
|
+
* that serves it (`sourceOf` gives a source's client, or `undefined` for the app's own), and `meta`, `invoke` and the
|
|
6
|
+
* public forms go to the app's own. A batch goes to the one API all its writes are for; one that writes to two cannot be atomic, so it is
|
|
7
7
|
* refused before anything is sent.
|
|
8
8
|
*/
|
|
9
9
|
export declare const routedClient: (own: Client, sourceOf: (resource: string) => Client | undefined) => Client;
|
package/dist/routed-client.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
const nameOf = (resource) => typeof resource === "string" ? resource : resource.toModel().name;
|
|
3
3
|
/**
|
|
4
4
|
* One client over the app's own API and the sources it draws resources from: a call about a resource goes to the API
|
|
5
|
-
* that serves it (`sourceOf` gives a source's client, or `undefined` for the app's own), and `meta
|
|
6
|
-
* the app's own. A batch goes to the one API all its writes are for; one that writes to two cannot be atomic, so it is
|
|
5
|
+
* that serves it (`sourceOf` gives a source's client, or `undefined` for the app's own), and `meta`, `invoke` and the
|
|
6
|
+
* public forms go to the app's own. A batch goes to the one API all its writes are for; one that writes to two cannot be atomic, so it is
|
|
7
7
|
* refused before anything is sent.
|
|
8
8
|
*/
|
|
9
9
|
const routedClient = (own, sourceOf) => {
|
|
@@ -31,7 +31,10 @@ const routedClient = (own, sourceOf) => {
|
|
|
31
31
|
seek: (resource, params) => to(resource).seek(resource, params),
|
|
32
32
|
meta: (etag, options) => own.meta(etag, options),
|
|
33
33
|
invoke: (name, options) => own.invoke(name, options),
|
|
34
|
-
upload: (resource, field, file, options) => to(resource).upload(resource, field, file, options)
|
|
34
|
+
upload: (resource, field, file, options) => to(resource).upload(resource, field, file, options),
|
|
35
|
+
form: (name) => own.form(name),
|
|
36
|
+
formChallenge: (name) => own.formChallenge(name),
|
|
37
|
+
submitForm: (name, values, proof) => own.submitForm(name, values, proof)
|
|
35
38
|
};
|
|
36
39
|
};
|
|
37
40
|
//#endregion
|
package/dist/types.d.ts
CHANGED
|
@@ -34,6 +34,43 @@ export type HistoryChange = {
|
|
|
34
34
|
/** The database role that wrote; `null` when unknown. */
|
|
35
35
|
databaseRole: string | null;
|
|
36
36
|
};
|
|
37
|
+
/** A public form as `/-/forms/<name>` draws it: its fields as `/meta` would give them, with their hints, and no more. */
|
|
38
|
+
export type PublicForm = {
|
|
39
|
+
name: string;
|
|
40
|
+
/** The page's heading, when the form gives one; else the view's singular name. */
|
|
41
|
+
title?: string;
|
|
42
|
+
/** The fields a visitor fills in, in order. */
|
|
43
|
+
fields: string[];
|
|
44
|
+
/** What the page shows once the form is sent. */
|
|
45
|
+
thanks: string;
|
|
46
|
+
/** The resource restricted to the form's fields (and its key). */
|
|
47
|
+
resource: ResourceModel;
|
|
48
|
+
/** The view's names and the form fields' hints. */
|
|
49
|
+
view: ViewModel;
|
|
50
|
+
};
|
|
51
|
+
/** A public form's bot check as the server hands it out: an ALTCHA proof-of-work challenge, solved with `altcha-lib`. */
|
|
52
|
+
export type FormChallenge = {
|
|
53
|
+
parameters: {
|
|
54
|
+
algorithm: string;
|
|
55
|
+
nonce: string;
|
|
56
|
+
salt: string;
|
|
57
|
+
cost: number;
|
|
58
|
+
keyLength: number;
|
|
59
|
+
keyPrefix: string;
|
|
60
|
+
keySignature?: string;
|
|
61
|
+
expiresAt?: number;
|
|
62
|
+
data?: Record<string, string | number | boolean | null>;
|
|
63
|
+
};
|
|
64
|
+
signature?: string;
|
|
65
|
+
};
|
|
66
|
+
/** A solved bot check, sent with the form: the challenge as it came, and the solver's answer. */
|
|
67
|
+
export type FormProof = {
|
|
68
|
+
challenge: FormChallenge;
|
|
69
|
+
solution: {
|
|
70
|
+
counter: number;
|
|
71
|
+
derivedKey: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
37
74
|
/** A page of a record's history, newest first. */
|
|
38
75
|
export type HistoryPage = {
|
|
39
76
|
items: HistoryChange[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/client",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.7",
|
|
4
4
|
"description": "Typed fetch client for the Protobase REST API.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@better-auth/passkey": "^1.7.7",
|
|
33
|
-
"@protobase/layout": "0.21.
|
|
34
|
-
"@protobase/schema": "0.21.
|
|
33
|
+
"@protobase/layout": "0.21.7",
|
|
34
|
+
"@protobase/schema": "0.21.7",
|
|
35
35
|
"@simplewebauthn/browser": "^13.3.0",
|
|
36
36
|
"better-auth": "^1.7.7"
|
|
37
37
|
}
|