@unofficialbox/box-open-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.
@@ -65,6 +65,19 @@ class FilesManager {
65
65
  const data = runtime.responseBytes(resp);
66
66
  return JSON.parse(new TextDecoder().decode(data));
67
67
  }
68
+ /** `get` with `If-None-Match` set to `etag`: resolves `undefined` when
69
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
70
+ async getIfModified(fileId, etag, opts) {
71
+ try {
72
+ return await this.get(fileId, { ...opts, "if-none-match": etag });
73
+ }
74
+ catch (err) {
75
+ if (err instanceof runtime.BoxApiError && err.status === 304) {
76
+ return undefined;
77
+ }
78
+ throw err;
79
+ }
80
+ }
68
81
  async update(fileId, body, opts) {
69
82
  let url = this.session.baseUrl("api");
70
83
  url += "/files";
@@ -74,6 +74,19 @@ class FoldersManager {
74
74
  const data = runtime.responseBytes(resp);
75
75
  return JSON.parse(new TextDecoder().decode(data));
76
76
  }
77
+ /** `get` with `If-None-Match` set to `etag`: resolves `undefined` when
78
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
79
+ async getIfModified(folderId, etag, opts) {
80
+ try {
81
+ return await this.get(folderId, { ...opts, "if-none-match": etag });
82
+ }
83
+ catch (err) {
84
+ if (err instanceof runtime.BoxApiError && err.status === 304) {
85
+ return undefined;
86
+ }
87
+ throw err;
88
+ }
89
+ }
77
90
  async update(folderId, body, opts) {
78
91
  let url = this.session.baseUrl("api");
79
92
  url += "/folders";
@@ -59,6 +59,19 @@ class SharedLinksFilesManager {
59
59
  const data = runtime.responseBytes(resp);
60
60
  return JSON.parse(new TextDecoder().decode(data));
61
61
  }
62
+ /** `getSharedItems` with `If-None-Match` set to `etag`: resolves `undefined` when
63
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
64
+ async getSharedItemsIfModified(boxapi, etag, opts) {
65
+ try {
66
+ return await this.getSharedItems(boxapi, { ...opts, "if-none-match": etag });
67
+ }
68
+ catch (err) {
69
+ if (err instanceof runtime.BoxApiError && err.status === 304) {
70
+ return undefined;
71
+ }
72
+ throw err;
73
+ }
74
+ }
62
75
  async getFileGetSharedLink(fileId, fields) {
63
76
  let url = this.session.baseUrl("api");
64
77
  url += "/files";
@@ -59,6 +59,19 @@ class SharedLinksFoldersManager {
59
59
  const data = runtime.responseBytes(resp);
60
60
  return JSON.parse(new TextDecoder().decode(data));
61
61
  }
62
+ /** `getSharedItemsFolders` with `If-None-Match` set to `etag`: resolves `undefined` when
63
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
64
+ async getSharedItemsIfModifiedFolders(boxapi, etag, opts) {
65
+ try {
66
+ return await this.getSharedItemsFolders(boxapi, { ...opts, "if-none-match": etag });
67
+ }
68
+ catch (err) {
69
+ if (err instanceof runtime.BoxApiError && err.status === 304) {
70
+ return undefined;
71
+ }
72
+ throw err;
73
+ }
74
+ }
62
75
  async getFolderGetSharedLink(folderId, fields) {
63
76
  let url = this.session.baseUrl("api");
64
77
  url += "/folders";
@@ -59,6 +59,19 @@ class SharedLinksWebLinksManager {
59
59
  const data = runtime.responseBytes(resp);
60
60
  return JSON.parse(new TextDecoder().decode(data));
61
61
  }
62
+ /** `getSharedItemsWebLinks` with `If-None-Match` set to `etag`: resolves `undefined` when
63
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
64
+ async getSharedItemsIfModifiedWebLinks(boxapi, etag, opts) {
65
+ try {
66
+ return await this.getSharedItemsWebLinks(boxapi, { ...opts, "if-none-match": etag });
67
+ }
68
+ catch (err) {
69
+ if (err instanceof runtime.BoxApiError && err.status === 304) {
70
+ return undefined;
71
+ }
72
+ throw err;
73
+ }
74
+ }
62
75
  async getWebLinkGetSharedLink(webLinkId, fields) {
63
76
  let url = this.session.baseUrl("api");
64
77
  url += "/web_links";
@@ -29,6 +29,19 @@ export class FilesManager {
29
29
  const data = runtime.responseBytes(resp);
30
30
  return JSON.parse(new TextDecoder().decode(data));
31
31
  }
32
+ /** `get` with `If-None-Match` set to `etag`: resolves `undefined` when
33
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
34
+ async getIfModified(fileId, etag, opts) {
35
+ try {
36
+ return await this.get(fileId, { ...opts, "if-none-match": etag });
37
+ }
38
+ catch (err) {
39
+ if (err instanceof runtime.BoxApiError && err.status === 304) {
40
+ return undefined;
41
+ }
42
+ throw err;
43
+ }
44
+ }
32
45
  async update(fileId, body, opts) {
33
46
  let url = this.session.baseUrl("api");
34
47
  url += "/files";
@@ -38,6 +38,19 @@ export class FoldersManager {
38
38
  const data = runtime.responseBytes(resp);
39
39
  return JSON.parse(new TextDecoder().decode(data));
40
40
  }
41
+ /** `get` with `If-None-Match` set to `etag`: resolves `undefined` when
42
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
43
+ async getIfModified(folderId, etag, opts) {
44
+ try {
45
+ return await this.get(folderId, { ...opts, "if-none-match": etag });
46
+ }
47
+ catch (err) {
48
+ if (err instanceof runtime.BoxApiError && err.status === 304) {
49
+ return undefined;
50
+ }
51
+ throw err;
52
+ }
53
+ }
41
54
  async update(folderId, body, opts) {
42
55
  let url = this.session.baseUrl("api");
43
56
  url += "/folders";
@@ -23,6 +23,19 @@ export class SharedLinksFilesManager {
23
23
  const data = runtime.responseBytes(resp);
24
24
  return JSON.parse(new TextDecoder().decode(data));
25
25
  }
26
+ /** `getSharedItems` with `If-None-Match` set to `etag`: resolves `undefined` when
27
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
28
+ async getSharedItemsIfModified(boxapi, etag, opts) {
29
+ try {
30
+ return await this.getSharedItems(boxapi, { ...opts, "if-none-match": etag });
31
+ }
32
+ catch (err) {
33
+ if (err instanceof runtime.BoxApiError && err.status === 304) {
34
+ return undefined;
35
+ }
36
+ throw err;
37
+ }
38
+ }
26
39
  async getFileGetSharedLink(fileId, fields) {
27
40
  let url = this.session.baseUrl("api");
28
41
  url += "/files";
@@ -23,6 +23,19 @@ export class SharedLinksFoldersManager {
23
23
  const data = runtime.responseBytes(resp);
24
24
  return JSON.parse(new TextDecoder().decode(data));
25
25
  }
26
+ /** `getSharedItemsFolders` with `If-None-Match` set to `etag`: resolves `undefined` when
27
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
28
+ async getSharedItemsIfModifiedFolders(boxapi, etag, opts) {
29
+ try {
30
+ return await this.getSharedItemsFolders(boxapi, { ...opts, "if-none-match": etag });
31
+ }
32
+ catch (err) {
33
+ if (err instanceof runtime.BoxApiError && err.status === 304) {
34
+ return undefined;
35
+ }
36
+ throw err;
37
+ }
38
+ }
26
39
  async getFolderGetSharedLink(folderId, fields) {
27
40
  let url = this.session.baseUrl("api");
28
41
  url += "/folders";
@@ -23,6 +23,19 @@ export class SharedLinksWebLinksManager {
23
23
  const data = runtime.responseBytes(resp);
24
24
  return JSON.parse(new TextDecoder().decode(data));
25
25
  }
26
+ /** `getSharedItemsWebLinks` with `If-None-Match` set to `etag`: resolves `undefined` when
27
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
28
+ async getSharedItemsIfModifiedWebLinks(boxapi, etag, opts) {
29
+ try {
30
+ return await this.getSharedItemsWebLinks(boxapi, { ...opts, "if-none-match": etag });
31
+ }
32
+ catch (err) {
33
+ if (err instanceof runtime.BoxApiError && err.status === 304) {
34
+ return undefined;
35
+ }
36
+ throw err;
37
+ }
38
+ }
26
39
  async getWebLinkGetSharedLink(webLinkId, fields) {
27
40
  let url = this.session.baseUrl("api");
28
41
  url += "/web_links";
@@ -32,6 +32,9 @@ export declare class FilesManager {
32
32
  private readonly session;
33
33
  constructor(session: runtime.Client);
34
34
  get(fileId: string, opts?: FilesManagerGetOptions): Promise<models.schemas.FileFull>;
35
+ /** `get` with `If-None-Match` set to `etag`: resolves `undefined` when
36
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
37
+ getIfModified(fileId: string, etag: string, opts?: FilesManagerGetOptions): Promise<models.schemas.FileFull | undefined>;
35
38
  update(fileId: string, body: models.schemas.UpdateFileRequest, opts?: FilesManagerUpdateOptions): Promise<models.schemas.FileFull>;
36
39
  delete_(fileId: string, opts?: FilesManagerDeleteOptions): Promise<void>;
37
40
  copy(fileId: string, body: models.schemas.CopyFileRequest, opts?: FilesManagerCopyOptions): Promise<models.schemas.FileFull>;
@@ -44,6 +44,9 @@ export declare class FoldersManager {
44
44
  private readonly session;
45
45
  constructor(session: runtime.Client);
46
46
  get(folderId: string, opts?: FoldersManagerGetOptions): Promise<models.schemas.FolderFull>;
47
+ /** `get` with `If-None-Match` set to `etag`: resolves `undefined` when
48
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
49
+ getIfModified(folderId: string, etag: string, opts?: FoldersManagerGetOptions): Promise<models.schemas.FolderFull | undefined>;
47
50
  update(folderId: string, body: models.schemas.UpdateFolderRequest, opts?: FoldersManagerUpdateOptions): Promise<models.schemas.FolderFull>;
48
51
  delete_(folderId: string, opts?: FoldersManagerDeleteOptions): Promise<void>;
49
52
  /** Iterate every `models.schemas.Item` across pages, threading the marker cursor. */
@@ -10,6 +10,9 @@ export declare class SharedLinksFilesManager {
10
10
  private readonly session;
11
11
  constructor(session: runtime.Client);
12
12
  getSharedItems(boxapi: string, opts?: SharedLinksFilesManagerGetSharedItemsOptions): Promise<models.schemas.FileFull>;
13
+ /** `getSharedItems` with `If-None-Match` set to `etag`: resolves `undefined` when
14
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
15
+ getSharedItemsIfModified(boxapi: string, etag: string, opts?: SharedLinksFilesManagerGetSharedItemsOptions): Promise<models.schemas.FileFull | undefined>;
13
16
  getFileGetSharedLink(fileId: string, fields: string): Promise<models.schemas.FileFull>;
14
17
  updateFileAddSharedLink(fileId: string, fields: string, body: models.schemas.UpdateFileAddSharedLinkRequest): Promise<models.schemas.FileFull>;
15
18
  updateFileUpdateSharedLink(fileId: string, fields: string, body: models.schemas.UpdateFileAddSharedLinkRequest): Promise<models.schemas.FileFull>;
@@ -10,6 +10,9 @@ export declare class SharedLinksFoldersManager {
10
10
  private readonly session;
11
11
  constructor(session: runtime.Client);
12
12
  getSharedItemsFolders(boxapi: string, opts?: SharedLinksFoldersManagerGetSharedItemsFoldersOptions): Promise<models.schemas.FolderFull>;
13
+ /** `getSharedItemsFolders` with `If-None-Match` set to `etag`: resolves `undefined` when
14
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
15
+ getSharedItemsIfModifiedFolders(boxapi: string, etag: string, opts?: SharedLinksFoldersManagerGetSharedItemsFoldersOptions): Promise<models.schemas.FolderFull | undefined>;
13
16
  getFolderGetSharedLink(folderId: string, fields: string): Promise<models.schemas.FolderFull>;
14
17
  updateFolderAddSharedLink(folderId: string, fields: string, body: models.schemas.UpdateFileAddSharedLinkRequest): Promise<models.schemas.FolderFull>;
15
18
  updateFolderUpdateSharedLink(folderId: string, fields: string, body: models.schemas.UpdateFolderUpdateSharedLinkRequest): Promise<models.schemas.FolderFull>;
@@ -10,6 +10,9 @@ export declare class SharedLinksWebLinksManager {
10
10
  private readonly session;
11
11
  constructor(session: runtime.Client);
12
12
  getSharedItemsWebLinks(boxapi: string, opts?: SharedLinksWebLinksManagerGetSharedItemsWebLinksOptions): Promise<models.schemas.WebLink>;
13
+ /** `getSharedItemsWebLinks` with `If-None-Match` set to `etag`: resolves `undefined` when
14
+ * the item is unchanged since `etag` (Box answers 304 Not Modified). */
15
+ getSharedItemsIfModifiedWebLinks(boxapi: string, etag: string, opts?: SharedLinksWebLinksManagerGetSharedItemsWebLinksOptions): Promise<models.schemas.WebLink | undefined>;
13
16
  getWebLinkGetSharedLink(webLinkId: string, fields: string): Promise<models.schemas.WebLink>;
14
17
  updateWebLinkAddSharedLink(webLinkId: string, fields: string, body: models.schemas.UpdateFileAddSharedLinkRequest): Promise<models.schemas.WebLink>;
15
18
  updateWebLinkUpdateSharedLink(webLinkId: string, fields: string, body: models.schemas.UpdateFileAddSharedLinkRequest): Promise<models.schemas.WebLink>;
package/docs/errors.md CHANGED
@@ -12,10 +12,40 @@ and the raw `body`; transport and decode failures carry the underlying
12
12
  ```ts
13
13
  import { runtime } from '@unofficialbox/box-open-sdk';
14
14
  try {
15
- await client.files.getFileById(fileId);
15
+ await client.files.get(fileId);
16
16
  } catch (err) {
17
- if (err instanceof runtime.BoxApiError) {
18
- // err.status, err.code, err.boxMessage, err.requestId, err.body, err.cause
17
+ if (err instanceof runtime.BoxApiError) {
18
+ // err.status, err.code, err.boxMessage, err.requestId, err.body, err.cause
19
+ }
19
20
  }
21
+ ```
22
+
23
+ ## Etags: `If-None-Match` and `If-Match`
24
+
25
+ Files and folders carry an `etag`. Send it back to stay in sync with Box
26
+ (Box's [Ensure consistency](https://developer.box.com/guides/api-calls/ensure-consistency/)
27
+ guide):
28
+
29
+ - **Reads** — a file or folder `get`, and each shared-item lookup, has an
30
+ `…IfModified` variant that takes the stored etag, sends it as
31
+ `If-None-Match`, and returns `undefined` when Box answers `304 Not Modified`:
32
+ keep your cached copy. (The plain method surfaces that 304 as the error
33
+ above if you set `if-none-match` on it yourself.)
34
+ - **Writes** — pass the etag as `'if-match'` on a file or folder update or
35
+ delete, or a new file version upload. Box answers `412 Precondition
36
+ Failed` (code `precondition_failed`) when the item changed since you read
37
+ it: read it again, reapply your change, retry. `If-Match` can't block a move.
38
+
39
+ ```ts
40
+ const file = await client.files.getIfModified(fileId, etag);
41
+ if (file === undefined) {
42
+ // unchanged since etag
43
+ }
44
+ try {
45
+ await client.files.update(fileId, body, { 'if-match': etag });
46
+ } catch (err) {
47
+ if (err instanceof runtime.BoxApiError && err.status === 412) {
48
+ // changed since etag: re-read and retry
49
+ }
20
50
  }
21
51
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unofficialbox/box-open-sdk",
3
- "version": "0.6.0",
3
+ "version": "0.7.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",