@usenadia/node 0.2.0 → 0.4.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/README.md CHANGED
@@ -9,7 +9,7 @@ pnpm add @usenadia/node
9
9
 
10
10
  <!-- smoke:start -->
11
11
  ```ts
12
- import { Nadia, NadiaError } from '@usenadia/node';
12
+ import { Nadia, NadiaConfirmationRequired, NadiaError } from '@usenadia/node';
13
13
 
14
14
  const nadia = new Nadia(process.env.NADIA_API_KEY ?? '');
15
15
 
@@ -33,7 +33,14 @@ try {
33
33
  ],
34
34
  });
35
35
 
36
- await nadia.deletePost(postId);
36
+ // A deletion waits for a yes by default: nothing is done on the first call
37
+ // (see Confirmations below). This draft is ours, so we confirm it.
38
+ try {
39
+ await nadia.deletePost(postId);
40
+ } catch (err) {
41
+ if (!(err instanceof NadiaConfirmationRequired)) throw err;
42
+ await err.confirm();
43
+ }
37
44
  } catch (err) {
38
45
  if (err instanceof NadiaError) {
39
46
  console.error(err.status, err.message); // 402 "You have reached your limit"
@@ -56,11 +63,49 @@ media.path; // what a post takes as image[].
56
63
  An MP4, JPEG, PNG, WebP or GIF goes in parts of 20 MB straight to the
57
64
  storage, four at a time: a part cut by the network is sent again, and so are
58
65
  the parts the server says are missing, before it confirms. Up to 500 MB.
59
- A server without the upload in parts, or another type (HEIC, MOV, which the
60
- server converts), gets the whole file in one request, as before. In one
61
- request the server takes an image up to 10 MB, a MOV up to 1 GB, and an MP4
62
- up to 25 MB only (`413 FILE_TOO_LARGE` beyond: a recent server takes it in
63
- parts).
66
+ A server without the upload in parts, or another image type (HEIC, which the
67
+ server converts to JPEG; AVIF…), gets the whole file in one request, as
68
+ before. In one request the server takes an image up to 10 MB and an MP4 up to
69
+ 25 MB only (`413 FILE_TOO_LARGE` beyond: a recent server takes it in parts).
70
+ A MOV or an M4V is converted on neither path: the server refuses it (`415`),
71
+ convert it to MP4 first (`ffmpeg -i in.mov -c copy -movflags +faststart out.mp4`).
72
+
73
+ A file already online goes in by its URL, downloaded by the server:
74
+
75
+ ```ts
76
+ const media = await nadia.uploadFromUrl('https://cdn.example.com/reel.mp4');
77
+ ```
78
+
79
+ A long import (not done within 25 seconds) is answered `202` by the server
80
+ and goes on there: `uploadFromUrl` reads it again every 3 seconds until it
81
+ ends (15 minutes at most, `importPoll` in the options), and resolves to the
82
+ media all the same. A failed import throws the `NadiaError` the server would
83
+ have answered at once.
84
+
85
+ ## Confirmations
86
+
87
+ Since 0.4.0. In Settings › Developers, each action of the API either runs at once or
88
+ waits for a yes (the same two columns as the MCP; by default, the deletions
89
+ of a post, a card, a webhook and a workspace wait). Such an action answers
90
+ `428` and **does nothing**: the SDK throws `NadiaConfirmationRequired`, with
91
+ `preview` (what the action will do) and `confirmationToken`.
92
+
93
+ ```ts
94
+ try {
95
+ await nadia.deletePost(id);
96
+ } catch (err) {
97
+ if (!(err instanceof NadiaConfirmationRequired)) throw err;
98
+ console.log(err.preview); // { action: 'post.delete', request: 'DELETE …', … }
99
+ if (await askTheUser()) await err.confirm(); // the same request, with the token
100
+ }
101
+ ```
102
+
103
+ The token is single use and lasts 15 minutes; another body or query asks
104
+ again. `deletePost(id, { confirmationToken })` and `deleteContent` take it
105
+ directly, and any generated operation takes it as `query.confirmationToken`.
106
+ `new Nadia(key, { autoConfirm: true })` confirms every `428` at once (once
107
+ per call): only for a program that already has its user's yes. Details:
108
+ [usenadia.com/docs/public-api/confirmations](https://usenadia.com/docs/public-api/confirmations).
64
109
 
65
110
  ## The content board
66
111