@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.
- package/dist/aggregation/index.js +1 -265
- package/dist/analytics/posthog-metering-reader.js +4 -266
- package/dist/analytics/posthog-metering.js +1 -45
- package/dist/browser/aggregation/index.js +1 -265
- package/dist/browser/analytics/posthog-metering-reader.js +4 -266
- package/dist/browser/analytics/posthog-metering.js +1 -45
- package/dist/browser/contracts/index.js +1 -617
- package/dist/browser/docs/index.js +4 -18
- package/dist/browser/docs/metering.docblock.js +4 -18
- package/dist/browser/entities/index.js +1 -350
- package/dist/browser/events.js +1 -269
- package/dist/browser/index.js +7 -1877
- package/dist/browser/metering.capability.js +1 -31
- package/dist/browser/metering.feature.js +1 -53
- package/dist/contracts/index.js +1 -617
- package/dist/docs/index.js +4 -18
- package/dist/docs/metering.docblock.js +4 -18
- package/dist/entities/index.js +1 -350
- package/dist/events.js +1 -269
- package/dist/index.js +7 -1877
- package/dist/metering.capability.js +1 -31
- package/dist/metering.feature.js +1 -53
- package/dist/node/aggregation/index.js +1 -265
- package/dist/node/analytics/posthog-metering-reader.js +4 -266
- package/dist/node/analytics/posthog-metering.js +1 -45
- package/dist/node/contracts/index.js +1 -617
- package/dist/node/docs/index.js +4 -18
- package/dist/node/docs/metering.docblock.js +4 -18
- package/dist/node/entities/index.js +1 -350
- package/dist/node/events.js +1 -269
- package/dist/node/index.js +7 -1877
- package/dist/node/metering.capability.js +1 -31
- package/dist/node/metering.feature.js +1 -53
- package/package.json +6 -6
package/dist/contracts/index.js
CHANGED
|
@@ -1,618 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// src/contracts/index.ts
|
|
3
|
-
import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
|
|
4
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
5
|
-
var OWNERS = ["platform.metering"];
|
|
6
|
-
var MetricDefinitionModel = defineSchemaModel({
|
|
7
|
-
name: "MetricDefinition",
|
|
8
|
-
description: "Represents a metric definition",
|
|
9
|
-
fields: {
|
|
10
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
11
|
-
key: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
12
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
13
|
-
description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
14
|
-
unit: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
15
|
-
aggregationType: {
|
|
16
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
17
|
-
isOptional: false
|
|
18
|
-
},
|
|
19
|
-
resetPeriod: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
20
|
-
category: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
21
|
-
isActive: { type: ScalarTypeEnum.Boolean(), isOptional: false },
|
|
22
|
-
orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
23
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
24
|
-
updatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
var UsageRecordModel = defineSchemaModel({
|
|
28
|
-
name: "UsageRecord",
|
|
29
|
-
description: "Represents a usage record",
|
|
30
|
-
fields: {
|
|
31
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
32
|
-
metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
33
|
-
subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
34
|
-
subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
35
|
-
quantity: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
36
|
-
source: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
37
|
-
resourceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
38
|
-
resourceType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
39
|
-
metadata: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
40
|
-
timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
41
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
var UsageSummaryModel = defineSchemaModel({
|
|
45
|
-
name: "UsageSummary",
|
|
46
|
-
description: "Represents aggregated usage",
|
|
47
|
-
fields: {
|
|
48
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
49
|
-
metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
50
|
-
subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
51
|
-
subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
52
|
-
periodType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
53
|
-
periodStart: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
54
|
-
periodEnd: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
55
|
-
totalQuantity: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
56
|
-
recordCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
57
|
-
minQuantity: { type: ScalarTypeEnum.Float_unsecure(), isOptional: true },
|
|
58
|
-
maxQuantity: { type: ScalarTypeEnum.Float_unsecure(), isOptional: true },
|
|
59
|
-
avgQuantity: { type: ScalarTypeEnum.Float_unsecure(), isOptional: true }
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
var UsageThresholdModel = defineSchemaModel({
|
|
63
|
-
name: "UsageThreshold",
|
|
64
|
-
description: "Represents a usage threshold",
|
|
65
|
-
fields: {
|
|
66
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
67
|
-
metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
68
|
-
subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
69
|
-
subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
70
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
71
|
-
threshold: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
72
|
-
warnThreshold: { type: ScalarTypeEnum.Float_unsecure(), isOptional: true },
|
|
73
|
-
periodType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
74
|
-
action: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
75
|
-
currentValue: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
76
|
-
isActive: { type: ScalarTypeEnum.Boolean(), isOptional: false },
|
|
77
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
var DefineMetricInput = defineSchemaModel({
|
|
81
|
-
name: "DefineMetricInput",
|
|
82
|
-
description: "Input for defining a metric",
|
|
83
|
-
fields: {
|
|
84
|
-
key: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
85
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
86
|
-
description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
87
|
-
unit: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
88
|
-
aggregationType: {
|
|
89
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
90
|
-
isOptional: true
|
|
91
|
-
},
|
|
92
|
-
resetPeriod: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
93
|
-
category: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
94
|
-
orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
95
|
-
metadata: { type: ScalarTypeEnum.JSON(), isOptional: true }
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
var UpdateMetricInput = defineSchemaModel({
|
|
99
|
-
name: "UpdateMetricInput",
|
|
100
|
-
description: "Input for updating a metric",
|
|
101
|
-
fields: {
|
|
102
|
-
metricId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
103
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
104
|
-
description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
105
|
-
category: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
106
|
-
isActive: { type: ScalarTypeEnum.Boolean(), isOptional: true },
|
|
107
|
-
metadata: { type: ScalarTypeEnum.JSON(), isOptional: true }
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
var DeleteMetricInput = defineSchemaModel({
|
|
111
|
-
name: "DeleteMetricInput",
|
|
112
|
-
description: "Input for deleting a metric",
|
|
113
|
-
fields: {
|
|
114
|
-
metricId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
var GetMetricInput = defineSchemaModel({
|
|
118
|
-
name: "GetMetricInput",
|
|
119
|
-
description: "Input for getting a metric",
|
|
120
|
-
fields: {
|
|
121
|
-
key: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
122
|
-
orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
var ListMetricsInput = defineSchemaModel({
|
|
126
|
-
name: "ListMetricsInput",
|
|
127
|
-
description: "Input for listing metrics",
|
|
128
|
-
fields: {
|
|
129
|
-
orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
130
|
-
category: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
131
|
-
isActive: { type: ScalarTypeEnum.Boolean(), isOptional: true },
|
|
132
|
-
limit: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
|
|
133
|
-
offset: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true }
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
var ListMetricsOutput = defineSchemaModel({
|
|
137
|
-
name: "ListMetricsOutput",
|
|
138
|
-
description: "Output for listing metrics",
|
|
139
|
-
fields: {
|
|
140
|
-
metrics: { type: MetricDefinitionModel, isArray: true, isOptional: false },
|
|
141
|
-
total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false }
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
var RecordUsageInput = defineSchemaModel({
|
|
145
|
-
name: "RecordUsageInput",
|
|
146
|
-
description: "Input for recording usage",
|
|
147
|
-
fields: {
|
|
148
|
-
metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
149
|
-
subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
150
|
-
subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
151
|
-
quantity: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
152
|
-
timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
153
|
-
source: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
154
|
-
resourceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
155
|
-
resourceType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
156
|
-
metadata: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
157
|
-
idempotencyKey: {
|
|
158
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
159
|
-
isOptional: true
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
var RecordBatchUsageInput = defineSchemaModel({
|
|
164
|
-
name: "RecordBatchUsageInput",
|
|
165
|
-
description: "Input for recording batch usage",
|
|
166
|
-
fields: {
|
|
167
|
-
records: { type: RecordUsageInput, isArray: true, isOptional: false }
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
var RecordBatchUsageOutput = defineSchemaModel({
|
|
171
|
-
name: "RecordBatchUsageOutput",
|
|
172
|
-
description: "Output for recording batch usage",
|
|
173
|
-
fields: {
|
|
174
|
-
recordedCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
175
|
-
skippedCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
176
|
-
recordIds: { type: ScalarTypeEnum.JSON(), isOptional: false }
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
var GetUsageInput = defineSchemaModel({
|
|
180
|
-
name: "GetUsageInput",
|
|
181
|
-
description: "Input for getting usage",
|
|
182
|
-
fields: {
|
|
183
|
-
metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
184
|
-
subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
185
|
-
subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
186
|
-
startDate: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
187
|
-
endDate: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
188
|
-
limit: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
|
|
189
|
-
offset: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true }
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
var GetUsageOutput = defineSchemaModel({
|
|
193
|
-
name: "GetUsageOutput",
|
|
194
|
-
description: "Output for getting usage",
|
|
195
|
-
fields: {
|
|
196
|
-
records: { type: UsageRecordModel, isArray: true, isOptional: false },
|
|
197
|
-
total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
198
|
-
totalQuantity: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false }
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
var GetUsageSummaryInput = defineSchemaModel({
|
|
202
|
-
name: "GetUsageSummaryInput",
|
|
203
|
-
description: "Input for getting usage summary",
|
|
204
|
-
fields: {
|
|
205
|
-
metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
206
|
-
subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
207
|
-
subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
208
|
-
periodType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
209
|
-
startDate: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
210
|
-
endDate: { type: ScalarTypeEnum.DateTime(), isOptional: true }
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
var GetUsageSummaryOutput = defineSchemaModel({
|
|
214
|
-
name: "GetUsageSummaryOutput",
|
|
215
|
-
description: "Output for getting usage summary",
|
|
216
|
-
fields: {
|
|
217
|
-
summaries: { type: UsageSummaryModel, isArray: true, isOptional: false },
|
|
218
|
-
total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false }
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
var CreateThresholdInput = defineSchemaModel({
|
|
222
|
-
name: "CreateThresholdInput",
|
|
223
|
-
description: "Input for creating a threshold",
|
|
224
|
-
fields: {
|
|
225
|
-
metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
226
|
-
subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
227
|
-
subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
228
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
229
|
-
threshold: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
230
|
-
warnThreshold: { type: ScalarTypeEnum.Float_unsecure(), isOptional: true },
|
|
231
|
-
periodType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
232
|
-
action: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
233
|
-
notifyEmails: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
234
|
-
notifyWebhook: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
var UpdateThresholdInput = defineSchemaModel({
|
|
238
|
-
name: "UpdateThresholdInput",
|
|
239
|
-
description: "Input for updating a threshold",
|
|
240
|
-
fields: {
|
|
241
|
-
thresholdId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
242
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
243
|
-
threshold: { type: ScalarTypeEnum.Float_unsecure(), isOptional: true },
|
|
244
|
-
warnThreshold: { type: ScalarTypeEnum.Float_unsecure(), isOptional: true },
|
|
245
|
-
action: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
246
|
-
notifyEmails: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
247
|
-
notifyWebhook: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
248
|
-
isActive: { type: ScalarTypeEnum.Boolean(), isOptional: true }
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
var DeleteThresholdInput = defineSchemaModel({
|
|
252
|
-
name: "DeleteThresholdInput",
|
|
253
|
-
description: "Input for deleting a threshold",
|
|
254
|
-
fields: {
|
|
255
|
-
thresholdId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
var ListThresholdsInput = defineSchemaModel({
|
|
259
|
-
name: "ListThresholdsInput",
|
|
260
|
-
description: "Input for listing thresholds",
|
|
261
|
-
fields: {
|
|
262
|
-
metricKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
263
|
-
subjectType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
264
|
-
subjectId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
265
|
-
isActive: { type: ScalarTypeEnum.Boolean(), isOptional: true }
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
var ListThresholdsOutput = defineSchemaModel({
|
|
269
|
-
name: "ListThresholdsOutput",
|
|
270
|
-
description: "Output for listing thresholds",
|
|
271
|
-
fields: {
|
|
272
|
-
thresholds: { type: UsageThresholdModel, isArray: true, isOptional: false },
|
|
273
|
-
total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false }
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
var SuccessOutput = defineSchemaModel({
|
|
277
|
-
name: "SuccessOutput",
|
|
278
|
-
description: "Generic success output",
|
|
279
|
-
fields: {
|
|
280
|
-
success: { type: ScalarTypeEnum.Boolean(), isOptional: false }
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
var DefineMetricContract = defineCommand({
|
|
284
|
-
meta: {
|
|
285
|
-
key: "metric.define",
|
|
286
|
-
version: "1.0.0",
|
|
287
|
-
stability: "stable",
|
|
288
|
-
owners: [...OWNERS],
|
|
289
|
-
tags: ["metering", "metric", "define"],
|
|
290
|
-
description: "Define a new usage metric.",
|
|
291
|
-
goal: "Create a new metric for tracking usage.",
|
|
292
|
-
context: "Called when setting up metering."
|
|
293
|
-
},
|
|
294
|
-
io: {
|
|
295
|
-
input: DefineMetricInput,
|
|
296
|
-
output: MetricDefinitionModel,
|
|
297
|
-
errors: {
|
|
298
|
-
METRIC_KEY_EXISTS: {
|
|
299
|
-
description: "Metric key already exists",
|
|
300
|
-
http: 409,
|
|
301
|
-
gqlCode: "METRIC_KEY_EXISTS",
|
|
302
|
-
when: "A metric with this key already exists"
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
policy: {
|
|
307
|
-
auth: "admin"
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
var UpdateMetricContract = defineCommand({
|
|
311
|
-
meta: {
|
|
312
|
-
key: "metric.update",
|
|
313
|
-
version: "1.0.0",
|
|
314
|
-
stability: "stable",
|
|
315
|
-
owners: [...OWNERS],
|
|
316
|
-
tags: ["metering", "metric", "update"],
|
|
317
|
-
description: "Update a metric definition.",
|
|
318
|
-
goal: "Modify metric configuration.",
|
|
319
|
-
context: "Called when updating metric settings."
|
|
320
|
-
},
|
|
321
|
-
io: {
|
|
322
|
-
input: UpdateMetricInput,
|
|
323
|
-
output: MetricDefinitionModel,
|
|
324
|
-
errors: {
|
|
325
|
-
METRIC_NOT_FOUND: {
|
|
326
|
-
description: "Metric does not exist",
|
|
327
|
-
http: 404,
|
|
328
|
-
gqlCode: "METRIC_NOT_FOUND",
|
|
329
|
-
when: "Metric ID is invalid"
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
},
|
|
333
|
-
policy: {
|
|
334
|
-
auth: "admin"
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
var DeleteMetricContract = defineCommand({
|
|
338
|
-
meta: {
|
|
339
|
-
key: "metric.delete",
|
|
340
|
-
version: "1.0.0",
|
|
341
|
-
stability: "stable",
|
|
342
|
-
owners: [...OWNERS],
|
|
343
|
-
tags: ["metering", "metric", "delete"],
|
|
344
|
-
description: "Delete a metric definition.",
|
|
345
|
-
goal: "Remove a metric and its data.",
|
|
346
|
-
context: "Called when removing a metric."
|
|
347
|
-
},
|
|
348
|
-
io: {
|
|
349
|
-
input: DeleteMetricInput,
|
|
350
|
-
output: SuccessOutput,
|
|
351
|
-
errors: {
|
|
352
|
-
METRIC_NOT_FOUND: {
|
|
353
|
-
description: "Metric does not exist",
|
|
354
|
-
http: 404,
|
|
355
|
-
gqlCode: "METRIC_NOT_FOUND",
|
|
356
|
-
when: "Metric ID is invalid"
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
policy: {
|
|
361
|
-
auth: "admin"
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
var GetMetricContract = defineQuery({
|
|
365
|
-
meta: {
|
|
366
|
-
key: "metric.get",
|
|
367
|
-
version: "1.0.0",
|
|
368
|
-
stability: "stable",
|
|
369
|
-
owners: [...OWNERS],
|
|
370
|
-
tags: ["metering", "metric", "get"],
|
|
371
|
-
description: "Get a metric by key.",
|
|
372
|
-
goal: "Retrieve metric definition.",
|
|
373
|
-
context: "Called to inspect metric details."
|
|
374
|
-
},
|
|
375
|
-
io: {
|
|
376
|
-
input: GetMetricInput,
|
|
377
|
-
output: MetricDefinitionModel,
|
|
378
|
-
errors: {
|
|
379
|
-
METRIC_NOT_FOUND: {
|
|
380
|
-
description: "Metric does not exist",
|
|
381
|
-
http: 404,
|
|
382
|
-
gqlCode: "METRIC_NOT_FOUND",
|
|
383
|
-
when: "Metric key is invalid"
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
},
|
|
387
|
-
policy: {
|
|
388
|
-
auth: "user"
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
var ListMetricsContract = defineQuery({
|
|
392
|
-
meta: {
|
|
393
|
-
key: "metric.list",
|
|
394
|
-
version: "1.0.0",
|
|
395
|
-
stability: "stable",
|
|
396
|
-
owners: [...OWNERS],
|
|
397
|
-
tags: ["metering", "metric", "list"],
|
|
398
|
-
description: "List all metrics.",
|
|
399
|
-
goal: "View configured metrics.",
|
|
400
|
-
context: "Called to browse metrics."
|
|
401
|
-
},
|
|
402
|
-
io: {
|
|
403
|
-
input: ListMetricsInput,
|
|
404
|
-
output: ListMetricsOutput
|
|
405
|
-
},
|
|
406
|
-
policy: {
|
|
407
|
-
auth: "user"
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
var RecordUsageContract = defineCommand({
|
|
411
|
-
meta: {
|
|
412
|
-
key: "usage.record",
|
|
413
|
-
version: "1.0.0",
|
|
414
|
-
stability: "stable",
|
|
415
|
-
owners: [...OWNERS],
|
|
416
|
-
tags: ["metering", "usage", "record"],
|
|
417
|
-
description: "Record a usage event.",
|
|
418
|
-
goal: "Track usage for billing and monitoring.",
|
|
419
|
-
context: "Called when usage occurs."
|
|
420
|
-
},
|
|
421
|
-
io: {
|
|
422
|
-
input: RecordUsageInput,
|
|
423
|
-
output: UsageRecordModel,
|
|
424
|
-
errors: {
|
|
425
|
-
METRIC_NOT_FOUND: {
|
|
426
|
-
description: "Metric does not exist",
|
|
427
|
-
http: 404,
|
|
428
|
-
gqlCode: "METRIC_NOT_FOUND",
|
|
429
|
-
when: "Metric key is invalid"
|
|
430
|
-
},
|
|
431
|
-
DUPLICATE_RECORD: {
|
|
432
|
-
description: "Record already exists",
|
|
433
|
-
http: 409,
|
|
434
|
-
gqlCode: "DUPLICATE_RECORD",
|
|
435
|
-
when: "Idempotency key already used"
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
},
|
|
439
|
-
policy: {
|
|
440
|
-
auth: "admin"
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
var RecordBatchUsageContract = defineCommand({
|
|
444
|
-
meta: {
|
|
445
|
-
key: "usage.recordBatch",
|
|
446
|
-
version: "1.0.0",
|
|
447
|
-
stability: "stable",
|
|
448
|
-
owners: [...OWNERS],
|
|
449
|
-
tags: ["metering", "usage", "batch"],
|
|
450
|
-
description: "Record multiple usage events.",
|
|
451
|
-
goal: "Efficiently track bulk usage.",
|
|
452
|
-
context: "Called for batch processing."
|
|
453
|
-
},
|
|
454
|
-
io: {
|
|
455
|
-
input: RecordBatchUsageInput,
|
|
456
|
-
output: RecordBatchUsageOutput
|
|
457
|
-
},
|
|
458
|
-
policy: {
|
|
459
|
-
auth: "admin"
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
var GetUsageContract = defineQuery({
|
|
463
|
-
meta: {
|
|
464
|
-
key: "usage.get",
|
|
465
|
-
version: "1.0.0",
|
|
466
|
-
stability: "stable",
|
|
467
|
-
owners: [...OWNERS],
|
|
468
|
-
tags: ["metering", "usage", "get"],
|
|
469
|
-
description: "Get usage records for a subject.",
|
|
470
|
-
goal: "View detailed usage history.",
|
|
471
|
-
context: "Called to analyze usage."
|
|
472
|
-
},
|
|
473
|
-
io: {
|
|
474
|
-
input: GetUsageInput,
|
|
475
|
-
output: GetUsageOutput
|
|
476
|
-
},
|
|
477
|
-
policy: {
|
|
478
|
-
auth: "user"
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
var GetUsageSummaryContract = defineQuery({
|
|
482
|
-
meta: {
|
|
483
|
-
key: "usage.getSummary",
|
|
484
|
-
version: "1.0.0",
|
|
485
|
-
stability: "stable",
|
|
486
|
-
owners: [...OWNERS],
|
|
487
|
-
tags: ["metering", "usage", "summary"],
|
|
488
|
-
description: "Get aggregated usage summary.",
|
|
489
|
-
goal: "View usage totals for billing.",
|
|
490
|
-
context: "Called for billing and reporting."
|
|
491
|
-
},
|
|
492
|
-
io: {
|
|
493
|
-
input: GetUsageSummaryInput,
|
|
494
|
-
output: GetUsageSummaryOutput
|
|
495
|
-
},
|
|
496
|
-
policy: {
|
|
497
|
-
auth: "user"
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
var CreateThresholdContract = defineCommand({
|
|
501
|
-
meta: {
|
|
502
|
-
key: "threshold.create",
|
|
503
|
-
version: "1.0.0",
|
|
504
|
-
stability: "stable",
|
|
505
|
-
owners: [...OWNERS],
|
|
506
|
-
tags: ["metering", "threshold", "create"],
|
|
507
|
-
description: "Create a usage threshold.",
|
|
508
|
-
goal: "Set up usage limits and alerts.",
|
|
509
|
-
context: "Called when configuring limits."
|
|
510
|
-
},
|
|
511
|
-
io: {
|
|
512
|
-
input: CreateThresholdInput,
|
|
513
|
-
output: UsageThresholdModel,
|
|
514
|
-
errors: {
|
|
515
|
-
METRIC_NOT_FOUND: {
|
|
516
|
-
description: "Metric does not exist",
|
|
517
|
-
http: 404,
|
|
518
|
-
gqlCode: "METRIC_NOT_FOUND",
|
|
519
|
-
when: "Metric key is invalid"
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
},
|
|
523
|
-
policy: {
|
|
524
|
-
auth: "admin"
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
var UpdateThresholdContract = defineCommand({
|
|
528
|
-
meta: {
|
|
529
|
-
key: "threshold.update",
|
|
530
|
-
version: "1.0.0",
|
|
531
|
-
stability: "stable",
|
|
532
|
-
owners: [...OWNERS],
|
|
533
|
-
tags: ["metering", "threshold", "update"],
|
|
534
|
-
description: "Update a threshold.",
|
|
535
|
-
goal: "Modify threshold configuration.",
|
|
536
|
-
context: "Called when adjusting limits."
|
|
537
|
-
},
|
|
538
|
-
io: {
|
|
539
|
-
input: UpdateThresholdInput,
|
|
540
|
-
output: UsageThresholdModel,
|
|
541
|
-
errors: {
|
|
542
|
-
THRESHOLD_NOT_FOUND: {
|
|
543
|
-
description: "Threshold does not exist",
|
|
544
|
-
http: 404,
|
|
545
|
-
gqlCode: "THRESHOLD_NOT_FOUND",
|
|
546
|
-
when: "Threshold ID is invalid"
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
},
|
|
550
|
-
policy: {
|
|
551
|
-
auth: "admin"
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
var DeleteThresholdContract = defineCommand({
|
|
555
|
-
meta: {
|
|
556
|
-
key: "threshold.delete",
|
|
557
|
-
version: "1.0.0",
|
|
558
|
-
stability: "stable",
|
|
559
|
-
owners: [...OWNERS],
|
|
560
|
-
tags: ["metering", "threshold", "delete"],
|
|
561
|
-
description: "Delete a threshold.",
|
|
562
|
-
goal: "Remove a usage threshold.",
|
|
563
|
-
context: "Called when removing limits."
|
|
564
|
-
},
|
|
565
|
-
io: {
|
|
566
|
-
input: DeleteThresholdInput,
|
|
567
|
-
output: SuccessOutput,
|
|
568
|
-
errors: {
|
|
569
|
-
THRESHOLD_NOT_FOUND: {
|
|
570
|
-
description: "Threshold does not exist",
|
|
571
|
-
http: 404,
|
|
572
|
-
gqlCode: "THRESHOLD_NOT_FOUND",
|
|
573
|
-
when: "Threshold ID is invalid"
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
},
|
|
577
|
-
policy: {
|
|
578
|
-
auth: "admin"
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
var ListThresholdsContract = defineQuery({
|
|
582
|
-
meta: {
|
|
583
|
-
key: "threshold.list",
|
|
584
|
-
version: "1.0.0",
|
|
585
|
-
stability: "stable",
|
|
586
|
-
owners: [...OWNERS],
|
|
587
|
-
tags: ["metering", "threshold", "list"],
|
|
588
|
-
description: "List usage thresholds.",
|
|
589
|
-
goal: "View configured limits.",
|
|
590
|
-
context: "Called to browse thresholds."
|
|
591
|
-
},
|
|
592
|
-
io: {
|
|
593
|
-
input: ListThresholdsInput,
|
|
594
|
-
output: ListThresholdsOutput
|
|
595
|
-
},
|
|
596
|
-
policy: {
|
|
597
|
-
auth: "user"
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
export {
|
|
601
|
-
UsageThresholdModel,
|
|
602
|
-
UsageSummaryModel,
|
|
603
|
-
UsageRecordModel,
|
|
604
|
-
UpdateThresholdContract,
|
|
605
|
-
UpdateMetricContract,
|
|
606
|
-
RecordUsageContract,
|
|
607
|
-
RecordBatchUsageContract,
|
|
608
|
-
MetricDefinitionModel,
|
|
609
|
-
ListThresholdsContract,
|
|
610
|
-
ListMetricsContract,
|
|
611
|
-
GetUsageSummaryContract,
|
|
612
|
-
GetUsageContract,
|
|
613
|
-
GetMetricContract,
|
|
614
|
-
DeleteThresholdContract,
|
|
615
|
-
DeleteMetricContract,
|
|
616
|
-
DefineMetricContract,
|
|
617
|
-
CreateThresholdContract
|
|
618
|
-
};
|
|
2
|
+
import{defineCommand as v,defineQuery as w}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as k,ScalarTypeEnum as j}from"@contractspec/lib.schema";var q=["platform.metering"],x=k({name:"MetricDefinition",description:"Represents a metric definition",fields:{id:{type:j.String_unsecure(),isOptional:!1},key:{type:j.String_unsecure(),isOptional:!1},name:{type:j.String_unsecure(),isOptional:!1},description:{type:j.String_unsecure(),isOptional:!0},unit:{type:j.String_unsecure(),isOptional:!1},aggregationType:{type:j.String_unsecure(),isOptional:!1},resetPeriod:{type:j.String_unsecure(),isOptional:!1},category:{type:j.String_unsecure(),isOptional:!0},isActive:{type:j.Boolean(),isOptional:!1},orgId:{type:j.String_unsecure(),isOptional:!0},createdAt:{type:j.DateTime(),isOptional:!1},updatedAt:{type:j.DateTime(),isOptional:!1}}}),A=k({name:"UsageRecord",description:"Represents a usage record",fields:{id:{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},resourceId:{type:j.String_unsecure(),isOptional:!0},resourceType:{type:j.String_unsecure(),isOptional:!0},metadata:{type:j.JSON(),isOptional:!0},timestamp:{type:j.DateTime(),isOptional:!1},createdAt:{type:j.DateTime(),isOptional:!1}}}),J=k({name:"UsageSummary",description:"Represents aggregated usage",fields:{id:{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},minQuantity:{type:j.Float_unsecure(),isOptional:!0},maxQuantity:{type:j.Float_unsecure(),isOptional:!0},avgQuantity:{type:j.Float_unsecure(),isOptional:!0}}}),z=k({name:"UsageThreshold",description:"Represents a usage threshold",fields:{id:{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},name:{type:j.String_unsecure(),isOptional:!1},threshold:{type:j.Float_unsecure(),isOptional:!1},warnThreshold:{type:j.Float_unsecure(),isOptional:!0},periodType:{type:j.String_unsecure(),isOptional:!1},action:{type:j.String_unsecure(),isOptional:!1},currentValue:{type:j.Float_unsecure(),isOptional:!1},isActive:{type:j.Boolean(),isOptional:!1},createdAt:{type:j.DateTime(),isOptional:!1}}}),K=k({name:"DefineMetricInput",description:"Input for defining a metric",fields:{key:{type:j.String_unsecure(),isOptional:!1},name:{type:j.String_unsecure(),isOptional:!1},description:{type:j.String_unsecure(),isOptional:!0},unit:{type:j.String_unsecure(),isOptional:!1},aggregationType:{type:j.String_unsecure(),isOptional:!0},resetPeriod:{type:j.String_unsecure(),isOptional:!0},category:{type:j.String_unsecure(),isOptional:!0},orgId:{type:j.String_unsecure(),isOptional:!0},metadata:{type:j.JSON(),isOptional:!0}}}),P=k({name:"UpdateMetricInput",description:"Input for updating a metric",fields:{metricId:{type:j.String_unsecure(),isOptional:!1},name:{type:j.String_unsecure(),isOptional:!0},description:{type:j.String_unsecure(),isOptional:!0},category:{type:j.String_unsecure(),isOptional:!0},isActive:{type:j.Boolean(),isOptional:!0},metadata:{type:j.JSON(),isOptional:!0}}}),V=k({name:"DeleteMetricInput",description:"Input for deleting a metric",fields:{metricId:{type:j.String_unsecure(),isOptional:!1}}}),X=k({name:"GetMetricInput",description:"Input for getting a metric",fields:{key:{type:j.String_unsecure(),isOptional:!1},orgId:{type:j.String_unsecure(),isOptional:!0}}}),Y=k({name:"ListMetricsInput",description:"Input for listing metrics",fields:{orgId:{type:j.String_unsecure(),isOptional:!0},category:{type:j.String_unsecure(),isOptional:!0},isActive:{type:j.Boolean(),isOptional:!0},limit:{type:j.Int_unsecure(),isOptional:!0},offset:{type:j.Int_unsecure(),isOptional:!0}}}),Z=k({name:"ListMetricsOutput",description:"Output for listing metrics",fields:{metrics:{type:x,isArray:!0,isOptional:!1},total:{type:j.Int_unsecure(),isOptional:!1}}}),F=k({name:"RecordUsageInput",description:"Input for recording usage",fields:{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},timestamp:{type:j.DateTime(),isOptional:!0},source:{type:j.String_unsecure(),isOptional:!0},resourceId:{type:j.String_unsecure(),isOptional:!0},resourceType:{type:j.String_unsecure(),isOptional:!0},metadata:{type:j.JSON(),isOptional:!0},idempotencyKey:{type:j.String_unsecure(),isOptional:!0}}}),_=k({name:"RecordBatchUsageInput",description:"Input for recording batch usage",fields:{records:{type:F,isArray:!0,isOptional:!1}}}),$=k({name:"RecordBatchUsageOutput",description:"Output for recording batch usage",fields:{recordedCount:{type:j.Int_unsecure(),isOptional:!1},skippedCount:{type:j.Int_unsecure(),isOptional:!1},recordIds:{type:j.JSON(),isOptional:!1}}}),b=k({name:"GetUsageInput",description:"Input for getting usage",fields:{metricKey:{type:j.String_unsecure(),isOptional:!1},subjectType:{type:j.String_unsecure(),isOptional:!1},subjectId:{type:j.String_unsecure(),isOptional:!1},startDate:{type:j.DateTime(),isOptional:!1},endDate:{type:j.DateTime(),isOptional:!1},limit:{type:j.Int_unsecure(),isOptional:!0},offset:{type:j.Int_unsecure(),isOptional:!0}}}),B=k({name:"GetUsageOutput",description:"Output for getting usage",fields:{records:{type:A,isArray:!0,isOptional:!1},total:{type:j.Int_unsecure(),isOptional:!1},totalQuantity:{type:j.Float_unsecure(),isOptional:!1}}}),L=k({name:"GetUsageSummaryInput",description:"Input for getting usage summary",fields:{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},startDate:{type:j.DateTime(),isOptional:!1},endDate:{type:j.DateTime(),isOptional:!0}}}),G=k({name:"GetUsageSummaryOutput",description:"Output for getting usage summary",fields:{summaries:{type:J,isArray:!0,isOptional:!1},total:{type:j.Int_unsecure(),isOptional:!1}}}),Q=k({name:"CreateThresholdInput",description:"Input for creating a threshold",fields:{metricKey:{type:j.String_unsecure(),isOptional:!1},subjectType:{type:j.String_unsecure(),isOptional:!0},subjectId:{type:j.String_unsecure(),isOptional:!0},name:{type:j.String_unsecure(),isOptional:!1},threshold:{type:j.Float_unsecure(),isOptional:!1},warnThreshold:{type:j.Float_unsecure(),isOptional:!0},periodType:{type:j.String_unsecure(),isOptional:!0},action:{type:j.String_unsecure(),isOptional:!0},notifyEmails:{type:j.JSON(),isOptional:!0},notifyWebhook:{type:j.String_unsecure(),isOptional:!0}}}),D=k({name:"UpdateThresholdInput",description:"Input for updating a threshold",fields:{thresholdId:{type:j.String_unsecure(),isOptional:!1},name:{type:j.String_unsecure(),isOptional:!0},threshold:{type:j.Float_unsecure(),isOptional:!0},warnThreshold:{type:j.Float_unsecure(),isOptional:!0},action:{type:j.String_unsecure(),isOptional:!0},notifyEmails:{type:j.JSON(),isOptional:!0},notifyWebhook:{type:j.String_unsecure(),isOptional:!0},isActive:{type:j.Boolean(),isOptional:!0}}}),C=k({name:"DeleteThresholdInput",description:"Input for deleting a threshold",fields:{thresholdId:{type:j.String_unsecure(),isOptional:!1}}}),N=k({name:"ListThresholdsInput",description:"Input for listing thresholds",fields:{metricKey:{type:j.String_unsecure(),isOptional:!0},subjectType:{type:j.String_unsecure(),isOptional:!0},subjectId:{type:j.String_unsecure(),isOptional:!0},isActive:{type:j.Boolean(),isOptional:!0}}}),W=k({name:"ListThresholdsOutput",description:"Output for listing thresholds",fields:{thresholds:{type:z,isArray:!0,isOptional:!1},total:{type:j.Int_unsecure(),isOptional:!1}}}),H=k({name:"SuccessOutput",description:"Generic success output",fields:{success:{type:j.Boolean(),isOptional:!1}}}),U=v({meta:{key:"metric.define",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","metric","define"],description:"Define a new usage metric.",goal:"Create a new metric for tracking usage.",context:"Called when setting up metering."},io:{input:K,output:x,errors:{METRIC_KEY_EXISTS:{description:"Metric key already exists",http:409,gqlCode:"METRIC_KEY_EXISTS",when:"A metric with this key already exists"}}},policy:{auth:"admin"}}),R=v({meta:{key:"metric.update",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","metric","update"],description:"Update a metric definition.",goal:"Modify metric configuration.",context:"Called when updating metric settings."},io:{input:P,output:x,errors:{METRIC_NOT_FOUND:{description:"Metric does not exist",http:404,gqlCode:"METRIC_NOT_FOUND",when:"Metric ID is invalid"}}},policy:{auth:"admin"}}),O=v({meta:{key:"metric.delete",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","metric","delete"],description:"Delete a metric definition.",goal:"Remove a metric and its data.",context:"Called when removing a metric."},io:{input:V,output:H,errors:{METRIC_NOT_FOUND:{description:"Metric does not exist",http:404,gqlCode:"METRIC_NOT_FOUND",when:"Metric ID is invalid"}}},policy:{auth:"admin"}}),s=w({meta:{key:"metric.get",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","metric","get"],description:"Get a metric by key.",goal:"Retrieve metric definition.",context:"Called to inspect metric details."},io:{input:X,output:x,errors:{METRIC_NOT_FOUND:{description:"Metric does not exist",http:404,gqlCode:"METRIC_NOT_FOUND",when:"Metric key is invalid"}}},policy:{auth:"user"}}),f=w({meta:{key:"metric.list",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","metric","list"],description:"List all metrics.",goal:"View configured metrics.",context:"Called to browse metrics."},io:{input:Y,output:Z},policy:{auth:"user"}}),h=v({meta:{key:"usage.record",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","usage","record"],description:"Record a usage event.",goal:"Track usage for billing and monitoring.",context:"Called when usage occurs."},io:{input:F,output:A,errors:{METRIC_NOT_FOUND:{description:"Metric does not exist",http:404,gqlCode:"METRIC_NOT_FOUND",when:"Metric key is invalid"},DUPLICATE_RECORD:{description:"Record already exists",http:409,gqlCode:"DUPLICATE_RECORD",when:"Idempotency key already used"}}},policy:{auth:"admin"}}),M=v({meta:{key:"usage.recordBatch",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","usage","batch"],description:"Record multiple usage events.",goal:"Efficiently track bulk usage.",context:"Called for batch processing."},io:{input:_,output:$},policy:{auth:"admin"}}),o=w({meta:{key:"usage.get",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","usage","get"],description:"Get usage records for a subject.",goal:"View detailed usage history.",context:"Called to analyze usage."},io:{input:b,output:B},policy:{auth:"user"}}),t=w({meta:{key:"usage.getSummary",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","usage","summary"],description:"Get aggregated usage summary.",goal:"View usage totals for billing.",context:"Called for billing and reporting."},io:{input:L,output:G},policy:{auth:"user"}}),i=v({meta:{key:"threshold.create",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","threshold","create"],description:"Create a usage threshold.",goal:"Set up usage limits and alerts.",context:"Called when configuring limits."},io:{input:Q,output:z,errors:{METRIC_NOT_FOUND:{description:"Metric does not exist",http:404,gqlCode:"METRIC_NOT_FOUND",when:"Metric key is invalid"}}},policy:{auth:"admin"}}),d=v({meta:{key:"threshold.update",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","threshold","update"],description:"Update a threshold.",goal:"Modify threshold configuration.",context:"Called when adjusting limits."},io:{input:D,output:z,errors:{THRESHOLD_NOT_FOUND:{description:"Threshold does not exist",http:404,gqlCode:"THRESHOLD_NOT_FOUND",when:"Threshold ID is invalid"}}},policy:{auth:"admin"}}),y=v({meta:{key:"threshold.delete",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","threshold","delete"],description:"Delete a threshold.",goal:"Remove a usage threshold.",context:"Called when removing limits."},io:{input:C,output:H,errors:{THRESHOLD_NOT_FOUND:{description:"Threshold does not exist",http:404,gqlCode:"THRESHOLD_NOT_FOUND",when:"Threshold ID is invalid"}}},policy:{auth:"admin"}}),T=w({meta:{key:"threshold.list",version:"1.0.0",stability:"stable",owners:[...q],tags:["metering","threshold","list"],description:"List usage thresholds.",goal:"View configured limits.",context:"Called to browse thresholds."},io:{input:N,output:W},policy:{auth:"user"}});export{z as UsageThresholdModel,J as UsageSummaryModel,A as UsageRecordModel,d as UpdateThresholdContract,R as UpdateMetricContract,h as RecordUsageContract,M as RecordBatchUsageContract,x as MetricDefinitionModel,T as ListThresholdsContract,f as ListMetricsContract,t as GetUsageSummaryContract,o as GetUsageContract,s as GetMetricContract,y as DeleteThresholdContract,O as DeleteMetricContract,U as DefineMetricContract,i as CreateThresholdContract};
|
package/dist/docs/index.js
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { registerDocBlocks } from "@contractspec/lib.contracts-spec/docs";
|
|
4
|
-
var meteringDocBlocks = [
|
|
5
|
-
{
|
|
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: ["metering", "usage", "billing", "quotas"],
|
|
13
|
-
body: `## Capabilities
|
|
2
|
+
import{registerDocBlocks as f}from"@contractspec/lib.contracts-spec/docs";var h=[{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
|
|
14
3
|
|
|
15
4
|
- **Entities**: MetricDefinition, UsageRecord, UsageSummary, UsageThreshold, UsageAlert.
|
|
16
5
|
- **Contracts**: define/list metrics; record usage (batch + idempotent); retrieve usage by subject; manage thresholds and alerts.
|
|
@@ -35,7 +24,7 @@ var meteringDocBlocks = [
|
|
|
35
24
|
|
|
36
25
|
## Example
|
|
37
26
|
|
|
38
|
-
|
|
27
|
+
\`\`\`ts
|
|
39
28
|
import { meteringSchemaContribution } from '@contractspec/lib.metering';
|
|
40
29
|
import { aggregateUsage } from '@contractspec/lib.metering/aggregation';
|
|
41
30
|
|
|
@@ -50,14 +39,11 @@ await aggregateUsage({
|
|
|
50
39
|
usage: usageRepository,
|
|
51
40
|
period: 'DAILY',
|
|
52
41
|
});
|
|
53
|
-
|
|
42
|
+
\`\`\`,
|
|
54
43
|
|
|
55
44
|
## Guardrails
|
|
56
45
|
|
|
57
46
|
- Keep metric keys stable; store quantities as decimals for currency/units.
|
|
58
47
|
- Use idempotency keys for external ingestion; avoid PII in metric metadata.
|
|
59
48
|
- Scope by org/user for multi-tenant isolation; emit audit + analytics events on changes.
|
|
60
|
-
`
|
|
61
|
-
}
|
|
62
|
-
];
|
|
63
|
-
registerDocBlocks(meteringDocBlocks);
|
|
49
|
+
`}];f(h);
|