MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / integrationsRemove

Function integrationsRemove

packages/core/sdk/src/executor.ts:3363–3419  ·  view source on GitHub ↗
(
      slug: IntegrationSlug,
    )

Source from the content-addressed store, hash-verified

3361 });
3362
3363 const integrationsRemove = (
3364 slug: IntegrationSlug,
3365 ): Effect.Effect<
3366 void,
3367 IntegrationRemovalNotAllowedError | OrgWriteDeniedError | StorageFailure
3368 > =>
3369 transaction(
3370 Effect.gen(function* () {
3371 yield* guardOrgWrite();
3372 const existing = yield* findIntegrationRow(slug);
3373 if (!existing) return null;
3374 if (!existing.can_remove) {
3375 return yield* new IntegrationRemovalNotAllowedError({ slug });
3376 }
3377 const runtime = runtimes.get(existing.plugin_id);
3378 if (runtime?.plugin.removeIntegration) {
3379 const authMethods = yield* describeAuthMethodsForRow(existing);
3380 yield* runtime.plugin
3381 .removeIntegration({
3382 ctx: runtime.ctx,
3383 integration: rowToIntegrationRecord(existing, authMethods),
3384 })
3385 .pipe(
3386 Effect.mapError((cause) =>
3387 pluginStorageFailure(existing.plugin_id, "removeIntegration", cause),
3388 ),
3389 );
3390 }
3391 // The catalog row goes first through the bound handle: a read-only
3392 // (platform-view) context is refused here, before the widened
3393 // cascade below could touch anything.
3394 yield* core.deleteMany("integration", {
3395 where: (b: AnyCb) => b("slug", "=", String(slug)),
3396 });
3397 // Drop connections / tools / definitions for this integration across
3398 // EVERY subject in the tenant, not just the remover's own rows. A
3399 // removed integration has no reason to keep anyone's rows, and rows
3400 // left behind become orphans: invisible in the catalog, yet still
3401 // listed to agents and still targetable by reconnect.
3402 const where = (b: AnyCb) => b("integration", "=", String(slug));
3403 yield* cascadeCore.deleteMany("tool", { where });
3404 yield* cascadeCore.deleteMany("definition", { where });
3405 yield* cascadeCore.deleteMany("connection", { where });
3406 return existing.plugin_id;
3407 }),
3408 ).pipe(
3409 Effect.tap((removedPluginId) =>
3410 removedPluginId !== null
3411 ? notifyIntegrationChange({
3412 kind: "removed",
3413 pluginKey: removedPluginId,
3414 slug,
3415 })
3416 : Effect.void,
3417 ),
3418 Effect.asVoid,
3419 );
3420

Callers 1

createExecutorFunction · 0.85

Calls 8

guardOrgWriteFunction · 0.85
findIntegrationRowFunction · 0.85
rowToIntegrationRecordFunction · 0.85
pluginStorageFailureFunction · 0.85
notifyIntegrationChangeFunction · 0.85
transactionFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected