UNPKG

@shopify/cli-kit

Version:

A set of utilities, interfaces, and models that are common across all the platform features

97 lines 3.44 kB
import { graphqlRequest, graphqlRequestDoc } from './graphql.js'; import { handleDeprecations } from './partners.js'; import { businessPlatformFqdn } from '../context/fqdn.js'; /** * Sets up the request to the Business Platform Destinations API. * * @param token - Business Platform token. */ async function setupRequest(token) { const api = 'BusinessPlatform'; const fqdn = await businessPlatformFqdn(); const url = `https://${fqdn}/destinations/api/2020-07/graphql`; return { token, api, url, responseOptions: { onResponse: handleDeprecations }, }; } /** * Executes a GraphQL query against the Business Platform Destinations API. * * @param query - GraphQL query to execute. * @param token - Business Platform token. * @param variables - GraphQL variables to pass to the query. * @param cacheOptions - Cache options for the request. If not present, the request will not be cached. * @returns The response of the query of generic type <T>. */ export async function businessPlatformRequest(query, token, variables, cacheOptions) { return graphqlRequest({ ...(await setupRequest(token)), query, variables, cacheOptions, }); } /** * Executes a GraphQL query against the Business Platform Destinations API. Uses typed documents. * * @param options - The options for the request. * @returns The response of the query of generic type <TResult>. */ export async function businessPlatformRequestDoc(options) { return graphqlRequestDoc({ ...(await setupRequest(options.token)), query: options.query, variables: options.variables, cacheOptions: options.cacheOptions, unauthorizedHandler: options.unauthorizedHandler, }); } /** * Sets up the request to the Business Platform Organizations API. * * @param token - Business Platform token. * @param organizationId - Organization ID as a numeric (non-GID) value. */ async function setupOrganizationsRequest(token, organizationId) { const api = 'BusinessPlatform'; const fqdn = await businessPlatformFqdn(); const url = `https://${fqdn}/organizations/api/unstable/organization/${organizationId}/graphql`; return { token, api, url, responseOptions: { onResponse: handleDeprecations }, }; } /** * Executes a GraphQL query against the Business Platform Organizations API. * * @param options - The options for the request. * @returns The response of the query of generic type <T>. */ export async function businessPlatformOrganizationsRequest(options) { return graphqlRequest({ query: options.query, ...(await setupOrganizationsRequest(options.token, options.organizationId)), variables: options.variables, unauthorizedHandler: options.unauthorizedHandler, }); } /** * Executes a GraphQL query against the Business Platform Organizations API. Uses typed documents. * * @param options - The options for the request. * @returns The response of the query of generic type <T>. */ export async function businessPlatformOrganizationsRequestDoc(options) { return graphqlRequestDoc({ query: options.query, ...(await setupOrganizationsRequest(options.token, options.organizationId)), variables: options.variables, unauthorizedHandler: options.unauthorizedHandler, }); } //# sourceMappingURL=business-platform.js.map