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

Function resolveAppEventUrl

src/core/app-events.ts:36–66  ·  view source on GitHub ↗
(
  device: AppEventDevice,
  eventName: string,
  payload?: AppEventPayload,
)

Source from the content-addressed store, hash-verified

34}
35
36export function resolveAppEventUrl(
37 device: AppEventDevice,
38 eventName: string,
39 payload?: AppEventPayload,
40): string {
41 const platform = publicPlatformString(device);
42 const template = readAppEventUrlTemplate(device);
43 if (!template) {
44 throw new AppError(
45 'UNSUPPORTED_OPERATION',
46 `No app event URL template configured for ${platform}.`,
47 {
48 hint: `Set AGENT_DEVICE_${platform.toUpperCase()}_APP_EVENT_URL_TEMPLATE or AGENT_DEVICE_APP_EVENT_URL_TEMPLATE, for example "myapp://agent-device/event?name={event}&payload={payload}".`,
49 },
50 );
51 }
52
53 const payloadText = payload ? JSON.stringify(payload) : '';
54 const eventUrl = template
55 .replaceAll('{event}', encodeURIComponent(eventName))
56 .replaceAll('{payload}', encodeURIComponent(payloadText))
57 .replaceAll('{platform}', encodeURIComponent(platform));
58 if (eventUrl.length > MAX_APP_EVENT_URL_LENGTH) {
59 throw new AppError('INVALID_ARGS', 'trigger-app-event URL exceeds maximum supported length', {
60 hint: 'Reduce payload size or shorten AGENT_DEVICE_*_APP_EVENT_URL_TEMPLATE.',
61 length: eventUrl.length,
62 maxLength: MAX_APP_EVENT_URL_LENGTH,
63 });
64 }
65 return eventUrl;
66}
67
68function parseTriggerEventPayload(
69 payloadArg: string | undefined,

Callers 1

Calls 2

publicPlatformStringFunction · 0.90
readAppEventUrlTemplateFunction · 0.85

Tested by

no test coverage detected