(
pluginId: string,
input: RegisterIntegrationInput,
)
| 2674 | config.onIntegrationChange ? afterCommit(config.onIntegrationChange(event)) : Effect.void; |
| 2675 | |
| 2676 | const integrationsRegister = ( |
| 2677 | pluginId: string, |
| 2678 | input: RegisterIntegrationInput, |
| 2679 | ): Effect.Effect<void, StorageFailure> => |
| 2680 | transaction( |
| 2681 | Effect.gen(function* () { |
| 2682 | const now = new Date(); |
| 2683 | const existing = yield* findIntegrationRow(input.slug); |
| 2684 | const config = input.config === undefined ? null : input.config; |
| 2685 | if (existing) { |
| 2686 | yield* core.updateMany("integration", { |
| 2687 | where: (b: AnyCb) => b("slug", "=", String(input.slug)), |
| 2688 | set: { |
| 2689 | plugin_id: pluginId, |
| 2690 | name: input.name ?? existing.name ?? null, |
| 2691 | description: input.description, |
| 2692 | config, |
| 2693 | can_remove: input.canRemove ?? Boolean(existing.can_remove), |
| 2694 | can_refresh: input.canRefresh ?? Boolean(existing.can_refresh), |
| 2695 | updated_at: now, |
| 2696 | }, |
| 2697 | }); |
| 2698 | return false; |
| 2699 | } |
| 2700 | yield* core.create("integration", { |
| 2701 | tenant, |
| 2702 | slug: String(input.slug), |
| 2703 | plugin_id: pluginId, |
| 2704 | name: input.name ?? null, |
| 2705 | description: input.description, |
| 2706 | config, |
| 2707 | can_remove: input.canRemove ?? true, |
| 2708 | can_refresh: input.canRefresh ?? false, |
| 2709 | created_at: now, |
| 2710 | updated_at: now, |
| 2711 | }); |
| 2712 | return true; |
| 2713 | }), |
| 2714 | ).pipe( |
| 2715 | Effect.tap((created) => |
| 2716 | created |
| 2717 | ? notifyIntegrationChange({ kind: "added", pluginKey: pluginId, slug: input.slug }) |
| 2718 | : Effect.void, |
| 2719 | ), |
| 2720 | Effect.asVoid, |
| 2721 | ); |
| 2722 | |
| 2723 | const integrationsUpdate = ( |
| 2724 | slug: IntegrationSlug, |
no test coverage detected