@proteos/sdk 0.94.0 → 0.95.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteos/sdk",
3
- "version": "0.94.0",
3
+ "version": "0.95.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "TypeScript SDK for the Proteos platform",
6
6
  "repository": {
@@ -156,6 +156,9 @@ export const PLATFORM_ENTITIES: readonly PlatformEntity[] = [
156
156
  // Usage (usage-service): the metering ledger. Read-only and org-level —
157
157
  // whoever reads usage reads all of the org's usage.
158
158
  { slug: 'usage-records', name: 'Usage Records' },
159
+ // The org's usage limits per meter and period (stacking contributions).
160
+ // Org-level; org roles read, only platform admins write.
161
+ { slug: 'usage-limits', name: 'Usage Limits' },
159
162
  ] as const
160
163
 
161
164
  /** Just the platform entity slugs, in canonical order. */
@@ -2675,6 +2675,8 @@ export interface ContactPurposeStatus {
2675
2675
  is_inherited: boolean
2676
2676
  /** Addresses opted out of this purpose (or all) on their own scope. */
2677
2677
  opted_out_address_ids: string[]
2678
+ /** Addresses opted in to this purpose (or all) on their own scope, such as a double opt-in for one address. */
2679
+ opted_in_address_ids: string[]
2678
2680
  /** Addresses with a double opt-in for this purpose waiting to be confirmed. */
2679
2681
  pending_address_ids: string[]
2680
2682
  /** Addresses whose double opt-in for this purpose was not confirmed in time. */
package/src/index.ts CHANGED
@@ -1300,6 +1300,19 @@ export {
1300
1300
  resolveOptions,
1301
1301
  UserRefSchema,
1302
1302
  } from './types/index.js'
1303
+ // Usage types (usage-service: the metering ledger and the org's usage limits)
1304
+ export type {
1305
+ EffectiveUsageLimit,
1306
+ Meter,
1307
+ MeterAggregation,
1308
+ MeterUnit,
1309
+ UsageLimit,
1310
+ UsageLimitPeriod,
1311
+ UsageLimitSource,
1312
+ UsageSummaryQuery,
1313
+ UsageSummaryRow,
1314
+ } from './usage/index.js'
1315
+ export { UsageClient } from './usage/index.js'
1303
1316
  export type {
1304
1317
  AgentActionParams,
1305
1318
  BinaryRef,
@@ -0,0 +1,49 @@
1
+ import type { ProteosClient } from '../client.js'
2
+ import type { EffectiveUsageLimit, Meter, UsageSummaryQuery, UsageSummaryRow } from './types.js'
3
+
4
+ export * from './types.js'
5
+
6
+ const USAGE_BASE_PATH = '/usage/v1'
7
+
8
+ /**
9
+ * Facade for usage-service: the metering ledger (read-only) and the org's
10
+ * usage limits. Quantities only, never money.
11
+ *
12
+ * ```ts
13
+ * const usage = new UsageClient(client)
14
+ * const meters = await usage.meters()
15
+ * const rows = await usage.summary({ from, to, group_by: 'day' })
16
+ * const limits = await usage.limits()
17
+ * ```
18
+ */
19
+ export class UsageClient {
20
+ constructor(private readonly client: ProteosClient) {}
21
+
22
+ /** The meter catalogue. */
23
+ async meters(): Promise<Meter[]> {
24
+ const response = await this.client.request<{ data: Meter[] }>(
25
+ 'GET',
26
+ `${USAGE_BASE_PATH}/meters`,
27
+ )
28
+ return response.data
29
+ }
30
+
31
+ /** Totals per meter over a period: sum meters from the ledger, latest meters from snapshots. */
32
+ async summary(query: UsageSummaryQuery): Promise<UsageSummaryRow[]> {
33
+ const response = await this.client.requestWithQuery<{ data: UsageSummaryRow[] }>(
34
+ 'GET',
35
+ `${USAGE_BASE_PATH}/summary`,
36
+ query,
37
+ )
38
+ return response.data
39
+ }
40
+
41
+ /** The org's limits active now, with their usage in the current window. */
42
+ async limits(): Promise<EffectiveUsageLimit[]> {
43
+ const response = await this.client.request<{ data: EffectiveUsageLimit[] }>(
44
+ 'GET',
45
+ `${USAGE_BASE_PATH}/limits`,
46
+ )
47
+ return response.data
48
+ }
49
+ }
@@ -0,0 +1,93 @@
1
+ import type { UserRef } from '../types/index.js'
2
+
3
+ /** How a meter's records combine over a period: summed, or a daily level. */
4
+ export type MeterAggregation = 'sum' | 'latest'
5
+
6
+ /** Raw base unit of a meter's quantity. */
7
+ export type MeterUnit = 'count' | 'seconds' | 'bytes' | 'tokens'
8
+
9
+ /** One metered quantity from the catalogue (`GET /usage/v1/meters`). */
10
+ export interface Meter {
11
+ key: string
12
+ aggregation: MeterAggregation
13
+ unit: MeterUnit
14
+ /** Dimension keys a record of this meter may carry. */
15
+ dimensions: string[]
16
+ description: string
17
+ }
18
+
19
+ /** One group of a usage summary. Fields of groups not asked for are absent. */
20
+ export interface UsageSummaryRow {
21
+ meter_key: string
22
+ aggregation: MeterAggregation
23
+ unit: MeterUnit
24
+ actor?: UserRef
25
+ on_behalf_of?: UserRef
26
+ /** Start of the UTC day or month bucket, with `group_by` day or month. */
27
+ period_start?: string
28
+ dimensions?: Record<string, string>
29
+ /** Sum meters: the sum. Latest meters: the level on the last measured day. */
30
+ quantity: number
31
+ record_count?: number
32
+ average?: number
33
+ max?: number
34
+ day_count?: number
35
+ }
36
+
37
+ /**
38
+ * A usage summary over `[from, to)` (ISO timestamps, at most 366 days).
39
+ * `group_by` is a comma-separated list of actor, on_behalf_of, day or month,
40
+ * and dimension:<key>; `meter` a comma-separated list of meter keys.
41
+ */
42
+ export interface UsageSummaryQuery {
43
+ from: string
44
+ to: string
45
+ meter?: string
46
+ group_by?: string
47
+ actor?: string
48
+ }
49
+
50
+ export type UsageLimitPeriod =
51
+ | 'rolling_1h'
52
+ | 'rolling_24h'
53
+ | 'day'
54
+ | 'month'
55
+ | 'quarter'
56
+ | 'year'
57
+ | 'none'
58
+
59
+ export interface UsageLimitSource {
60
+ /** base (from code, every org), manual (platform staff), later module, credit_pack. */
61
+ type: string
62
+ id?: string
63
+ }
64
+
65
+ /** One stored or base contribution to a limit. */
66
+ export interface UsageLimit {
67
+ id: string
68
+ org_id?: string
69
+ applies_to?: UserRef
70
+ meter_key: string
71
+ dimensions: Record<string, string>
72
+ period: UsageLimitPeriod
73
+ quantity: number
74
+ source: UsageLimitSource
75
+ valid_from?: string
76
+ valid_until?: string
77
+ }
78
+
79
+ /** An org's limit for one (meter, dimensions, period), measured now. */
80
+ export interface EffectiveUsageLimit {
81
+ applies_to?: UserRef
82
+ meter_key: string
83
+ aggregation: MeterAggregation
84
+ unit: MeterUnit
85
+ dimensions: Record<string, string>
86
+ period: UsageLimitPeriod
87
+ /** Start of the current window; absent for period none. */
88
+ window_start?: string
89
+ limit: number
90
+ used: number
91
+ remaining: number
92
+ contributions: UsageLimit[]
93
+ }