@nohead/sdk 0.0.0 → 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.
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export {};
@@ -0,0 +1,8 @@
1
+ export { Nohead } from "./client.ts";
2
+ export { APIPromise, Page, PagePromise, type APIResponse, } from "./api-promise.ts";
3
+ export type { ClientOptions, ConditionalRequestOptions, RequestOptions, } from "./core.ts";
4
+ export { APIError, AbortError, AuthenticationError, AuthorizationError, ConflictError, ConnectionError, InternalServerError, InvalidRequestError, NoheadError, NotFoundError, PlanLimitExceededError, PreconditionFailedError, RateLimitError, ServiceUnavailableError, TimeoutError, UploadError, ValidationError, WebhookVerificationError, } from "./errors.ts";
5
+ export type { Uploadable, UploadParams } from "./resources/assets.ts";
6
+ export type * from "./types.ts";
7
+ export { unwrapWebhook, type AssetEvent, type RecordEvent, type SchemaChangedEvent, type UnwrapOptions, type WebhookEvent, type WebhookHeaders, type WebhookTestEvent, } from "./webhooks.ts";
8
+ export { VERSION } from "./version.ts";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { Nohead } from "./client.js";
2
+ export { APIPromise, Page, PagePromise, } from "./api-promise.js";
3
+ export { APIError, AbortError, AuthenticationError, AuthorizationError, ConflictError, ConnectionError, InternalServerError, InvalidRequestError, NoheadError, NotFoundError, PlanLimitExceededError, PreconditionFailedError, RateLimitError, ServiceUnavailableError, TimeoutError, UploadError, ValidationError, WebhookVerificationError, } from "./errors.js";
4
+ export { unwrapWebhook, } from "./webhooks.js";
5
+ export { VERSION } from "./version.js";
@@ -0,0 +1,44 @@
1
+ import type { APIPromise, PagePromise } from "../api-promise.ts";
2
+ import type { RequestOptions } from "../core.ts";
3
+ import type { Asset, AssetUpload, AssetUploadCreate, DownloadUrl, ImageUrl } from "../generated/types.gen.ts";
4
+ import type { DeletedListParams, ImageUrlParams } from "../types.ts";
5
+ import { Resource } from "./resource.ts";
6
+ /** What `assets.upload` accepts. A stream needs `byte_size`. */
7
+ export type Uploadable = Blob | ArrayBuffer | Uint8Array | ReadableStream;
8
+ export interface UploadParams {
9
+ /** Defaults to a `File`'s name, else `upload`. */
10
+ filename?: string;
11
+ /** Defaults to the `Blob`'s type, else `application/octet-stream`. */
12
+ content_type?: string;
13
+ /** Required for a `ReadableStream`; known for everything else. */
14
+ byte_size?: number;
15
+ }
16
+ /** Files of the key's project. `asset` is an asset ID (`ast_…`). */
17
+ export declare class Assets extends Resource {
18
+ /**
19
+ * Uploads a file and returns the `ready` asset: creates the upload, sends
20
+ * the bytes straight to storage, then completes it (which checks the
21
+ * file). Throws `UploadError` if storage refuses the bytes, and
22
+ * `ValidationError` if the file fails the checks.
23
+ *
24
+ * import { openAsBlob } from "node:fs"
25
+ * const asset = await nohead.assets.upload(await openAsBlob("a.jpg"), { filename: "a.jpg" })
26
+ */
27
+ upload(file: Uploadable, params?: UploadParams, options?: RequestOptions): Promise<Asset>;
28
+ /**
29
+ * The first step of an upload: a `pending` asset and a presigned URL to
30
+ * `PUT` the bytes to (for example from a browser). Then `complete` it.
31
+ */
32
+ createUpload(params: AssetUploadCreate, options?: RequestOptions): APIPromise<AssetUpload>;
33
+ /** Checks an uploaded file and marks the asset `ready`. */
34
+ complete(asset: string, options?: RequestOptions): APIPromise<Asset>;
35
+ list(params?: DeletedListParams, options?: RequestOptions): PagePromise<Asset>;
36
+ get(asset: string, options?: RequestOptions): APIPromise<Asset>;
37
+ /** Soft-deletes the asset; the file is purged after 30 days. */
38
+ delete(asset: string, options?: RequestOptions): APIPromise<Asset>;
39
+ restore(asset: string, options?: RequestOptions): APIPromise<Asset>;
40
+ /** A signed, cacheable URL of an image rendition (`url`). */
41
+ imageUrl(asset: string, params?: ImageUrlParams, options?: RequestOptions): APIPromise<ImageUrl>;
42
+ /** A 15-minute link to download the original file (`url`). */
43
+ downloadUrl(asset: string, options?: RequestOptions): APIPromise<DownloadUrl>;
44
+ }
@@ -0,0 +1,86 @@
1
+ import { AbortError, UploadError } from "../errors.js";
2
+ import { Resource } from "./resource.js";
3
+ /** Files of the key's project. `asset` is an asset ID (`ast_…`). */
4
+ export class Assets extends Resource {
5
+ /**
6
+ * Uploads a file and returns the `ready` asset: creates the upload, sends
7
+ * the bytes straight to storage, then completes it (which checks the
8
+ * file). Throws `UploadError` if storage refuses the bytes, and
9
+ * `ValidationError` if the file fails the checks.
10
+ *
11
+ * import { openAsBlob } from "node:fs"
12
+ * const asset = await nohead.assets.upload(await openAsBlob("a.jpg"), { filename: "a.jpg" })
13
+ */
14
+ async upload(file, params = {}, options) {
15
+ const byteSize = params.byte_size ?? sizeOf(file);
16
+ if (byteSize === undefined) {
17
+ throw new UploadError("Uploading a stream needs `byte_size`");
18
+ }
19
+ const { asset, upload } = await this.createUpload({
20
+ filename: params.filename ??
21
+ (typeof File !== "undefined" && file instanceof File
22
+ ? file.name
23
+ : "upload"),
24
+ content_type: params.content_type ??
25
+ ((file instanceof Blob && file.type) || "application/octet-stream"),
26
+ byte_size: byteSize,
27
+ }, options);
28
+ const stream = file instanceof ReadableStream;
29
+ const response = await this.core
30
+ .fetchWithRetries(upload.url, {
31
+ method: upload.method,
32
+ headers: upload.headers,
33
+ body: file,
34
+ ...(stream ? { duplex: "half" } : {}),
35
+ }, { ...options, retry: !stream })
36
+ .catch((error) => {
37
+ if (error instanceof AbortError)
38
+ throw error;
39
+ throw new UploadError(`Could not upload ${asset.filename}: ${error.message}`, undefined, { cause: error });
40
+ });
41
+ if (!response.ok) {
42
+ throw new UploadError(`Storage refused the upload of ${asset.filename} (${response.status})`, response.status);
43
+ }
44
+ return this.complete(asset.id, options);
45
+ }
46
+ /**
47
+ * The first step of an upload: a `pending` asset and a presigned URL to
48
+ * `PUT` the bytes to (for example from a browser). Then `complete` it.
49
+ */
50
+ createUpload(params, options) {
51
+ return this.core.request("assets_upload", { body: params }, options);
52
+ }
53
+ /** Checks an uploaded file and marks the asset `ready`. */
54
+ complete(asset, options) {
55
+ return this.core.request("assets_complete", { path: { asset_id: asset } }, options);
56
+ }
57
+ list(params = {}, options) {
58
+ return this.core.paginate("assets_list", { query: params }, options);
59
+ }
60
+ get(asset, options) {
61
+ return this.core.request("assets_get", { path: { asset_id: asset } }, options);
62
+ }
63
+ /** Soft-deletes the asset; the file is purged after 30 days. */
64
+ delete(asset, options) {
65
+ return this.core.request("assets_delete", { path: { asset_id: asset } }, options);
66
+ }
67
+ restore(asset, options) {
68
+ return this.core.request("assets_restore", { path: { asset_id: asset } }, options);
69
+ }
70
+ /** A signed, cacheable URL of an image rendition (`url`). */
71
+ imageUrl(asset, params = {}, options) {
72
+ return this.core.request("assets_image_url", { path: { asset_id: asset }, query: params }, options);
73
+ }
74
+ /** A 15-minute link to download the original file (`url`). */
75
+ downloadUrl(asset, options) {
76
+ return this.core.request("assets_download_url", { path: { asset_id: asset } }, options);
77
+ }
78
+ }
79
+ function sizeOf(file) {
80
+ if (file instanceof Blob)
81
+ return file.size;
82
+ if (file instanceof ArrayBuffer || ArrayBuffer.isView(file)) {
83
+ return file.byteLength;
84
+ }
85
+ return undefined;
86
+ }
@@ -0,0 +1,20 @@
1
+ import type { APIPromise, PagePromise } from "../api-promise.ts";
2
+ import type { RequestOptions } from "../core.ts";
3
+ import type { AuditEvent, FeatureFlags as FeatureFlagList, Health as HealthStatus, Principal } from "../generated/types.gen.ts";
4
+ import type { AuditEventListParams } from "../types.ts";
5
+ import { Resource } from "./resource.ts";
6
+ /** The project's activity log, newest first. Needs the `audit:read` scope. */
7
+ export declare class AuditEvents extends Resource {
8
+ list(params?: AuditEventListParams, options?: RequestOptions): PagePromise<AuditEvent>;
9
+ }
10
+ export declare class FeatureFlags extends Resource {
11
+ /** Flags evaluated for the key's project. */
12
+ list(options?: RequestOptions): APIPromise<FeatureFlagList>;
13
+ }
14
+ export declare class Me extends Resource {
15
+ /** The API key: its project, scopes, `published_only` and expiry. */
16
+ get(options?: RequestOptions): APIPromise<Principal>;
17
+ }
18
+ export declare class Health extends Resource {
19
+ check(options?: RequestOptions): APIPromise<HealthStatus>;
20
+ }
@@ -0,0 +1,24 @@
1
+ import { Resource } from "./resource.js";
2
+ /** The project's activity log, newest first. Needs the `audit:read` scope. */
3
+ export class AuditEvents extends Resource {
4
+ list(params = {}, options) {
5
+ return this.core.paginate("audit_events_list_for_project", { query: params }, options);
6
+ }
7
+ }
8
+ export class FeatureFlags extends Resource {
9
+ /** Flags evaluated for the key's project. */
10
+ list(options) {
11
+ return this.core.request("feature_flags_list", {}, options);
12
+ }
13
+ }
14
+ export class Me extends Resource {
15
+ /** The API key: its project, scopes, `published_only` and expiry. */
16
+ get(options) {
17
+ return this.core.request("me_get", {}, options);
18
+ }
19
+ }
20
+ export class Health extends Resource {
21
+ check(options) {
22
+ return this.core.request("health_check", {}, options);
23
+ }
24
+ }
@@ -0,0 +1,52 @@
1
+ import type { APIPromise, PagePromise } from "../api-promise.ts";
2
+ import type { ConditionalRequestOptions, RequestOptions } from "../core.ts";
3
+ import type { RecordData, RecordDiff, RecordRevision, RecordRevisionDetail, RevertPreview, BulkRecordsResult, RecordCount } from "../generated/types.gen.ts";
4
+ import type { DryRunParams, NoheadRecord, RecordBulkParams, RecordCountParams, RecordCreateParams, RecordDiffParams, RecordGetParams, RecordListParams, RecordScheduleParams, RecordSearchParams, RecordUpdateParams, RevisionListParams, SearchMeta } from "../types.ts";
5
+ import { Resource } from "./resource.ts";
6
+ /**
7
+ * Records: the content of a collection. `collection` is a collection ID or
8
+ * slug; `record` a record ID (`rec_…`).
9
+ */
10
+ export declare class Records extends Resource {
11
+ readonly revisions: Revisions;
12
+ /** A collection's records, newest first by default. */
13
+ list<D = RecordData>(collection: string, params?: RecordListParams, options?: RequestOptions): PagePromise<NoheadRecord<D>>;
14
+ get<D = RecordData>(record: string, params?: RecordGetParams, options?: RequestOptions): APIPromise<NoheadRecord<D>>;
15
+ /** Creates a draft. */
16
+ create<D = RecordData>(collection: string, params: RecordCreateParams<D>, options?: RequestOptions): APIPromise<NoheadRecord<D>>;
17
+ /** Sets the given fields (`null` clears one); others keep their values. */
18
+ update<D = RecordData>(record: string, params: RecordUpdateParams<D>, options?: ConditionalRequestOptions): APIPromise<NoheadRecord<D>>;
19
+ /** Soft-deletes the record: `restore` brings it back within 30 days. */
20
+ delete<D = RecordData>(record: string, options?: ConditionalRequestOptions): APIPromise<NoheadRecord<D>>;
21
+ restore<D = RecordData>(record: string, options?: RequestOptions): APIPromise<NoheadRecord<D>>;
22
+ publish<D = RecordData>(record: string, options?: ConditionalRequestOptions): APIPromise<NoheadRecord<D>>;
23
+ unpublish<D = RecordData>(record: string, options?: ConditionalRequestOptions): APIPromise<NoheadRecord<D>>;
24
+ /** Publishes and/or unpublishes the record later. */
25
+ schedule<D = RecordData>(record: string, params: RecordScheduleParams, options?: RequestOptions): APIPromise<NoheadRecord<D>>;
26
+ /** Clears both scheduled times. */
27
+ unschedule<D = RecordData>(record: string, options?: RequestOptions): APIPromise<NoheadRecord<D>>;
28
+ count(collection: string, params?: RecordCountParams, options?: RequestOptions): APIPromise<RecordCount>;
29
+ /**
30
+ * Publishes, unpublishes, deletes, restores or updates up to 100 records.
31
+ * Each record succeeds or fails on its own; see `results`.
32
+ */
33
+ bulk(collection: string, params: RecordBulkParams, options?: RequestOptions): APIPromise<BulkRecordsResult>;
34
+ /** The changes between two revisions. */
35
+ diff(record: string, params: RecordDiffParams, options?: RequestOptions): APIPromise<RecordDiff>;
36
+ /**
37
+ * Full-text search in one collection (`search_enabled` collections).
38
+ * Pages through the first 1,000 hits, most relevant first.
39
+ */
40
+ search<D = RecordData>(collection: string, query: string, params?: RecordSearchParams, options?: RequestOptions): PagePromise<NoheadRecord<D>, SearchMeta>;
41
+ }
42
+ /** A record's version history. `revision` is a revision number. */
43
+ export declare class Revisions extends Resource {
44
+ /** Newest first. */
45
+ list(record: string, params?: RevisionListParams, options?: RequestOptions): PagePromise<RecordRevision>;
46
+ get(record: string, revision: number, options?: RequestOptions): APIPromise<RecordRevisionDetail>;
47
+ /** Restores the record's data as of `revision`, as a new revision. */
48
+ revert(record: string, revision: number, params: {
49
+ dry_run: true;
50
+ }, options?: ConditionalRequestOptions): APIPromise<RevertPreview>;
51
+ revert<D = RecordData>(record: string, revision: number, params?: DryRunParams, options?: ConditionalRequestOptions): APIPromise<NoheadRecord<D>>;
52
+ }
@@ -0,0 +1,78 @@
1
+ import { Resource } from "./resource.js";
2
+ /**
3
+ * Records: the content of a collection. `collection` is a collection ID or
4
+ * slug; `record` a record ID (`rec_…`).
5
+ */
6
+ export class Records extends Resource {
7
+ revisions = new Revisions(this.core);
8
+ /** A collection's records, newest first by default. */
9
+ list(collection, params = {}, options) {
10
+ return this.core.paginate("records_list", { path: { collection_id: collection }, query: params }, options);
11
+ }
12
+ get(record, params = {}, options) {
13
+ return this.core.request("records_get", { path: { record_id: record }, query: params }, options);
14
+ }
15
+ /** Creates a draft. */
16
+ create(collection, params, options) {
17
+ return this.core.request("records_create", { path: { collection_id: collection }, body: params }, options);
18
+ }
19
+ /** Sets the given fields (`null` clears one); others keep their values. */
20
+ update(record, params, options) {
21
+ return this.core.request("records_update", { path: { record_id: record }, body: params }, options);
22
+ }
23
+ /** Soft-deletes the record: `restore` brings it back within 30 days. */
24
+ delete(record, options) {
25
+ return this.core.request("records_delete", { path: { record_id: record } }, options);
26
+ }
27
+ restore(record, options) {
28
+ return this.core.request("records_restore", { path: { record_id: record } }, options);
29
+ }
30
+ publish(record, options) {
31
+ return this.core.request("records_publish", { path: { record_id: record } }, options);
32
+ }
33
+ unpublish(record, options) {
34
+ return this.core.request("records_unpublish", { path: { record_id: record } }, options);
35
+ }
36
+ /** Publishes and/or unpublishes the record later. */
37
+ schedule(record, params, options) {
38
+ return this.core.request("records_schedule", { path: { record_id: record }, body: params }, options);
39
+ }
40
+ /** Clears both scheduled times. */
41
+ unschedule(record, options) {
42
+ return this.core.request("records_unschedule", { path: { record_id: record } }, options);
43
+ }
44
+ count(collection, params = {}, options) {
45
+ return this.core.request("records_count", { path: { collection_id: collection }, query: params }, options);
46
+ }
47
+ /**
48
+ * Publishes, unpublishes, deletes, restores or updates up to 100 records.
49
+ * Each record succeeds or fails on its own; see `results`.
50
+ */
51
+ bulk(collection, params, options) {
52
+ return this.core.request("records_bulk", { path: { collection_id: collection }, body: params }, options);
53
+ }
54
+ /** The changes between two revisions. */
55
+ diff(record, params, options) {
56
+ return this.core.request("records_diff", { path: { record_id: record }, query: params }, options);
57
+ }
58
+ /**
59
+ * Full-text search in one collection (`search_enabled` collections).
60
+ * Pages through the first 1,000 hits, most relevant first.
61
+ */
62
+ search(collection, query, params = {}, options) {
63
+ return this.core.paginate("collections_search", { path: { collection_id: collection }, query: { q: query, ...params } }, options);
64
+ }
65
+ }
66
+ /** A record's version history. `revision` is a revision number. */
67
+ export class Revisions extends Resource {
68
+ /** Newest first. */
69
+ list(record, params = {}, options) {
70
+ return this.core.paginate("record_revisions_list", { path: { record_id: record }, query: params }, options);
71
+ }
72
+ get(record, revision, options) {
73
+ return this.core.request("record_revisions_get", { path: { record_id: record, revision } }, options);
74
+ }
75
+ revert(record, revision, params = {}, options) {
76
+ return this.core.request("record_revisions_revert", { path: { record_id: record, revision }, query: params }, options);
77
+ }
78
+ }
@@ -0,0 +1,5 @@
1
+ import type { Core } from "../core.ts";
2
+ export declare abstract class Resource {
3
+ protected readonly core: Core;
4
+ constructor(core: Core);
5
+ }
@@ -0,0 +1,6 @@
1
+ export class Resource {
2
+ core;
3
+ constructor(core) {
4
+ this.core = core;
5
+ }
6
+ }
@@ -0,0 +1,64 @@
1
+ import type { APIPromise, PagePromise } from "../api-promise.ts";
2
+ import type { RequestOptions } from "../core.ts";
3
+ import type { Collection, CollectionCreate, CollectionUpdate, Field, FieldCreate, FieldMigration, FieldMigrationPreview, FieldUpdate, Schema, SchemaChange, SchemaChangeDetail, SearchIndex } from "../generated/types.gen.ts";
4
+ import type { DeletedListParams, DryRunParams, FieldMigrateParams, ListParams, SchemaParams } from "../types.ts";
5
+ import { Resource } from "./resource.ts";
6
+ /** Collections of the key's project. `collection` is an ID or slug. */
7
+ export declare class Collections extends Resource {
8
+ readonly schemaChanges: SchemaChanges;
9
+ readonly searchIndex: SearchIndexes;
10
+ list(params?: DeletedListParams, options?: RequestOptions): PagePromise<Collection>;
11
+ get(collection: string, options?: RequestOptions): APIPromise<Collection>;
12
+ /** Creates a collection, optionally with its fields. */
13
+ create(params: CollectionCreate, options?: RequestOptions): APIPromise<Collection>;
14
+ update(collection: string, params: CollectionUpdate, options?: RequestOptions): APIPromise<Collection>;
15
+ /** Soft-deletes the collection and its records for 30 days. */
16
+ delete(collection: string, options?: RequestOptions): APIPromise<Collection>;
17
+ restore(collection: string, options?: RequestOptions): APIPromise<Collection>;
18
+ /** The collection's schema, now or at a past `version`. */
19
+ schema(collection: string, params?: SchemaParams, options?: RequestOptions): APIPromise<Schema>;
20
+ }
21
+ /** A collection's schema history, newest first. */
22
+ export declare class SchemaChanges extends Resource {
23
+ list(collection: string, params?: ListParams, options?: RequestOptions): PagePromise<SchemaChange>;
24
+ get(collection: string, schemaChange: string, options?: RequestOptions): APIPromise<SchemaChangeDetail>;
25
+ }
26
+ /** A collection's search index. */
27
+ export declare class SearchIndexes extends Resource {
28
+ get(collection: string, options?: RequestOptions): APIPromise<SearchIndex>;
29
+ /** Rebuilds the index from the records; searches keep working meanwhile. */
30
+ rebuild(collection: string, options?: RequestOptions): APIPromise<SearchIndex>;
31
+ }
32
+ /** Fields of a collection. `field` is a field ID (`fld_…`). */
33
+ export declare class Fields extends Resource {
34
+ list(collection: string, params?: DeletedListParams, options?: RequestOptions): PagePromise<Field>;
35
+ create(collection: string, params: FieldCreate, options?: RequestOptions): APIPromise<Field>;
36
+ /**
37
+ * Renames, describes or loosens a field. Changes that rewrite record
38
+ * values (type, `multiple`, tighter rules) are `migrate`.
39
+ */
40
+ update(field: string, params: FieldUpdate, options?: RequestOptions): APIPromise<Field>;
41
+ /** Soft-deletes the field: its values return with `restore` for 30 days. */
42
+ delete(field: string, options?: RequestOptions): APIPromise<Field>;
43
+ restore(field: string, options?: RequestOptions): APIPromise<Field>;
44
+ /** Puts the collection's fields in this order. */
45
+ reorder(collection: string, params: {
46
+ field_ids: string[];
47
+ }, options?: RequestOptions): APIPromise<Collection>;
48
+ /** Stops accepting a renamed field's old API key before its 6 months end. */
49
+ removeAlias(field: string, alias: string, options?: RequestOptions): APIPromise<Field>;
50
+ /**
51
+ * Starts a field migration (type, `multiple`, tighter configuration or a
52
+ * backfill) that rewrites every record. With `dry_run`, previews it.
53
+ */
54
+ migrate(field: string, params: FieldMigrateParams & {
55
+ dry_run: true;
56
+ }, options?: RequestOptions): APIPromise<FieldMigrationPreview>;
57
+ migrate(field: string, params: FieldMigrateParams & DryRunParams, options?: RequestOptions): APIPromise<FieldMigration>;
58
+ }
59
+ /** Field migrations. While one runs, its collection is read-only. */
60
+ export declare class Migrations extends Resource {
61
+ list(collection: string, params?: ListParams, options?: RequestOptions): PagePromise<FieldMigration>;
62
+ get(migration: string, options?: RequestOptions): APIPromise<FieldMigration>;
63
+ cancel(migration: string, options?: RequestOptions): APIPromise<FieldMigration>;
64
+ }
@@ -0,0 +1,97 @@
1
+ import { Resource } from "./resource.js";
2
+ /** Collections of the key's project. `collection` is an ID or slug. */
3
+ export class Collections extends Resource {
4
+ schemaChanges = new SchemaChanges(this.core);
5
+ searchIndex = new SearchIndexes(this.core);
6
+ list(params = {}, options) {
7
+ return this.core.paginate("collections_list", { query: params }, options);
8
+ }
9
+ get(collection, options) {
10
+ return this.core.request("collections_get", { path: { collection_id: collection } }, options);
11
+ }
12
+ /** Creates a collection, optionally with its fields. */
13
+ create(params, options) {
14
+ return this.core.request("collections_create", { body: params }, options);
15
+ }
16
+ update(collection, params, options) {
17
+ return this.core.request("collections_update", { path: { collection_id: collection }, body: params }, options);
18
+ }
19
+ /** Soft-deletes the collection and its records for 30 days. */
20
+ delete(collection, options) {
21
+ return this.core.request("collections_delete", { path: { collection_id: collection } }, options);
22
+ }
23
+ restore(collection, options) {
24
+ return this.core.request("collections_restore", { path: { collection_id: collection } }, options);
25
+ }
26
+ /** The collection's schema, now or at a past `version`. */
27
+ schema(collection, params = {}, options) {
28
+ return this.core.request("collections_get_schema", { path: { collection_id: collection }, query: params }, options);
29
+ }
30
+ }
31
+ /** A collection's schema history, newest first. */
32
+ export class SchemaChanges extends Resource {
33
+ list(collection, params = {}, options) {
34
+ return this.core.paginate("schema_changes_list", { path: { collection_id: collection }, query: params }, options);
35
+ }
36
+ get(collection, schemaChange, options) {
37
+ return this.core.request("schema_changes_get", {
38
+ path: { collection_id: collection, schema_change_id: schemaChange },
39
+ }, options);
40
+ }
41
+ }
42
+ /** A collection's search index. */
43
+ export class SearchIndexes extends Resource {
44
+ get(collection, options) {
45
+ return this.core.request("search_index_get", { path: { collection_id: collection } }, options);
46
+ }
47
+ /** Rebuilds the index from the records; searches keep working meanwhile. */
48
+ rebuild(collection, options) {
49
+ return this.core.request("search_index_rebuild", { path: { collection_id: collection } }, options);
50
+ }
51
+ }
52
+ /** Fields of a collection. `field` is a field ID (`fld_…`). */
53
+ export class Fields extends Resource {
54
+ list(collection, params = {}, options) {
55
+ return this.core.paginate("fields_list", { path: { collection_id: collection }, query: params }, options);
56
+ }
57
+ create(collection, params, options) {
58
+ return this.core.request("fields_create", { path: { collection_id: collection }, body: params }, options);
59
+ }
60
+ /**
61
+ * Renames, describes or loosens a field. Changes that rewrite record
62
+ * values (type, `multiple`, tighter rules) are `migrate`.
63
+ */
64
+ update(field, params, options) {
65
+ return this.core.request("fields_update", { path: { field_id: field }, body: params }, options);
66
+ }
67
+ /** Soft-deletes the field: its values return with `restore` for 30 days. */
68
+ delete(field, options) {
69
+ return this.core.request("fields_delete", { path: { field_id: field } }, options);
70
+ }
71
+ restore(field, options) {
72
+ return this.core.request("fields_restore", { path: { field_id: field } }, options);
73
+ }
74
+ /** Puts the collection's fields in this order. */
75
+ reorder(collection, params, options) {
76
+ return this.core.request("fields_reorder", { path: { collection_id: collection }, body: params }, options);
77
+ }
78
+ /** Stops accepting a renamed field's old API key before its 6 months end. */
79
+ removeAlias(field, alias, options) {
80
+ return this.core.request("fields_remove_alias", { path: { field_id: field, alias } }, options);
81
+ }
82
+ migrate(field, { dry_run, ...body }, options) {
83
+ return this.core.request("fields_migrate", { path: { field_id: field }, query: { dry_run }, body }, options);
84
+ }
85
+ }
86
+ /** Field migrations. While one runs, its collection is read-only. */
87
+ export class Migrations extends Resource {
88
+ list(collection, params = {}, options) {
89
+ return this.core.paginate("migrations_list", { path: { collection_id: collection }, query: params }, options);
90
+ }
91
+ get(migration, options) {
92
+ return this.core.request("migrations_get", { path: { migration_id: migration } }, options);
93
+ }
94
+ cancel(migration, options) {
95
+ return this.core.request("migrations_cancel", { path: { migration_id: migration } }, options);
96
+ }
97
+ }
@@ -0,0 +1,32 @@
1
+ import type { APIPromise, PagePromise } from "../api-promise.ts";
2
+ import type { RequestOptions } from "../core.ts";
3
+ import type { Webhook, WebhookCreate, WebhookDelivery, WebhookDeliveryDetail, WebhookUpdate, WebhookWithSecret } from "../generated/types.gen.ts";
4
+ import type { DeliveryListParams, ListParams, RecordData } from "../types.ts";
5
+ import { type UnwrapOptions, type WebhookEvent, type WebhookHeaders } from "../webhooks.ts";
6
+ import { Resource } from "./resource.ts";
7
+ /** Webhooks of the key's project. `webhook` is a webhook ID (`wh_…`). */
8
+ export declare class Webhooks extends Resource {
9
+ readonly deliveries: Deliveries;
10
+ list(params?: ListParams, options?: RequestOptions): PagePromise<Webhook>;
11
+ get(webhook: string, options?: RequestOptions): APIPromise<Webhook>;
12
+ /** Subscribes a URL. The response is the only time `secret` is shown. */
13
+ create(params: WebhookCreate, options?: RequestOptions): APIPromise<WebhookWithSecret>;
14
+ update(webhook: string, params: WebhookUpdate, options?: RequestOptions): APIPromise<Webhook>;
15
+ delete(webhook: string, options?: RequestOptions): APIPromise<Webhook>;
16
+ /** A new signing secret; the old one stops working at once. */
17
+ rotateSecret(webhook: string, options?: RequestOptions): APIPromise<WebhookWithSecret>;
18
+ /** Sends a `webhook.test` event to the URL. */
19
+ test(webhook: string, options?: RequestOptions): APIPromise<WebhookDelivery>;
20
+ /**
21
+ * Checks a webhook request's signature and returns its event (see
22
+ * `unwrapWebhook` in `@nohead/sdk/webhooks`, which needs no client).
23
+ */
24
+ unwrap<D = RecordData>(body: string | ArrayBuffer | Uint8Array, headers: WebhookHeaders, options: UnwrapOptions): Promise<WebhookEvent<D>>;
25
+ }
26
+ /** Delivery attempts of a webhook's events. */
27
+ export declare class Deliveries extends Resource {
28
+ list(webhook: string, params?: DeliveryListParams, options?: RequestOptions): PagePromise<WebhookDelivery>;
29
+ get(delivery: string, options?: RequestOptions): APIPromise<WebhookDeliveryDetail>;
30
+ /** Sends the event again. */
31
+ retry(delivery: string, options?: RequestOptions): APIPromise<WebhookDelivery>;
32
+ }
@@ -0,0 +1,50 @@
1
+ import { unwrapWebhook, } from "../webhooks.js";
2
+ import { Resource } from "./resource.js";
3
+ /** Webhooks of the key's project. `webhook` is a webhook ID (`wh_…`). */
4
+ export class Webhooks extends Resource {
5
+ deliveries = new Deliveries(this.core);
6
+ list(params = {}, options) {
7
+ return this.core.paginate("webhooks_list", { query: params }, options);
8
+ }
9
+ get(webhook, options) {
10
+ return this.core.request("webhooks_get", { path: { webhook_id: webhook } }, options);
11
+ }
12
+ /** Subscribes a URL. The response is the only time `secret` is shown. */
13
+ create(params, options) {
14
+ return this.core.request("webhooks_create", { body: params }, options);
15
+ }
16
+ update(webhook, params, options) {
17
+ return this.core.request("webhooks_update", { path: { webhook_id: webhook }, body: params }, options);
18
+ }
19
+ delete(webhook, options) {
20
+ return this.core.request("webhooks_delete", { path: { webhook_id: webhook } }, options);
21
+ }
22
+ /** A new signing secret; the old one stops working at once. */
23
+ rotateSecret(webhook, options) {
24
+ return this.core.request("webhooks_rotate_secret", { path: { webhook_id: webhook } }, options);
25
+ }
26
+ /** Sends a `webhook.test` event to the URL. */
27
+ test(webhook, options) {
28
+ return this.core.request("webhooks_test", { path: { webhook_id: webhook } }, options);
29
+ }
30
+ /**
31
+ * Checks a webhook request's signature and returns its event (see
32
+ * `unwrapWebhook` in `@nohead/sdk/webhooks`, which needs no client).
33
+ */
34
+ unwrap(body, headers, options) {
35
+ return unwrapWebhook(body, headers, options);
36
+ }
37
+ }
38
+ /** Delivery attempts of a webhook's events. */
39
+ export class Deliveries extends Resource {
40
+ list(webhook, params = {}, options) {
41
+ return this.core.paginate("webhook_deliveries_list", { path: { webhook_id: webhook }, query: params }, options);
42
+ }
43
+ get(delivery, options) {
44
+ return this.core.request("webhook_deliveries_get", { path: { delivery_id: delivery } }, options);
45
+ }
46
+ /** Sends the event again. */
47
+ retry(delivery, options) {
48
+ return this.core.request("webhook_deliveries_retry", { path: { delivery_id: delivery } }, options);
49
+ }
50
+ }