@palbase/backend 11.0.0 → 12.0.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.
@@ -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 { defineJob, Database, Log } from "@palbase/backend";
48
+ import { Database, Job, Log, type JobMeta } from "@palbase/backend";
48
49
 
49
- export default defineJob({
50
- name: "cleanup-expired",
51
- schedule: "0 3 * * *", // standard cron
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 { defineWebhook, Database, Log } from "@palbase/backend";
47
+ import { Database, Log, On, Webhook, type WebhookMeta } from "@palbase/backend";
47
48
 
48
- export default defineWebhook({
49
- provider: "stripe",
50
- secret: { env: "STRIPE_WEBHOOK_SECRET" }, // signing secret resolved from env
51
- events: {
52
- "checkout.session.completed": async (event, meta) => {
53
- await Database.insert("orders", { status: "paid", data: event });
54
- },
55
- "payment_intent.payment_failed": async (event, meta) => {
56
- Log.error("payment failed");
57
- await Database.insert("payment_failures", { data: event });
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
- The signing secret is resolved by the runtime from `secret: { env: "NAME" }`;
64
- your handlers access Environment variables via `meta.env`. The runtime verifies the
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 }`.
@@ -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 { defineJob, Database, Log } from "@palbase/backend";
1605
+ import { Database, Job, Log, type JobMeta } from "@palbase/backend";
1605
1606
 
1606
- export default defineJob({
1607
- name: "cleanup-expired",
1608
- schedule: "0 3 * * *", // standard cron
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 { defineWebhook, Database, Log } from "@palbase/backend";
1671
-
1672
- export default defineWebhook({
1673
- provider: "stripe",
1674
- secret: { env: "STRIPE_WEBHOOK_SECRET" }, // signing secret resolved from env
1675
- events: {
1676
- "checkout.session.completed": async (event, meta) => {
1677
- await Database.insert("orders", { status: "paid", data: event });
1678
- },
1679
- "payment_intent.payment_failed": async (event, meta) => {
1680
- Log.error("payment failed");
1681
- await Database.insert("payment_failures", { data: event });
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
- The signing secret is resolved by the runtime from `secret: { env: "NAME" }`;
1688
- your handlers access Environment variables via `meta.env`. The runtime verifies the
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@palbase/backend",
3
- "version": "11.0.0",
3
+ "version": "12.0.0",
4
4
  "description": "Palbase Backend SDK — class controllers (@Controller/@Get/@Post + @Body/@QueryParams/@Param), error classes, schema DSL",
5
5
  "license": "MIT",
6
6
  "repository": {