@appweaver/skill 3.0.0 → 3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appweaver/skill",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Appweaver - the backend framework for AI-first development (@skill)",
5
5
  "author": "Luka Matosevic",
6
6
  "license": "MIT",
package/skill/SKILL.md CHANGED
@@ -115,6 +115,7 @@ task): one JSON document on stdout, the logs and errors on stderr.
115
115
  | Emails, text messages, templates and translations | [mailer.md](references/mailer.md), [sms.md](references/sms.md), [templates.md](references/templates.md) |
116
116
  | Realtime channels, resource events, actions and streams | [realtime.md](references/realtime.md) |
117
117
  | AI models and tools, the MCP server | [ai.md](references/ai.md), [mcp.md](references/mcp.md) |
118
+ | Online payments, subscriptions, Stripe, payment webhooks | [payments.md](references/payments.md) |
118
119
  | Time series, spatial fields, audit log | [timeseries.md](references/timeseries.md), [spatial.md](references/spatial.md), [audit.md](references/audit.md) |
119
120
  | Logging, OpenTelemetry | [logging.md](references/logging.md), [telemetry.md](references/telemetry.md) |
120
121
  | A typed HTTP client of the API | [client.md](references/client.md) |
@@ -62,6 +62,8 @@ The changes of a request whose category is disabled are still recorded, each wit
62
62
 
63
63
  - `audit.excludePaths`: URL paths, exact or a prefix ending with `*`. The health check, Swagger, static file and
64
64
  template preview routes are always left out, and so are the `OPTIONS` requests.
65
+ - The webhook and return routes of `@appweaver/payments` and its read-only record routes are left out too
66
+ (`audit: false`). Its action routes (a refund, a capture, a subscription) are recorded like any custom route.
65
67
  - `audit.excludeModels`: whole resources, their routes and their changes.
66
68
  - `audit.excludeActions`: an action of every model (`find`, `export`, `auth.refresh`) or of one (`Post.update`).
67
69
  - The `audit` option of a route: `false` leaves the route and the changes it makes out, an object sets the category
@@ -322,6 +322,12 @@ prefer the SQL migrations for custom SQL: `weaver migration new <name> --sql [--
322
322
  `database/sql/<timestamp>_<name>[.<database>].sql` instead ([database.md](./database.md#sql-migrations)). The command
323
323
  fails before creating a Prisma migration that would drop a column or an index a SQL migration created.
324
324
 
325
+ With generated columns in the models ([resources.md](./resources.md#generated-columns)), it first creates and applies
326
+ the Prisma migration `<timestamp>_generated_columns` recording them, when they are new or changed: a SQL migration
327
+ creates them, which `prisma migrate dev` would otherwise report as a drift of the database. Commit it with the
328
+ migration created after it. When it cannot be applied (a database without the tables of the models), the command
329
+ removes it and marks it as rolled back, so the next run is not refused with `P3009`.
330
+
325
331
  ### `weaver migration check`
326
332
 
327
333
  Tells whether the models changed without a migration, like `makemigrations --check` of Django. It builds the Prisma
@@ -369,6 +375,9 @@ of `weaver migration new` and `weaver test setup`, see **Run tests** in [SKILL.m
369
375
  Without `--force` the command runs only when `NODE_ENV` resolves to `dev` or `test`, and aborts otherwise. Either
370
376
  `--force` or `--yes` skips the Prisma confirmation prompt.
371
377
 
378
+ The SQL migrations of `database.sqlDirPath` are applied after the reset. A project without a Prisma migration yet has
379
+ no table for them, so they are skipped: run `weaver migrate` after the first `weaver migration new`.
380
+
372
381
  ---
373
382
 
374
383
  ## `weaver module`
@@ -431,6 +440,22 @@ the English texts. The dependencies are installed when `package.json` changed. `
431
440
  the `data` module (`weaver module add data --database postgresql`), SQLite by default; it is refused once `data` is
432
441
  enabled, and reported as ignored when `data` is not added.
433
442
 
443
+ The command ends with its `Next steps`, what the added modules leave to do by hand. The modules changing the
444
+ database share one migration step, naming what each adds:
445
+
446
+ ```
447
+ Next steps:
448
+ - Run "npx weaver generate", then "npx weaver migration new add_data_web" to add to the database: the table of the seeders, the User model with its roles, permissions, API keys and tokens.
449
+ - Run "npm run seed" once the database is migrated, to create the roles and the admin user.
450
+ ```
451
+
452
+ | Module | Next steps |
453
+ | ------------ | -------------------------------------------------------------------------------------------- |
454
+ | `data` | The migration of the table of the seeders |
455
+ | `web` | The migration of the `User` model and the auth data model, then the seeders (`npm run seed`) |
456
+ | `payments` | The migration of the models of the payments, and the Stripe keys to set in `.env` |
457
+ | `timeseries` | A migration once a model declares `series` fields, each getting its `<Model>Series` table |
458
+
434
459
  A name that is not a scaffold module, with a scope, a `-` or a `/`, is a module package
435
460
  (`weaver module add @acme/appweaver-gcs`), installed with
436
461
  `npm install --ignore-scripts <package>` (`bun add` on Bun), so its install scripts never run. The command then
@@ -461,6 +486,10 @@ of `web` are deleted (the `User` resource and its admin seeder), the changed one
461
486
  changed e2e test of `web`. Removing `data` deletes `database/` with its migrations and seeders, listing the ones written
462
487
  in the project in a warning.
463
488
 
489
+ The command ends with its `Next steps` when a removed module changed the database (`web`, `payments`): `weaver
490
+ generate`, then `weaver migration new remove_<modules>`, the migration dropping their tables with their data. Removing
491
+ `data` leaves no migrations, so it tells that the database keeps its tables, to drop by hand.
492
+
464
493
  | Option | Description | Default |
465
494
  | -------------- | ----------------------------------------- | --------- |
466
495
  | `--no-install` | Skip the installation of the dependencies | installed |
@@ -551,7 +580,9 @@ weaver run src/tasks/orders/count.ts Paid # run the task of a file
551
580
  ```
552
581
 
553
582
  The tasks of the enabled modules are listed and run too (see [modules](./modules.md)), a task of the application
554
- replacing a module task of the same name. A plain default function, `(args: string[]) => number | void`, still works,
583
+ replacing a module task of the same name: `maintenance` of core, and with `@appweaver/payments` the tasks
584
+ `payments-sync-plans [gateway]` (reads the recurring prices of the gateways into the plans) and
585
+ `payments-replay [id]` (processes the failed webhook events again, see [payments](./payments.md)). A plain default function, `(args: string[]) => number | void`, still works,
555
586
  receiving the raw arguments. On Node the tasks run from the build output (`dist/src/tasks/`), so build first.
556
587
 
557
588
  ---
@@ -58,10 +58,9 @@ Reads an OpenAPI v3 schema and generates TypeScript types and a typed client cla
58
58
  | Option | Description | Default |
59
59
  |----------------------------|----------------------------------------------------------------------------------------------|---------------------------|
60
60
  | `--types-only` | Generate TypeScript types only, skip client class generation | `false` |
61
- | `--client-only` | Generate client class only, skip TypeScript types generation | `false` |
62
- | `-o, --output-path <path>` | Output path of the client (and of the types with `--types-only`) | `./generated/client.ts` |
63
- | `--types-path <path>` | Output path of the types, the output path for a single file | `<output>.types.ts` |
64
- | `--client-path <path>` | Output path for generated client class only | same as `--output-path` |
61
+ | `--client-only` | Generate client class only, importing the types of `--types-path` (required with it) | `false` |
62
+ | `-o, --output-path <path>` | Output path of the client and its types, written into one file | `./generated/client.ts` |
63
+ | `--types-path <path>` | Output path of the types, written into a file of their own the client imports | same as `--output-path` |
65
64
  | `--client-name <name>` | Custom name for the generated client class | derived from schema title |
66
65
  | `--framework <framework>` | Framework for the generated client class (`fetch` or `angular`) | `fetch` |
67
66
  | `--no-types` | Generate an untyped client class, without the TypeScript types | typed |
@@ -84,7 +83,8 @@ Reads an OpenAPI v3 schema and generates TypeScript types and a typed client cla
84
83
  (`.d.ts`), the constant is declared rather than initialized, since such a file carries no runtime values.
85
84
  6. Classifies all API paths into route groups: resources, auth, account, health, files, and custom. `paths` keeps the
86
85
  custom routes only, the module and resource clients typing their requests by their module types; the other routes
87
- keep their error codes in `routeErrors`, so `RouteErrorCode` and `isRouteError` type every route.
86
+ keep their error codes in `routeErrors`, so `RouteErrorCode` and `isRouteError` type every route, while
87
+ `sendRequest` and `sendRequestRaw` accept the custom routes only.
88
88
  7. Derives the types of a resource that equal another one instead of declaring them again: `Replace` and
89
89
  `RelationCreate` as `Create`, `Update` as `Partial<Create>`, `Multiple` as `Single` or `Omit<Single, ...>`, and
90
90
  `ExportRequest` as `Pick<QueryRequest, 'filter' | 'sort'>`.
@@ -92,17 +92,20 @@ Reads an OpenAPI v3 schema and generates TypeScript types and a typed client cla
92
92
  omitted operations, or its used ones (`{ only: [...] }`) when shorter, and the operations its model cannot have
93
93
  (files, time series) are left out by the types of the library.
94
94
  9. Formats all output with Prettier.
95
- 10. Writes the client and the types (`client.ts` and `client.types.ts` by default), the client re-exporting the types,
96
- each with an autogenerated header comment.
95
+ 10. Writes the client and the types into the one file of `--output-path`, under an autogenerated header comment. With
96
+ `--types-path`, the types are written into that file instead, which the client imports and re-exports.
97
97
 
98
98
  **Examples:**
99
99
 
100
100
  ```bash
101
- # Generate the client and its types from a local OpenAPI file (client.ts and client.types.ts)
101
+ # Generate the client and its types from a local OpenAPI file, into one file
102
102
  weaver-client generate ./openapi.json --output-path ./src/generated/client.ts
103
103
 
104
- # Generate the client and its types into a single file, with the doc comments
105
- weaver-client generate ./openapi.json -o ./src/generated/client.ts --types-path ./src/generated/client.ts --comments
104
+ # Generate them with the doc comments of the schema
105
+ weaver-client generate ./openapi.json -o ./src/generated/client.ts --comments
106
+
107
+ # Generate the client and its types into two files (client.ts and client.types.ts)
108
+ weaver-client generate ./openapi.json -o ./src/generated/client.ts --types-path ./src/generated/client.types.ts
106
109
 
107
110
  # Generate types + client from a running server
108
111
  weaver-client generate http://localhost:3000/openapi.json --output-path ./src/generated/client.ts
@@ -110,16 +113,16 @@ weaver-client generate http://localhost:3000/openapi.json --output-path ./src/ge
110
113
  # Generate types only
111
114
  weaver-client generate ./openapi.json --types-only --output-path ./src/types/api.ts
112
115
 
113
- # Generate client class only
114
- weaver-client generate ./openapi.json --client-only --output-path ./src/client.ts
116
+ # Generate client class only, importing the types generated before
117
+ weaver-client generate ./openapi.json --client-only --output-path ./src/client.ts --types-path ./src/types/api.ts
115
118
 
116
119
  # Generate client class without TypeScript types
117
120
  weaver-client generate ./openapi.json --no-types --output-path ./src/client.ts
118
121
 
119
122
  # Separate output files with a custom class name
120
123
  weaver-client generate ./openapi.json \
124
+ --output-path ./src/client.ts \
121
125
  --types-path ./src/types/api.ts \
122
- --client-path ./src/client.ts \
123
126
  --client-name CmsApiClient
124
127
  ```
125
128
 
@@ -147,10 +150,11 @@ const users = await client.user.query({ filter: { enabled: true } });
147
150
 
148
151
  ## Generated output
149
152
 
150
- Running `weaver-client generate` produces the client and its types in two files by default (`client.ts` and
151
- `client.types.ts`), the client re-exporting the types, so every type is imported from the client.
153
+ Running `weaver-client generate` produces the client and its types in one file by default (`client.ts`). With
154
+ `--types-path`, the types are written into a file of their own (i.e. `client.types.ts`), which the client imports as
155
+ `Type` and re-exports. Either way, every type is imported from the client.
152
156
 
153
- ### Types file
157
+ ### Types
154
158
 
155
159
  Contains all TypeScript interfaces and type aliases derived from the OpenAPI schema. The key export is the `paths`
156
160
  type used to parameterise `FetchClient`, holding the custom routes and the error codes of the other ones
@@ -207,7 +211,10 @@ export type PostQueryFilter = {
207
211
  };
208
212
  ```
209
213
 
210
- ### Client file
214
+ ### Client class
215
+
216
+ The client of a types file (`--types-path ./generated/client.types.ts`) refers to its types as `Type.<name>`. In a
217
+ single file it refers to them by their name alone (`FetchClient<paths>`), and has no import of them.
211
218
 
212
219
  ```ts
213
220
  // Generated by Appweaver. Please do not edit this file manually.
@@ -226,6 +233,9 @@ export class CMSAPIClient extends FetchClient<Type.paths> {
226
233
 
227
234
  public files = this.filesClient('/files');
228
235
 
236
+ // Only for an API with the routes of @appweaver/payments
237
+ public payments = this.paymentsClient<Type.PaymentsModuleType>('/api');
238
+
229
239
  // Resource with some operations excluded (compile-time Omit)
230
240
  public apiKey = this.resourceClient<
231
241
  Type.ApiKeyResourceModuleType,
@@ -286,6 +296,9 @@ const client = new CMSAPIClient(httpClient, {
286
296
  client.user.query({ filter: { enabled: true } }).subscribe((users) => {});
287
297
  ```
288
298
 
299
+ The [raw operations](#raw-responses-raw) of a resource return observables too, emitting `{ data, error, response }`
300
+ (`client.user.raw.find(1).subscribe(({ data, response }) => {})`).
301
+
289
302
  An error response reaches the `error` callback as a `ClientError`, as with `FetchClient`, not as Angular's
290
303
  `HttpErrorResponse`. Only a network error (status 0) is passed on as the `HttpErrorResponse` itself:
291
304
 
@@ -510,6 +523,43 @@ await client.post.deleteFileVersions(1, {
510
523
  });
511
524
  ```
512
525
 
526
+ #### Request options
527
+
528
+ The last argument of every operation takes the options of the request (`RequestOptions`, the options of
529
+ `openapi-fetch`): `headers`, additional `params.query`, a `signal`, and so on. The arguments of the operation win over
530
+ them, so the `id` of the path and the body cannot be overridden.
531
+
532
+ ```ts
533
+ const post = await client.post.find(1, {
534
+ headers: { 'X-Tenant': 'acme' },
535
+ params: { query: { include: 'author' } },
536
+ signal: controller.signal
537
+ });
538
+ ```
539
+
540
+ #### Raw responses (`raw`)
541
+
542
+ `client.<resource>.raw` holds the same operations, each resolving to `{ data, error, response }` (`RawResponse`)
543
+ instead of its data, and not throwing for an error response. Use it to read the status or the headers of a response,
544
+ or to handle an error inline. Exactly one of `data` and `error` is set, the `error` being the problem details of the
545
+ response. An operation the resource client leaves out is left out of `raw` too.
546
+
547
+ ```ts
548
+ const { data, error, response } = await client.post.raw.find(1);
549
+
550
+ if (error) {
551
+ console.error(response.status, error.code); // 404 'RESOURCE_NOT_FOUND'
552
+ } else {
553
+ console.log(response.headers.get('ETag'), data.title);
554
+ }
555
+
556
+ // The export resolves its file as the data
557
+ const { data: file } = await client.post.raw.export({ filter: { published: true } });
558
+ ```
559
+
560
+ The type arguments of an operation are not passed on: a raw bulk operation is typed as the records or their count
561
+ (`ResourceBulkResponse`), and `raw.fileVersions` as `unknown[]`.
562
+
513
563
  ### `AuthClient`
514
564
 
515
565
  The routes of [security.md](./security.md#auth-routes).
@@ -591,6 +641,55 @@ if (session.twoFactorMethods) {
591
641
  }
592
642
  ```
593
643
 
644
+ ### `PaymentsClient`
645
+
646
+ `client.payments` is generated for an API with `@appweaver/payments` and its `payments.routes.enabled`, described in
647
+ [payments.md](./payments.md#routes). The paths are under the API prefix (`/api`). An API with
648
+ `payments.subscriptions.enabled: false` has no subscription routes, so its client has none of the five subscription
649
+ methods below.
650
+
651
+ | Method | HTTP | Description |
652
+ |----------------------------------------------|-------------------------------------------|---------------------------------------------------------------|
653
+ | `setupPaymentMethod(request?, options?)` | `POST /payment-methods/setup` | Start saving a payment method, returns `{ nextAction }` |
654
+ | `setDefaultPaymentMethod(id, options?)` | `POST /payment-methods/{id}/default` | Charge the subscriptions of the user to a saved method |
655
+ | `removePaymentMethod(id, options?)` | `DELETE /payment-methods/{id}` | Remove a saved method, at the gateway too |
656
+ | `subscribe(request, options?)` | `POST /payment-subscriptions/subscribe` | Subscribe to a plan, returns `{ subscription, nextAction }` |
657
+ | `subscribeCheckout(request, options?)` | `POST /payment-subscriptions/checkout` | Subscribe on the page of the gateway (`redirect` next action) |
658
+ | `cancelSubscription(id, request?, options?)` | `POST /payment-subscriptions/{id}/cancel` | Cancel at the end of the period, or at once (`atPeriodEnd`) |
659
+ | `resumeSubscription(id, options?)` | `POST /payment-subscriptions/{id}/resume` | Keep a subscription canceled with the end of its period |
660
+ | `changePlan(id, request, options?)` | `POST /payment-subscriptions/{id}/plan` | Move a subscription to another plan |
661
+ | `portal(request?, options?)` | `POST /payments/portal` | The `url` of the billing page of the gateway |
662
+ | `refund(id, request?, options?)` | `POST /payments/{id}/refund` | Admin roles: refund a payment, returns the ledger entry |
663
+ | `capture(id, request?, options?)` | `POST /payments/{id}/capture` | Admin roles: capture an authorized payment |
664
+ | `cancel(id, options?)` | `POST /payments/{id}/cancel` | Admin roles: cancel a payment that is not paid |
665
+ | `sync(id, options?)` | `POST /payments/{id}/sync` | Admin roles: read a payment from its gateway again |
666
+
667
+ ```ts
668
+ // Save a card: confirm the client secret with the library of the gateway (Stripe.js)
669
+ const { nextAction } = await client.payments.setupPaymentMethod();
670
+ if (nextAction.type === 'confirm') {
671
+ const stripe = await loadStripe(nextAction.publicKey!);
672
+ await stripe!.confirmSetup({ elements, clientSecret: nextAction.clientSecret! });
673
+ }
674
+
675
+ const { subscription, nextAction: next } = await client.payments.subscribe({
676
+ plan: 'pro-monthly'
677
+ });
678
+ if (next.type === 'redirect') {
679
+ window.location.href = next.url!;
680
+ }
681
+ await client.payments.cancelSubscription(subscription.id);
682
+
683
+ const { url } = await client.payments.portal({ returnUrl: window.location.href });
684
+ ```
685
+
686
+ - The records are read with their resource clients, `find` and `query` only: `client.payment`,
687
+ `client.paymentMethod`, `client.paymentSubscription`, `client.paymentInvoice`, `client.paymentTransaction` and
688
+ `client.paymentPlan`. The operations answering with a record are typed by them (`PaymentSubscriptionSingle`).
689
+ - The types of the bodies and the answers are `Payments<Name>` (`PaymentsSubscribeRequest`, `PaymentsNextAction`).
690
+ - There is no operation creating a one-time payment: the application sets its amount in a route of its own, called
691
+ as a [custom request](#custom-request-generated).
692
+
594
693
  ### `HealthClient`
595
694
 
596
695
  | Method | HTTP | Description |
@@ -763,6 +862,10 @@ Sends a typed request and returns the parsed response body. Throws `ClientError`
763
862
  const data = await client.sendRequest('get', '/api/custom-endpoint');
764
863
  ```
765
864
 
865
+ `sendRequest` and `sendRequestRaw` are typed for the routes `paths` declares whole, the custom ones. The path of a
866
+ module or a resource route (`/api/posts/{id}`) is a type error, since `paths` keeps only its error codes: call its
867
+ module client instead (`client.post.find(1, options)`, or `client.post.raw.find(1)` for the raw response).
868
+
766
869
  ### `sendRequestRaw`
767
870
 
768
871
  Returns the raw `{ data, error, response }` tuple from `openapi-fetch` without throwing. Useful when the caller needs to
@@ -867,16 +970,11 @@ Every operation types its error responses per status, narrowing the `code` of `P
867
970
  documents, i.e. `code: 'RESOURCE_NOT_FOUND'` for the 404 of a find. The responses the operations share are declared
868
971
  once in `components['responses']` (i.e. `ResourceNotFoundError`) and referred to by every operation.
869
972
 
870
- Use `sendRequestRaw` to avoid exceptions and handle errors inline:
973
+ Use the [raw operations](#raw-responses-raw) of a resource, or `sendRequestRaw` for a custom route, to avoid
974
+ exceptions and handle errors inline:
871
975
 
872
976
  ```ts
873
- const { data, error, response } = await client.sendRequestRaw(
874
- 'get',
875
- '/api/posts/{id}',
876
- {
877
- params: { path: { id: 999 } }
878
- }
879
- );
977
+ const { data, error, response } = await client.post.raw.find(999);
880
978
 
881
979
  if (error?.code === 'RESOURCE_NOT_FOUND') {
882
980
  // handle not found
@@ -1070,29 +1070,94 @@ The messages are sent through the `sms` queue, see [sms](./sms.md).
1070
1070
  | `SMS_TWILIO_STATUS_URL` | string | `'https://status.twilio.com/api/v2/status.json'` | Status page of the Twilio platform read by the health check, down during a major or critical outage. |
1071
1071
  | `SMS_TWILIO_TIMEOUT` | duration | `10000` | Timeout of a request to the Twilio API, milliseconds or a duration string. |
1072
1072
 
1073
+ ### Payments (PAYMENTS\_\*)
1074
+
1075
+ The online payments of `@appweaver/payments`, see [payments](./payments.md): the gateways by their names, each an
1076
+ account at a payment provider reached by a driver (`stripe` of `@appweaver/stripe`), several usable at once. The name
1077
+ of a gateway is stored with every record it creates and ends the URL of its webhooks
1078
+ (`/payments/webhooks/<gateway>`), so it is never renamed once it took a payment.
1079
+
1080
+ | Property | Type | Default | Description |
1081
+ |----------------------------------|----------|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1082
+ | `PAYMENTS_GATEWAYS` | record | `{}` | The gateways by name, each with `driver` (default: the name of the gateway, so a gateway named `stripe` needs none), `secretKey`, `publicKey`, `webhookSecret`, `apiVersion`, `apiUrl`, `countries` (ISO 3166-1 alpha-2 codes whose payments the gateway takes), `currencies` (ISO 4217 codes it takes when no country selects a gateway), `timeout` and `maxRetries`. Each property is also its own variable, `PAYMENTS_GATEWAYS_<NAME>_<PROPERTY>` (`PAYMENTS_GATEWAYS_STRIPE_SECRET_KEY`). The `fake` gateway is built in, outside of production. |
1083
+ | `PAYMENTS_DEFAULT_GATEWAY` | string? | the only gateway | The gateway of a call naming none whose country and currency select none. Required with several gateways; without any, `fake` outside of production. |
1084
+ | `PAYMENTS_CURRENCY` | string | `'USD'` | The currency of a payment setting none, an ISO 4217 code. |
1085
+ | `PAYMENTS_CURRENCIES` | string[] | `[]` | The currencies a payment may be created in, empty for any. Another one fails with `PAYMENT_CURRENCY_UNSUPPORTED`. |
1086
+ | `PAYMENTS_SUCCESS_URL` | string? | `APP_HOSTNAME` | Where the user is sent once a hosted checkout is paid, with the `paymentId` and the `status` of the payment in its query. |
1087
+ | `PAYMENTS_CANCEL_URL` | string? | `PAYMENTS_SUCCESS_URL` | Where the user is sent when leaving a hosted checkout unpaid. |
1088
+ | `PAYMENTS_PENDING_TTL` | duration | `'1d'` | How long a payment may stay unpaid before the reconciliation cancels it, milliseconds or a duration string, `0` to keep it. |
1089
+ | `PAYMENTS_RECONCILE_AFTER` | duration | `'15m'` | The age from which a payment or a subscription in a state that is not final is read from its gateway again, catching the webhooks never received. `0` turns the reconciliation off. |
1090
+ | `PAYMENTS_EVENT_RETENTION` | duration | `'90d'` | How long the delivered events of the payments are kept, `0` to keep them. The failed ones are kept. |
1091
+ | `PAYMENTS_EVENT_MAX_ATTEMPTS` | integer | `5` | The attempts of delivering an event to the handlers of `onPaymentEvent`, before it is marked as failed. |
1092
+ | `PAYMENTS_TIMEOUT` | duration | `30000` | The timeout of a request to a gateway setting none, milliseconds or a duration string. |
1093
+ | `PAYMENTS_MAX_RETRIES` | integer | `2` | The retries of a request failing on the network or with a server error, of a gateway setting none. |
1094
+ | `PAYMENTS_QUEUE_CONCURRENCY` | integer | `4` | Jobs of the `payments` queue a worker runs at once. |
1095
+ | `PAYMENTS_HEALTH_CHECK_GATEWAYS` | string[] | `[]` | The gateways the `payments` health check checks, by a request with their credentials. |
1096
+
1097
+ #### Webhooks (PAYMENTS_WEBHOOKS\_\*)
1098
+
1099
+ | Property | Type | Default | Description |
1100
+ |-----------------------------------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------|
1101
+ | `PAYMENTS_WEBHOOKS_TOLERANCE` | duration | `'5m'` | How old the signature of a webhook may be, against the replay of a captured one, milliseconds or a duration string. |
1102
+ | `PAYMENTS_WEBHOOKS_BODY_MAX_SIZE` | size | `'1MB'` | The maximum size of the body of a webhook, bytes or a size string. |
1103
+ | `PAYMENTS_WEBHOOKS_REFETCH` | boolean | `true` | Read the object of an event from its gateway before applying it, so the events delivered out of order cannot move a record back. |
1104
+ | `PAYMENTS_WEBHOOKS_MAX_ATTEMPTS` | integer | `5` | The attempts of processing a received event, before it is marked as failed and waits for `weaver run payments-replay`. |
1105
+ | `PAYMENTS_WEBHOOKS_RETENTION` | duration | `'30d'` | How long the processed events are kept, `0` to keep them. The failed ones are kept. |
1106
+
1107
+ #### Routes (PAYMENTS_ROUTES\_\*)
1108
+
1109
+ | Property | Type | Default | Description |
1110
+ |-------------------------------|----------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1111
+ | `PAYMENTS_ROUTES_ENABLED` | boolean | `false` | Register the routes of the payments: the records of the user, saving a payment method, subscribing to a plan, the billing portal, and the capture, cancellation and refund of the admin roles. The webhook and return routes are registered without it. |
1112
+ | `PAYMENTS_ROUTES_ADMIN_ROLES` | string[] | `['Admin']` | The roles reading the payment records of every user, and capturing, canceling and refunding the payments. |
1113
+
1114
+ #### Subscriptions (PAYMENTS_SUBSCRIPTIONS\_\*)
1115
+
1116
+ | Property | Type | Default | Description |
1117
+ |---------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1118
+ | `PAYMENTS_SUBSCRIPTIONS_ENABLED` | boolean | `true` | Enable the recurring payments. `false` for one-time payments only: the `PaymentPlan`, `PaymentSubscription` and `PaymentInvoice` models get no tables, the `SubscriptionsService` fails with `PAYMENT_SUBSCRIPTIONS_DISABLED`, the routes of the subscriptions are not registered and the webhook events of the subscriptions and invoices are ignored. |
1119
+ | `PAYMENTS_SUBSCRIPTIONS_GRACE_PERIOD` | duration | `'3d'` | How long a subscription whose renewal failed still counts as active for `isActive`, while the gateway retries the payment. |
1120
+ | `PAYMENTS_SUBSCRIPTIONS_PRORATE` | boolean | `true` | Charge or credit the difference of a plan change for the rest of the period. |
1121
+
1122
+ #### Emails (PAYMENTS_EMAILS\_\*)
1123
+
1124
+ Sent to the customer of the payment with a mailer, from the templates and the translations of the module, each
1125
+ replaced by the one of the application with the same name.
1126
+
1127
+ | Property | Type | Default | Description |
1128
+ |-----------------------------------------|---------|---------|------------------------------------------------------------------------------------------------------------------------|
1129
+ | `PAYMENTS_EMAILS_ENABLED` | boolean | `true` | Send the emails of the payments. Nothing is sent without a mailer or an email address of the customer. |
1130
+ | `PAYMENTS_EMAILS_RECEIPT` | boolean | `true` | Send the receipt of a paid payment (`emails/payment-receipt`). |
1131
+ | `PAYMENTS_EMAILS_FAILED` | boolean | `true` | Tell the customer a payment failed (`emails/payment-failed`). |
1132
+ | `PAYMENTS_EMAILS_REFUNDED` | boolean | `true` | Confirm a refund (`emails/payment-refunded`). |
1133
+ | `PAYMENTS_EMAILS_ACTION_REQUIRED` | boolean | `true` | Ask the customer to confirm a renewal their bank holds, i.e. one needing 3D Secure (`emails/payment-action-required`). |
1134
+ | `PAYMENTS_EMAILS_SUBSCRIPTION_CANCELED` | boolean | `true` | Confirm a canceled subscription (`emails/subscription-canceled`). |
1135
+ | `PAYMENTS_EMAILS_TRIAL_ENDING` | boolean | `true` | Tell the customer the trial of a subscription ends soon (`emails/subscription-trial-ending`). |
1136
+
1073
1137
  ### Telemetry (TELEMETRY\_\*)
1074
1138
 
1075
1139
  The OpenTelemetry instrumentation of the framework, and the SDK of `@appweaver/opentelemetry` exporting it, see
1076
1140
  [telemetry](./telemetry.md). The keys of the first table belong to the framework, the others to the module.
1077
1141
 
1078
- | Property | Type | Default | Description |
1079
- |----------------------------------------|----------|---------|-------------------------------------------------------------------------------------------------------------------|
1080
- | `TELEMETRY_ENABLED` | boolean | `true` | Enable the instrumentation, the log correlation and the SDK. Nothing is recorded until an SDK is registered. |
1081
- | `TELEMETRY_LOG_CORRELATION` | boolean | `true` | Add the `trace_id`, `span_id` and `trace_flags` of the active span to every log record. |
1082
- | `TELEMETRY_INSTRUMENTATIONS_HTTP` | boolean | `true` | Trace and measure the requests of the HTTP server. |
1083
- | `TELEMETRY_INSTRUMENTATIONS_DATABASE` | boolean | `true` | Trace and measure the database operations. |
1084
- | `TELEMETRY_INSTRUMENTATIONS_QUEUE` | boolean | `true` | Trace and measure the queue jobs, carrying the trace from the sender to the worker. |
1085
- | `TELEMETRY_INSTRUMENTATIONS_SCHEDULER` | boolean | `true` | Trace and measure the runs of the scheduled jobs. |
1086
- | `TELEMETRY_INSTRUMENTATIONS_MAILER` | boolean | `true` | Trace the emails the mailer sends. |
1087
- | `TELEMETRY_INSTRUMENTATIONS_SMS` | boolean | `true` | Trace the text messages the SMS sender sends. |
1088
- | `TELEMETRY_INSTRUMENTATIONS_CACHE` | boolean | `true` | Count the cache hits and misses. |
1089
- | `TELEMETRY_INSTRUMENTATIONS_TASK` | boolean | `true` | Trace the tasks of `weaver run`. |
1090
- | `TELEMETRY_INSTRUMENTATIONS_REALTIME` | boolean | `true` | Trace the realtime actions and streams, and measure the realtime connections, events and streams. (realtime) |
1091
- | `TELEMETRY_INSTRUMENTATIONS_AI` | boolean | `true` | Trace and measure the calls of the AI models, their tokens and the tool calls. (ai) |
1092
- | `TELEMETRY_INSTRUMENTATIONS_MCP` | boolean | `true` | Trace and measure the calls of the MCP server. (mcp) |
1093
- | `TELEMETRY_INSTRUMENTATIONS_AUDIT` | boolean | `true` | Count the audit log entries written and dropped. (audit) |
1094
- | `TELEMETRY_HTTP_IGNORE_PATHS` | string[] | `[]` | URL paths left out of the traces and the metrics: an exact path, or a prefix ending with `*` (`/public/*`). (web) |
1095
- | `TELEMETRY_HTTP_HEALTH_CHECK` | boolean | `false` | Trace and measure the requests of the health check routes. (web) |
1142
+ | Property | Type | Default | Description |
1143
+ |----------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------|
1144
+ | `TELEMETRY_ENABLED` | boolean | `true` | Enable the instrumentation, the log correlation and the SDK. Nothing is recorded until an SDK is registered. |
1145
+ | `TELEMETRY_LOG_CORRELATION` | boolean | `true` | Add the `trace_id`, `span_id` and `trace_flags` of the active span to every log record. |
1146
+ | `TELEMETRY_INSTRUMENTATIONS_HTTP` | boolean | `true` | Trace and measure the requests of the HTTP server. |
1147
+ | `TELEMETRY_INSTRUMENTATIONS_DATABASE` | boolean | `true` | Trace and measure the database operations. |
1148
+ | `TELEMETRY_INSTRUMENTATIONS_QUEUE` | boolean | `true` | Trace and measure the queue jobs, carrying the trace from the sender to the worker. |
1149
+ | `TELEMETRY_INSTRUMENTATIONS_SCHEDULER` | boolean | `true` | Trace and measure the runs of the scheduled jobs. |
1150
+ | `TELEMETRY_INSTRUMENTATIONS_MAILER` | boolean | `true` | Trace the emails the mailer sends. |
1151
+ | `TELEMETRY_INSTRUMENTATIONS_SMS` | boolean | `true` | Trace the text messages the SMS sender sends. |
1152
+ | `TELEMETRY_INSTRUMENTATIONS_CACHE` | boolean | `true` | Count the cache hits and misses. |
1153
+ | `TELEMETRY_INSTRUMENTATIONS_TASK` | boolean | `true` | Trace the tasks of `weaver run`. |
1154
+ | `TELEMETRY_INSTRUMENTATIONS_REALTIME` | boolean | `true` | Trace the realtime actions and streams, and measure the realtime connections, events and streams. (realtime) |
1155
+ | `TELEMETRY_INSTRUMENTATIONS_AI` | boolean | `true` | Trace and measure the calls of the AI models, their tokens and the tool calls. (ai) |
1156
+ | `TELEMETRY_INSTRUMENTATIONS_MCP` | boolean | `true` | Trace and measure the calls of the MCP server. (mcp) |
1157
+ | `TELEMETRY_INSTRUMENTATIONS_AUDIT` | boolean | `true` | Count the audit log entries written and dropped. (audit) |
1158
+ | `TELEMETRY_INSTRUMENTATIONS_PAYMENTS` | boolean | `true` | Trace and measure the requests to the payment gateways, and count the webhook events and the events of the payments. (payments) |
1159
+ | `TELEMETRY_HTTP_IGNORE_PATHS` | string[] | `[]` | URL paths left out of the traces and the metrics: an exact path, or a prefix ending with `*` (`/public/*`). (web) |
1160
+ | `TELEMETRY_HTTP_HEALTH_CHECK` | boolean | `false` | Trace and measure the requests of the health check routes. (web) |
1096
1161
 
1097
1162
  With `@appweaver/opentelemetry`:
1098
1163
 
@@ -207,6 +207,8 @@ weaver migrate # Prisma migration
207
207
  checksum with `weaver migrate --fix-checksums`.
208
208
  - `weaver test setup`, `weaver test reset` and `weaver migration reset` apply them after the reset, so the tests run
209
209
  with them. They connect with the Prisma client of the build, so build before migrating, like the database setup.
210
+ `weaver migration reset` skips them while the project has no Prisma migration, since the Prisma migrations create
211
+ the tables they need: run `weaver migrate` after the first `weaver migration new`.
210
212
  - A module ships its own in the `sql` directory of its manifest (`path.join(__dirname, 'sql')`), applied before the
211
213
  application's, recorded under the module name (`billing/20261201_plans`).
212
214
  - Prisma does not know these objects: `weaver migration new` and `weaver migration check` fail when the next Prisma
@@ -216,6 +218,8 @@ weaver migrate # Prisma migration
216
218
  warns, so the migration can be created, then a SQL migration creating the lost objects again
217
219
  (`CREATE INDEX IF NOT EXISTS`), applied after it by `weaver migrate`; the repeatable `indexes/generated.sql` is
218
220
  applied again only once it changes.
221
+ - The generated columns of `columns/generated.sql` are the exception, since Prisma sees a column: `weaver migration
222
+ new` records them in a Prisma migration of their own first ([resources.md](./resources.md#generated-columns)).
219
223
  - `weaver generate` writes the repeatable `columns/generated.sql` and `indexes/generated.sql` from the generated
220
224
  columns and the expression indexes of the models ([resources.md](./resources.md#generated-columns)); leave them to it.
221
225
  - A Docker image copies `database/sql` beside `database/migrations`.
@@ -104,7 +104,7 @@ const apiUrl = inject<string>('ApiBaseUrl');
104
104
 
105
105
  A string token ending with `Model`, `Service`, `Routes`, or `Policy` (e.g. `'PostService'`) also resolves the resource
106
106
  definition of that model, but only when no definition was registered under that exact name, so a value defined as
107
- `'PaymentService'` is always injectable by that name.
107
+ `'ShippingService'` is always injectable by that name.
108
108
 
109
109
  **Inject by symbol token:**
110
110