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

Function mergeAuthTemplates

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

Source from the content-addressed store, hash-verified

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

Callers 3

plugin.tsFile · 0.90
configureAuthFunction · 0.90
configureAuthMethodsFunction · 0.90

Calls 2

freshCustomAuthSlugFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected