@nohead/sdk 0.6.0 → 0.8.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/CHANGELOG.md CHANGED
@@ -5,6 +5,30 @@ Changes to `@nohead/sdk` that you can notice. Versions follow
5
5
  releases; a change that could break your code is a major one. Each release's
6
6
  section is its GitHub release's notes.
7
7
 
8
+ ## 0.8.0
9
+
10
+ - `Asset` has `file_url`, the file as uploaded, which downloads under its
11
+ filename, and for video and audio `media_url`, which plays it inline (in
12
+ `<video>` and `<audio>`, with range requests). Both are open, never expire
13
+ and are cached on a CDN, like `image_url`.
14
+
15
+ - `assets.downloadUrl` is removed, with the API's
16
+ `GET /v1/assets/{asset_id}/download-url` and its 2-minute links: use the
17
+ asset's `file_url`.
18
+
19
+ - An upload larger than the plan allows (10 MB a file on Free, 100 MB on paid
20
+ plans) is refused with a `PlanLimitExceededError` when it starts.
21
+
22
+ ## 0.7.0
23
+
24
+ - `assets.list({ q, kind })`: `q` finds assets whose filename or alt text
25
+ has every word, ignoring case; `kind` lists only `image`, `video`,
26
+ `audio`, `document` or `other` assets, or several kinds as a list.
27
+
28
+ - `assets.upload` types a file by its filename's extension when the Blob has
29
+ no type, as Node's `openAsBlob` makes them: `cover.jpg` is now an
30
+ `image/jpeg` asset, not `application/octet-stream`.
31
+
8
32
  ## 0.6.0
9
33
 
10
34
  - API keys now start `nohead_sk_`, or `nohead_pk_` for published-only keys;
package/README.md CHANGED
@@ -372,6 +372,8 @@ Verify a webhook request, then use its event:
372
372
 
373
373
  ```ts
374
374
  // e.g. a Next.js route handler
375
+ import { revalidateTag } from "next/cache"
376
+
375
377
  export async function POST(request: Request) {
376
378
  const event = await nohead.webhooks.unwrap(
377
379
  await request.text(),
@@ -381,12 +383,14 @@ export async function POST(request: Request) {
381
383
  }
382
384
  )
383
385
  if (event.type === "record.published" && event.data.record) {
384
- revalidateTag(event.data.record.collection)
386
+ revalidateTag(event.data.record.collection, "max")
385
387
  }
386
388
  return new Response(null, { status: 204 })
387
389
  }
388
390
  ```
389
391
 
392
+ With `"max"`, Next.js serves the old version to the next request while it fetches the new one; pass `{ expire: 0 }` instead to drop it at once.
393
+
390
394
  Event types are those of the activity log (`record.published`, `record.restored`, `field.updated`, `asset.purged`, …), and a webhook subscribes to types or wildcards (`record.*`, `*`). Narrowing by `type` types `event.data`, and `unwrap<Post>` types the records and drafts in it. `unwrap` checks the signature and the timestamp (Standard Webhooks), and throws `WebhookVerificationError` if either is off. After `rotateSecret`, requests carry a signature for the old secret and the new one for 24 hours, so switch the receiver's secret within that day (or end it sooner with `webhooks.secrets.retire`). Pass the raw body: parsing and re-serializing JSON changes the bytes.
391
395
 
392
396
  A receiver that never calls the API can use `unwrapWebhook` from `@nohead/sdk/webhooks` without a client. Events can arrive more than once, so deduplicate by the `webhook-id` header.
@@ -414,7 +418,7 @@ response.headers.get("RateLimit-Remaining")
414
418
  | `collections.searchIndex` | `get`, `rebuild` |
415
419
  | `fields` | `list`, `get`, `create`, `update`, `delete`, `restore`, `order`, `reorder`, `removeAlias` |
416
420
  | `migrations` | `create`, `list`, `get`, `cancel` |
417
- | `assets` | `upload`, `createUpload`, `complete`, `list`, `get`, `update`, `delete`, `restore`, `purge`, `usage`, `downloadUrl` |
421
+ | `assets` | `upload`, `createUpload`, `complete`, `list`, `get`, `update`, `delete`, `restore`, `purge`, `usage` |
418
422
  | `webhooks` | `list`, `get`, `create`, `update`, `delete`, `restore`, `rotateSecret`, `test`, `unwrap` |
419
423
  | `webhooks.secrets` | `list`, `retire` |
420
424
  | `webhooks.deliveries` | `list`, `get`, `retry` |
@@ -8,10 +8,6 @@ export declare const OPERATIONS: {
8
8
  readonly method: "DELETE";
9
9
  readonly path: "/v1/assets/{asset_id}";
10
10
  };
11
- readonly assets_download_url: {
12
- readonly method: "GET";
13
- readonly path: "/v1/assets/{asset_id}/download-url";
14
- };
15
11
  readonly assets_get: {
16
12
  readonly method: "GET";
17
13
  readonly path: "/v1/assets/{asset_id}";
@@ -339,10 +335,6 @@ export interface Operations {
339
335
  data: T.AssetsDeleteData;
340
336
  response: T.AssetsDeleteResponse;
341
337
  };
342
- assets_download_url: {
343
- data: T.AssetsDownloadUrlData;
344
- response: T.AssetsDownloadUrlResponse;
345
- };
346
338
  assets_get: {
347
339
  data: T.AssetsGetData;
348
340
  response: T.AssetsGetResponse;
@@ -1,7 +1,6 @@
1
1
  export const OPERATIONS = {
2
2
  assets_complete: { method: "POST", path: "/v1/assets/{asset_id}/complete" },
3
3
  assets_delete: { method: "DELETE", path: "/v1/assets/{asset_id}" },
4
- assets_download_url: { method: "GET", path: "/v1/assets/{asset_id}/download-url" },
5
4
  assets_get: { method: "GET", path: "/v1/assets/{asset_id}" },
6
5
  assets_list: { method: "GET", path: "/v1/projects/{project_id}/assets" },
7
6
  assets_purge: { method: "POST", path: "/v1/assets/{asset_id}/purge" },
@@ -1 +1 @@
1
- export type { Actor, ApiKeyScope, Asset, AssetEventData, AssetField, AssetFieldConfiguration, AssetFieldCreate, AssetList, AssetProperties, AssetUpdate, AssetUploadCreate, AssetUploadTarget, AssetUsage, AssetWithUpload, AuditEvent, AuditEventList, BooleanField, BooleanFieldConfiguration, BooleanFieldCreate, Change, Collection, CollectionCreate, CollectionList, CollectionUpdate, DateField, DateFieldConfiguration, DateFieldCreate, DecimalField, DecimalFieldConfiguration, DecimalFieldCreate, DownloadUrl, Draft, DraftCreate, DraftEventData, DraftList, DraftSchedule, DraftScheduleUpdate, EnumField, EnumFieldConfiguration, EnumFieldCreate, Error, ErrorDetail, ErrorType, FeatureFlags, Field, FieldAliasEventData, FieldConfiguration, FieldCreate, FieldCreateProperties, FieldDefinition, FieldList, FieldMigration, FieldMigrationCounts, FieldMigrationList, FieldMigrationPreview, FieldMigrationRequest, FieldOrder, FieldProperties, FieldType, FieldUpdate, Health, IntegerField, IntegerFieldConfiguration, IntegerFieldCreate, JsonField, JsonFieldConfiguration, JsonFieldCreate, ListMeta, LongTextField, LongTextFieldConfiguration, LongTextFieldCreate, MergedDraft, NullableTimestamp, Principal, PublishedOnly, RecordBatch, RecordBatchRequest, RecordCount, RecordCreate, RecordData, RecordDiff, RecordEventData, RecordFilterValue, RecordList, RecordPublication, RecordRevision, RecordRevisionDetail, RecordRevisionList, RecordRevisionOperation, RecordRevisionProperties, RecordSchedule, RecordScheduleUpdate, RecordWrite, RelationField, RelationFieldConfiguration, RelationFieldCreate, RequestId, RevertPreview, RichTextField, RichTextFieldConfiguration, RichTextFieldCreate, ScheduledChange, ScheduledChangeList, Schema, SchemaChange, SchemaChangeDetail, SchemaChangeList, SchemaChangeProperties, SchemaDefinition, SchemaEventData, SearchIndex, SearchResults, TextField, TextFieldConfiguration, TextFieldCreate, TimeFilter, Timestamp, Via, Webhook, WebhookCreate, WebhookDelivery, WebhookDeliveryDetail, WebhookDeliveryList, WebhookDeliveryProperties, WebhookEventPayload, WebhookEventType, WebhookList, WebhookProperties, WebhookSecret, WebhookSecretList, WebhookSecretProperties, WebhookSecretWithValue, WebhookSubscription, WebhookTestEventData, WebhookUpdate, WebhookWithSecret, } from "./types.gen.ts";
1
+ export type { Actor, ApiKeyScope, Asset, AssetEventData, AssetField, AssetFieldConfiguration, AssetFieldCreate, AssetKind, AssetList, AssetProperties, AssetUpdate, AssetUploadCreate, AssetUploadTarget, AssetUsage, AssetWithUpload, AuditEvent, AuditEventList, BooleanField, BooleanFieldConfiguration, BooleanFieldCreate, Change, Collection, CollectionCreate, CollectionList, CollectionUpdate, DateField, DateFieldConfiguration, DateFieldCreate, DecimalField, DecimalFieldConfiguration, DecimalFieldCreate, Draft, DraftCreate, DraftEventData, DraftList, DraftSchedule, DraftScheduleUpdate, EnumField, EnumFieldConfiguration, EnumFieldCreate, Error, ErrorDetail, ErrorType, FeatureFlags, Field, FieldAliasEventData, FieldConfiguration, FieldCreate, FieldCreateProperties, FieldDefinition, FieldList, FieldMigration, FieldMigrationCounts, FieldMigrationList, FieldMigrationPreview, FieldMigrationRequest, FieldOrder, FieldProperties, FieldType, FieldUpdate, Health, IntegerField, IntegerFieldConfiguration, IntegerFieldCreate, JsonField, JsonFieldConfiguration, JsonFieldCreate, ListMeta, LongTextField, LongTextFieldConfiguration, LongTextFieldCreate, MergedDraft, NullableTimestamp, Principal, PublishedOnly, RecordBatch, RecordBatchRequest, RecordCount, RecordCreate, RecordData, RecordDiff, RecordEventData, RecordFilterValue, RecordList, RecordPublication, RecordRevision, RecordRevisionDetail, RecordRevisionList, RecordRevisionOperation, RecordRevisionProperties, RecordSchedule, RecordScheduleUpdate, RecordWrite, RelationField, RelationFieldConfiguration, RelationFieldCreate, RequestId, RevertPreview, RichTextField, RichTextFieldConfiguration, RichTextFieldCreate, ScheduledChange, ScheduledChangeList, Schema, SchemaChange, SchemaChangeDetail, SchemaChangeList, SchemaChangeProperties, SchemaDefinition, SchemaEventData, SearchIndex, SearchResults, TextField, TextFieldConfiguration, TextFieldCreate, TimeFilter, Timestamp, Via, Webhook, WebhookCreate, WebhookDelivery, WebhookDeliveryDetail, WebhookDeliveryList, WebhookDeliveryProperties, WebhookEventPayload, WebhookEventType, WebhookList, WebhookProperties, WebhookSecret, WebhookSecretList, WebhookSecretProperties, WebhookSecretWithValue, WebhookSubscription, WebhookTestEventData, WebhookUpdate, WebhookWithSecret, } from "./types.gen.ts";