@contractspec/example.saas-boilerplate 1.57.0 → 1.58.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/.turbo/turbo-build.log +160 -180
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +20 -0
- package/dist/billing/billing.entity.d.ts +40 -45
- package/dist/billing/billing.entity.d.ts.map +1 -1
- package/dist/billing/billing.entity.js +110 -118
- package/dist/billing/billing.enum.d.ts +2 -7
- package/dist/billing/billing.enum.d.ts.map +1 -1
- package/dist/billing/billing.enum.js +17 -24
- package/dist/billing/billing.event.d.ts +67 -73
- package/dist/billing/billing.event.d.ts.map +1 -1
- package/dist/billing/billing.event.js +84 -146
- package/dist/billing/billing.handler.d.ts +59 -62
- package/dist/billing/billing.handler.d.ts.map +1 -1
- package/dist/billing/billing.handler.js +140 -49
- package/dist/billing/billing.operations.d.ts +138 -144
- package/dist/billing/billing.operations.d.ts.map +1 -1
- package/dist/billing/billing.operations.js +273 -175
- package/dist/billing/billing.presentation.d.ts +2 -7
- package/dist/billing/billing.presentation.d.ts.map +1 -1
- package/dist/billing/billing.presentation.js +51 -57
- package/dist/billing/billing.schema.d.ts +159 -164
- package/dist/billing/billing.schema.d.ts.map +1 -1
- package/dist/billing/billing.schema.js +112 -204
- package/dist/billing/index.d.ts +11 -8
- package/dist/billing/index.d.ts.map +1 -0
- package/dist/billing/index.js +689 -9
- package/dist/browser/billing/billing.entity.js +113 -0
- package/dist/browser/billing/billing.enum.js +19 -0
- package/dist/browser/billing/billing.event.js +90 -0
- package/dist/browser/billing/billing.handler.js +148 -0
- package/dist/browser/billing/billing.operations.js +278 -0
- package/dist/browser/billing/billing.presentation.js +52 -0
- package/dist/browser/billing/billing.schema.js +121 -0
- package/dist/browser/billing/index.js +688 -0
- package/dist/browser/dashboard/dashboard.presentation.js +52 -0
- package/dist/browser/dashboard/index.js +52 -0
- package/dist/browser/docs/index.js +93 -0
- package/dist/browser/docs/saas-boilerplate.docblock.js +93 -0
- package/dist/browser/example.js +39 -0
- package/dist/browser/handlers/index.js +358 -0
- package/dist/browser/handlers/saas.handlers.js +134 -0
- package/dist/browser/index.js +3340 -0
- package/dist/browser/presentations/index.js +290 -0
- package/dist/browser/project/index.js +790 -0
- package/dist/browser/project/project.entity.js +77 -0
- package/dist/browser/project/project.enum.js +18 -0
- package/dist/browser/project/project.event.js +103 -0
- package/dist/browser/project/project.handler.js +178 -0
- package/dist/browser/project/project.operations.js +372 -0
- package/dist/browser/project/project.presentation.js +177 -0
- package/dist/browser/project/project.schema.js +134 -0
- package/dist/browser/saas-boilerplate.feature.js +88 -0
- package/dist/browser/seeders/index.js +20 -0
- package/dist/browser/settings/index.js +75 -0
- package/dist/browser/settings/settings.entity.js +74 -0
- package/dist/browser/settings/settings.enum.js +11 -0
- package/dist/browser/shared/mock-data.js +104 -0
- package/dist/browser/shared/overlay-types.js +0 -0
- package/dist/browser/tests/operations.test-spec.js +112 -0
- package/dist/browser/ui/SaasDashboard.js +988 -0
- package/dist/browser/ui/SaasProjectList.js +162 -0
- package/dist/browser/ui/SaasSettingsPanel.js +145 -0
- package/dist/browser/ui/hooks/index.js +159 -0
- package/dist/browser/ui/hooks/useProjectList.js +66 -0
- package/dist/browser/ui/hooks/useProjectMutations.js +91 -0
- package/dist/browser/ui/index.js +1808 -0
- package/dist/browser/ui/modals/CreateProjectModal.js +153 -0
- package/dist/browser/ui/modals/ProjectActionsModal.js +335 -0
- package/dist/browser/ui/modals/index.js +487 -0
- package/dist/browser/ui/overlays/demo-overlays.js +61 -0
- package/dist/browser/ui/overlays/index.js +61 -0
- package/dist/browser/ui/renderers/index.js +675 -0
- package/dist/browser/ui/renderers/project-list.markdown.js +499 -0
- package/dist/browser/ui/renderers/project-list.renderer.js +177 -0
- package/dist/dashboard/dashboard.presentation.d.ts +2 -7
- package/dist/dashboard/dashboard.presentation.d.ts.map +1 -1
- package/dist/dashboard/dashboard.presentation.js +51 -53
- package/dist/dashboard/index.d.ts +5 -2
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +53 -3
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +94 -1
- package/dist/docs/saas-boilerplate.docblock.d.ts +2 -1
- package/dist/docs/saas-boilerplate.docblock.d.ts.map +1 -0
- package/dist/docs/saas-boilerplate.docblock.js +45 -51
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +38 -50
- package/dist/handlers/index.d.ts +7 -4
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +358 -4
- package/dist/handlers/saas.handlers.d.ts +60 -59
- package/dist/handlers/saas.handlers.d.ts.map +1 -1
- package/dist/handlers/saas.handlers.js +127 -140
- package/dist/index.d.ts +15 -45
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3335 -75
- package/dist/node/billing/billing.entity.js +113 -0
- package/dist/node/billing/billing.enum.js +19 -0
- package/dist/node/billing/billing.event.js +90 -0
- package/dist/node/billing/billing.handler.js +148 -0
- package/dist/node/billing/billing.operations.js +278 -0
- package/dist/node/billing/billing.presentation.js +52 -0
- package/dist/node/billing/billing.schema.js +121 -0
- package/dist/node/billing/index.js +688 -0
- package/dist/node/dashboard/dashboard.presentation.js +52 -0
- package/dist/node/dashboard/index.js +52 -0
- package/dist/node/docs/index.js +93 -0
- package/dist/node/docs/saas-boilerplate.docblock.js +93 -0
- package/dist/node/example.js +39 -0
- package/dist/node/handlers/index.js +358 -0
- package/dist/node/handlers/saas.handlers.js +134 -0
- package/dist/node/index.js +3340 -0
- package/dist/node/presentations/index.js +290 -0
- package/dist/node/project/index.js +790 -0
- package/dist/node/project/project.entity.js +77 -0
- package/dist/node/project/project.enum.js +18 -0
- package/dist/node/project/project.event.js +103 -0
- package/dist/node/project/project.handler.js +178 -0
- package/dist/node/project/project.operations.js +372 -0
- package/dist/node/project/project.presentation.js +177 -0
- package/dist/node/project/project.schema.js +134 -0
- package/dist/node/saas-boilerplate.feature.js +88 -0
- package/dist/node/seeders/index.js +20 -0
- package/dist/node/settings/index.js +75 -0
- package/dist/node/settings/settings.entity.js +74 -0
- package/dist/node/settings/settings.enum.js +11 -0
- package/dist/node/shared/mock-data.js +104 -0
- package/dist/node/shared/overlay-types.js +0 -0
- package/dist/node/tests/operations.test-spec.js +112 -0
- package/dist/node/ui/SaasDashboard.js +988 -0
- package/dist/node/ui/SaasProjectList.js +162 -0
- package/dist/node/ui/SaasSettingsPanel.js +145 -0
- package/dist/node/ui/hooks/index.js +159 -0
- package/dist/node/ui/hooks/useProjectList.js +66 -0
- package/dist/node/ui/hooks/useProjectMutations.js +91 -0
- package/dist/node/ui/index.js +1808 -0
- package/dist/node/ui/modals/CreateProjectModal.js +153 -0
- package/dist/node/ui/modals/ProjectActionsModal.js +335 -0
- package/dist/node/ui/modals/index.js +487 -0
- package/dist/node/ui/overlays/demo-overlays.js +61 -0
- package/dist/node/ui/overlays/index.js +61 -0
- package/dist/node/ui/renderers/index.js +675 -0
- package/dist/node/ui/renderers/project-list.markdown.js +499 -0
- package/dist/node/ui/renderers/project-list.renderer.js +177 -0
- package/dist/presentations/index.d.ts +13 -14
- package/dist/presentations/index.d.ts.map +1 -1
- package/dist/presentations/index.js +289 -15
- package/dist/project/index.d.ts +11 -8
- package/dist/project/index.d.ts.map +1 -0
- package/dist/project/index.js +791 -9
- package/dist/project/project.entity.d.ts +23 -28
- package/dist/project/project.entity.d.ts.map +1 -1
- package/dist/project/project.entity.js +75 -82
- package/dist/project/project.enum.d.ts +2 -7
- package/dist/project/project.enum.d.ts.map +1 -1
- package/dist/project/project.enum.js +16 -23
- package/dist/project/project.event.d.ts +69 -75
- package/dist/project/project.event.d.ts.map +1 -1
- package/dist/project/project.event.js +95 -156
- package/dist/project/project.handler.d.ts +44 -47
- package/dist/project/project.handler.d.ts.map +1 -1
- package/dist/project/project.handler.js +168 -71
- package/dist/project/project.operations.d.ts +341 -347
- package/dist/project/project.operations.d.ts.map +1 -1
- package/dist/project/project.operations.js +366 -253
- package/dist/project/project.presentation.d.ts +2 -7
- package/dist/project/project.presentation.d.ts.map +1 -1
- package/dist/project/project.presentation.js +174 -61
- package/dist/project/project.schema.d.ts +191 -196
- package/dist/project/project.schema.d.ts.map +1 -1
- package/dist/project/project.schema.js +125 -205
- package/dist/saas-boilerplate.feature.d.ts +1 -6
- package/dist/saas-boilerplate.feature.d.ts.map +1 -1
- package/dist/saas-boilerplate.feature.js +87 -206
- package/dist/seeders/index.d.ts +4 -8
- package/dist/seeders/index.d.ts.map +1 -1
- package/dist/seeders/index.js +18 -16
- package/dist/settings/index.d.ts +6 -3
- package/dist/settings/index.d.ts.map +1 -0
- package/dist/settings/index.js +75 -3
- package/dist/settings/settings.entity.d.ts +23 -28
- package/dist/settings/settings.entity.d.ts.map +1 -1
- package/dist/settings/settings.entity.js +72 -75
- package/dist/settings/settings.enum.d.ts +1 -6
- package/dist/settings/settings.enum.d.ts.map +1 -1
- package/dist/settings/settings.enum.js +10 -19
- package/dist/shared/mock-data.d.ts +74 -77
- package/dist/shared/mock-data.d.ts.map +1 -1
- package/dist/shared/mock-data.js +102 -135
- package/dist/shared/overlay-types.d.ts +25 -28
- package/dist/shared/overlay-types.d.ts.map +1 -1
- package/dist/shared/overlay-types.js +1 -0
- package/dist/tests/operations.test-spec.d.ts +4 -9
- package/dist/tests/operations.test-spec.d.ts.map +1 -1
- package/dist/tests/operations.test-spec.js +108 -118
- package/dist/ui/SaasDashboard.d.ts +1 -6
- package/dist/ui/SaasDashboard.d.ts.map +1 -1
- package/dist/ui/SaasDashboard.js +977 -286
- package/dist/ui/SaasProjectList.d.ts +4 -11
- package/dist/ui/SaasProjectList.d.ts.map +1 -1
- package/dist/ui/SaasProjectList.js +159 -72
- package/dist/ui/SaasSettingsPanel.d.ts +1 -6
- package/dist/ui/SaasSettingsPanel.d.ts.map +1 -1
- package/dist/ui/SaasSettingsPanel.js +142 -134
- package/dist/ui/hooks/index.d.ts +3 -3
- package/dist/ui/hooks/index.d.ts.map +1 -0
- package/dist/ui/hooks/index.js +158 -4
- package/dist/ui/hooks/useProjectList.d.ts +26 -30
- package/dist/ui/hooks/useProjectList.d.ts.map +1 -1
- package/dist/ui/hooks/useProjectList.js +63 -71
- package/dist/ui/hooks/useProjectMutations.d.ts +20 -24
- package/dist/ui/hooks/useProjectMutations.d.ts.map +1 -1
- package/dist/ui/hooks/useProjectMutations.js +88 -142
- package/dist/ui/index.d.ts +8 -14
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +1809 -15
- package/dist/ui/modals/CreateProjectModal.d.ts +10 -19
- package/dist/ui/modals/CreateProjectModal.d.ts.map +1 -1
- package/dist/ui/modals/CreateProjectModal.js +150 -135
- package/dist/ui/modals/ProjectActionsModal.d.ts +20 -33
- package/dist/ui/modals/ProjectActionsModal.d.ts.map +1 -1
- package/dist/ui/modals/ProjectActionsModal.js +333 -289
- package/dist/ui/modals/index.d.ts +3 -3
- package/dist/ui/modals/index.d.ts.map +1 -0
- package/dist/ui/modals/index.js +487 -3
- package/dist/ui/overlays/demo-overlays.d.ts +10 -8
- package/dist/ui/overlays/demo-overlays.d.ts.map +1 -1
- package/dist/ui/overlays/demo-overlays.js +60 -68
- package/dist/ui/overlays/index.d.ts +2 -2
- package/dist/ui/overlays/index.d.ts.map +1 -0
- package/dist/ui/overlays/index.js +62 -3
- package/dist/ui/renderers/index.d.ts +3 -3
- package/dist/ui/renderers/index.d.ts.map +1 -0
- package/dist/ui/renderers/index.js +675 -3
- package/dist/ui/renderers/project-list.markdown.d.ts +15 -14
- package/dist/ui/renderers/project-list.markdown.d.ts.map +1 -1
- package/dist/ui/renderers/project-list.markdown.js +496 -146
- package/dist/ui/renderers/project-list.renderer.d.ts +6 -7
- package/dist/ui/renderers/project-list.renderer.d.ts.map +1 -1
- package/dist/ui/renderers/project-list.renderer.js +176 -15
- package/package.json +508 -98
- package/tsdown.config.js +1 -2
- package/.turbo/turbo-build$colon$bundle.log +0 -180
- package/dist/billing/billing.entity.js.map +0 -1
- package/dist/billing/billing.enum.js.map +0 -1
- package/dist/billing/billing.event.js.map +0 -1
- package/dist/billing/billing.handler.js.map +0 -1
- package/dist/billing/billing.operations.js.map +0 -1
- package/dist/billing/billing.presentation.js.map +0 -1
- package/dist/billing/billing.schema.js.map +0 -1
- package/dist/dashboard/dashboard.presentation.js.map +0 -1
- package/dist/docs/saas-boilerplate.docblock.js.map +0 -1
- package/dist/example.js.map +0 -1
- package/dist/handlers/saas.handlers.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/presentations/index.js.map +0 -1
- package/dist/project/project.entity.js.map +0 -1
- package/dist/project/project.enum.js.map +0 -1
- package/dist/project/project.event.js.map +0 -1
- package/dist/project/project.handler.js.map +0 -1
- package/dist/project/project.operations.js.map +0 -1
- package/dist/project/project.presentation.js.map +0 -1
- package/dist/project/project.schema.js.map +0 -1
- package/dist/saas-boilerplate.feature.js.map +0 -1
- package/dist/seeders/index.js.map +0 -1
- package/dist/settings/settings.entity.js.map +0 -1
- package/dist/settings/settings.enum.js.map +0 -1
- package/dist/shared/mock-data.js.map +0 -1
- package/dist/tests/operations.test-spec.js.map +0 -1
- package/dist/ui/SaasDashboard.js.map +0 -1
- package/dist/ui/SaasProjectList.js.map +0 -1
- package/dist/ui/SaasSettingsPanel.js.map +0 -1
- package/dist/ui/hooks/useProjectList.js.map +0 -1
- package/dist/ui/hooks/useProjectMutations.js.map +0 -1
- package/dist/ui/modals/CreateProjectModal.js.map +0 -1
- package/dist/ui/modals/ProjectActionsModal.js.map +0 -1
- package/dist/ui/overlays/demo-overlays.js.map +0 -1
- package/dist/ui/renderers/project-list.markdown.js.map +0 -1
- package/dist/ui/renderers/project-list.renderer.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/billing/billing.entity.ts
|
|
2
|
+
import {
|
|
3
|
+
defineEntity,
|
|
4
|
+
defineEntityEnum,
|
|
5
|
+
field,
|
|
6
|
+
index
|
|
7
|
+
} from "@contractspec/lib.schema";
|
|
8
|
+
var SubscriptionStatusEnum = defineEntityEnum({
|
|
9
|
+
name: "SubscriptionStatus",
|
|
10
|
+
values: ["TRIALING", "ACTIVE", "PAST_DUE", "CANCELED", "PAUSED"],
|
|
11
|
+
schema: "saas_app",
|
|
12
|
+
description: "Status of a subscription."
|
|
13
|
+
});
|
|
14
|
+
var SubscriptionEntity = defineEntity({
|
|
15
|
+
name: "Subscription",
|
|
16
|
+
description: "Organization subscription/plan information.",
|
|
17
|
+
schema: "saas_app",
|
|
18
|
+
map: "subscription",
|
|
19
|
+
fields: {
|
|
20
|
+
id: field.id(),
|
|
21
|
+
organizationId: field.foreignKey({ isUnique: true }),
|
|
22
|
+
planId: field.string({ description: "Plan identifier" }),
|
|
23
|
+
planName: field.string({ description: "Plan display name" }),
|
|
24
|
+
status: field.enum("SubscriptionStatus"),
|
|
25
|
+
currentPeriodStart: field.dateTime(),
|
|
26
|
+
currentPeriodEnd: field.dateTime(),
|
|
27
|
+
trialEndsAt: field.dateTime({ isOptional: true }),
|
|
28
|
+
cancelAtPeriodEnd: field.boolean({ default: false }),
|
|
29
|
+
canceledAt: field.dateTime({ isOptional: true }),
|
|
30
|
+
stripeSubscriptionId: field.string({ isOptional: true }),
|
|
31
|
+
stripeCustomerId: field.string({ isOptional: true }),
|
|
32
|
+
metadata: field.json({ isOptional: true }),
|
|
33
|
+
createdAt: field.createdAt(),
|
|
34
|
+
updatedAt: field.updatedAt()
|
|
35
|
+
},
|
|
36
|
+
enums: [SubscriptionStatusEnum]
|
|
37
|
+
});
|
|
38
|
+
var BillingUsageEntity = defineEntity({
|
|
39
|
+
name: "BillingUsage",
|
|
40
|
+
description: "Track usage of metered features.",
|
|
41
|
+
schema: "saas_app",
|
|
42
|
+
map: "billing_usage",
|
|
43
|
+
fields: {
|
|
44
|
+
id: field.id(),
|
|
45
|
+
organizationId: field.foreignKey(),
|
|
46
|
+
feature: field.string({
|
|
47
|
+
description: 'Feature being tracked (e.g., "api_calls", "storage_gb")'
|
|
48
|
+
}),
|
|
49
|
+
quantity: field.int({ description: "Usage quantity" }),
|
|
50
|
+
unit: field.string({
|
|
51
|
+
isOptional: true,
|
|
52
|
+
description: "Unit of measurement"
|
|
53
|
+
}),
|
|
54
|
+
billingPeriod: field.string({
|
|
55
|
+
description: 'Billing period (e.g., "2024-01")'
|
|
56
|
+
}),
|
|
57
|
+
recordedAt: field.dateTime({ description: "When usage was recorded" }),
|
|
58
|
+
sourceId: field.string({
|
|
59
|
+
isOptional: true,
|
|
60
|
+
description: "Source of usage (e.g., request ID)"
|
|
61
|
+
}),
|
|
62
|
+
sourceType: field.string({ isOptional: true }),
|
|
63
|
+
metadata: field.json({ isOptional: true })
|
|
64
|
+
},
|
|
65
|
+
indexes: [
|
|
66
|
+
index.on(["organizationId", "feature", "billingPeriod"]),
|
|
67
|
+
index.on(["organizationId", "recordedAt"])
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
var UsageLimitEntity = defineEntity({
|
|
71
|
+
name: "UsageLimit",
|
|
72
|
+
description: "Usage limits per plan/organization.",
|
|
73
|
+
schema: "saas_app",
|
|
74
|
+
map: "usage_limit",
|
|
75
|
+
fields: {
|
|
76
|
+
id: field.id(),
|
|
77
|
+
planId: field.string({
|
|
78
|
+
isOptional: true,
|
|
79
|
+
description: "Plan this limit applies to"
|
|
80
|
+
}),
|
|
81
|
+
organizationId: field.string({
|
|
82
|
+
isOptional: true,
|
|
83
|
+
description: "Org-specific override"
|
|
84
|
+
}),
|
|
85
|
+
feature: field.string({ description: "Feature being limited" }),
|
|
86
|
+
limit: field.int({ description: "Maximum allowed usage" }),
|
|
87
|
+
resetPeriod: field.string({
|
|
88
|
+
default: '"monthly"',
|
|
89
|
+
description: "When limit resets"
|
|
90
|
+
}),
|
|
91
|
+
isSoftLimit: field.boolean({
|
|
92
|
+
default: false,
|
|
93
|
+
description: "Whether to warn vs block"
|
|
94
|
+
}),
|
|
95
|
+
overage: field.boolean({
|
|
96
|
+
default: false,
|
|
97
|
+
description: "Whether overage is allowed"
|
|
98
|
+
}),
|
|
99
|
+
overageRate: field.float({
|
|
100
|
+
isOptional: true,
|
|
101
|
+
description: "Cost per unit over limit"
|
|
102
|
+
}),
|
|
103
|
+
createdAt: field.createdAt(),
|
|
104
|
+
updatedAt: field.updatedAt()
|
|
105
|
+
},
|
|
106
|
+
indexes: [index.unique(["planId", "feature"])]
|
|
107
|
+
});
|
|
108
|
+
export {
|
|
109
|
+
UsageLimitEntity,
|
|
110
|
+
SubscriptionStatusEnum,
|
|
111
|
+
SubscriptionEntity,
|
|
112
|
+
BillingUsageEntity
|
|
113
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/billing/billing.enum.ts
|
|
2
|
+
import { defineEnum } from "@contractspec/lib.schema";
|
|
3
|
+
var SubscriptionStatusSchemaEnum = defineEnum("SubscriptionStatus", [
|
|
4
|
+
"TRIALING",
|
|
5
|
+
"ACTIVE",
|
|
6
|
+
"PAST_DUE",
|
|
7
|
+
"CANCELED",
|
|
8
|
+
"PAUSED"
|
|
9
|
+
]);
|
|
10
|
+
var FeatureAccessReasonEnum = defineEnum("FeatureAccessReason", [
|
|
11
|
+
"included",
|
|
12
|
+
"limit_available",
|
|
13
|
+
"limit_reached",
|
|
14
|
+
"not_in_plan"
|
|
15
|
+
]);
|
|
16
|
+
export {
|
|
17
|
+
SubscriptionStatusSchemaEnum,
|
|
18
|
+
FeatureAccessReasonEnum
|
|
19
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/billing/billing.event.ts
|
|
2
|
+
import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
|
|
3
|
+
import { defineEvent } from "@contractspec/lib.contracts";
|
|
4
|
+
var UsageRecordedPayload = defineSchemaModel({
|
|
5
|
+
name: "UsageRecordedPayload",
|
|
6
|
+
description: "Payload when feature usage is recorded",
|
|
7
|
+
fields: {
|
|
8
|
+
organizationId: {
|
|
9
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
10
|
+
isOptional: false
|
|
11
|
+
},
|
|
12
|
+
feature: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
13
|
+
quantity: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
14
|
+
billingPeriod: {
|
|
15
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
16
|
+
isOptional: false
|
|
17
|
+
},
|
|
18
|
+
recordedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
var UsageLimitReachedPayload = defineSchemaModel({
|
|
22
|
+
name: "UsageLimitReachedPayload",
|
|
23
|
+
description: "Payload when usage limit is reached",
|
|
24
|
+
fields: {
|
|
25
|
+
organizationId: {
|
|
26
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
27
|
+
isOptional: false
|
|
28
|
+
},
|
|
29
|
+
feature: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
30
|
+
limit: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
31
|
+
currentUsage: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
32
|
+
reachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
var SubscriptionChangedPayload = defineSchemaModel({
|
|
36
|
+
name: "SubscriptionChangedPayload",
|
|
37
|
+
description: "Payload when subscription status changes",
|
|
38
|
+
fields: {
|
|
39
|
+
organizationId: {
|
|
40
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
41
|
+
isOptional: false
|
|
42
|
+
},
|
|
43
|
+
previousPlan: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
44
|
+
newPlan: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
45
|
+
previousStatus: {
|
|
46
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
47
|
+
isOptional: true
|
|
48
|
+
},
|
|
49
|
+
newStatus: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
50
|
+
changedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
var UsageRecordedEvent = defineEvent({
|
|
54
|
+
meta: {
|
|
55
|
+
key: "billing.usage.recorded",
|
|
56
|
+
version: "1.0.0",
|
|
57
|
+
description: "Feature usage has been recorded.",
|
|
58
|
+
stability: "stable",
|
|
59
|
+
owners: ["@saas-team"],
|
|
60
|
+
tags: ["billing", "usage", "recorded"]
|
|
61
|
+
},
|
|
62
|
+
payload: UsageRecordedPayload
|
|
63
|
+
});
|
|
64
|
+
var UsageLimitReachedEvent = defineEvent({
|
|
65
|
+
meta: {
|
|
66
|
+
key: "billing.limit.reached",
|
|
67
|
+
version: "1.0.0",
|
|
68
|
+
description: "Usage limit has been reached for a feature.",
|
|
69
|
+
stability: "stable",
|
|
70
|
+
owners: ["@saas-team"],
|
|
71
|
+
tags: ["billing", "limit", "reached"]
|
|
72
|
+
},
|
|
73
|
+
payload: UsageLimitReachedPayload
|
|
74
|
+
});
|
|
75
|
+
var SubscriptionChangedEvent = defineEvent({
|
|
76
|
+
meta: {
|
|
77
|
+
key: "billing.subscription.changed",
|
|
78
|
+
version: "1.0.0",
|
|
79
|
+
description: "Subscription status has changed.",
|
|
80
|
+
stability: "stable",
|
|
81
|
+
owners: ["@saas-team"],
|
|
82
|
+
tags: ["billing", "subscription", "changed"]
|
|
83
|
+
},
|
|
84
|
+
payload: SubscriptionChangedPayload
|
|
85
|
+
});
|
|
86
|
+
export {
|
|
87
|
+
UsageRecordedEvent,
|
|
88
|
+
UsageLimitReachedEvent,
|
|
89
|
+
SubscriptionChangedEvent
|
|
90
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// src/shared/mock-data.ts
|
|
2
|
+
var MOCK_PROJECTS = [
|
|
3
|
+
{
|
|
4
|
+
id: "proj-1",
|
|
5
|
+
name: "Marketing Website",
|
|
6
|
+
description: "Main company website redesign project",
|
|
7
|
+
slug: "marketing-website",
|
|
8
|
+
organizationId: "demo-org",
|
|
9
|
+
createdBy: "user-1",
|
|
10
|
+
status: "ACTIVE",
|
|
11
|
+
isPublic: false,
|
|
12
|
+
tags: ["marketing", "website", "redesign"],
|
|
13
|
+
createdAt: new Date("2024-01-15T10:00:00Z"),
|
|
14
|
+
updatedAt: new Date("2024-03-20T14:30:00Z")
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "proj-2",
|
|
18
|
+
name: "Mobile App v2",
|
|
19
|
+
description: "Next generation mobile application",
|
|
20
|
+
slug: "mobile-app-v2",
|
|
21
|
+
organizationId: "demo-org",
|
|
22
|
+
createdBy: "user-2",
|
|
23
|
+
status: "ACTIVE",
|
|
24
|
+
isPublic: false,
|
|
25
|
+
tags: ["mobile", "app", "v2"],
|
|
26
|
+
createdAt: new Date("2024-02-01T09:00:00Z"),
|
|
27
|
+
updatedAt: new Date("2024-04-05T11:15:00Z")
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "proj-3",
|
|
31
|
+
name: "API Integration",
|
|
32
|
+
description: "Third-party API integration project",
|
|
33
|
+
slug: "api-integration",
|
|
34
|
+
organizationId: "demo-org",
|
|
35
|
+
createdBy: "user-1",
|
|
36
|
+
status: "DRAFT",
|
|
37
|
+
isPublic: false,
|
|
38
|
+
tags: ["api", "integration"],
|
|
39
|
+
createdAt: new Date("2024-03-10T08:00:00Z"),
|
|
40
|
+
updatedAt: new Date("2024-03-10T08:00:00Z")
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "proj-4",
|
|
44
|
+
name: "Analytics Dashboard",
|
|
45
|
+
description: "Internal analytics and reporting dashboard",
|
|
46
|
+
slug: "analytics-dashboard",
|
|
47
|
+
organizationId: "demo-org",
|
|
48
|
+
createdBy: "user-3",
|
|
49
|
+
status: "ARCHIVED",
|
|
50
|
+
isPublic: true,
|
|
51
|
+
tags: ["analytics", "dashboard", "reporting"],
|
|
52
|
+
createdAt: new Date("2023-10-01T12:00:00Z"),
|
|
53
|
+
updatedAt: new Date("2024-02-28T16:45:00Z")
|
|
54
|
+
}
|
|
55
|
+
];
|
|
56
|
+
var MOCK_SUBSCRIPTION = {
|
|
57
|
+
id: "sub-1",
|
|
58
|
+
organizationId: "demo-org",
|
|
59
|
+
planId: "pro",
|
|
60
|
+
planName: "Professional",
|
|
61
|
+
status: "ACTIVE",
|
|
62
|
+
currentPeriodStart: new Date("2024-04-01T00:00:00Z"),
|
|
63
|
+
currentPeriodEnd: new Date("2024-05-01T00:00:00Z"),
|
|
64
|
+
limits: {
|
|
65
|
+
projects: 25,
|
|
66
|
+
users: 10,
|
|
67
|
+
storage: 50,
|
|
68
|
+
apiCalls: 1e5
|
|
69
|
+
},
|
|
70
|
+
usage: {
|
|
71
|
+
projects: 4,
|
|
72
|
+
users: 5,
|
|
73
|
+
storage: 12.5,
|
|
74
|
+
apiCalls: 45230
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var MOCK_USAGE_SUMMARY = {
|
|
78
|
+
organizationId: "demo-org",
|
|
79
|
+
period: "current_month",
|
|
80
|
+
apiCalls: {
|
|
81
|
+
total: 45230,
|
|
82
|
+
limit: 1e5,
|
|
83
|
+
percentUsed: 45.23
|
|
84
|
+
},
|
|
85
|
+
storage: {
|
|
86
|
+
totalGb: 12.5,
|
|
87
|
+
limitGb: 50,
|
|
88
|
+
percentUsed: 25
|
|
89
|
+
},
|
|
90
|
+
activeProjects: 4,
|
|
91
|
+
activeUsers: 5,
|
|
92
|
+
breakdown: [
|
|
93
|
+
{ date: "2024-04-01", apiCalls: 3200, storageGb: 12.1 },
|
|
94
|
+
{ date: "2024-04-02", apiCalls: 2800, storageGb: 12.2 },
|
|
95
|
+
{ date: "2024-04-03", apiCalls: 4100, storageGb: 12.3 },
|
|
96
|
+
{ date: "2024-04-04", apiCalls: 3600, storageGb: 12.4 },
|
|
97
|
+
{ date: "2024-04-05", apiCalls: 3800, storageGb: 12.5 }
|
|
98
|
+
]
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/billing/billing.handler.ts
|
|
102
|
+
async function mockGetSubscriptionHandler() {
|
|
103
|
+
return MOCK_SUBSCRIPTION;
|
|
104
|
+
}
|
|
105
|
+
async function mockGetUsageSummaryHandler(input) {
|
|
106
|
+
return {
|
|
107
|
+
...MOCK_USAGE_SUMMARY,
|
|
108
|
+
period: input.period ?? "current_month"
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async function mockRecordUsageHandler(input) {
|
|
112
|
+
const currentUsage = MOCK_USAGE_SUMMARY.apiCalls.total;
|
|
113
|
+
const newTotal = currentUsage + input.quantity;
|
|
114
|
+
return {
|
|
115
|
+
recorded: true,
|
|
116
|
+
newTotal
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async function mockCheckFeatureAccessHandler(input) {
|
|
120
|
+
const { feature } = input;
|
|
121
|
+
const featureMap = {
|
|
122
|
+
custom_domains: {
|
|
123
|
+
allowed: true
|
|
124
|
+
},
|
|
125
|
+
api_access: {
|
|
126
|
+
allowed: true,
|
|
127
|
+
currentUsage: MOCK_USAGE_SUMMARY.apiCalls.total,
|
|
128
|
+
limit: MOCK_USAGE_SUMMARY.apiCalls.limit
|
|
129
|
+
},
|
|
130
|
+
advanced_analytics: {
|
|
131
|
+
allowed: false,
|
|
132
|
+
reason: "FEATURE_NOT_INCLUDED"
|
|
133
|
+
},
|
|
134
|
+
unlimited_projects: {
|
|
135
|
+
allowed: false,
|
|
136
|
+
reason: "PLAN_LIMIT",
|
|
137
|
+
currentUsage: MOCK_SUBSCRIPTION.usage.projects,
|
|
138
|
+
limit: MOCK_SUBSCRIPTION.limits.projects
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
return featureMap[feature] ?? { allowed: true };
|
|
142
|
+
}
|
|
143
|
+
export {
|
|
144
|
+
mockRecordUsageHandler,
|
|
145
|
+
mockGetUsageSummaryHandler,
|
|
146
|
+
mockGetSubscriptionHandler,
|
|
147
|
+
mockCheckFeatureAccessHandler
|
|
148
|
+
};
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// src/billing/billing.enum.ts
|
|
2
|
+
import { defineEnum } from "@contractspec/lib.schema";
|
|
3
|
+
var SubscriptionStatusSchemaEnum = defineEnum("SubscriptionStatus", [
|
|
4
|
+
"TRIALING",
|
|
5
|
+
"ACTIVE",
|
|
6
|
+
"PAST_DUE",
|
|
7
|
+
"CANCELED",
|
|
8
|
+
"PAUSED"
|
|
9
|
+
]);
|
|
10
|
+
var FeatureAccessReasonEnum = defineEnum("FeatureAccessReason", [
|
|
11
|
+
"included",
|
|
12
|
+
"limit_available",
|
|
13
|
+
"limit_reached",
|
|
14
|
+
"not_in_plan"
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
// src/billing/billing.schema.ts
|
|
18
|
+
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
19
|
+
var SubscriptionModel = defineSchemaModel({
|
|
20
|
+
name: "Subscription",
|
|
21
|
+
description: "Organization subscription details",
|
|
22
|
+
fields: {
|
|
23
|
+
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
24
|
+
organizationId: {
|
|
25
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
26
|
+
isOptional: false
|
|
27
|
+
},
|
|
28
|
+
planId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
29
|
+
planName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
30
|
+
status: { type: SubscriptionStatusSchemaEnum, isOptional: false },
|
|
31
|
+
currentPeriodStart: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
32
|
+
currentPeriodEnd: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
33
|
+
trialEndsAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
34
|
+
cancelAtPeriodEnd: { type: ScalarTypeEnum.Boolean(), isOptional: false }
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
var UsageSummaryModel = defineSchemaModel({
|
|
38
|
+
name: "UsageSummary",
|
|
39
|
+
description: "Usage summary for a feature",
|
|
40
|
+
fields: {
|
|
41
|
+
feature: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
42
|
+
used: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
43
|
+
limit: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
|
|
44
|
+
unit: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
45
|
+
percentage: { type: ScalarTypeEnum.Float_unsecure(), isOptional: true }
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
var RecordUsageInputModel = defineSchemaModel({
|
|
49
|
+
name: "RecordUsageInput",
|
|
50
|
+
description: "Input for recording feature usage",
|
|
51
|
+
fields: {
|
|
52
|
+
feature: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
53
|
+
quantity: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
54
|
+
sourceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
55
|
+
sourceType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
56
|
+
metadata: { type: ScalarTypeEnum.JSONObject(), isOptional: true }
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
var RecordUsageOutputModel = defineSchemaModel({
|
|
60
|
+
name: "RecordUsageOutput",
|
|
61
|
+
description: "Output for recording feature usage",
|
|
62
|
+
fields: {
|
|
63
|
+
recorded: { type: ScalarTypeEnum.Boolean(), isOptional: false },
|
|
64
|
+
currentUsage: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
65
|
+
limit: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
|
|
66
|
+
limitReached: { type: ScalarTypeEnum.Boolean(), isOptional: false }
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
var UsageRecordedPayloadModel = defineSchemaModel({
|
|
70
|
+
name: "UsageRecordedPayload",
|
|
71
|
+
description: "Payload for usage.recorded event",
|
|
72
|
+
fields: {
|
|
73
|
+
feature: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
74
|
+
quantity: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false }
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var GetUsageSummaryInputModel = defineSchemaModel({
|
|
78
|
+
name: "GetUsageSummaryInput",
|
|
79
|
+
description: "Input for getting usage summary",
|
|
80
|
+
fields: {
|
|
81
|
+
billingPeriod: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
var GetUsageSummaryOutputModel = defineSchemaModel({
|
|
85
|
+
name: "GetUsageSummaryOutput",
|
|
86
|
+
description: "Output for usage summary",
|
|
87
|
+
fields: {
|
|
88
|
+
billingPeriod: {
|
|
89
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
90
|
+
isOptional: false
|
|
91
|
+
},
|
|
92
|
+
usage: { type: UsageSummaryModel, isArray: true, isOptional: false }
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
var CheckFeatureAccessInputModel = defineSchemaModel({
|
|
96
|
+
name: "CheckFeatureAccessInput",
|
|
97
|
+
description: "Input for checking feature access",
|
|
98
|
+
fields: {
|
|
99
|
+
feature: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
var CheckFeatureAccessOutputModel = defineSchemaModel({
|
|
103
|
+
name: "CheckFeatureAccessOutput",
|
|
104
|
+
description: "Output for feature access check",
|
|
105
|
+
fields: {
|
|
106
|
+
hasAccess: { type: ScalarTypeEnum.Boolean(), isOptional: false },
|
|
107
|
+
reason: { type: FeatureAccessReasonEnum, isOptional: true },
|
|
108
|
+
upgradeUrl: { type: ScalarTypeEnum.URL(), isOptional: true }
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// src/billing/billing.operations.ts
|
|
113
|
+
import { defineCommand, defineQuery } from "@contractspec/lib.contracts";
|
|
114
|
+
var OWNERS = ["@example.saas-boilerplate"];
|
|
115
|
+
var GetSubscriptionContract = defineQuery({
|
|
116
|
+
meta: {
|
|
117
|
+
key: "saas.billing.subscription.get",
|
|
118
|
+
version: "1.0.0",
|
|
119
|
+
stability: "stable",
|
|
120
|
+
owners: [...OWNERS],
|
|
121
|
+
tags: ["saas", "billing", "subscription"],
|
|
122
|
+
description: "Get organization subscription status.",
|
|
123
|
+
goal: "Show current plan and billing status.",
|
|
124
|
+
context: "Billing page, plan upgrade prompts."
|
|
125
|
+
},
|
|
126
|
+
io: {
|
|
127
|
+
input: null,
|
|
128
|
+
output: SubscriptionModel
|
|
129
|
+
},
|
|
130
|
+
policy: {
|
|
131
|
+
auth: "user"
|
|
132
|
+
},
|
|
133
|
+
acceptance: {
|
|
134
|
+
scenarios: [
|
|
135
|
+
{
|
|
136
|
+
key: "get-subscription-happy-path",
|
|
137
|
+
given: ["Organization has active subscription"],
|
|
138
|
+
when: ["User requests subscription status"],
|
|
139
|
+
then: ["Subscription details are returned"]
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
examples: [
|
|
143
|
+
{
|
|
144
|
+
key: "get-basic",
|
|
145
|
+
input: null,
|
|
146
|
+
output: {
|
|
147
|
+
plan: "pro",
|
|
148
|
+
status: "active",
|
|
149
|
+
currentPeriodEnd: "2025-02-01T00:00:00Z"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
var RecordUsageContract = defineCommand({
|
|
156
|
+
meta: {
|
|
157
|
+
key: "saas.billing.usage.record",
|
|
158
|
+
version: "1.0.0",
|
|
159
|
+
stability: "stable",
|
|
160
|
+
owners: [...OWNERS],
|
|
161
|
+
tags: ["saas", "billing", "usage"],
|
|
162
|
+
description: "Record usage of a metered feature.",
|
|
163
|
+
goal: "Track feature usage for billing.",
|
|
164
|
+
context: "Called by services when metered features are used."
|
|
165
|
+
},
|
|
166
|
+
io: {
|
|
167
|
+
input: RecordUsageInputModel,
|
|
168
|
+
output: RecordUsageOutputModel
|
|
169
|
+
},
|
|
170
|
+
policy: {
|
|
171
|
+
auth: "user"
|
|
172
|
+
},
|
|
173
|
+
sideEffects: {
|
|
174
|
+
emits: [
|
|
175
|
+
{
|
|
176
|
+
key: "billing.usage.recorded",
|
|
177
|
+
version: "1.0.0",
|
|
178
|
+
when: "Usage is recorded",
|
|
179
|
+
payload: UsageRecordedPayloadModel
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
},
|
|
183
|
+
acceptance: {
|
|
184
|
+
scenarios: [
|
|
185
|
+
{
|
|
186
|
+
key: "record-usage-happy-path",
|
|
187
|
+
given: ["Organization exists"],
|
|
188
|
+
when: ["System records feature usage"],
|
|
189
|
+
then: ["Usage is recorded"]
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
examples: [
|
|
193
|
+
{
|
|
194
|
+
key: "record-api-call",
|
|
195
|
+
input: { feature: "api_calls", quantity: 1, idempotencyKey: "abc-123" },
|
|
196
|
+
output: { recorded: true, currentUsage: 100 }
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
var GetUsageSummaryContract = defineQuery({
|
|
202
|
+
meta: {
|
|
203
|
+
key: "saas.billing.usage.summary",
|
|
204
|
+
version: "1.0.0",
|
|
205
|
+
stability: "stable",
|
|
206
|
+
owners: [...OWNERS],
|
|
207
|
+
tags: ["saas", "billing", "usage"],
|
|
208
|
+
description: "Get usage summary for the current billing period.",
|
|
209
|
+
goal: "Show usage vs limits.",
|
|
210
|
+
context: "Billing page, usage dashboards."
|
|
211
|
+
},
|
|
212
|
+
io: {
|
|
213
|
+
input: GetUsageSummaryInputModel,
|
|
214
|
+
output: GetUsageSummaryOutputModel
|
|
215
|
+
},
|
|
216
|
+
policy: {
|
|
217
|
+
auth: "user"
|
|
218
|
+
},
|
|
219
|
+
acceptance: {
|
|
220
|
+
scenarios: [
|
|
221
|
+
{
|
|
222
|
+
key: "get-usage-happy-path",
|
|
223
|
+
given: ["Organization has usage history"],
|
|
224
|
+
when: ["User requests usage summary"],
|
|
225
|
+
then: ["Usage metrics are returned"]
|
|
226
|
+
}
|
|
227
|
+
],
|
|
228
|
+
examples: [
|
|
229
|
+
{
|
|
230
|
+
key: "get-current-usage",
|
|
231
|
+
input: { period: "current" },
|
|
232
|
+
output: { features: [{ name: "api_calls", used: 100, limit: 1000 }] }
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
var CheckFeatureAccessContract = defineQuery({
|
|
238
|
+
meta: {
|
|
239
|
+
key: "saas.billing.feature.check",
|
|
240
|
+
version: "1.0.0",
|
|
241
|
+
stability: "stable",
|
|
242
|
+
owners: [...OWNERS],
|
|
243
|
+
tags: ["saas", "billing", "feature"],
|
|
244
|
+
description: "Check if organization has access to a feature.",
|
|
245
|
+
goal: "Gate features based on plan/usage.",
|
|
246
|
+
context: "Feature access checks, upgrade prompts."
|
|
247
|
+
},
|
|
248
|
+
io: {
|
|
249
|
+
input: CheckFeatureAccessInputModel,
|
|
250
|
+
output: CheckFeatureAccessOutputModel
|
|
251
|
+
},
|
|
252
|
+
policy: {
|
|
253
|
+
auth: "user"
|
|
254
|
+
},
|
|
255
|
+
acceptance: {
|
|
256
|
+
scenarios: [
|
|
257
|
+
{
|
|
258
|
+
key: "check-access-granted",
|
|
259
|
+
given: ["Organization is on Pro plan"],
|
|
260
|
+
when: ["User checks access to Pro feature"],
|
|
261
|
+
then: ["Access is granted"]
|
|
262
|
+
}
|
|
263
|
+
],
|
|
264
|
+
examples: [
|
|
265
|
+
{
|
|
266
|
+
key: "check-advanced-reports",
|
|
267
|
+
input: { feature: "advanced_reports" },
|
|
268
|
+
output: { hasAccess: true, reason: "Included in Pro plan" }
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
export {
|
|
274
|
+
RecordUsageContract,
|
|
275
|
+
GetUsageSummaryContract,
|
|
276
|
+
GetSubscriptionContract,
|
|
277
|
+
CheckFeatureAccessContract
|
|
278
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/billing/billing.presentation.ts
|
|
2
|
+
import { definePresentation, StabilityEnum } from "@contractspec/lib.contracts";
|
|
3
|
+
var SubscriptionPresentation = definePresentation({
|
|
4
|
+
meta: {
|
|
5
|
+
key: "saas.billing.subscription",
|
|
6
|
+
version: "1.0.0",
|
|
7
|
+
title: "Subscription Status",
|
|
8
|
+
description: "Subscription status with plan info, limits, and current usage",
|
|
9
|
+
domain: "saas-boilerplate",
|
|
10
|
+
owners: ["@saas-team"],
|
|
11
|
+
tags: ["billing", "subscription"],
|
|
12
|
+
stability: StabilityEnum.Beta,
|
|
13
|
+
goal: "View subscription plan and status",
|
|
14
|
+
context: "Billing section"
|
|
15
|
+
},
|
|
16
|
+
source: {
|
|
17
|
+
type: "component",
|
|
18
|
+
framework: "react",
|
|
19
|
+
componentKey: "SubscriptionView"
|
|
20
|
+
},
|
|
21
|
+
targets: ["react", "markdown"],
|
|
22
|
+
policy: {
|
|
23
|
+
flags: ["saas.billing.enabled"]
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
var UsageDashboardPresentation = definePresentation({
|
|
27
|
+
meta: {
|
|
28
|
+
key: "saas.billing.usage",
|
|
29
|
+
version: "1.0.0",
|
|
30
|
+
title: "Usage Dashboard",
|
|
31
|
+
description: "Usage metrics and breakdown by resource type",
|
|
32
|
+
domain: "saas-boilerplate",
|
|
33
|
+
owners: ["@saas-team"],
|
|
34
|
+
tags: ["billing", "usage", "metrics"],
|
|
35
|
+
stability: StabilityEnum.Beta,
|
|
36
|
+
goal: "Monitor feature usage and limits",
|
|
37
|
+
context: "Billing section"
|
|
38
|
+
},
|
|
39
|
+
source: {
|
|
40
|
+
type: "component",
|
|
41
|
+
framework: "react",
|
|
42
|
+
componentKey: "UsageDashboardView"
|
|
43
|
+
},
|
|
44
|
+
targets: ["react", "markdown"],
|
|
45
|
+
policy: {
|
|
46
|
+
flags: ["saas.billing.enabled"]
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
export {
|
|
50
|
+
UsageDashboardPresentation,
|
|
51
|
+
SubscriptionPresentation
|
|
52
|
+
};
|