@usenadia/node 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +195 -2
- package/dist/index.d.mts +4519 -0
- package/dist/index.d.ts +4519 -0
- package/dist/index.js +1809 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1701 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +41 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vincent Ventalon (UseNadia)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,196 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @usenadia/node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Node SDK for the **UseNadia** public API (`/public/v1`) — schedule posts,
|
|
4
|
+
manage channels, and drive the Instagram comment/story → DM machinery.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pnpm add @usenadia/node
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
<!-- smoke:start -->
|
|
11
|
+
```ts
|
|
12
|
+
import { Nadia, NadiaError } from '@usenadia/node';
|
|
13
|
+
|
|
14
|
+
const nadia = new Nadia(process.env.NADIA_API_KEY ?? '');
|
|
15
|
+
|
|
16
|
+
const channels = await nadia.integrations();
|
|
17
|
+
const instagram = channels.find((c) => c.identifier === 'instagram-standalone');
|
|
18
|
+
if (!instagram) throw new Error('Connect an Instagram account first.');
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const [{ postId }] = await nadia.post({
|
|
22
|
+
type: 'draft', // or 'schedule' / 'now'
|
|
23
|
+
date: '2030-01-15T09:00:00.000Z',
|
|
24
|
+
shortLink: false,
|
|
25
|
+
tags: [],
|
|
26
|
+
posts: [
|
|
27
|
+
{
|
|
28
|
+
integration: { id: instagram.id },
|
|
29
|
+
value: [{ content: 'Hello from the SDK', image: [] }],
|
|
30
|
+
// Each network has its own settings; Instagram wants `post_type`.
|
|
31
|
+
settings: { __type: 'instagram-standalone', post_type: 'post' },
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
await nadia.deletePost(postId);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
if (err instanceof NadiaError) {
|
|
39
|
+
console.error(err.status, err.message); // 402 "You have reached your limit"
|
|
40
|
+
}
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
<!-- smoke:end -->
|
|
45
|
+
|
|
46
|
+
This block is run as is against the real API by the smoke test
|
|
47
|
+
(`test/smoke.test.mjs`): if it stops working, the release stops.
|
|
48
|
+
|
|
49
|
+
## The content board
|
|
50
|
+
|
|
51
|
+
Every card of the board in the app is reachable: create one from anywhere
|
|
52
|
+
(a voice note, a Notion page, a DM), move it along, read its numbers once
|
|
53
|
+
it is published.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const card = await nadia.createContent({
|
|
57
|
+
title: 'Three mistakes when moving to Malta',
|
|
58
|
+
hook: 'Nobody told me about the third one.',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
await nadia.moveContent(card.id, 'SCRIPT');
|
|
62
|
+
await nadia.updateContent(card.id, { script: '…' });
|
|
63
|
+
|
|
64
|
+
// Scheduled with nadia.post({ …, posts: [{ group: 'g-42', … }] }):
|
|
65
|
+
await nadia.linkContentPost(card.id, 'g-42'); // → PUBLISHED when it goes live
|
|
66
|
+
|
|
67
|
+
const numbers = await nadia.contentsPerformance(); // keyed by card id
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Columns, in order: `IDEA`, `SCRIPT`, `VALIDATED`, `TO_SHOOT`, `TO_EDIT`,
|
|
71
|
+
`TO_SCHEDULE`, `PUBLISHED`.
|
|
72
|
+
|
|
73
|
+
## How it is built
|
|
74
|
+
|
|
75
|
+
Two layers, and the split is deliberate.
|
|
76
|
+
|
|
77
|
+
- **`src/generated/`** — the transport. Generated from `openapi.public.json`
|
|
78
|
+
by [`@hey-api/openapi-ts`](https://heyapi.dev), covers every operation,
|
|
79
|
+
never edited by hand, not committed.
|
|
80
|
+
- **`src/index.ts`** — this SDK's own surface: the `Nadia` class, sane
|
|
81
|
+
defaults, typed errors, retries. Small, hand-written, reviewed.
|
|
82
|
+
|
|
83
|
+
Everything the facade does not wrap is still reachable — the generated
|
|
84
|
+
operations and types are re-exported, and `nadia.raw` is the configured
|
|
85
|
+
client:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { getChannelAnalytics } from '@usenadia/node';
|
|
89
|
+
|
|
90
|
+
await getChannelAnalytics({
|
|
91
|
+
client: nadia.raw,
|
|
92
|
+
path: { integration: channelId },
|
|
93
|
+
query: { date: '30' },
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Same call, with the facade's typed errors and retries:
|
|
97
|
+
await nadia.request((o) =>
|
|
98
|
+
getChannelAnalytics({ ...o, path: { integration: channelId }, query: { date: '30' } })
|
|
99
|
+
);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Webhooks
|
|
103
|
+
|
|
104
|
+
UseNadia signs every delivery: `X-Nadia-Signature: sha256=<hex>`, an
|
|
105
|
+
HMAC-SHA256 of `` `${X-Nadia-Timestamp}.${raw body}` `` with the secret
|
|
106
|
+
returned when the webhook was created. `parseWebhook` checks it (in constant
|
|
107
|
+
time), refuses a timestamp more than 5 minutes off, and returns the parsed
|
|
108
|
+
delivery — or throws a `NadiaWebhookError` whose `reason` says why
|
|
109
|
+
(`missing_header`, `bad_signature`, `stale`, `bad_body`).
|
|
110
|
+
|
|
111
|
+
**Read the raw body.** A body parsed then re-serialized is not byte-identical
|
|
112
|
+
and will not verify.
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import express from 'express';
|
|
116
|
+
import { parseWebhook, NadiaWebhookError } from '@usenadia/node';
|
|
117
|
+
|
|
118
|
+
const app = express();
|
|
119
|
+
|
|
120
|
+
app.post('/nadia', express.raw({ type: 'application/json' }), (req, res) => {
|
|
121
|
+
try {
|
|
122
|
+
const delivery = parseWebhook({
|
|
123
|
+
secret: process.env.NADIA_WEBHOOK_SECRET!,
|
|
124
|
+
headers: req.headers,
|
|
125
|
+
body: req.body, // a Buffer, thanks to express.raw()
|
|
126
|
+
});
|
|
127
|
+
if (delivery.event === 'post.published') {
|
|
128
|
+
// delivery.data …
|
|
129
|
+
}
|
|
130
|
+
res.sendStatus(200);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (err instanceof NadiaWebhookError) return res.status(400).send(err.reason);
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Fastify: register a `content-type` parser with `{ parseAs: 'buffer' }` and
|
|
139
|
+
pass `request.headers` and the buffer the same way. With the Fetch API
|
|
140
|
+
(Next.js route handlers, Hono, Workers with `nodejs_compat`):
|
|
141
|
+
`parseWebhook({ secret, headers: request.headers, body: await request.text() })`.
|
|
142
|
+
|
|
143
|
+
`verifyWebhookSignature({ secret, signature, timestamp, body, tolerance? })`
|
|
144
|
+
is the primitive underneath: it returns a boolean and checks the timestamp
|
|
145
|
+
only when `tolerance` (seconds) is given. Both are tested against the
|
|
146
|
+
fixture the server signs with
|
|
147
|
+
(`libraries/nestjs-libraries/src/database/prisma/webhooks/__fixtures__/signed-delivery.json`).
|
|
148
|
+
|
|
149
|
+
## Errors
|
|
150
|
+
|
|
151
|
+
Every response with a status ≥ 400 throws a `NadiaError` carrying `status`,
|
|
152
|
+
`body` and the API's message (`msg`, or the list of fields a validation
|
|
153
|
+
error names). `err.isTransient` is true for 429 and 5xx — those
|
|
154
|
+
are retried automatically (twice by default, `new Nadia(key, { retries: 0 })`
|
|
155
|
+
to turn it off).
|
|
156
|
+
|
|
157
|
+
## Coming from upstream's SDK
|
|
158
|
+
|
|
159
|
+
The class is called `Nadia` instead of upstream's name. Otherwise
|
|
160
|
+
`new Nadia(apiKey, baseUrl?)` and the five original methods (`post`,
|
|
161
|
+
`postList`, `upload`, `integrations`, `deletePost`) keep their names and
|
|
162
|
+
shapes, so existing code only changes its import. Two other differences,
|
|
163
|
+
both fixes:
|
|
164
|
+
|
|
165
|
+
- **HTTP errors are no longer swallowed.** Upstream called `.json()` without
|
|
166
|
+
looking at the status, so a 402 came back looking like a success.
|
|
167
|
+
- **`deletePost()` awaits.** Upstream returned an unawaited `fetch`.
|
|
168
|
+
|
|
169
|
+
The default base URL is `https://app.usenadia.com/api`.
|
|
170
|
+
|
|
171
|
+
## Regenerating and testing
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
pnpm run generate # from apps/sdk/node — reads ../../../openapi.public.json
|
|
175
|
+
pnpm run build
|
|
176
|
+
pnpm test # offline, stubbed transport
|
|
177
|
+
NADIA_API_KEY=… pnpm run test:smoke # real API: one draft in 2030, deleted
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Releasing
|
|
181
|
+
|
|
182
|
+
A tag publishes; nothing is published from a laptop.
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# 1. bump "version" in apps/sdk/node/package.json, commit, push main
|
|
186
|
+
# 2. tag it — the tag must equal the version
|
|
187
|
+
git tag node-v0.1.1 && git push origin node-v0.1.1
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`.github/workflows/publish-npm.yml` refuses a tag that does not match
|
|
191
|
+
`package.json`, builds, runs the offline tests **and the smoke test against
|
|
192
|
+
the real API**, and publishes only if all are green (npm Trusted Publisher,
|
|
193
|
+
no token).
|
|
194
|
+
|
|
195
|
+
`openapi.public.json` itself is produced by `pnpm openapi:dump` at the repo
|
|
196
|
+
root and guarded by CI. Plan: `docs/roadmap/done/19-sdk-public-api.md`.
|