@recursyve/nestjs-pidgey 11.0.0 → 11.1.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 +7 -0
- package/LICENSE +21 -0
- package/README.md +221 -0
- package/dist/index.d.mts +1261 -0
- package/dist/index.mjs +2152 -0
- package/package.json +38 -31
- package/index.d.ts +0 -10
- package/index.js +0 -69
- package/modules/auth0/auth/model/access-token.model.d.ts +0 -5
- package/modules/auth0/auth/model/access-token.model.js +0 -2
- package/modules/auth0/auth/services/auth.service.d.ts +0 -14
- package/modules/auth0/auth/services/auth.service.js +0 -54
- package/modules/auth0/auth.client.d.ts +0 -7
- package/modules/auth0/auth.client.js +0 -26
- package/modules/auth0/auth0.module.d.ts +0 -2
- package/modules/auth0/auth0.module.js +0 -21
- package/modules/auth0/auth0.service.d.ts +0 -6
- package/modules/auth0/auth0.service.js +0 -27
- package/modules/config/models/auth0-config.d.ts +0 -7
- package/modules/config/models/auth0-config.js +0 -11
- package/modules/config/models/pubsub-config.d.ts +0 -16
- package/modules/config/models/pubsub-config.js +0 -35
- package/modules/config/models/server-config.d.ts +0 -4
- package/modules/config/models/server-config.js +0 -9
- package/modules/config/services/pidgey-config-store.service.d.ts +0 -8
- package/modules/config/services/pidgey-config-store.service.js +0 -64
- package/modules/config/services/pidgey-config.service.d.ts +0 -13
- package/modules/config/services/pidgey-config.service.js +0 -39
- package/modules/constant.d.ts +0 -2
- package/modules/constant.js +0 -5
- package/modules/mails/dto/mail-templates.dto.d.ts +0 -15
- package/modules/mails/dto/mail-templates.dto.js +0 -6
- package/modules/mails/dto/mails.dto.d.ts +0 -4
- package/modules/mails/dto/mails.dto.js +0 -2
- package/modules/mails/index.d.ts +0 -8
- package/modules/mails/index.js +0 -54
- package/modules/mails/models/mail-templates.model.d.ts +0 -9
- package/modules/mails/models/mail-templates.model.js +0 -2
- package/modules/mails/models/mails.model.d.ts +0 -31
- package/modules/mails/models/mails.model.js +0 -9
- package/modules/mails/services/mail-templates.service.d.ts +0 -14
- package/modules/mails/services/mail-templates.service.js +0 -56
- package/modules/mails/services/mails.service.d.ts +0 -10
- package/modules/mails/services/mails.service.js +0 -52
- package/modules/postal/dto/postal-templates.dto.d.ts +0 -15
- package/modules/postal/dto/postal-templates.dto.js +0 -6
- package/modules/postal/index.d.ts +0 -7
- package/modules/postal/index.js +0 -52
- package/modules/postal/models/postal-templates.model.d.ts +0 -9
- package/modules/postal/models/postal-templates.model.js +0 -2
- package/modules/postal/services/postal-templates.service.d.ts +0 -14
- package/modules/postal/services/postal-templates.service.js +0 -56
- package/modules/service-base/service-base.d.ts +0 -19
- package/modules/service-base/service-base.js +0 -63
- package/modules/service-base/service-base.module.d.ts +0 -2
- package/modules/service-base/service-base.module.js +0 -21
- package/modules/sms/dto/sms-templates.dto.d.ts +0 -15
- package/modules/sms/dto/sms-templates.dto.js +0 -6
- package/modules/sms/index.d.ts +0 -7
- package/modules/sms/index.js +0 -52
- package/modules/sms/models/sms-templates.model.d.ts +0 -9
- package/modules/sms/models/sms-templates.model.js +0 -2
- package/modules/sms/services/sms-templates.service.d.ts +0 -14
- package/modules/sms/services/sms-templates.service.js +0 -56
- package/modules/tenants/index.d.ts +0 -6
- package/modules/tenants/index.js +0 -51
- package/modules/tenants/models/credentials/gcp.credential.d.ts +0 -5
- package/modules/tenants/models/credentials/gcp.credential.js +0 -2
- package/modules/tenants/models/mail-modules.model.d.ts +0 -3
- package/modules/tenants/models/mail-modules.model.js +0 -2
- package/modules/tenants/models/postal-modules.model.d.ts +0 -3
- package/modules/tenants/models/postal-modules.model.js +0 -2
- package/modules/tenants/models/sms-modules.model.d.ts +0 -3
- package/modules/tenants/models/sms-modules.model.js +0 -2
- package/modules/tenants/models/tenant-credentials.model.d.ts +0 -8
- package/modules/tenants/models/tenant-credentials.model.js +0 -10
- package/modules/tenants/models/tenants.model.d.ts +0 -12
- package/modules/tenants/models/tenants.model.js +0 -2
- package/modules/tenants/services/tenants.service.d.ts +0 -9
- package/modules/tenants/services/tenants.service.js +0 -17
- package/modules/transport/dto/email.dto.d.ts +0 -21
- package/modules/transport/dto/email.dto.js +0 -2
- package/modules/transport/dto/postal.dto.d.ts +0 -29
- package/modules/transport/dto/postal.dto.js +0 -6
- package/modules/transport/dto/sms.dto.d.ts +0 -8
- package/modules/transport/dto/sms.dto.js +0 -2
- package/modules/transport/index.d.ts +0 -11
- package/modules/transport/index.js +0 -42
- package/modules/transport/services/email-transport.service.d.ts +0 -13
- package/modules/transport/services/email-transport.service.js +0 -52
- package/modules/transport/services/postal-transport.service.d.ts +0 -13
- package/modules/transport/services/postal-transport.service.js +0 -50
- package/modules/transport/services/sms-transport.service.d.ts +0 -13
- package/modules/transport/services/sms-transport.service.js +0 -50
- package/modules/webhooks/guards/webhook.guard.d.ts +0 -7
- package/modules/webhooks/guards/webhook.guard.js +0 -44
- package/modules/webhooks/index.d.ts +0 -5
- package/modules/webhooks/index.js +0 -21
- package/modules/webhooks/models/mail-status-updated-webhooks.event.d.ts +0 -5
- package/modules/webhooks/models/mail-status-updated-webhooks.event.js +0 -2
- package/modules/webhooks/models/webhooks-event.interface.d.ts +0 -6
- package/modules/webhooks/models/webhooks-event.interface.js +0 -2
- package/modules/webhooks/models/webhooks.event.d.ts +0 -2
- package/modules/webhooks/models/webhooks.event.js +0 -2
- package/modules/webhooks/models/webhooks.type.d.ts +0 -1
- package/modules/webhooks/models/webhooks.type.js +0 -2
- package/tenant.factory.d.ts +0 -4
- package/tenant.factory.js +0 -33
- package/testbed.d.ts +0 -4
- package/testbed.js +0 -55
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @recursyve/nestjs-pidgey
|
|
2
|
+
|
|
3
|
+
## 11.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`464b2b0`](https://github.com/Recursyve/nestjs-pidgey/commit/464b2b0c74d8424ef3a9bfef5257774f0ca612d9) Thanks [@gabrielroberge](https://github.com/gabrielroberge)! - Add a typed NestJS client for the Pidgey v2 API, with modules for API keys, attachments, OAuth clients, infrastructure, logs, mail, SMS, tenants, and webhooks. Module options can also be read from environment variables.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Recursyve
|
|
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
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# @recursyve/nestjs-pidgey
|
|
2
|
+
|
|
3
|
+
Typed NestJS client for the [Pidgey](https://github.com/recursyve/nestjs-pidgey) v2 API. It registers a configured HTTP client and exposes handwritten modules for API keys, attachments, OAuth clients, infrastructure, logs, mail, SMS, tenants, and webhooks.
|
|
4
|
+
|
|
5
|
+
Only symbols exported from the package root (`@recursyve/nestjs-pidgey`) are part of the supported public API.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @recursyve/nestjs-pidgey
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Peer dependencies: `@nestjs/common`, `@nestjs/core`, `reflect-metadata`, and `rxjs` (Nest 11+).
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
Register `PidgeyModule` once in the application module. It is global by default, so feature modules can inject the Pidgey HTTP client without importing `PidgeyModule` again. Import the feature modules whose services you need.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { Module } from "@nestjs/common";
|
|
21
|
+
import {
|
|
22
|
+
ApiKeysModule,
|
|
23
|
+
AttachmentsModule,
|
|
24
|
+
ClientsModule,
|
|
25
|
+
InfrastructureModule,
|
|
26
|
+
LogsModule,
|
|
27
|
+
MailModule,
|
|
28
|
+
PidgeyModule,
|
|
29
|
+
SmsModule,
|
|
30
|
+
TenantsModule,
|
|
31
|
+
WebhooksModule
|
|
32
|
+
} from "@recursyve/nestjs-pidgey";
|
|
33
|
+
|
|
34
|
+
@Module({
|
|
35
|
+
imports: [
|
|
36
|
+
PidgeyModule.forRoot({
|
|
37
|
+
apiKey: "pidgey-api-key",
|
|
38
|
+
baseUrl: "https://pidgey.example/api",
|
|
39
|
+
tenantId: "tenant-id",
|
|
40
|
+
webhookSecret: "webhook-secret"
|
|
41
|
+
}),
|
|
42
|
+
ApiKeysModule,
|
|
43
|
+
AttachmentsModule,
|
|
44
|
+
ClientsModule,
|
|
45
|
+
InfrastructureModule,
|
|
46
|
+
LogsModule,
|
|
47
|
+
MailModule,
|
|
48
|
+
SmsModule,
|
|
49
|
+
TenantsModule,
|
|
50
|
+
WebhooksModule
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
|
+
export class AppModule {}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`apiKey` and `tenantId` are required non-empty strings. `baseUrl` defaults to `https://pidgey.recursyve.dev/api`; when set, it must be an absolute HTTP or HTTPS URL, and trailing slashes are stripped. `webhookSecret` is optional unless you use `WebhookGuard`. Empty strings are rejected at registration.
|
|
57
|
+
|
|
58
|
+
Any option you leave out is read from its environment variable:
|
|
59
|
+
|
|
60
|
+
| Option | Environment variable | Default |
|
|
61
|
+
| --------------- | ----------------------- | ---------------------------------- |
|
|
62
|
+
| `apiKey` | `PIDGEY_API_KEY` | required |
|
|
63
|
+
| `baseUrl` | `PIDGEY_BASE_URL` | `https://pidgey.recursyve.dev/api` |
|
|
64
|
+
| `tenantId` | `PIDGEY_TENANT_ID` | required |
|
|
65
|
+
| `webhookSecret` | `PIDGEY_WEBHOOK_SECRET` | none |
|
|
66
|
+
|
|
67
|
+
Options passed to the module take precedence. To configure everything from the environment, call `PidgeyModule.forRoot()` with no arguments. If a required value is set neither in the options nor in the environment (an empty variable counts as missing), the application fails at startup with an error naming the missing variable.
|
|
68
|
+
|
|
69
|
+
Every request sends that `apiKey` and `tenantId`. Mail, SMS, logs, attachments, API keys, OAuth clients, webhooks, and `TenantProvidersService` operate on that tenant. `TenantsService` creates, lists, and updates tenants, and reads a tenant by id. `InfrastructureService` exposes server information and health checks.
|
|
70
|
+
|
|
71
|
+
Async registration:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
PidgeyModule.forRootAsync({
|
|
75
|
+
imports: [ConfigModule],
|
|
76
|
+
inject: [ConfigService],
|
|
77
|
+
useFactory: (config: ConfigService) => ({
|
|
78
|
+
apiKey: config.getOrThrow("PIDGEY_API_KEY"),
|
|
79
|
+
baseUrl: config.get("PIDGEY_BASE_URL"),
|
|
80
|
+
tenantId: config.getOrThrow("PIDGEY_TENANT_ID"),
|
|
81
|
+
webhookSecret: config.get("PIDGEY_WEBHOOK_SECRET")
|
|
82
|
+
})
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Pass `isGlobal: false` if you do not want `PidgeyModule` to be global. On `forRoot`, put it next to the other options. On `forRootAsync`, put it next to `useFactory`, not inside the factory return value. When the module is not global, import `PidgeyModule` in the same module as the feature modules you use.
|
|
87
|
+
|
|
88
|
+
Paged list methods return `Paged<T>` (`values`, plus optional `page`, `next`, and `total`). Entity types such as `Mail`, `ApiKey`, and `Tenant` are exported from the package root.
|
|
89
|
+
|
|
90
|
+
## Errors
|
|
91
|
+
|
|
92
|
+
All service methods throw when the HTTP request fails. They do not return error result objects.
|
|
93
|
+
|
|
94
|
+
On a non-success response, the thrown value is the JSON body when the response parses as JSON, or the response text otherwise. Network and other transport failures throw as usual.
|
|
95
|
+
|
|
96
|
+
## Infrastructure
|
|
97
|
+
|
|
98
|
+
Inject `InfrastructureService` after importing `InfrastructureModule`. `getServerInfo()` returns a `ServerInfo` (`mode` and `version`). `getHealth()` returns a `HealthCheck`.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
const info = await this.infrastructure.getServerInfo();
|
|
102
|
+
const health = await this.infrastructure.getHealth();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## API keys
|
|
106
|
+
|
|
107
|
+
Inject `ApiKeysService` after importing `ApiKeysModule`. Create, list, and update keys. `create()` returns a `CreatedApiKey` that includes the secret once; `findAll()` returns `Paged<ApiKey>` without it.
|
|
108
|
+
|
|
109
|
+
## Attachments
|
|
110
|
+
|
|
111
|
+
Inject `AttachmentsService` after importing `AttachmentsModule`. Upload `File` or `Blob` values, then pass the returned id as `attachmentRefId` when sending mail.
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const attachment = await this.attachments.upload({
|
|
115
|
+
attachments: [new File(["invoice"], "invoice.pdf", { type: "application/pdf" })]
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
await this.mails.send({
|
|
119
|
+
to: ["billing@example.com"],
|
|
120
|
+
subject: "Invoice",
|
|
121
|
+
text: "See attached.",
|
|
122
|
+
attachmentRefId: attachment._id
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## OAuth clients
|
|
127
|
+
|
|
128
|
+
Inject `OauthClientsService` after importing `ClientsModule`. `create()` creates a client on the current tenant, `add()` attaches an existing client id, `findAll()` lists clients, and `update()` changes name and scopes.
|
|
129
|
+
|
|
130
|
+
## Logs
|
|
131
|
+
|
|
132
|
+
Inject `LogsService` after importing `LogsModule`. `find()` lists mail or SMS logs for a time range.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
const logs = await this.logs.find({
|
|
136
|
+
from: "2026-01-01T00:00:00Z",
|
|
137
|
+
to: "2026-01-31T23:59:59Z",
|
|
138
|
+
type: "mail"
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Mail
|
|
143
|
+
|
|
144
|
+
Inject `MailsService` or `MailTemplatesService` after importing `MailModule`.
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import { Injectable } from "@nestjs/common";
|
|
148
|
+
import { MailsService } from "@recursyve/nestjs-pidgey";
|
|
149
|
+
|
|
150
|
+
@Injectable()
|
|
151
|
+
export class NotificationsService {
|
|
152
|
+
constructor(private readonly mails: MailsService) {}
|
|
153
|
+
|
|
154
|
+
public async sendWelcome(email: string): Promise<void> {
|
|
155
|
+
await this.mails.send({
|
|
156
|
+
to: [email],
|
|
157
|
+
subject: "Welcome",
|
|
158
|
+
templateId: "welcome",
|
|
159
|
+
variables: { name: "Ada" }
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
`MailsService.find()` lists sent mail. `MailTemplatesService` can create, list, fetch by id or name, update, and `remove()` templates, and list provider templates with `findProviderTemplates()`.
|
|
166
|
+
|
|
167
|
+
## SMS
|
|
168
|
+
|
|
169
|
+
Inject `SmsService` or `SmsTemplatesService` after importing `SmsModule`.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
await this.sms.send({
|
|
173
|
+
to: ["+15145550100"],
|
|
174
|
+
templateId: "otp",
|
|
175
|
+
variables: { code: "123456" }
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`SmsService.find()` lists sent SMS. `SmsTemplatesService` can create, list, fetch by id or name, update, and `remove()` templates.
|
|
180
|
+
|
|
181
|
+
## Tenants
|
|
182
|
+
|
|
183
|
+
Inject `TenantsService` or `TenantProvidersService` after importing `TenantsModule`.
|
|
184
|
+
|
|
185
|
+
`TenantsService` creates, lists, fetches, and updates tenants, and lists a tenant's modules with `findModules(id)`. `TenantProvidersService` enables mail or SMS on the current tenant, configures the provider, or patches the default sender.
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
await this.tenantProviders.enableMail();
|
|
189
|
+
await this.tenantProviders.configureMail({
|
|
190
|
+
type: "mailgun",
|
|
191
|
+
defaultSender: "noreply@example.com",
|
|
192
|
+
mailgun: {
|
|
193
|
+
domain: "mg.example.com",
|
|
194
|
+
apiKey: "mailgun-api-key"
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Webhooks
|
|
200
|
+
|
|
201
|
+
Import `WebhooksModule` and set `webhookSecret` on `PidgeyModule`. `WebhooksService` can `create()` listeners, `findAll()`, `findSecret()`, and `remove()` a listener.
|
|
202
|
+
|
|
203
|
+
`WebhookGuard` verifies `Pidgey-Webhook-Signature` (hex HMAC-SHA256 of `eventType:timestamp`). Invalid signatures throw `NotAcceptableException`.
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
import { Body, Controller, Post, UseGuards } from "@nestjs/common";
|
|
207
|
+
import { MailStatusUpdatedWebhookEvent, WebhookGuard } from "@recursyve/nestjs-pidgey";
|
|
208
|
+
|
|
209
|
+
@Controller("webhooks/pidgey")
|
|
210
|
+
export class WebhooksController {
|
|
211
|
+
@Post("mail")
|
|
212
|
+
@UseGuards(WebhookGuard)
|
|
213
|
+
public onMailStatus(@Body() event: MailStatusUpdatedWebhookEvent): void {
|
|
214
|
+
// event.data is a Mail
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
|
|
221
|
+
MIT
|