| 349 | } |
| 350 | |
| 351 | async registerTrigger( |
| 352 | client: string, |
| 353 | id: string, |
| 354 | key: string, |
| 355 | payload: RegisterTriggerBodyV2, |
| 356 | idempotencyKey?: string |
| 357 | ): Promise<RegisterSourceEventV2> { |
| 358 | const apiKey = await this.#apiKey(); |
| 359 | |
| 360 | this.#logger.debug("registering trigger", { |
| 361 | id, |
| 362 | payload, |
| 363 | }); |
| 364 | |
| 365 | const headers: HeadersInit = { |
| 366 | "Content-Type": "application/json", |
| 367 | Authorization: `Bearer ${apiKey}`, |
| 368 | }; |
| 369 | |
| 370 | if (idempotencyKey) { |
| 371 | headers["Idempotency-Key"] = idempotencyKey; |
| 372 | } |
| 373 | |
| 374 | const response = await zodfetch( |
| 375 | RegisterSourceEventSchemaV2, |
| 376 | `${this.#apiUrl}/api/v2/${client}/triggers/${id}/registrations/${key}`, |
| 377 | { |
| 378 | method: "PUT", |
| 379 | headers: headers, |
| 380 | body: JSON.stringify(payload), |
| 381 | } |
| 382 | ); |
| 383 | |
| 384 | return response; |
| 385 | } |
| 386 | |
| 387 | async registerSchedule(client: string, id: string, key: string, payload: ScheduleMetadata) { |
| 388 | const apiKey = await this.#apiKey(); |