@contractspec/lib.metering 3.7.17 → 3.7.18

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.
Files changed (34) hide show
  1. package/dist/aggregation/index.js +1 -265
  2. package/dist/analytics/posthog-metering-reader.js +4 -266
  3. package/dist/analytics/posthog-metering.js +1 -45
  4. package/dist/browser/aggregation/index.js +1 -265
  5. package/dist/browser/analytics/posthog-metering-reader.js +4 -266
  6. package/dist/browser/analytics/posthog-metering.js +1 -45
  7. package/dist/browser/contracts/index.js +1 -617
  8. package/dist/browser/docs/index.js +4 -18
  9. package/dist/browser/docs/metering.docblock.js +4 -18
  10. package/dist/browser/entities/index.js +1 -350
  11. package/dist/browser/events.js +1 -269
  12. package/dist/browser/index.js +7 -1877
  13. package/dist/browser/metering.capability.js +1 -31
  14. package/dist/browser/metering.feature.js +1 -53
  15. package/dist/contracts/index.js +1 -617
  16. package/dist/docs/index.js +4 -18
  17. package/dist/docs/metering.docblock.js +4 -18
  18. package/dist/entities/index.js +1 -350
  19. package/dist/events.js +1 -269
  20. package/dist/index.js +7 -1877
  21. package/dist/metering.capability.js +1 -31
  22. package/dist/metering.feature.js +1 -53
  23. package/dist/node/aggregation/index.js +1 -265
  24. package/dist/node/analytics/posthog-metering-reader.js +4 -266
  25. package/dist/node/analytics/posthog-metering.js +1 -45
  26. package/dist/node/contracts/index.js +1 -617
  27. package/dist/node/docs/index.js +4 -18
  28. package/dist/node/docs/metering.docblock.js +4 -18
  29. package/dist/node/entities/index.js +1 -350
  30. package/dist/node/events.js +1 -269
  31. package/dist/node/index.js +7 -1877
  32. package/dist/node/metering.capability.js +1 -31
  33. package/dist/node/metering.feature.js +1 -53
  34. package/package.json +6 -6
package/dist/events.js CHANGED
@@ -1,270 +1,2 @@
1
1
  // @bun
2
- // src/events.ts
3
- import { defineEvent } from "@contractspec/lib.contracts-spec";
4
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
5
- var MetricDefinedPayload = defineSchemaModel({
6
- name: "MetricDefinedEventPayload",
7
- description: "Payload when a metric is defined",
8
- fields: {
9
- metricId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
10
- key: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
11
- name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
12
- unit: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
13
- aggregationType: {
14
- type: ScalarTypeEnum.String_unsecure(),
15
- isOptional: false
16
- },
17
- orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
18
- createdBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
19
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
20
- }
21
- });
22
- var MetricUpdatedPayload = defineSchemaModel({
23
- name: "MetricUpdatedEventPayload",
24
- description: "Payload when a metric is updated",
25
- fields: {
26
- metricId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
27
- key: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
28
- changes: { type: ScalarTypeEnum.JSON(), isOptional: false },
29
- updatedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
30
- updatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
31
- }
32
- });
33
- var UsageRecordedPayload = defineSchemaModel({
34
- name: "UsageRecordedEventPayload",
35
- description: "Payload when usage is recorded",
36
- fields: {
37
- recordId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
38
- metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
39
- subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
40
- subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
41
- quantity: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
42
- source: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
43
- timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
44
- }
45
- });
46
- var UsageBatchRecordedPayload = defineSchemaModel({
47
- name: "UsageBatchRecordedEventPayload",
48
- description: "Payload when a batch of usage is recorded",
49
- fields: {
50
- recordCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
51
- metricKeys: { type: ScalarTypeEnum.JSON(), isOptional: false },
52
- totalQuantity: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
53
- timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
54
- }
55
- });
56
- var UsageAggregatedPayload = defineSchemaModel({
57
- name: "UsageAggregatedEventPayload",
58
- description: "Payload when usage is aggregated",
59
- fields: {
60
- summaryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
61
- metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
62
- subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
63
- subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
64
- periodType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
65
- periodStart: { type: ScalarTypeEnum.DateTime(), isOptional: false },
66
- periodEnd: { type: ScalarTypeEnum.DateTime(), isOptional: false },
67
- totalQuantity: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
68
- recordCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
69
- aggregatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
70
- }
71
- });
72
- var ThresholdCreatedPayload = defineSchemaModel({
73
- name: "ThresholdCreatedEventPayload",
74
- description: "Payload when a threshold is created",
75
- fields: {
76
- thresholdId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
77
- metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
78
- subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
79
- subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
80
- threshold: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
81
- action: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
82
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
83
- }
84
- });
85
- var ThresholdExceededPayload = defineSchemaModel({
86
- name: "ThresholdExceededEventPayload",
87
- description: "Payload when a threshold is exceeded",
88
- fields: {
89
- alertId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
90
- thresholdId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
91
- metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
92
- subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
93
- subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
94
- threshold: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
95
- actualValue: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
96
- percentageUsed: {
97
- type: ScalarTypeEnum.Float_unsecure(),
98
- isOptional: false
99
- },
100
- action: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
101
- triggeredAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
102
- }
103
- });
104
- var ThresholdApproachingPayload = defineSchemaModel({
105
- name: "ThresholdApproachingEventPayload",
106
- description: "Payload when usage is approaching a threshold",
107
- fields: {
108
- thresholdId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
109
- metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
110
- subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
111
- subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
112
- threshold: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
113
- currentValue: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
114
- percentageUsed: {
115
- type: ScalarTypeEnum.Float_unsecure(),
116
- isOptional: false
117
- },
118
- triggeredAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
119
- }
120
- });
121
- var MetricDefinedEvent = defineEvent({
122
- meta: {
123
- key: "metric.defined",
124
- version: "1.0.0",
125
- description: "A metric has been defined.",
126
- stability: "stable",
127
- owners: ["@platform.metering"],
128
- tags: ["metering", "metric"]
129
- },
130
- payload: MetricDefinedPayload
131
- });
132
- var MetricUpdatedEvent = defineEvent({
133
- meta: {
134
- key: "metric.updated",
135
- version: "1.0.0",
136
- description: "A metric has been updated.",
137
- stability: "stable",
138
- owners: ["@platform.metering"],
139
- tags: ["metering", "metric"]
140
- },
141
- payload: MetricUpdatedPayload
142
- });
143
- var UsageRecordedEvent = defineEvent({
144
- meta: {
145
- key: "usage.recorded",
146
- version: "1.0.0",
147
- description: "Usage has been recorded.",
148
- stability: "stable",
149
- owners: ["@platform.metering"],
150
- tags: ["metering", "usage"]
151
- },
152
- payload: UsageRecordedPayload
153
- });
154
- var UsageBatchRecordedEvent = defineEvent({
155
- meta: {
156
- key: "usage.batch_recorded",
157
- version: "1.0.0",
158
- description: "A batch of usage has been recorded.",
159
- stability: "stable",
160
- owners: ["@platform.metering"],
161
- tags: ["metering", "usage"]
162
- },
163
- payload: UsageBatchRecordedPayload
164
- });
165
- var UsageAggregatedEvent = defineEvent({
166
- meta: {
167
- key: "usage.aggregated",
168
- version: "1.0.0",
169
- description: "Usage has been aggregated into a summary.",
170
- stability: "stable",
171
- owners: ["@platform.metering"],
172
- tags: ["metering", "usage"]
173
- },
174
- payload: UsageAggregatedPayload
175
- });
176
- var ThresholdCreatedEvent = defineEvent({
177
- meta: {
178
- key: "threshold.created",
179
- version: "1.0.0",
180
- description: "A usage threshold has been created.",
181
- stability: "stable",
182
- owners: ["@platform.metering"],
183
- tags: ["metering", "threshold"]
184
- },
185
- payload: ThresholdCreatedPayload
186
- });
187
- var ThresholdExceededEvent = defineEvent({
188
- meta: {
189
- key: "threshold.exceeded",
190
- version: "1.0.0",
191
- description: "Usage has exceeded a threshold.",
192
- stability: "stable",
193
- owners: ["@platform.metering"],
194
- tags: ["metering", "threshold"]
195
- },
196
- payload: ThresholdExceededPayload
197
- });
198
- var ThresholdApproachingEvent = defineEvent({
199
- meta: {
200
- key: "threshold.approaching",
201
- version: "1.0.0",
202
- description: "Usage is approaching a threshold.",
203
- stability: "stable",
204
- owners: ["@platform.metering"],
205
- tags: ["metering", "threshold"]
206
- },
207
- payload: ThresholdApproachingPayload
208
- });
209
- var ModelSelectionPayload = defineSchemaModel({
210
- name: "ModelSelectionEventPayload",
211
- description: "Payload when an AI model is selected via ranking",
212
- fields: {
213
- modelId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
214
- providerKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
215
- dimension: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
216
- score: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
217
- reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
218
- alternativesCount: {
219
- type: ScalarTypeEnum.Int_unsecure(),
220
- isOptional: false
221
- },
222
- costEstimateInput: {
223
- type: ScalarTypeEnum.Float_unsecure(),
224
- isOptional: true
225
- },
226
- costEstimateOutput: {
227
- type: ScalarTypeEnum.Float_unsecure(),
228
- isOptional: true
229
- },
230
- selectionDurationMs: {
231
- type: ScalarTypeEnum.Float_unsecure(),
232
- isOptional: true
233
- },
234
- timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
235
- }
236
- });
237
- var ModelSelectionEvent = defineEvent({
238
- meta: {
239
- key: "model.selected",
240
- version: "1.0.0",
241
- description: "An AI model has been selected via ranking-driven selection.",
242
- stability: "experimental",
243
- owners: ["@platform.metering"],
244
- tags: ["metering", "ai", "model-selection"]
245
- },
246
- payload: ModelSelectionPayload
247
- });
248
- var MeteringEvents = {
249
- MetricDefinedEvent,
250
- MetricUpdatedEvent,
251
- UsageRecordedEvent,
252
- UsageBatchRecordedEvent,
253
- UsageAggregatedEvent,
254
- ThresholdCreatedEvent,
255
- ThresholdExceededEvent,
256
- ThresholdApproachingEvent,
257
- ModelSelectionEvent
258
- };
259
- export {
260
- UsageRecordedEvent,
261
- UsageBatchRecordedEvent,
262
- UsageAggregatedEvent,
263
- ThresholdExceededEvent,
264
- ThresholdCreatedEvent,
265
- ThresholdApproachingEvent,
266
- ModelSelectionEvent,
267
- MetricUpdatedEvent,
268
- MetricDefinedEvent,
269
- MeteringEvents
270
- };
2
+ import{defineEvent as k}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as q,ScalarTypeEnum as j}from"@contractspec/lib.schema";var w=q({name:"MetricDefinedEventPayload",description:"Payload when a metric is defined",fields:{metricId:{type:j.String_unsecure(),isOptional:!1},key:{type:j.String_unsecure(),isOptional:!1},name:{type:j.String_unsecure(),isOptional:!1},unit:{type:j.String_unsecure(),isOptional:!1},aggregationType:{type:j.String_unsecure(),isOptional:!1},orgId:{type:j.String_unsecure(),isOptional:!0},createdBy:{type:j.String_unsecure(),isOptional:!0},createdAt:{type:j.DateTime(),isOptional:!1}}}),z=q({name:"MetricUpdatedEventPayload",description:"Payload when a metric is updated",fields:{metricId:{type:j.String_unsecure(),isOptional:!1},key:{type:j.String_unsecure(),isOptional:!1},changes:{type:j.JSON(),isOptional:!1},updatedBy:{type:j.String_unsecure(),isOptional:!0},updatedAt:{type:j.DateTime(),isOptional:!1}}}),F=q({name:"UsageRecordedEventPayload",description:"Payload when usage is recorded",fields:{recordId:{type:j.String_unsecure(),isOptional:!1},metricKey:{type:j.String_unsecure(),isOptional:!1},subjectType:{type:j.String_unsecure(),isOptional:!1},subjectId:{type:j.String_unsecure(),isOptional:!1},quantity:{type:j.Float_unsecure(),isOptional:!1},source:{type:j.String_unsecure(),isOptional:!0},timestamp:{type:j.DateTime(),isOptional:!1}}}),G=q({name:"UsageBatchRecordedEventPayload",description:"Payload when a batch of usage is recorded",fields:{recordCount:{type:j.Int_unsecure(),isOptional:!1},metricKeys:{type:j.JSON(),isOptional:!1},totalQuantity:{type:j.Float_unsecure(),isOptional:!1},timestamp:{type:j.DateTime(),isOptional:!1}}}),H=q({name:"UsageAggregatedEventPayload",description:"Payload when usage is aggregated",fields:{summaryId:{type:j.String_unsecure(),isOptional:!1},metricKey:{type:j.String_unsecure(),isOptional:!1},subjectType:{type:j.String_unsecure(),isOptional:!1},subjectId:{type:j.String_unsecure(),isOptional:!1},periodType:{type:j.String_unsecure(),isOptional:!1},periodStart:{type:j.DateTime(),isOptional:!1},periodEnd:{type:j.DateTime(),isOptional:!1},totalQuantity:{type:j.Float_unsecure(),isOptional:!1},recordCount:{type:j.Int_unsecure(),isOptional:!1},aggregatedAt:{type:j.DateTime(),isOptional:!1}}}),I=q({name:"ThresholdCreatedEventPayload",description:"Payload when a threshold is created",fields:{thresholdId:{type:j.String_unsecure(),isOptional:!1},metricKey:{type:j.String_unsecure(),isOptional:!1},subjectType:{type:j.String_unsecure(),isOptional:!0},subjectId:{type:j.String_unsecure(),isOptional:!0},threshold:{type:j.Float_unsecure(),isOptional:!1},action:{type:j.String_unsecure(),isOptional:!1},createdAt:{type:j.DateTime(),isOptional:!1}}}),J=q({name:"ThresholdExceededEventPayload",description:"Payload when a threshold is exceeded",fields:{alertId:{type:j.String_unsecure(),isOptional:!1},thresholdId:{type:j.String_unsecure(),isOptional:!1},metricKey:{type:j.String_unsecure(),isOptional:!1},subjectType:{type:j.String_unsecure(),isOptional:!0},subjectId:{type:j.String_unsecure(),isOptional:!0},threshold:{type:j.Float_unsecure(),isOptional:!1},actualValue:{type:j.Float_unsecure(),isOptional:!1},percentageUsed:{type:j.Float_unsecure(),isOptional:!1},action:{type:j.String_unsecure(),isOptional:!1},triggeredAt:{type:j.DateTime(),isOptional:!1}}}),K=q({name:"ThresholdApproachingEventPayload",description:"Payload when usage is approaching a threshold",fields:{thresholdId:{type:j.String_unsecure(),isOptional:!1},metricKey:{type:j.String_unsecure(),isOptional:!1},subjectType:{type:j.String_unsecure(),isOptional:!0},subjectId:{type:j.String_unsecure(),isOptional:!0},threshold:{type:j.Float_unsecure(),isOptional:!1},currentValue:{type:j.Float_unsecure(),isOptional:!1},percentageUsed:{type:j.Float_unsecure(),isOptional:!1},triggeredAt:{type:j.DateTime(),isOptional:!1}}}),L=k({meta:{key:"metric.defined",version:"1.0.0",description:"A metric has been defined.",stability:"stable",owners:["@platform.metering"],tags:["metering","metric"]},payload:w}),N=k({meta:{key:"metric.updated",version:"1.0.0",description:"A metric has been updated.",stability:"stable",owners:["@platform.metering"],tags:["metering","metric"]},payload:z}),O=k({meta:{key:"usage.recorded",version:"1.0.0",description:"Usage has been recorded.",stability:"stable",owners:["@platform.metering"],tags:["metering","usage"]},payload:F}),Q=k({meta:{key:"usage.batch_recorded",version:"1.0.0",description:"A batch of usage has been recorded.",stability:"stable",owners:["@platform.metering"],tags:["metering","usage"]},payload:G}),V=k({meta:{key:"usage.aggregated",version:"1.0.0",description:"Usage has been aggregated into a summary.",stability:"stable",owners:["@platform.metering"],tags:["metering","usage"]},payload:H}),W=k({meta:{key:"threshold.created",version:"1.0.0",description:"A usage threshold has been created.",stability:"stable",owners:["@platform.metering"],tags:["metering","threshold"]},payload:I}),X=k({meta:{key:"threshold.exceeded",version:"1.0.0",description:"Usage has exceeded a threshold.",stability:"stable",owners:["@platform.metering"],tags:["metering","threshold"]},payload:J}),Y=k({meta:{key:"threshold.approaching",version:"1.0.0",description:"Usage is approaching a threshold.",stability:"stable",owners:["@platform.metering"],tags:["metering","threshold"]},payload:K}),Z=q({name:"ModelSelectionEventPayload",description:"Payload when an AI model is selected via ranking",fields:{modelId:{type:j.String_unsecure(),isOptional:!1},providerKey:{type:j.String_unsecure(),isOptional:!1},dimension:{type:j.String_unsecure(),isOptional:!0},score:{type:j.Float_unsecure(),isOptional:!1},reason:{type:j.String_unsecure(),isOptional:!1},alternativesCount:{type:j.Int_unsecure(),isOptional:!1},costEstimateInput:{type:j.Float_unsecure(),isOptional:!0},costEstimateOutput:{type:j.Float_unsecure(),isOptional:!0},selectionDurationMs:{type:j.Float_unsecure(),isOptional:!0},timestamp:{type:j.DateTime(),isOptional:!1}}}),_=k({meta:{key:"model.selected",version:"1.0.0",description:"An AI model has been selected via ranking-driven selection.",stability:"experimental",owners:["@platform.metering"],tags:["metering","ai","model-selection"]},payload:Z}),x={MetricDefinedEvent:L,MetricUpdatedEvent:N,UsageRecordedEvent:O,UsageBatchRecordedEvent:Q,UsageAggregatedEvent:V,ThresholdCreatedEvent:W,ThresholdExceededEvent:X,ThresholdApproachingEvent:Y,ModelSelectionEvent:_};export{O as UsageRecordedEvent,Q as UsageBatchRecordedEvent,V as UsageAggregatedEvent,X as ThresholdExceededEvent,W as ThresholdCreatedEvent,Y as ThresholdApproachingEvent,_ as ModelSelectionEvent,N as MetricUpdatedEvent,L as MetricDefinedEvent,x as MeteringEvents};