{"version":3,"file":"durable-webhook-CL8hkdP6.mjs","names":["path: string","requestOptions: RequestAzureFunctionsDurableTaskWebhookOptions"],"sources":["../src/durable-webhook.ts"],"sourcesContent":["/**\n * @module\n * Helper utils to interact with Azure Functions - Durable Task framework (v2).\n */\n\n/**\n * Request options for Azure Functions Durable Task Webhook.\n */\nexport type RequestAzureFunctionsDurableTaskWebhookOptions = {\n  /**\n   * The base URL for the APIs mentioned in this article is the same as the base URL for your function app.\n   * When developing locally using the Azure Functions Core Tools,\n   * the base URL is typically http://localhost:7071.\n   * In the Azure Functions hosted service, the base URL is typically https://{appName}.azurewebsites.net.\n   * Custom hostnames are also supported if configured on your App Service app.\n   */\n  baseUrl: string;\n  /**\n   * The authorization key required to invoke the API.\n   * systemKey is an authorization key autogenerated by the Azure Functions host.\n   * It specifically grants access to the Durable Task extension APIs.\n   */\n  systemKey: string;\n  /**\n   * The name of the [task hub](https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-task-hubs).\n   * If not specified, the current function app's task hub name is assumed.\n   */\n  taskHub?: string;\n  /**\n   * The name of the connection app setting for the backend storage provider.\n   * If not specified, the default connection configuration for the function app is assumed.\n   */\n  connection?: string;\n  /**\n   * The abort signal to cancel the request.\n   */\n  abortSignal?: AbortSignal;\n  /**\n   * The HTTP method to use for the request.\n   */\n  method?: \"POST\" | \"GET\" | \"DELETE\" | \"PUT\";\n  /**\n   * The request body to send with the request.\n   */\n  body?: BodyInit;\n  /**\n   * The URL search parameters to include in the request.\n   */\n  searchParams?: URLSearchParamsInit;\n  /**\n   * The headers to include in the request.\n   */\n  headers?: HeadersInit;\n};\n\n/**\n * Makes an HTTP Request to Azure Functions Durable Task Webhook.\n * @param path URL path to the Durable Task Webhook API.\n * @param requestOptions Options for the request.\n * @returns The HTTP response from the Durable Task Webhook API.\n */\nexport async function requestAzureFunctionsDurableTaskWebhookOrThrow(\n  path: string,\n  requestOptions: RequestAzureFunctionsDurableTaskWebhookOptions\n): Promise<Response> {\n  const {\n    abortSignal,\n    baseUrl,\n    systemKey,\n    connection,\n    taskHub,\n    body,\n    method,\n    searchParams,\n    headers,\n  } = requestOptions;\n\n  if (!baseUrl) {\n    throw new Error(\"Azure Functions base URL is required.\");\n  }\n\n  const urlSearchParams = new URLSearchParams(searchParams);\n  if (systemKey) {\n    urlSearchParams.set(\"code\", systemKey);\n  }\n  if (taskHub) {\n    urlSearchParams.set(\"taskHub\", taskHub);\n  }\n  if (connection) {\n    urlSearchParams.set(\"connection\", connection);\n  }\n\n  const url = new URL(`/runtime/webhooks/durabletask/${path}`, baseUrl);\n  url.search = urlSearchParams.toString();\n\n  const response = await fetch(url, {\n    method,\n    body,\n    headers,\n    signal: abortSignal,\n  });\n\n  if (!response.ok) {\n    const cause = await response\n      .clone()\n      .json()\n      .catch(() => {});\n\n    throw new Error(\n      `Failed to request Azure Functions Durable Webhook: ${response.status} ${\n        response.statusText\n      }, ${JSON.stringify(cause)}`\n    );\n  }\n\n  return response;\n}\n\ntype URLSearchParamsInit =\n  | string[][]\n  | Record<string, string>\n  | string\n  | URLSearchParams;\n"],"mappings":";;;;;;;AA6DA,eAAsB,+CACpBA,MACAC,gBACmB;CACnB,MAAM,EACJ,aACA,SACA,WACA,YACA,SACA,MACA,QACA,cACA,SACD,GAAG;AAEJ,MAAK,QACH,OAAM,IAAI,MAAM;CAGlB,MAAM,kBAAkB,IAAI,gBAAgB;AAC5C,KAAI,UACF,iBAAgB,IAAI,QAAQ,UAAU;AAExC,KAAI,QACF,iBAAgB,IAAI,WAAW,QAAQ;AAEzC,KAAI,WACF,iBAAgB,IAAI,cAAc,WAAW;CAG/C,MAAM,MAAM,IAAI,KAAK,gCAAgC,KAAK,GAAG;AAC7D,KAAI,SAAS,gBAAgB,UAAU;CAEvC,MAAM,WAAW,MAAM,MAAM,KAAK;EAChC;EACA;EACA;EACA,QAAQ;CACT,EAAC;AAEF,MAAK,SAAS,IAAI;EAChB,MAAM,QAAQ,MAAM,SACjB,OAAO,CACP,MAAM,CACN,MAAM,MAAM,CAAE,EAAC;AAElB,QAAM,IAAI,OACP,qDAAqD,SAAS,OAAO,GACpE,SAAS,WACV,IAAI,KAAK,UAAU,MAAM,CAAC;CAE9B;AAED,QAAO;AACR"}