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

Function integrationsRegister

packages/core/sdk/src/executor.ts:3264–3321  ·  view source on GitHub ↗
(
      pluginId: string,
      input: RegisterIntegrationInput,
    )

Source from the content-addressed store, hash-verified

3262 config.onIntegrationChange ? afterCommit(config.onIntegrationChange(event)) : Effect.void;
3263
3264 const integrationsRegister = (
3265 pluginId: string,
3266 input: RegisterIntegrationInput,
3267 ): Effect.Effect<void, OrgWriteDeniedError | StorageFailure> =>
3268 transaction(
3269 Effect.gen(function* () {
3270 const now = new Date();
3271 const existing = yield* findIntegrationRow(input.slug);
3272 const config = input.config === undefined ? null : input.config;
3273 if (existing) {
3274 // Extension methods also run for subjectless boot/system executors,
3275 // which must be able to converge existing catalog rows. A bound
3276 // subject is an end-user principal, so its replacement is the same
3277 // workspace mutation as creation and requires the live role guard.
3278 if (subject !== null) yield* guardOrgWrite();
3279 yield* core.updateMany("integration", {
3280 where: (b: AnyCb) => b("slug", "=", String(input.slug)),
3281 set: {
3282 plugin_id: pluginId,
3283 name: input.name ?? existing.name ?? null,
3284 description: input.description,
3285 config,
3286 can_remove: input.canRemove ?? Boolean(existing.can_remove),
3287 can_refresh: input.canRefresh ?? Boolean(existing.can_refresh),
3288 updated_at: now,
3289 },
3290 });
3291 return false;
3292 }
3293 // A NEW catalog row is always user intent (the add-integration
3294 // flows), including from a subjectless executor.
3295 yield* guardOrgWrite();
3296 yield* core.create("integration", {
3297 tenant,
3298 slug: String(input.slug),
3299 plugin_id: pluginId,
3300 name: input.name ?? null,
3301 description: input.description,
3302 config,
3303 can_remove: input.canRemove ?? true,
3304 can_refresh: input.canRefresh ?? false,
3305 created_at: now,
3306 updated_at: now,
3307 });
3308 return true;
3309 }),
3310 ).pipe(
3311 Effect.tap((created) =>
3312 created
3313 ? notifyIntegrationChange({
3314 kind: "added",
3315 pluginKey: pluginId,
3316 slug: input.slug,
3317 })
3318 : Effect.void,
3319 ),
3320 Effect.asVoid,
3321 );

Callers 1

createExecutorFunction · 0.85

Calls 4

findIntegrationRowFunction · 0.85
guardOrgWriteFunction · 0.85
notifyIntegrationChangeFunction · 0.85
transactionFunction · 0.70

Tested by

no test coverage detected