@usenadia/node 0.3.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"
@@ -75,6 +82,31 @@ ends (15 minutes at most, `importPoll` in the options), and resolves to the
75
82
  media all the same. A failed import throws the `NadiaError` the server would
76
83
  have answered at once.
77
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).
109
+
78
110
  ## The content board
79
111
 
80
112
  Every card of the board in the app is reachable: create one from anywhere