@friggframework/core 2.0.0--canary.700.80ec1cc.0 → 2.0.0--canary.702.047d3c4.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 (130) hide show
  1. package/database/documentdb-utils.js +1 -6
  2. package/errors/index.js +0 -4
  3. package/generated/prisma-mongodb/edge.js +4 -52
  4. package/generated/prisma-mongodb/index-browser.js +1 -49
  5. package/generated/prisma-mongodb/index.d.ts +60 -3506
  6. package/generated/prisma-mongodb/index.js +4 -52
  7. package/generated/prisma-mongodb/package.json +1 -1
  8. package/generated/prisma-mongodb/schema.prisma +0 -65
  9. package/generated/prisma-mongodb/wasm.js +4 -52
  10. package/generated/prisma-postgresql/edge.js +4 -52
  11. package/generated/prisma-postgresql/index-browser.js +1 -49
  12. package/generated/prisma-postgresql/index.d.ts +94 -3824
  13. package/generated/prisma-postgresql/index.js +4 -52
  14. package/generated/prisma-postgresql/package.json +1 -1
  15. package/generated/prisma-postgresql/schema.prisma +0 -63
  16. package/generated/prisma-postgresql/wasm.js +4 -52
  17. package/handlers/WEBHOOKS.md +0 -29
  18. package/handlers/app-definition-loader.js +9 -2
  19. package/handlers/app-handler-helpers.js +2 -5
  20. package/handlers/integration-event-dispatcher.js +3 -7
  21. package/handlers/routers/integration-webhook-routers.js +38 -26
  22. package/index.js +0 -2
  23. package/integrations/integration-base.js +1 -162
  24. package/integrations/integration-router.js +1 -6
  25. package/integrations/repositories/integration-mapping-repository-documentdb.js +0 -50
  26. package/integrations/repositories/integration-mapping-repository-interface.js +0 -15
  27. package/integrations/repositories/integration-mapping-repository-mongo.js +0 -29
  28. package/integrations/repositories/integration-mapping-repository-postgres.js +0 -30
  29. package/integrations/repositories/integration-mapping-repository.js +0 -29
  30. package/integrations/repositories/integration-repository-documentdb.js +2 -6
  31. package/integrations/repositories/integration-repository-interface.js +0 -3
  32. package/integrations/repositories/integration-repository-mongo.js +5 -20
  33. package/integrations/repositories/integration-repository-postgres.js +1 -5
  34. package/integrations/repositories/process-repository-mongo.js +1 -1
  35. package/integrations/use-cases/create-integration.js +4 -14
  36. package/integrations/use-cases/delete-integration-for-user.js +4 -4
  37. package/integrations/use-cases/get-integration-for-user.js +2 -4
  38. package/integrations/use-cases/get-integration-instance.js +4 -4
  39. package/integrations/use-cases/get-integrations-for-user.js +4 -4
  40. package/integrations/use-cases/get-possible-integrations.js +2 -7
  41. package/integrations/use-cases/update-integration.js +4 -4
  42. package/package.json +6 -6
  43. package/prisma-mongodb/schema.prisma +0 -65
  44. package/prisma-postgresql/schema.prisma +0 -63
  45. package/queues/queuer-util.js +2 -9
  46. package/errors/mapping-already-exists-error.js +0 -14
  47. package/handlers/workers/integration-triggers.js +0 -25
  48. package/infrastructure/scheduler/recurrence.js +0 -204
  49. package/integrations/definitions/README.md +0 -278
  50. package/integrations/definitions/canonical.js +0 -11
  51. package/integrations/definitions/capabilities/AUDIT.md +0 -480
  52. package/integrations/definitions/capabilities/acmeerp.capabilities.json +0 -633
  53. package/integrations/definitions/capabilities/asana.capabilities.json +0 -279
  54. package/integrations/definitions/capabilities/calendly.capabilities.json +0 -385
  55. package/integrations/definitions/capabilities/docusign.capabilities.json +0 -314
  56. package/integrations/definitions/capabilities/fathom.capabilities.json +0 -238
  57. package/integrations/definitions/capabilities/github.capabilities.json +0 -585
  58. package/integrations/definitions/capabilities/hubspot.capabilities.json +0 -822
  59. package/integrations/definitions/capabilities/jira.capabilities.json +0 -391
  60. package/integrations/definitions/capabilities/klaviyo.capabilities.json +0 -503
  61. package/integrations/definitions/capabilities/linear.capabilities.json +0 -378
  62. package/integrations/definitions/capabilities/netsuite.capabilities.json +0 -535
  63. package/integrations/definitions/capabilities/notion.capabilities.json +0 -208
  64. package/integrations/definitions/capabilities/phone.capabilities.json +0 -511
  65. package/integrations/definitions/capabilities/pipedrive.capabilities.json +0 -430
  66. package/integrations/definitions/capabilities/quickbooks.capabilities.json +0 -635
  67. package/integrations/definitions/capabilities/salesforce.capabilities.json +0 -568
  68. package/integrations/definitions/capabilities/shopify.capabilities.json +0 -1128
  69. package/integrations/definitions/capabilities/slack.capabilities.json +0 -373
  70. package/integrations/definitions/capabilities/stripe.capabilities.json +0 -630
  71. package/integrations/definitions/capabilities/webflow.capabilities.json +0 -196
  72. package/integrations/definitions/capabilities/zendesk.capabilities.json +0 -422
  73. package/integrations/definitions/compile.js +0 -80
  74. package/integrations/definitions/config-form.js +0 -137
  75. package/integrations/definitions/examples/acme-erp-quickbooks.definition.json +0 -467
  76. package/integrations/definitions/examples/asana-slack.definition.json +0 -219
  77. package/integrations/definitions/examples/calendly-salesforce.definition.json +0 -459
  78. package/integrations/definitions/examples/docusign-salesforce.definition.json +0 -305
  79. package/integrations/definitions/examples/fathom-hubspot-notion.definition.json +0 -575
  80. package/integrations/definitions/examples/github-linear.definition.json +0 -322
  81. package/integrations/definitions/examples/hubspot-slack.definition.json +0 -427
  82. package/integrations/definitions/examples/klaviyo-hubspot.definition.json +0 -336
  83. package/integrations/definitions/examples/phone-hubspot.definition.json +0 -633
  84. package/integrations/definitions/examples/pipedrive-hubspot.definition.json +0 -136
  85. package/integrations/definitions/examples/pipedrive-phone.definition.json +0 -340
  86. package/integrations/definitions/examples/records/phone-hubspot.definition-version.json +0 -652
  87. package/integrations/definitions/examples/records/phone-hubspot.integration.json +0 -86
  88. package/integrations/definitions/examples/records/phone-hubspot.mappings.json +0 -39
  89. package/integrations/definitions/examples/records/phone-hubspot.workflow-run.json +0 -62
  90. package/integrations/definitions/examples/shopify-klaviyo.definition.json +0 -488
  91. package/integrations/definitions/examples/shopify-netsuite.definition.json +0 -622
  92. package/integrations/definitions/examples/stripe-quickbooks.definition.json +0 -476
  93. package/integrations/definitions/examples/webflow-hubspot-slack.definition.json +0 -262
  94. package/integrations/definitions/examples/zendesk-jira.definition.json +0 -604
  95. package/integrations/definitions/expressions.js +0 -229
  96. package/integrations/definitions/index.js +0 -45
  97. package/integrations/definitions/integration-runtime.js +0 -763
  98. package/integrations/definitions/interpreter.js +0 -104
  99. package/integrations/definitions/manifests.js +0 -177
  100. package/integrations/definitions/renderers/common.js +0 -67
  101. package/integrations/definitions/renderers/html.js +0 -129
  102. package/integrations/definitions/renderers/hubspot.js +0 -59
  103. package/integrations/definitions/renderers/preview.js +0 -154
  104. package/integrations/definitions/renderers/slack.js +0 -146
  105. package/integrations/definitions/repositories/definition-version-repository.js +0 -67
  106. package/integrations/definitions/repositories/workflow-run-repository.js +0 -80
  107. package/integrations/definitions/router.js +0 -170
  108. package/integrations/definitions/runtime.js +0 -268
  109. package/integrations/definitions/schema/capability-manifest.v0.1.schema.json +0 -549
  110. package/integrations/definitions/schema/installation.v0.1.schema.json +0 -130
  111. package/integrations/definitions/schema/integration-definition.v0.1.schema.json +0 -909
  112. package/integrations/definitions/schema/records.md +0 -105
  113. package/integrations/definitions/schema-check.js +0 -58
  114. package/integrations/definitions/scripts/check-manifests.js +0 -220
  115. package/integrations/definitions/scripts/validate.js +0 -66
  116. package/integrations/definitions/steps.js +0 -123
  117. package/integrations/definitions/sync-engine.js +0 -297
  118. package/integrations/definitions/tests/helpers-fake-crm.js +0 -49
  119. package/integrations/definitions/transforms.js +0 -91
  120. package/integrations/definitions/use-cases/definition-use-cases.js +0 -245
  121. package/integrations/definitions/validate.js +0 -436
  122. package/integrations/definitions/versioning.js +0 -176
  123. package/integrations/definitions/webhooks.js +0 -119
  124. package/integrations/integration-types.js +0 -64
  125. package/integrations/triggers.js +0 -244
  126. package/integrations/use-cases/run-trigger-tick.js +0 -155
  127. package/integrations/use-cases/run-trigger.js +0 -77
  128. package/prisma-postgresql/migrations/20261018000000_add_data_defined_integrations/migration.sql +0 -66
  129. package/prisma-postgresql/migrations/20261019000000_workflow_run_waits/migration.sql +0 -7
  130. package/prisma-postgresql/migrations/20261019120000_definition_workspace/migration.sql +0 -5
@@ -22,7 +22,6 @@ const { getTelemetry } = require('../telemetry/telemetry-runtime');
22
22
  const { instrumentHandler } = require('../telemetry/instrument-handler');
23
23
  const { bindTelemetryContext } = require('../telemetry/bind-telemetry-context');
24
24
  const { getLogger } = require('../logs');
25
- const { TRIGGER_RUN, TRIGGER_TICK, resolveTrigger } = require('./triggers');
26
25
 
27
26
  const constantsToBeMigrated = {
28
27
  defaultEvents: {
@@ -36,8 +35,6 @@ const constantsToBeMigrated = {
36
35
  REFRESH_USER_ACTION_OPTIONS: 'REFRESH_USER_ACTION_OPTIONS',
37
36
  WEBHOOK_RECEIVED: 'WEBHOOK_RECEIVED', // HTTP handler, no DB
38
37
  ON_WEBHOOK: 'ON_WEBHOOK', // Queue worker, DB-connected
39
- [TRIGGER_RUN]: TRIGGER_RUN, // Queue worker: one recurring trigger run (ADR-055)
40
- [TRIGGER_TICK]: TRIGGER_TICK, // Queue worker: a trigger tick carrying on from its page cursor
41
38
  // etc...
42
39
  },
43
40
  types: {
@@ -46,26 +43,6 @@ const constantsToBeMigrated = {
46
43
  },
47
44
  };
48
45
 
49
- /**
50
- * The facts about a webhook request that signature checks need, small enough to travel in the queue message: the
51
- * method, the public URL the vendor called, and the raw body (up to 96 KB; beyond that it is left out and a check that
52
- * needs it fails closed, because SQS messages are capped at 256 KB and the parsed body travels too).
53
- */
54
- const RAW_BODY_LIMIT = 96 * 1024;
55
- function webhookRequestFacts(req) {
56
- const h = req.headers || {};
57
- const proto = String(h['x-forwarded-proto'] || req.protocol || 'https').split(',')[0].trim();
58
- const host = h['x-forwarded-host'] || h.host;
59
- const url = host ? `${proto}://${host}${req.originalUrl || req.url || ''}` : undefined;
60
- const raw = req.rawBody;
61
- const rawBody = raw == null ? undefined : (Buffer.isBuffer(raw) ? raw.toString('utf8') : String(raw));
62
- return {
63
- method: req.method,
64
- ...(url ? { url } : {}),
65
- ...(rawBody !== undefined && Buffer.byteLength(rawBody) <= RAW_BODY_LIMIT ? { rawBody } : {}),
66
- };
67
- }
68
-
69
46
  class IntegrationBase {
70
47
  // todo: maybe we can pass this as Dependency Injection in the sub-class constructor
71
48
  integrationRepository = createIntegrationRepository();
@@ -114,9 +91,6 @@ class IntegrationBase {
114
91
  extensions: {},
115
92
  // usage: { canonical: ['records.synced'], custom: { 'deals.enriched': { unit, label } } }
116
93
  usage: {},
117
- // Recurring triggers (ADR-055) — see integrations/triggers.js
118
- // Shape: { [name]: { every | at | cron, timezone?, tick?, when?, overlap?, configurable?, handler } }
119
- triggers: {},
120
94
  display: {
121
95
  name: 'Integration Name',
122
96
  logo: '',
@@ -129,14 +103,6 @@ class IntegrationBase {
129
103
  return this.Definition.name;
130
104
  }
131
105
 
132
- /**
133
- * The deployed integration whose queue and functions this one runs on: itself, unless another class hosts it
134
- * (`static Host`, e.g. a published integration definition run by the shared runtime).
135
- */
136
- static getDeploymentName() {
137
- return (this.Host || this).Definition.name;
138
- }
139
-
140
106
  static getCurrentVersion() {
141
107
  return this.Definition.version;
142
108
  }
@@ -205,14 +171,6 @@ class IntegrationBase {
205
171
  type: constantsToBeMigrated.types.LIFE_CYCLE_EVENT,
206
172
  handler: this.onWebhook,
207
173
  },
208
- [TRIGGER_RUN]: {
209
- type: constantsToBeMigrated.types.LIFE_CYCLE_EVENT,
210
- handler: this.onTriggerRun,
211
- },
212
- [TRIGGER_TICK]: {
213
- type: constantsToBeMigrated.types.LIFE_CYCLE_EVENT,
214
- handler: this.onTriggerTick,
215
- },
216
174
  };
217
175
  }
218
176
 
@@ -499,35 +457,6 @@ class IntegrationBase {
499
457
  );
500
458
  }
501
459
 
502
- /**
503
- * Insert-only mapping write; usable as an atomic claim/lock row.
504
- * @throws {MappingAlreadyExistsError} If a mapping for sourceId exists
505
- */
506
- async createMapping(sourceId, mapping) {
507
- if (!sourceId) {
508
- throw new Error(`sourceId must be set`);
509
- }
510
- return await this.integrationMappingRepository.createMapping(
511
- this.id,
512
- sourceId,
513
- mapping
514
- );
515
- }
516
-
517
- /**
518
- * Deletes the mapping for sourceId. A missing mapping is not an error
519
- * (resolves with deletedCount 0).
520
- */
521
- async deleteMapping(sourceId) {
522
- if (!sourceId) {
523
- throw new Error(`sourceId must be set`);
524
- }
525
- return await this.integrationMappingRepository.deleteMapping(
526
- this.id,
527
- sourceId
528
- );
529
- }
530
-
531
460
  /**
532
461
  * CHILDREN CAN OVERRIDE THESE CONFIGURATION METHODS
533
462
  */
@@ -564,90 +493,10 @@ class IntegrationBase {
564
493
  } else if (this.status === 'NEEDS_CONFIG') {
565
494
  await this.persistStatus('ENABLED');
566
495
  }
567
- await this.reportTriggerChoices();
568
496
  }
569
497
 
570
498
  async onDelete(params) {}
571
499
 
572
- /**
573
- * The recurring triggers declared for one installation (ADR-055): `Definition.triggers`, each with its `name`.
574
- * Static so the tick can read them from a record without hydrating the installation; a class whose triggers
575
- * depend on the installation (integrations published as definitions, `Definition.instanceTriggers`) overrides it.
576
- * @param {{ config?: Object, record?: Object }} [installation]
577
- * @returns {Promise<Array<Object>>}
578
- */
579
- static async triggersFor(installation = {}) {
580
- return Object.entries(this.Definition?.triggers || {}).map(([name, t]) => ({ ...t, name }));
581
- }
582
-
583
- /** This installation's trigger declarations (the static `triggersFor`, unless a subclass knows better). */
584
- async triggerDeclarations() {
585
- return this.constructor.triggersFor({ config: this.config || {}, record: this.record });
586
- }
587
-
588
- /**
589
- * Run one recurring trigger: the queue worker dispatches `FRIGG_TRIGGER_RUN` here with
590
- * `{ integrationId, trigger, scheduledFor }` after hydrating the installation. The handler is called as
591
- * `handler(payload, ctx)` with `payload = { trigger, scheduledFor }` and `ctx = { modules, config, log, integration }`
592
- * (ADR-054); a string handler names a method on this instance. Overlap and the run record: use-cases/run-trigger.js.
593
- */
594
- async onTriggerRun({ data = {} } = {}) {
595
- const declarations = await this.triggerDeclarations();
596
- const declaration = declarations.find((t) => t.name === data.trigger);
597
- const resolved = declaration ? resolveTrigger(declaration.name, declaration, this.config || {}) : null;
598
- const payload = { trigger: data.trigger, scheduledFor: data.scheduledFor };
599
- const invoke = async (p) => {
600
- const handler = typeof declaration.handler === 'string' ? this[declaration.handler] : declaration.handler;
601
- if (typeof handler !== 'function') throw new Error(`Trigger "${declaration.name}" handler "${declaration.handler}" is not a method of ${this.constructor.Definition?.name}`);
602
- return handler.call(this, p, { modules: this.modules, config: this.config || {}, log: this.logger, integration: this });
603
- };
604
- const { RunTrigger } = require('./use-cases/run-trigger');
605
- if (!this.triggerProcessRepository) {
606
- const { createProcessRepository } = require('./repositories/process-repository-factory');
607
- this.triggerProcessRepository = createProcessRepository();
608
- }
609
- const outcome = await new RunTrigger({ processRepository: this.triggerProcessRepository }).execute({ integration: this, resolved, invoke, payload });
610
- if (outcome.status !== 'ran') {
611
- this.logger.info('Trigger run not started', { eventName: `${this.logger.name}.trigger_${outcome.status}`, trigger: data.trigger, reason: outcome.reason });
612
- }
613
- return outcome;
614
- }
615
-
616
- /** The queue a one-time scheduled job (a paused run's resume) fires into: this integration's deployment queue (`<NAME>_QUEUE_URL`). */
617
- scheduleQueueUrl() {
618
- if (typeof this.getQueueUrl === 'function') return this.getQueueUrl();
619
- return process.env[`${this.constructor.getDeploymentName().toUpperCase().replace(/-/g, '_')}_QUEUE_URL`];
620
- }
621
-
622
- /** A tick that ran out of time continues here, on a dry instance, from its page cursor. */
623
- async onTriggerTick({ data = {}, context } = {}) {
624
- const { runTriggerTick } = require('./use-cases/run-trigger-tick');
625
- return runTriggerTick(this.constructor, data, context);
626
- }
627
-
628
- /**
629
- * Report each trigger timing this installation chose that cannot be used (not configurable, or under the
630
- * floor): the trigger keeps its default, and the integration gets a warning message saying why. No-op for an
631
- * integration without triggers.
632
- */
633
- async reportTriggerChoices() {
634
- if (this.id === undefined || this.id === null) return [];
635
- try {
636
- const declarations = await this.triggerDeclarations();
637
- const problems = declarations
638
- .map((t) => ({ name: t.name, problems: resolveTrigger(t.name, t, this.config || {}).problems }))
639
- .filter((p) => p.problems.length);
640
- for (const p of problems) {
641
- await this.updateIntegrationMessages.execute(this.id, 'warnings', 'Trigger timing not changed', `${p.name}: ${p.problems.join('; ')}`, Date.now());
642
- }
643
- return problems;
644
- } catch (error) {
645
- // A report, never a reason to fail the update.
646
- this.logger.warn('Trigger choices not checked', { eventName: `${this.logger.name}.trigger_choices_unchecked`, error });
647
- return [];
648
- }
649
- }
650
-
651
500
  async getConfigOptions() {
652
501
  const options = {
653
502
  jsonSchema: {},
@@ -719,7 +568,6 @@ class IntegrationBase {
719
568
  body,
720
569
  headers: req.headers,
721
570
  query: req.query,
722
- ...webhookRequestFacts(req),
723
571
  });
724
572
 
725
573
  res.status(200).json({ received: true });
@@ -729,15 +577,6 @@ class IntegrationBase {
729
577
  // Default: no-op, integrations override this
730
578
  }
731
579
 
732
- /**
733
- * What a module's verifyWebhookSignature needs about a queued delivery (onWebhookReceived put it there): the
734
- * headers, the parsed body, the raw body exactly as received, and the method and public URL some vendors sign
735
- * (HubSpot v3). Call as `this.<module>.api.verifyWebhookSignature(this.webhookVerificationInput(data))`.
736
- */
737
- webhookVerificationInput(data = {}) {
738
- return { headers: data.headers || {}, body: data.body, query: data.query || {}, rawBody: data.rawBody, method: data.method, url: data.url };
739
- }
740
-
741
580
  /**
742
581
  * Queue a webhook for asynchronous worker dispatch.
743
582
  *
@@ -754,7 +593,7 @@ class IntegrationBase {
754
593
  async queueWebhook(data) {
755
594
  const { QueuerUtil } = require('../queues');
756
595
 
757
- const queueName = `${this.constructor.getDeploymentName()
596
+ const queueName = `${this.constructor.Definition.name
758
597
  .toUpperCase()
759
598
  .replace(/-/g, '_')}_QUEUE_URL`;
760
599
  const queueUrl = process.env[queueName];
@@ -209,11 +209,6 @@ function createIntegrationRouter() {
209
209
  updateIntegration,
210
210
  getPossibleIntegrations,
211
211
  });
212
- // Integration versions, run history, sync progress and approvals (ADR-063): mounted when the app registers the integration runtime.
213
- require('./definitions/router').setIntegrationRuntimeRoutes(router, authenticateUser, {
214
- getIntegrationInstance,
215
- integrationClasses,
216
- });
217
212
  setEntityRoutes(router, authenticateUser, {
218
213
  getCredentialForUser,
219
214
  getModuleInstanceFromType,
@@ -274,7 +269,7 @@ function setIntegrationRoutes(router, authenticateUser, useCases) {
274
269
  const integrations = await getIntegrationsForUser.execute(userId);
275
270
  const results = {
276
271
  entities: {
277
- options: await getPossibleIntegrations.execute({ userId }),
272
+ options: await getPossibleIntegrations.execute(),
278
273
  authorized: await getEntitiesForUser.execute(userId),
279
274
  },
280
275
  integrations: integrations,
@@ -1,5 +1,4 @@
1
1
  const { prisma } = require('../../database/prisma');
2
- const { MappingAlreadyExistsError } = require('../../errors');
3
2
  const {
4
3
  toObjectId,
5
4
  fromObjectId,
@@ -181,55 +180,6 @@ class IntegrationMappingRepositoryDocumentDB extends IntegrationMappingRepositor
181
180
  return this._mapMapping(decryptedMapping);
182
181
  }
183
182
 
184
- async createMapping(integrationId, sourceId, mapping) {
185
- const now = new Date();
186
- const encryptedDocument = await this.encryptionService.encryptFields(
187
- 'IntegrationMapping',
188
- {
189
- integrationId,
190
- sourceId:
191
- sourceId === null || sourceId === undefined
192
- ? null
193
- : String(sourceId),
194
- mapping,
195
- createdAt: now,
196
- updatedAt: now,
197
- }
198
- );
199
-
200
- let insertedId;
201
- try {
202
- insertedId = await insertOne(
203
- this.prisma,
204
- 'IntegrationMapping',
205
- encryptedDocument
206
- );
207
- } catch (error) {
208
- if (error.code === 11000) {
209
- throw new MappingAlreadyExistsError(integrationId, sourceId, {
210
- cause: error,
211
- });
212
- }
213
- throw error;
214
- }
215
-
216
- const created = await findOne(this.prisma, 'IntegrationMapping', {
217
- _id: insertedId,
218
- });
219
- if (!created) {
220
- throw new Error(
221
- 'Failed to create mapping: Document not found after insert. ' +
222
- 'This indicates a database consistency issue.'
223
- );
224
- }
225
- return this._mapMapping(
226
- await this.encryptionService.decryptFields(
227
- 'IntegrationMapping',
228
- created
229
- )
230
- );
231
- }
232
-
233
183
  async findMappingsByIntegration(integrationId) {
234
184
  const filter = {};
235
185
  if (integrationId) filter.integrationId = integrationId;
@@ -39,21 +39,6 @@ class IntegrationMappingRepositoryInterface {
39
39
  throw new Error('Method upsertMapping must be implemented by subclass');
40
40
  }
41
41
 
42
- /**
43
- * Insert a mapping, failing if one already exists for the
44
- * (integrationId, sourceId) pair. Atomic: usable as a claim/lock row.
45
- *
46
- * @param {string|number} integrationId - The integration ID
47
- * @param {string} sourceId - The source ID for lookup
48
- * @param {Object} mapping - The mapping data
49
- * @returns {Promise<Object>} The created mapping document
50
- * @throws {MappingAlreadyExistsError} If the pair already exists
51
- * @abstract
52
- */
53
- async createMapping(integrationId, sourceId, mapping) {
54
- throw new Error('createMapping must be implemented by subclass');
55
- }
56
-
57
42
  /**
58
43
  * Find all mappings for an integration
59
44
  *
@@ -1,5 +1,4 @@
1
1
  const { prisma } = require('../../database/prisma');
2
- const { MappingAlreadyExistsError } = require('../../errors');
3
2
  const {
4
3
  assertMappingWrittenUnencrypted,
5
4
  decryptQueriedMappings,
@@ -94,34 +93,6 @@ class IntegrationMappingRepositoryMongo extends IntegrationMappingRepositoryInte
94
93
  });
95
94
  }
96
95
 
97
- /**
98
- * Insert a mapping; fails if (integrationId, sourceId) already exists
99
- *
100
- * @param {string} integrationId - The integration ID
101
- * @param {string} sourceId - The source ID
102
- * @param {Object} mapping - The mapping data
103
- * @returns {Promise<Object>} The created mapping document
104
- * @throws {MappingAlreadyExistsError} If the pair already exists
105
- */
106
- async createMapping(integrationId, sourceId, mapping) {
107
- try {
108
- return await this.prisma.integrationMapping.create({
109
- data: {
110
- integrationId,
111
- sourceId: this._toString(sourceId),
112
- mapping,
113
- },
114
- });
115
- } catch (error) {
116
- if (error.code === 'P2002') {
117
- throw new MappingAlreadyExistsError(integrationId, sourceId, {
118
- cause: error,
119
- });
120
- }
121
- throw error;
122
- }
123
- }
124
-
125
96
  /**
126
97
  * Find all mappings for an integration
127
98
  * Replaces: IntegrationMapping.find({ integration: integrationId })
@@ -1,5 +1,4 @@
1
1
  const { prisma } = require('../../database/prisma');
2
- const { MappingAlreadyExistsError } = require('../../errors');
3
2
  const {
4
3
  assertMappingWrittenUnencrypted,
5
4
  decryptQueriedMappings,
@@ -151,35 +150,6 @@ class IntegrationMappingRepositoryPostgres extends IntegrationMappingRepositoryI
151
150
  return this._convertMappingIds(result);
152
151
  }
153
152
 
154
- /**
155
- * Insert a mapping; fails if (integrationId, sourceId) already exists
156
- *
157
- * @param {string} integrationId - The integration ID
158
- * @param {string} sourceId - The source ID
159
- * @param {Object} mapping - The mapping data
160
- * @returns {Promise<Object>} The created mapping document
161
- * @throws {MappingAlreadyExistsError} If the pair already exists
162
- */
163
- async createMapping(integrationId, sourceId, mapping) {
164
- try {
165
- const created = await this.prisma.integrationMapping.create({
166
- data: {
167
- integrationId: this._stringToInt(integrationId),
168
- sourceId: this._toString(sourceId),
169
- mapping,
170
- },
171
- });
172
- return this._convertMappingIds(created);
173
- } catch (error) {
174
- if (error.code === 'P2002') {
175
- throw new MappingAlreadyExistsError(integrationId, sourceId, {
176
- cause: error,
177
- });
178
- }
179
- throw error;
180
- }
181
- }
182
-
183
153
  /**
184
154
  * Find all mappings for an integration
185
155
  * Replaces: IntegrationMapping.find({ integration: integrationId })
@@ -1,5 +1,4 @@
1
1
  const { prisma } = require('../../database/prisma');
2
- const { MappingAlreadyExistsError } = require('../../errors');
3
2
  const {
4
3
  IntegrationMappingRepositoryInterface,
5
4
  } = require('./integration-mapping-repository-interface');
@@ -70,34 +69,6 @@ class IntegrationMappingRepository extends IntegrationMappingRepositoryInterface
70
69
  });
71
70
  }
72
71
 
73
- /**
74
- * Insert a mapping; fails if (integrationId, sourceId) already exists
75
- *
76
- * @param {string} integrationId - The integration ID
77
- * @param {string} sourceId - The source ID
78
- * @param {Object} mapping - The mapping data
79
- * @returns {Promise<Object>} The created mapping document
80
- * @throws {MappingAlreadyExistsError} If the pair already exists
81
- */
82
- async createMapping(integrationId, sourceId, mapping) {
83
- try {
84
- return await this.prisma.integrationMapping.create({
85
- data: {
86
- integrationId,
87
- sourceId,
88
- mapping,
89
- },
90
- });
91
- } catch (error) {
92
- if (error.code === 'P2002') {
93
- throw new MappingAlreadyExistsError(integrationId, sourceId, {
94
- cause: error,
95
- });
96
- }
97
- throw error;
98
- }
99
- }
100
-
101
72
  /**
102
73
  * Find all mappings for an integration
103
74
  * Replaces: IntegrationMapping.find({ integration: integrationId })
@@ -28,7 +28,7 @@ class IntegrationRepositoryDocumentDB extends IntegrationRepositoryInterface {
28
28
  return records.map((doc) => this._mapIntegration(doc));
29
29
  }
30
30
 
31
- async findIntegrations({ type, status, limit, after } = {}) {
31
+ async findIntegrations({ type, status } = {}) {
32
32
  const filter = {};
33
33
  if (type) {
34
34
  filter['config.type'] = type;
@@ -36,11 +36,7 @@ class IntegrationRepositoryDocumentDB extends IntegrationRepositoryInterface {
36
36
  if (status) {
37
37
  filter.status = status;
38
38
  }
39
- if (limit && after !== undefined && after !== null) {
40
- // Extended JSON: $runCommandRaw does not match a BSON ObjectId instance inside an operator.
41
- filter._id = { $gt: { $oid: fromObjectId(toObjectId(after)) } };
42
- }
43
- const records = await findMany(this.prisma, 'Integration', filter, limit ? { sort: { _id: 1 }, limit, batchSize: limit } : {});
39
+ const records = await findMany(this.prisma, 'Integration', filter);
44
40
  return records.map((doc) => this._mapIntegration(doc));
45
41
  }
46
42
 
@@ -28,9 +28,6 @@ class IntegrationRepositoryInterface {
28
28
  * @param {Object} [filter={}]
29
29
  * @param {string} [filter.type] - Integration type (config.type)
30
30
  * @param {string} [filter.status] - Integration status
31
- * @param {number} [filter.limit] - Page size: at most this many rows, in id order
32
- * @param {string|number} [filter.after] - With limit: only rows whose id sorts after this one (the last id of the
33
- * previous page), so a caller can page through every row (the trigger tick does, ADR-055)
34
31
  * @returns {Promise<Array>} Array of integration objects (possibly empty)
35
32
  * @abstract
36
33
  */
@@ -61,35 +61,20 @@ class IntegrationRepositoryMongo extends IntegrationRepositoryInterface {
61
61
  * @param {string} [filter.status] - Integration status
62
62
  * @returns {Promise<Array>} Array of integration objects (possibly empty)
63
63
  */
64
- async findIntegrations({ type, status, limit, after } = {}) {
64
+ async findIntegrations({ type, status } = {}) {
65
65
  const where = {};
66
+ if (type) {
67
+ where.config = { path: ['type'], equals: type };
68
+ }
66
69
  if (status) {
67
70
  where.status = status;
68
71
  }
69
- if (limit && after !== undefined && after !== null) {
70
- where.id = { gt: after };
71
- }
72
- if (type) {
73
- // Prisma's MongoDB connector has no JSON path filter (`config: { path }` is refused), so the ids of the
74
- // matching rows come from a raw find on config.type, then the rows load as usual.
75
- const filter = { 'config.type': type };
76
- if (status) filter.status = status;
77
- if (where.id) filter._id = { $gt: { $oid: String(after) } };
78
- const found = await this.prisma.integration.findRaw({
79
- filter,
80
- options: { projection: { _id: 1 }, sort: { _id: 1 }, ...(limit ? { limit } : {}) },
81
- });
82
- const ids = found.map((doc) => doc._id?.$oid ?? String(doc._id));
83
- if (!ids.length) return [];
84
- where.id = { in: ids };
85
- }
86
72
 
87
73
  const integrations = await this.prisma.integration.findMany({
88
74
  where,
89
75
  include: {
90
76
  entities: true,
91
77
  },
92
- ...(limit ? { orderBy: { id: 'asc' }, take: limit } : {}),
93
78
  });
94
79
 
95
80
  return integrations.map((integration) => ({
@@ -434,7 +419,7 @@ class IntegrationRepositoryMongo extends IntegrationRepositoryInterface {
434
419
  for (const [key, value] of Object.entries(patch)) {
435
420
  $set[`config.${key}`] = value;
436
421
  }
437
- $set.updatedAt = { $date: new Date().toISOString() };
422
+ $set.updatedAt = new Date();
438
423
 
439
424
  const result = await this.prisma.$runCommandRaw({
440
425
  findAndModify: 'Integration',
@@ -99,7 +99,7 @@ class IntegrationRepositoryPostgres extends IntegrationRepositoryInterface {
99
99
  * @param {string} [filter.status] - Integration status
100
100
  * @returns {Promise<Array>} Array of integration objects (possibly empty)
101
101
  */
102
- async findIntegrations({ type, status, limit, after } = {}) {
102
+ async findIntegrations({ type, status } = {}) {
103
103
  const where = {};
104
104
  if (type) {
105
105
  where.config = { path: ['type'], equals: type };
@@ -107,16 +107,12 @@ class IntegrationRepositoryPostgres extends IntegrationRepositoryInterface {
107
107
  if (status) {
108
108
  where.status = status;
109
109
  }
110
- if (limit && after !== undefined && after !== null) {
111
- where.id = { gt: this._convertId(after) };
112
- }
113
110
 
114
111
  const integrations = await this.prisma.integration.findMany({
115
112
  where,
116
113
  include: {
117
114
  entities: true,
118
115
  },
119
- ...(limit ? { orderBy: { id: 'asc' }, take: limit } : {}),
120
116
  });
121
117
 
122
118
  return integrations.map((integration) => {
@@ -120,7 +120,7 @@ class ProcessRepositoryMongo extends ProcessRepositoryInterface {
120
120
  if (normalized.newState !== null) {
121
121
  $set.state = normalized.newState;
122
122
  }
123
- $set.updatedAt = { $date: new Date().toISOString() };
123
+ $set.updatedAt = new Date();
124
124
  update.$set = $set;
125
125
 
126
126
  if (Object.keys(normalized.pushSlice).length > 0) {
@@ -1,4 +1,3 @@
1
- const { resolveIntegrationClass } = require('../integration-types');
2
1
  // Removed Integration wrapper - using IntegrationBase directly
3
2
  const {
4
3
  mapIntegrationClassToIntegrationDTO,
@@ -39,16 +38,6 @@ class CreateIntegration {
39
38
  `[Frigg] Creating ${config?.type} integration for user ${userId} with entities [${entities}]`
40
39
  );
41
40
 
42
- // Only a type this user may install: registered code, the app's catalogue, or one their workspace built.
43
- const integrationClass = await resolveIntegrationClass(
44
- this.integrationClasses,
45
- config?.type,
46
- { workspaceId: String(userId) }
47
- );
48
- if (!integrationClass) {
49
- throw new Error(`No integration class found for type: ${config?.type}`);
50
- }
51
-
52
41
  const existing = await this._findDuplicate(
53
42
  userId,
54
43
  config?.type,
@@ -185,9 +174,10 @@ class CreateIntegration {
185
174
  }
186
175
 
187
176
  async _buildInstance(integrationRecord) {
188
- const integrationClass = await resolveIntegrationClass(
189
- this.integrationClasses,
190
- integrationRecord.config.type
177
+ const integrationClass = this.integrationClasses.find(
178
+ (integrationClass) =>
179
+ integrationClass.Definition.name ===
180
+ integrationRecord.config.type
191
181
  );
192
182
 
193
183
  if (!integrationClass) {
@@ -1,4 +1,3 @@
1
- const { resolveIntegrationClass } = require('../integration-types');
2
1
  const Boom = require('@hapi/boom');
3
2
  const { getLogger } = require('../../logs');
4
3
 
@@ -45,9 +44,10 @@ class DeleteIntegrationForUser {
45
44
  );
46
45
  }
47
46
 
48
- const integrationClass = await resolveIntegrationClass(
49
- this.integrationClasses,
50
- integrationRecord.config.type
47
+ const integrationClass = this.integrationClasses.find(
48
+ (integrationClass) =>
49
+ integrationClass.Definition.name ===
50
+ integrationRecord.config.type
51
51
  );
52
52
 
53
53
  if (integrationRecord.userId !== userId) {
@@ -1,4 +1,3 @@
1
- const { resolveIntegrationClass } = require('../integration-types');
2
1
  // Removed Integration wrapper - using IntegrationBase directly
3
2
  const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
4
3
  const Boom = require('@hapi/boom');
@@ -48,9 +47,8 @@ class GetIntegrationForUser {
48
47
  throw Boom.forbidden('User does not have access to this integration');
49
48
  }
50
49
 
51
- const integrationClass = await resolveIntegrationClass(
52
- this.integrationClasses,
53
- integrationRecord.config.type
50
+ const integrationClass = this.integrationClasses.find(
51
+ (integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
54
52
  );
55
53
 
56
54
  const modules = [];