@palbase/backend 11.0.0 → 12.0.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/dist/index.cjs +148 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -158
- package/dist/index.d.ts +56 -158
- package/dist/index.js +143 -106
- package/dist/index.js.map +1 -1
- package/docs/background.md +8 -9
- package/docs/events.md +20 -17
- package/docs/llms-full.txt +29 -27
- package/package.json +1 -1
package/docs/background.md
CHANGED
|
@@ -40,22 +40,21 @@ await Queue.push("process-order", { orderId: "ord_1", amount: 1000 });
|
|
|
40
40
|
|
|
41
41
|
## Jobs (cron-scheduled)
|
|
42
42
|
|
|
43
|
-
A job runs on a cron schedule. File lives under `jobs
|
|
43
|
+
A job runs on a cron schedule. File lives under `jobs/` — the job's name is
|
|
44
|
+
the file name, there is no `name` option.
|
|
44
45
|
|
|
45
46
|
```ts
|
|
46
47
|
// jobs/cleanup.ts
|
|
47
|
-
import {
|
|
48
|
+
import { Database, Job, Log, type JobMeta } from "@palbase/backend";
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
timeout: 120, // optional, seconds
|
|
53
|
-
handler: async (meta) => {
|
|
50
|
+
@Job({ schedule: "0 3 * * *", timeout: 120 }) // schedule: standard cron; timeout: optional, seconds
|
|
51
|
+
export default class CleanupJob {
|
|
52
|
+
async run(meta: JobMeta) {
|
|
54
53
|
const expired = await Database.findMany("sessions", { expired: true });
|
|
55
54
|
for (const s of expired) await Database.delete("sessions", s.id as string);
|
|
56
55
|
Log.info(`cleaned ${expired.length} sessions in ${meta.environmentId}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
59
58
|
```
|
|
60
59
|
|
|
61
60
|
`meta` shape: `{ env, environmentId }`. No `user` (jobs are
|
package/docs/events.md
CHANGED
|
@@ -39,29 +39,32 @@ Available hook builders: `auth.onUserCreated`, `auth.onSignIn`, `auth.onSignOut`
|
|
|
39
39
|
## Webhooks (inbound provider events)
|
|
40
40
|
|
|
41
41
|
Receive and verify webhooks from third-party providers. Files live under
|
|
42
|
-
`webhooks
|
|
42
|
+
`webhooks/` — the URL is `POST /webhooks/<file-name>` (e.g. `webhooks/stripe.ts`
|
|
43
|
+
→ `POST /webhooks/stripe`); there is no `path` option.
|
|
43
44
|
|
|
44
45
|
```ts
|
|
45
46
|
// webhooks/stripe.ts
|
|
46
|
-
import {
|
|
47
|
+
import { Database, Log, On, Webhook, type WebhookMeta } from "@palbase/backend";
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
49
|
+
@Webhook({ provider: "stripe", secret: { env: "STRIPE_WEBHOOK_SECRET" } }) // signing secret resolved from env
|
|
50
|
+
export default class StripeWebhook {
|
|
51
|
+
@On("checkout.session.completed")
|
|
52
|
+
async checkoutCompleted(event: unknown, meta: WebhookMeta) {
|
|
53
|
+
await Database.insert("orders", { status: "paid", data: event });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@On("payment_intent.payment_failed")
|
|
57
|
+
async paymentFailed(event: unknown, meta: WebhookMeta) {
|
|
58
|
+
Log.error("payment failed");
|
|
59
|
+
await Database.insert("payment_failures", { data: event });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
61
62
|
```
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
`provider` selects a preset signature scheme; a service with no preset spells
|
|
65
|
+
one out with `signature` instead — one of the two is required. The signing
|
|
66
|
+
secret is resolved by the runtime from `secret: { env: "NAME" }`; your
|
|
67
|
+
handlers access Environment variables via `meta.env`. The runtime verifies the
|
|
65
68
|
signature before dispatching to your event handlers.
|
|
66
69
|
|
|
67
70
|
`meta` shape: `{ env, requestId, environmentId }`.
|
package/docs/llms-full.txt
CHANGED
|
@@ -1597,22 +1597,21 @@ await Queue.push("process-order", { orderId: "ord_1", amount: 1000 });
|
|
|
1597
1597
|
|
|
1598
1598
|
## Jobs (cron-scheduled)
|
|
1599
1599
|
|
|
1600
|
-
A job runs on a cron schedule. File lives under `jobs
|
|
1600
|
+
A job runs on a cron schedule. File lives under `jobs/` — the job's name is
|
|
1601
|
+
the file name, there is no `name` option.
|
|
1601
1602
|
|
|
1602
1603
|
```ts
|
|
1603
1604
|
// jobs/cleanup.ts
|
|
1604
|
-
import {
|
|
1605
|
+
import { Database, Job, Log, type JobMeta } from "@palbase/backend";
|
|
1605
1606
|
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
timeout: 120, // optional, seconds
|
|
1610
|
-
handler: async (meta) => {
|
|
1607
|
+
@Job({ schedule: "0 3 * * *", timeout: 120 }) // schedule: standard cron; timeout: optional, seconds
|
|
1608
|
+
export default class CleanupJob {
|
|
1609
|
+
async run(meta: JobMeta) {
|
|
1611
1610
|
const expired = await Database.findMany("sessions", { expired: true });
|
|
1612
1611
|
for (const s of expired) await Database.delete("sessions", s.id as string);
|
|
1613
1612
|
Log.info(`cleaned ${expired.length} sessions in ${meta.environmentId}`);
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1616
1615
|
```
|
|
1617
1616
|
|
|
1618
1617
|
`meta` shape: `{ env, environmentId }`. No `user` (jobs are
|
|
@@ -1663,29 +1662,32 @@ Available hook builders: `auth.onUserCreated`, `auth.onSignIn`, `auth.onSignOut`
|
|
|
1663
1662
|
## Webhooks (inbound provider events)
|
|
1664
1663
|
|
|
1665
1664
|
Receive and verify webhooks from third-party providers. Files live under
|
|
1666
|
-
`webhooks
|
|
1665
|
+
`webhooks/` — the URL is `POST /webhooks/<file-name>` (e.g. `webhooks/stripe.ts`
|
|
1666
|
+
→ `POST /webhooks/stripe`); there is no `path` option.
|
|
1667
1667
|
|
|
1668
1668
|
```ts
|
|
1669
1669
|
// webhooks/stripe.ts
|
|
1670
|
-
import {
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1670
|
+
import { Database, Log, On, Webhook, type WebhookMeta } from "@palbase/backend";
|
|
1671
|
+
|
|
1672
|
+
@Webhook({ provider: "stripe", secret: { env: "STRIPE_WEBHOOK_SECRET" } }) // signing secret resolved from env
|
|
1673
|
+
export default class StripeWebhook {
|
|
1674
|
+
@On("checkout.session.completed")
|
|
1675
|
+
async checkoutCompleted(event: unknown, meta: WebhookMeta) {
|
|
1676
|
+
await Database.insert("orders", { status: "paid", data: event });
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
@On("payment_intent.payment_failed")
|
|
1680
|
+
async paymentFailed(event: unknown, meta: WebhookMeta) {
|
|
1681
|
+
Log.error("payment failed");
|
|
1682
|
+
await Database.insert("payment_failures", { data: event });
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
1685
|
```
|
|
1686
1686
|
|
|
1687
|
-
|
|
1688
|
-
|
|
1687
|
+
`provider` selects a preset signature scheme; a service with no preset spells
|
|
1688
|
+
one out with `signature` instead — one of the two is required. The signing
|
|
1689
|
+
secret is resolved by the runtime from `secret: { env: "NAME" }`; your
|
|
1690
|
+
handlers access Environment variables via `meta.env`. The runtime verifies the
|
|
1689
1691
|
signature before dispatching to your event handlers.
|
|
1690
1692
|
|
|
1691
1693
|
`meta` shape: `{ env, requestId, environmentId }`.
|
package/package.json
CHANGED