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

Function mergeAuthTemplates

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

Source from the content-addressed store, hash-verified

136};
137
138export const mergeAuthTemplates = <T extends { readonly slug: string }>(
139 existing: readonly T[],
140 incoming: readonly T[],
141): readonly T[] => {
142 const result: T[] = existing.map((entry: T) => entry);
143 const taken = new Set<string>(result.map((entry: T) => String(entry.slug)));
144 for (const entry of incoming) {
145 // `slug` may be branded-required in the plugin's schema, but JSON callers
146 // can submit it empty/blank — read defensively and backfill so every
147 // stored template has a stable slug.
148 const rawSlug = (entry as { readonly slug?: unknown }).slug;
149 const requested = typeof rawSlug === "string" ? rawSlug.trim() : "";
150 const existingIndex = result.findIndex((current: T) => String(current.slug) === requested);
151 if (requested.length > 0 && existingIndex >= 0) {
152 result[existingIndex] = entry;
153 continue;
154 }
155 const slug =
156 requested.length > 0 && !taken.has(requested) ? requested : freshCustomAuthSlug(taken);
157 taken.add(slug);
158 result.push({ ...entry, slug } as T);
159 }
160 return result;
161};
162
163/**
164 * A durable change to the integration catalog, emitted through

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