MCPcopy Index your code
hub / github.com/callstack/agent-device / parseInstallSource

Function parseInstallSource

src/daemon/server/http-server.ts:287–333  ·  view source on GitHub ↗
(params: Record<string, unknown>)

Source from the content-addressed store, hash-verified

285}
286
287function parseInstallSource(params: Record<string, unknown>): DaemonInstallSource {
288 const source = params.source;
289 if (!source || typeof source !== 'object') {
290 throw new AppError('INVALID_ARGS', 'Invalid params: source is required');
291 }
292 const record = source as Record<string, unknown>;
293 if (record.kind === 'url') {
294 const url = typeof record.url === 'string' ? record.url.trim() : '';
295 if (!url) {
296 throw new AppError('INVALID_ARGS', 'Invalid params: source.url is required for url sources');
297 }
298 const rawHeaders = record.headers;
299 const headers: Record<string, string> = {};
300 if (rawHeaders !== undefined) {
301 if (!rawHeaders || typeof rawHeaders !== 'object' || Array.isArray(rawHeaders)) {
302 throw new AppError('INVALID_ARGS', 'Invalid params: source.headers must be a string map');
303 }
304 for (const [key, value] of Object.entries(rawHeaders as Record<string, unknown>)) {
305 if (typeof value !== 'string') {
306 throw new AppError(
307 'INVALID_ARGS',
308 'Invalid params: source.headers values must be strings',
309 );
310 }
311 headers[key] = value;
312 }
313 }
314 return Object.keys(headers).length > 0 ? { kind: 'url', url, headers } : { kind: 'url', url };
315 }
316 if (record.kind === 'path') {
317 const artifactPath = typeof record.path === 'string' ? record.path.trim() : '';
318 if (!artifactPath) {
319 throw new AppError(
320 'INVALID_ARGS',
321 'Invalid params: source.path is required for path sources',
322 );
323 }
324 return { kind: 'path', path: artifactPath };
325 }
326 if (record.kind === 'github-actions-artifact') {
327 return parseGitHubActionsArtifactSource(record);
328 }
329 throw new AppError(
330 'INVALID_ARGS',
331 'Invalid params: source.kind must be "url", "path", or "github-actions-artifact"',
332 );
333}
334
335function toInstallFromSourceDaemonRequest(
336 params: Record<string, unknown>,

Callers 1

Calls 1

Tested by

no test coverage detected