@contractspec/lib.metering 3.7.17 → 3.7.19

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