@postshiba/node 0.0.0-stage → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ Adds the rest of the API catalog: bulk send (`emails.sendBulk`, `listBulk`, `getBulk`), IP pools, outbound messages and retention, DKIM signing, recipients, analytics, status, planned sends, support tickets, ShieldShiba sites, and new actions on clusters, network, sending domains, tenants, inboxes, SMTP credentials, webhooks, and suppressions. List methods take only the query options you set.
6
+
7
+ ## 0.1.0
8
+
9
+ Initial Node.js client. Published to npm as `@postshiba/node` (compiled ESM). `postshiba` is a thin alias of the same version.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PostShiba
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,444 @@
1
- # Temporary Holding Version
1
+ # PostShiba
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > [!NOTE]
4
+ > [PostShiba skills](https://github.com/postshiba/postshiba-skills) connect agents to MCP for first send, domains, inboxes, and sandbox mail.
5
+
6
+ PostShiba API client for Node.js.
7
+
8
+ ## Installation
9
+
10
+ ```sh
11
+ npm install @postshiba/node
12
+ ```
13
+
14
+ `npm install postshiba` is the same client.
15
+
16
+ Node 18 or later. The client uses `fetch`. Open pull requests on [postshiba/sdks](https://github.com/postshiba/sdks).
17
+
18
+ ## How It Works
19
+
20
+ `PostShiba` is a thin HTTPS client. Pass a platform application token. Team-scoped routes need `teamId` on the constructor. `GET /users/me` does not return one, so the client does not guess.
21
+
22
+ Send mail with `emails.send`. Nest services inject the same client and call that method.
23
+
24
+ ## Send an email
25
+
26
+ ```ts
27
+ import { PostShiba } from "@postshiba/node"
28
+
29
+ const postshiba = new PostShiba(process.env.POSTSHIBA_API_KEY, { teamId: "KjkAJW" })
30
+
31
+ await postshiba.emails.send({
32
+ from: "hello@mail.example.com",
33
+ to: ["you@example.com"],
34
+ subject: "PostShiba test",
35
+ text: "hello from PostShiba",
36
+ html: "<p>hello from PostShiba</p>",
37
+ })
38
+ ```
39
+
40
+ Pass `clusterId` to send `X-Capsule-Cluster-Id`. The path stays `POST /api/v1/emails`.
41
+
42
+ ```ts
43
+ await postshiba.emails.send(body, { clusterId: "NmQpXr" })
44
+ ```
45
+
46
+ Cluster send can set `sandbox` and send `Idempotency-Key`:
47
+
48
+ ```ts
49
+ await postshiba.emails.sendOnCluster("NmQpXr", body, {
50
+ sandbox: true,
51
+ idempotencyKey: "ikey-1",
52
+ })
53
+ ```
54
+
55
+ ## Send in bulk
56
+
57
+ Send up to 1,000 `messages` in one request. Each message has `to`, an optional `name`, `variables`, and `unique_args`. Liquid such as `{{ name }}` works in `subject`, `html`, `text`, `reply_to`, and header values.
58
+
59
+ ```ts
60
+ await postshiba.emails.sendBulk({
61
+ from: "Party <hello@mail.example.com>",
62
+ subject: "{{ name }}, you're invited",
63
+ html: "<p>RSVP at {{ rsvp_url }}</p>",
64
+ text: "RSVP at {{ rsvp_url }}",
65
+ reply_to: "rsvp+{{ guest_id }}@inbox.example.com",
66
+ headers: {
67
+ "List-Unsubscribe": "<{{ unsubscribe_url }}>",
68
+ "List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
69
+ },
70
+ unique_args: { event_id: "evt_1" },
71
+ reference: "invites-2026-11-28",
72
+ messages: [
73
+ {
74
+ to: "ada@example.com",
75
+ name: "Ada",
76
+ variables: {
77
+ guest_id: "g1",
78
+ rsvp_url: "https://example.com/r/g1",
79
+ unsubscribe_url: "https://example.com/u/g1",
80
+ },
81
+ unique_args: { invite_id: "inv_1" },
82
+ },
83
+ ],
84
+ })
85
+ ```
86
+
87
+ Bulk send takes no `Idempotency-Key`. Set `reference`, and if a request times out, check `emails.listBulk({ reference })` before you retry. Pass `clusterId` as the second argument to send `X-Capsule-Cluster-Id`.
88
+
89
+ ## NestJS
90
+
91
+ The Nest entry is a module and an injectable token, not a mailer. Import `@postshiba/node` without Nest. Import `@postshiba/node/nest` only in Nest apps.
92
+
93
+ ```ts
94
+ import { Inject, Injectable, Module } from "@nestjs/common"
95
+ import { POSTSHIBA, PostShibaModule, sendMail } from "@postshiba/node/nest"
96
+ import type { PostShiba } from "@postshiba/node"
97
+
98
+ @Module({
99
+ imports: [
100
+ PostShibaModule.register({
101
+ apiKey: process.env.POSTSHIBA_API_KEY!,
102
+ teamId: "KjkAJW",
103
+ }),
104
+ ],
105
+ })
106
+ export class AppModule {}
107
+
108
+ @Injectable()
109
+ export class MailService {
110
+ constructor(@Inject(POSTSHIBA) private readonly postshiba: PostShiba) {}
111
+
112
+ sendWelcome() {
113
+ return sendMail(this.postshiba, {
114
+ from: "hello@mail.example.com",
115
+ to: "you@example.com",
116
+ subject: "Welcome",
117
+ text: "hello",
118
+ html: "<p>hello</p>",
119
+ })
120
+ }
121
+ }
122
+ ```
123
+
124
+ `sendMail` maps `to`, `from`, `subject`, `html`, `text`, and `attachments` onto `emails.send`. It does not pass a cluster id. Call `this.postshiba.emails.send(body, { clusterId: "NmQpXr" })` to pin a cluster.
125
+
126
+ ## API
127
+
128
+ Override `baseUrl` when you are not on production.
129
+
130
+ ```ts
131
+ new PostShiba(process.env.POSTSHIBA_API_KEY, {
132
+ teamId: "KjkAJW",
133
+ baseUrl: "https://app.postshiba.com",
134
+ })
135
+ ```
136
+
137
+ ### Users
138
+
139
+ ```ts
140
+ await postshiba.users.me()
141
+ ```
142
+
143
+ ### Emails
144
+
145
+ ```ts
146
+ await postshiba.emails.send(body)
147
+ await postshiba.emails.send(body, { clusterId: "NmQpXr" })
148
+ await postshiba.emails.sendOnCluster("NmQpXr", body, { sandbox: true })
149
+ await postshiba.emails.send({
150
+ to: ["you@example.com"],
151
+ template: { id: "welcome", variables: { name: "Ada" } },
152
+ })
153
+ await postshiba.emails.sendBulk(bulkBody, { clusterId: "NmQpXr" })
154
+ await postshiba.emails.listBulk({ reference: "invites-2026-11-28" })
155
+ await postshiba.emails.getBulk("bLkSnD")
156
+ ```
157
+
158
+ ### Clusters
159
+
160
+ ```ts
161
+ await postshiba.clusters.list()
162
+ await postshiba.clusters.get("NmQpXr")
163
+ await postshiba.clusters.create({ cluster: { name: "edge", size: "small", region: "manual", plan: "nano" } })
164
+ await postshiba.clusters.update("NmQpXr", { cluster: { plan: "small" } })
165
+ await postshiba.clusters.suspend("NmQpXr")
166
+ await postshiba.clusters.resume("NmQpXr")
167
+ await postshiba.clusters.delete("NmQpXr")
168
+ await postshiba.clusters.boost("NmQpXr", { sku: "small_to_large" })
169
+ await postshiba.clusters.extendBoost("NmQpXr", { idempotency_key: "extend-1" })
170
+ await postshiba.clusters.cancelBoost("NmQpXr")
171
+ await postshiba.clusters.reactivate("NmQpXr")
172
+ await postshiba.clusters.setAutoBoost("NmQpXr", { sku: "small_to_medium", monthly_limit: 3 })
173
+ ```
174
+
175
+ ### Network
176
+
177
+ ```ts
178
+ await postshiba.network.list()
179
+ await postshiba.network.create({ ip_address_id: "IpQwEr", cluster_id: "NmQpXr" })
180
+ await postshiba.network.assign({ ip_address_id: "IpQwEr", cluster_id: "NmQpXr" })
181
+ await postshiba.network.unassign({ ip_address_id: "IpQwEr", cluster_id: "NmQpXr" })
182
+ await postshiba.network.switch({ ip_address_id: "IpQwEr", cluster_id: "NmQpXr" })
183
+ await postshiba.network.release({ ip_address_id: "IpQwEr" })
184
+ await postshiba.network.warmup({ ip_address_id: "IpQwEr", warmup_mode: "slow" })
185
+ ```
186
+
187
+ ### IP pools
188
+
189
+ ```ts
190
+ await postshiba.ipPools.list({ classification: "bulk" })
191
+ await postshiba.ipPools.get("PoOlIp")
192
+ await postshiba.ipPools.create({ name: "site_123", classification: "bulk", warmup_overflow: true })
193
+ await postshiba.ipPools.update("PoOlIp", { name: "site_123_bulk", warmup_overflow: false })
194
+ await postshiba.ipPools.delete("PoOlIp")
195
+ await postshiba.ipPools.addIp("PoOlIp", { ip_address_id: "IpQwEr", weight: 100 })
196
+ await postshiba.ipPools.removeIp("PoOlIp", { ip_address_id: "IpQwEr" })
197
+ await postshiba.ipPools.attach("PoOlIp", { cluster_id: "NmQpXr" })
198
+ await postshiba.ipPools.detach("PoOlIp", { cluster_id: "NmQpXr" })
199
+ ```
200
+
201
+ ### Sending domains
202
+
203
+ ```ts
204
+ await postshiba.sendingDomains.list()
205
+ await postshiba.sendingDomains.get("HsVtYk")
206
+ await postshiba.sendingDomains.create({ sending_domain: { name: "mail.example.com", tenant_id: "WbLcFd" } })
207
+ await postshiba.sendingDomains.update("HsVtYk", { sending_domain: { dkim_selector: "s1", dkim_manual: true } })
208
+ await postshiba.sendingDomains.refresh("HsVtYk")
209
+ await postshiba.sendingDomains.verify("HsVtYk")
210
+ await postshiba.sendingDomains.suspend("HsVtYk")
211
+ await postshiba.sendingDomains.resume("HsVtYk")
212
+ await postshiba.sendingDomains.makePrimary("HsVtYk")
213
+ await postshiba.sendingDomains.delete("HsVtYk")
214
+ await postshiba.sendingDomains.flushQueue("HsVtYk")
215
+ await postshiba.sendingDomains.move("HsVtYk", { sending_domain: { tenant_id: "WbLcFd" } })
216
+ const started = await postshiba.sendingDomains.canISendThis("HsVtYk")
217
+ await postshiba.sendingDomains.canISendThisResult("HsVtYk", token)
218
+ ```
219
+
220
+ `canISendThisResult` requires `token`.
221
+
222
+ ### Tenants
223
+
224
+ ```ts
225
+ await postshiba.tenants.list()
226
+ await postshiba.tenants.get("WbLcFd")
227
+ await postshiba.tenants.create({ tenant: { name: "Acme Florist" } })
228
+ await postshiba.tenants.update("WbLcFd", { tenant: { suppress_hard_bounces: false } })
229
+ await postshiba.tenants.suspend("WbLcFd")
230
+ await postshiba.tenants.resume("WbLcFd")
231
+ await postshiba.tenants.delete("WbLcFd")
232
+ ```
233
+
234
+ ### Inboxes
235
+
236
+ ```ts
237
+ await postshiba.inboxes.list()
238
+ await postshiba.inboxes.get("PqRzMn")
239
+ await postshiba.inboxes.create({
240
+ inbox: {
241
+ name: "agent",
242
+ webhook_url: "https://hooks.example.com/mail",
243
+ host: "inbound.example.com",
244
+ forward_to: "you@example.com",
245
+ },
246
+ })
247
+ await postshiba.inboxes.update("PqRzMn", { inbox: { webhook_url: "https://hooks.example.com/mail", webhook_format: "json" } })
248
+ await postshiba.inboxes.verify("PqRzMn")
249
+ await postshiba.inboxes.delete("PqRzMn")
250
+ ```
251
+
252
+ ### Messages
253
+
254
+ ```ts
255
+ await postshiba.messages.list("PqRzMn")
256
+ await postshiba.messages.get("PqRzMn", "GxTyVu")
257
+ await postshiba.messages.downloadAttachment("PqRzMn", "GxTyVu", 1)
258
+ ```
259
+
260
+ ### Outbound messages
261
+
262
+ ```ts
263
+ await postshiba.outboundMessages.list({ q: "ada@example.com", before: "OuTbMs", limit: 50 })
264
+ await postshiba.outboundMessages.get("OuTbMs")
265
+ const eml = await postshiba.outboundMessages.raw("OuTbMs")
266
+ await postshiba.outboundMessages.downloadAttachment("OuTbMs", 1)
267
+ await postshiba.outboundRetention.get()
268
+ await postshiba.outboundRetention.update({ team: { outbound_retention_days: 45 } })
269
+ ```
270
+
271
+ `raw` returns the `message/rfc822` source as a string. `downloadAttachment` returns an `ArrayBuffer`.
272
+
273
+ ### DKIM signing
274
+
275
+ ```ts
276
+ await postshiba.dkimSigning.get()
277
+ await postshiba.dkimSigning.update({ team: { sign_with_primary_domain: false } })
278
+ ```
279
+
280
+ ### Recipients, analytics, and status
281
+
282
+ ```ts
283
+ await postshiba.recipients.get("ada@example.com")
284
+ await postshiba.analytics.get({ since: "2026-09-15T12:00:00Z", until: "2026-09-16T12:00:00Z", dimension: "mx_provider" })
285
+ await postshiba.status.get()
286
+ ```
287
+
288
+ `analytics.get` also takes `minProcessed`, `compare`, `compareSince`, and `compareUntil`, sent as `min_processed`, `compare`, `compare_since`, and `compare_until`. Only the options you set are sent.
289
+
290
+ ### Planned sends
291
+
292
+ ```ts
293
+ await postshiba.plannedSends.list()
294
+ await postshiba.plannedSends.get("PlAnSd")
295
+ await postshiba.plannedSends.create({
296
+ planned_send: { cluster_id: "NmQpXr", volume_per_hour: 500, scheduled_for: "2026-09-21T09:00:00Z", name: "Launch" },
297
+ })
298
+ await postshiba.plannedSends.cancel("PlAnSd")
299
+ ```
300
+
301
+ ### Support tickets
302
+
303
+ ```ts
304
+ await postshiba.supportTickets.list({ all: true })
305
+ await postshiba.supportTickets.get("SuPtKt")
306
+ await postshiba.supportTickets.create({
307
+ support_ticket: { subject: "Forwarded mail bounces with SPF fail", category: "receiving", body: "..." },
308
+ })
309
+ await postshiba.supportTickets.reply("SuPtKt", { support_ticket_message: { body: "It still bounces." } })
310
+ ```
311
+
312
+ ### Events
313
+
314
+ ```ts
315
+ await postshiba.events.listTeam()
316
+ await postshiba.events.list("NmQpXr")
317
+ await postshiba.events.get("JkLmNp")
318
+ ```
319
+
320
+ ### SMTP credentials
321
+
322
+ ```ts
323
+ await postshiba.smtpCredentials.create("NmQpXr", { smtp_credential: { tenant_id: "WbLcFd" } })
324
+ await postshiba.smtpCredentials.delete("NmQpXr", "RvWsXq")
325
+ await postshiba.smtpCredentials.enable("NmQpXr", "RvWsXq")
326
+ ```
327
+
328
+ Create returns `password`. Delete does not.
329
+
330
+ ### Webhooks
331
+
332
+ ```ts
333
+ await postshiba.webhooks.list()
334
+ await postshiba.webhooks.get("CdFgHj")
335
+ await postshiba.webhooks.create({
336
+ webhook_endpoint: {
337
+ url: "https://hooks.example.com/capsule",
338
+ event_types: ["delivered", "bounce"],
339
+ cluster_id: "NmQpXr",
340
+ },
341
+ })
342
+ await postshiba.webhooks.update("CdFgHj", {
343
+ webhook_endpoint: { enabled: false, event_types: ["delivered", "bounce"] },
344
+ })
345
+ await postshiba.webhooks.delete("CdFgHj")
346
+ await postshiba.webhooks.sendTest("CdFgHj")
347
+ ```
348
+
349
+ List and update omit `secret`. Get and create return it.
350
+
351
+ ### Templates
352
+
353
+ ```ts
354
+ await postshiba.templates.list()
355
+ await postshiba.templates.get("welcome")
356
+ await postshiba.templates.create({
357
+ email_template: {
358
+ name: "Welcome",
359
+ alias: "welcome",
360
+ subject: "Hi {{ name }}",
361
+ html: "<p>Hi {{ name }}</p>",
362
+ },
363
+ })
364
+ await postshiba.templates.update("TpLmQr", { email_template: { subject: "Welcome, {{ name }}" } })
365
+ await postshiba.templates.publish("TpLmQr")
366
+ await postshiba.templates.duplicate("TpLmQr")
367
+ await postshiba.templates.delete("TpLmQr")
368
+ ```
369
+
370
+ Send uses the published snapshot. `get` and member routes accept the public id or the alias.
371
+
372
+ ### Suppressions
373
+
374
+ ```ts
375
+ await postshiba.suppressions.list()
376
+ await postshiba.suppressions.create({ suppression: { email: "blocked@example.com", tenant_id: "WbLcFd" } })
377
+ await postshiba.suppressions.import({ emails: ["blocked@example.com", "old@example.com"], tenant_id: "WbLcFd" })
378
+ await postshiba.suppressions.delete("YtReWq")
379
+ await postshiba.suppressions.bulkDelete({
380
+ emails: ["blocked@example.com", "old@example.com"],
381
+ reason: "bounce",
382
+ tenant_id: "WbLcFd",
383
+ before: "2026-02-01T00:00:00Z",
384
+ })
385
+ ```
386
+
387
+ ### Firewall
388
+
389
+ ```ts
390
+ await postshiba.firewall.get()
391
+ await postshiba.firewall.update({ firewall: { enabled_checks: ["temp_providers", "plus_addressing"] } })
392
+ await postshiba.firewall.addEntry({ firewall_entry: { list: "deny", value: "mailinator.com" } })
393
+ await postshiba.firewall.deleteEntry("BnMkLo")
394
+ ```
395
+
396
+ ### ShieldShiba sites
397
+
398
+ ```ts
399
+ await postshiba.shieldSites.list()
400
+ await postshiba.shieldSites.get("ShLdSt")
401
+ await postshiba.shieldSites.create({
402
+ shield_site: { name: "Signup", allowed_hostnames: "acme.com, app.acme.com", block_hosting: true, block_free_email: false },
403
+ })
404
+ await postshiba.shieldSites.update("ShLdSt", { shield_site: { block_free_email: true } })
405
+ await postshiba.shieldSites.rotateSecret("ShLdSt")
406
+ await postshiba.shieldSites.delete("ShLdSt")
407
+ ```
408
+
409
+ ## Verify webhooks
410
+
411
+ HMAC-SHA256 of `{timestamp}.{rawBody}` against `X-Capsule-Signature`. A `sha256=` prefix is stripped.
412
+
413
+ ```ts
414
+ const ok = postshiba.webhooks.verify(rawBody, timestamp, signature, secret)
415
+ ```
416
+
417
+ ## Errors and throttling
418
+
419
+ Non-2xx responses throw `PostShibaError` with `error`, `field`, and `message` from the JSON body.
420
+
421
+ ```ts
422
+ import { PostShibaError } from "@postshiba/node"
423
+
424
+ try {
425
+ await postshiba.emails.send(body)
426
+ } catch (err) {
427
+ if (err instanceof PostShibaError) {
428
+ console.error(err.error, err.field, err.message)
429
+ }
430
+ }
431
+ ```
432
+
433
+ A `429` response with `error` `throttled` means the cluster hit its hourly send limit. Do not retry that send immediately. Immediate retries hit the same cap. Wait until the next hour. The client does not delay for you. In a queued job, catch `PostShibaError` and check `err.error === "throttled"` before sending again.
434
+
435
+ Missing `teamId` on a team-scoped call throws before any request.
436
+
437
+ ## Contributing
438
+
439
+ ```sh
440
+ npm install
441
+ npm test
442
+ ```
443
+
444
+ Tests mock HTTP and load fixtures from `../../fixtures/catalog`. They do not call production.
@@ -0,0 +1,221 @@
1
+ export type Id = string;
2
+ export type Json = Record<string, unknown>;
3
+ export type PostShibaOptions = {
4
+ baseUrl?: string;
5
+ teamId?: Id;
6
+ };
7
+ export type SendOptions = {
8
+ clusterId?: Id;
9
+ };
10
+ export type ClusterSendOptions = {
11
+ idempotencyKey?: string;
12
+ sandbox?: boolean;
13
+ };
14
+ export type QueryValue = string | number | boolean | null | undefined;
15
+ export type Query = Record<string, QueryValue>;
16
+ export type BulkListOptions = {
17
+ reference?: string;
18
+ };
19
+ export type IpPoolListOptions = {
20
+ classification?: string;
21
+ };
22
+ export type OutboundMessageListOptions = {
23
+ q?: string;
24
+ before?: string;
25
+ limit?: number;
26
+ };
27
+ export type AnalyticsOptions = {
28
+ since?: string;
29
+ until?: string;
30
+ dimension?: string;
31
+ minProcessed?: number;
32
+ compare?: boolean;
33
+ compareSince?: string;
34
+ compareUntil?: string;
35
+ };
36
+ export type SupportTicketListOptions = {
37
+ all?: boolean;
38
+ };
39
+ export declare class PostShibaError extends Error {
40
+ readonly error: string;
41
+ readonly field: string | null;
42
+ constructor(attrs: {
43
+ error?: string;
44
+ field?: string | null;
45
+ message?: string;
46
+ });
47
+ }
48
+ export declare class PostShiba {
49
+ readonly apiKey: string;
50
+ readonly baseUrl: string;
51
+ readonly teamId?: Id;
52
+ constructor(apiKey: string, options?: PostShibaOptions);
53
+ private requireTeamId;
54
+ private request;
55
+ readonly users: {
56
+ me: () => Promise<unknown>;
57
+ };
58
+ readonly emails: {
59
+ send: (body: Json, options?: SendOptions) => Promise<unknown>;
60
+ sendBulk: (body: Json, options?: SendOptions) => Promise<unknown>;
61
+ listBulk: (options?: BulkListOptions) => Promise<unknown>;
62
+ getBulk: (id: Id) => Promise<unknown>;
63
+ sendOnCluster: (clusterId: Id, body: Json, options?: ClusterSendOptions) => Promise<unknown>;
64
+ };
65
+ readonly clusters: {
66
+ list: () => Promise<unknown>;
67
+ get: (id: Id) => Promise<unknown>;
68
+ create: (body: Json) => Promise<unknown>;
69
+ update: (id: Id, body: Json) => Promise<unknown>;
70
+ suspend: (id: Id) => Promise<unknown>;
71
+ resume: (id: Id) => Promise<unknown>;
72
+ delete: (id: Id) => Promise<unknown>;
73
+ boost: (id: Id, body: Json) => Promise<unknown>;
74
+ extendBoost: (id: Id, body: Json) => Promise<unknown>;
75
+ cancelBoost: (id: Id) => Promise<unknown>;
76
+ reactivate: (id: Id) => Promise<unknown>;
77
+ setAutoBoost: (id: Id, body: Json) => Promise<unknown>;
78
+ };
79
+ readonly network: {
80
+ list: () => Promise<unknown>;
81
+ create: (body: Json) => Promise<unknown>;
82
+ assign: (body: Json) => Promise<unknown>;
83
+ unassign: (body: Json) => Promise<unknown>;
84
+ switch: (body: Json) => Promise<unknown>;
85
+ release: (body: Json) => Promise<unknown>;
86
+ warmup: (body: Json) => Promise<unknown>;
87
+ };
88
+ readonly ipPools: {
89
+ list: (options?: IpPoolListOptions) => Promise<unknown>;
90
+ get: (id: Id) => Promise<unknown>;
91
+ create: (body: Json) => Promise<unknown>;
92
+ update: (id: Id, body: Json) => Promise<unknown>;
93
+ delete: (id: Id) => Promise<unknown>;
94
+ addIp: (id: Id, body: Json) => Promise<unknown>;
95
+ removeIp: (id: Id, body: Json) => Promise<unknown>;
96
+ attach: (id: Id, body: Json) => Promise<unknown>;
97
+ detach: (id: Id, body: Json) => Promise<unknown>;
98
+ };
99
+ readonly sendingDomains: {
100
+ list: () => Promise<unknown>;
101
+ get: (id: Id) => Promise<unknown>;
102
+ create: (body: Json) => Promise<unknown>;
103
+ update: (id: Id, body: Json) => Promise<unknown>;
104
+ refresh: (id: Id) => Promise<unknown>;
105
+ verify: (id: Id) => Promise<unknown>;
106
+ suspend: (id: Id) => Promise<unknown>;
107
+ resume: (id: Id) => Promise<unknown>;
108
+ makePrimary: (id: Id) => Promise<unknown>;
109
+ delete: (id: Id) => Promise<unknown>;
110
+ flushQueue: (id: Id) => Promise<unknown>;
111
+ move: (id: Id, body: Json) => Promise<unknown>;
112
+ canISendThis: (id: Id) => Promise<unknown>;
113
+ canISendThisResult: (id: Id, token: string) => Promise<unknown>;
114
+ };
115
+ readonly tenants: {
116
+ list: () => Promise<unknown>;
117
+ get: (id: Id) => Promise<unknown>;
118
+ create: (body: Json) => Promise<unknown>;
119
+ update: (id: Id, body: Json) => Promise<unknown>;
120
+ suspend: (id: Id) => Promise<unknown>;
121
+ resume: (id: Id) => Promise<unknown>;
122
+ delete: (id: Id) => Promise<unknown>;
123
+ };
124
+ readonly inboxes: {
125
+ list: () => Promise<unknown>;
126
+ get: (id: Id) => Promise<unknown>;
127
+ create: (body: Json) => Promise<unknown>;
128
+ update: (id: Id, body: Json) => Promise<unknown>;
129
+ verify: (id: Id) => Promise<unknown>;
130
+ delete: (id: Id) => Promise<unknown>;
131
+ };
132
+ readonly messages: {
133
+ list: (inboxId: Id) => Promise<unknown>;
134
+ get: (inboxId: Id, id: Id) => Promise<unknown>;
135
+ downloadAttachment: (inboxId: Id, id: Id, index: number) => Promise<unknown>;
136
+ };
137
+ readonly outboundMessages: {
138
+ list: (options?: OutboundMessageListOptions) => Promise<unknown>;
139
+ get: (id: Id) => Promise<unknown>;
140
+ raw: (id: Id) => Promise<string>;
141
+ downloadAttachment: (id: Id, index: number) => Promise<unknown>;
142
+ };
143
+ readonly outboundRetention: {
144
+ get: () => Promise<unknown>;
145
+ update: (body: Json) => Promise<unknown>;
146
+ };
147
+ readonly dkimSigning: {
148
+ get: () => Promise<unknown>;
149
+ update: (body: Json) => Promise<unknown>;
150
+ };
151
+ readonly recipients: {
152
+ get: (email: string) => Promise<unknown>;
153
+ };
154
+ readonly analytics: {
155
+ get: (options?: AnalyticsOptions) => Promise<unknown>;
156
+ };
157
+ readonly status: {
158
+ get: () => Promise<unknown>;
159
+ };
160
+ readonly plannedSends: {
161
+ list: () => Promise<unknown>;
162
+ get: (id: Id) => Promise<unknown>;
163
+ create: (body: Json) => Promise<unknown>;
164
+ cancel: (id: Id) => Promise<unknown>;
165
+ };
166
+ readonly supportTickets: {
167
+ list: (options?: SupportTicketListOptions) => Promise<unknown>;
168
+ get: (id: Id) => Promise<unknown>;
169
+ create: (body: Json) => Promise<unknown>;
170
+ reply: (id: Id, body: Json) => Promise<unknown>;
171
+ };
172
+ readonly shieldSites: {
173
+ list: () => Promise<unknown>;
174
+ get: (id: Id) => Promise<unknown>;
175
+ create: (body: Json) => Promise<unknown>;
176
+ update: (id: Id, body: Json) => Promise<unknown>;
177
+ rotateSecret: (id: Id) => Promise<unknown>;
178
+ delete: (id: Id) => Promise<unknown>;
179
+ };
180
+ readonly events: {
181
+ listTeam: () => Promise<unknown>;
182
+ list: (clusterId: Id) => Promise<unknown>;
183
+ get: (id: Id) => Promise<unknown>;
184
+ };
185
+ readonly smtpCredentials: {
186
+ create: (clusterId: Id, body: Json) => Promise<unknown>;
187
+ delete: (clusterId: Id, id: Id) => Promise<unknown>;
188
+ enable: (clusterId: Id, id: Id) => Promise<unknown>;
189
+ };
190
+ readonly webhooks: {
191
+ list: () => Promise<unknown>;
192
+ get: (id: Id) => Promise<unknown>;
193
+ create: (body: Json) => Promise<unknown>;
194
+ update: (id: Id, body: Json) => Promise<unknown>;
195
+ delete: (id: Id) => Promise<unknown>;
196
+ sendTest: (id: Id) => Promise<unknown>;
197
+ verify: (rawBody: string, timestamp: string, signature: string, secret: string) => boolean;
198
+ };
199
+ readonly templates: {
200
+ list: () => Promise<unknown>;
201
+ get: (id: Id) => Promise<unknown>;
202
+ create: (body: Json) => Promise<unknown>;
203
+ update: (id: Id, body: Json) => Promise<unknown>;
204
+ publish: (id: Id) => Promise<unknown>;
205
+ duplicate: (id: Id) => Promise<unknown>;
206
+ delete: (id: Id) => Promise<unknown>;
207
+ };
208
+ readonly suppressions: {
209
+ list: () => Promise<unknown>;
210
+ create: (body: Json) => Promise<unknown>;
211
+ import: (body: Json) => Promise<unknown>;
212
+ bulkDelete: (body: Json) => Promise<unknown>;
213
+ delete: (id: Id) => Promise<unknown>;
214
+ };
215
+ readonly firewall: {
216
+ get: () => Promise<unknown>;
217
+ update: (body: Json) => Promise<unknown>;
218
+ addEntry: (body: Json) => Promise<unknown>;
219
+ deleteEntry: (id: Id) => Promise<unknown>;
220
+ };
221
+ }
package/dist/index.js ADDED
@@ -0,0 +1,290 @@
1
+ import { createHmac, timingSafeEqual } from "node:crypto";
2
+ export class PostShibaError extends Error {
3
+ error;
4
+ field;
5
+ constructor(attrs) {
6
+ super(attrs.message ?? attrs.error ?? "Request failed");
7
+ this.name = "PostShibaError";
8
+ this.error = attrs.error ?? "error";
9
+ this.field = attrs.field ?? null;
10
+ }
11
+ }
12
+ function parseJson(text) {
13
+ if (!text)
14
+ return {};
15
+ try {
16
+ return JSON.parse(text);
17
+ }
18
+ catch {
19
+ return text;
20
+ }
21
+ }
22
+ function queryString(query) {
23
+ if (!query)
24
+ return "";
25
+ const params = new URLSearchParams();
26
+ for (const [key, value] of Object.entries(query)) {
27
+ if (value === undefined || value === null)
28
+ continue;
29
+ params.append(key, String(value));
30
+ }
31
+ const encoded = params.toString();
32
+ return encoded ? `?${encoded}` : "";
33
+ }
34
+ function clusterHeaders(options) {
35
+ const headers = {};
36
+ if (options.clusterId !== undefined && options.clusterId !== null && options.clusterId !== "") {
37
+ headers["X-Capsule-Cluster-Id"] = String(options.clusterId);
38
+ }
39
+ return headers;
40
+ }
41
+ function asErrorPayload(value) {
42
+ if (value && typeof value === "object")
43
+ return value;
44
+ return {};
45
+ }
46
+ export class PostShiba {
47
+ apiKey;
48
+ baseUrl;
49
+ teamId;
50
+ constructor(apiKey, options = {}) {
51
+ this.apiKey = apiKey;
52
+ this.baseUrl = (options.baseUrl ?? "https://app.postshiba.com").replace(/\/$/, "");
53
+ this.teamId = options.teamId;
54
+ }
55
+ requireTeamId() {
56
+ if (this.teamId === undefined || this.teamId === null || this.teamId === "") {
57
+ throw new Error("teamId is required");
58
+ }
59
+ return this.teamId;
60
+ }
61
+ async request(method, path, opts = {}) {
62
+ const base = opts.team ? `/api/v1/teams/${this.requireTeamId()}${path}` : path;
63
+ const resolved = `${base}${queryString(opts.query)}`;
64
+ const headers = {
65
+ Authorization: `Bearer ${this.apiKey}`,
66
+ Accept: "application/json",
67
+ ...opts.headers,
68
+ };
69
+ if (opts.body !== undefined)
70
+ headers["Content-Type"] = "application/json";
71
+ const res = await fetch(`${this.baseUrl}${resolved}`, {
72
+ method,
73
+ headers,
74
+ body: opts.body === undefined ? undefined : JSON.stringify(opts.body),
75
+ });
76
+ if (!res.ok) {
77
+ const payload = asErrorPayload(parseJson(await res.text()));
78
+ throw new PostShibaError({
79
+ error: payload.error,
80
+ field: payload.field ?? null,
81
+ message: payload.message,
82
+ });
83
+ }
84
+ if (opts.binary)
85
+ return res.arrayBuffer();
86
+ if (opts.text)
87
+ return res.text();
88
+ return parseJson(await res.text());
89
+ }
90
+ users = {
91
+ me: () => this.request("GET", "/api/v1/users/me"),
92
+ };
93
+ emails = {
94
+ send: (body, options = {}) => this.request("POST", "/api/v1/emails", { body, headers: clusterHeaders(options) }),
95
+ sendBulk: (body, options = {}) => this.request("POST", "/api/v1/emails/bulk", { body, headers: clusterHeaders(options) }),
96
+ listBulk: (options = {}) => this.request("GET", "/api/v1/emails/bulk", { query: options }),
97
+ getBulk: (id) => this.request("GET", `/api/v1/emails/bulk/${id}`),
98
+ sendOnCluster: (clusterId, body, options = {}) => {
99
+ const payload = options.sandbox ? { ...body, sandbox: true } : body;
100
+ const headers = {};
101
+ if (options.idempotencyKey)
102
+ headers["Idempotency-Key"] = options.idempotencyKey;
103
+ return this.request("POST", `/clusters/${clusterId}/sends`, { body: payload, headers, team: true });
104
+ },
105
+ };
106
+ clusters = {
107
+ list: () => this.request("GET", "/clusters", { team: true }),
108
+ get: (id) => this.request("GET", `/api/v1/clusters/${id}`),
109
+ create: (body) => this.request("POST", "/clusters", { body, team: true }),
110
+ update: (id, body) => this.request("PATCH", `/api/v1/clusters/${id}`, { body }),
111
+ suspend: (id) => this.request("POST", `/api/v1/clusters/${id}/suspend`),
112
+ resume: (id) => this.request("POST", `/api/v1/clusters/${id}/resume`),
113
+ delete: (id) => this.request("DELETE", `/api/v1/clusters/${id}`),
114
+ boost: (id, body) => this.request("POST", `/api/v1/clusters/${id}/boost`, { body }),
115
+ extendBoost: (id, body) => this.request("POST", `/api/v1/clusters/${id}/extend_boost`, { body }),
116
+ cancelBoost: (id) => this.request("POST", `/api/v1/clusters/${id}/cancel_boost`),
117
+ reactivate: (id) => this.request("POST", `/api/v1/clusters/${id}/reactivate`),
118
+ setAutoBoost: (id, body) => this.request("PATCH", `/api/v1/clusters/${id}/auto_boost`, { body }),
119
+ };
120
+ network = {
121
+ list: () => this.request("GET", "/network", { team: true }),
122
+ create: (body) => this.request("POST", "/network", { body, team: true }),
123
+ assign: (body) => this.request("POST", "/network/assign", { body, team: true }),
124
+ unassign: (body) => this.request("POST", "/network/unassign", { body, team: true }),
125
+ switch: (body) => this.request("POST", "/network/switch", { body, team: true }),
126
+ release: (body) => this.request("POST", "/network/release", { body, team: true }),
127
+ warmup: (body) => this.request("POST", "/network/warmup", { body, team: true }),
128
+ };
129
+ ipPools = {
130
+ list: (options = {}) => this.request("GET", "/ip_pools", { team: true, query: options }),
131
+ get: (id) => this.request("GET", `/api/v1/ip_pools/${id}`),
132
+ create: (body) => this.request("POST", "/ip_pools", { body, team: true }),
133
+ update: (id, body) => this.request("PATCH", `/api/v1/ip_pools/${id}`, { body }),
134
+ delete: (id) => this.request("DELETE", `/api/v1/ip_pools/${id}`),
135
+ addIp: (id, body) => this.request("POST", `/api/v1/ip_pools/${id}/add_ip`, { body }),
136
+ removeIp: (id, body) => this.request("POST", `/api/v1/ip_pools/${id}/remove_ip`, { body }),
137
+ attach: (id, body) => this.request("POST", `/api/v1/ip_pools/${id}/attach`, { body }),
138
+ detach: (id, body) => this.request("POST", `/api/v1/ip_pools/${id}/detach`, { body }),
139
+ };
140
+ sendingDomains = {
141
+ list: () => this.request("GET", "/sending_domains", { team: true }),
142
+ get: (id) => this.request("GET", `/api/v1/sending_domains/${id}`),
143
+ create: (body) => this.request("POST", "/sending_domains", { body, team: true }),
144
+ update: (id, body) => this.request("PATCH", `/api/v1/sending_domains/${id}`, { body }),
145
+ refresh: (id) => this.request("POST", `/api/v1/sending_domains/${id}/refresh`),
146
+ verify: (id) => this.request("POST", `/api/v1/sending_domains/${id}/verify`),
147
+ suspend: (id) => this.request("POST", `/api/v1/sending_domains/${id}/suspend`),
148
+ resume: (id) => this.request("POST", `/api/v1/sending_domains/${id}/resume`),
149
+ makePrimary: (id) => this.request("POST", `/api/v1/sending_domains/${id}/make_primary`),
150
+ delete: (id) => this.request("DELETE", `/api/v1/sending_domains/${id}`),
151
+ flushQueue: (id) => this.request("POST", `/api/v1/sending_domains/${id}/flush_queue`),
152
+ move: (id, body) => this.request("POST", `/api/v1/sending_domains/${id}/move`, { body }),
153
+ canISendThis: (id) => this.request("POST", `/api/v1/sending_domains/${id}/can_i_send_this`),
154
+ canISendThisResult: (id, token) => {
155
+ if (!token)
156
+ return Promise.reject(new Error("token is required"));
157
+ return this.request("GET", `/api/v1/sending_domains/${id}/can_i_send_this`, { query: { token } });
158
+ },
159
+ };
160
+ tenants = {
161
+ list: () => this.request("GET", "/tenants", { team: true }),
162
+ get: (id) => this.request("GET", `/api/v1/tenants/${id}`),
163
+ create: (body) => this.request("POST", "/tenants", { body, team: true }),
164
+ update: (id, body) => this.request("PATCH", `/api/v1/tenants/${id}`, { body }),
165
+ suspend: (id) => this.request("POST", `/api/v1/tenants/${id}/suspend`),
166
+ resume: (id) => this.request("POST", `/api/v1/tenants/${id}/resume`),
167
+ delete: (id) => this.request("DELETE", `/api/v1/tenants/${id}`),
168
+ };
169
+ inboxes = {
170
+ list: () => this.request("GET", "/inboxes", { team: true }),
171
+ get: (id) => this.request("GET", `/api/v1/inboxes/${id}`),
172
+ create: (body) => this.request("POST", "/inboxes", { body, team: true }),
173
+ update: (id, body) => this.request("PATCH", `/api/v1/inboxes/${id}`, { body }),
174
+ verify: (id) => this.request("POST", `/api/v1/inboxes/${id}/verify`),
175
+ delete: (id) => this.request("DELETE", `/api/v1/inboxes/${id}`),
176
+ };
177
+ messages = {
178
+ list: (inboxId) => this.request("GET", `/api/v1/inboxes/${inboxId}/inbound_messages`),
179
+ get: (inboxId, id) => this.request("GET", `/api/v1/inboxes/${inboxId}/inbound_messages/${id}`),
180
+ downloadAttachment: (inboxId, id, index) => this.request("GET", `/api/v1/inboxes/${inboxId}/inbound_messages/${id}/attachments/${index}`, { binary: true }),
181
+ };
182
+ outboundMessages = {
183
+ list: (options = {}) => this.request("GET", "/outbound_messages", { team: true, query: options }),
184
+ get: (id) => this.request("GET", `/api/v1/outbound_messages/${id}`),
185
+ raw: (id) => this.request("GET", `/api/v1/outbound_messages/${id}/raw`, { text: true }),
186
+ downloadAttachment: (id, index) => this.request("GET", `/api/v1/outbound_messages/${id}/attachments/${index}`, { binary: true }),
187
+ };
188
+ outboundRetention = {
189
+ get: () => this.request("GET", "/outbound_retention", { team: true }),
190
+ update: (body) => this.request("PATCH", "/outbound_retention", { body, team: true }),
191
+ };
192
+ dkimSigning = {
193
+ get: () => this.request("GET", "/dkim_signing", { team: true }),
194
+ update: (body) => this.request("PATCH", "/dkim_signing", { body, team: true }),
195
+ };
196
+ recipients = {
197
+ get: (email) => {
198
+ if (!email)
199
+ return Promise.reject(new Error("email is required"));
200
+ return this.request("GET", "/recipients", { team: true, query: { email } });
201
+ },
202
+ };
203
+ analytics = {
204
+ get: (options = {}) => this.request("GET", "/analytics", {
205
+ team: true,
206
+ query: {
207
+ since: options.since,
208
+ until: options.until,
209
+ dimension: options.dimension,
210
+ min_processed: options.minProcessed,
211
+ compare: options.compare,
212
+ compare_since: options.compareSince,
213
+ compare_until: options.compareUntil,
214
+ },
215
+ }),
216
+ };
217
+ status = {
218
+ get: () => this.request("GET", "/status", { team: true }),
219
+ };
220
+ plannedSends = {
221
+ list: () => this.request("GET", "/planned_sends", { team: true }),
222
+ get: (id) => this.request("GET", `/api/v1/planned_sends/${id}`),
223
+ create: (body) => this.request("POST", "/planned_sends", { body, team: true }),
224
+ cancel: (id) => this.request("DELETE", `/api/v1/planned_sends/${id}`),
225
+ };
226
+ supportTickets = {
227
+ list: (options = {}) => this.request("GET", "/support_tickets", { team: true, query: options }),
228
+ get: (id) => this.request("GET", `/api/v1/support_tickets/${id}`),
229
+ create: (body) => this.request("POST", "/support_tickets", { body, team: true }),
230
+ reply: (id, body) => this.request("POST", `/api/v1/support_tickets/${id}/reply`, { body }),
231
+ };
232
+ shieldSites = {
233
+ list: () => this.request("GET", "/shield_sites", { team: true }),
234
+ get: (id) => this.request("GET", `/api/v1/shield_sites/${id}`),
235
+ create: (body) => this.request("POST", "/shield_sites", { body, team: true }),
236
+ update: (id, body) => this.request("PATCH", `/api/v1/shield_sites/${id}`, { body }),
237
+ rotateSecret: (id) => this.request("POST", `/api/v1/shield_sites/${id}/rotate_secret`),
238
+ delete: (id) => this.request("DELETE", `/api/v1/shield_sites/${id}`),
239
+ };
240
+ events = {
241
+ listTeam: () => this.request("GET", "/message_events", { team: true }),
242
+ list: (clusterId) => this.request("GET", `/clusters/${clusterId}/message_events`, { team: true }),
243
+ get: (id) => this.request("GET", `/api/v1/message_events/${id}`),
244
+ };
245
+ smtpCredentials = {
246
+ create: (clusterId, body) => this.request("POST", `/clusters/${clusterId}/smtp_credentials`, { body, team: true }),
247
+ delete: (clusterId, id) => this.request("DELETE", `/clusters/${clusterId}/smtp_credentials/${id}`, { team: true }),
248
+ enable: (clusterId, id) => this.request("POST", `/clusters/${clusterId}/smtp_credentials/${id}/enable`, { team: true }),
249
+ };
250
+ webhooks = {
251
+ list: () => this.request("GET", "/webhook_endpoints", { team: true }),
252
+ get: (id) => this.request("GET", `/api/v1/webhook_endpoints/${id}`),
253
+ create: (body) => this.request("POST", "/webhook_endpoints", { body, team: true }),
254
+ update: (id, body) => this.request("PATCH", `/api/v1/webhook_endpoints/${id}`, { body }),
255
+ delete: (id) => this.request("DELETE", `/api/v1/webhook_endpoints/${id}`),
256
+ sendTest: (id) => this.request("POST", `/api/v1/webhook_endpoints/${id}/send_test`),
257
+ verify: (rawBody, timestamp, signature, secret) => verifySignature(rawBody, timestamp, signature, secret),
258
+ };
259
+ templates = {
260
+ list: () => this.request("GET", "/templates", { team: true }),
261
+ get: (id) => this.request("GET", `/api/v1/templates/${id}`),
262
+ create: (body) => this.request("POST", "/templates", { body, team: true }),
263
+ update: (id, body) => this.request("PATCH", `/api/v1/templates/${id}`, { body }),
264
+ publish: (id) => this.request("POST", `/api/v1/templates/${id}/publish`),
265
+ duplicate: (id) => this.request("POST", `/api/v1/templates/${id}/duplicate`),
266
+ delete: (id) => this.request("DELETE", `/api/v1/templates/${id}`),
267
+ };
268
+ suppressions = {
269
+ list: () => this.request("GET", "/suppressions", { team: true }),
270
+ create: (body) => this.request("POST", "/suppressions", { body, team: true }),
271
+ import: (body) => this.request("POST", "/suppressions/import", { body, team: true }),
272
+ bulkDelete: (body) => this.request("POST", "/suppressions/bulk_delete", { body, team: true }),
273
+ delete: (id) => this.request("DELETE", `/api/v1/suppressions/${id}`),
274
+ };
275
+ firewall = {
276
+ get: () => this.request("GET", "/firewall", { team: true }),
277
+ update: (body) => this.request("PATCH", "/firewall", { body, team: true }),
278
+ addEntry: (body) => this.request("POST", "/firewall_entries", { body, team: true }),
279
+ deleteEntry: (id) => this.request("DELETE", `/api/v1/firewall_entries/${id}`),
280
+ };
281
+ }
282
+ function verifySignature(rawBody, timestamp, signature, secret) {
283
+ const given = signature.replace(/^sha256=/, "");
284
+ const expected = createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
285
+ const a = Buffer.from(expected);
286
+ const b = Buffer.from(given);
287
+ if (a.length !== b.length)
288
+ return false;
289
+ return timingSafeEqual(a, b);
290
+ }
package/dist/nest.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { DynamicModule } from "@nestjs/common";
2
+ import { PostShiba } from "./index.js";
3
+ import type { PostShibaOptions } from "./index.js";
4
+ export { PostShiba, PostShibaError } from "./index.js";
5
+ export type { Id, Json, PostShibaOptions } from "./index.js";
6
+ export declare const POSTSHIBA = "POSTSHIBA";
7
+ export type MailFields = {
8
+ to: string | string[];
9
+ from: string;
10
+ subject: string;
11
+ html?: string;
12
+ text?: string;
13
+ attachments?: unknown[];
14
+ cc?: string | string[];
15
+ bcc?: string | string[];
16
+ replyTo?: string;
17
+ headers?: Record<string, string>;
18
+ uniqueArgs?: Record<string, unknown>;
19
+ };
20
+ export declare function sendMail(client: PostShiba, mail: MailFields): Promise<unknown>;
21
+ export declare class PostShibaModule {
22
+ static register(options: {
23
+ apiKey: string;
24
+ } & PostShibaOptions): DynamicModule;
25
+ }
package/dist/nest.js ADDED
@@ -0,0 +1,118 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ import { Module } from "@nestjs/common";
36
+ import { PostShiba } from "./index.js";
37
+ export { PostShiba, PostShibaError } from "./index.js";
38
+ export const POSTSHIBA = "POSTSHIBA";
39
+ function asList(value) {
40
+ return Array.isArray(value) ? value : [value];
41
+ }
42
+ function uniqueArgsFromHeaders(headers) {
43
+ const key = Object.keys(headers).find((name) => name.toLowerCase() === "x-capsule-unique-args");
44
+ if (!key) {
45
+ return undefined;
46
+ }
47
+ const raw = headers[key];
48
+ delete headers[key];
49
+ try {
50
+ const parsed = JSON.parse(raw);
51
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
52
+ return parsed;
53
+ }
54
+ }
55
+ catch {
56
+ return undefined;
57
+ }
58
+ return undefined;
59
+ }
60
+ export function sendMail(client, mail) {
61
+ const body = {
62
+ from: mail.from,
63
+ to: asList(mail.to),
64
+ subject: mail.subject,
65
+ };
66
+ if (mail.html !== undefined)
67
+ body.html = mail.html;
68
+ if (mail.text !== undefined)
69
+ body.text = mail.text;
70
+ if (mail.attachments !== undefined)
71
+ body.attachments = mail.attachments;
72
+ if (mail.cc !== undefined)
73
+ body.cc = asList(mail.cc);
74
+ if (mail.bcc !== undefined)
75
+ body.bcc = asList(mail.bcc);
76
+ if (mail.replyTo)
77
+ body.reply_to = mail.replyTo;
78
+ const headers = mail.headers ? { ...mail.headers } : {};
79
+ const fromHeader = uniqueArgsFromHeaders(headers);
80
+ if (Object.keys(headers).length > 0)
81
+ body.headers = headers;
82
+ if (fromHeader)
83
+ body.unique_args = fromHeader;
84
+ if (mail.uniqueArgs && Object.keys(mail.uniqueArgs).length > 0) {
85
+ body.unique_args = mail.uniqueArgs;
86
+ }
87
+ return client.emails.send(body);
88
+ }
89
+ let PostShibaModule = (() => {
90
+ let _classDecorators = [Module({})];
91
+ let _classDescriptor;
92
+ let _classExtraInitializers = [];
93
+ let _classThis;
94
+ var PostShibaModule = class {
95
+ static { _classThis = this; }
96
+ static {
97
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
98
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
99
+ PostShibaModule = _classThis = _classDescriptor.value;
100
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
101
+ __runInitializers(_classThis, _classExtraInitializers);
102
+ }
103
+ static register(options) {
104
+ return {
105
+ module: PostShibaModule,
106
+ providers: [
107
+ {
108
+ provide: POSTSHIBA,
109
+ useValue: new PostShiba(options.apiKey, options),
110
+ },
111
+ ],
112
+ exports: [POSTSHIBA],
113
+ };
114
+ }
115
+ };
116
+ return PostShibaModule = _classThis;
117
+ })();
118
+ export { PostShibaModule };
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@postshiba/node",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "PostShiba API client",
5
+ "license": "MIT",
6
+ "author": "PostShiba",
7
+ "homepage": "https://github.com/postshiba/postshiba-node",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/postshiba/postshiba-node.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/postshiba/postshiba-node/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "./nest": {
25
+ "types": "./dist/nest.d.ts",
26
+ "import": "./dist/nest.js",
27
+ "default": "./dist/nest.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "LICENSE",
33
+ "README.md",
34
+ "CHANGELOG.md"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
42
+ "scripts": {
43
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
44
+ "prepublishOnly": "npm run build && npm test",
45
+ "test": "vitest run"
46
+ },
47
+ "peerDependencies": {
48
+ "@nestjs/common": "^10.0.0 || ^11.0.0"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "@nestjs/common": {
52
+ "optional": true
53
+ }
54
+ },
55
+ "devDependencies": {
56
+ "@nestjs/common": "^11.1.6",
57
+ "@types/node": "^24.5.2",
58
+ "typescript": "^5.9.2",
59
+ "vitest": "^3.2.4"
60
+ }
61
+ }