@lssm/lib.metering 0.0.0-canary-20251217083314 → 1.41.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aggregation/index.js +1 -271
- package/dist/contracts/index.js +1 -1034
- package/dist/docs/index.js +1 -1
- package/dist/docs/metering.docblock.js +2 -22
- package/dist/entities/index.js +1 -418
- package/dist/events.js +1 -379
- package/dist/index.js +1 -8
- package/dist/metering.feature.js +1 -125
- package/package.json +13 -13
- package/dist/aggregation/index.d.ts +0 -155
- package/dist/contracts/dist/capabilities/openbanking.js +0 -88
- package/dist/contracts/dist/client/index.js +0 -5
- package/dist/contracts/dist/client/react/feature-render.js +0 -2
- package/dist/contracts/dist/client/react/form-render.js +0 -4
- package/dist/contracts/dist/client/react/index.js +0 -4
- package/dist/contracts/dist/contract-registry/index.js +0 -1
- package/dist/contracts/dist/contract-registry/schemas.js +0 -60
- package/dist/contracts/dist/docs/PUBLISHING.docblock.js +0 -16
- package/dist/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +0 -16
- package/dist/contracts/dist/docs/index.js +0 -29
- package/dist/contracts/dist/docs/presentations.js +0 -71
- package/dist/contracts/dist/docs/registry.js +0 -44
- package/dist/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +0 -80
- package/dist/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +0 -57
- package/dist/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/llm/llm-integration.docblock.js +0 -357
- package/dist/contracts/dist/docs/tech/mcp-endpoints.docblock.js +0 -37
- package/dist/contracts/dist/docs/tech/presentation-runtime.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/schema/README.docblock.js +0 -20
- package/dist/contracts/dist/docs/tech/studio/learning-events.docblock.js +0 -48
- package/dist/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +0 -79
- package/dist/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +0 -84
- package/dist/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +0 -45
- package/dist/contracts/dist/docs/tech/studio/project-routing.docblock.js +0 -67
- package/dist/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +0 -40
- package/dist/contracts/dist/docs/tech/studio/team-invitations.docblock.js +0 -69
- package/dist/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +0 -47
- package/dist/contracts/dist/docs/tech/studio/workspaces.docblock.js +0 -62
- package/dist/contracts/dist/docs/tech/telemetry-ingest.docblock.js +0 -155
- package/dist/contracts/dist/docs/tech/templates/runtime.docblock.js +0 -20
- package/dist/contracts/dist/docs/tech/vscode-extension.docblock.js +0 -101
- package/dist/contracts/dist/docs/tech/workflows/overview.docblock.js +0 -20
- package/dist/contracts/dist/events.js +0 -10
- package/dist/contracts/dist/experiments/evaluator.js +0 -1
- package/dist/contracts/dist/index.js +0 -71
- package/dist/contracts/dist/install.js +0 -2
- package/dist/contracts/dist/integrations/contracts.js +0 -377
- package/dist/contracts/dist/integrations/index.js +0 -18
- package/dist/contracts/dist/integrations/openbanking/contracts/accounts.js +0 -228
- package/dist/contracts/dist/integrations/openbanking/contracts/balances.js +0 -159
- package/dist/contracts/dist/integrations/openbanking/contracts/index.js +0 -3
- package/dist/contracts/dist/integrations/openbanking/contracts/transactions.js +0 -210
- package/dist/contracts/dist/integrations/openbanking/models.js +0 -242
- package/dist/contracts/dist/integrations/openbanking/telemetry.js +0 -13
- package/dist/contracts/dist/integrations/providers/elevenlabs.js +0 -52
- package/dist/contracts/dist/integrations/providers/gcs-storage.js +0 -75
- package/dist/contracts/dist/integrations/providers/gmail.js +0 -87
- package/dist/contracts/dist/integrations/providers/google-calendar.js +0 -66
- package/dist/contracts/dist/integrations/providers/index.js +0 -11
- package/dist/contracts/dist/integrations/providers/mistral.js +0 -68
- package/dist/contracts/dist/integrations/providers/postmark.js +0 -68
- package/dist/contracts/dist/integrations/providers/powens.js +0 -116
- package/dist/contracts/dist/integrations/providers/qdrant.js +0 -73
- package/dist/contracts/dist/integrations/providers/registry.js +0 -10
- package/dist/contracts/dist/integrations/providers/stripe.js +0 -83
- package/dist/contracts/dist/integrations/providers/twilio-sms.js +0 -61
- package/dist/contracts/dist/jsonschema.js +0 -1
- package/dist/contracts/dist/knowledge/contracts.js +0 -306
- package/dist/contracts/dist/knowledge/index.js +0 -7
- package/dist/contracts/dist/knowledge/spaces/email-threads.js +0 -34
- package/dist/contracts/dist/knowledge/spaces/financial-docs.js +0 -34
- package/dist/contracts/dist/knowledge/spaces/financial-overview.js +0 -38
- package/dist/contracts/dist/knowledge/spaces/index.js +0 -6
- package/dist/contracts/dist/knowledge/spaces/product-canon.js +0 -34
- package/dist/contracts/dist/knowledge/spaces/support-faq.js +0 -37
- package/dist/contracts/dist/knowledge/spaces/uploaded-docs.js +0 -34
- package/dist/contracts/dist/llm/exporters.js +0 -19
- package/dist/contracts/dist/llm/index.js +0 -2
- package/dist/contracts/dist/llm/prompts.js +0 -1
- package/dist/contracts/dist/onboarding-base.js +0 -196
- package/dist/contracts/dist/openapi.js +0 -1
- package/dist/contracts/dist/ownership.js +0 -21
- package/dist/contracts/dist/presentations.js +0 -1
- package/dist/contracts/dist/presentations.v2.js +0 -11
- package/dist/contracts/dist/prompt.js +0 -1
- package/dist/contracts/dist/promptRegistry.js +0 -1
- package/dist/contracts/dist/regenerator/index.js +0 -1
- package/dist/contracts/dist/regenerator/service.js +0 -6
- package/dist/contracts/dist/registry.js +0 -2
- package/dist/contracts/dist/resources.js +0 -1
- package/dist/contracts/dist/schema/dist/EnumType.js +0 -2
- package/dist/contracts/dist/schema/dist/FieldType.js +0 -49
- package/dist/contracts/dist/schema/dist/ScalarTypeEnum.js +0 -236
- package/dist/contracts/dist/schema/dist/SchemaModel.js +0 -34
- package/dist/contracts/dist/schema/dist/entity/defineEntity.js +0 -1
- package/dist/contracts/dist/schema/dist/entity/index.js +0 -2
- package/dist/contracts/dist/schema/dist/entity/types.js +0 -1
- package/dist/contracts/dist/schema/dist/index.js +0 -6
- package/dist/contracts/dist/server/graphql-pothos.js +0 -6
- package/dist/contracts/dist/server/index.js +0 -8
- package/dist/contracts/dist/server/mcp/createMcpServer.js +0 -4
- package/dist/contracts/dist/server/mcp/registerPresentations.js +0 -2
- package/dist/contracts/dist/server/mcp/registerPrompts.js +0 -1
- package/dist/contracts/dist/server/mcp/registerResources.js +0 -2
- package/dist/contracts/dist/server/mcp/registerTools.js +0 -1
- package/dist/contracts/dist/server/provider-mcp.js +0 -1
- package/dist/contracts/dist/server/rest-elysia.js +0 -1
- package/dist/contracts/dist/server/rest-express.js +0 -1
- package/dist/contracts/dist/server/rest-generic.js +0 -1
- package/dist/contracts/dist/server/rest-next-app.js +0 -1
- package/dist/contracts/dist/server/rest-next-pages.js +0 -1
- package/dist/contracts/dist/spec.js +0 -34
- package/dist/contracts/dist/telemetry/index.js +0 -1
- package/dist/contracts/dist/telemetry/tracker.js +0 -1
- package/dist/contracts/dist/tests/index.js +0 -1
- package/dist/contracts/dist/tests/runner.js +0 -2
- package/dist/contracts/dist/workflow/index.js +0 -1
- package/dist/contracts/dist/workflow/runner.js +0 -1
- package/dist/contracts/index.d.ts +0 -1138
- package/dist/docs/index.d.ts +0 -1
- package/dist/docs/metering.docblock.d.ts +0 -1
- package/dist/entities/index.d.ts +0 -230
- package/dist/events.d.ts +0 -539
- package/dist/index.d.ts +0 -6
- package/dist/metering.feature.d.ts +0 -11
- package/dist/schema/dist/EnumType.js +0 -2
- package/dist/schema/dist/FieldType.js +0 -49
- package/dist/schema/dist/ScalarTypeEnum.js +0 -236
- package/dist/schema/dist/SchemaModel.js +0 -39
- package/dist/schema/dist/entity/defineEntity.js +0 -236
- package/dist/schema/dist/entity/index.js +0 -2
- package/dist/schema/dist/entity/types.js +0 -1
- package/dist/schema/dist/index.js +0 -6
package/dist/docs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import"./metering.docblock.js";
|
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "../contracts/dist/docs/index.js";
|
|
3
|
-
|
|
4
|
-
//#region src/docs/metering.docblock.ts
|
|
5
|
-
registerDocBlocks([{
|
|
6
|
-
id: "docs.metering.usage",
|
|
7
|
-
title: "Usage Metering & Billing Core",
|
|
8
|
-
summary: "Reusable usage/metering layer with metric definitions, usage ingestion, aggregation, thresholds, and alerts for billing or quotas.",
|
|
9
|
-
kind: "reference",
|
|
10
|
-
visibility: "public",
|
|
11
|
-
route: "/docs/metering/usage",
|
|
12
|
-
tags: [
|
|
13
|
-
"metering",
|
|
14
|
-
"usage",
|
|
15
|
-
"billing",
|
|
16
|
-
"quotas"
|
|
17
|
-
],
|
|
18
|
-
body: `## Capabilities
|
|
1
|
+
import{registerDocBlocks as e}from"@lssm/lib.contracts/docs";e([{id:`docs.metering.usage`,title:`Usage Metering & Billing Core`,summary:`Reusable usage/metering layer with metric definitions, usage ingestion, aggregation, thresholds, and alerts for billing or quotas.`,kind:`reference`,visibility:`public`,route:`/docs/metering/usage`,tags:[`metering`,`usage`,`billing`,`quotas`],body:`## Capabilities
|
|
19
2
|
|
|
20
3
|
- **Entities**: MetricDefinition, UsageRecord, UsageSummary, UsageThreshold, UsageAlert.
|
|
21
4
|
- **Contracts**: define/list metrics; record usage (batch + idempotent); retrieve usage by subject; manage thresholds and alerts.
|
|
@@ -61,7 +44,4 @@ await aggregateUsage({
|
|
|
61
44
|
- Keep metric keys stable; store quantities as decimals for currency/units.
|
|
62
45
|
- Use idempotency keys for external ingestion; avoid PII in metric metadata.
|
|
63
46
|
- Scope by org/user for multi-tenant isolation; emit audit + analytics events on changes.
|
|
64
|
-
`
|
|
65
|
-
}]);
|
|
66
|
-
|
|
67
|
-
//#endregion
|
|
47
|
+
`}]);
|
package/dist/entities/index.js
CHANGED
|
@@ -1,418 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../schema/dist/index.js";
|
|
3
|
-
|
|
4
|
-
//#region src/entities/index.ts
|
|
5
|
-
/**
|
|
6
|
-
* Aggregation type enum.
|
|
7
|
-
*/
|
|
8
|
-
const AggregationTypeEnum = defineEntityEnum({
|
|
9
|
-
name: "AggregationType",
|
|
10
|
-
values: [
|
|
11
|
-
"COUNT",
|
|
12
|
-
"SUM",
|
|
13
|
-
"AVG",
|
|
14
|
-
"MAX",
|
|
15
|
-
"MIN",
|
|
16
|
-
"LAST"
|
|
17
|
-
],
|
|
18
|
-
schema: "lssm_metering",
|
|
19
|
-
description: "How to aggregate metric values."
|
|
20
|
-
});
|
|
21
|
-
/**
|
|
22
|
-
* Reset period enum.
|
|
23
|
-
*/
|
|
24
|
-
const ResetPeriodEnum = defineEntityEnum({
|
|
25
|
-
name: "ResetPeriod",
|
|
26
|
-
values: [
|
|
27
|
-
"NEVER",
|
|
28
|
-
"HOURLY",
|
|
29
|
-
"DAILY",
|
|
30
|
-
"WEEKLY",
|
|
31
|
-
"MONTHLY",
|
|
32
|
-
"YEARLY"
|
|
33
|
-
],
|
|
34
|
-
schema: "lssm_metering",
|
|
35
|
-
description: "When to reset metric counters."
|
|
36
|
-
});
|
|
37
|
-
/**
|
|
38
|
-
* Period type enum.
|
|
39
|
-
*/
|
|
40
|
-
const PeriodTypeEnum = defineEntityEnum({
|
|
41
|
-
name: "PeriodType",
|
|
42
|
-
values: [
|
|
43
|
-
"HOURLY",
|
|
44
|
-
"DAILY",
|
|
45
|
-
"WEEKLY",
|
|
46
|
-
"MONTHLY",
|
|
47
|
-
"YEARLY"
|
|
48
|
-
],
|
|
49
|
-
schema: "lssm_metering",
|
|
50
|
-
description: "Time period for aggregation."
|
|
51
|
-
});
|
|
52
|
-
/**
|
|
53
|
-
* Threshold action enum.
|
|
54
|
-
*/
|
|
55
|
-
const ThresholdActionEnum = defineEntityEnum({
|
|
56
|
-
name: "ThresholdAction",
|
|
57
|
-
values: [
|
|
58
|
-
"NONE",
|
|
59
|
-
"ALERT",
|
|
60
|
-
"WARN",
|
|
61
|
-
"BLOCK",
|
|
62
|
-
"DOWNGRADE"
|
|
63
|
-
],
|
|
64
|
-
schema: "lssm_metering",
|
|
65
|
-
description: "Action to take when threshold is exceeded."
|
|
66
|
-
});
|
|
67
|
-
/**
|
|
68
|
-
* MetricDefinition entity - defines a trackable metric.
|
|
69
|
-
*/
|
|
70
|
-
const MetricDefinitionEntity = defineEntity({
|
|
71
|
-
name: "MetricDefinition",
|
|
72
|
-
description: "Definition of a usage metric.",
|
|
73
|
-
schema: "lssm_metering",
|
|
74
|
-
map: "metric_definition",
|
|
75
|
-
fields: {
|
|
76
|
-
id: field.id({ description: "Unique identifier" }),
|
|
77
|
-
key: field.string({
|
|
78
|
-
isUnique: true,
|
|
79
|
-
description: "Metric key (e.g., api_calls, storage_gb)"
|
|
80
|
-
}),
|
|
81
|
-
name: field.string({ description: "Human-readable name" }),
|
|
82
|
-
description: field.string({
|
|
83
|
-
isOptional: true,
|
|
84
|
-
description: "Metric description"
|
|
85
|
-
}),
|
|
86
|
-
unit: field.string({ description: "Unit of measurement (calls, bytes, etc.)" }),
|
|
87
|
-
aggregationType: field.enum("AggregationType", {
|
|
88
|
-
default: "SUM",
|
|
89
|
-
description: "How to aggregate values"
|
|
90
|
-
}),
|
|
91
|
-
resetPeriod: field.enum("ResetPeriod", {
|
|
92
|
-
default: "MONTHLY",
|
|
93
|
-
description: "When to reset counters"
|
|
94
|
-
}),
|
|
95
|
-
precision: field.int({
|
|
96
|
-
default: 2,
|
|
97
|
-
description: "Decimal precision"
|
|
98
|
-
}),
|
|
99
|
-
orgId: field.string({
|
|
100
|
-
isOptional: true,
|
|
101
|
-
description: "Organization scope (null = global metric)"
|
|
102
|
-
}),
|
|
103
|
-
category: field.string({
|
|
104
|
-
isOptional: true,
|
|
105
|
-
description: "Category for grouping"
|
|
106
|
-
}),
|
|
107
|
-
displayOrder: field.int({
|
|
108
|
-
default: 0,
|
|
109
|
-
description: "Order for display"
|
|
110
|
-
}),
|
|
111
|
-
metadata: field.json({
|
|
112
|
-
isOptional: true,
|
|
113
|
-
description: "Additional metadata"
|
|
114
|
-
}),
|
|
115
|
-
isActive: field.boolean({
|
|
116
|
-
default: true,
|
|
117
|
-
description: "Whether metric is active"
|
|
118
|
-
}),
|
|
119
|
-
createdAt: field.createdAt(),
|
|
120
|
-
updatedAt: field.updatedAt(),
|
|
121
|
-
usageRecords: field.hasMany("UsageRecord"),
|
|
122
|
-
usageSummaries: field.hasMany("UsageSummary"),
|
|
123
|
-
thresholds: field.hasMany("UsageThreshold")
|
|
124
|
-
},
|
|
125
|
-
indexes: [
|
|
126
|
-
index.on(["orgId", "key"]),
|
|
127
|
-
index.on(["category"]),
|
|
128
|
-
index.on(["isActive"])
|
|
129
|
-
],
|
|
130
|
-
enums: [AggregationTypeEnum, ResetPeriodEnum]
|
|
131
|
-
});
|
|
132
|
-
/**
|
|
133
|
-
* UsageRecord entity - individual usage event.
|
|
134
|
-
*/
|
|
135
|
-
const UsageRecordEntity = defineEntity({
|
|
136
|
-
name: "UsageRecord",
|
|
137
|
-
description: "A single usage event.",
|
|
138
|
-
schema: "lssm_metering",
|
|
139
|
-
map: "usage_record",
|
|
140
|
-
fields: {
|
|
141
|
-
id: field.id({ description: "Unique identifier" }),
|
|
142
|
-
metricKey: field.string({ description: "Metric being recorded" }),
|
|
143
|
-
metricId: field.string({
|
|
144
|
-
isOptional: true,
|
|
145
|
-
description: "Metric ID (for FK)"
|
|
146
|
-
}),
|
|
147
|
-
subjectType: field.string({ description: "Subject type (org, user, project)" }),
|
|
148
|
-
subjectId: field.string({ description: "Subject identifier" }),
|
|
149
|
-
quantity: field.decimal({ description: "Usage quantity" }),
|
|
150
|
-
source: field.string({
|
|
151
|
-
isOptional: true,
|
|
152
|
-
description: "Source of usage (endpoint, feature, etc.)"
|
|
153
|
-
}),
|
|
154
|
-
resourceId: field.string({
|
|
155
|
-
isOptional: true,
|
|
156
|
-
description: "Related resource ID"
|
|
157
|
-
}),
|
|
158
|
-
resourceType: field.string({
|
|
159
|
-
isOptional: true,
|
|
160
|
-
description: "Related resource type"
|
|
161
|
-
}),
|
|
162
|
-
metadata: field.json({
|
|
163
|
-
isOptional: true,
|
|
164
|
-
description: "Additional context"
|
|
165
|
-
}),
|
|
166
|
-
idempotencyKey: field.string({
|
|
167
|
-
isOptional: true,
|
|
168
|
-
description: "Idempotency key for deduplication"
|
|
169
|
-
}),
|
|
170
|
-
timestamp: field.dateTime({ description: "When usage occurred" }),
|
|
171
|
-
createdAt: field.createdAt(),
|
|
172
|
-
aggregated: field.boolean({
|
|
173
|
-
default: false,
|
|
174
|
-
description: "Whether included in summary"
|
|
175
|
-
}),
|
|
176
|
-
aggregatedAt: field.dateTime({
|
|
177
|
-
isOptional: true,
|
|
178
|
-
description: "When aggregated"
|
|
179
|
-
})
|
|
180
|
-
},
|
|
181
|
-
indexes: [
|
|
182
|
-
index.on([
|
|
183
|
-
"metricKey",
|
|
184
|
-
"subjectType",
|
|
185
|
-
"subjectId",
|
|
186
|
-
"timestamp"
|
|
187
|
-
]),
|
|
188
|
-
index.on([
|
|
189
|
-
"subjectType",
|
|
190
|
-
"subjectId",
|
|
191
|
-
"timestamp"
|
|
192
|
-
]),
|
|
193
|
-
index.on(["timestamp"]),
|
|
194
|
-
index.on(["aggregated", "timestamp"]),
|
|
195
|
-
index.unique(["idempotencyKey"], { name: "usage_record_idempotency" })
|
|
196
|
-
]
|
|
197
|
-
});
|
|
198
|
-
/**
|
|
199
|
-
* UsageSummary entity - pre-aggregated usage.
|
|
200
|
-
*/
|
|
201
|
-
const UsageSummaryEntity = defineEntity({
|
|
202
|
-
name: "UsageSummary",
|
|
203
|
-
description: "Pre-aggregated usage summary.",
|
|
204
|
-
schema: "lssm_metering",
|
|
205
|
-
map: "usage_summary",
|
|
206
|
-
fields: {
|
|
207
|
-
id: field.id({ description: "Unique identifier" }),
|
|
208
|
-
metricKey: field.string({ description: "Metric key" }),
|
|
209
|
-
metricId: field.string({
|
|
210
|
-
isOptional: true,
|
|
211
|
-
description: "Metric ID (for FK)"
|
|
212
|
-
}),
|
|
213
|
-
subjectType: field.string({ description: "Subject type" }),
|
|
214
|
-
subjectId: field.string({ description: "Subject identifier" }),
|
|
215
|
-
periodType: field.enum("PeriodType", { description: "Period type" }),
|
|
216
|
-
periodStart: field.dateTime({ description: "Period start time" }),
|
|
217
|
-
periodEnd: field.dateTime({ description: "Period end time" }),
|
|
218
|
-
totalQuantity: field.decimal({ description: "Total/aggregated quantity" }),
|
|
219
|
-
recordCount: field.int({
|
|
220
|
-
default: 0,
|
|
221
|
-
description: "Number of records aggregated"
|
|
222
|
-
}),
|
|
223
|
-
minQuantity: field.decimal({
|
|
224
|
-
isOptional: true,
|
|
225
|
-
description: "Minimum value"
|
|
226
|
-
}),
|
|
227
|
-
maxQuantity: field.decimal({
|
|
228
|
-
isOptional: true,
|
|
229
|
-
description: "Maximum value"
|
|
230
|
-
}),
|
|
231
|
-
avgQuantity: field.decimal({
|
|
232
|
-
isOptional: true,
|
|
233
|
-
description: "Average value"
|
|
234
|
-
}),
|
|
235
|
-
metadata: field.json({
|
|
236
|
-
isOptional: true,
|
|
237
|
-
description: "Additional metadata"
|
|
238
|
-
}),
|
|
239
|
-
createdAt: field.createdAt(),
|
|
240
|
-
updatedAt: field.updatedAt()
|
|
241
|
-
},
|
|
242
|
-
indexes: [
|
|
243
|
-
index.unique([
|
|
244
|
-
"metricKey",
|
|
245
|
-
"subjectType",
|
|
246
|
-
"subjectId",
|
|
247
|
-
"periodType",
|
|
248
|
-
"periodStart"
|
|
249
|
-
], { name: "usage_summary_unique" }),
|
|
250
|
-
index.on([
|
|
251
|
-
"subjectType",
|
|
252
|
-
"subjectId",
|
|
253
|
-
"periodType",
|
|
254
|
-
"periodStart"
|
|
255
|
-
]),
|
|
256
|
-
index.on([
|
|
257
|
-
"metricKey",
|
|
258
|
-
"periodType",
|
|
259
|
-
"periodStart"
|
|
260
|
-
])
|
|
261
|
-
],
|
|
262
|
-
enums: [PeriodTypeEnum]
|
|
263
|
-
});
|
|
264
|
-
/**
|
|
265
|
-
* UsageThreshold entity - threshold configuration.
|
|
266
|
-
*/
|
|
267
|
-
const UsageThresholdEntity = defineEntity({
|
|
268
|
-
name: "UsageThreshold",
|
|
269
|
-
description: "Usage threshold configuration.",
|
|
270
|
-
schema: "lssm_metering",
|
|
271
|
-
map: "usage_threshold",
|
|
272
|
-
fields: {
|
|
273
|
-
id: field.id({ description: "Unique identifier" }),
|
|
274
|
-
metricKey: field.string({ description: "Metric to monitor" }),
|
|
275
|
-
metricId: field.string({
|
|
276
|
-
isOptional: true,
|
|
277
|
-
description: "Metric ID (for FK)"
|
|
278
|
-
}),
|
|
279
|
-
subjectType: field.string({
|
|
280
|
-
isOptional: true,
|
|
281
|
-
description: "Subject type"
|
|
282
|
-
}),
|
|
283
|
-
subjectId: field.string({
|
|
284
|
-
isOptional: true,
|
|
285
|
-
description: "Subject identifier"
|
|
286
|
-
}),
|
|
287
|
-
name: field.string({ description: "Threshold name" }),
|
|
288
|
-
threshold: field.decimal({ description: "Threshold value" }),
|
|
289
|
-
warnThreshold: field.decimal({
|
|
290
|
-
isOptional: true,
|
|
291
|
-
description: "Warning threshold (e.g., 80%)"
|
|
292
|
-
}),
|
|
293
|
-
periodType: field.enum("PeriodType", {
|
|
294
|
-
default: "MONTHLY",
|
|
295
|
-
description: "Period to evaluate"
|
|
296
|
-
}),
|
|
297
|
-
action: field.enum("ThresholdAction", {
|
|
298
|
-
default: "ALERT",
|
|
299
|
-
description: "Action when exceeded"
|
|
300
|
-
}),
|
|
301
|
-
notifyEmails: field.json({
|
|
302
|
-
isOptional: true,
|
|
303
|
-
description: "Email addresses to notify"
|
|
304
|
-
}),
|
|
305
|
-
notifyWebhook: field.string({
|
|
306
|
-
isOptional: true,
|
|
307
|
-
description: "Webhook URL to call"
|
|
308
|
-
}),
|
|
309
|
-
currentValue: field.decimal({
|
|
310
|
-
default: 0,
|
|
311
|
-
description: "Current usage value"
|
|
312
|
-
}),
|
|
313
|
-
lastCheckedAt: field.dateTime({
|
|
314
|
-
isOptional: true,
|
|
315
|
-
description: "Last threshold check"
|
|
316
|
-
}),
|
|
317
|
-
lastExceededAt: field.dateTime({
|
|
318
|
-
isOptional: true,
|
|
319
|
-
description: "Last time threshold was exceeded"
|
|
320
|
-
}),
|
|
321
|
-
isActive: field.boolean({
|
|
322
|
-
default: true,
|
|
323
|
-
description: "Whether threshold is active"
|
|
324
|
-
}),
|
|
325
|
-
metadata: field.json({
|
|
326
|
-
isOptional: true,
|
|
327
|
-
description: "Additional metadata"
|
|
328
|
-
}),
|
|
329
|
-
createdAt: field.createdAt(),
|
|
330
|
-
updatedAt: field.updatedAt()
|
|
331
|
-
},
|
|
332
|
-
indexes: [
|
|
333
|
-
index.on(["metricKey"]),
|
|
334
|
-
index.on(["subjectType", "subjectId"]),
|
|
335
|
-
index.on(["isActive", "metricKey"])
|
|
336
|
-
],
|
|
337
|
-
enums: [ThresholdActionEnum]
|
|
338
|
-
});
|
|
339
|
-
/**
|
|
340
|
-
* UsageAlert entity - threshold violation alerts.
|
|
341
|
-
*/
|
|
342
|
-
const UsageAlertEntity = defineEntity({
|
|
343
|
-
name: "UsageAlert",
|
|
344
|
-
description: "Alert generated when threshold is exceeded.",
|
|
345
|
-
schema: "lssm_metering",
|
|
346
|
-
map: "usage_alert",
|
|
347
|
-
fields: {
|
|
348
|
-
id: field.id({ description: "Unique identifier" }),
|
|
349
|
-
thresholdId: field.foreignKey({ description: "Threshold that triggered alert" }),
|
|
350
|
-
metricKey: field.string({ description: "Metric key" }),
|
|
351
|
-
subjectType: field.string({
|
|
352
|
-
isOptional: true,
|
|
353
|
-
description: "Subject type"
|
|
354
|
-
}),
|
|
355
|
-
subjectId: field.string({
|
|
356
|
-
isOptional: true,
|
|
357
|
-
description: "Subject identifier"
|
|
358
|
-
}),
|
|
359
|
-
alertType: field.string({ description: "Alert type (warn, exceed, etc.)" }),
|
|
360
|
-
threshold: field.decimal({ description: "Threshold value" }),
|
|
361
|
-
actualValue: field.decimal({ description: "Actual usage value" }),
|
|
362
|
-
percentageUsed: field.decimal({ description: "Percentage of threshold used" }),
|
|
363
|
-
status: field.string({
|
|
364
|
-
default: "\"pending\"",
|
|
365
|
-
description: "Alert status (pending, acknowledged, resolved)"
|
|
366
|
-
}),
|
|
367
|
-
acknowledgedBy: field.string({
|
|
368
|
-
isOptional: true,
|
|
369
|
-
description: "User who acknowledged"
|
|
370
|
-
}),
|
|
371
|
-
acknowledgedAt: field.dateTime({
|
|
372
|
-
isOptional: true,
|
|
373
|
-
description: "When acknowledged"
|
|
374
|
-
}),
|
|
375
|
-
resolvedAt: field.dateTime({
|
|
376
|
-
isOptional: true,
|
|
377
|
-
description: "When resolved"
|
|
378
|
-
}),
|
|
379
|
-
notificationsSent: field.json({
|
|
380
|
-
isOptional: true,
|
|
381
|
-
description: "Notifications sent"
|
|
382
|
-
}),
|
|
383
|
-
triggeredAt: field.dateTime({ description: "When alert was triggered" }),
|
|
384
|
-
createdAt: field.createdAt(),
|
|
385
|
-
thresholdRelation: field.belongsTo("UsageThreshold", ["thresholdId"], ["id"], { onDelete: "Cascade" })
|
|
386
|
-
},
|
|
387
|
-
indexes: [
|
|
388
|
-
index.on(["thresholdId", "status"]),
|
|
389
|
-
index.on(["metricKey", "triggeredAt"]),
|
|
390
|
-
index.on(["status", "triggeredAt"])
|
|
391
|
-
]
|
|
392
|
-
});
|
|
393
|
-
/**
|
|
394
|
-
* All metering entities for schema composition.
|
|
395
|
-
*/
|
|
396
|
-
const meteringEntities = [
|
|
397
|
-
MetricDefinitionEntity,
|
|
398
|
-
UsageRecordEntity,
|
|
399
|
-
UsageSummaryEntity,
|
|
400
|
-
UsageThresholdEntity,
|
|
401
|
-
UsageAlertEntity
|
|
402
|
-
];
|
|
403
|
-
/**
|
|
404
|
-
* Module schema contribution for metering.
|
|
405
|
-
*/
|
|
406
|
-
const meteringSchemaContribution = {
|
|
407
|
-
moduleId: "@lssm/lib.metering",
|
|
408
|
-
entities: meteringEntities,
|
|
409
|
-
enums: [
|
|
410
|
-
AggregationTypeEnum,
|
|
411
|
-
ResetPeriodEnum,
|
|
412
|
-
PeriodTypeEnum,
|
|
413
|
-
ThresholdActionEnum
|
|
414
|
-
]
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
//#endregion
|
|
418
|
-
export { AggregationTypeEnum, MetricDefinitionEntity, PeriodTypeEnum, ResetPeriodEnum, ThresholdActionEnum, UsageAlertEntity, UsageRecordEntity, UsageSummaryEntity, UsageThresholdEntity, meteringEntities, meteringSchemaContribution };
|
|
1
|
+
import{defineEntity as e,defineEntityEnum as t,field as n,index as r}from"@lssm/lib.schema";const i=t({name:`AggregationType`,values:[`COUNT`,`SUM`,`AVG`,`MAX`,`MIN`,`LAST`],schema:`lssm_metering`,description:`How to aggregate metric values.`}),a=t({name:`ResetPeriod`,values:[`NEVER`,`HOURLY`,`DAILY`,`WEEKLY`,`MONTHLY`,`YEARLY`],schema:`lssm_metering`,description:`When to reset metric counters.`}),o=t({name:`PeriodType`,values:[`HOURLY`,`DAILY`,`WEEKLY`,`MONTHLY`,`YEARLY`],schema:`lssm_metering`,description:`Time period for aggregation.`}),s=t({name:`ThresholdAction`,values:[`NONE`,`ALERT`,`WARN`,`BLOCK`,`DOWNGRADE`],schema:`lssm_metering`,description:`Action to take when threshold is exceeded.`}),c=e({name:`MetricDefinition`,description:`Definition of a usage metric.`,schema:`lssm_metering`,map:`metric_definition`,fields:{id:n.id({description:`Unique identifier`}),key:n.string({isUnique:!0,description:`Metric key (e.g., api_calls, storage_gb)`}),name:n.string({description:`Human-readable name`}),description:n.string({isOptional:!0,description:`Metric description`}),unit:n.string({description:`Unit of measurement (calls, bytes, etc.)`}),aggregationType:n.enum(`AggregationType`,{default:`SUM`,description:`How to aggregate values`}),resetPeriod:n.enum(`ResetPeriod`,{default:`MONTHLY`,description:`When to reset counters`}),precision:n.int({default:2,description:`Decimal precision`}),orgId:n.string({isOptional:!0,description:`Organization scope (null = global metric)`}),category:n.string({isOptional:!0,description:`Category for grouping`}),displayOrder:n.int({default:0,description:`Order for display`}),metadata:n.json({isOptional:!0,description:`Additional metadata`}),isActive:n.boolean({default:!0,description:`Whether metric is active`}),createdAt:n.createdAt(),updatedAt:n.updatedAt(),usageRecords:n.hasMany(`UsageRecord`),usageSummaries:n.hasMany(`UsageSummary`),thresholds:n.hasMany(`UsageThreshold`)},indexes:[r.on([`orgId`,`key`]),r.on([`category`]),r.on([`isActive`])],enums:[i,a]}),l=e({name:`UsageRecord`,description:`A single usage event.`,schema:`lssm_metering`,map:`usage_record`,fields:{id:n.id({description:`Unique identifier`}),metricKey:n.string({description:`Metric being recorded`}),metricId:n.string({isOptional:!0,description:`Metric ID (for FK)`}),subjectType:n.string({description:`Subject type (org, user, project)`}),subjectId:n.string({description:`Subject identifier`}),quantity:n.decimal({description:`Usage quantity`}),source:n.string({isOptional:!0,description:`Source of usage (endpoint, feature, etc.)`}),resourceId:n.string({isOptional:!0,description:`Related resource ID`}),resourceType:n.string({isOptional:!0,description:`Related resource type`}),metadata:n.json({isOptional:!0,description:`Additional context`}),idempotencyKey:n.string({isOptional:!0,description:`Idempotency key for deduplication`}),timestamp:n.dateTime({description:`When usage occurred`}),createdAt:n.createdAt(),aggregated:n.boolean({default:!1,description:`Whether included in summary`}),aggregatedAt:n.dateTime({isOptional:!0,description:`When aggregated`})},indexes:[r.on([`metricKey`,`subjectType`,`subjectId`,`timestamp`]),r.on([`subjectType`,`subjectId`,`timestamp`]),r.on([`timestamp`]),r.on([`aggregated`,`timestamp`]),r.unique([`idempotencyKey`],{name:`usage_record_idempotency`})]}),u=e({name:`UsageSummary`,description:`Pre-aggregated usage summary.`,schema:`lssm_metering`,map:`usage_summary`,fields:{id:n.id({description:`Unique identifier`}),metricKey:n.string({description:`Metric key`}),metricId:n.string({isOptional:!0,description:`Metric ID (for FK)`}),subjectType:n.string({description:`Subject type`}),subjectId:n.string({description:`Subject identifier`}),periodType:n.enum(`PeriodType`,{description:`Period type`}),periodStart:n.dateTime({description:`Period start time`}),periodEnd:n.dateTime({description:`Period end time`}),totalQuantity:n.decimal({description:`Total/aggregated quantity`}),recordCount:n.int({default:0,description:`Number of records aggregated`}),minQuantity:n.decimal({isOptional:!0,description:`Minimum value`}),maxQuantity:n.decimal({isOptional:!0,description:`Maximum value`}),avgQuantity:n.decimal({isOptional:!0,description:`Average value`}),metadata:n.json({isOptional:!0,description:`Additional metadata`}),createdAt:n.createdAt(),updatedAt:n.updatedAt()},indexes:[r.unique([`metricKey`,`subjectType`,`subjectId`,`periodType`,`periodStart`],{name:`usage_summary_unique`}),r.on([`subjectType`,`subjectId`,`periodType`,`periodStart`]),r.on([`metricKey`,`periodType`,`periodStart`])],enums:[o]}),d=e({name:`UsageThreshold`,description:`Usage threshold configuration.`,schema:`lssm_metering`,map:`usage_threshold`,fields:{id:n.id({description:`Unique identifier`}),metricKey:n.string({description:`Metric to monitor`}),metricId:n.string({isOptional:!0,description:`Metric ID (for FK)`}),subjectType:n.string({isOptional:!0,description:`Subject type`}),subjectId:n.string({isOptional:!0,description:`Subject identifier`}),name:n.string({description:`Threshold name`}),threshold:n.decimal({description:`Threshold value`}),warnThreshold:n.decimal({isOptional:!0,description:`Warning threshold (e.g., 80%)`}),periodType:n.enum(`PeriodType`,{default:`MONTHLY`,description:`Period to evaluate`}),action:n.enum(`ThresholdAction`,{default:`ALERT`,description:`Action when exceeded`}),notifyEmails:n.json({isOptional:!0,description:`Email addresses to notify`}),notifyWebhook:n.string({isOptional:!0,description:`Webhook URL to call`}),currentValue:n.decimal({default:0,description:`Current usage value`}),lastCheckedAt:n.dateTime({isOptional:!0,description:`Last threshold check`}),lastExceededAt:n.dateTime({isOptional:!0,description:`Last time threshold was exceeded`}),isActive:n.boolean({default:!0,description:`Whether threshold is active`}),metadata:n.json({isOptional:!0,description:`Additional metadata`}),createdAt:n.createdAt(),updatedAt:n.updatedAt()},indexes:[r.on([`metricKey`]),r.on([`subjectType`,`subjectId`]),r.on([`isActive`,`metricKey`])],enums:[s]}),f=e({name:`UsageAlert`,description:`Alert generated when threshold is exceeded.`,schema:`lssm_metering`,map:`usage_alert`,fields:{id:n.id({description:`Unique identifier`}),thresholdId:n.foreignKey({description:`Threshold that triggered alert`}),metricKey:n.string({description:`Metric key`}),subjectType:n.string({isOptional:!0,description:`Subject type`}),subjectId:n.string({isOptional:!0,description:`Subject identifier`}),alertType:n.string({description:`Alert type (warn, exceed, etc.)`}),threshold:n.decimal({description:`Threshold value`}),actualValue:n.decimal({description:`Actual usage value`}),percentageUsed:n.decimal({description:`Percentage of threshold used`}),status:n.string({default:`"pending"`,description:`Alert status (pending, acknowledged, resolved)`}),acknowledgedBy:n.string({isOptional:!0,description:`User who acknowledged`}),acknowledgedAt:n.dateTime({isOptional:!0,description:`When acknowledged`}),resolvedAt:n.dateTime({isOptional:!0,description:`When resolved`}),notificationsSent:n.json({isOptional:!0,description:`Notifications sent`}),triggeredAt:n.dateTime({description:`When alert was triggered`}),createdAt:n.createdAt(),thresholdRelation:n.belongsTo(`UsageThreshold`,[`thresholdId`],[`id`],{onDelete:`Cascade`})},indexes:[r.on([`thresholdId`,`status`]),r.on([`metricKey`,`triggeredAt`]),r.on([`status`,`triggeredAt`])]}),p=[c,l,u,d,f],m={moduleId:`@lssm/lib.metering`,entities:p,enums:[i,a,o,s]};export{i as AggregationTypeEnum,c as MetricDefinitionEntity,o as PeriodTypeEnum,a as ResetPeriodEnum,s as ThresholdActionEnum,f as UsageAlertEntity,l as UsageRecordEntity,u as UsageSummaryEntity,d as UsageThresholdEntity,p as meteringEntities,m as meteringSchemaContribution};
|