@forgezero/providers 0.1.11 → 0.1.12
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 +33 -5
- package/dist/binance.js +1 -1
- package/dist/chain.js +1 -1
- package/dist/database.js +1 -1
- package/dist/email.js +1 -1
- package/dist/http.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/pool.js +1 -1
- package/dist/storage.js +1 -1
- package/dist/translation.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -112,11 +112,14 @@ import * as api from '@forgezero/providers/realtime';
|
|
|
112
112
|
The service owns send/sendBatch. Attach provider methods directly in priority arrays; SMTP is never presented as batch-capable.
|
|
113
113
|
|
|
114
114
|
```text
|
|
115
|
-
import { createService } from '@forgezero/providers';
|
|
116
|
-
import { emailService, jetemail, smtp } from '@forgezero/providers/email';
|
|
115
|
+
import { createService, type EmailMessage } from '@forgezero/providers';
|
|
116
|
+
import { emailService, jetemail, smtp, type SmtpTransport } from '@forgezero/providers/email';
|
|
117
117
|
import { createVault } from '@forgezero/vault';
|
|
118
118
|
import { vaultCredentials } from '@forgezero/vault/providers';
|
|
119
119
|
|
|
120
|
+
// Adapt Nodemailer, Bun, or an HTTP SMTP relay once at the host boundary.
|
|
121
|
+
declare const transport: SmtpTransport;
|
|
122
|
+
|
|
120
123
|
const vault = createVault({ project: 'my-project', environment: 'production' });
|
|
121
124
|
const email = createService(emailService, {
|
|
122
125
|
send: [
|
|
@@ -128,7 +131,10 @@ const email = createService(emailService, {
|
|
|
128
131
|
]
|
|
129
132
|
});
|
|
130
133
|
|
|
134
|
+
const message: EmailMessage = { to: 'user@example.com', subject: 'Hello', text: 'Sent by ForgeZero' };
|
|
131
135
|
const outcome = await email.call('send', message);
|
|
136
|
+
if (!outcome.ok) throw outcome.error;
|
|
137
|
+
console.log(outcome.result, outcome.attempts);
|
|
132
138
|
```
|
|
133
139
|
|
|
134
140
|
## Extend with a custom provider and service
|
|
@@ -136,9 +142,26 @@ const outcome = await email.call('send', message);
|
|
|
136
142
|
Public consumers define provider capabilities and application services independently, then attach them with the same ordered-array API.
|
|
137
143
|
|
|
138
144
|
```text
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
import { createService, defineService, defineSingleMethodProvider, serviceMethod } from '@forgezero/providers';
|
|
146
|
+
import { createVault } from '@forgezero/vault';
|
|
147
|
+
import { vaultCredentials } from '@forgezero/vault/providers';
|
|
148
|
+
|
|
149
|
+
type Notice = { text: string };
|
|
150
|
+
type Receipt = { id: string };
|
|
151
|
+
const vault = createVault({ project: 'my-project', environment: 'production' });
|
|
152
|
+
|
|
153
|
+
const postmark = defineSingleMethodProvider({
|
|
154
|
+
id: 'postmark', label: 'Postmark', method: 'deliver',
|
|
155
|
+
async invoke(context, notice: Notice): Promise<Receipt> {
|
|
156
|
+
const response = await fetch('https://api.postmarkapp.com/email', {
|
|
157
|
+
method: 'POST', signal: context.signal,
|
|
158
|
+
headers: { 'x-postmark-server-token': await context.secret('apiKey') },
|
|
159
|
+
body: JSON.stringify(notice)
|
|
160
|
+
});
|
|
161
|
+
if (!response.ok) throw new Error(`Postmark returned ${response.status}`);
|
|
162
|
+
return { id: response.headers.get('x-message-id') ?? crypto.randomUUID() };
|
|
163
|
+
},
|
|
164
|
+
classify: () => 'retryable'
|
|
142
165
|
});
|
|
143
166
|
const notifications = defineService({
|
|
144
167
|
key: 'notifications', methods: { deliver: serviceMethod<Notice, Receipt>() }
|
|
@@ -153,6 +176,11 @@ const service = createService(notifications, {
|
|
|
153
176
|
Bootstrap tries the scoped Vault entry first and the identically named systemd credential second. If neither exists, the provider call fails.
|
|
154
177
|
|
|
155
178
|
```text
|
|
179
|
+
import { chainScopedCredentials, scopeCredentials } from '@forgezero/providers';
|
|
180
|
+
import { createVault, systemdCredentials } from '@forgezero/vault';
|
|
181
|
+
import { vaultCredentials } from '@forgezero/vault/providers';
|
|
182
|
+
|
|
183
|
+
const vault = createVault({ project: 'my-project', environment: 'production' });
|
|
156
184
|
const credentials = chainScopedCredentials(
|
|
157
185
|
vaultCredentials(vault, 'jetemail'),
|
|
158
186
|
scopeCredentials(systemdCredentials({
|
package/dist/binance.js
CHANGED
package/dist/chain.js
CHANGED
package/dist/database.js
CHANGED
package/dist/email.js
CHANGED
package/dist/http.js
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/pool.js
CHANGED
package/dist/storage.js
CHANGED
package/dist/translation.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forgezero/providers",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -86,6 +86,6 @@
|
|
|
86
86
|
"LICENSE"
|
|
87
87
|
],
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@forgezero/runtime": "^0.1.
|
|
89
|
+
"@forgezero/runtime": "^0.1.7"
|
|
90
90
|
}
|
|
91
91
|
}
|