@azure/core-lro 3.1.1-alpha.20250313.3 → 3.2.0-alpha.20250318.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/browser/http/models.d.ts +4 -0
  2. package/dist/browser/http/models.js.map +1 -1
  3. package/dist/browser/http/operation.js.map +1 -1
  4. package/dist/browser/http/poller.js +3 -2
  5. package/dist/browser/http/poller.js.map +1 -1
  6. package/dist/browser/http/utils.d.ts +15 -0
  7. package/dist/browser/http/utils.js +44 -0
  8. package/dist/browser/http/utils.js.map +1 -0
  9. package/dist/commonjs/http/models.d.ts +4 -0
  10. package/dist/commonjs/http/models.js.map +1 -1
  11. package/dist/commonjs/http/operation.js.map +1 -1
  12. package/dist/commonjs/http/poller.js +3 -2
  13. package/dist/commonjs/http/poller.js.map +1 -1
  14. package/dist/commonjs/http/utils.d.ts +15 -0
  15. package/dist/commonjs/http/utils.js +47 -0
  16. package/dist/commonjs/http/utils.js.map +1 -0
  17. package/dist/commonjs/tsdoc-metadata.json +1 -1
  18. package/dist/esm/http/models.d.ts +4 -0
  19. package/dist/esm/http/models.js.map +1 -1
  20. package/dist/esm/http/operation.js.map +1 -1
  21. package/dist/esm/http/poller.js +3 -2
  22. package/dist/esm/http/poller.js.map +1 -1
  23. package/dist/esm/http/utils.d.ts +15 -0
  24. package/dist/esm/http/utils.js +44 -0
  25. package/dist/esm/http/utils.js.map +1 -0
  26. package/dist/react-native/http/models.d.ts +4 -0
  27. package/dist/react-native/http/models.js.map +1 -1
  28. package/dist/react-native/http/operation.js.map +1 -1
  29. package/dist/react-native/http/poller.js +3 -2
  30. package/dist/react-native/http/poller.js.map +1 -1
  31. package/dist/react-native/http/utils.d.ts +15 -0
  32. package/dist/react-native/http/utils.js +44 -0
  33. package/dist/react-native/http/utils.js.map +1 -0
  34. package/package.json +5 -5
@@ -88,6 +88,10 @@ export interface CreateHttpPollerOptions<TResult, TState> {
88
88
  * The potential location of the result of the LRO if specified by the LRO extension in the swagger.
89
89
  */
90
90
  resourceLocationConfig?: ResourceLocationConfig;
91
+ /**
92
+ * The base URL to use when making requests.
93
+ */
94
+ baseUrl?: string;
91
95
  /**
92
96
  * A function to process the result of the LRO.
93
97
  */
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAwB;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAwB;IAC5D,OAAO,WAAW,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,oBAAoB,CAAC,MAK7B;;IACC,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,MAAM,CAAC;IAChF,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,OAAO,MAAA,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AAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault() {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAwB;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAwB;I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,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;IAC/F,OAAO,aAAa,CAAC;QACnB,KAAK;QACL,QAAQ;QACR,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,UAAU,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
@@ -2,6 +2,7 @@
2
2
  // Licensed under the MIT License.
3
3
  import { getErrorFromResponse, getOperationLocation, getOperationStatus, getResourceLocation, getStatusFromInitialResponse, inferLroMode, isOperationError, parseRetryAfter, } from "./operation.js";
4
4
  import { buildCreatePoller } from "../poller/poller.js";
5
+ import { rewriteUrl } from "./utils.js";
5
6
  /**
6
7
  * Creates a poller that can be used to poll a long-running operation.
7
8
  * @param lro - Description of the long-running operation
@@ -9,7 +10,7 @@ import { buildCreatePoller } from "../poller/poller.js";
9
10
  * @returns an initialized poller
10
11
  */
11
12
  export function createHttpPoller(lro, options) {
12
- const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, } = options || {};
13
+ const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, } = options || {};
13
14
  return buildCreatePoller({
14
15
  getStatusFromInitialResponse,
15
16
  getStatusFromPollResponse: getOperationStatus,
@@ -23,7 +24,7 @@ export function createHttpPoller(lro, options) {
23
24
  init: async () => {
24
25
  const response = await lro.sendInitialRequest();
25
26
  const config = inferLroMode(response.rawResponse, resourceLocationConfig);
26
- return Object.assign({ response, operationLocation: config === null || config === void 0 ? void 0 : config.operationLocation, resourceLocation: config === null || config === void 0 ? void 0 : config.resourceLocation, initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
27
+ return Object.assign({ response, operationLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.operationLocation, baseUrl }), resourceLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.resourceLocation, baseUrl }), initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
27
28
  },
28
29
  poll: lro.sendPollRequest,
29
30
  }, {
@@ -1 +1 @@
1
- {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACp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AC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: config?.operationLocation,\n resourceLocation: config?.resourceLocation,\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
1
+ {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,4BAA4B,EAC5B,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAqB,EACrB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,GAAG,KAAK,EAC7B,OAAO,GACR,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,OAAO,iBAAiB,CAAqC;QAC3D,4BAA4B;QAC5B,yBAAyB,EAAE,kBAAkB;QAC7C,gBAAgB;QAChB,oBAAoB;QACpB,mBAAmB;QACnB,kBAAkB,EAAE,eAAe;QACnC,QAAQ,EAAE,oBAAoB;QAC9B,qBAAqB;KACtB,CAAC,CACA;QACE,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,kBAAkB,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAC;YAC1E,uBACE,QAAQ,EACR,iBAAiB,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAAE,OAAO,EAAE,CAAC,EAC1E,gBAAgB,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC,EACxE,iBAAiB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,aAAa,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,IACjC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Rewrites a given URL to use the specified base URL.
3
+ * It preserves the pathname, search parameters, and fragment.
4
+ * Handles relative URLs and proper encoding.
5
+ *
6
+ * @param params - An object containing the url and baseUrl.
7
+ * url - The original URL (absolute or relative).
8
+ * baseUrl - The new base URL to use.
9
+ * @returns The rewritten URL as a string.
10
+ */
11
+ export declare function rewriteUrl({ url, baseUrl, }: {
12
+ url?: string;
13
+ baseUrl?: string;
14
+ }): string | undefined;
15
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,44 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /**
4
+ * Rewrites a given URL to use the specified base URL.
5
+ * It preserves the pathname, search parameters, and fragment.
6
+ * Handles relative URLs and proper encoding.
7
+ *
8
+ * @param params - An object containing the url and baseUrl.
9
+ * url - The original URL (absolute or relative).
10
+ * baseUrl - The new base URL to use.
11
+ * @returns The rewritten URL as a string.
12
+ */
13
+ export function rewriteUrl({ url, baseUrl, }) {
14
+ if (!url) {
15
+ return undefined;
16
+ }
17
+ if (!baseUrl) {
18
+ return url;
19
+ }
20
+ let originalUrl;
21
+ try {
22
+ // Try to parse inputUrl as an absolute URL.
23
+ originalUrl = new URL(url);
24
+ }
25
+ catch (_a) {
26
+ // If inputUrl is relative, resolve using the provided baseUrl.
27
+ try {
28
+ originalUrl = new URL(url, baseUrl);
29
+ }
30
+ catch (e) {
31
+ throw new Error(`Invalid input URL provided: ${url}`);
32
+ }
33
+ }
34
+ let newBase;
35
+ try {
36
+ newBase = new URL(baseUrl);
37
+ }
38
+ catch (e) {
39
+ throw new Error(`Invalid base URL provided: ${baseUrl}`);
40
+ }
41
+ const rewrittenUrl = new URL(`${originalUrl.pathname}${originalUrl.search}${originalUrl.hash}`, newBase);
42
+ return rewrittenUrl.toString();
43
+ }
44
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/http/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,GAAG,EACH,OAAO,GAIR;IACC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,WAAgB,CAAC;IAErB,IAAI,CAAC;QACH,4CAA4C;QAC5C,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,WAAM,CAAC;QACP,+DAA+D;QAC/D,IAAI,CAAC;YACH,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,IAAI,OAAY,CAAC;IACjB,IAAI,CAAC;QACH,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,8BAA8B,OAAO,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,GAAG,CAC1B,GAAG,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,EACjE,OAAO,CACR,CAAC;IAEF,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Rewrites a given URL to use the specified base URL.\n * It preserves the pathname, search parameters, and fragment.\n * Handles relative URLs and proper encoding.\n *\n * @param params - An object containing the url and baseUrl.\n * url - The original URL (absolute or relative).\n * baseUrl - The new base URL to use.\n * @returns The rewritten URL as a string.\n */\nexport function rewriteUrl({\n url,\n baseUrl,\n}: {\n url?: string;\n baseUrl?: string;\n}): string | undefined {\n if (!url) {\n return undefined;\n }\n if (!baseUrl) {\n return url;\n }\n\n let originalUrl: URL;\n\n try {\n // Try to parse inputUrl as an absolute URL.\n originalUrl = new URL(url);\n } catch {\n // If inputUrl is relative, resolve using the provided baseUrl.\n try {\n originalUrl = new URL(url, baseUrl);\n } catch (e) {\n throw new Error(`Invalid input URL provided: ${url}`);\n }\n }\n\n let newBase: URL;\n try {\n newBase = new URL(baseUrl);\n } catch (e) {\n throw new Error(`Invalid base URL provided: ${baseUrl}`);\n }\n\n const rewrittenUrl = new URL(\n `${originalUrl.pathname}${originalUrl.search}${originalUrl.hash}`,\n newBase,\n );\n\n return rewrittenUrl.toString();\n}\n"]}
@@ -88,6 +88,10 @@ export interface CreateHttpPollerOptions<TResult, TState> {
88
88
  * The potential location of the result of the LRO if specified by the LRO extension in the swagger.
89
89
  */
90
90
  resourceLocationConfig?: ResourceLocationConfig;
91
+ /**
92
+ * The base URL to use when making requests.
93
+ */
94
+ baseUrl?: string;
91
95
  /**
92
96
  * A function to process the result of the LRO.
93
97
  */
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAgFlC,oCAyCC;AAqDD,0CAUC;AAED,oDAeC;AAWD,oEAsBC;AAED,oDAoBC;AAED,gDAkBC;AASD,kDASC;AAED,4CAEC;AAGD,8CAiCC;AA7TD,yDAAuD;AAEvD,4CAAsC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAwB;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAwB;IAC5D,OAAO,WAAW,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACrD,CAAC;AAED,SAAS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,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,UAAU,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault() {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAgFlC,oCAyCC;AAqDD,0CAUC;AAED,oDAeC;AAWD,oEAsBC;AAED,oDAoBC;AAED,gDAkBC;AASD,kDASC;AAED,4CAEC;AAGD,8CAiCC;AA7TD,yDAAuD;AAEvD,4CAAsC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAA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AAG,GAAG,CAAC;IACtC,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC;AACvC,CAAC;AAED,SAAgB,gBAAgB,CAAC,CAAQ;IACvC,OAAO,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;AAChC,CAAC;AAED,wCAAwC;AACjC,KAAK,UAAU,iBAAiB,CAAkD,MASxF;IACC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;IAC/F,OAAO,IAAA,4BAAa,EAAC;QACnB,KAAK;QACL,QAAQ;QACR,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,UAAU,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.createHttpPoller = createHttpPoller;
6
6
  const operation_js_1 = require("./operation.js");
7
7
  const poller_js_1 = require("../poller/poller.js");
8
+ const utils_js_1 = require("./utils.js");
8
9
  /**
9
10
  * Creates a poller that can be used to poll a long-running operation.
10
11
  * @param lro - Description of the long-running operation
@@ -12,7 +13,7 @@ const poller_js_1 = require("../poller/poller.js");
12
13
  * @returns an initialized poller
13
14
  */
14
15
  function createHttpPoller(lro, options) {
15
- const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, } = options || {};
16
+ const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, } = options || {};
16
17
  return (0, poller_js_1.buildCreatePoller)({
17
18
  getStatusFromInitialResponse: operation_js_1.getStatusFromInitialResponse,
18
19
  getStatusFromPollResponse: operation_js_1.getOperationStatus,
@@ -26,7 +27,7 @@ function createHttpPoller(lro, options) {
26
27
  init: async () => {
27
28
  const response = await lro.sendInitialRequest();
28
29
  const config = (0, operation_js_1.inferLroMode)(response.rawResponse, resourceLocationConfig);
29
- return Object.assign({ response, operationLocation: config === null || config === void 0 ? void 0 : config.operationLocation, resourceLocation: config === null || config === void 0 ? void 0 : config.resourceLocation, initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
30
+ return Object.assign({ response, operationLocation: (0, utils_js_1.rewriteUrl)({ url: config === null || config === void 0 ? void 0 : config.operationLocation, baseUrl }), resourceLocation: (0, utils_js_1.rewriteUrl)({ url: config === null || config === void 0 ? void 0 : config.resourceLocation, baseUrl }), initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
30
31
  },
31
32
  poll: lro.sendPollRequest,
32
33
  }, {
@@ -1 +1 @@
1
- {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAuBlC,4CAgDC;AAnED,iDASwB;AAExB,mDAAwD;AAExD;;;;;GAKG;AACH,SAAgB,gBAAgB,CAC9B,GAAqB,EACrB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,GAAG,KAAK,GAC9B,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,OAAO,IAAA,6BAAiB,EAAqC;QAC3D,4BAA4B,EAA5B,2CAA4B;QAC5B,yBAAyB,EAAE,iCAAkB;QAC7C,gBAAgB,EAAhB,+BAAgB;QAChB,oBAAoB,EAApB,mCAAoB;QACpB,mBAAmB,EAAnB,kCAAmB;QACnB,kBAAkB,EAAE,8BAAe;QACnC,QAAQ,EAAE,mCAAoB;QAC9B,qBAAqB;KACtB,CAAC,CACA;QACE,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,kBAAkB,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,IAAA,2BAAY,EAAC,QAAQ,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAC;YAC1E,uBACE,QAAQ,EACR,iBAAiB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,gBAAgB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,EAC1C,iBAAiB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,aAAa,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,IACjC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: config?.operationLocation,\n resourceLocation: config?.resourceLocation,\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
1
+ {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAwBlC,4CAiDC;AArED,iDASwB;AAExB,mDAAwD;AACxD,yCAAwC;AAExC;;;;;GAKG;AACH,SAAgB,gBAAgB,CAC9B,GAAqB,EACrB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,GAAG,KAAK,EAC7B,OAAO,GACR,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,OAAO,IAAA,6BAAiB,EAAqC;QAC3D,4BAA4B,EAA5B,2CAA4B;QAC5B,yBAAyB,EAAE,iCAAkB;QAC7C,gBAAgB,EAAhB,+BAAgB;QAChB,oBAAoB,EAApB,mCAAoB;QACpB,mBAAmB,EAAnB,kCAAmB;QACnB,kBAAkB,EAAE,8BAAe;QACnC,QAAQ,EAAE,mCAAoB;QAC9B,qBAAqB;KACtB,CAAC,CACA;QACE,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,kBAAkB,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,IAAA,2BAAY,EAAC,QAAQ,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAC;YAC1E,uBACE,QAAQ,EACR,iBAAiB,EAAE,IAAA,qBAAU,EAAC,EAAE,GAAG,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAAE,OAAO,EAAE,CAAC,EAC1E,gBAAgB,EAAE,IAAA,qBAAU,EAAC,EAAE,GAAG,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC,EACxE,iBAAiB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,aAAa,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,IACjC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Rewrites a given URL to use the specified base URL.
3
+ * It preserves the pathname, search parameters, and fragment.
4
+ * Handles relative URLs and proper encoding.
5
+ *
6
+ * @param params - An object containing the url and baseUrl.
7
+ * url - The original URL (absolute or relative).
8
+ * baseUrl - The new base URL to use.
9
+ * @returns The rewritten URL as a string.
10
+ */
11
+ export declare function rewriteUrl({ url, baseUrl, }: {
12
+ url?: string;
13
+ baseUrl?: string;
14
+ }): string | undefined;
15
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.rewriteUrl = rewriteUrl;
6
+ /**
7
+ * Rewrites a given URL to use the specified base URL.
8
+ * It preserves the pathname, search parameters, and fragment.
9
+ * Handles relative URLs and proper encoding.
10
+ *
11
+ * @param params - An object containing the url and baseUrl.
12
+ * url - The original URL (absolute or relative).
13
+ * baseUrl - The new base URL to use.
14
+ * @returns The rewritten URL as a string.
15
+ */
16
+ function rewriteUrl({ url, baseUrl, }) {
17
+ if (!url) {
18
+ return undefined;
19
+ }
20
+ if (!baseUrl) {
21
+ return url;
22
+ }
23
+ let originalUrl;
24
+ try {
25
+ // Try to parse inputUrl as an absolute URL.
26
+ originalUrl = new URL(url);
27
+ }
28
+ catch (_a) {
29
+ // If inputUrl is relative, resolve using the provided baseUrl.
30
+ try {
31
+ originalUrl = new URL(url, baseUrl);
32
+ }
33
+ catch (e) {
34
+ throw new Error(`Invalid input URL provided: ${url}`);
35
+ }
36
+ }
37
+ let newBase;
38
+ try {
39
+ newBase = new URL(baseUrl);
40
+ }
41
+ catch (e) {
42
+ throw new Error(`Invalid base URL provided: ${baseUrl}`);
43
+ }
44
+ const rewrittenUrl = new URL(`${originalUrl.pathname}${originalUrl.search}${originalUrl.hash}`, newBase);
45
+ return rewrittenUrl.toString();
46
+ }
47
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/http/utils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAYlC,gCAyCC;AAnDD;;;;;;;;;GASG;AACH,SAAgB,UAAU,CAAC,EACzB,GAAG,EACH,OAAO,GAIR;IACC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,WAAgB,CAAC;IAErB,IAAI,CAAC;QACH,4CAA4C;QAC5C,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,WAAM,CAAC;QACP,+DAA+D;QAC/D,IAAI,CAAC;YACH,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,IAAI,OAAY,CAAC;IACjB,IAAI,CAAC;QACH,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,8BAA8B,OAAO,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,GAAG,CAC1B,GAAG,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,EACjE,OAAO,CACR,CAAC;IAEF,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Rewrites a given URL to use the specified base URL.\n * It preserves the pathname, search parameters, and fragment.\n * Handles relative URLs and proper encoding.\n *\n * @param params - An object containing the url and baseUrl.\n * url - The original URL (absolute or relative).\n * baseUrl - The new base URL to use.\n * @returns The rewritten URL as a string.\n */\nexport function rewriteUrl({\n url,\n baseUrl,\n}: {\n url?: string;\n baseUrl?: string;\n}): string | undefined {\n if (!url) {\n return undefined;\n }\n if (!baseUrl) {\n return url;\n }\n\n let originalUrl: URL;\n\n try {\n // Try to parse inputUrl as an absolute URL.\n originalUrl = new URL(url);\n } catch {\n // If inputUrl is relative, resolve using the provided baseUrl.\n try {\n originalUrl = new URL(url, baseUrl);\n } catch (e) {\n throw new Error(`Invalid input URL provided: ${url}`);\n }\n }\n\n let newBase: URL;\n try {\n newBase = new URL(baseUrl);\n } catch (e) {\n throw new Error(`Invalid base URL provided: ${baseUrl}`);\n }\n\n const rewrittenUrl = new URL(\n `${originalUrl.pathname}${originalUrl.search}${originalUrl.hash}`,\n newBase,\n );\n\n return rewrittenUrl.toString();\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.50.1"
8
+ "packageVersion": "7.52.1"
9
9
  }
10
10
  ]
11
11
  }
@@ -88,6 +88,10 @@ export interface CreateHttpPollerOptions<TResult, TState> {
88
88
  * The potential location of the result of the LRO if specified by the LRO extension in the swagger.
89
89
  */
90
90
  resourceLocationConfig?: ResourceLocationConfig;
91
+ /**
92
+ * The base URL to use when making requests.
93
+ */
94
+ baseUrl?: string;
91
95
  /**
92
96
  * A function to process the result of the LRO.
93
97
  */
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB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gBAAgB,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,CAAQ;IACvC,OAAO,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;AAChC,CAAC;AAED,wCAAwC;AACxC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAkD,MASxF;IACC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;IAC/F,OAAO,aAAa,CAAC;QACnB,KAAK;QACL,QAAQ;QACR,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,UAAU,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault() {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAwB;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAwB;IAC5D,OAAO,WAAW,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,oBAAoB,CAAC,MAK7B;;IACC,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,MAAM,CAAC;IAChF,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,OAAO,MAAA,UAAU,EAAE,mCAAI,WAAW,CAAC;QACrC,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,OAAO,UAAU,EAAE,CAAC;QACtB,CAAC;IACH,CAAC;IAED,SAAS,UAAU;QACjB,QAA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YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
@@ -2,6 +2,7 @@
2
2
  // Licensed under the MIT License.
3
3
  import { getErrorFromResponse, getOperationLocation, getOperationStatus, getResourceLocation, getStatusFromInitialResponse, inferLroMode, isOperationError, parseRetryAfter, } from "./operation.js";
4
4
  import { buildCreatePoller } from "../poller/poller.js";
5
+ import { rewriteUrl } from "./utils.js";
5
6
  /**
6
7
  * Creates a poller that can be used to poll a long-running operation.
7
8
  * @param lro - Description of the long-running operation
@@ -9,7 +10,7 @@ import { buildCreatePoller } from "../poller/poller.js";
9
10
  * @returns an initialized poller
10
11
  */
11
12
  export function createHttpPoller(lro, options) {
12
- const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, } = options || {};
13
+ const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, } = options || {};
13
14
  return buildCreatePoller({
14
15
  getStatusFromInitialResponse,
15
16
  getStatusFromPollResponse: getOperationStatus,
@@ -23,7 +24,7 @@ export function createHttpPoller(lro, options) {
23
24
  init: async () => {
24
25
  const response = await lro.sendInitialRequest();
25
26
  const config = inferLroMode(response.rawResponse, resourceLocationConfig);
26
- return Object.assign({ response, operationLocation: config === null || config === void 0 ? void 0 : config.operationLocation, resourceLocation: config === null || config === void 0 ? void 0 : config.resourceLocation, initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
27
+ return Object.assign({ response, operationLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.operationLocation, baseUrl }), resourceLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.resourceLocation, baseUrl }), initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
27
28
  },
28
29
  poll: lro.sendPollRequest,
29
30
  }, {
@@ -1 +1 @@
1
- {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,4BAA4B,EAC5B,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAqB,EACrB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,GAAG,KAAK,GAC9B,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,OAAO,iBAAiB,CAAqC;QAC3D,4BAA4B;QAC5B,yBAAyB,EAAE,kBAAkB;QAC7C,gBAAgB;QAChB,oBAAoB;QACpB,mBAAmB;QACnB,kBAAkB,EAAE,eAAe;QACnC,QAAQ,EAAE,oBAAoB;QAC9B,qBAAqB;KACtB,CAAC,CACA;QACE,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,kBAAkB,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAC;YAC1E,uBACE,QAAQ,EACR,iBAAiB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,gBAAgB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,EAC1C,iBAAiB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,aAAa,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,IACjC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: config?.operationLocation,\n resourceLocation: config?.resourceLocation,\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
1
+ {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,4BAA4B,EAC5B,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qB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E,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Rewrites a given URL to use the specified base URL.
3
+ * It preserves the pathname, search parameters, and fragment.
4
+ * Handles relative URLs and proper encoding.
5
+ *
6
+ * @param params - An object containing the url and baseUrl.
7
+ * url - The original URL (absolute or relative).
8
+ * baseUrl - The new base URL to use.
9
+ * @returns The rewritten URL as a string.
10
+ */
11
+ export declare function rewriteUrl({ url, baseUrl, }: {
12
+ url?: string;
13
+ baseUrl?: string;
14
+ }): string | undefined;
15
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,44 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /**
4
+ * Rewrites a given URL to use the specified base URL.
5
+ * It preserves the pathname, search parameters, and fragment.
6
+ * Handles relative URLs and proper encoding.
7
+ *
8
+ * @param params - An object containing the url and baseUrl.
9
+ * url - The original URL (absolute or relative).
10
+ * baseUrl - The new base URL to use.
11
+ * @returns The rewritten URL as a string.
12
+ */
13
+ export function rewriteUrl({ url, baseUrl, }) {
14
+ if (!url) {
15
+ return undefined;
16
+ }
17
+ if (!baseUrl) {
18
+ return url;
19
+ }
20
+ let originalUrl;
21
+ try {
22
+ // Try to parse inputUrl as an absolute URL.
23
+ originalUrl = new URL(url);
24
+ }
25
+ catch (_a) {
26
+ // If inputUrl is relative, resolve using the provided baseUrl.
27
+ try {
28
+ originalUrl = new URL(url, baseUrl);
29
+ }
30
+ catch (e) {
31
+ throw new Error(`Invalid input URL provided: ${url}`);
32
+ }
33
+ }
34
+ let newBase;
35
+ try {
36
+ newBase = new URL(baseUrl);
37
+ }
38
+ catch (e) {
39
+ throw new Error(`Invalid base URL provided: ${baseUrl}`);
40
+ }
41
+ const rewrittenUrl = new URL(`${originalUrl.pathname}${originalUrl.search}${originalUrl.hash}`, newBase);
42
+ return rewrittenUrl.toString();
43
+ }
44
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/http/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,GAAG,EACH,OAAO,GAIR;IACC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,WAAgB,CAAC;IAErB,IAAI,CAAC;QACH,4CAA4C;QAC5C,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,WAAM,CAAC;QACP,+DAA+D;QAC/D,IAAI,CAAC;YACH,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,IAAI,OAAY,CAAC;IACjB,IAAI,CAAC;QACH,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,8BAA8B,OAAO,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,GAAG,CAC1B,GAAG,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,EACjE,OAAO,CACR,CAAC;IAEF,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Rewrites a given URL to use the specified base URL.\n * It preserves the pathname, search parameters, and fragment.\n * Handles relative URLs and proper encoding.\n *\n * @param params - An object containing the url and baseUrl.\n * url - The original URL (absolute or relative).\n * baseUrl - The new base URL to use.\n * @returns The rewritten URL as a string.\n */\nexport function rewriteUrl({\n url,\n baseUrl,\n}: {\n url?: string;\n baseUrl?: string;\n}): string | undefined {\n if (!url) {\n return undefined;\n }\n if (!baseUrl) {\n return url;\n }\n\n let originalUrl: URL;\n\n try {\n // Try to parse inputUrl as an absolute URL.\n originalUrl = new URL(url);\n } catch {\n // If inputUrl is relative, resolve using the provided baseUrl.\n try {\n originalUrl = new URL(url, baseUrl);\n } catch (e) {\n throw new Error(`Invalid input URL provided: ${url}`);\n }\n }\n\n let newBase: URL;\n try {\n newBase = new URL(baseUrl);\n } catch (e) {\n throw new Error(`Invalid base URL provided: ${baseUrl}`);\n }\n\n const rewrittenUrl = new URL(\n `${originalUrl.pathname}${originalUrl.search}${originalUrl.hash}`,\n newBase,\n );\n\n return rewrittenUrl.toString();\n}\n"]}
@@ -88,6 +88,10 @@ export interface CreateHttpPollerOptions<TResult, TState> {
88
88
  * The potential location of the result of the LRO if specified by the LRO extension in the swagger.
89
89
  */
90
90
  resourceLocationConfig?: ResourceLocationConfig;
91
+ /**
92
+ * The base URL to use when making requests.
93
+ */
94
+ baseUrl?: string;
91
95
  /**
92
96
  * A function to process the result of the LRO.
93
97
  */
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAAA,uCAAu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RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault() {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAwB;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAwB;IAC5D,OAAO,WAAW,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,oBAAoB,CAAC,MAK7B;;IACC,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,MAAM,CAAC;IAChF,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,OAAO,WAAW,CAAC;Q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AE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
@@ -2,6 +2,7 @@
2
2
  // Licensed under the MIT License.
3
3
  import { getErrorFromResponse, getOperationLocation, getOperationStatus, getResourceLocation, getStatusFromInitialResponse, inferLroMode, isOperationError, parseRetryAfter, } from "./operation.js";
4
4
  import { buildCreatePoller } from "../poller/poller.js";
5
+ import { rewriteUrl } from "./utils.js";
5
6
  /**
6
7
  * Creates a poller that can be used to poll a long-running operation.
7
8
  * @param lro - Description of the long-running operation
@@ -9,7 +10,7 @@ import { buildCreatePoller } from "../poller/poller.js";
9
10
  * @returns an initialized poller
10
11
  */
11
12
  export function createHttpPoller(lro, options) {
12
- const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, } = options || {};
13
+ const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, } = options || {};
13
14
  return buildCreatePoller({
14
15
  getStatusFromInitialResponse,
15
16
  getStatusFromPollResponse: getOperationStatus,
@@ -23,7 +24,7 @@ export function createHttpPoller(lro, options) {
23
24
  init: async () => {
24
25
  const response = await lro.sendInitialRequest();
25
26
  const config = inferLroMode(response.rawResponse, resourceLocationConfig);
26
- return Object.assign({ response, operationLocation: config === null || config === void 0 ? void 0 : config.operationLocation, resourceLocation: config === null || config === void 0 ? void 0 : config.resourceLocation, initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
27
+ return Object.assign({ response, operationLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.operationLocation, baseUrl }), resourceLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.resourceLocation, baseUrl }), initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
27
28
  },
28
29
  poll: lro.sendPollRequest,
29
30
  }, {
@@ -1 +1 @@
1
- {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,4BAA4B,EAC5B,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAqB,EACrB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY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YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: config?.operationLocation,\n resourceLocation: config?.resourceLocation,\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
1
+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,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,aAAa,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,IACjC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Rewrites a given URL to use the specified base URL.
3
+ * It preserves the pathname, search parameters, and fragment.
4
+ * Handles relative URLs and proper encoding.
5
+ *
6
+ * @param params - An object containing the url and baseUrl.
7
+ * url - The original URL (absolute or relative).
8
+ * baseUrl - The new base URL to use.
9
+ * @returns The rewritten URL as a string.
10
+ */
11
+ export declare function rewriteUrl({ url, baseUrl, }: {
12
+ url?: string;
13
+ baseUrl?: string;
14
+ }): string | undefined;
15
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,44 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /**
4
+ * Rewrites a given URL to use the specified base URL.
5
+ * It preserves the pathname, search parameters, and fragment.
6
+ * Handles relative URLs and proper encoding.
7
+ *
8
+ * @param params - An object containing the url and baseUrl.
9
+ * url - The original URL (absolute or relative).
10
+ * baseUrl - The new base URL to use.
11
+ * @returns The rewritten URL as a string.
12
+ */
13
+ export function rewriteUrl({ url, baseUrl, }) {
14
+ if (!url) {
15
+ return undefined;
16
+ }
17
+ if (!baseUrl) {
18
+ return url;
19
+ }
20
+ let originalUrl;
21
+ try {
22
+ // Try to parse inputUrl as an absolute URL.
23
+ originalUrl = new URL(url);
24
+ }
25
+ catch (_a) {
26
+ // If inputUrl is relative, resolve using the provided baseUrl.
27
+ try {
28
+ originalUrl = new URL(url, baseUrl);
29
+ }
30
+ catch (e) {
31
+ throw new Error(`Invalid input URL provided: ${url}`);
32
+ }
33
+ }
34
+ let newBase;
35
+ try {
36
+ newBase = new URL(baseUrl);
37
+ }
38
+ catch (e) {
39
+ throw new Error(`Invalid base URL provided: ${baseUrl}`);
40
+ }
41
+ const rewrittenUrl = new URL(`${originalUrl.pathname}${originalUrl.search}${originalUrl.hash}`, newBase);
42
+ return rewrittenUrl.toString();
43
+ }
44
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/http/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,GAAG,EACH,OAAO,GAIR;IACC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,WAAgB,CAAC;IAErB,IAAI,CAAC;QACH,4CAA4C;QAC5C,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,WAAM,CAAC;QACP,+DAA+D;QAC/D,IAAI,CAAC;YACH,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,IAAI,OAAY,CAAC;IACjB,IAAI,CAAC;QACH,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,8BAA8B,OAAO,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,GAAG,CAC1B,GAAG,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,EACjE,OAAO,CACR,CAAC;IAEF,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Rewrites a given URL to use the specified base URL.\n * It preserves the pathname, search parameters, and fragment.\n * Handles relative URLs and proper encoding.\n *\n * @param params - An object containing the url and baseUrl.\n * url - The original URL (absolute or relative).\n * baseUrl - The new base URL to use.\n * @returns The rewritten URL as a string.\n */\nexport function rewriteUrl({\n url,\n baseUrl,\n}: {\n url?: string;\n baseUrl?: string;\n}): string | undefined {\n if (!url) {\n return undefined;\n }\n if (!baseUrl) {\n return url;\n }\n\n let originalUrl: URL;\n\n try {\n // Try to parse inputUrl as an absolute URL.\n originalUrl = new URL(url);\n } catch {\n // If inputUrl is relative, resolve using the provided baseUrl.\n try {\n originalUrl = new URL(url, baseUrl);\n } catch (e) {\n throw new Error(`Invalid input URL provided: ${url}`);\n }\n }\n\n let newBase: URL;\n try {\n newBase = new URL(baseUrl);\n } catch (e) {\n throw new Error(`Invalid base URL provided: ${baseUrl}`);\n }\n\n const rewrittenUrl = new URL(\n `${originalUrl.pathname}${originalUrl.search}${originalUrl.hash}`,\n newBase,\n );\n\n return rewrittenUrl.toString();\n}\n"]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@azure/core-lro",
3
3
  "author": "Microsoft Corporation",
4
4
  "sdk-type": "client",
5
- "version": "3.1.1-alpha.20250313.3",
5
+ "version": "3.2.0-alpha.20250318.3",
6
6
  "type": "module",
7
7
  "description": "Isomorphic client library for supporting long-running operations in node.js and browser.",
8
8
  "exports": {
@@ -102,12 +102,12 @@
102
102
  "@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
103
103
  "@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
104
104
  "@types/node": "^18.0.0",
105
- "@vitest/browser": "^3.0.3",
106
- "@vitest/coverage-istanbul": "^3.0.3",
105
+ "@vitest/browser": "^3.0.9",
106
+ "@vitest/coverage-istanbul": "^3.0.9",
107
107
  "eslint": "^9.9.0",
108
108
  "playwright": "^1.41.2",
109
- "typescript": "~5.7.2",
110
- "vitest": "^3.0.3"
109
+ "typescript": "~5.8.2",
110
+ "vitest": "^3.0.9"
111
111
  },
112
112
  "//metadata": {
113
113
  "migrationDate": "2023-03-08T18:36:03.000Z",