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

Function mergeAuthTemplates

packages/core/sdk/src/integration.ts:126–149  ·  view source on GitHub ↗
(
  existing: readonly T[],
  incoming: readonly T[],
)

Source from the content-addressed store, hash-verified

124};
125
126export const mergeAuthTemplates = <T extends { readonly slug: string }>(
127 existing: readonly T[],
128 incoming: readonly T[],
129): readonly T[] => {
130 const result: T[] = existing.map((entry: T) => entry);
131 const taken = new Set<string>(result.map((entry: T) => String(entry.slug)));
132 for (const entry of incoming) {
133 // `slug` may be branded-required in the plugin's schema, but JSON callers
134 // can submit it empty/blank — read defensively and backfill so every
135 // stored template has a stable slug.
136 const rawSlug = (entry as { readonly slug?: unknown }).slug;
137 const requested = typeof rawSlug === "string" ? rawSlug.trim() : "";
138 const existingIndex = result.findIndex((current: T) => String(current.slug) === requested);
139 if (requested.length > 0 && existingIndex >= 0) {
140 result[existingIndex] = entry;
141 continue;
142 }
143 const slug =
144 requested.length > 0 && !taken.has(requested) ? requested : freshCustomAuthSlug(taken);
145 taken.add(slug);
146 result.push({ ...entry, slug } as T);
147 }
148 return result;
149};
150
151/** What a plugin's extension method passes to `ctx.core.integrations.register`.
152 * The v2 analog of v1's `SourceInput`, minus the per-source tool list (tools are

Callers 5

plugin.tsFile · 0.90
configureAuthFunction · 0.90
configureAuthMethodsFunction · 0.90

Calls 2

freshCustomAuthSlugFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected