@lssm/lib.metering 0.0.0-canary-20251217063201 → 0.0.0-canary-20251217073102

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 (130) hide show
  1. package/dist/aggregation/index.js +271 -1
  2. package/dist/contracts/dist/capabilities/openbanking.js +88 -1
  3. package/dist/contracts/dist/client/index.js +5 -1
  4. package/dist/contracts/dist/client/react/feature-render.js +2 -1
  5. package/dist/contracts/dist/client/react/form-render.js +4 -1
  6. package/dist/contracts/dist/client/react/index.js +4 -1
  7. package/dist/contracts/dist/contract-registry/index.js +1 -1
  8. package/dist/contracts/dist/contract-registry/schemas.js +60 -1
  9. package/dist/contracts/dist/docs/PUBLISHING.docblock.js +16 -76
  10. package/dist/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +16 -350
  11. package/dist/contracts/dist/docs/index.js +29 -1
  12. package/dist/contracts/dist/docs/presentations.js +71 -1
  13. package/dist/contracts/dist/docs/registry.js +44 -1
  14. package/dist/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +16 -383
  15. package/dist/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +16 -68
  16. package/dist/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +16 -140
  17. package/dist/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +16 -86
  18. package/dist/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +16 -1
  19. package/dist/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +24 -2
  20. package/dist/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +21 -2
  21. package/dist/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +16 -213
  22. package/dist/contracts/dist/docs/tech/llm/llm-integration.docblock.js +73 -5
  23. package/dist/contracts/dist/docs/tech/mcp-endpoints.docblock.js +37 -1
  24. package/dist/contracts/dist/docs/tech/presentation-runtime.docblock.js +16 -1
  25. package/dist/contracts/dist/docs/tech/schema/README.docblock.js +20 -262
  26. package/dist/contracts/dist/docs/tech/studio/learning-events.docblock.js +48 -1
  27. package/dist/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +24 -2
  28. package/dist/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +23 -2
  29. package/dist/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +25 -16
  30. package/dist/contracts/dist/docs/tech/studio/project-routing.docblock.js +67 -1
  31. package/dist/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +22 -2
  32. package/dist/contracts/dist/docs/tech/studio/team-invitations.docblock.js +40 -36
  33. package/dist/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +47 -1
  34. package/dist/contracts/dist/docs/tech/studio/workspaces.docblock.js +23 -2
  35. package/dist/contracts/dist/docs/tech/telemetry-ingest.docblock.js +36 -3
  36. package/dist/contracts/dist/docs/tech/templates/runtime.docblock.js +20 -1
  37. package/dist/contracts/dist/docs/tech/vscode-extension.docblock.js +36 -3
  38. package/dist/contracts/dist/docs/tech/workflows/overview.docblock.js +20 -1
  39. package/dist/contracts/dist/events.js +10 -1
  40. package/dist/contracts/dist/experiments/evaluator.js +1 -1
  41. package/dist/contracts/dist/index.js +71 -1
  42. package/dist/contracts/dist/install.js +2 -1
  43. package/dist/contracts/dist/integrations/contracts.js +377 -1
  44. package/dist/contracts/dist/integrations/index.js +18 -1
  45. package/dist/contracts/dist/integrations/openbanking/contracts/accounts.js +228 -1
  46. package/dist/contracts/dist/integrations/openbanking/contracts/balances.js +159 -1
  47. package/dist/contracts/dist/integrations/openbanking/contracts/index.js +3 -1
  48. package/dist/contracts/dist/integrations/openbanking/contracts/transactions.js +210 -1
  49. package/dist/contracts/dist/integrations/openbanking/models.js +242 -1
  50. package/dist/contracts/dist/integrations/openbanking/telemetry.js +13 -1
  51. package/dist/contracts/dist/integrations/providers/elevenlabs.js +52 -1
  52. package/dist/contracts/dist/integrations/providers/gcs-storage.js +75 -1
  53. package/dist/contracts/dist/integrations/providers/gmail.js +87 -1
  54. package/dist/contracts/dist/integrations/providers/google-calendar.js +66 -1
  55. package/dist/contracts/dist/integrations/providers/index.js +11 -1
  56. package/dist/contracts/dist/integrations/providers/mistral.js +68 -1
  57. package/dist/contracts/dist/integrations/providers/postmark.js +68 -1
  58. package/dist/contracts/dist/integrations/providers/powens.js +116 -1
  59. package/dist/contracts/dist/integrations/providers/qdrant.js +73 -1
  60. package/dist/contracts/dist/integrations/providers/registry.js +10 -1
  61. package/dist/contracts/dist/integrations/providers/stripe.js +83 -1
  62. package/dist/contracts/dist/integrations/providers/twilio-sms.js +61 -1
  63. package/dist/contracts/dist/jsonschema.js +1 -1
  64. package/dist/contracts/dist/knowledge/contracts.js +306 -1
  65. package/dist/contracts/dist/knowledge/index.js +7 -1
  66. package/dist/contracts/dist/knowledge/spaces/email-threads.js +34 -1
  67. package/dist/contracts/dist/knowledge/spaces/financial-docs.js +34 -1
  68. package/dist/contracts/dist/knowledge/spaces/financial-overview.js +38 -1
  69. package/dist/contracts/dist/knowledge/spaces/index.js +6 -1
  70. package/dist/contracts/dist/knowledge/spaces/product-canon.js +34 -1
  71. package/dist/contracts/dist/knowledge/spaces/support-faq.js +37 -1
  72. package/dist/contracts/dist/knowledge/spaces/uploaded-docs.js +34 -1
  73. package/dist/contracts/dist/llm/exporters.js +19 -1
  74. package/dist/contracts/dist/llm/index.js +2 -1
  75. package/dist/contracts/dist/llm/prompts.js +1 -1
  76. package/dist/contracts/dist/onboarding-base.js +196 -1
  77. package/dist/contracts/dist/openapi.js +1 -1
  78. package/dist/contracts/dist/ownership.js +21 -1
  79. package/dist/contracts/dist/presentations.js +1 -1
  80. package/dist/contracts/dist/presentations.v2.js +11 -1
  81. package/dist/contracts/dist/prompt.js +1 -1
  82. package/dist/contracts/dist/promptRegistry.js +1 -1
  83. package/dist/contracts/dist/regenerator/index.js +1 -1
  84. package/dist/contracts/dist/regenerator/service.js +6 -1
  85. package/dist/contracts/dist/registry.js +2 -1
  86. package/dist/contracts/dist/resources.js +1 -1
  87. package/dist/contracts/dist/schema/dist/EnumType.js +2 -1
  88. package/dist/contracts/dist/schema/dist/FieldType.js +49 -1
  89. package/dist/contracts/dist/schema/dist/ScalarTypeEnum.js +236 -1
  90. package/dist/contracts/dist/schema/dist/SchemaModel.js +34 -1
  91. package/dist/contracts/dist/schema/dist/entity/defineEntity.js +1 -1
  92. package/dist/contracts/dist/schema/dist/entity/index.js +2 -1
  93. package/dist/contracts/dist/schema/dist/entity/types.js +1 -1
  94. package/dist/contracts/dist/schema/dist/index.js +6 -1
  95. package/dist/contracts/dist/server/graphql-pothos.js +6 -1
  96. package/dist/contracts/dist/server/index.js +8 -1
  97. package/dist/contracts/dist/server/mcp/createMcpServer.js +4 -1
  98. package/dist/contracts/dist/server/mcp/registerPresentations.js +2 -1
  99. package/dist/contracts/dist/server/mcp/registerPrompts.js +1 -1
  100. package/dist/contracts/dist/server/mcp/registerResources.js +2 -1
  101. package/dist/contracts/dist/server/mcp/registerTools.js +1 -1
  102. package/dist/contracts/dist/server/provider-mcp.js +1 -1
  103. package/dist/contracts/dist/server/rest-elysia.js +1 -1
  104. package/dist/contracts/dist/server/rest-express.js +1 -1
  105. package/dist/contracts/dist/server/rest-generic.js +1 -1
  106. package/dist/contracts/dist/server/rest-next-app.js +1 -1
  107. package/dist/contracts/dist/server/rest-next-pages.js +1 -1
  108. package/dist/contracts/dist/spec.js +34 -1
  109. package/dist/contracts/dist/telemetry/index.js +1 -1
  110. package/dist/contracts/dist/telemetry/tracker.js +1 -1
  111. package/dist/contracts/dist/tests/index.js +1 -1
  112. package/dist/contracts/dist/tests/runner.js +2 -1
  113. package/dist/contracts/dist/workflow/index.js +1 -1
  114. package/dist/contracts/dist/workflow/runner.js +1 -1
  115. package/dist/contracts/index.js +1034 -1
  116. package/dist/docs/index.js +1 -1
  117. package/dist/docs/metering.docblock.js +22 -2
  118. package/dist/entities/index.js +418 -1
  119. package/dist/events.js +379 -1
  120. package/dist/index.js +8 -1
  121. package/dist/metering.feature.js +125 -1
  122. package/dist/schema/dist/EnumType.js +2 -1
  123. package/dist/schema/dist/FieldType.js +49 -1
  124. package/dist/schema/dist/ScalarTypeEnum.js +236 -1
  125. package/dist/schema/dist/SchemaModel.js +39 -1
  126. package/dist/schema/dist/entity/defineEntity.js +236 -1
  127. package/dist/schema/dist/entity/index.js +2 -1
  128. package/dist/schema/dist/entity/types.js +1 -1
  129. package/dist/schema/dist/index.js +6 -1
  130. package/package.json +5 -5
@@ -1 +1,271 @@
1
- function e(e,t){let n=new Date(e);switch(t){case`HOURLY`:return n.setMinutes(0,0,0),n;case`DAILY`:return n.setHours(0,0,0,0),n;case`WEEKLY`:n.setHours(0,0,0,0);let e=n.getDay();return n.setDate(n.getDate()-e),n;case`MONTHLY`:return n.setHours(0,0,0,0),n.setDate(1),n;case`YEARLY`:return n.setHours(0,0,0,0),n.setMonth(0,1),n}}function t(t,n){let r=e(t,n);switch(n){case`HOURLY`:return new Date(r.getTime()+3600*1e3);case`DAILY`:return new Date(r.getTime()+1440*60*1e3);case`WEEKLY`:return new Date(r.getTime()+10080*60*1e3);case`MONTHLY`:{let e=new Date(r);return e.setMonth(e.getMonth()+1),e}case`YEARLY`:{let e=new Date(r);return e.setFullYear(e.getFullYear()+1),e}}}function n(t,n){let i=e(t,n),a=i.getFullYear(),o=String(i.getMonth()+1).padStart(2,`0`),s=String(i.getDate()).padStart(2,`0`),c=String(i.getHours()).padStart(2,`0`);switch(n){case`HOURLY`:return`${a}-${o}-${s}T${c}`;case`DAILY`:return`${a}-${o}-${s}`;case`WEEKLY`:return`${a}-W${r(i)}`;case`MONTHLY`:return`${a}-${o}`;case`YEARLY`:return`${a}`}}function r(e){let t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())),n=t.getUTCDay()||7;t.setUTCDate(t.getUTCDate()+4-n);let r=new Date(Date.UTC(t.getUTCFullYear(),0,1)),i=Math.ceil(((t.getTime()-r.getTime())/864e5+1)/7);return String(i).padStart(2,`0`)}var i=class{storage;batchSize;constructor(e){this.storage=e.storage,this.batchSize=e.batchSize||1e3}async aggregate(e){let{periodType:n,periodStart:r,metricKey:i}=e,a=e.periodEnd||t(r,n),o={periodType:n,periodStart:r,periodEnd:a,recordsProcessed:0,summariesCreated:0,summariesUpdated:0,errors:[]},s=await this.storage.getUnaggregatedRecords({metricKey:i,periodStart:r,periodEnd:a,limit:this.batchSize});if(s.length===0)return o;let c=this.groupRecords(s,n);for(let[e,t]of c.entries())try{await this.aggregateGroup(e,t,n,o)}catch(t){let[n,r,i]=e.split(`::`);o.errors.push({metricKey:n,subjectType:r,subjectId:i,error:t instanceof Error?t.message:String(t)})}let l=s.map(e=>e.id);return await this.storage.markRecordsAggregated(l,new Date),o.recordsProcessed=s.length,o}groupRecords(e,t){let r=new Map;for(let i of e){let e=n(i.timestamp,t),a=`${i.metricKey}::${i.subjectType}::${i.subjectId}::${e}`,o=r.get(a)||[];o.push(i),r.set(a,o)}return r}async aggregateGroup(n,r,i,a){let[o,s,c]=n.split(`::`);if(!o||!s||!c||r.length===0)return;let l=r[0],u=e(l.timestamp,i),d=t(l.timestamp,i),f=(await this.storage.getMetric(o))?.aggregationType||`SUM`,p=r.map(e=>e.quantity),m=this.calculateAggregation(p,f);await this.storage.upsertSummary({metricKey:o,subjectType:s,subjectId:c,periodType:i,periodStart:u,periodEnd:d,totalQuantity:m.total,recordCount:r.length,minQuantity:m.min,maxQuantity:m.max,avgQuantity:m.avg}),a.summariesCreated++}calculateAggregation(e,t){if(e.length===0)return{total:0,min:0,max:0,avg:0};let n=Math.min(...e),r=Math.max(...e),i=e.reduce((e,t)=>e+t,0),a=i/e.length,o=e.length,s;switch(t){case`COUNT`:s=o;break;case`SUM`:s=i;break;case`AVG`:s=a;break;case`MAX`:s=r;break;case`MIN`:s=n;break;case`LAST`:s=e[e.length-1]??0;break;default:s=i}return{total:s,min:n,max:r,avg:a}}},a=class{records=[];summaries=new Map;metrics=new Map;addRecord(e){this.records.push(e)}addMetric(e){this.metrics.set(e.key,e)}async getUnaggregatedRecords(e){let t=this.records.filter(t=>{let n=t.timestamp>=e.periodStart&&t.timestamp<e.periodEnd,r=!e.metricKey||t.metricKey===e.metricKey;return n&&r});return e.limit&&(t=t.slice(0,e.limit)),t}async markRecordsAggregated(e){this.records=this.records.filter(t=>!e.includes(t.id))}async upsertSummary(e){let t=`${e.metricKey}::${e.subjectType}::${e.subjectId}::${e.periodType}::${e.periodStart.toISOString()}`,n=this.summaries.get(t);if(n)return n.totalQuantity+=e.totalQuantity,n.recordCount+=e.recordCount,e.minQuantity!==void 0&&(n.minQuantity=Math.min(n.minQuantity??1/0,e.minQuantity)),e.maxQuantity!==void 0&&(n.maxQuantity=Math.max(n.maxQuantity??-1/0,e.maxQuantity)),n;let r={id:`summary-${Date.now()}-${Math.random().toString(36).slice(2)}`,...e};return this.summaries.set(t,r),r}async getMetric(e){return this.metrics.get(e)||null}async listMetrics(){return Array.from(this.metrics.values())}getSummaries(){return Array.from(this.summaries.values())}clear(){this.records=[],this.summaries.clear(),this.metrics.clear()}};export{a as InMemoryUsageStorage,i as UsageAggregator,n as formatPeriodKey,t as getPeriodEnd,e as getPeriodStart};
1
+ //#region src/aggregation/index.ts
2
+ /**
3
+ * Get the start of a period for a given date.
4
+ */
5
+ function getPeriodStart(date, periodType) {
6
+ const d = new Date(date);
7
+ switch (periodType) {
8
+ case "HOURLY":
9
+ d.setMinutes(0, 0, 0);
10
+ return d;
11
+ case "DAILY":
12
+ d.setHours(0, 0, 0, 0);
13
+ return d;
14
+ case "WEEKLY":
15
+ d.setHours(0, 0, 0, 0);
16
+ const day = d.getDay();
17
+ d.setDate(d.getDate() - day);
18
+ return d;
19
+ case "MONTHLY":
20
+ d.setHours(0, 0, 0, 0);
21
+ d.setDate(1);
22
+ return d;
23
+ case "YEARLY":
24
+ d.setHours(0, 0, 0, 0);
25
+ d.setMonth(0, 1);
26
+ return d;
27
+ }
28
+ }
29
+ /**
30
+ * Get the end of a period for a given date.
31
+ */
32
+ function getPeriodEnd(date, periodType) {
33
+ const start = getPeriodStart(date, periodType);
34
+ switch (periodType) {
35
+ case "HOURLY": return new Date(start.getTime() + 3600 * 1e3);
36
+ case "DAILY": return new Date(start.getTime() + 1440 * 60 * 1e3);
37
+ case "WEEKLY": return new Date(start.getTime() + 10080 * 60 * 1e3);
38
+ case "MONTHLY": {
39
+ const end = new Date(start);
40
+ end.setMonth(end.getMonth() + 1);
41
+ return end;
42
+ }
43
+ case "YEARLY": {
44
+ const end = new Date(start);
45
+ end.setFullYear(end.getFullYear() + 1);
46
+ return end;
47
+ }
48
+ }
49
+ }
50
+ /**
51
+ * Format a period key for grouping.
52
+ */
53
+ function formatPeriodKey(date, periodType) {
54
+ const start = getPeriodStart(date, periodType);
55
+ const year = start.getFullYear();
56
+ const month = String(start.getMonth() + 1).padStart(2, "0");
57
+ const day = String(start.getDate()).padStart(2, "0");
58
+ const hour = String(start.getHours()).padStart(2, "0");
59
+ switch (periodType) {
60
+ case "HOURLY": return `${year}-${month}-${day}T${hour}`;
61
+ case "DAILY": return `${year}-${month}-${day}`;
62
+ case "WEEKLY": return `${year}-W${getWeekNumber(start)}`;
63
+ case "MONTHLY": return `${year}-${month}`;
64
+ case "YEARLY": return `${year}`;
65
+ }
66
+ }
67
+ function getWeekNumber(date) {
68
+ const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
69
+ const dayNum = d.getUTCDay() || 7;
70
+ d.setUTCDate(d.getUTCDate() + 4 - dayNum);
71
+ const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
72
+ const weekNum = Math.ceil(((d.getTime() - yearStart.getTime()) / 864e5 + 1) / 7);
73
+ return String(weekNum).padStart(2, "0");
74
+ }
75
+ /**
76
+ * Usage aggregator.
77
+ *
78
+ * Aggregates usage records into summaries based on period type.
79
+ */
80
+ var UsageAggregator = class {
81
+ storage;
82
+ batchSize;
83
+ constructor(options) {
84
+ this.storage = options.storage;
85
+ this.batchSize = options.batchSize || 1e3;
86
+ }
87
+ /**
88
+ * Aggregate usage records for a period.
89
+ */
90
+ async aggregate(params) {
91
+ const { periodType, periodStart, metricKey } = params;
92
+ const periodEnd = params.periodEnd || getPeriodEnd(periodStart, periodType);
93
+ const result = {
94
+ periodType,
95
+ periodStart,
96
+ periodEnd,
97
+ recordsProcessed: 0,
98
+ summariesCreated: 0,
99
+ summariesUpdated: 0,
100
+ errors: []
101
+ };
102
+ const records = await this.storage.getUnaggregatedRecords({
103
+ metricKey,
104
+ periodStart,
105
+ periodEnd,
106
+ limit: this.batchSize
107
+ });
108
+ if (records.length === 0) return result;
109
+ const groups = this.groupRecords(records, periodType);
110
+ for (const [groupKey, groupRecords] of groups.entries()) try {
111
+ await this.aggregateGroup(groupKey, groupRecords, periodType, result);
112
+ } catch (error) {
113
+ const [metricKey$1, subjectType, subjectId] = groupKey.split("::");
114
+ result.errors.push({
115
+ metricKey: metricKey$1,
116
+ subjectType,
117
+ subjectId,
118
+ error: error instanceof Error ? error.message : String(error)
119
+ });
120
+ }
121
+ const recordIds = records.map((r) => r.id);
122
+ await this.storage.markRecordsAggregated(recordIds, /* @__PURE__ */ new Date());
123
+ result.recordsProcessed = records.length;
124
+ return result;
125
+ }
126
+ /**
127
+ * Group records by metric, subject, and period.
128
+ */
129
+ groupRecords(records, periodType) {
130
+ const groups = /* @__PURE__ */ new Map();
131
+ for (const record of records) {
132
+ const periodKey = formatPeriodKey(record.timestamp, periodType);
133
+ const groupKey = `${record.metricKey}::${record.subjectType}::${record.subjectId}::${periodKey}`;
134
+ const existing = groups.get(groupKey) || [];
135
+ existing.push(record);
136
+ groups.set(groupKey, existing);
137
+ }
138
+ return groups;
139
+ }
140
+ /**
141
+ * Aggregate a group of records into a summary.
142
+ */
143
+ async aggregateGroup(groupKey, records, periodType, result) {
144
+ const [metricKey, subjectType, subjectId] = groupKey.split("::");
145
+ if (!metricKey || !subjectType || !subjectId || records.length === 0) return;
146
+ const firstRecord = records[0];
147
+ const periodStart = getPeriodStart(firstRecord.timestamp, periodType);
148
+ const periodEnd = getPeriodEnd(firstRecord.timestamp, periodType);
149
+ const aggregationType = (await this.storage.getMetric(metricKey))?.aggregationType || "SUM";
150
+ const quantities = records.map((r) => r.quantity);
151
+ const aggregated = this.calculateAggregation(quantities, aggregationType);
152
+ await this.storage.upsertSummary({
153
+ metricKey,
154
+ subjectType,
155
+ subjectId,
156
+ periodType,
157
+ periodStart,
158
+ periodEnd,
159
+ totalQuantity: aggregated.total,
160
+ recordCount: records.length,
161
+ minQuantity: aggregated.min,
162
+ maxQuantity: aggregated.max,
163
+ avgQuantity: aggregated.avg
164
+ });
165
+ result.summariesCreated++;
166
+ }
167
+ /**
168
+ * Calculate aggregation values.
169
+ */
170
+ calculateAggregation(quantities, aggregationType) {
171
+ if (quantities.length === 0) return {
172
+ total: 0,
173
+ min: 0,
174
+ max: 0,
175
+ avg: 0
176
+ };
177
+ const min = Math.min(...quantities);
178
+ const max = Math.max(...quantities);
179
+ const sum = quantities.reduce((a, b) => a + b, 0);
180
+ const avg = sum / quantities.length;
181
+ const count = quantities.length;
182
+ let total;
183
+ switch (aggregationType) {
184
+ case "COUNT":
185
+ total = count;
186
+ break;
187
+ case "SUM":
188
+ total = sum;
189
+ break;
190
+ case "AVG":
191
+ total = avg;
192
+ break;
193
+ case "MAX":
194
+ total = max;
195
+ break;
196
+ case "MIN":
197
+ total = min;
198
+ break;
199
+ case "LAST":
200
+ total = quantities[quantities.length - 1] ?? 0;
201
+ break;
202
+ default: total = sum;
203
+ }
204
+ return {
205
+ total,
206
+ min,
207
+ max,
208
+ avg
209
+ };
210
+ }
211
+ };
212
+ /**
213
+ * In-memory usage storage for testing.
214
+ */
215
+ var InMemoryUsageStorage = class {
216
+ records = [];
217
+ summaries = /* @__PURE__ */ new Map();
218
+ metrics = /* @__PURE__ */ new Map();
219
+ addRecord(record) {
220
+ this.records.push(record);
221
+ }
222
+ addMetric(metric) {
223
+ this.metrics.set(metric.key, metric);
224
+ }
225
+ async getUnaggregatedRecords(options) {
226
+ let records = this.records.filter((r) => {
227
+ const inPeriod = r.timestamp >= options.periodStart && r.timestamp < options.periodEnd;
228
+ const matchesMetric = !options.metricKey || r.metricKey === options.metricKey;
229
+ return inPeriod && matchesMetric;
230
+ });
231
+ if (options.limit) records = records.slice(0, options.limit);
232
+ return records;
233
+ }
234
+ async markRecordsAggregated(recordIds) {
235
+ this.records = this.records.filter((r) => !recordIds.includes(r.id));
236
+ }
237
+ async upsertSummary(summary) {
238
+ const key = `${summary.metricKey}::${summary.subjectType}::${summary.subjectId}::${summary.periodType}::${summary.periodStart.toISOString()}`;
239
+ const existing = this.summaries.get(key);
240
+ if (existing) {
241
+ existing.totalQuantity += summary.totalQuantity;
242
+ existing.recordCount += summary.recordCount;
243
+ if (summary.minQuantity !== void 0) existing.minQuantity = Math.min(existing.minQuantity ?? Infinity, summary.minQuantity);
244
+ if (summary.maxQuantity !== void 0) existing.maxQuantity = Math.max(existing.maxQuantity ?? -Infinity, summary.maxQuantity);
245
+ return existing;
246
+ }
247
+ const newSummary = {
248
+ id: `summary-${Date.now()}-${Math.random().toString(36).slice(2)}`,
249
+ ...summary
250
+ };
251
+ this.summaries.set(key, newSummary);
252
+ return newSummary;
253
+ }
254
+ async getMetric(key) {
255
+ return this.metrics.get(key) || null;
256
+ }
257
+ async listMetrics() {
258
+ return Array.from(this.metrics.values());
259
+ }
260
+ getSummaries() {
261
+ return Array.from(this.summaries.values());
262
+ }
263
+ clear() {
264
+ this.records = [];
265
+ this.summaries.clear();
266
+ this.metrics.clear();
267
+ }
268
+ };
269
+
270
+ //#endregion
271
+ export { InMemoryUsageStorage, UsageAggregator, formatPeriodKey, getPeriodEnd, getPeriodStart };
@@ -1 +1,88 @@
1
- import{e}from"../ownership.js";const t=[`platform.finance`],n=[`open-banking`,`finance`];[...t],[...n],e.Experimental,[...t],[...n],e.Experimental,[...t],[...n],e.Experimental;
1
+ import { StabilityEnum } from "../ownership.js";
2
+
3
+ //#region ../contracts/dist/capabilities/openbanking.js
4
+ const OWNERS = ["platform.finance"];
5
+ const TAGS = ["open-banking", "finance"];
6
+ const openBankingAccountsReadCapability = {
7
+ meta: {
8
+ key: "openbanking.accounts.read",
9
+ version: 1,
10
+ kind: "integration",
11
+ title: "Open Banking Accounts (Read)",
12
+ description: "Provides read-only access to linked bank accounts, including account summaries and metadata.",
13
+ domain: "finance",
14
+ owners: [...OWNERS],
15
+ tags: [...TAGS],
16
+ stability: StabilityEnum.Experimental
17
+ },
18
+ provides: [
19
+ {
20
+ surface: "operation",
21
+ name: "openbanking.accounts.list",
22
+ version: 1,
23
+ description: "List bank accounts linked to a Powens open banking connection."
24
+ },
25
+ {
26
+ surface: "operation",
27
+ name: "openbanking.accounts.get",
28
+ version: 1,
29
+ description: "Retrieve the canonical bank account record for a specific account."
30
+ },
31
+ {
32
+ surface: "operation",
33
+ name: "openbanking.accounts.sync",
34
+ version: 1,
35
+ description: "Trigger a refresh of bank account metadata from the open banking provider."
36
+ }
37
+ ]
38
+ };
39
+ const openBankingTransactionsReadCapability = {
40
+ meta: {
41
+ key: "openbanking.transactions.read",
42
+ version: 1,
43
+ kind: "integration",
44
+ title: "Open Banking Transactions (Read)",
45
+ description: "Enables retrieval of transaction history for linked bank accounts via open banking providers.",
46
+ domain: "finance",
47
+ owners: [...OWNERS],
48
+ tags: [...TAGS, "transactions"],
49
+ stability: StabilityEnum.Experimental
50
+ },
51
+ provides: [{
52
+ surface: "operation",
53
+ name: "openbanking.transactions.list",
54
+ version: 1,
55
+ description: "List transactions for a given bank account with optional date filtering."
56
+ }, {
57
+ surface: "operation",
58
+ name: "openbanking.transactions.sync",
59
+ version: 1,
60
+ description: "Synchronise transactions from the open banking provider into the canonical ledger."
61
+ }]
62
+ };
63
+ const openBankingBalancesReadCapability = {
64
+ meta: {
65
+ key: "openbanking.balances.read",
66
+ version: 1,
67
+ kind: "integration",
68
+ title: "Open Banking Balances (Read)",
69
+ description: "Allows querying of current and available balances for linked bank accounts via open banking providers.",
70
+ domain: "finance",
71
+ owners: [...OWNERS],
72
+ tags: [...TAGS, "balances"],
73
+ stability: StabilityEnum.Experimental
74
+ },
75
+ provides: [{
76
+ surface: "operation",
77
+ name: "openbanking.balances.get",
78
+ version: 1,
79
+ description: "Retrieve the latest known balances for a specified bank account."
80
+ }, {
81
+ surface: "operation",
82
+ name: "openbanking.balances.refresh",
83
+ version: 1,
84
+ description: "Force a balance refresh from the open banking provider."
85
+ }]
86
+ };
87
+
88
+ //#endregion
@@ -1 +1,5 @@
1
- "use client";import"./react/feature-render.js";import"./react/form-render.js";import"./react/index.js";
1
+ 'use client';
2
+
3
+ import "./react/feature-render.js";
4
+ import "./react/form-render.js";
5
+ import "./react/index.js";
@@ -1 +1,2 @@
1
- import"../../presentations.v2.js";import"react";
1
+ import "../../presentations.v2.js";
2
+ import "react";
@@ -1 +1,4 @@
1
- import"react";import"react-hook-form";import"@hookform/resolvers/zod";import"react/jsx-runtime";
1
+ import "react";
2
+ import "react-hook-form";
3
+ import "@hookform/resolvers/zod";
4
+ import "react/jsx-runtime";
@@ -1 +1,4 @@
1
- "use client";import"./feature-render.js";import"./form-render.js";
1
+ 'use client';
2
+
3
+ import "./feature-render.js";
4
+ import "./form-render.js";
@@ -1 +1 @@
1
- import{i as e,n as t,r as n}from"./schemas.js";
1
+ import { ContractRegistryFileSchema, ContractRegistryItemSchema, ContractRegistryItemTypeSchema } from "./schemas.js";
@@ -1 +1,60 @@
1
- import{e}from"../ownership.js";import t from"zod";const n=t.enum([`contractspec:operation`,`contractspec:event`,`contractspec:presentation`,`contractspec:form`,`contractspec:feature`,`contractspec:workflow`,`contractspec:template`,`contractspec:integration`,`contractspec:data-view`,`contractspec:migration`,`contractspec:telemetry`,`contractspec:experiment`,`contractspec:app-config`,`contractspec:knowledge`]),r=t.object({path:t.string().min(1),type:t.string().min(1),content:t.string().optional()}),i=t.object({name:t.string().min(1),type:n,version:t.number().int().nonnegative(),title:t.string().min(1),description:t.string().min(1),meta:t.object({stability:t.enum([e.Idea,e.InCreation,e.Experimental,e.Beta,e.Stable,e.Deprecated]),owners:t.array(t.string().min(1)).default([]),tags:t.array(t.string().min(1)).default([])}),dependencies:t.array(t.string().min(1)).optional(),registryDependencies:t.array(t.string().min(1)).optional(),files:t.array(r).min(1),schema:t.object({input:t.unknown().optional(),output:t.unknown().optional()}).optional()});t.object({$schema:t.string().min(1).optional(),name:t.string().min(1),homepage:t.string().min(1).optional(),items:t.array(i)});export{i,n,r};
1
+ import { StabilityEnum } from "../ownership.js";
2
+ import z from "zod";
3
+
4
+ //#region ../contracts/dist/contract-registry/schemas.js
5
+ const ContractRegistryItemTypeSchema = z.enum([
6
+ "contractspec:operation",
7
+ "contractspec:event",
8
+ "contractspec:presentation",
9
+ "contractspec:form",
10
+ "contractspec:feature",
11
+ "contractspec:workflow",
12
+ "contractspec:template",
13
+ "contractspec:integration",
14
+ "contractspec:data-view",
15
+ "contractspec:migration",
16
+ "contractspec:telemetry",
17
+ "contractspec:experiment",
18
+ "contractspec:app-config",
19
+ "contractspec:knowledge"
20
+ ]);
21
+ const ContractRegistryFileSchema = z.object({
22
+ path: z.string().min(1),
23
+ type: z.string().min(1),
24
+ content: z.string().optional()
25
+ });
26
+ const ContractRegistryItemSchema = z.object({
27
+ name: z.string().min(1),
28
+ type: ContractRegistryItemTypeSchema,
29
+ version: z.number().int().nonnegative(),
30
+ title: z.string().min(1),
31
+ description: z.string().min(1),
32
+ meta: z.object({
33
+ stability: z.enum([
34
+ StabilityEnum.Idea,
35
+ StabilityEnum.InCreation,
36
+ StabilityEnum.Experimental,
37
+ StabilityEnum.Beta,
38
+ StabilityEnum.Stable,
39
+ StabilityEnum.Deprecated
40
+ ]),
41
+ owners: z.array(z.string().min(1)).default([]),
42
+ tags: z.array(z.string().min(1)).default([])
43
+ }),
44
+ dependencies: z.array(z.string().min(1)).optional(),
45
+ registryDependencies: z.array(z.string().min(1)).optional(),
46
+ files: z.array(ContractRegistryFileSchema).min(1),
47
+ schema: z.object({
48
+ input: z.unknown().optional(),
49
+ output: z.unknown().optional()
50
+ }).optional()
51
+ });
52
+ const ContractRegistryManifestSchema = z.object({
53
+ $schema: z.string().min(1).optional(),
54
+ name: z.string().min(1),
55
+ homepage: z.string().min(1).optional(),
56
+ items: z.array(ContractRegistryItemSchema)
57
+ });
58
+
59
+ //#endregion
60
+ export { ContractRegistryFileSchema, ContractRegistryItemSchema, ContractRegistryItemTypeSchema };
@@ -1,76 +1,16 @@
1
- import{a as e}from"./registry.js";e([{id:`docs.PUBLISHING`,title:`Publishing ContractSpec Libraries`,summary:`This guide describes how we release the ContractSpec libraries to npm. We use a dual-track release system: **Stable** (manual) and **Canary** (automatic).`,kind:`reference`,visibility:`public`,route:`/docs/PUBLISHING`,tags:[`PUBLISHING`],body:`# Publishing ContractSpec Libraries
2
-
3
- This guide describes how we release the ContractSpec libraries to npm. We use a dual-track release system: **Stable** (manual) and **Canary** (automatic).
4
-
5
- ## Release Tracks
6
-
7
- | Track | Branch | npm Tag | Frequency | Versioning | Use Case |
8
- |-------|--------|---------|-----------|------------|----------|
9
- | **Stable** | \`release\` | \`latest\` | Manual | SemVer (e.g., \`1.7.4\`) | Production, external users |
10
- | **Canary** | \`main\` | \`canary\` | Every Push | Snapshot (e.g., \`1.7.4-canary...\`) | Dev, internal testing |
11
-
12
- ## Prerequisites
13
-
14
- - ✅ \`NPM_TOKEN\` secret is configured in GitHub (owner or automation token with _publish_ scope).
15
- - ✅ \`GITHUB_TOKEN\` (built-in) has permissions to create PRs (enabled by default in new repos).
16
- - ✅ For stable releases: \`release\` branch exists and is protected.
17
-
18
- ## Canary Workflow (Automatic)
19
-
20
- Every commit pushed to \`main\` triggers the \`.github/workflows/publish-canary.yml\` workflow.
21
-
22
- 1. **Trigger**: Push to \`main\`.
23
- 2. **Versioning**: Runs \`changeset version --snapshot canary\` to generate a temporary snapshot version.
24
- 3. **Publish**: Packages are published to npm with the \`canary\` tag using \`changeset publish --tag canary\`.
25
-
26
- ### Consuming Canary Builds
27
-
28
- To install the latest bleeding-edge version:
29
-
30
- \`\`\`bash
31
- npm install @lssm/lib.contracts@canary
32
- # or
33
- bun add @lssm/lib.contracts@canary
34
- \`\`\`
35
-
36
- ## Stable Release Workflow (Manual)
37
-
38
- Stable releases are managed via the \`release\` branch using the standard [Changesets Action](https://github.com/changesets/action).
39
-
40
- 1. **Develop on \`main\`**: Create features and fixes.
41
- 2. **Add Changesets**: Run \`bun changeset\` to document changes and impact (major/minor/patch).
42
- 3. **Merge to \`release\`**: When ready to ship, open a PR from \`main\` to \`release\` or merge manually.
43
- 4. **"Version Packages" PR**:
44
- - The GitHub Action detects new changesets and automatically creates a Pull Request titled **"Version Packages"**.
45
- - This PR contains the version bumps and updated \`CHANGELOG.md\` files.
46
- 5. **Merge & Publish**:
47
- - Review and merge the "Version Packages" PR.
48
- - The Action runs again, detects the versions have been bumped, builds the libraries, and publishes them to npm with the \`latest\` tag.
49
-
50
- ### Publishing Steps
51
-
52
- 1. Ensure all changesets are present on \`main\`.
53
- 2. Merge \`main\` into \`release\`:
54
- \`\`\`bash
55
- git checkout release
56
- git pull origin release
57
- git merge main
58
- git push origin release
59
- \`\`\`
60
- 3. Go to GitHub Pull Requests. You will see a **"Version Packages"** PR created by the bot.
61
- 4. Merge that PR.
62
- 5. The release is now live on npm!
63
-
64
- ## Manual Verification (Optional)
65
-
66
- Before publishing a new version you can run:
67
-
68
- \`\`\`bash
69
- bun run build:not-apps
70
- npx npm-packlist --json packages/libs/contracts
71
- \`\`\`
72
-
73
- ## Rollback
74
-
75
- If a publish fails mid-way, re-run the workflow once the issue is fixed. Already published packages are skipped automatically. Use \`npm deprecate <package>@<version>\` if we need to warn consumers about a broken release.
76
- `}]);
1
+ import { registerDocBlocks } from "./registry.js";
2
+
3
+ //#region ../contracts/dist/docs/PUBLISHING.docblock.js
4
+ const PUBLISHING_DocBlocks = [{
5
+ id: "docs.PUBLISHING",
6
+ title: "Publishing ContractSpec Libraries",
7
+ summary: "This guide describes how we release the ContractSpec libraries to npm. We use a dual-track release system: **Stable** (manual) and **Canary** (automatic).",
8
+ kind: "reference",
9
+ visibility: "public",
10
+ route: "/docs/PUBLISHING",
11
+ tags: ["PUBLISHING"],
12
+ body: "# Publishing ContractSpec Libraries\n\nThis guide describes how we release the ContractSpec libraries to npm. We use a dual-track release system: **Stable** (manual) and **Canary** (automatic).\n\n## Release Tracks\n\n| Track | Branch | npm Tag | Frequency | Versioning | Use Case |\n|-------|--------|---------|-----------|------------|----------|\n| **Stable** | `release` | `latest` | Manual | SemVer (e.g., `1.7.4`) | Production, external users |\n| **Canary** | `main` | `canary` | Every Push | Snapshot (e.g., `1.7.4-canary...`) | Dev, internal testing |\n\n## Prerequisites\n\n- ✅ `NPM_TOKEN` secret is configured in GitHub (owner or automation token with _publish_ scope).\n- ✅ `GITHUB_TOKEN` (built-in) has permissions to create PRs (enabled by default in new repos).\n- ✅ For stable releases: `release` branch exists and is protected.\n\n## Canary Workflow (Automatic)\n\nEvery commit pushed to `main` triggers the `.github/workflows/publish-canary.yml` workflow.\n\n1. **Trigger**: Push to `main`.\n2. **Versioning**: Runs `changeset version --snapshot canary` to generate a temporary snapshot version.\n3. **Publish**: Packages are published to npm with the `canary` tag using `changeset publish --tag canary`.\n\n### Consuming Canary Builds\n\nTo install the latest bleeding-edge version:\n\n```bash\nnpm install @lssm/lib.contracts@canary\n# or\nbun add @lssm/lib.contracts@canary\n```\n\n## Stable Release Workflow (Manual)\n\nStable releases are managed via the `release` branch using the standard [Changesets Action](https://github.com/changesets/action).\n\n1. **Develop on `main`**: Create features and fixes.\n2. **Add Changesets**: Run `bun changeset` to document changes and impact (major/minor/patch).\n3. **Merge to `release`**: When ready to ship, open a PR from `main` to `release` or merge manually.\n4. **\"Version Packages\" PR**:\n - The GitHub Action detects new changesets and automatically creates a Pull Request titled **\"Version Packages\"**.\n - This PR contains the version bumps and updated `CHANGELOG.md` files.\n5. **Merge & Publish**:\n - Review and merge the \"Version Packages\" PR.\n - The Action runs again, detects the versions have been bumped, builds the libraries, and publishes them to npm with the `latest` tag.\n\n### Publishing Steps\n\n1. Ensure all changesets are present on `main`.\n2. Merge `main` into `release`:\n ```bash\n git checkout release\n git pull origin release\n git merge main\n git push origin release\n ```\n3. Go to GitHub Pull Requests. You will see a **\"Version Packages\"** PR created by the bot.\n4. Merge that PR.\n5. The release is now live on npm!\n\n## Manual Verification (Optional)\n\nBefore publishing a new version you can run:\n\n```bash\nbun run build:not-apps\nnpx npm-packlist --json packages/libs/contracts\n```\n\n## Rollback\n\nIf a publish fails mid-way, re-run the workflow once the issue is fixed. Already published packages are skipped automatically. Use `npm deprecate <package>@<version>` if we need to warn consumers about a broken release.\n"
13
+ }];
14
+ registerDocBlocks(PUBLISHING_DocBlocks);
15
+
16
+ //#endregion