@stacksjs/defaults 0.75.543 → 0.75.548
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/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-auto-imports/SKILL.md +1 -1
- package/ai/skills/stacks-commerce/SKILL.md +6 -3
- package/ai/skills/stacks-database/SKILL.md +1 -1
- package/ai/skills/stacks-deploy/SKILL.md +7 -0
- package/ai/skills/stacks-desktop/SKILL.md +188 -3
- package/ai/skills/stacks-licensing/SKILL.md +214 -0
- package/ai/skills/stacks-migrations/SKILL.md +2 -2
- package/ai/skills/stacks-models/SKILL.md +2 -2
- package/ai/skills/stacks-native/CATALOG.md +6 -6
- package/ai/skills/stacks-orm/SKILL.md +2 -2
- package/ai/skills/stacks-payments/SKILL.md +1 -0
- package/ai/skills/stacks-writing-for-agents/SKILL.md +1 -1
- package/app/Actions/Commerce/Licensing/LicenseActivateAction.ts +36 -0
- package/app/Actions/Commerce/Licensing/LicenseCheckAction.ts +31 -0
- package/app/Actions/Commerce/Licensing/LicenseDeactivateAction.ts +20 -0
- package/app/Actions/Commerce/Licensing/LicenseResendAction.ts +47 -0
- package/app/Actions/Commerce/Licensing/LicenseSeatDestroyAction.ts +25 -0
- package/app/Actions/Commerce/Licensing/LicenseSeatIndexAction.ts +20 -0
- package/app/Actions/Commerce/Licensing/LicenseSeatStoreAction.ts +28 -0
- package/app/Actions/Commerce/Licensing/LicenseTransferAction.ts +32 -0
- package/app/Actions/Commerce/Licensing/license-response.ts +34 -0
- package/app/Actions/Commerce/Licensing/license-seat-access.ts +31 -0
- package/app/Actions/Desktop/UpdateFeedAction.ts +35 -0
- package/app/Mail/LicenseEmail.ts +80 -0
- package/app/Models/commerce/LicenseActivation.ts +98 -0
- package/app/Models/commerce/LicenseKey.ts +149 -7
- package/app/Models/commerce/LicenseSeat.ts +56 -0
- package/bootstrap.ts +35 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +3 -3
- package/resources/emails/license.stx +52 -0
- package/routes/desktop-updates.ts +11 -0
- package/routes/licensing.ts +35 -0
- package/routes/payments.ts +9 -1
|
@@ -39,7 +39,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
39
39
|
| `@stacksjs/datetime` | [`stacks-datetime`](../stacks-datetime/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/datetime/src/index.ts) | 22 |
|
|
40
40
|
| `@stacksjs/defaults` | [`stacks-build`](../stacks-build/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/defaults/package.json) | 3 |
|
|
41
41
|
| `@stacksjs/deploy` | [`stacks-deploy`](../stacks-deploy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/deploy/package.json) | 1 |
|
|
42
|
-
| `@stacksjs/desktop-build` | [`stacks-desktop`](../stacks-desktop/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/index.ts) |
|
|
42
|
+
| `@stacksjs/desktop-build` | [`stacks-desktop`](../stacks-desktop/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/index.ts) | 19 |
|
|
43
43
|
| `@stacksjs/development` | [`stacks-development`](../stacks-development/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/development/package.json) | 1 |
|
|
44
44
|
| `@stacksjs/dns` | [`stacks-dns`](../stacks-dns/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/dns/src/index.ts) | 4 |
|
|
45
45
|
| `@stacksjs/docs` | [`stacks-docs`](../stacks-docs/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/docs/src/index.ts) | 3 |
|
|
@@ -314,9 +314,9 @@ Evidence directory: [2 retained tests](https://github.com/stacksjs/stacks/blob/m
|
|
|
314
314
|
|
|
315
315
|
Guidance: [`stacks-commerce`](../stacks-commerce/SKILL.md). Source: [storage/framework/core/commerce/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/index.ts).
|
|
316
316
|
|
|
317
|
-
Declared runtime exports: `PriceFormatError`, `auctions`, `breakdownFor`, `carts`, `catalog`, `catalogImport`, `commerce`, `coupons`, `currencyExponent`, `customers`, `decimalToMinor`, `default`, `devices`, `errors`, `formatCurrency`, `formatMinor`, `giftCards`, `minorToDecimal`, `minorToInput`, `minorToMajor`, `money`, `moneyInputError`, `moneyInputStep`, `multiplierOf`, `orders`, `parseMoneyInput`, `parseSalesTaxSetup`, `parseTaxRateWriteData`, `payments`, `products`, `receiptLinesText`, `receipts`, `register`, `releases`, `restaurant`, `restockedQuantity`, `shippings`, `tax`, `waitlists`.
|
|
317
|
+
Declared runtime exports: `PriceFormatError`, `auctions`, `breakdownFor`, `carts`, `catalog`, `catalogImport`, `commerce`, `coupons`, `currencyExponent`, `customers`, `decimalToMinor`, `default`, `devices`, `errors`, `formatCurrency`, `formatMinor`, `giftCards`, `licensing`, `minorToDecimal`, `minorToInput`, `minorToMajor`, `money`, `moneyInputError`, `moneyInputStep`, `multiplierOf`, `orders`, `parseMoneyInput`, `parseSalesTaxSetup`, `parseTaxRateWriteData`, `payments`, `products`, `receiptLinesText`, `receipts`, `register`, `releases`, `restaurant`, `restockedQuantity`, `shippings`, `tax`, `waitlists`.
|
|
318
318
|
|
|
319
|
-
Local source modules: [src/auctions/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/auctions/index.ts), [src/carts/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/carts/index.ts), [src/catalog.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/catalog.ts), [src/coupons/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/coupons/index.ts), [src/customers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/customers/index.ts), [src/devices/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/devices/index.ts), [src/errors/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/errors/index.ts), [src/gift-cards/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/gift-cards/index.ts), [src/imports/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/imports/index.ts), [src/inventory.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/inventory.ts), [src/money.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/money.ts), [src/orders/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/orders/index.ts), [src/payments/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/payments/index.ts), [src/products/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/products/index.ts), [src/receipt-text.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/receipt-text.ts), [src/receipts/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/receipts/index.ts), [src/register.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/register.ts), [src/releases.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/releases.ts), [src/sales-tax.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/sales-tax.ts), [src/shippings/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/shippings/index.ts), [src/tax-input.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/tax-input.ts), [src/tax/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/tax/index.ts), [src/waitlists/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/waitlists/index.ts), [src/waitlists/restaurant/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/waitlists/restaurant/index.ts).
|
|
319
|
+
Local source modules: [src/auctions/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/auctions/index.ts), [src/carts/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/carts/index.ts), [src/catalog.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/catalog.ts), [src/coupons/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/coupons/index.ts), [src/customers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/customers/index.ts), [src/devices/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/devices/index.ts), [src/errors/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/errors/index.ts), [src/gift-cards/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/gift-cards/index.ts), [src/imports/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/imports/index.ts), [src/inventory.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/inventory.ts), [src/licensing/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/licensing/index.ts), [src/money.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/money.ts), [src/orders/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/orders/index.ts), [src/payments/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/payments/index.ts), [src/products/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/products/index.ts), [src/receipt-text.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/receipt-text.ts), [src/receipts/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/receipts/index.ts), [src/register.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/register.ts), [src/releases.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/releases.ts), [src/sales-tax.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/sales-tax.ts), [src/shippings/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/shippings/index.ts), [src/tax-input.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/tax-input.ts), [src/tax/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/tax/index.ts), [src/waitlists/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/waitlists/index.ts), [src/waitlists/restaurant/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/waitlists/restaurant/index.ts).
|
|
320
320
|
|
|
321
321
|
Evidence directory: [15 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
322
322
|
|
|
@@ -392,9 +392,9 @@ Guidance: [`stacks-desktop`](../stacks-desktop/SKILL.md). Source: [storage/frame
|
|
|
392
392
|
|
|
393
393
|
Declared runtime exports: `BUN_EXECUTABLE_MARKER`, `RESERVED_PLIST_KEYS`, `USERLAND_LAUNCHER`, `bundleDirectoryFor`, `codesignArgs`, `craftDevCommand`, `createUpdateManifestUrl`, `describeRuntimeDuplication`, `desktopAppVersion`, `desktopLauncherCompileArgs`, `developerIdProblem`, `dmgVolumeName`, `hasUserlandDesktopLauncher`, `isMachO`, `looksLikeBunExecutable`, `notarizationOutcome`, `notarytoolAuthArgs`, `openDevWindow`, `plistValue`, `renderInfoPlist`, `renderUserlandPlistEntries`, `resolveCraftBinary`, `resolveCraftExecutable`, `resolveDesktopLauncher`, `resolveDevWindowUrl`, `resolveDmgPackaging`, `xmlEscape`.
|
|
394
394
|
|
|
395
|
-
Local source modules: [src/agent-launcher.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/agent-launcher.ts), [src/agent.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/agent.ts), [src/invites.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/invites.ts), [src/macos-app.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/macos-app.ts), [src/macos-bundle.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/macos-bundle.ts), [src/support.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/support.ts), [src/updater.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/updater.ts).
|
|
395
|
+
Local source modules: [src/agent-launcher.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/agent-launcher.ts), [src/agent.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/agent.ts), [src/invites.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/invites.ts), [src/macos-app.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/macos-app.ts), [src/macos-bundle.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/macos-bundle.ts), [src/support.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/support.ts), [src/update-feed.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/update-feed.ts), [src/update-install.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/update-install.ts), [src/update-signing.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/update-signing.ts), [src/updater.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/updater.ts), [src/webview-agent.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/webview-agent.ts), [src/webview-app.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/webview-app.ts), [src/webview-launcher.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/webview-launcher.ts).
|
|
396
396
|
|
|
397
|
-
Evidence directory: [
|
|
397
|
+
Evidence directory: [19 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
398
398
|
|
|
399
399
|
### @stacksjs/development
|
|
400
400
|
|
|
@@ -648,7 +648,7 @@ Evidence directory: [10 retained tests](https://github.com/stacksjs/stacks/blob/
|
|
|
648
648
|
|
|
649
649
|
Guidance: [`stacks-orm`](../stacks-orm/SKILL.md). Source: [storage/framework/core/orm/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/index.ts).
|
|
650
650
|
|
|
651
|
-
Declared runtime exports: `Activity`, `AnalyticsEvent`, `Auction`, `AuctionItem`, `Author`, `Automation`, `AutomationRun`, `BILLABLE_INSTANCE_METHODS`, `Bid`, `Board`, `BoardColumn`, `Campaign`, `CampaignSend`, `CampaignVariant`, `Card`, `CardAttachment`, `CardComment`, `Cart`, `CartItem`, `Categorizable`, `Category`, `Comment`, `CommunicationSuppression`, `ConsentEvent`, `Coupon`, `Courier`, `CourierPing`, `Customer`, `DeliveryRoute`, `DeliveryStop`, `Deployment`, `DigitalDelivery`, `EmailIdempotency`, `EmailList`, `EmailListSubscriber`, `EmailSuppression`, `EmailWebhookEvent`, `ErrorModel`, `FailedJob`, `FeedbackToken`, `Form`, `FormField`, `FormSubmission`, `GdprRequest`, `GiftCard`, `Job`, `Label`, `LicenseKey`, `Log`, `LoyaltyPoint`, `LoyaltyReward`, `MagicLinkToken`, `MailPreference`, `Manufacturer`, `Menu`, `MenuItem`, `ModelUnavailableError`, `Notification`, `NotificationDelivery`, `Order`, `OrderIdempotency`, `OrderItem`, `Page`, `PageRevision`, `Payment`, `PaymentMethod`, `PaymentProduct`, `PaymentTransaction`, `PaymentWebhookEvent`, `PersonalAccessToken`, `Pledge`, `Post`, `PrintDevice`, `Product`, `ProductUnit`, `ProductVariant`, `QueryLog`, `QueueWorker`, `Receipt`, `Redirect`, `Referral`, `ReferralCode`, `Release`, `Request`, `Review`, `SenderDomain`, `ShippingMethod`, `ShippingRate`, `ShippingZone`, `Site`, `SiteDomain`, `SmsOptOut`, `SocialAccount`, `SocialPost`, `StorageItem`, `StorageItemTask`, `Subscriber`, `SubscriberEmail`, `Subscription`, `SubscriptionNotOwnedError`, `Tag`, `TaxRate`, `Team`, `TeamInvitation`, `TeamMember`, `Transaction`, `UsageEvent`, `User`, `WaitlistProduct`, `WaitlistRestaurant`, `Websocket`, `buildDatabaseSchema`, `collectEncryptedAttributes`, `createAuditMethods`, `createCategorizableMethods`, `createCommentableMethods`, `createLikeableMethods`, `createTaggableMethods`, `customerOwnership`, `decryptValue`, `encryptValue`, `enrichPaginatorUrls`, `filterFillable`, `frameworkModelFeature`, `getWritableFields`, `isBillable`, `isCursorPaginator`, `isEncrypted`, `isPaginator`, `isSimplePaginator`, `isUniqueViolation`, `mapWriteError`, `modelGlobalNames`, `ormReady`, `parentOwnership`, `parseCursor`, `renderDatabaseTypeFile`, `resolveCursorArgs`, `resolvePageArgs`, `selfOwnership`, `setAuditUser`, `siteOwnership`, `teamMembershipOwnership`, `toCursorPaginator`, `toPaginator`, `toSimplePaginator`, `toSnakeCaseKeys`.
|
|
651
|
+
Declared runtime exports: `Activity`, `AnalyticsEvent`, `Auction`, `AuctionItem`, `Author`, `Automation`, `AutomationRun`, `BILLABLE_INSTANCE_METHODS`, `Bid`, `Board`, `BoardColumn`, `Campaign`, `CampaignSend`, `CampaignVariant`, `Card`, `CardAttachment`, `CardComment`, `Cart`, `CartItem`, `Categorizable`, `Category`, `Comment`, `CommunicationSuppression`, `ConsentEvent`, `Coupon`, `Courier`, `CourierPing`, `Customer`, `DeliveryRoute`, `DeliveryStop`, `Deployment`, `DigitalDelivery`, `EmailIdempotency`, `EmailList`, `EmailListSubscriber`, `EmailSuppression`, `EmailWebhookEvent`, `ErrorModel`, `FailedJob`, `FeedbackToken`, `Form`, `FormField`, `FormSubmission`, `GdprRequest`, `GiftCard`, `Job`, `Label`, `LicenseActivation`, `LicenseKey`, `LicenseSeat`, `Log`, `LoyaltyPoint`, `LoyaltyReward`, `MagicLinkToken`, `MailPreference`, `Manufacturer`, `Menu`, `MenuItem`, `ModelUnavailableError`, `Notification`, `NotificationDelivery`, `Order`, `OrderIdempotency`, `OrderItem`, `Page`, `PageRevision`, `Payment`, `PaymentMethod`, `PaymentProduct`, `PaymentTransaction`, `PaymentWebhookEvent`, `PersonalAccessToken`, `Pledge`, `Post`, `PrintDevice`, `Product`, `ProductUnit`, `ProductVariant`, `QueryLog`, `QueueWorker`, `Receipt`, `Redirect`, `Referral`, `ReferralCode`, `Release`, `Request`, `Review`, `SenderDomain`, `ShippingMethod`, `ShippingRate`, `ShippingZone`, `Site`, `SiteDomain`, `SmsOptOut`, `SocialAccount`, `SocialPost`, `StorageItem`, `StorageItemTask`, `Subscriber`, `SubscriberEmail`, `Subscription`, `SubscriptionNotOwnedError`, `Tag`, `TaxRate`, `Team`, `TeamInvitation`, `TeamMember`, `Transaction`, `UsageEvent`, `User`, `WaitlistProduct`, `WaitlistRestaurant`, `Websocket`, `buildDatabaseSchema`, `collectEncryptedAttributes`, `createAuditMethods`, `createCategorizableMethods`, `createCommentableMethods`, `createLikeableMethods`, `createTaggableMethods`, `customerOwnership`, `decryptValue`, `encryptValue`, `enrichPaginatorUrls`, `filterFillable`, `frameworkModelFeature`, `getWritableFields`, `isBillable`, `isCursorPaginator`, `isEncrypted`, `isPaginator`, `isSimplePaginator`, `isUniqueViolation`, `mapWriteError`, `modelGlobalNames`, `ormReady`, `parentOwnership`, `parseCursor`, `renderDatabaseTypeFile`, `resolveCursorArgs`, `resolvePageArgs`, `selfOwnership`, `setAuditUser`, `siteOwnership`, `teamMembershipOwnership`, `toCursorPaginator`, `toPaginator`, `toSimplePaginator`, `toSnakeCaseKeys`.
|
|
652
652
|
|
|
653
653
|
Local source modules: [src/auto-crud.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/auto-crud.ts), [src/batch-loader.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/batch-loader.ts), [src/db.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/db.ts), [src/define-model.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/define-model.ts), [src/extend-model.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/extend-model.ts), [src/gdpr/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/gdpr/index.ts), [src/generate-database-schema.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/generate-database-schema.ts), [src/locked-row.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/locked-row.ts), [src/messaging.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/messaging.ts), [src/model-types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/model-types.ts), [src/ownership.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/ownership.ts), [src/paginator-request.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/paginator-request.ts), [src/row-token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/row-token.ts), [src/subquery.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/subquery.ts), [src/traits/audit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/audit.ts), [src/traits/billable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/billable.ts), [src/traits/categorizable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/categorizable.ts), [src/traits/commentable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/commentable.ts), [src/traits/likeable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/likeable.ts), [src/traits/taggable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/taggable.ts), [src/transaction.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/transaction.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/types.ts), [src/utils/encrypted.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/utils/encrypted.ts), [src/utils/prunable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/utils/prunable.ts).
|
|
654
654
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-orm
|
|
3
|
-
description: Use when querying or writing Stacks models, using transactions and relationships, preserving inferred model types, or enabling native model traits. Covers @stacksjs/orm, the model runtime, and
|
|
3
|
+
description: Use when querying or writing Stacks models, using transactions and relationships, preserving inferred model types, or enabling native model traits. Covers @stacksjs/orm, the model runtime, and 110 built-in models.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -10,7 +10,7 @@ allowed-tools: Read Edit Write Bash Grep Glob
|
|
|
10
10
|
|
|
11
11
|
`defineModel` produces an immediately usable query surface over
|
|
12
12
|
`bun-query-builder`. Model-driven migrations change the schema; there are no
|
|
13
|
-
per-model ORM classes to generate. The framework declares
|
|
13
|
+
per-model ORM classes to generate. The framework declares 110 models on disk,
|
|
14
14
|
but optional feature gates determine which built-ins load in a running app.
|
|
15
15
|
|
|
16
16
|
## Definitions and typed rows
|
|
@@ -35,6 +35,7 @@ Nothing throws at import, by design, so an app missing the SDK starts clean and
|
|
|
35
35
|
- The Stripe driver delegates to the existing billable modules, so idempotency keys and `stripe_id` handling are unchanged.
|
|
36
36
|
- Webhook route: the `payments` default route bundle (mounted with the `commerce` feature) serves `POST /webhooks/payments` through `orders.receivePaymentWebhook(request)`: 401 `missing-config` while the driver's secret is unset (`WebhookNotConfiguredError`), 400 `invalid-signature` (`WebhookSignatureError`), otherwise applies the events and answers with `acknowledgeWebhook()`.
|
|
37
37
|
- Commerce: `orders.handleCommercePaymentEvent(event)` from `@stacksjs/commerce` applies `payment.succeeded` / `payment.failed` (reason into `payments.failure_reason`) / `refund.succeeded` (added to `refund_amount`; `refunded` + order REFUNDED only when it covers the payment, else `partiallyRefunded`) to the order, deduplicated in `payment_webhook_events` (the `PaymentWebhookEvent` model) in the same transaction.
|
|
38
|
+
- Licensing: the same webhook calls `licensing.handleLicensePaymentEvent(event)`. A checkout whose `reference` is `licensing.licensePurchaseReference({ tier })` is issued a license once when it is paid, on any driver, and a refund of that payment revokes it. See `stacks-licensing`.
|
|
38
39
|
- The Payment facade's neutral functions go through this driver; its Stripe-only functions and everything Stripe-level below return Stripe objects.
|
|
39
40
|
|
|
40
41
|
## Key Paths
|
|
@@ -13,7 +13,7 @@ project `AGENTS.md`, a doc reached by a pointer. The packaging differs, the
|
|
|
13
13
|
writing does not. The same levers make each one predictable, because the agent
|
|
14
14
|
takes the same *process* every run rather than producing the same output.
|
|
15
15
|
|
|
16
|
-
Stacks ships
|
|
16
|
+
Stacks ships 211 skills and expects projects to add their own under
|
|
17
17
|
`app/Skills/`, so this is the skill that keeps that set from turning to sludge.
|
|
18
18
|
The Stacks-specific mechanics (frontmatter, invocation, the override model,
|
|
19
19
|
what `buddy setup:ai` does with the result) are in
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { licensing } from '@stacksjs/commerce'
|
|
4
|
+
import { response } from '@stacksjs/router'
|
|
5
|
+
import { answer, refusal } from './license-response'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Activate a license key on a device.
|
|
9
|
+
*
|
|
10
|
+
* The key is the credential: whoever holds it may use one of its device
|
|
11
|
+
* slots. The device is named only by the SHA-256 of an id the app chose.
|
|
12
|
+
* Answers the signed token the app keeps for offline use, or, beyond the
|
|
13
|
+
* device limit, a 409 naming the devices holding the slots.
|
|
14
|
+
*/
|
|
15
|
+
export default new Action({
|
|
16
|
+
name: 'License Activate',
|
|
17
|
+
description: 'Activate a license key on a device and answer its signed offline token.',
|
|
18
|
+
method: 'POST',
|
|
19
|
+
apiResponse: true,
|
|
20
|
+
|
|
21
|
+
async handle(request: RequestInstance) {
|
|
22
|
+
return answer(async () => {
|
|
23
|
+
const result = await licensing.activateLicense({
|
|
24
|
+
key: request.get('key'),
|
|
25
|
+
deviceHash: request.get('deviceHash'),
|
|
26
|
+
deviceName: request.get('deviceName'),
|
|
27
|
+
platform: request.get('platform'),
|
|
28
|
+
appVersion: request.get('appVersion'),
|
|
29
|
+
email: request.get('email'),
|
|
30
|
+
})
|
|
31
|
+
if (!result.ok)
|
|
32
|
+
return refusal(result.reason, result.message, result.devices ? { devices: result.devices } : {})
|
|
33
|
+
return response.json({ ok: true, valid: true, key: result.key, token: result.token, license: result.license })
|
|
34
|
+
})
|
|
35
|
+
},
|
|
36
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { licensing } from '@stacksjs/commerce'
|
|
4
|
+
import { response } from '@stacksjs/router'
|
|
5
|
+
import { answer } from './license-response'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Where a license stands for a device, with a fresh token when it is good.
|
|
9
|
+
*
|
|
10
|
+
* Always a 200 when the question could be answered: `valid: false` with a
|
|
11
|
+
* reason (`revoked`, `refunded`, `expired`, `released`, `not-found`) is an
|
|
12
|
+
* answer, and a client drops its stored token on it. Only a 5xx means "ask
|
|
13
|
+
* again later", which is why a refusal is not an error status here.
|
|
14
|
+
*/
|
|
15
|
+
export default new Action({
|
|
16
|
+
name: 'License Check',
|
|
17
|
+
description: 'Answer a license\'s standing for a device, with a fresh signed token.',
|
|
18
|
+
method: 'POST',
|
|
19
|
+
apiResponse: true,
|
|
20
|
+
|
|
21
|
+
async handle(request: RequestInstance) {
|
|
22
|
+
return answer(async () => {
|
|
23
|
+
const result = await licensing.checkLicense({
|
|
24
|
+
key: request.get('key'),
|
|
25
|
+
deviceHash: request.get('deviceHash'),
|
|
26
|
+
appVersion: request.get('appVersion'),
|
|
27
|
+
})
|
|
28
|
+
return response.json({ ok: true, ...result })
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { licensing } from '@stacksjs/commerce'
|
|
4
|
+
import { response } from '@stacksjs/router'
|
|
5
|
+
import { refusal } from './license-response'
|
|
6
|
+
|
|
7
|
+
/** Release a device's slot on a license, so another device can take it. */
|
|
8
|
+
export default new Action({
|
|
9
|
+
name: 'License Deactivate',
|
|
10
|
+
description: 'Release a device from a license key.',
|
|
11
|
+
method: 'POST',
|
|
12
|
+
apiResponse: true,
|
|
13
|
+
|
|
14
|
+
async handle(request: RequestInstance) {
|
|
15
|
+
const result = await licensing.deactivateLicense({ key: request.get('key'), deviceHash: request.get('deviceHash') })
|
|
16
|
+
if (!result.ok)
|
|
17
|
+
return refusal('not-found', 'That license key was not found.')
|
|
18
|
+
return response.json({ ok: true, released: result.released })
|
|
19
|
+
},
|
|
20
|
+
})
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { licensing } from '@stacksjs/commerce'
|
|
4
|
+
import { rateLimit, response } from '@stacksjs/router'
|
|
5
|
+
import { sendLicenseKeys } from '../../../Mail/LicenseEmail'
|
|
6
|
+
|
|
7
|
+
/** Take a slot in a resend bucket; false once it is full. */
|
|
8
|
+
async function allow(bucket: 'ip' | 'email', identity?: string): Promise<boolean> {
|
|
9
|
+
const limit = licensing.RESEND_LIMITS[bucket]
|
|
10
|
+
try {
|
|
11
|
+
// No identity for the IP bucket: the limiter reads the client address itself.
|
|
12
|
+
await rateLimit(`license-resend-${bucket}`, limit.max, bucket === 'email' ? { identity: `email:${identity}` } : {}).over(limit.windowSeconds)
|
|
13
|
+
return true
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if ((error as { status?: number, statusCode?: number })?.status === 429 || (error as { statusCode?: number })?.statusCode === 429)
|
|
17
|
+
return false
|
|
18
|
+
throw error
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* "Email me my license key again."
|
|
24
|
+
*
|
|
25
|
+
* The answer is the same whether or not the address bought anything, and is
|
|
26
|
+
* given before the lookup runs, so neither the body nor the timing says which.
|
|
27
|
+
* Keys only ever go to the address on the license.
|
|
28
|
+
*/
|
|
29
|
+
export default new Action({
|
|
30
|
+
name: 'License Resend',
|
|
31
|
+
description: 'Send the license keys bought with an address to that address again.',
|
|
32
|
+
method: 'POST',
|
|
33
|
+
apiResponse: true,
|
|
34
|
+
|
|
35
|
+
async handle(request: RequestInstance) {
|
|
36
|
+
const { outcome } = await licensing.requestLicenseResend(request.get('email'), {
|
|
37
|
+
allow,
|
|
38
|
+
active: email => licensing.activeLicensesFor(email),
|
|
39
|
+
send: licenses => sendLicenseKeys(licenses),
|
|
40
|
+
})
|
|
41
|
+
if (outcome === 'invalid')
|
|
42
|
+
return response.json({ ok: false, reason: 'invalid-email', message: 'Enter the email address you bought with.' }, 422)
|
|
43
|
+
if (outcome === 'limited')
|
|
44
|
+
return response.json({ ok: false, reason: 'limited', message: 'Too many requests. Try again in an hour.' }, 429)
|
|
45
|
+
return response.json({ ok: true, message: 'If that address has a license, its key is on the way.' })
|
|
46
|
+
},
|
|
47
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { licensing } from '@stacksjs/commerce'
|
|
4
|
+
import { response } from '@stacksjs/router'
|
|
5
|
+
import { seatLicense } from './license-seat-access'
|
|
6
|
+
|
|
7
|
+
/** Take a member's seat back, releasing the devices activated under it. */
|
|
8
|
+
export default new Action({
|
|
9
|
+
name: 'License Seat Destroy',
|
|
10
|
+
description: 'Remove a member\'s seat on a team license.',
|
|
11
|
+
method: 'DELETE',
|
|
12
|
+
apiResponse: true,
|
|
13
|
+
|
|
14
|
+
async handle(request: RequestInstance) {
|
|
15
|
+
const access = await seatLicense(request)
|
|
16
|
+
if (access.error)
|
|
17
|
+
return access.error
|
|
18
|
+
const userId = Number(request.get('userId'))
|
|
19
|
+
if (!Number.isSafeInteger(userId) || userId < 1)
|
|
20
|
+
return response.json({ ok: false, reason: 'invalid-user', message: 'userId must be a team member\'s user id.' }, 422)
|
|
21
|
+
|
|
22
|
+
const result = await licensing.unassignLicenseSeat({ key: access.license.key, userId })
|
|
23
|
+
return response.json({ ok: true, removed: result.removed })
|
|
24
|
+
},
|
|
25
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { licensing } from '@stacksjs/commerce'
|
|
4
|
+
import { response } from '@stacksjs/router'
|
|
5
|
+
import { seatLicense } from './license-seat-access'
|
|
6
|
+
|
|
7
|
+
/** Who holds a seat on a team license, for the team's owner or admin. */
|
|
8
|
+
export default new Action({
|
|
9
|
+
name: 'License Seat Index',
|
|
10
|
+
description: 'List the seats assigned on a team license.',
|
|
11
|
+
method: 'GET',
|
|
12
|
+
apiResponse: true,
|
|
13
|
+
|
|
14
|
+
async handle(request: RequestInstance) {
|
|
15
|
+
const access = await seatLicense(request)
|
|
16
|
+
if (access.error)
|
|
17
|
+
return access.error
|
|
18
|
+
return response.json({ ok: true, seats: access.license.seats, assigned: await licensing.licenseSeats(access.license.key) })
|
|
19
|
+
},
|
|
20
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { licensing } from '@stacksjs/commerce'
|
|
4
|
+
import { response } from '@stacksjs/router'
|
|
5
|
+
import { refusal } from './license-response'
|
|
6
|
+
import { seatLicense } from './license-seat-access'
|
|
7
|
+
|
|
8
|
+
/** Give a member of the license's team a seat. */
|
|
9
|
+
export default new Action({
|
|
10
|
+
name: 'License Seat Store',
|
|
11
|
+
description: 'Assign a team license seat to a member of its team.',
|
|
12
|
+
method: 'POST',
|
|
13
|
+
apiResponse: true,
|
|
14
|
+
|
|
15
|
+
async handle(request: RequestInstance) {
|
|
16
|
+
const access = await seatLicense(request)
|
|
17
|
+
if (access.error)
|
|
18
|
+
return access.error
|
|
19
|
+
const userId = Number(request.get('userId'))
|
|
20
|
+
if (!Number.isSafeInteger(userId) || userId < 1)
|
|
21
|
+
return response.json({ ok: false, reason: 'invalid-user', message: 'userId must be a team member\'s user id.' }, 422)
|
|
22
|
+
|
|
23
|
+
const result = await licensing.assignLicenseSeat({ key: access.license.key, userId })
|
|
24
|
+
if (!result.ok)
|
|
25
|
+
return refusal(result.reason, result.message)
|
|
26
|
+
return response.json({ ok: true, seat: result.seat })
|
|
27
|
+
},
|
|
28
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { licensing } from '@stacksjs/commerce'
|
|
4
|
+
import { response } from '@stacksjs/router'
|
|
5
|
+
import { refusal } from './license-response'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hand a license to another person.
|
|
9
|
+
*
|
|
10
|
+
* The caller names the key and the address it is registered to. Every device
|
|
11
|
+
* is released and the key is emailed to the new owner.
|
|
12
|
+
*/
|
|
13
|
+
export default new Action({
|
|
14
|
+
name: 'License Transfer',
|
|
15
|
+
description: 'Transfer a license key to a new owner\'s email address.',
|
|
16
|
+
method: 'POST',
|
|
17
|
+
apiResponse: true,
|
|
18
|
+
|
|
19
|
+
async handle(request: RequestInstance) {
|
|
20
|
+
const result = await licensing.transferLicense({
|
|
21
|
+
key: request.get('key'),
|
|
22
|
+
fromEmail: request.get('email'),
|
|
23
|
+
toEmail: request.get('toEmail'),
|
|
24
|
+
})
|
|
25
|
+
if (!result.ok) {
|
|
26
|
+
// "No such key" and "not yours" are one answer, so a key cannot be probed for its owner.
|
|
27
|
+
const reason = result.reason === 'not-owner' ? 'not-found' : result.reason
|
|
28
|
+
return refusal(reason, result.message)
|
|
29
|
+
}
|
|
30
|
+
return response.json({ ok: true, email: result.license.email })
|
|
31
|
+
},
|
|
32
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ResponseStatus } from '@stacksjs/bun-router'
|
|
2
|
+
import { licensing } from '@stacksjs/commerce'
|
|
3
|
+
import { response } from '@stacksjs/router'
|
|
4
|
+
|
|
5
|
+
/** The HTTP status each refusal answers with. Anything unlisted is a 403. */
|
|
6
|
+
const STATUSES: Record<string, ResponseStatus> = {
|
|
7
|
+
'not-found': 404,
|
|
8
|
+
'invalid-device': 422,
|
|
9
|
+
'invalid-email': 422,
|
|
10
|
+
'device-limit': 409,
|
|
11
|
+
'seat-limit': 409,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function refusal(reason: string, message: string, extra: Record<string, unknown> = {}): Response {
|
|
15
|
+
return response.json({ ok: false, reason, message, ...extra }, STATUSES[reason] ?? 403)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Run a licensing call, answering 503 when the app has no signing key yet
|
|
20
|
+
* instead of a stack trace: a misconfigured server is not the caller's fault,
|
|
21
|
+
* and a client treats a 5xx as "try again later", keeping its stored token.
|
|
22
|
+
*/
|
|
23
|
+
export async function answer(run: () => Promise<Response>): Promise<Response> {
|
|
24
|
+
try {
|
|
25
|
+
return await run()
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (error instanceof licensing.LicensingNotConfiguredError) {
|
|
29
|
+
console.error(`[licensing] ${error.message}`)
|
|
30
|
+
return response.json({ reason: 'not-configured', message: 'Licensing is not configured on this server.' }, 503)
|
|
31
|
+
}
|
|
32
|
+
throw error
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import type { License } from '@stacksjs/commerce'
|
|
3
|
+
import { resolveAuthenticatedUser } from '@stacksjs/auth'
|
|
4
|
+
import { licensing } from '@stacksjs/commerce'
|
|
5
|
+
import { db } from '@stacksjs/database/runtime'
|
|
6
|
+
import { response } from '@stacksjs/router'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The team license a seat request is about, once the caller is known to run
|
|
10
|
+
* its team. Seats are managed by an active `owner` or `admin` of the `Team`
|
|
11
|
+
* the license belongs to, and by nobody else, key or no key.
|
|
12
|
+
*/
|
|
13
|
+
export async function seatLicense(request: RequestInstance): Promise<{ license: License, error?: undefined } | { error: Response, license?: undefined }> {
|
|
14
|
+
const user = await resolveAuthenticatedUser(request as any)
|
|
15
|
+
if (!user?.id)
|
|
16
|
+
return { error: response.json({ ok: false, reason: 'unauthenticated', message: 'Sign in to manage seats.' }, 401) }
|
|
17
|
+
|
|
18
|
+
const license = await licensing.findLicenseByKey(request.get('key'))
|
|
19
|
+
const member = license?.teamId
|
|
20
|
+
? await db.selectFrom('team_members')
|
|
21
|
+
.where('team_id', '=', license.teamId)
|
|
22
|
+
.where('user_id', '=', Number(user.id))
|
|
23
|
+
.where('status', '=', 'active')
|
|
24
|
+
.select(['id', 'role'])
|
|
25
|
+
.executeTakeFirst()
|
|
26
|
+
: null
|
|
27
|
+
// One answer for "no such license" and "not your team's".
|
|
28
|
+
if (!license || license.tier !== 'team' || !member || !['owner', 'admin'].includes(String(member.role)))
|
|
29
|
+
return { error: response.json({ ok: false, reason: 'not-found', message: 'That team license was not found.' }, 404) }
|
|
30
|
+
return { license }
|
|
31
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The update feed of the desktop app this project builds
|
|
5
|
+
* (`desktop.webview.updates` in config/desktop.ts):
|
|
6
|
+
* `GET /api/updates/{platform}/{arch}`.
|
|
7
|
+
*
|
|
8
|
+
* It serves the manifest `buddy release:desktop` published for that platform
|
|
9
|
+
* and architecture, exactly as stored. The manifest is signed with a key this
|
|
10
|
+
* server never holds, so nothing here can make an app accept an update the
|
|
11
|
+
* releaser did not sign. `?current=<version>` gets 204 when there is nothing
|
|
12
|
+
* newer; `?channel=beta` reads another channel.
|
|
13
|
+
*
|
|
14
|
+
* Mounted by the framework when `webview.updates` is configured. To change the
|
|
15
|
+
* path, mount it yourself in routes/api.ts:
|
|
16
|
+
*
|
|
17
|
+
* route.get('/desktop/feed/{platform}/{arch}', 'Actions/Desktop/UpdateFeedAction')
|
|
18
|
+
*/
|
|
19
|
+
export default new Action({
|
|
20
|
+
name: 'DesktopUpdateFeedAction',
|
|
21
|
+
description: 'Serves the signed update manifest for a desktop platform and architecture.',
|
|
22
|
+
method: 'GET',
|
|
23
|
+
|
|
24
|
+
async handle(request: RequestInstance) {
|
|
25
|
+
const { answerUpdateFeed } = await import('@stacksjs/desktop-build/update-feed')
|
|
26
|
+
const channel = request.get('channel')
|
|
27
|
+
const current = request.get('current')
|
|
28
|
+
return answerUpdateFeed({
|
|
29
|
+
platform: String(request.getParam('platform') ?? ''),
|
|
30
|
+
architecture: String(request.getParam('arch') ?? ''),
|
|
31
|
+
channel: typeof channel === 'string' ? channel : null,
|
|
32
|
+
currentVersion: typeof current === 'string' ? current : null,
|
|
33
|
+
})
|
|
34
|
+
},
|
|
35
|
+
})
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { License } from '@stacksjs/commerce'
|
|
2
|
+
import { config } from '@stacksjs/config'
|
|
3
|
+
import { mail, template } from '@stacksjs/email'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The email that carries license keys, in two variants of one design
|
|
7
|
+
* (`resources/emails/license.stx`): the purchase email, sent once when a
|
|
8
|
+
* purchase becomes a license, and the resend, sent when someone asks for the
|
|
9
|
+
* keys bought with an address.
|
|
10
|
+
*
|
|
11
|
+
* To send your own, copy the template to your app's `resources/emails/`, or
|
|
12
|
+
* replace the mailer outright with `licensing.configureLicensing({ onIssued })`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const TIER_NAMES: Record<License['tier'], string> = {
|
|
16
|
+
standard: 'Pro',
|
|
17
|
+
lifetime: 'Pro Lifetime',
|
|
18
|
+
team: 'Team',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function day(iso: string | null): string {
|
|
22
|
+
return iso ? new Date(iso).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' }) : ''
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** What a license includes, in a sentence. */
|
|
26
|
+
export function licenseTerms(license: License): string {
|
|
27
|
+
const devices = `${license.maxDevices} ${license.maxDevices === 1 ? 'device' : 'devices'}`
|
|
28
|
+
if (license.tier === 'lifetime')
|
|
29
|
+
return `Every update, for good, on up to ${devices}.`
|
|
30
|
+
if (license.tier === 'team')
|
|
31
|
+
return `${license.seats} ${license.seats === 1 ? 'seat' : 'seats'}, ${devices} each${license.expiresAt ? `, until ${day(license.expiresAt)}` : ''}.`
|
|
32
|
+
if (license.updatesUntil)
|
|
33
|
+
return `Updates until ${day(license.updatesUntil)}, on up to ${devices}. Every version released by then is yours to keep.`
|
|
34
|
+
return `On up to ${devices}.`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function send(to: string, licenses: License[], variant: 'purchase' | 'resend'): Promise<void> {
|
|
38
|
+
const appName = config.app.name || 'Stacks'
|
|
39
|
+
const several = licenses.length > 1
|
|
40
|
+
const subject = several ? `Your ${appName} license keys` : `Your ${appName} license key`
|
|
41
|
+
const { html, text } = await template('license', {
|
|
42
|
+
variables: {
|
|
43
|
+
appName,
|
|
44
|
+
appUrl: config.app.url ? `https://${String(config.app.url).replace(/^https?:\/\//, '')}` : '',
|
|
45
|
+
variant,
|
|
46
|
+
keys: licenses.map(license => ({ name: TIER_NAMES[license.tier], key: license.key, terms: licenseTerms(license) })),
|
|
47
|
+
subject,
|
|
48
|
+
},
|
|
49
|
+
subject,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
await mail.sendOrFail({
|
|
53
|
+
to: [to],
|
|
54
|
+
from: {
|
|
55
|
+
name: config.email.from?.name || appName,
|
|
56
|
+
address: config.email.from?.address || 'hello@stacksjs.com',
|
|
57
|
+
},
|
|
58
|
+
subject,
|
|
59
|
+
html,
|
|
60
|
+
text,
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The purchase email: one key, to the address on the license. */
|
|
65
|
+
export async function sendLicenseEmail(license: License): Promise<void> {
|
|
66
|
+
if (license.email)
|
|
67
|
+
await send(license.email, [license], 'purchase')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The resend: every key given, to the address they share. Takes licenses
|
|
72
|
+
* rather than an address, so keys cannot be directed anywhere else.
|
|
73
|
+
*/
|
|
74
|
+
export async function sendLicenseKeys(licenses: License[]): Promise<void> {
|
|
75
|
+
const to = licenses[0]?.email
|
|
76
|
+
if (to)
|
|
77
|
+
await send(to, licenses.filter(license => license.email === to), 'resend')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default sendLicenseEmail
|