@friggframework/core 2.0.0--canary.622.fe9da2d.0 → 2.0.0--canary.623.ee3bde8.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.
Files changed (56) hide show
  1. package/README.md +0 -40
  2. package/application/index.js +9 -10
  3. package/core/create-handler.js +10 -112
  4. package/generated/prisma-mongodb/edge.js +4 -16
  5. package/generated/prisma-mongodb/index-browser.js +1 -13
  6. package/generated/prisma-mongodb/index.d.ts +96 -1494
  7. package/generated/prisma-mongodb/index.js +4 -16
  8. package/generated/prisma-mongodb/package.json +1 -1
  9. package/generated/prisma-mongodb/schema.prisma +0 -23
  10. package/generated/prisma-mongodb/wasm.js +4 -16
  11. package/generated/prisma-postgresql/edge.js +4 -16
  12. package/generated/prisma-postgresql/index-browser.js +1 -13
  13. package/generated/prisma-postgresql/index.d.ts +91 -1540
  14. package/generated/prisma-postgresql/index.js +4 -16
  15. package/generated/prisma-postgresql/package.json +1 -1
  16. package/generated/prisma-postgresql/schema.prisma +0 -22
  17. package/generated/prisma-postgresql/wasm.js +4 -16
  18. package/handlers/app-definition-loader.js +3 -26
  19. package/handlers/integration-event-dispatcher.js +15 -29
  20. package/handlers/routers/integration-webhook-routers.js +7 -20
  21. package/index.js +9 -16
  22. package/integrations/integration-base.js +14 -65
  23. package/modules/module.js +15 -2
  24. package/modules/requester/requester.js +60 -105
  25. package/package.json +5 -12
  26. package/prisma-mongodb/schema.prisma +0 -23
  27. package/prisma-postgresql/schema.prisma +0 -22
  28. package/reporting/README.md +1 -8
  29. package/reporting/reporting-router.js +1 -8
  30. package/reporting/use-cases/list-integrations-report.js +6 -53
  31. package/application/commands/usage-commands.js +0 -56
  32. package/prisma-postgresql/migrations/20260705000000_create_usage_counter/migration.sql +0 -26
  33. package/telemetry/README.md +0 -331
  34. package/telemetry/bind-telemetry-context.js +0 -73
  35. package/telemetry/canonical-counters.js +0 -52
  36. package/telemetry/exporters.js +0 -85
  37. package/telemetry/index.js +0 -26
  38. package/telemetry/instrument-handler.js +0 -87
  39. package/telemetry/no-op-telemetry.js +0 -67
  40. package/telemetry/north-star.js +0 -103
  41. package/telemetry/otel-telemetry.js +0 -213
  42. package/telemetry/plugin-subscribers.js +0 -77
  43. package/telemetry/telemetry-config.js +0 -120
  44. package/telemetry/telemetry-context.js +0 -40
  45. package/telemetry/telemetry-event-bus.js +0 -58
  46. package/telemetry/telemetry-runtime.js +0 -147
  47. package/telemetry/telemetry-service.js +0 -51
  48. package/telemetry/usage-rollup-subscriber.js +0 -116
  49. package/usage/README.md +0 -54
  50. package/usage/index.js +0 -17
  51. package/usage/repositories/usage-repository-documentdb.js +0 -194
  52. package/usage/repositories/usage-repository-factory.js +0 -25
  53. package/usage/repositories/usage-repository-interface.js +0 -37
  54. package/usage/repositories/usage-repository-prisma.js +0 -146
  55. package/usage/tracked-metrics.js +0 -38
  56. package/usage/usage-windows.js +0 -24
package/README.md CHANGED
@@ -200,46 +200,6 @@ const secureData = cryptor.encrypt(JSON.stringify({
200
200
  }));
201
201
  ```
202
202
 
203
- ### 4b. Telemetry & Usage Tracking (`/telemetry`, `/usage`)
204
-
205
- Vendor-neutral OpenTelemetry observability plus durable, per-integration usage
206
- counters (ADR-011). No-op by default (zero cold-start cost); framework seams are
207
- auto-instrumented so integrations get handler/API-module/webhook metrics for free.
208
-
209
- **Usage:**
210
- ```javascript
211
- // App definition — turn on export + declare a North Star:
212
- const Definition = {
213
- name: 'my-app',
214
- telemetry: {
215
- exporter: { type: 'otlp', endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT },
216
- northStar: { default: { name: 'records.synced' } },
217
- },
218
- };
219
-
220
- // Integration code — custom metrics/spans (this.telemetry is auto-tagged):
221
- await this.telemetry.span('delta_sync', async () => {
222
- this.telemetry.count('records.synced', batch.length, { entity: 'contact' });
223
- });
224
-
225
- // Declare which usage counters an integration reports (opts into reporting):
226
- class HubSpotIntegration extends IntegrationBase {
227
- static Definition = {
228
- name: 'hubspot',
229
- usage: { canonical: ['records.synced', 'api.requests'] },
230
- };
231
- }
232
-
233
- // Read the durable usage store (never an APM):
234
- const frigg = createFriggCommands({ integrationClass: HubSpotIntegration });
235
- await frigg.usage.getTotalsByDimension({ metric: 'records.synced', groupBy: 'integrationType' });
236
- ```
237
-
238
- **See:** [`telemetry/README.md`](telemetry/README.md) for the full guide
239
- (exporters, custom metrics, the Usage-Counter contract, North Star, the plugin
240
- tap, cardinality rules, and caveats) and [`usage/README.md`](usage/README.md) for
241
- the store internals.
242
-
243
203
  ### 5. Error Handling (`/errors`)
244
204
 
245
205
  Standardized error types with proper HTTP status codes.
@@ -4,10 +4,15 @@ const {
4
4
  } = require('./commands/integration-commands');
5
5
  const { createUserCommands } = require('./commands/user-commands');
6
6
  const { createEntityCommands } = require('./commands/entity-commands');
7
- const { createCredentialCommands } = require('./commands/credential-commands');
8
- const { createProcessCommands } = require('./commands/process-commands');
9
- const { createSchedulerCommands } = require('./commands/scheduler-commands');
10
- const { createUsageCommands } = require('./commands/usage-commands');
7
+ const {
8
+ createCredentialCommands,
9
+ } = require('./commands/credential-commands');
10
+ const {
11
+ createProcessCommands,
12
+ } = require('./commands/process-commands');
13
+ const {
14
+ createSchedulerCommands,
15
+ } = require('./commands/scheduler-commands');
11
16
 
12
17
  /**
13
18
  * Create a unified command factory with all CRUD operations
@@ -51,11 +56,6 @@ function createFriggCommands({ integrationClass }) {
51
56
 
52
57
  // Process commands
53
58
  ...processCommands,
54
-
55
- // Usage read/write — nested to match `frigg.usage.*`. The North Star
56
- // read takes its config as a call argument, so nothing telemetry-specific
57
- // is threaded through this general factory.
58
- usage: createUsageCommands(),
59
59
  };
60
60
  }
61
61
 
@@ -70,7 +70,6 @@ module.exports = {
70
70
  createCredentialCommands,
71
71
  createProcessCommands,
72
72
  createSchedulerCommands,
73
- createUsageCommands,
74
73
 
75
74
  // Legacy standalone function
76
75
  findIntegrationContextByExternalEntityId,
@@ -4,91 +4,6 @@
4
4
 
5
5
  const { initDebugLog, flushDebugLog } = require('../logs');
6
6
  const { secretsToEnv } = require('./secrets-to-env');
7
- const {
8
- getTelemetry,
9
- getUsageRollupSubscriber,
10
- getPluginTelemetrySubscribers,
11
- } = require('../telemetry/telemetry-runtime');
12
-
13
- // Bounds the tail latency telemetry adds to every warm invocation. Kept low so
14
- // an unreachable OTLP endpoint (e.g. a VPC Lambda with no NAT/egress) costs at
15
- // most this, not multiple seconds. Override with OTEL_FLUSH_TIMEOUT_MS.
16
- const DEFAULT_FLUSH_TIMEOUT_MS =
17
- Number(process.env.OTEL_FLUSH_TIMEOUT_MS) || 500;
18
-
19
- /**
20
- * Fold the invocation's buffered usage counters into the durable store, then
21
- * clear the buffer. On an SQS redelivery (ApproximateReceiveCount > 1) we
22
- * DISCARD rather than flush — the prior delivery already counted, and the usage
23
- * accuracy contract is "approximate, skip obvious redeliveries". Fully guarded.
24
- */
25
- async function flushUsageRollup(subscriber, eventSummary, shouldUseDatabase) {
26
- if (!subscriber) return;
27
- try {
28
- // Persisting usage requires a DB connection. DB-free handlers (e.g. the
29
- // webhook-receipt route) never called connectPrisma, so drop the buffer
30
- // instead of issuing a connectionless Prisma write.
31
- if (!shouldUseDatabase) {
32
- subscriber.discard();
33
- return;
34
- }
35
- // Discard only when EVERY record in the batch is a redelivery. The buffer
36
- // is invocation-scoped (not per-message), so discarding on *any*
37
- // redelivery would drop the fresh records' counts too (silent
38
- // under-count). For a mixed batch we flush: preserving fresh counts and
39
- // at worst re-counting the one redelivered record is strictly better than
40
- // losing fresh data for an approximate store. (Integration queue workers
41
- // are batchSize:1 today, so a batch is all-or-nothing; this keeps it
42
- // correct if batchSize is ever raised.)
43
- const records = Array.isArray(eventSummary?.records)
44
- ? eventSummary.records
45
- : [];
46
- const allRedelivered =
47
- records.length > 0 &&
48
- records.every((r) => Number(r.receiveCount) > 1);
49
- if (allRedelivered) {
50
- subscriber.discard();
51
- } else {
52
- await subscriber.flush();
53
- }
54
- } catch (_) {
55
- // Usage rollup must never break the handler.
56
- }
57
- }
58
-
59
- /**
60
- * Flush telemetry before the Lambda container freezes. Because
61
- * `callbackWaitsForEmptyEventLoop=false` (below) stops the event loop the moment
62
- * the handler returns, OTel's timer-driven batch processors would never fire —
63
- * so spans/metrics must be flushed synchronously here. Bounded by a timeout so a
64
- * stalled exporter can never block the response, and fully guarded so a flush
65
- * failure never breaks the handler.
66
- */
67
- async function flushTelemetry(telemetry, timeoutMs) {
68
- try {
69
- if (
70
- !telemetry ||
71
- typeof telemetry.isEnabled !== 'function' ||
72
- !telemetry.isEnabled()
73
- ) {
74
- return;
75
- }
76
- let timer;
77
- const deadline = new Promise((resolve) => {
78
- timer = setTimeout(resolve, timeoutMs);
79
- });
80
- try {
81
- await Promise.race([
82
- Promise.resolve(telemetry.forceFlush()),
83
- deadline,
84
- ]);
85
- } finally {
86
- clearTimeout(timer);
87
- }
88
- } catch (_) {
89
- // Telemetry flush must never break the handler.
90
- }
91
- }
92
7
 
93
8
  // Best-effort extraction of correlation identifiers from a Lambda event.
94
9
  // For SQS: pulls messageIds + parsed event/processId/integrationId from each
@@ -121,7 +36,8 @@ const summarizeLambdaEvent = (event) => {
121
36
  if (event.httpMethod || event.requestContext?.http) {
122
37
  return {
123
38
  source: 'http',
124
- method: event.httpMethod || event.requestContext?.http?.method,
39
+ method:
40
+ event.httpMethod || event.requestContext?.http?.method,
125
41
  path: event.path || event.rawPath,
126
42
  };
127
43
  }
@@ -134,9 +50,6 @@ const createHandler = (optionByName = {}) => {
134
50
  isUserFacingResponse = true,
135
51
  method,
136
52
  shouldUseDatabase = true,
137
- telemetry,
138
- flushTimeoutMs = DEFAULT_FLUSH_TIMEOUT_MS,
139
- usageRollup,
140
53
  } = optionByName;
141
54
 
142
55
  if (!method) {
@@ -145,23 +58,16 @@ const createHandler = (optionByName = {}) => {
145
58
 
146
59
  return async (event, context) => {
147
60
  const eventSummary = summarizeLambdaEvent(event);
148
- const activeTelemetry = telemetry || getTelemetry();
149
- const activeUsageRollup =
150
- usageRollup !== undefined
151
- ? usageRollup
152
- : getUsageRollupSubscriber();
153
-
154
- // Wire adopter-declared telemetry subscribers once per cold start.
155
- // Memoized in the singleton, so this is a cheap
156
- // no-op after the first invocation.
157
- getPluginTelemetrySubscribers();
158
61
 
159
62
  try {
160
- console.info(`[createHandler] ${eventName}: handler entry`, {
161
- eventName,
162
- awsRequestId: context?.awsRequestId,
163
- ...eventSummary,
164
- });
63
+ console.info(
64
+ `[createHandler] ${eventName}: handler entry`,
65
+ {
66
+ eventName,
67
+ awsRequestId: context?.awsRequestId,
68
+ ...eventSummary,
69
+ }
70
+ );
165
71
 
166
72
  initDebugLog(eventName, event);
167
73
 
@@ -233,14 +139,6 @@ const createHandler = (optionByName = {}) => {
233
139
 
234
140
  // Here we can just rethrow and let AWS build the response.
235
141
  throw error;
236
- } finally {
237
- // Flush telemetry + usage before the container freezes.
238
- await flushTelemetry(activeTelemetry, flushTimeoutMs);
239
- await flushUsageRollup(
240
- activeUsageRollup,
241
- eventSummary,
242
- shouldUseDatabase
243
- );
244
142
  }
245
143
  };
246
144
  };