UNPKG

@shopify/cli-kit

Version:

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

48 lines 1.7 kB
import { graphqlRequestDoc } from './graphql.js'; import { handleDeprecations } from './app-management.js'; import { appManagementFqdn } from '../context/fqdn.js'; import Bottleneck from 'bottleneck'; // API Rate limiter for partners API (Limit is 10 requests per second) // Jobs are launched every 150ms to add an extra 50ms margin per request. // Only 10 requests can be executed concurrently. const limiter = new Bottleneck({ minTime: 150, maxConcurrent: 10, }); /** * Prepares the request configuration for the App Management Functions API. * * @param orgId - Organization identifier. * @param token - Authentication token. * @param appId - App identifier. * @returns Request configuration object. */ async function setupRequest(orgId, token, appId) { const api = 'Functions'; const fqdn = await appManagementFqdn(); const url = `https://${fqdn}/functions/unstable/organizations/${orgId}/${appId}/graphql`; return { token, api, url, responseOptions: { onResponse: handleDeprecations }, }; } /** * Executes a rate-limited GraphQL request against the App Management Functions API. * * @param options - Request options. * @returns Promise resolving to the typed query result. */ export async function functionsRequestDoc(options) { const result = await limiter.schedule(async () => { return graphqlRequestDoc({ ...(await setupRequest(options.organizationId, options.token, options.appId)), query: options.query, variables: options.variables, unauthorizedHandler: options.unauthorizedHandler, }); }); return result; } //# sourceMappingURL=functions.js.map