@unofficialbox/box-open-sdk 0.7.1 → 0.9.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/dist/cjs/buildinfo.js +2 -2
- package/dist/cjs/client.js +11 -2
- package/dist/cjs/errors.js +3 -2
- package/dist/cjs/managers/authorization.js +15 -0
- package/dist/cjs/managers/events.js +27 -1
- package/dist/cjs/managers/web_links.js +26 -2
- package/dist/cjs/models/schemas/ai.js +1 -1
- package/dist/cjs/models/schemas/ai_studio.js +1 -1
- package/dist/cjs/models/schemas/app_item_associations.js +1 -1
- package/dist/cjs/models/schemas/archives.js +1 -1
- package/dist/cjs/models/schemas/authorization.js +1 -1
- package/dist/cjs/models/schemas/automate_workflows.js +1 -1
- package/dist/cjs/models/schemas/avatars.js +1 -1
- package/dist/cjs/models/schemas/chunked_uploads.js +1 -1
- package/dist/cjs/models/schemas/classifications.js +1 -1
- package/dist/cjs/models/schemas/collaboration_allowlist_entries.js +1 -1
- package/dist/cjs/models/schemas/collaboration_allowlist_exempt_targets.js +1 -1
- package/dist/cjs/models/schemas/collections.js +1 -1
- package/dist/cjs/models/schemas/comments.js +1 -1
- package/dist/cjs/models/schemas/device_pinners.js +1 -1
- package/dist/cjs/models/schemas/docgen.js +1 -1
- package/dist/cjs/models/schemas/docgen_template.js +1 -1
- package/dist/cjs/models/schemas/document_split.js +1 -1
- package/dist/cjs/models/schemas/email_aliases.js +1 -1
- package/dist/cjs/models/schemas/enterprise_configurations.js +1 -1
- package/dist/cjs/models/schemas/events.js +1 -1
- package/dist/cjs/models/schemas/external_users.js +1 -1
- package/dist/cjs/models/schemas/file_requests.js +1 -1
- package/dist/cjs/models/schemas/file_version_legal_holds.js +1 -1
- package/dist/cjs/models/schemas/file_version_retentions.js +1 -1
- package/dist/cjs/models/schemas/file_versions.js +1 -1
- package/dist/cjs/models/schemas/files.js +1 -1
- package/dist/cjs/models/schemas/folder_locks.js +1 -1
- package/dist/cjs/models/schemas/folders.js +1 -1
- package/dist/cjs/models/schemas/groups.js +1 -1
- package/dist/cjs/models/schemas/hub_collaborations.js +1 -1
- package/dist/cjs/models/schemas/hub_document.js +1 -1
- package/dist/cjs/models/schemas/hub_items.js +1 -1
- package/dist/cjs/models/schemas/hubs.js +1 -1
- package/dist/cjs/models/schemas/integration_mappings.js +1 -1
- package/dist/cjs/models/schemas/invites.js +1 -1
- package/dist/cjs/models/schemas/legal_hold_policies.js +1 -1
- package/dist/cjs/models/schemas/legal_hold_policy_assignments.js +1 -1
- package/dist/cjs/models/schemas/list_collaborations.js +1 -1
- package/dist/cjs/models/schemas/memberships.js +1 -1
- package/dist/cjs/models/schemas/metadata_cascade_policies.js +1 -1
- package/dist/cjs/models/schemas/metadata_taxonomies.js +1 -1
- package/dist/cjs/models/schemas/metadata_templates.js +1 -1
- package/dist/cjs/models/schemas/notes.js +1 -1
- package/dist/cjs/models/schemas/query.js +1 -1
- package/dist/cjs/models/schemas/recent_items.js +1 -1
- package/dist/cjs/models/schemas/retention_policies.js +1 -1
- package/dist/cjs/models/schemas/retention_policy_assignments.js +1 -1
- package/dist/cjs/models/schemas/search.js +1 -1
- package/dist/cjs/models/schemas/session_termination.js +1 -1
- package/dist/cjs/models/schemas/shared_links_folders.js +1 -1
- package/dist/cjs/models/schemas/shield_information_barrier_reports.js +1 -1
- package/dist/cjs/models/schemas/shield_information_barrier_segment_members.js +1 -1
- package/dist/cjs/models/schemas/shield_information_barrier_segment_restrictions.js +1 -1
- package/dist/cjs/models/schemas/shield_information_barrier_segments.js +1 -1
- package/dist/cjs/models/schemas/shield_information_barriers.js +1 -1
- package/dist/cjs/models/schemas/shield_lists.js +1 -1
- package/dist/cjs/models/schemas/shuttle.js +1 -1
- package/dist/cjs/models/schemas/sign_requests.js +1 -1
- package/dist/cjs/models/schemas/sign_templates.js +1 -1
- package/dist/cjs/models/schemas/skills.js +1 -1
- package/dist/cjs/models/schemas/storage_policies.js +1 -1
- package/dist/cjs/models/schemas/storage_policy_assignments.js +1 -1
- package/dist/cjs/models/schemas/task_assignments.js +1 -1
- package/dist/cjs/models/schemas/tasks.js +1 -1
- package/dist/cjs/models/schemas/terms_of_service_user_statuses.js +1 -1
- package/dist/cjs/models/schemas/terms_of_services.js +1 -1
- package/dist/cjs/models/schemas/transfer.js +1 -1
- package/dist/cjs/models/schemas/trashed_files.js +1 -1
- package/dist/cjs/models/schemas/trashed_folders.js +1 -1
- package/dist/cjs/models/schemas/trashed_items.js +1 -1
- package/dist/cjs/models/schemas/trashed_web_links.js +1 -1
- package/dist/cjs/models/schemas/uploads.js +1 -1
- package/dist/cjs/models/schemas/user_collaborations.js +1 -1
- package/dist/cjs/models/schemas/users.js +1 -1
- package/dist/cjs/models/schemas/web_links.js +1 -1
- package/dist/cjs/models/schemas/webhooks.js +1 -1
- package/dist/cjs/models/schemas/workflows.js +1 -1
- package/dist/cjs/models/schemas/zip_downloads.js +1 -1
- package/dist/cjs/models/schemas.js +1 -1
- package/dist/cjs/runtime.js +127 -0
- package/dist/cjs/webhooks.js +113 -0
- package/dist/esm/buildinfo.js +2 -2
- package/dist/esm/client.js +11 -2
- package/dist/esm/errors.js +3 -2
- package/dist/esm/managers/authorization.js +15 -0
- package/dist/esm/managers/events.js +27 -1
- package/dist/esm/managers/web_links.js +26 -2
- package/dist/esm/models/schemas/ai.js +1 -1
- package/dist/esm/models/schemas/ai_studio.js +1 -1
- package/dist/esm/models/schemas/app_item_associations.js +1 -1
- package/dist/esm/models/schemas/archives.js +1 -1
- package/dist/esm/models/schemas/authorization.js +1 -1
- package/dist/esm/models/schemas/automate_workflows.js +1 -1
- package/dist/esm/models/schemas/avatars.js +1 -1
- package/dist/esm/models/schemas/chunked_uploads.js +1 -1
- package/dist/esm/models/schemas/classifications.js +1 -1
- package/dist/esm/models/schemas/collaboration_allowlist_entries.js +1 -1
- package/dist/esm/models/schemas/collaboration_allowlist_exempt_targets.js +1 -1
- package/dist/esm/models/schemas/collections.js +1 -1
- package/dist/esm/models/schemas/comments.js +1 -1
- package/dist/esm/models/schemas/device_pinners.js +1 -1
- package/dist/esm/models/schemas/docgen.js +1 -1
- package/dist/esm/models/schemas/docgen_template.js +1 -1
- package/dist/esm/models/schemas/document_split.js +1 -1
- package/dist/esm/models/schemas/email_aliases.js +1 -1
- package/dist/esm/models/schemas/enterprise_configurations.js +1 -1
- package/dist/esm/models/schemas/events.js +1 -1
- package/dist/esm/models/schemas/external_users.js +1 -1
- package/dist/esm/models/schemas/file_requests.js +1 -1
- package/dist/esm/models/schemas/file_version_legal_holds.js +1 -1
- package/dist/esm/models/schemas/file_version_retentions.js +1 -1
- package/dist/esm/models/schemas/file_versions.js +1 -1
- package/dist/esm/models/schemas/files.js +1 -1
- package/dist/esm/models/schemas/folder_locks.js +1 -1
- package/dist/esm/models/schemas/folders.js +1 -1
- package/dist/esm/models/schemas/groups.js +1 -1
- package/dist/esm/models/schemas/hub_collaborations.js +1 -1
- package/dist/esm/models/schemas/hub_document.js +1 -1
- package/dist/esm/models/schemas/hub_items.js +1 -1
- package/dist/esm/models/schemas/hubs.js +1 -1
- package/dist/esm/models/schemas/integration_mappings.js +1 -1
- package/dist/esm/models/schemas/invites.js +1 -1
- package/dist/esm/models/schemas/legal_hold_policies.js +1 -1
- package/dist/esm/models/schemas/legal_hold_policy_assignments.js +1 -1
- package/dist/esm/models/schemas/list_collaborations.js +1 -1
- package/dist/esm/models/schemas/memberships.js +1 -1
- package/dist/esm/models/schemas/metadata_cascade_policies.js +1 -1
- package/dist/esm/models/schemas/metadata_taxonomies.js +1 -1
- package/dist/esm/models/schemas/metadata_templates.js +1 -1
- package/dist/esm/models/schemas/notes.js +1 -1
- package/dist/esm/models/schemas/query.js +1 -1
- package/dist/esm/models/schemas/recent_items.js +1 -1
- package/dist/esm/models/schemas/retention_policies.js +1 -1
- package/dist/esm/models/schemas/retention_policy_assignments.js +1 -1
- package/dist/esm/models/schemas/search.js +1 -1
- package/dist/esm/models/schemas/session_termination.js +1 -1
- package/dist/esm/models/schemas/shared_links_folders.js +1 -1
- package/dist/esm/models/schemas/shield_information_barrier_reports.js +1 -1
- package/dist/esm/models/schemas/shield_information_barrier_segment_members.js +1 -1
- package/dist/esm/models/schemas/shield_information_barrier_segment_restrictions.js +1 -1
- package/dist/esm/models/schemas/shield_information_barrier_segments.js +1 -1
- package/dist/esm/models/schemas/shield_information_barriers.js +1 -1
- package/dist/esm/models/schemas/shield_lists.js +1 -1
- package/dist/esm/models/schemas/shuttle.js +1 -1
- package/dist/esm/models/schemas/sign_requests.js +1 -1
- package/dist/esm/models/schemas/sign_templates.js +1 -1
- package/dist/esm/models/schemas/skills.js +1 -1
- package/dist/esm/models/schemas/storage_policies.js +1 -1
- package/dist/esm/models/schemas/storage_policy_assignments.js +1 -1
- package/dist/esm/models/schemas/task_assignments.js +1 -1
- package/dist/esm/models/schemas/tasks.js +1 -1
- package/dist/esm/models/schemas/terms_of_service_user_statuses.js +1 -1
- package/dist/esm/models/schemas/terms_of_services.js +1 -1
- package/dist/esm/models/schemas/transfer.js +1 -1
- package/dist/esm/models/schemas/trashed_files.js +1 -1
- package/dist/esm/models/schemas/trashed_folders.js +1 -1
- package/dist/esm/models/schemas/trashed_items.js +1 -1
- package/dist/esm/models/schemas/trashed_web_links.js +1 -1
- package/dist/esm/models/schemas/uploads.js +1 -1
- package/dist/esm/models/schemas/user_collaborations.js +1 -1
- package/dist/esm/models/schemas/users.js +1 -1
- package/dist/esm/models/schemas/web_links.js +1 -1
- package/dist/esm/models/schemas/webhooks.js +1 -1
- package/dist/esm/models/schemas/workflows.js +1 -1
- package/dist/esm/models/schemas/zip_downloads.js +1 -1
- package/dist/esm/models/schemas.js +1 -1
- package/dist/esm/runtime.js +124 -0
- package/dist/esm/webhooks.js +109 -0
- package/dist/types/buildinfo.d.ts +1 -1
- package/dist/types/client.d.ts +9 -3
- package/dist/types/managers/authorization.d.ts +6 -0
- package/dist/types/managers/events.d.ts +4 -0
- package/dist/types/managers/web_links.d.ts +14 -2
- package/dist/types/runtime.d.ts +41 -0
- package/dist/types/webhooks.d.ts +24 -0
- package/docs/README.md +1 -0
- package/docs/auth.md +35 -8
- package/docs/errors.md +2 -2
- package/docs/managers/web_links.md +3 -0
- package/docs/pagination.md +17 -1
- package/docs/webhooks.md +34 -0
- package/package.json +1 -1
|
@@ -3,6 +3,15 @@ import type * as models from '../models/index.js';
|
|
|
3
3
|
/** Optional parameters for WebLinksManager.get. */
|
|
4
4
|
export interface WebLinksManagerGetOptions {
|
|
5
5
|
boxapi?: string;
|
|
6
|
+
"if-none-match"?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Optional parameters for WebLinksManager.update. */
|
|
9
|
+
export interface WebLinksManagerUpdateOptions {
|
|
10
|
+
"if-match"?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Optional parameters for WebLinksManager.delete_. */
|
|
13
|
+
export interface WebLinksManagerDeleteOptions {
|
|
14
|
+
"if-match"?: string;
|
|
6
15
|
}
|
|
7
16
|
/** Operations for the "web_links" API area. */
|
|
8
17
|
export declare class WebLinksManager {
|
|
@@ -10,6 +19,9 @@ export declare class WebLinksManager {
|
|
|
10
19
|
constructor(session: runtime.Client);
|
|
11
20
|
create(body: models.schemas.CreateWebLinkRequest): Promise<models.schemas.WebLink>;
|
|
12
21
|
get(webLinkId: string, opts?: WebLinksManagerGetOptions): Promise<models.schemas.WebLink>;
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
/** `get` with `If-None-Match` set to `etag`: resolves `undefined` when
|
|
23
|
+
* the item is unchanged since `etag` (Box answers 304 Not Modified). */
|
|
24
|
+
getIfModified(webLinkId: string, etag: string, opts?: WebLinksManagerGetOptions): Promise<models.schemas.WebLink | undefined>;
|
|
25
|
+
update(webLinkId: string, body: models.schemas.UpdateWebLinkRequest, opts?: WebLinksManagerUpdateOptions): Promise<models.schemas.WebLink>;
|
|
26
|
+
delete_(webLinkId: string, opts?: WebLinksManagerDeleteOptions): Promise<void>;
|
|
15
27
|
}
|
package/dist/types/runtime.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Auth } from './auth.js';
|
|
2
2
|
export { BoxApiError, isPreconditionFailed } from './errors.js';
|
|
3
3
|
export * from './auth.js';
|
|
4
|
+
export * from './webhooks.js';
|
|
4
5
|
/** The runtime-owned HTTP request envelope, assembled by the `with*` builders
|
|
5
6
|
* before `fetch` executes it. */
|
|
6
7
|
export declare class Request {
|
|
@@ -52,6 +53,12 @@ export declare class Client {
|
|
|
52
53
|
private readonly fetchImpl;
|
|
53
54
|
private readonly defaultHeaders;
|
|
54
55
|
constructor(auth: Auth, options?: ClientOptions);
|
|
56
|
+
/** A new client that sends `As-User: userId` with every API request, so Box
|
|
57
|
+
* acts as that user (an admin, or a service account whose app may "make API
|
|
58
|
+
* calls using the as-user header"). It shares this client's auth flow and
|
|
59
|
+
* token cache, `fetch`, base URLs, and retry policy; this client is
|
|
60
|
+
* unchanged. Token requests never carry the header. */
|
|
61
|
+
withAsUserHeader(userId: string): Client;
|
|
55
62
|
/** The configured base URL for a D-106 class, without a trailing slash. */
|
|
56
63
|
baseUrl(name: string): string;
|
|
57
64
|
/** A valid access token for the configured auth flow. The `signal` is
|
|
@@ -97,3 +104,37 @@ export declare function responseStream(response: Response): Stream;
|
|
|
97
104
|
export declare function responseHeader(response: Response, name: string): string;
|
|
98
105
|
/** The response status code. */
|
|
99
106
|
export declare function statusCode(response: Response): number;
|
|
107
|
+
/** One of Box's real-time servers, as `OPTIONS /events` lists them. An absent
|
|
108
|
+
* `maxRetries` or `retryTimeoutSeconds` takes Box's documented default. */
|
|
109
|
+
export interface LongPollServer {
|
|
110
|
+
url: string;
|
|
111
|
+
maxRetries?: number;
|
|
112
|
+
retryTimeoutSeconds?: number;
|
|
113
|
+
}
|
|
114
|
+
/** What `eventStream` drives: the typed calls a generated events manager
|
|
115
|
+
* supplies. `server` lists a real-time server; `page` fetches the events after
|
|
116
|
+
* a stream position and the position to wait from next; `id` names an event
|
|
117
|
+
* so a repeat can be dropped. */
|
|
118
|
+
export interface EventSource<E> {
|
|
119
|
+
server(): Promise<LongPollServer>;
|
|
120
|
+
page(position: string): Promise<{
|
|
121
|
+
events: E[];
|
|
122
|
+
next?: string;
|
|
123
|
+
}>;
|
|
124
|
+
id(event: E): string | undefined;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Follow Box's long-poll protocol from `position` (`'now'` for events from
|
|
128
|
+
* here on): yield the events after it, each once, then wait on a real-time
|
|
129
|
+
* server until Box reports a change and yield those. A `reconnect` answer, or
|
|
130
|
+
* exhausting the server's retries, lists a fresh server. A long poll that times
|
|
131
|
+
* out or fails in transit is retried; an error response from Box ends the
|
|
132
|
+
* stream by throwing it, and aborting `signal` throws the abort.
|
|
133
|
+
*/
|
|
134
|
+
export declare function eventStream<E>(client: Client, position: string, source: EventSource<E>, signal?: AbortSignal): AsyncGenerator<E, void, undefined>;
|
|
135
|
+
/** A stream position Box sent as a JSON string or number, as the string to
|
|
136
|
+
* send back. */
|
|
137
|
+
export declare function streamPosition(value: unknown): string | undefined;
|
|
138
|
+
/** `JSON.parse`, except an integer too large for a `number` keeps its exact
|
|
139
|
+
* digits as a string — a stream position must round-trip unchanged. */
|
|
140
|
+
export declare function parseJsonExact(text: string): unknown;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** How old a delivery may be, in seconds, before it's rejected as a possible
|
|
2
|
+
* replay: Box's ten minutes. */
|
|
3
|
+
export declare const DEFAULT_WEBHOOK_MAX_AGE_SECONDS = 600;
|
|
4
|
+
/** The keys and limits a delivery is checked against. */
|
|
5
|
+
export interface WebhookKeys {
|
|
6
|
+
/** The app's primary signature key, from the Developer Console. */
|
|
7
|
+
primaryKey?: string;
|
|
8
|
+
/** The app's secondary signature key. A delivery is genuine when the
|
|
9
|
+
* signature of any configured key matches, so a key can be rotated while the
|
|
10
|
+
* other keeps verifying. */
|
|
11
|
+
secondaryKey?: string;
|
|
12
|
+
/** How old a delivery may be (default `DEFAULT_WEBHOOK_MAX_AGE_SECONDS`). */
|
|
13
|
+
maxAgeSeconds?: number;
|
|
14
|
+
/** The clock (default: now). */
|
|
15
|
+
now?: Date;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Whether `body` and `headers` are a genuine, recent delivery from Box. Pass
|
|
19
|
+
* the body exactly as received; header names match in any case. Resolves
|
|
20
|
+
* `false` for an unknown signature version or algorithm, a delivery older than
|
|
21
|
+
* the maximum age or timestamped in the future, and a signature no configured
|
|
22
|
+
* key produces.
|
|
23
|
+
*/
|
|
24
|
+
export declare function verifyWebhook(body: Uint8Array | string, headers: Headers | Record<string, string | undefined>, keys: WebhookKeys): Promise<boolean>;
|
package/docs/README.md
CHANGED
package/docs/auth.md
CHANGED
|
@@ -23,9 +23,9 @@ to act as a managed user:
|
|
|
23
23
|
```ts
|
|
24
24
|
import { auth } from '@unofficialbox/box-open-sdk';
|
|
25
25
|
const client = new Client(auth.clientCredentials({
|
|
26
|
-
clientId: 'CLIENT_ID',
|
|
27
|
-
clientSecret: 'CLIENT_SECRET',
|
|
28
|
-
enterpriseId: 'ENTERPRISE_ID',
|
|
26
|
+
clientId: 'CLIENT_ID',
|
|
27
|
+
clientSecret: 'CLIENT_SECRET',
|
|
28
|
+
enterpriseId: 'ENTERPRISE_ID',
|
|
29
29
|
}));
|
|
30
30
|
```
|
|
31
31
|
|
|
@@ -38,11 +38,11 @@ imported from the runtime's `./jwt` entry point and returns a promise:
|
|
|
38
38
|
```ts
|
|
39
39
|
import { jwtAuth } from '@unofficialbox/box-open-sdk/jwt';
|
|
40
40
|
const auth = await jwtAuth({
|
|
41
|
-
clientId: 'CLIENT_ID',
|
|
42
|
-
clientSecret: 'CLIENT_SECRET',
|
|
43
|
-
publicKeyId: 'PUBLIC_KEY_ID',
|
|
44
|
-
privateKeyPem: privateKeyPem, // optionally encrypted; set passphrase
|
|
45
|
-
enterpriseId: 'ENTERPRISE_ID',
|
|
41
|
+
clientId: 'CLIENT_ID',
|
|
42
|
+
clientSecret: 'CLIENT_SECRET',
|
|
43
|
+
publicKeyId: 'PUBLIC_KEY_ID',
|
|
44
|
+
privateKeyPem: privateKeyPem, // optionally encrypted; set passphrase
|
|
45
|
+
enterpriseId: 'ENTERPRISE_ID',
|
|
46
46
|
});
|
|
47
47
|
const client = new Client(auth);
|
|
48
48
|
```
|
|
@@ -58,3 +58,30 @@ import { auth } from '@unofficialbox/box-open-sdk';
|
|
|
58
58
|
const source = auth.oauth({ clientId: 'CLIENT_ID', clientSecret: 'CLIENT_SECRET' }, storedRefreshToken);
|
|
59
59
|
const client = new Client(source);
|
|
60
60
|
```
|
|
61
|
+
|
|
62
|
+
## Acting as another user
|
|
63
|
+
|
|
64
|
+
An admin, or a service account whose app may *make API calls using the as-user
|
|
65
|
+
header*, can act as another user. `withAsUserHeader` returns a new client whose
|
|
66
|
+
every call sends Box's `As-User` header; it shares the original's auth (and
|
|
67
|
+
token cache) and configuration, and the original is unchanged:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const userClient = client.withAsUserHeader('USER_ID');
|
|
71
|
+
const me = await userClient.users.getMe(); // the user USER_ID
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Downscoping a token
|
|
75
|
+
|
|
76
|
+
Exchange the session's access token for one limited to `scopes` and,
|
|
77
|
+
optionally, to one item (its API URL) or shared link — e.g. to hand a
|
|
78
|
+
browser-side preview a narrow token. The result has no refresh token; build
|
|
79
|
+
a client from it as a developer token:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const down = await client.authorization.downscopeToken(
|
|
83
|
+
['item_preview'],
|
|
84
|
+
'https://api.box.com/2.0/files/123',
|
|
85
|
+
);
|
|
86
|
+
const preview = new Client(auth.developerToken(down.access_token!));
|
|
87
|
+
```
|
package/docs/errors.md
CHANGED
|
@@ -26,12 +26,12 @@ Files and folders carry an `etag`. Send it back to stay in sync with Box
|
|
|
26
26
|
(Box's [Ensure consistency](https://developer.box.com/guides/api-calls/ensure-consistency/)
|
|
27
27
|
guide):
|
|
28
28
|
|
|
29
|
-
- **Reads** — a file or
|
|
29
|
+
- **Reads** — a file, folder, or web link `get`, and each shared-item lookup, has an
|
|
30
30
|
`…IfModified` variant that takes the stored etag, sends it as
|
|
31
31
|
`If-None-Match`, and returns `undefined` when Box answers `304 Not Modified`:
|
|
32
32
|
keep your cached copy. (The plain method surfaces that 304 as the error
|
|
33
33
|
above if you set `if-none-match` on it yourself.)
|
|
34
|
-
- **Writes** — pass the etag as `'if-match'` on a file or
|
|
34
|
+
- **Writes** — pass the etag as `'if-match'` on a file, folder, or web link update or
|
|
35
35
|
delete, or a new file version upload. Box answers `412 Precondition
|
|
36
36
|
Failed` (code `precondition_failed`) when the item changed since you read
|
|
37
37
|
it, and `runtime.isPreconditionFailed(err)` reports it: read it again,
|
|
@@ -25,6 +25,7 @@ const result = await client.webLinks.create({ /* … */ });
|
|
|
25
25
|
|---|---|---|---|
|
|
26
26
|
| `web_link_id` | path | `string` | yes |
|
|
27
27
|
| `boxapi` | header | `string` | no |
|
|
28
|
+
| `if-none-match` | header | `string` | no |
|
|
28
29
|
|
|
29
30
|
**Returns:** `WebLink`
|
|
30
31
|
|
|
@@ -41,6 +42,7 @@ const result = await client.webLinks.get("WEB_LINK_ID");
|
|
|
41
42
|
| Parameter | In | Type | Required |
|
|
42
43
|
|---|---|---|---|
|
|
43
44
|
| `web_link_id` | path | `string` | yes |
|
|
45
|
+
| `if-match` | header | `string` | no |
|
|
44
46
|
|
|
45
47
|
**Request body** (`application/json`): `UpdateWebLinkRequest`
|
|
46
48
|
|
|
@@ -59,6 +61,7 @@ const result = await client.webLinks.update("WEB_LINK_ID", { /* … */ });
|
|
|
59
61
|
| Parameter | In | Type | Required |
|
|
60
62
|
|---|---|---|---|
|
|
61
63
|
| `web_link_id` | path | `string` | yes |
|
|
64
|
+
| `if-match` | header | `string` | no |
|
|
62
65
|
|
|
63
66
|
**Returns:** `void`
|
|
64
67
|
|
package/docs/pagination.md
CHANGED
|
@@ -7,7 +7,7 @@ that yields one entry at a time, threading the cursor for you — the list metho
|
|
|
7
7
|
|
|
8
8
|
```ts
|
|
9
9
|
for await (const item of client.folders.listItems(folderId)) {
|
|
10
|
-
// use item
|
|
10
|
+
// use item
|
|
11
11
|
}
|
|
12
12
|
```
|
|
13
13
|
|
|
@@ -15,3 +15,19 @@ It walks every page until the response has no next cursor (or an empty page, for
|
|
|
15
15
|
offset pagination), and owns a private copy of the options you pass, so your
|
|
16
16
|
value is never mutated. The wire cursor (`next_marker` / `offset`, verbatim per
|
|
17
17
|
TR-TS.2) is threaded through the options for you.
|
|
18
|
+
|
|
19
|
+
## Events
|
|
20
|
+
|
|
21
|
+
`client.events.stream` follows Box's long-poll event stream: it yields the events
|
|
22
|
+
after `stream_position` (`'now'` when unset), each once — Box may deliver an
|
|
23
|
+
event twice — then waits on a real-time server until Box reports a change. It
|
|
24
|
+
lists a fresh server when Box asks it to reconnect, and retries a long poll that
|
|
25
|
+
times out. It rejects when a call fails; `break` or an `AbortSignal` stops it.
|
|
26
|
+
Stream positions keep every digit, even past `Number.MAX_SAFE_INTEGER`:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
for await (const event of client.events.stream({}, controller.signal)) {
|
|
31
|
+
// use event
|
|
32
|
+
}
|
|
33
|
+
```
|
package/docs/webhooks.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<!-- Generated by box-gantry. DO NOT EDIT. -->
|
|
2
|
+
# Webhooks
|
|
3
|
+
|
|
4
|
+
Once you generate signature keys for your app (Developer Console → **Webhooks**
|
|
5
|
+
→ **Manage signature keys**), Box signs every webhook delivery. Each
|
|
6
|
+
`BOX-SIGNATURE-PRIMARY` / `BOX-SIGNATURE-SECONDARY` header is the base64
|
|
7
|
+
HMAC-SHA256, under that key, of the request body followed by the
|
|
8
|
+
`BOX-DELIVERY-TIMESTAMP` header (Box's
|
|
9
|
+
[Verify webhook signatures](https://developer.box.com/guides/webhooks/v2/signatures-v2/)
|
|
10
|
+
guide). `runtime.verifyWebhook` checks a delivery before you trust it:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { runtime } from '@unofficialbox/box-open-sdk';
|
|
14
|
+
|
|
15
|
+
// `body`: the raw request body (bytes or string); `headers`: a `Headers`
|
|
16
|
+
// object or a plain record.
|
|
17
|
+
const genuine = await runtime.verifyWebhook(body, headers, {
|
|
18
|
+
primaryKey,
|
|
19
|
+
secondaryKey,
|
|
20
|
+
});
|
|
21
|
+
if (!genuine) {
|
|
22
|
+
// reject: not from Box, altered, or stale
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
- **Pass the body exactly as received.** Parsed and re-serialized JSON won't
|
|
27
|
+
verify.
|
|
28
|
+
- **Either key may be missing.** A delivery is genuine when the signature of
|
|
29
|
+
any configured key matches, so you can rotate one key while the other keeps
|
|
30
|
+
verifying.
|
|
31
|
+
- **Old or future deliveries are refused.** A delivery stamped more than ten
|
|
32
|
+
minutes ago (`maxAgeSeconds`) or in the future fails, which blocks replays.
|
|
33
|
+
- **Header names match in any case**, and the comparison takes the same time
|
|
34
|
+
wherever a signature differs.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unofficialbox/box-open-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Box API client for TypeScript (open source, community, punk rock) — typed models, async managers, and a fetch runtime with retry, backoff, and token refresh.",
|
|
5
5
|
"keywords": ["box", "box-api", "sdk", "api-client", "typescript", "unofficial"],
|
|
6
6
|
"license": "MIT",
|