( operation: WorkdayOperation, args: Record<string, unknown>, endpoint: string, username: string, password: string )
| 562 | } |
| 563 | |
| 564 | async function callOperation( |
| 565 | operation: WorkdayOperation, |
| 566 | args: Record<string, unknown>, |
| 567 | endpoint: string, |
| 568 | username: string, |
| 569 | password: string |
| 570 | ): Promise<[WorkdaySoapResult, string, Record<string, unknown>, string]> { |
| 571 | const envelope = buildEnvelope(operation, args, username, password) |
| 572 | |
| 573 | const response = await fetch(endpoint, { |
| 574 | method: 'POST', |
| 575 | headers: { |
| 576 | 'Content-Type': 'text/xml; charset=utf-8', |
| 577 | SOAPAction: `""`, |
| 578 | }, |
| 579 | body: envelope, |
| 580 | }) |
| 581 | |
| 582 | const responseText = await response.text() |
| 583 | |
| 584 | let root: XmlNode |
| 585 | try { |
| 586 | root = parseXml(responseText) |
| 587 | } catch (err) { |
| 588 | logger.error('Failed to parse Workday SOAP response', { |
| 589 | operation, |
| 590 | status: response.status, |
| 591 | error: getErrorMessage(err), |
| 592 | }) |
| 593 | throw new Error( |
| 594 | `Workday returned an unparseable response (HTTP ${response.status}): ${responseText.slice(0, 500)}` |
| 595 | ) |
| 596 | } |
| 597 | |
| 598 | const fault = extractFaultMessage(root) |
| 599 | if (fault) { |
| 600 | throw new Error(fault) |
| 601 | } |
| 602 | |
| 603 | if (!response.ok) { |
| 604 | throw new Error(`Workday SOAP request failed (HTTP ${response.status})`) |
| 605 | } |
| 606 | |
| 607 | const responseElement = findFirst(root, `${operation}_Response`) |
| 608 | const value = (responseElement ? nodeToValue(responseElement) : {}) as WorkdaySoapResult |
| 609 | |
| 610 | return [value, responseText, {}, envelope] |
| 611 | } |
| 612 | |
| 613 | /** |
| 614 | * Creates a typed SOAP client for a Workday service. The returned object |
no test coverage detected