(input: MigrationInput)
| 1296 | `${op.targetProvider}\0${op.owner.tenant}\0${op.owner.owner}\0${op.owner.subject}\0${op.itemId}`; |
| 1297 | |
| 1298 | export const planMigration = (input: MigrationInput): MigrationPlan => { |
| 1299 | const warnings: string[] = []; |
| 1300 | const secretOps: SecretOp[] = []; |
| 1301 | const connections: PlannedConnectionFull[] = []; |
| 1302 | const ownerForScope = input.ownerForScope ?? parseScope; |
| 1303 | const defaultWritableProvider = input.defaultWritableProvider ?? "workos-vault"; |
| 1304 | |
| 1305 | // --- Integrations (one per source) + the policy slug map (source ∪ tool ids). |
| 1306 | const integrations: PlannedIntegrationRow[] = []; |
| 1307 | const slugMap = new Map<string, string>(); |
| 1308 | const sourceIdsByTenant = new Map<string, Set<string>>(); |
| 1309 | const addSourceIdForOwner = (owner: OwnerKeys | null, sourceId: string): void => { |
| 1310 | if (!owner) return; |
| 1311 | const set = sourceIdsByTenant.get(owner.tenant) ?? new Set<string>(); |
| 1312 | set.add(sourceId); |
| 1313 | sourceIdsByTenant.set(owner.tenant, set); |
| 1314 | }; |
| 1315 | for (const id of input.toolSourceIds) slugMap.set(id, id); |
| 1316 | for (const source of input.sources) { |
| 1317 | slugMap.set(source.id, source.id); |
| 1318 | addSourceIdForOwner(ownerForScope(source.scopeId), source.id); |
| 1319 | const migrated = input.migratedConfigs.get(sourceKey(source.scopeId, source.id)); |
| 1320 | const row = planIntegrationRow({ |
| 1321 | scopeId: source.scopeId, |
| 1322 | sourceId: source.id, |
| 1323 | pluginId: source.pluginId, |
| 1324 | description: source.name, |
| 1325 | config: migrated?.config ?? {}, |
| 1326 | ownerForScope, |
| 1327 | }); |
| 1328 | if (!row) { |
| 1329 | warnings.push(`Skipped source "${source.id}": unparseable scope "${source.scopeId}".`); |
| 1330 | continue; |
| 1331 | } |
| 1332 | integrations.push(row); |
| 1333 | for (const w of migrated?.warnings ?? []) warnings.push(`[${source.id}] ${w}`); |
| 1334 | } |
| 1335 | |
| 1336 | const policySlugMapForOwner = (owner: OwnerKeys): ReadonlyMap<string, string> => { |
| 1337 | const tenantSourceIds = sourceIdsByTenant.get(owner.tenant); |
| 1338 | if ( |
| 1339 | tenantSourceIds?.has(MICROSOFT_GRAPH_CURATED_SLUG) && |
| 1340 | !tenantSourceIds.has(MICROSOFT_GRAPH_LEGACY_SLUG) |
| 1341 | ) { |
| 1342 | return new Map(slugMap).set(MICROSOFT_GRAPH_LEGACY_SLUG, MICROSOFT_GRAPH_CURATED_SLUG); |
| 1343 | } |
| 1344 | return slugMap; |
| 1345 | }; |
| 1346 | |
| 1347 | // --- Group bindings by (scope, source); each group → one connection. |
| 1348 | const groups = new Map<string, V1BindingRow[]>(); |
| 1349 | for (const b of input.bindings) { |
| 1350 | const key = sourceKey(b.scopeId, b.sourceId); |
| 1351 | const list = groups.get(key) ?? []; |
| 1352 | list.push(b); |
| 1353 | groups.set(key, list); |
| 1354 | } |
| 1355 | const connectionById = new Map<string, V1ConnectionRow>(); |
no test coverage detected