@nohead/sdk 0.6.0 → 0.7.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 +10 -0
- package/dist/generated/schemas.gen.d.ts +1 -1
- package/dist/generated/types.gen.d.ts +369 -94
- package/dist/resources/assets.d.ts +4 -2
- package/dist/resources/assets.js +42 -7
- package/dist/resources/records.d.ts +3 -3
- package/dist/resources/records.js +3 -3
- package/dist/types.d.ts +11 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -13,7 +13,6 @@ export interface UploadParams {
|
|
|
13
13
|
/** Required for a `ReadableStream`; known for everything else. */
|
|
14
14
|
byte_size?: number;
|
|
15
15
|
}
|
|
16
|
-
/** Files of the key's project. `asset` is an asset ID (`ast_…`). */
|
|
17
16
|
export declare class Assets extends Resource {
|
|
18
17
|
/**
|
|
19
18
|
* Uploads a file and returns the `ready` asset: creates the upload, sends
|
|
@@ -28,6 +27,9 @@ export declare class Assets extends Resource {
|
|
|
28
27
|
*
|
|
29
28
|
* import { openAsBlob } from "node:fs"
|
|
30
29
|
* const asset = await nohead.assets.upload(await openAsBlob("a.jpg"), { filename: "a.jpg" })
|
|
30
|
+
*
|
|
31
|
+
* Without `content_type`, the type is the Blob's, or else the filename's
|
|
32
|
+
* extension's for common files.
|
|
31
33
|
*/
|
|
32
34
|
upload(file: Uploadable, params?: UploadParams, options?: RequestOptions): Promise<Asset>;
|
|
33
35
|
/**
|
|
@@ -38,7 +40,7 @@ export declare class Assets extends Resource {
|
|
|
38
40
|
createUpload(params: AssetUploadCreate, options?: RequestOptions): APIPromise<AssetWithUpload>;
|
|
39
41
|
/** Checks an uploaded file and marks the asset `ready`. */
|
|
40
42
|
complete(asset: string, options?: RequestOptions): APIPromise<Asset>;
|
|
41
|
-
list({ content_type, ...params }?: AssetListParams, options?: RequestOptions): PagePromise<Asset>;
|
|
43
|
+
list({ content_type, kind, ...params }?: AssetListParams, options?: RequestOptions): PagePromise<Asset>;
|
|
42
44
|
get(asset: string, options?: RequestOptions): APIPromise<Asset>;
|
|
43
45
|
/**
|
|
44
46
|
* Renames the asset (`filename`) or sets its `alt` text (`null` or `""`
|
package/dist/resources/assets.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { AbortError, UploadError } from "../errors.js";
|
|
2
2
|
import { listQuery, Resource } from "./resource.js";
|
|
3
3
|
/** Files of the key's project. `asset` is an asset ID (`ast_…`). */
|
|
4
|
+
/** Common files' types by extension, as the other SDKs guess them. */
|
|
5
|
+
const CONTENT_TYPES = {
|
|
6
|
+
avif: "image/avif",
|
|
7
|
+
gif: "image/gif",
|
|
8
|
+
jpeg: "image/jpeg",
|
|
9
|
+
jpg: "image/jpeg",
|
|
10
|
+
png: "image/png",
|
|
11
|
+
svg: "image/svg+xml",
|
|
12
|
+
webp: "image/webp",
|
|
13
|
+
pdf: "application/pdf",
|
|
14
|
+
json: "application/json",
|
|
15
|
+
txt: "text/plain",
|
|
16
|
+
md: "text/markdown",
|
|
17
|
+
csv: "text/csv",
|
|
18
|
+
mp3: "audio/mpeg",
|
|
19
|
+
mp4: "video/mp4",
|
|
20
|
+
webm: "video/webm",
|
|
21
|
+
zip: "application/zip",
|
|
22
|
+
};
|
|
23
|
+
function contentTypeOf(filename) {
|
|
24
|
+
const dot = filename.lastIndexOf(".");
|
|
25
|
+
return dot > 0
|
|
26
|
+
? CONTENT_TYPES[filename.slice(dot + 1).toLowerCase()]
|
|
27
|
+
: undefined;
|
|
28
|
+
}
|
|
4
29
|
export class Assets extends Resource {
|
|
5
30
|
/**
|
|
6
31
|
* Uploads a file and returns the `ready` asset: creates the upload, sends
|
|
@@ -15,19 +40,28 @@ export class Assets extends Resource {
|
|
|
15
40
|
*
|
|
16
41
|
* import { openAsBlob } from "node:fs"
|
|
17
42
|
* const asset = await nohead.assets.upload(await openAsBlob("a.jpg"), { filename: "a.jpg" })
|
|
43
|
+
*
|
|
44
|
+
* Without `content_type`, the type is the Blob's, or else the filename's
|
|
45
|
+
* extension's for common files.
|
|
18
46
|
*/
|
|
19
47
|
async upload(file, params = {}, options) {
|
|
20
48
|
const byteSize = params.byte_size ?? sizeOf(file);
|
|
21
49
|
if (byteSize === undefined) {
|
|
22
50
|
throw new UploadError("Uploading a stream needs `byte_size`");
|
|
23
51
|
}
|
|
52
|
+
const filename = params.filename ??
|
|
53
|
+
(typeof File !== "undefined" && file instanceof File
|
|
54
|
+
? file.name
|
|
55
|
+
: "upload");
|
|
24
56
|
const { upload, ...asset } = await this.createUpload({
|
|
25
|
-
filename
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
57
|
+
filename,
|
|
58
|
+
// The Blob's own type, or one the filename's extension implies (a
|
|
59
|
+
// Blob from Node's openAsBlob has none), as the Python and Ruby
|
|
60
|
+
// SDKs do.
|
|
29
61
|
content_type: params.content_type ??
|
|
30
|
-
((file instanceof Blob && file.type) ||
|
|
62
|
+
((file instanceof Blob && file.type) ||
|
|
63
|
+
contentTypeOf(filename) ||
|
|
64
|
+
"application/octet-stream"),
|
|
31
65
|
byte_size: byteSize,
|
|
32
66
|
}, options);
|
|
33
67
|
// A replayed start returns the first run's asset, which may be done.
|
|
@@ -74,14 +108,15 @@ export class Assets extends Resource {
|
|
|
74
108
|
complete(asset, options) {
|
|
75
109
|
return this.core.request("assets_complete", { path: { asset_id: asset } }, options);
|
|
76
110
|
}
|
|
77
|
-
list({ content_type, ...params } = {}, options) {
|
|
111
|
+
list({ content_type, kind, ...params } = {}, options) {
|
|
78
112
|
return this.core.paginate("assets_list", {
|
|
79
113
|
query: listQuery({
|
|
80
114
|
...params,
|
|
81
115
|
content_type: Array.isArray(content_type)
|
|
82
116
|
? { in: content_type }
|
|
83
117
|
: content_type,
|
|
84
|
-
|
|
118
|
+
kind: Array.isArray(kind) ? { in: kind } : kind,
|
|
119
|
+
}, ["deleted", "content_type", "kind"]),
|
|
85
120
|
}, options);
|
|
86
121
|
}
|
|
87
122
|
get(asset, options) {
|
|
@@ -53,9 +53,9 @@ export declare class Records extends Resource {
|
|
|
53
53
|
/** Clears both scheduled times. */
|
|
54
54
|
unschedule(record: string, options?: RequestOptions): APIPromise<RecordSchedule>;
|
|
55
55
|
/**
|
|
56
|
-
* A collection's pending scheduled
|
|
57
|
-
*
|
|
58
|
-
* appears twice.
|
|
56
|
+
* A collection's pending scheduled changes, soonest first: publishes,
|
|
57
|
+
* unpublishes and draft merges, one per change, so a record due to publish
|
|
58
|
+
* and later unpublish appears twice.
|
|
59
59
|
*/
|
|
60
60
|
scheduledChanges(collection: string, params?: ScheduledChangeListParams, options?: RequestOptions): PagePromise<ScheduledChange>;
|
|
61
61
|
count(collection: string, params?: RecordCountParams, options?: RequestOptions): APIPromise<RecordCount>;
|
|
@@ -75,9 +75,9 @@ export class Records extends Resource {
|
|
|
75
75
|
return this.core.request("records_unschedule", { path: { record_id: record } }, options);
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
* A collection's pending scheduled
|
|
79
|
-
*
|
|
80
|
-
* appears twice.
|
|
78
|
+
* A collection's pending scheduled changes, soonest first: publishes,
|
|
79
|
+
* unpublishes and draft merges, one per change, so a record due to publish
|
|
80
|
+
* and later unpublish appears twice.
|
|
81
81
|
*/
|
|
82
82
|
scheduledChanges(collection, params = {}, options) {
|
|
83
83
|
return this.core.paginate("scheduled_changes_list", { path: { collection_id: collection }, query: params }, options);
|
package/dist/types.d.ts
CHANGED
|
@@ -157,6 +157,17 @@ export interface DeletedListParams extends ListParams {
|
|
|
157
157
|
deleted?: boolean;
|
|
158
158
|
}
|
|
159
159
|
export interface AssetListParams extends DeletedListParams {
|
|
160
|
+
/**
|
|
161
|
+
* Words that must each appear in the filename or the alt text, ignoring
|
|
162
|
+
* case: `"hero jpg"` finds `Hero-banner.jpg`.
|
|
163
|
+
*/
|
|
164
|
+
q?: string;
|
|
165
|
+
/**
|
|
166
|
+
* Only assets of a kind, or of any of several: `"image"`, `"video"` and
|
|
167
|
+
* `"audio"` by their types, `"document"` for PDFs, text and office files,
|
|
168
|
+
* `"other"` for every other file.
|
|
169
|
+
*/
|
|
170
|
+
kind?: G.AssetKind | G.AssetKind[];
|
|
160
171
|
/**
|
|
161
172
|
* Only assets of a MIME type or `type/*` wildcard (`"image/*"`), or of any
|
|
162
173
|
* of several: `["image/*", "application/pdf"]`, such as an asset
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.7.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.7.0";
|