mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-03-25 19:21:49 +00:00
30 lines
847 B
TypeScript
30 lines
847 B
TypeScript
|
import { HttpHeaders } from "../Constants";
|
||
|
import { Offer } from "../../Contracts/DataModels";
|
||
|
import { RequestOptions } from "@azure/cosmos/dist-esm";
|
||
|
import { client } from "../CosmosClient";
|
||
|
import { parseSDKOfferResponse } from "../OfferUtility";
|
||
|
import { readOffers } from "./readOffers";
|
||
|
|
||
|
export const readOfferWithSDK = async (offerId: string, resourceId: string): Promise<Offer> => {
|
||
|
if (!offerId) {
|
||
|
const offers = await readOffers();
|
||
|
const offer = offers.find(offer => offer.resource === resourceId);
|
||
|
|
||
|
if (!offer) {
|
||
|
return undefined;
|
||
|
}
|
||
|
offerId = offer.id;
|
||
|
}
|
||
|
|
||
|
const options: RequestOptions = {
|
||
|
initialHeaders: {
|
||
|
[HttpHeaders.populateCollectionThroughputInfo]: true
|
||
|
}
|
||
|
};
|
||
|
const response = await client()
|
||
|
.offer(offerId)
|
||
|
.read(options);
|
||
|
|
||
|
return parseSDKOfferResponse(response);
|
||
|
};
|