( device: AppEventDevice, eventName: string, payload?: AppEventPayload, )
| 34 | } |
| 35 | |
| 36 | export 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 | |
| 68 | function parseTriggerEventPayload( |
| 69 | payloadArg: string | undefined, |
no test coverage detected