@shopify/cli-kit 3.80.7 → 3.81.0

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 (110) hide show
  1. package/dist/private/node/analytics.js +4 -4
  2. package/dist/private/node/analytics.js.map +1 -1
  3. package/dist/private/node/api/rest.d.ts +1 -1
  4. package/dist/private/node/api/rest.js.map +1 -1
  5. package/dist/private/node/api.d.ts +1 -1
  6. package/dist/private/node/api.js +3 -9
  7. package/dist/private/node/api.js.map +1 -1
  8. package/dist/private/node/conf-store.js +1 -1
  9. package/dist/private/node/conf-store.js.map +1 -1
  10. package/dist/private/node/constants.d.ts +0 -2
  11. package/dist/private/node/constants.js +0 -2
  12. package/dist/private/node/constants.js.map +1 -1
  13. package/dist/private/node/output.d.ts +22 -0
  14. package/dist/private/node/output.js +47 -0
  15. package/dist/private/node/output.js.map +1 -0
  16. package/dist/private/node/session/exchange.js +1 -1
  17. package/dist/private/node/session/exchange.js.map +1 -1
  18. package/dist/private/node/session/scopes.js +3 -1
  19. package/dist/private/node/session/scopes.js.map +1 -1
  20. package/dist/private/node/session/validate.js +1 -1
  21. package/dist/private/node/session/validate.js.map +1 -1
  22. package/dist/private/node/session.d.ts +1 -1
  23. package/dist/private/node/session.js +3 -4
  24. package/dist/private/node/session.js.map +1 -1
  25. package/dist/private/node/sleep-with-backoff.js +1 -1
  26. package/dist/private/node/sleep-with-backoff.js.map +1 -1
  27. package/dist/private/node/ui/alert.js +1 -8
  28. package/dist/private/node/ui/alert.js.map +1 -1
  29. package/dist/private/node/ui/components/Banner.test.js +1 -1
  30. package/dist/private/node/ui/components/Banner.test.js.map +1 -1
  31. package/dist/private/node/ui/components/TextPrompt.test.js +1 -1
  32. package/dist/private/node/ui/components/TextPrompt.test.js.map +1 -1
  33. package/dist/private/node/ui.d.ts +1 -1
  34. package/dist/private/node/ui.js +6 -8
  35. package/dist/private/node/ui.js.map +1 -1
  36. package/dist/public/common/ts/json-narrowing.js +1 -1
  37. package/dist/public/common/ts/json-narrowing.js.map +1 -1
  38. package/dist/public/common/version.d.ts +1 -1
  39. package/dist/public/common/version.js +1 -1
  40. package/dist/public/common/version.js.map +1 -1
  41. package/dist/public/node/api/admin.js +2 -2
  42. package/dist/public/node/api/admin.js.map +1 -1
  43. package/dist/public/node/api/app-dev.d.ts +16 -4
  44. package/dist/public/node/api/app-dev.js +7 -9
  45. package/dist/public/node/api/app-dev.js.map +1 -1
  46. package/dist/public/node/api/app-management.d.ts +17 -4
  47. package/dist/public/node/api/app-management.js +9 -13
  48. package/dist/public/node/api/app-management.js.map +1 -1
  49. package/dist/public/node/api/business-platform.d.ts +28 -16
  50. package/dist/public/node/api/business-platform.js +19 -25
  51. package/dist/public/node/api/business-platform.js.map +1 -1
  52. package/dist/public/node/api/functions.d.ts +16 -3
  53. package/dist/public/node/api/functions.js +6 -9
  54. package/dist/public/node/api/functions.js.map +1 -1
  55. package/dist/public/node/api/graphql.d.ts +10 -2
  56. package/dist/public/node/api/graphql.js +52 -10
  57. package/dist/public/node/api/graphql.js.map +1 -1
  58. package/dist/public/node/api/partners.d.ts +5 -3
  59. package/dist/public/node/api/partners.js +7 -3
  60. package/dist/public/node/api/partners.js.map +1 -1
  61. package/dist/public/node/api/rest-api-throttler.js +1 -1
  62. package/dist/public/node/api/rest-api-throttler.js.map +1 -1
  63. package/dist/public/node/api/webhooks.d.ts +13 -5
  64. package/dist/public/node/api/webhooks.js +7 -9
  65. package/dist/public/node/api/webhooks.js.map +1 -1
  66. package/dist/public/node/archiver.js +1 -2
  67. package/dist/public/node/archiver.js.map +1 -1
  68. package/dist/public/node/base-command.d.ts +5 -0
  69. package/dist/public/node/base-command.js +27 -10
  70. package/dist/public/node/base-command.js.map +1 -1
  71. package/dist/public/node/context/local.d.ts +0 -14
  72. package/dist/public/node/context/local.js +0 -18
  73. package/dist/public/node/context/local.js.map +1 -1
  74. package/dist/public/node/environments.d.ts +2 -0
  75. package/dist/public/node/environments.js +26 -11
  76. package/dist/public/node/environments.js.map +1 -1
  77. package/dist/public/node/hooks/deprecations.js +1 -1
  78. package/dist/public/node/hooks/deprecations.js.map +1 -1
  79. package/dist/public/node/json-schema.js +30 -11
  80. package/dist/public/node/json-schema.js.map +1 -1
  81. package/dist/public/node/logs.js +2 -2
  82. package/dist/public/node/logs.js.map +1 -1
  83. package/dist/public/node/node-package-manager.js +12 -4
  84. package/dist/public/node/node-package-manager.js.map +1 -1
  85. package/dist/public/node/notifications-system.js +1 -1
  86. package/dist/public/node/notifications-system.js.map +1 -1
  87. package/dist/public/node/output.d.ts +16 -26
  88. package/dist/public/node/output.js +24 -55
  89. package/dist/public/node/output.js.map +1 -1
  90. package/dist/public/node/themes/api.d.ts +2 -2
  91. package/dist/public/node/themes/api.js +8 -5
  92. package/dist/public/node/themes/api.js.map +1 -1
  93. package/dist/public/node/themes/conf.d.ts +2 -2
  94. package/dist/public/node/themes/conf.js +2 -2
  95. package/dist/public/node/themes/conf.js.map +1 -1
  96. package/dist/public/node/themes/factories.d.ts +1 -1
  97. package/dist/public/node/themes/factories.js.map +1 -1
  98. package/dist/public/node/themes/theme-manager.d.ts +3 -3
  99. package/dist/public/node/themes/theme-manager.js +2 -2
  100. package/dist/public/node/themes/theme-manager.js.map +1 -1
  101. package/dist/public/node/themes/urls.d.ts +2 -2
  102. package/dist/public/node/themes/urls.js.map +1 -1
  103. package/dist/public/node/themes/utils.d.ts +1 -1
  104. package/dist/public/node/themes/utils.js +1 -1
  105. package/dist/public/node/themes/utils.js.map +1 -1
  106. package/dist/public/node/ui.d.ts +0 -13
  107. package/dist/public/node/ui.js +2 -18
  108. package/dist/public/node/ui.js.map +1 -1
  109. package/dist/tsconfig.tsbuildinfo +1 -1
  110. package/package.json +3 -4
@@ -1 +1 @@
1
- {"version":3,"file":"admin.js","sourceRoot":"","sources":["../../../../src/public/node/api/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,iBAAiB,EAA2C,MAAM,cAAc,CAAA;A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;QACP,MAAM;QACN,IAAI;KACL,CAAC,CAAA;IAEF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAEpD,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE;KAChC,CAAA;AACH,CAAC","sourcesContent":["import {graphqlRequest, graphqlRequestDoc, GraphQLResponseOptions, GraphQLVariables} from './graphql.js'\nimport {AdminSession} from '../session.js'\nimport {outputContent, outputToken} from '../../../public/node/output.js'\nimport {AbortError, BugError} from '../error.js'\nimport {\n restRequestBody,\n restRequestHeaders,\n restRequestUrl,\n isThemeAccessSession,\n} from '../../../private/node/api/rest.js'\nimport {RequestModeInput, shopifyFetch} from '../http.js'\nimport {PublicApiVersions} from '../../../cli/api/graphql/admin/generated/public_api_versions.js'\nimport {normalizeStoreFqdn} from '../context/fqdn.js'\nimport {themeKitAccessDomain} from '../../../private/node/constants.js'\nimport {ClientError, Variables} from 'graphql-request'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\n\nconst LatestApiVersionByFQDN = new Map<string, string>()\n\n/**\n * Executes a GraphQL query against the Admin API.\n *\n * @param query - GraphQL query to execute.\n * @param session - Shopify admin session including token and Store FQDN.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T> {\n const api = 'Admin'\n const version = await fetchLatestSupportedApiVersion(session)\n const store = await normalizeStoreFqdn(session.storeFqdn)\n const url = adminUrl(store, version, session)\n const addedHeaders = themeAccessHeaders(session)\n return graphqlRequest({query, api, addedHeaders, url, token: session.token, variables})\n}\n\nexport interface AdminRequestOptions<TResult, TVariables extends Variables> {\n /** GraphQL query to execute. */\n query: TypedDocumentNode<TResult, TVariables>\n /** Shopify admin session including token and Store FQDN. */\n session: AdminSession\n /** GraphQL variables to pass to the query. */\n variables?: TVariables\n /** API version. */\n version?: string\n /** Control how API responses will be handled. */\n responseOptions?: GraphQLResponseOptions<TResult>\n /** Custom request behaviour for retries and timeouts. */\n requestBehaviour?: RequestModeInput\n}\n\n/**\n * Executes a GraphQL query against the Admin API. Uses typed documents.\n *\n * @param options - Admin request options.\n * @returns The response of the query of generic type <TResult>.\n */\nexport async function adminRequestDoc<TResult, TVariables extends Variables>(\n options: AdminRequestOptions<TResult, TVariables>,\n): Promise<TResult> {\n const {query, session, variables, version, responseOptions, requestBehaviour} = options\n\n let apiVersion = version ?? LatestApiVersionByFQDN.get(session.storeFqdn)\n if (!apiVersion) {\n apiVersion = await fetchLatestSupportedApiVersion(session)\n }\n const store = await normalizeStoreFqdn(session.storeFqdn)\n const addedHeaders = themeAccessHeaders(session)\n const opts = {\n url: adminUrl(store, apiVersion, session),\n api: 'Admin',\n token: session.token,\n addedHeaders,\n }\n let unauthorizedHandler\n if ('refresh' in session) {\n unauthorizedHandler = session.refresh as () => Promise<void>\n }\n const result = graphqlRequestDoc<TResult, TVariables>({\n ...opts,\n query,\n variables,\n responseOptions,\n unauthorizedHandler,\n requestBehaviour,\n })\n return result\n}\n\nfunction themeAccessHeaders(session: AdminSession): {[header: string]: string} {\n return isThemeAccessSession(session)\n ? {'X-Shopify-Shop': session.storeFqdn, 'X-Shopify-Access-Token': session.token}\n : {}\n}\n\n/**\n * GraphQL query to retrieve the latest supported API version.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - The latest supported API version.\n */\nasync function fetchLatestSupportedApiVersion(session: AdminSession): Promise<string> {\n const apiVersions = await supportedApiVersions(session)\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const latest = apiVersions.reverse()[0]!\n LatestApiVersionByFQDN.set(session.storeFqdn, latest)\n return latest\n}\n\n/**\n * GraphQL query to retrieve all supported API versions.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - An array of supported API versions.\n */\nexport async function supportedApiVersions(session: AdminSession): Promise<string[]> {\n const apiVersions = await fetchApiVersions(session)\n return apiVersions\n .filter((item) => item.supported)\n .map((item) => item.handle)\n .sort()\n}\n\n/**\n * GraphQL query to retrieve all API versions.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - An array of supported and unsupported API versions.\n */\nasync function fetchApiVersions(session: AdminSession): Promise<ApiVersion[]> {\n try {\n const response = await adminRequestDoc({\n query: PublicApiVersions,\n session,\n variables: {},\n version: 'unstable',\n responseOptions: {handleErrors: false},\n })\n return response.publicApiVersions\n } catch (error) {\n if (error instanceof ClientError && error.response.status === 403) {\n const storeName = session.storeFqdn.replace('.myshopify.com', '')\n throw new AbortError(\n outputContent`Looks like you don't have access this dev store: (${outputToken.link(\n storeName,\n `https://${session.storeFqdn}`,\n )})`,\n outputContent`If you're not the owner, create a dev store staff account for yourself`,\n )\n }\n if (error instanceof ClientError && (error.response.status === 401 || error.response.status === 404)) {\n throw new AbortError(\n `Error connecting to your store ${session.storeFqdn}: ${error.message} ${error.response.status} ${error.response.data}`,\n )\n } else {\n throw new BugError(\n `Unknown error connecting to your store ${session.storeFqdn}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n )\n }\n }\n}\n\n/**\n * Returns the Admin API URL for the given store and version.\n *\n * @param store - Store FQDN.\n * @param version - API version.\n * @param session - User session.\n * @returns - Admin API URL.\n */\nexport function adminUrl(store: string, version: string | undefined, session?: AdminSession): string {\n const realVersion = version ?? 'unstable'\n\n const url =\n session && isThemeAccessSession(session)\n ? `https://${themeKitAccessDomain}/cli/admin/api/${realVersion}/graphql.json`\n : `https://${store}/admin/api/${realVersion}/graphql.json`\n return url\n}\n\ninterface ApiVersion {\n handle: string\n supported: boolean\n}\n\n/**\n * Executes a REST request against the Admin API.\n *\n * @param method - Request's HTTP method.\n * @param path - Path of the REST resource.\n * @param session - Shopify Admin session including token and Store FQDN.\n * @param requestBody - Request body of including REST resource specific parameters.\n * @param searchParams - Search params, appended to the URL.\n * @param apiVersion - Admin API version.\n * @returns - The {@link RestResponse}.\n */\nexport async function restRequest<T>(\n method: string,\n path: string,\n session: AdminSession,\n requestBody?: T,\n searchParams: {[name: string]: string} = {},\n apiVersion = 'unstable',\n): Promise<RestResponse> {\n const url = restRequestUrl(session, apiVersion, path, searchParams)\n const body = restRequestBody<T>(requestBody)\n\n const headers = restRequestHeaders(session)\n const response = await shopifyFetch(url, {\n headers,\n method,\n body,\n })\n\n const json = await response.json().catch(() => ({}))\n\n return {\n json,\n status: response.status,\n headers: response.headers.raw(),\n }\n}\n\n/**\n * Respose of a REST request.\n */\nexport interface RestResponse {\n /**\n * REST JSON respose.\n */\n // Using `any` to avoid introducing extra DTO layers.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n json: any\n\n /**\n * HTTP response status.\n */\n status: number\n\n /**\n * HTTP response headers.\n */\n headers: {[key: string]: string[]}\n}\n"]}
1
+ {"version":3,"file":"admin.js","sourceRoot":"","sources":["../../../../src/public/node/api/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,iBAAiB,GAIlB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,gCAAgC,CAAA;AACzE,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAA;AAChD,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,oBAAoB,GACrB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAmB,YAAY,EAAC,MAAM,YAAY,CAAA;AACzD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iEAAiE,CAAA;AACjG,OAAO,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AACvE,OAAO,EAAC,WAAW,EAAY,MAAM,iBAAiB,CAAA;AAGtD,MAAM,sBAAsB,GAAG,IAAI,GA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AAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,OAA2B,EAAE,OAAsB;IACzF,MAAM,WAAW,GAAG,OAAO,IAAI,UAAU,CAAA;IAEzC,MAAM,GAAG,GACP,OAAO,IAAI,oBAAoB,CAAC,OAAO,CAAC;QACtC,CAAC,CAAC,WAAW,oBAAoB,kBAAkB,WAAW,eAAe;QAC7E,CAAC,CAAC,WAAW,KAAK,cAAc,WAAW,eAAe,CAAA;IAC9D,OAAO,GAAG,CAAA;AACZ,CAAC;AAOD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAc,EACd,IAAY,EACZ,OAAqB,EACrB,WAAe,EACf,eAAyC,EAAE,EAC3C,UAAU,GAAG,UAAU;IAEvB,MAAM,GAAG,GAAG,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,CAAC,CAAA;IACnE,MAAM,IAAI,GAAG,eAAe,CAAI,WAAW,CAAC,CAAA;IAE5C,MAAM,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAC3C,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,GAAG,EAAE;QACvC,OAAO;QACP,MAAM;QACN,IAAI;KACL,CAAC,CAAA;IAEF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAEpD,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE;KAChC,CAAA;AACH,CAAC","sourcesContent":["import {\n graphqlRequest,\n graphqlRequestDoc,\n GraphQLResponseOptions,\n GraphQLVariables,\n UnauthorizedHandler,\n} from './graphql.js'\nimport {AdminSession} from '../session.js'\nimport {outputContent, outputToken} from '../../../public/node/output.js'\nimport {AbortError, BugError} from '../error.js'\nimport {\n restRequestBody,\n restRequestHeaders,\n restRequestUrl,\n isThemeAccessSession,\n} from '../../../private/node/api/rest.js'\nimport {RequestModeInput, shopifyFetch} from '../http.js'\nimport {PublicApiVersions} from '../../../cli/api/graphql/admin/generated/public_api_versions.js'\nimport {normalizeStoreFqdn} from '../context/fqdn.js'\nimport {themeKitAccessDomain} from '../../../private/node/constants.js'\nimport {ClientError, Variables} from 'graphql-request'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\n\nconst LatestApiVersionByFQDN = new Map<string, string>()\n\n/**\n * Executes a GraphQL query against the Admin API.\n *\n * @param query - GraphQL query to execute.\n * @param session - Shopify admin session including token and Store FQDN.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T> {\n const api = 'Admin'\n const version = await fetchLatestSupportedApiVersion(session)\n const store = await normalizeStoreFqdn(session.storeFqdn)\n const url = adminUrl(store, version, session)\n const addedHeaders = themeAccessHeaders(session)\n return graphqlRequest({query, api, addedHeaders, url, token: session.token, variables})\n}\n\nexport interface AdminRequestOptions<TResult, TVariables extends Variables> {\n /** GraphQL query to execute. */\n query: TypedDocumentNode<TResult, TVariables>\n /** Shopify admin session including token and Store FQDN. */\n session: AdminSession\n /** GraphQL variables to pass to the query. */\n variables?: TVariables\n /** API version. */\n version?: string\n /** Control how API responses will be handled. */\n responseOptions?: GraphQLResponseOptions<TResult>\n /** Custom request behaviour for retries and timeouts. */\n requestBehaviour?: RequestModeInput\n}\n\n/**\n * Executes a GraphQL query against the Admin API. Uses typed documents.\n *\n * @param options - Admin request options.\n * @returns The response of the query of generic type <TResult>.\n */\nexport async function adminRequestDoc<TResult, TVariables extends Variables>(\n options: AdminRequestOptions<TResult, TVariables>,\n): Promise<TResult> {\n const {query, session, variables, version, responseOptions, requestBehaviour} = options\n\n let apiVersion = version ?? LatestApiVersionByFQDN.get(session.storeFqdn)\n if (!apiVersion) {\n apiVersion = await fetchLatestSupportedApiVersion(session)\n }\n const store = await normalizeStoreFqdn(session.storeFqdn)\n const addedHeaders = themeAccessHeaders(session)\n const opts = {\n url: adminUrl(store, apiVersion, session),\n api: 'Admin',\n token: session.token,\n addedHeaders,\n }\n let unauthorizedHandler: UnauthorizedHandler | undefined\n if ('refresh' in session) {\n unauthorizedHandler = {type: 'token_refresh', handler: session.refresh as () => Promise<{token: string}>}\n }\n const result = graphqlRequestDoc<TResult, TVariables>({\n ...opts,\n query,\n variables,\n responseOptions,\n unauthorizedHandler,\n requestBehaviour,\n })\n return result\n}\n\nfunction themeAccessHeaders(session: AdminSession): {[header: string]: string} {\n return isThemeAccessSession(session)\n ? {'X-Shopify-Shop': session.storeFqdn, 'X-Shopify-Access-Token': session.token}\n : {}\n}\n\n/**\n * GraphQL query to retrieve the latest supported API version.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - The latest supported API version.\n */\nasync function fetchLatestSupportedApiVersion(session: AdminSession): Promise<string> {\n const apiVersions = await supportedApiVersions(session)\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const latest = apiVersions.reverse()[0]!\n LatestApiVersionByFQDN.set(session.storeFqdn, latest)\n return latest\n}\n\n/**\n * GraphQL query to retrieve all supported API versions.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - An array of supported API versions.\n */\nexport async function supportedApiVersions(session: AdminSession): Promise<string[]> {\n const apiVersions = await fetchApiVersions(session)\n return apiVersions\n .filter((item) => item.supported)\n .map((item) => item.handle)\n .sort()\n}\n\n/**\n * GraphQL query to retrieve all API versions.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - An array of supported and unsupported API versions.\n */\nasync function fetchApiVersions(session: AdminSession): Promise<ApiVersion[]> {\n try {\n const response = await adminRequestDoc({\n query: PublicApiVersions,\n session,\n variables: {},\n version: 'unstable',\n responseOptions: {handleErrors: false},\n })\n return response.publicApiVersions\n } catch (error) {\n if (error instanceof ClientError && error.response.status === 403) {\n const storeName = session.storeFqdn.replace('.myshopify.com', '')\n throw new AbortError(\n outputContent`Looks like you don't have access this dev store: (${outputToken.link(\n storeName,\n `https://${session.storeFqdn}`,\n )})`,\n outputContent`If you're not the owner, create a dev store staff account for yourself`,\n )\n }\n if (error instanceof ClientError && (error.response.status === 401 || error.response.status === 404)) {\n throw new AbortError(\n `Error connecting to your store ${session.storeFqdn}: ${error.message} ${error.response.status} ${error.response.data}`,\n )\n } else {\n throw new BugError(\n `Unknown error connecting to your store ${session.storeFqdn}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n )\n }\n }\n}\n\n/**\n * Returns the Admin API URL for the given store and version.\n *\n * @param store - Store FQDN.\n * @param version - API version.\n * @param session - User session.\n * @returns - Admin API URL.\n */\nexport function adminUrl(store: string, version: string | undefined, session?: AdminSession): string {\n const realVersion = version ?? 'unstable'\n\n const url =\n session && isThemeAccessSession(session)\n ? `https://${themeKitAccessDomain}/cli/admin/api/${realVersion}/graphql.json`\n : `https://${store}/admin/api/${realVersion}/graphql.json`\n return url\n}\n\ninterface ApiVersion {\n handle: string\n supported: boolean\n}\n\n/**\n * Executes a REST request against the Admin API.\n *\n * @param method - Request's HTTP method.\n * @param path - Path of the REST resource.\n * @param session - Shopify Admin session including token and Store FQDN.\n * @param requestBody - Request body of including REST resource specific parameters.\n * @param searchParams - Search params, appended to the URL.\n * @param apiVersion - Admin API version.\n * @returns - The {@link RestResponse}.\n */\nexport async function restRequest<T>(\n method: string,\n path: string,\n session: AdminSession,\n requestBody?: T,\n searchParams: {[name: string]: string} = {},\n apiVersion = 'unstable',\n): Promise<RestResponse> {\n const url = restRequestUrl(session, apiVersion, path, searchParams)\n const body = restRequestBody<T>(requestBody)\n\n const headers = restRequestHeaders(session)\n const response = await shopifyFetch(url, {\n headers,\n method,\n body,\n })\n\n const json = await response.json().catch(() => ({}))\n\n return {\n json,\n status: response.status,\n headers: response.headers.raw(),\n }\n}\n\n/**\n * Respose of a REST request.\n */\nexport interface RestResponse {\n /**\n * REST JSON respose.\n */\n // Using `any` to avoid introducing extra DTO layers.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n json: any\n\n /**\n * HTTP response status.\n */\n status: number\n\n /**\n * HTTP response headers.\n */\n headers: {[key: string]: string[]}\n}\n"]}
@@ -1,13 +1,25 @@
1
+ import { UnauthorizedHandler } from './graphql.js';
1
2
  import { Variables } from 'graphql-request';
2
3
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
3
4
  /**
4
- * Executes an org-scoped GraphQL query against the App Management API.
5
- * Uses typed documents.
6
- *
7
5
  * @param query - GraphQL query to execute.
8
6
  * @param shopFqdn - The shop fqdn.
9
7
  * @param token - Partners token.
10
8
  * @param variables - GraphQL variables to pass to the query.
9
+ * @param unauthorizedHandler - Unauthorized handler to use.
10
+ */
11
+ export interface AppDevRequestOptions<TResult, TVariables extends Variables> {
12
+ query: TypedDocumentNode<TResult, TVariables>;
13
+ shopFqdn: string;
14
+ token: string;
15
+ unauthorizedHandler: UnauthorizedHandler;
16
+ variables?: TVariables;
17
+ }
18
+ /**
19
+ * Executes an org-scoped GraphQL query against the App Management API.
20
+ * Uses typed documents.
21
+ *
22
+ * @param options - The options for the request.
11
23
  * @returns The response of the query of generic type <T>.
12
24
  */
13
- export declare function appDevRequest<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, shopFqdn: string, token: string, variables?: TVariables): Promise<TResult>;
25
+ export declare function appDevRequestDoc<TResult, TVariables extends Variables>(options: AppDevRequestOptions<TResult, TVariables>): Promise<TResult>;
@@ -13,25 +13,23 @@ const limiter = new Bottleneck({
13
13
  * Executes an org-scoped GraphQL query against the App Management API.
14
14
  * Uses typed documents.
15
15
  *
16
- * @param query - GraphQL query to execute.
17
- * @param shopFqdn - The shop fqdn.
18
- * @param token - Partners token.
19
- * @param variables - GraphQL variables to pass to the query.
16
+ * @param options - The options for the request.
20
17
  * @returns The response of the query of generic type <T>.
21
18
  */
22
- export async function appDevRequest(query, shopFqdn, token, variables) {
19
+ export async function appDevRequestDoc(options) {
23
20
  const api = 'App Dev';
24
- const normalizedShopFqdn = await normalizeStoreFqdn(shopFqdn);
21
+ const normalizedShopFqdn = await normalizeStoreFqdn(options.shopFqdn);
25
22
  const fqdn = await appDevFqdn(normalizedShopFqdn);
26
23
  const url = `https://${fqdn}/app_dev/unstable/graphql.json`;
27
24
  const addedHeaders = serviceEnvironment() === 'local' ? { 'x-forwarded-host': normalizedShopFqdn } : undefined;
28
25
  const result = limiter.schedule(() => graphqlRequestDoc({
29
- query,
26
+ query: options.query,
30
27
  api,
31
28
  url,
32
- token,
29
+ token: options.token,
33
30
  addedHeaders,
34
- variables,
31
+ variables: options.variables,
32
+ unauthorizedHandler: options.unauthorizedHandler,
35
33
  }));
36
34
  return result;
37
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"app-dev.js","sourceRoot":"","sources":["../../../../src/public/node/api/app-dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAC,UAAU,EAAE,kBAAkB,EAAC,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAC,kBAAkB,EAAC,MAAM,0CAA0C,CAAA;AAC3E,OAAO,UAAU,MAAM,YAAY,CAAA;AAInC,mBAAmB;AACnB,gCAAgC;AAChC,iDAAiD;AACjD,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC;IAC7B,OAAO,EAAE,GAAG;IACZ,aAAa,EAAE,EAAE;CAClB,CAAC,CAAA;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAA6C,EAC7C,QAAgB,EAChB,KAAa,EACb,SAAsB;IAEtB,MAAM,GAAG,GAAG,SAAS,CAAA;IACrB,MAAM,kBAAkB,GAAG,MAAM,kBAAkB,CAAC,QAAQ,CAAC,CAAA;IAC7D,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,kBAAkB,CAAC,CAAA;IACjD,MAAM,GAAG,GAAG,WAAW,IAAI,gCAAgC,CAAA;IAE3D,MAAM,YAAY,GAAG,kBAAkB,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EAAC,kBAAkB,EAAE,kBAAkB,EAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAE5G,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAU,GAAG,EAAE,CAC5C,iBAAiB,CAAsB;QACrC,KAAK;QACL,GAAG;QACH,GAAG;QACH,KAAK;QACL,YAAY;QACZ,SAAS;KACV,CAAC,CACH,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import {graphqlRequestDoc} from './graphql.js'\nimport {appDevFqdn, normalizeStoreFqdn} from '../context/fqdn.js'\nimport {serviceEnvironment} from '../../../private/node/context/service.js'\nimport Bottleneck from 'bottleneck'\nimport {Variables} from 'graphql-request'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\n\n// API Rate limiter\n// Jobs are launched every 150ms\n// Only 10 requests can be executed concurrently.\nconst limiter = new Bottleneck({\n minTime: 150,\n maxConcurrent: 10,\n})\n\n/**\n * Executes an org-scoped GraphQL query against the App Management API.\n * Uses typed documents.\n *\n * @param query - GraphQL query to execute.\n * @param shopFqdn - The shop fqdn.\n * @param token - Partners token.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function appDevRequest<TResult, TVariables extends Variables>(\n query: TypedDocumentNode<TResult, TVariables>,\n shopFqdn: string,\n token: string,\n variables?: TVariables,\n): Promise<TResult> {\n const api = 'App Dev'\n const normalizedShopFqdn = await normalizeStoreFqdn(shopFqdn)\n const fqdn = await appDevFqdn(normalizedShopFqdn)\n const url = `https://${fqdn}/app_dev/unstable/graphql.json`\n\n const addedHeaders = serviceEnvironment() === 'local' ? {'x-forwarded-host': normalizedShopFqdn} : undefined\n\n const result = limiter.schedule<TResult>(() =>\n graphqlRequestDoc<TResult, TVariables>({\n query,\n api,\n url,\n token,\n addedHeaders,\n variables,\n }),\n )\n\n return result\n}\n"]}
1
+ {"version":3,"file":"app-dev.js","sourceRoot":"","sources":["../../../../src/public/node/api/app-dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAsB,MAAM,cAAc,CAAA;AACnE,OAAO,EAAC,UAAU,EAAE,kBAAkB,EAAC,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAC,kBAAkB,EAAC,MAAM,0CAA0C,CAAA;AAC3E,OAAO,UAAU,MAAM,YAAY,CAAA;AAInC,mBAAmB;AACnB,gCAAgC;AAChC,iDAAiD;AACjD,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC;IAC7B,OAAO,EAAE,GAAG;IACZ,aAAa,EAAE,EAAE;CAClB,CAAC,CAAA;AAgBF;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAkD;IAElD,MAAM,GAAG,GAAG,SAAS,CAAA;IACrB,MAAM,kBAAkB,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACrE,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,kBAAkB,CAAC,CAAA;IACjD,MAAM,GAAG,GAAG,WAAW,IAAI,gCAAgC,CAAA;IAE3D,MAAM,YAAY,GAAG,kBAAkB,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EAAC,kBAAkB,EAAE,kBAAkB,EAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAE5G,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAU,GAAG,EAAE,CAC5C,iBAAiB,CAAsB;QACrC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,GAAG;QACH,GAAG;QACH,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,YAAY;QACZ,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;KACjD,CAAC,CACH,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import {graphqlRequestDoc, UnauthorizedHandler} from './graphql.js'\nimport {appDevFqdn, normalizeStoreFqdn} from '../context/fqdn.js'\nimport {serviceEnvironment} from '../../../private/node/context/service.js'\nimport Bottleneck from 'bottleneck'\nimport {Variables} from 'graphql-request'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\n\n// API Rate limiter\n// Jobs are launched every 150ms\n// Only 10 requests can be executed concurrently.\nconst limiter = new Bottleneck({\n minTime: 150,\n maxConcurrent: 10,\n})\n\n/**\n * @param query - GraphQL query to execute.\n * @param shopFqdn - The shop fqdn.\n * @param token - Partners token.\n * @param variables - GraphQL variables to pass to the query.\n * @param unauthorizedHandler - Unauthorized handler to use.\n */\nexport interface AppDevRequestOptions<TResult, TVariables extends Variables> {\n query: TypedDocumentNode<TResult, TVariables>\n shopFqdn: string\n token: string\n unauthorizedHandler: UnauthorizedHandler\n variables?: TVariables\n}\n/**\n * Executes an org-scoped GraphQL query against the App Management API.\n * Uses typed documents.\n *\n * @param options - The options for the request.\n * @returns The response of the query of generic type <T>.\n */\nexport async function appDevRequestDoc<TResult, TVariables extends Variables>(\n options: AppDevRequestOptions<TResult, TVariables>,\n): Promise<TResult> {\n const api = 'App Dev'\n const normalizedShopFqdn = await normalizeStoreFqdn(options.shopFqdn)\n const fqdn = await appDevFqdn(normalizedShopFqdn)\n const url = `https://${fqdn}/app_dev/unstable/graphql.json`\n\n const addedHeaders = serviceEnvironment() === 'local' ? {'x-forwarded-host': normalizedShopFqdn} : undefined\n\n const result = limiter.schedule<TResult>(() =>\n graphqlRequestDoc<TResult, TVariables>({\n query: options.query,\n api,\n url,\n token: options.token,\n addedHeaders,\n variables: options.variables,\n unauthorizedHandler: options.unauthorizedHandler,\n }),\n )\n\n return result\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { CacheOptions, GraphQLResponse } from './graphql.js';
1
+ import { CacheOptions, GraphQLResponse, UnauthorizedHandler } from './graphql.js';
2
2
  import { RequestModeInput } from '../http.js';
3
3
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
4
4
  import { Variables } from 'graphql-request';
@@ -13,17 +13,30 @@ export interface RequestOptions {
13
13
  requestMode: RequestModeInput;
14
14
  }
15
15
  /**
16
- * Executes an org-scoped GraphQL query against the App Management API. Uses typed documents.
17
- *
18
16
  * @param orgId - The organization ID.
19
17
  * @param query - GraphQL query to execute.
20
18
  * @param token - Partners token.
21
19
  * @param variables - GraphQL variables to pass to the query.
22
20
  * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.
23
21
  * @param requestOptions - Preferred behaviour for the request.
22
+ * @param unauthorizedHandler - Optional handler for unauthorized requests.
23
+ */
24
+ export interface AppManagementRequestOptions<TResult, TVariables extends Variables> {
25
+ organizationId: string;
26
+ query: TypedDocumentNode<TResult, TVariables>;
27
+ token: string;
28
+ variables?: TVariables;
29
+ cacheOptions?: CacheOptions;
30
+ requestOptions?: RequestOptions;
31
+ unauthorizedHandler: UnauthorizedHandler;
32
+ }
33
+ /**
34
+ * Executes an org-scoped GraphQL query against the App Management API. Uses typed documents.
35
+ *
36
+ * @param options - The options for the request.
24
37
  * @returns The response of the query of generic type <T>.
25
38
  */
26
- export declare function appManagementRequestDoc<TResult, TVariables extends Variables>(orgId: string, query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, cacheOptions?: CacheOptions, requestOptions?: RequestOptions): Promise<TResult>;
39
+ export declare function appManagementRequestDoc<TResult, TVariables extends Variables>(options: AppManagementRequestOptions<TResult, TVariables>): Promise<TResult>;
27
40
  /**
28
41
  * Sets the next deprecation date from [GraphQL response extensions](https://www.apollographql.com/docs/resources/graphql-glossary/#extensions)
29
42
  * if `response.extensions.deprecations` objects contain a `supportedUntilDate` (ISO 8601-formatted string).
@@ -33,24 +33,20 @@ export const appManagementAppLogsUrl = async (organizationId, cursor, filters) =
33
33
  /**
34
34
  * Executes an org-scoped GraphQL query against the App Management API. Uses typed documents.
35
35
  *
36
- * @param orgId - The organization ID.
37
- * @param query - GraphQL query to execute.
38
- * @param token - Partners token.
39
- * @param variables - GraphQL variables to pass to the query.
40
- * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.
41
- * @param requestOptions - Preferred behaviour for the request.
36
+ * @param options - The options for the request.
42
37
  * @returns The response of the query of generic type <T>.
43
38
  */
44
- export async function appManagementRequestDoc(orgId, query, token, variables, cacheOptions, requestOptions) {
39
+ export async function appManagementRequestDoc(options) {
45
40
  // For app management, we need to cache the response based on the orgId.
46
- const cacheExtraKey = (cacheOptions?.cacheExtraKey ?? '') + orgId;
47
- const newCacheOptions = cacheOptions ? { ...cacheOptions, cacheExtraKey } : undefined;
41
+ const cacheExtraKey = (options.cacheOptions?.cacheExtraKey ?? '') + options.organizationId;
42
+ const newCacheOptions = options.cacheOptions ? { ...options.cacheOptions, cacheExtraKey } : undefined;
48
43
  const result = limiter.schedule(async () => graphqlRequestDoc({
49
- ...(await setupRequest(orgId, token)),
50
- query,
51
- variables,
44
+ ...(await setupRequest(options.organizationId, options.token)),
45
+ query: options.query,
46
+ variables: options.variables,
52
47
  cacheOptions: newCacheOptions,
53
- preferredBehaviour: requestOptions?.requestMode,
48
+ preferredBehaviour: options.requestOptions?.requestMode,
49
+ unauthorizedHandler: options.unauthorizedHandler,
54
50
  }));
55
51
  return result;
56
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"app-management.js","sourceRoot":"","sources":["../../../../src/public/node/api/app-management.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,iBAAiB,EAAC,MAAM,cAAc,CAAA;AAC7E,OAAO,EAAC,+BAA+B,EAAC,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAC,iBAAiB,EAAC,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAC,sBAAsB,EAAC,MAAM,qDAAqD,CAAA;AAC1F,OAAO,EAAC,YAAY,EAAC,MAAM,sCAAsC,CAAA;AAEjE,OAAO,UAAU,MAAM,YAAY,CAAA;AAInC,sEAAsE;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EnF,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAU,KAAK,IAAI,EAAE,CAClD,iBAAiB,CAAsB;QACrC,GAAG,CAAC,MAAM,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACrC,KAAK;QACL,SAAS;QACT,YAAY,EAAE,eAAe;QAC7B,kBAAkB,EAAE,cAAc,EAAE,WAAW;KAChD,CAAC,CACH,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAUD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAI,QAA4B;IAChE,IAAI,CAAC,QAAQ,CAAC,UAAU;QAAE,OAAM;IAEhC,MAAM,gBAAgB,GAAW,EAAE,CAAA;IACnC,KAAK,MAAM,WAAW,IAAK,QAAQ,CAAC,UAA+B,CAAC,YAAY,EAAE,CAAC;QACjF,IAAI,WAAW,CAAC,kBAAkB,EAAE,CAAC;YACnC,gBAAgB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAA;QACjE,CAAC;IACH,CAAC;IAED,sBAAsB,CAAC,gBAAgB,CAAC,CAAA;AAC1C,CAAC","sourcesContent":["import {CacheOptions, GraphQLResponse, graphqlRequestDoc} from './graphql.js'\nimport {addCursorAndFiltersToAppLogsUrl} from './utilities.js'\nimport {appManagementFqdn} from '../context/fqdn.js'\nimport {setNextDeprecationDate} from '../../../private/node/context/deprecations-store.js'\nimport {buildHeaders} from '../../../private/node/api/headers.js'\nimport {RequestModeInput} from '../http.js'\nimport Bottleneck from 'bottleneck'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\nimport {Variables} from 'graphql-request'\n\n// API Rate limiter for partners API (Limit is 10 requests per second)\n// Jobs are launched every 150ms to add an extra 50ms margin per request.\n// Only 10 requests can be executed concurrently.\nconst limiter = new Bottleneck({\n minTime: 150,\n maxConcurrent: 10,\n})\n\nasync function setupRequest(orgId: string, token: string) {\n const api = 'App Management'\n const fqdn = await appManagementFqdn()\n const url = `https://${fqdn}/app_management/unstable/organizations/${orgId}/graphql.json`\n return {\n token,\n api,\n url,\n responseOptions: {onResponse: handleDeprecations},\n }\n}\n\nexport const appManagementHeaders = (token: string): {[key: string]: string} => {\n return buildHeaders(token)\n}\n\nexport const appManagementAppLogsUrl = async (\n organizationId: string,\n cursor?: string,\n filters?: {\n status?: string\n source?: string\n },\n): Promise<string> => {\n const fqdn = await appManagementFqdn()\n const url = `https://${fqdn}/app_management/unstable/organizations/${organizationId}/app_logs/poll`\n return addCursorAndFiltersToAppLogsUrl(url, cursor, filters)\n}\n\nexport interface RequestOptions {\n requestMode: RequestModeInput\n}\n\n/**\n * Executes an org-scoped GraphQL query against the App Management API. Uses typed documents.\n *\n * @param orgId - The organization ID.\n * @param query - GraphQL query to execute.\n * @param token - Partners token.\n * @param variables - GraphQL variables to pass to the query.\n * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.\n * @param requestOptions - Preferred behaviour for the request.\n * @returns The response of the query of generic type <T>.\n */\nexport async function appManagementRequestDoc<TResult, TVariables extends Variables>(\n orgId: string,\n query: TypedDocumentNode<TResult, TVariables>,\n token: string,\n variables?: TVariables,\n cacheOptions?: CacheOptions,\n requestOptions?: RequestOptions,\n): Promise<TResult> {\n // For app management, we need to cache the response based on the orgId.\n const cacheExtraKey = (cacheOptions?.cacheExtraKey ?? '') + orgId\n const newCacheOptions = cacheOptions ? {...cacheOptions, cacheExtraKey} : undefined\n\n const result = limiter.schedule<TResult>(async () =>\n graphqlRequestDoc<TResult, TVariables>({\n ...(await setupRequest(orgId, token)),\n query,\n variables,\n cacheOptions: newCacheOptions,\n preferredBehaviour: requestOptions?.requestMode,\n }),\n )\n\n return result\n}\n\ninterface Deprecation {\n supportedUntilDate?: string\n}\n\ninterface WithDeprecations {\n deprecations: Deprecation[]\n}\n\n/**\n * Sets the next deprecation date from [GraphQL response extensions](https://www.apollographql.com/docs/resources/graphql-glossary/#extensions)\n * if `response.extensions.deprecations` objects contain a `supportedUntilDate` (ISO 8601-formatted string).\n *\n * @param response - The response of the query.\n */\nexport function handleDeprecations<T>(response: GraphQLResponse<T>): void {\n if (!response.extensions) return\n\n const deprecationDates: Date[] = []\n for (const deprecation of (response.extensions as WithDeprecations).deprecations) {\n if (deprecation.supportedUntilDate) {\n deprecationDates.push(new Date(deprecation.supportedUntilDate))\n }\n }\n\n setNextDeprecationDate(deprecationDates)\n}\n"]}
1
+ {"version":3,"file":"app-management.js","sourceRoot":"","sources":["../../../../src/public/node/api/app-management.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,iBAAiB,EAAC,MAAM,cAAc,CAAA;AAClG,OAAO,EAAC,+BAA+B,EAAC,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAC,iBAAiB,EAAC,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAC,sBAAsB,EAAC,MAAM,qDAAqD,CAAA;AAC1F,OAAO,EAAC,YAAY,EAAC,MAAM,sCAAsC,CAAA;AAEjE,OAAO,UAAU,MAAM,YAAY,CAAA;AAInC,sEAAsE;AACtE,yEAAyE;AACzE,iDAAiD;AACjD,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC;IAC7B,OAAO,EAAE,GAAG;IACZ,aAAa,EAAE,EAAE;CAClB,CAAC,CAAA;AAEF,KAAK,UAAU,YAAY,CAAC,KAAa,EAAE,KAAa;IACtD,MAAM,GAAG,GAAG,gBAAgB,CAAA;IAC5B,MAAM,IAAI,GAAG,MAAM,iBAAiB,EAAE,CAAA;IACtC,MAAM,GAAG,GAAG,WAAW,IAAI,0CAA0C,KAAK,eAAe,CAAA;IACzF,OAAO;QACL,KAAK;QACL,GAAG;QACH,GAAG;QACH,eAAe,EAAE,EAAC,UAAU,EAAE,kBAAkB,EAAC;KAClD,CAAA;AACH,CAAC;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAA2B,EAAE;IAC7E,OAAO,YAAY,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC,CAAA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,QAAQ,CAAC,UAA+B,CAAC,YAAY,EAAE,CAAC;QACjF,IAAI,WAAW,CAAC,kBAAkB,EAAE,CAAC;YACnC,gBAAgB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAA;QACjE,CAAC;IACH,CAAC;IAED,sBAAsB,CAAC,gBAAgB,CAAC,CAAA;AAC1C,CAAC","sourcesContent":["import {CacheOptions, GraphQLResponse, UnauthorizedHandler, graphqlRequestDoc} from './graphql.js'\nimport {addCursorAndFiltersToAppLogsUrl} from './utilities.js'\nimport {appManagementFqdn} from '../context/fqdn.js'\nimport {setNextDeprecationDate} from '../../../private/node/context/deprecations-store.js'\nimport {buildHeaders} from '../../../private/node/api/headers.js'\nimport {RequestModeInput} from '../http.js'\nimport Bottleneck from 'bottleneck'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\nimport {Variables} from 'graphql-request'\n\n// API Rate limiter for partners API (Limit is 10 requests per second)\n// Jobs are launched every 150ms to add an extra 50ms margin per request.\n// Only 10 requests can be executed concurrently.\nconst limiter = new Bottleneck({\n minTime: 150,\n maxConcurrent: 10,\n})\n\nasync function setupRequest(orgId: string, token: string) {\n const api = 'App Management'\n const fqdn = await appManagementFqdn()\n const url = `https://${fqdn}/app_management/unstable/organizations/${orgId}/graphql.json`\n return {\n token,\n api,\n url,\n responseOptions: {onResponse: handleDeprecations},\n }\n}\n\nexport const appManagementHeaders = (token: string): {[key: string]: string} => {\n return buildHeaders(token)\n}\n\nexport const appManagementAppLogsUrl = async (\n organizationId: string,\n cursor?: string,\n filters?: {\n status?: string\n source?: string\n },\n): Promise<string> => {\n const fqdn = await appManagementFqdn()\n const url = `https://${fqdn}/app_management/unstable/organizations/${organizationId}/app_logs/poll`\n return addCursorAndFiltersToAppLogsUrl(url, cursor, filters)\n}\n\nexport interface RequestOptions {\n requestMode: RequestModeInput\n}\n\n/**\n * @param orgId - The organization ID.\n * @param query - GraphQL query to execute.\n * @param token - Partners token.\n * @param variables - GraphQL variables to pass to the query.\n * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.\n * @param requestOptions - Preferred behaviour for the request.\n * @param unauthorizedHandler - Optional handler for unauthorized requests.\n */\nexport interface AppManagementRequestOptions<TResult, TVariables extends Variables> {\n organizationId: string\n query: TypedDocumentNode<TResult, TVariables>\n token: string\n variables?: TVariables\n cacheOptions?: CacheOptions\n requestOptions?: RequestOptions\n unauthorizedHandler: UnauthorizedHandler\n}\n\n/**\n * Executes an org-scoped GraphQL query against the App Management API. Uses typed documents.\n *\n * @param options - The options for the request.\n * @returns The response of the query of generic type <T>.\n */\nexport async function appManagementRequestDoc<TResult, TVariables extends Variables>(\n options: AppManagementRequestOptions<TResult, TVariables>,\n): Promise<TResult> {\n // For app management, we need to cache the response based on the orgId.\n const cacheExtraKey = (options.cacheOptions?.cacheExtraKey ?? '') + options.organizationId\n const newCacheOptions = options.cacheOptions ? {...options.cacheOptions, cacheExtraKey} : undefined\n\n const result = limiter.schedule<TResult>(async () =>\n graphqlRequestDoc<TResult, TVariables>({\n ...(await setupRequest(options.organizationId, options.token)),\n query: options.query,\n variables: options.variables,\n cacheOptions: newCacheOptions,\n preferredBehaviour: options.requestOptions?.requestMode,\n unauthorizedHandler: options.unauthorizedHandler,\n }),\n )\n\n return result\n}\n\ninterface Deprecation {\n supportedUntilDate?: string\n}\n\ninterface WithDeprecations {\n deprecations: Deprecation[]\n}\n\n/**\n * Sets the next deprecation date from [GraphQL response extensions](https://www.apollographql.com/docs/resources/graphql-glossary/#extensions)\n * if `response.extensions.deprecations` objects contain a `supportedUntilDate` (ISO 8601-formatted string).\n *\n * @param response - The response of the query.\n */\nexport function handleDeprecations<T>(response: GraphQLResponse<T>): void {\n if (!response.extensions) return\n\n const deprecationDates: Date[] = []\n for (const deprecation of (response.extensions as WithDeprecations).deprecations) {\n if (deprecation.supportedUntilDate) {\n deprecationDates.push(new Date(deprecation.supportedUntilDate))\n }\n }\n\n setNextDeprecationDate(deprecationDates)\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { CacheOptions, Exact, GraphQLVariables } from './graphql.js';
1
+ import { CacheOptions, GraphQLVariables, UnauthorizedHandler } from './graphql.js';
2
2
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
3
3
  import { Variables } from 'graphql-request';
4
4
  /**
@@ -12,34 +12,46 @@ import { Variables } from 'graphql-request';
12
12
  */
13
13
  export declare function businessPlatformRequest<T>(query: string, token: string, variables?: GraphQLVariables, cacheOptions?: CacheOptions): Promise<T>;
14
14
  /**
15
- * Executes a GraphQL query against the Business Platform Destinations API. Uses typed documents.
16
- *
17
15
  * @param query - GraphQL query to execute.
18
16
  * @param token - Business Platform token.
19
17
  * @param variables - GraphQL variables to pass to the query.
20
18
  * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.
19
+ */
20
+ export interface BusinessPlatformRequestOptions<TResult, TVariables extends Variables> {
21
+ query: TypedDocumentNode<TResult, TVariables>;
22
+ token: string;
23
+ variables?: TVariables;
24
+ cacheOptions?: CacheOptions;
25
+ unauthorizedHandler: UnauthorizedHandler;
26
+ }
27
+ /**
28
+ * Executes a GraphQL query against the Business Platform Destinations API. Uses typed documents.
29
+ *
30
+ * @param options - The options for the request.
21
31
  * @returns The response of the query of generic type <TResult>.
22
32
  */
23
- export declare function businessPlatformRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, cacheOptions?: CacheOptions): Promise<TResult>;
33
+ export declare function businessPlatformRequestDoc<TResult, TVariables extends Variables>(options: BusinessPlatformRequestOptions<TResult, TVariables>): Promise<TResult>;
34
+ export interface BusinessPlatformOrganizationsRequestNonTypedOptions {
35
+ query: string;
36
+ token: string;
37
+ organizationId: string;
38
+ unauthorizedHandler: UnauthorizedHandler;
39
+ variables?: GraphQLVariables;
40
+ }
24
41
  /**
25
42
  * Executes a GraphQL query against the Business Platform Organizations API.
26
43
  *
27
- * @param query - GraphQL query to execute.
28
- * @param token - Business Platform token.
29
- * @param organizationId - Organization ID as a numeric (non-GID) value.
30
- * @param variables - GraphQL variables to pass to the query.
44
+ * @param options - The options for the request.
31
45
  * @returns The response of the query of generic type <T>.
32
46
  */
33
- export declare function businessPlatformOrganizationsRequest<T>(query: string, token: string, organizationId: string, variables?: GraphQLVariables): Promise<T>;
47
+ export declare function businessPlatformOrganizationsRequest<T>(options: BusinessPlatformOrganizationsRequestNonTypedOptions): Promise<T>;
48
+ export interface BusinessPlatformOrganizationsRequestOptions<TResult, TVariables extends Variables> extends BusinessPlatformRequestOptions<TResult, TVariables> {
49
+ organizationId: string;
50
+ }
34
51
  /**
35
52
  * Executes a GraphQL query against the Business Platform Organizations API. Uses typed documents.
36
53
  *
37
- * @param query - GraphQL query to execute.
38
- * @param token - Business Platform token.
39
- * @param organizationId - Organization ID as a numeric value.
40
- * @param variables - GraphQL variables to pass to the query.
54
+ * @param options - The options for the request.
41
55
  * @returns The response of the query of generic type <T>.
42
56
  */
43
- export declare function businessPlatformOrganizationsRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables> | TypedDocumentNode<TResult, Exact<{
44
- [key: string]: never;
45
- }>>, token: string, organizationId: string, variables?: TVariables): Promise<TResult>;
57
+ export declare function businessPlatformOrganizationsRequestDoc<TResult, TVariables extends Variables>(options: BusinessPlatformOrganizationsRequestOptions<TResult, TVariables>): Promise<TResult>;
@@ -37,18 +37,16 @@ export async function businessPlatformRequest(query, token, variables, cacheOpti
37
37
  /**
38
38
  * Executes a GraphQL query against the Business Platform Destinations API. Uses typed documents.
39
39
  *
40
- * @param query - GraphQL query to execute.
41
- * @param token - Business Platform token.
42
- * @param variables - GraphQL variables to pass to the query.
43
- * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.
40
+ * @param options - The options for the request.
44
41
  * @returns The response of the query of generic type <TResult>.
45
42
  */
46
- export async function businessPlatformRequestDoc(query, token, variables, cacheOptions) {
43
+ export async function businessPlatformRequestDoc(options) {
47
44
  return graphqlRequestDoc({
48
- ...(await setupRequest(token)),
49
- query,
50
- variables,
51
- cacheOptions,
45
+ ...(await setupRequest(options.token)),
46
+ query: options.query,
47
+ variables: options.variables,
48
+ cacheOptions: options.cacheOptions,
49
+ unauthorizedHandler: options.unauthorizedHandler,
52
50
  });
53
51
  }
54
52
  /**
@@ -71,33 +69,29 @@ async function setupOrganizationsRequest(token, organizationId) {
71
69
  /**
72
70
  * Executes a GraphQL query against the Business Platform Organizations API.
73
71
  *
74
- * @param query - GraphQL query to execute.
75
- * @param token - Business Platform token.
76
- * @param organizationId - Organization ID as a numeric (non-GID) value.
77
- * @param variables - GraphQL variables to pass to the query.
72
+ * @param options - The options for the request.
78
73
  * @returns The response of the query of generic type <T>.
79
74
  */
80
- export async function businessPlatformOrganizationsRequest(query, token, organizationId, variables) {
75
+ export async function businessPlatformOrganizationsRequest(options) {
81
76
  return graphqlRequest({
82
- query,
83
- ...(await setupOrganizationsRequest(token, organizationId)),
84
- variables,
77
+ query: options.query,
78
+ ...(await setupOrganizationsRequest(options.token, options.organizationId)),
79
+ variables: options.variables,
80
+ unauthorizedHandler: options.unauthorizedHandler,
85
81
  });
86
82
  }
87
83
  /**
88
84
  * Executes a GraphQL query against the Business Platform Organizations API. Uses typed documents.
89
85
  *
90
- * @param query - GraphQL query to execute.
91
- * @param token - Business Platform token.
92
- * @param organizationId - Organization ID as a numeric value.
93
- * @param variables - GraphQL variables to pass to the query.
86
+ * @param options - The options for the request.
94
87
  * @returns The response of the query of generic type <T>.
95
88
  */
96
- export async function businessPlatformOrganizationsRequestDoc(query, token, organizationId, variables) {
89
+ export async function businessPlatformOrganizationsRequestDoc(options) {
97
90
  return graphqlRequestDoc({
98
- query,
99
- ...(await setupOrganizationsRequest(token, organizationId)),
100
- variables,
91
+ query: options.query,
92
+ ...(await setupOrganizationsRequest(options.token, options.organizationId)),
93
+ variables: options.variables,
94
+ unauthorizedHandler: options.unauthorizedHandler,
101
95
  });
102
96
  }
103
97
  //# sourceMappingURL=business-platform.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"business-platform.js","sourceRoot":"","sources":["../../../../src/public/node/api/business-platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,cAAc,EAAE,iBAAiB,EAAC,MAAM,cAAc,CAAA;AACrG,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAA;AAChD,OAAO,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAA;AAIvD;;;;GAIG;AACH,KAAK,UAAU,YAAY,CAAC,KAAa;IACvC,MAAM,GAAG,GAAG,kBAAkB,CAAA;IAC9B,MAAM,IAAI,GAAG,MAAM,oBAAoB,EAAE,CAAA;IACzC,MAAM,GAAG,GAAG,WAAW,IAAI,mCAAmC,CAAA;IAC9D,OAAO;QACL,KAAK;QACL,GAAG;QACH,GAAG;QACH,eAAe,EAAE,EAAC,UAAU,EAAE,kBAAkB,EAAC;KAClD,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAa,EACb,KAAa,EACb,SAA4B,EAC5B,YAA2B;IAE3B,OAAO,cAAc,CAAI;QACvB,GAAG,CAAC,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;QAC9B,KAAK;QACL,SAAS;QACT,YAAY;KACb,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,KAA6C,EAC7C,KAAa,EACb,SAAsB,EACtB,YAA2B;IAE3B,OAAO,iBAAiB,CAAsB;QAC5C,GAAG,CAAC,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;QAC9B,KAAK;QACL,SAAS;QACT,YAAY;KACb,CAAC,CAAA;AACJ,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,yBAAyB,CAAC,KAAa,EAAE,cAAsB;IAC5E,MAAM,GAAG,GAAG,kBAAkB,CAAA;IAC9B,MAAM,IAAI,GAAG,MAAM,oBAAoB,EAAE,CAAA;IACzC,MAAM,GAAG,GAAG,WAAW,IAAI,4CAA4C,cAAc,UAAU,CAAA;IAC/F,OAAO;QACL,KAAK;QACL,GAAG;QACH,GAAG;QACH,eAAe,EAAE,EAAC,UAAU,EAAE,kBAAkB,EAAC;KAClD,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,oCAAoC,CACxD,KAAa,EACb,KAAa,EACb,cAAsB,EACtB,SAA4B;IAE5B,OAAO,cAAc,CAAI;QACvB,KAAK;QACL,GAAG,CAAC,MAAM,yBAAyB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;QAC3D,SAAS;KACV,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,uCAAuC,CAC3D,KAAyG,EACzG,KAAa,EACb,cAAsB,EACtB,SAAsB;IAEtB,OAAO,iBAAiB,CAAsB;QAC5C,KAAK;QACL,GAAG,CAAC,MAAM,yBAAyB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;QAC3D,SAAS;KACV,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {CacheOptions, Exact, GraphQLVariables, graphqlRequest, graphqlRequestDoc} from './graphql.js'\nimport {handleDeprecations} from './partners.js'\nimport {businessPlatformFqdn} from '../context/fqdn.js'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\nimport {Variables} from 'graphql-request'\n\n/**\n * Sets up the request to the Business Platform Destinations API.\n *\n * @param token - Business Platform token.\n */\nasync function setupRequest(token: string) {\n const api = 'BusinessPlatform'\n const fqdn = await businessPlatformFqdn()\n const url = `https://${fqdn}/destinations/api/2020-07/graphql`\n return {\n token,\n api,\n url,\n responseOptions: {onResponse: handleDeprecations},\n }\n}\n\n/**\n * Executes a GraphQL query against the Business Platform Destinations API.\n *\n * @param query - GraphQL query to execute.\n * @param token - Business Platform token.\n * @param variables - GraphQL variables to pass to the query.\n * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.\n * @returns The response of the query of generic type <T>.\n */\nexport async function businessPlatformRequest<T>(\n query: string,\n token: string,\n variables?: GraphQLVariables,\n cacheOptions?: CacheOptions,\n): Promise<T> {\n return graphqlRequest<T>({\n ...(await setupRequest(token)),\n query,\n variables,\n cacheOptions,\n })\n}\n\n/**\n * Executes a GraphQL query against the Business Platform Destinations API. Uses typed documents.\n *\n * @param query - GraphQL query to execute.\n * @param token - Business Platform token.\n * @param variables - GraphQL variables to pass to the query.\n * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.\n * @returns The response of the query of generic type <TResult>.\n */\nexport async function businessPlatformRequestDoc<TResult, TVariables extends Variables>(\n query: TypedDocumentNode<TResult, TVariables>,\n token: string,\n variables?: TVariables,\n cacheOptions?: CacheOptions,\n): Promise<TResult> {\n return graphqlRequestDoc<TResult, TVariables>({\n ...(await setupRequest(token)),\n query,\n variables,\n cacheOptions,\n })\n}\n\n/**\n * Sets up the request to the Business Platform Organizations API.\n *\n * @param token - Business Platform token.\n * @param organizationId - Organization ID as a numeric (non-GID) value.\n */\nasync function setupOrganizationsRequest(token: string, organizationId: string) {\n const api = 'BusinessPlatform'\n const fqdn = await businessPlatformFqdn()\n const url = `https://${fqdn}/organizations/api/unstable/organization/${organizationId}/graphql`\n return {\n token,\n api,\n url,\n responseOptions: {onResponse: handleDeprecations},\n }\n}\n\n/**\n * Executes a GraphQL query against the Business Platform Organizations API.\n *\n * @param query - GraphQL query to execute.\n * @param token - Business Platform token.\n * @param organizationId - Organization ID as a numeric (non-GID) value.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function businessPlatformOrganizationsRequest<T>(\n query: string,\n token: string,\n organizationId: string,\n variables?: GraphQLVariables,\n): Promise<T> {\n return graphqlRequest<T>({\n query,\n ...(await setupOrganizationsRequest(token, organizationId)),\n variables,\n })\n}\n\n/**\n * Executes a GraphQL query against the Business Platform Organizations API. Uses typed documents.\n *\n * @param query - GraphQL query to execute.\n * @param token - Business Platform token.\n * @param organizationId - Organization ID as a numeric value.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function businessPlatformOrganizationsRequestDoc<TResult, TVariables extends Variables>(\n query: TypedDocumentNode<TResult, TVariables> | TypedDocumentNode<TResult, Exact<{[key: string]: never}>>,\n token: string,\n organizationId: string,\n variables?: TVariables,\n): Promise<TResult> {\n return graphqlRequestDoc<TResult, TVariables>({\n query,\n ...(await setupOrganizationsRequest(token, organizationId)),\n variables,\n })\n}\n"]}
1
+ {"version":3,"file":"business-platform.js","sourceRoot":"","sources":["../../../../src/public/node/api/business-platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsD,cAAc,EAAE,iBAAiB,EAAC,MAAM,cAAc,CAAA;AACnH,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAA;AAChD,OAAO,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAA;AAIvD;;;;GAIG;AACH,KAAK,UAAU,YAAY,CAAC,KAAa;IACvC,MAAM,GAAG,GAAG,kBAAkB,CAAA;IAC9B,MAAM,IAAI,GAAG,MAAM,oBAAoB,EAAE,CAAA;IACzC,MAAM,GAAG,GAAG,WAAW,IAAI,mCAAmC,CAAA;IAC9D,OAAO;QACL,KAAK;QACL,GAAG;QACH,GAAG;QACH,eAAe,EAAE,EAAC,UAAU,EAAE,kBAAkB,EAAC;KAClD,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAa,EACb,KAAa,EACb,SAA4B,EAC5B,YAA2B;IAE3B,OAAO,cAAc,CAAI;QACvB,GAAG,CAAC,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;QAC9B,KAAK;QACL,SAAS;QACT,YAAY;KACb,CAAC,CAAA;AACJ,CAAC;AAgBD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAA4D;IAE5D,OAA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,mBAAmB;KACjD,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {CacheOptions, GraphQLVariables, UnauthorizedHandler, graphqlRequest, graphqlRequestDoc} from './graphql.js'\nimport {handleDeprecations} from './partners.js'\nimport {businessPlatformFqdn} from '../context/fqdn.js'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\nimport {Variables} from 'graphql-request'\n\n/**\n * Sets up the request to the Business Platform Destinations API.\n *\n * @param token - Business Platform token.\n */\nasync function setupRequest(token: string) {\n const api = 'BusinessPlatform'\n const fqdn = await businessPlatformFqdn()\n const url = `https://${fqdn}/destinations/api/2020-07/graphql`\n return {\n token,\n api,\n url,\n responseOptions: {onResponse: handleDeprecations},\n }\n}\n\n/**\n * Executes a GraphQL query against the Business Platform Destinations API.\n *\n * @param query - GraphQL query to execute.\n * @param token - Business Platform token.\n * @param variables - GraphQL variables to pass to the query.\n * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.\n * @returns The response of the query of generic type <T>.\n */\nexport async function businessPlatformRequest<T>(\n query: string,\n token: string,\n variables?: GraphQLVariables,\n cacheOptions?: CacheOptions,\n): Promise<T> {\n return graphqlRequest<T>({\n ...(await setupRequest(token)),\n query,\n variables,\n cacheOptions,\n })\n}\n\n/**\n * @param query - GraphQL query to execute.\n * @param token - Business Platform token.\n * @param variables - GraphQL variables to pass to the query.\n * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.\n */\nexport interface BusinessPlatformRequestOptions<TResult, TVariables extends Variables> {\n query: TypedDocumentNode<TResult, TVariables>\n token: string\n variables?: TVariables\n cacheOptions?: CacheOptions\n unauthorizedHandler: UnauthorizedHandler\n}\n\n/**\n * Executes a GraphQL query against the Business Platform Destinations API. Uses typed documents.\n *\n * @param options - The options for the request.\n * @returns The response of the query of generic type <TResult>.\n */\nexport async function businessPlatformRequestDoc<TResult, TVariables extends Variables>(\n options: BusinessPlatformRequestOptions<TResult, TVariables>,\n): Promise<TResult> {\n return graphqlRequestDoc<TResult, TVariables>({\n ...(await setupRequest(options.token)),\n query: options.query,\n variables: options.variables,\n cacheOptions: options.cacheOptions,\n unauthorizedHandler: options.unauthorizedHandler,\n })\n}\n\n/**\n * Sets up the request to the Business Platform Organizations API.\n *\n * @param token - Business Platform token.\n * @param organizationId - Organization ID as a numeric (non-GID) value.\n */\nasync function setupOrganizationsRequest(token: string, organizationId: string) {\n const api = 'BusinessPlatform'\n const fqdn = await businessPlatformFqdn()\n const url = `https://${fqdn}/organizations/api/unstable/organization/${organizationId}/graphql`\n return {\n token,\n api,\n url,\n responseOptions: {onResponse: handleDeprecations},\n }\n}\n\nexport interface BusinessPlatformOrganizationsRequestNonTypedOptions {\n query: string\n token: string\n organizationId: string\n unauthorizedHandler: UnauthorizedHandler\n variables?: GraphQLVariables\n}\n\n/**\n * Executes a GraphQL query against the Business Platform Organizations API.\n *\n * @param options - The options for the request.\n * @returns The response of the query of generic type <T>.\n */\nexport async function businessPlatformOrganizationsRequest<T>(\n options: BusinessPlatformOrganizationsRequestNonTypedOptions,\n): Promise<T> {\n return graphqlRequest<T>({\n query: options.query,\n ...(await setupOrganizationsRequest(options.token, options.organizationId)),\n variables: options.variables,\n unauthorizedHandler: options.unauthorizedHandler,\n })\n}\n\nexport interface BusinessPlatformOrganizationsRequestOptions<TResult, TVariables extends Variables>\n extends BusinessPlatformRequestOptions<TResult, TVariables> {\n organizationId: string\n}\n\n/**\n * Executes a GraphQL query against the Business Platform Organizations API. Uses typed documents.\n *\n * @param options - The options for the request.\n * @returns The response of the query of generic type <T>.\n */\nexport async function businessPlatformOrganizationsRequestDoc<TResult, TVariables extends Variables>(\n options: BusinessPlatformOrganizationsRequestOptions<TResult, TVariables>,\n): Promise<TResult> {\n return graphqlRequestDoc<TResult, TVariables>({\n query: options.query,\n ...(await setupOrganizationsRequest(options.token, options.organizationId)),\n variables: options.variables,\n unauthorizedHandler: options.unauthorizedHandler,\n })\n}\n"]}
@@ -1,13 +1,26 @@
1
+ import { UnauthorizedHandler } from './graphql.js';
1
2
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
2
3
  import { Variables } from 'graphql-request';
3
4
  /**
4
- * Executes a rate-limited GraphQL request against the App Management Functions API.
5
- *
6
5
  * @param orgId - Organization identifier.
7
6
  * @param query - Typed GraphQL document node.
8
7
  * @param token - Authentication token.
9
8
  * @param appId - App identifier.
10
9
  * @param variables - Optional query variables.
10
+ * @param unauthorizedHandler - Optional handler for unauthorized requests.
11
+ */
12
+ export interface FunctionsRequestOptions<TResult, TVariables extends Variables> {
13
+ organizationId: string;
14
+ query: TypedDocumentNode<TResult, TVariables>;
15
+ token: string;
16
+ appId: string;
17
+ unauthorizedHandler: UnauthorizedHandler;
18
+ variables?: TVariables;
19
+ }
20
+ /**
21
+ * Executes a rate-limited GraphQL request against the App Management Functions API.
22
+ *
23
+ * @param options - Request options.
11
24
  * @returns Promise resolving to the typed query result.
12
25
  */
13
- export declare function functionsRequestDoc<TResult, TVariables extends Variables>(orgId: string, query: TypedDocumentNode<TResult, TVariables>, token: string, appId: string, variables?: TVariables): Promise<TResult>;
26
+ export declare function functionsRequestDoc<TResult, TVariables extends Variables>(options: FunctionsRequestOptions<TResult, TVariables>): Promise<TResult>;
@@ -31,19 +31,16 @@ async function setupRequest(orgId, token, appId) {
31
31
  /**
32
32
  * Executes a rate-limited GraphQL request against the App Management Functions API.
33
33
  *
34
- * @param orgId - Organization identifier.
35
- * @param query - Typed GraphQL document node.
36
- * @param token - Authentication token.
37
- * @param appId - App identifier.
38
- * @param variables - Optional query variables.
34
+ * @param options - Request options.
39
35
  * @returns Promise resolving to the typed query result.
40
36
  */
41
- export async function functionsRequestDoc(orgId, query, token, appId, variables) {
37
+ export async function functionsRequestDoc(options) {
42
38
  const result = await limiter.schedule(async () => {
43
39
  return graphqlRequestDoc({
44
- ...(await setupRequest(orgId, token, appId)),
45
- query,
46
- variables,
40
+ ...(await setupRequest(options.organizationId, options.token, options.appId)),
41
+ query: options.query,
42
+ variables: options.variables,
43
+ unauthorizedHandler: options.unauthorizedHandler,
47
44
  });
48
45
  });
49
46
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../../src/public/node/api/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAC,kBAAkB,EAAC,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAC,iBAAiB,EAAC,MAAM,oBAAoB,CAAA;AAGpD,OAAO,UAAU,MAAM,YAAY,CAAA;AAEnC,sEAAsE;AACtE,yEAAyE;AACzE,iDAAiD;AACjD,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC;IAC7B,OAAO,EAAE,GAAG;IACZ,aAAa,EAAE,EAAE;CAClB,CAAC,CAAA;AAEF;;;;;;;GAOG;AACH,KAAK,UAAU,YAAY,CAAC,KAAa,EAAE,KAAa,EAAE,KAAa;IACrE,MAAM,GAAG,GAAG,WAAW,CAAA;IACvB,MAAM,IAAI,GAAG,MAAM,iBAAiB,EAAE,CAAA;IACtC,MAAM,GAAG,GAAG,WAAW,IAAI,qCAAqC,KAAK,IAAI,KAAK,UAAU,CAAA;IAExF,OAAO;QACL,KAAK;QACL,GAAG;QACH,GAAG;QACH,eAAe,EAAE,EAAC,UAAU,EAAE,kBAAkB,EAAC;KAClD,CAAA;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,KAAa,EACb,KAA6C,EAC7C,KAAa,EACb,KAAa,EACb,SAAsB;IAEtB,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAU,KAAK,IAAI,EAAE;QACxD,OAAO,iBAAiB,CAAsB;YAC5C,GAAG,CAAC,MAAM,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;YAC5C,KAAK;YACL,SAAS;SACV,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import {graphqlRequestDoc} from './graphql.js'\nimport {handleDeprecations} from './app-management.js'\nimport {appManagementFqdn} from '../context/fqdn.js'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\nimport {Variables} from 'graphql-request'\nimport Bottleneck from 'bottleneck'\n\n// API Rate limiter for partners API (Limit is 10 requests per second)\n// Jobs are launched every 150ms to add an extra 50ms margin per request.\n// Only 10 requests can be executed concurrently.\nconst limiter = new Bottleneck({\n minTime: 150,\n maxConcurrent: 10,\n})\n\n/**\n * Prepares the request configuration for the App Management Functions API.\n *\n * @param orgId - Organization identifier.\n * @param token - Authentication token.\n * @param appId - App identifier.\n * @returns Request configuration object.\n */\nasync function setupRequest(orgId: string, token: string, appId: string) {\n const api = 'Functions'\n const fqdn = await appManagementFqdn()\n const url = `https://${fqdn}/functions/unstable/organizations/${orgId}/${appId}/graphql`\n\n return {\n token,\n api,\n url,\n responseOptions: {onResponse: handleDeprecations},\n }\n}\n\n/**\n * Executes a rate-limited GraphQL request against the App Management Functions API.\n *\n * @param orgId - Organization identifier.\n * @param query - Typed GraphQL document node.\n * @param token - Authentication token.\n * @param appId - App identifier.\n * @param variables - Optional query variables.\n * @returns Promise resolving to the typed query result.\n */\nexport async function functionsRequestDoc<TResult, TVariables extends Variables>(\n orgId: string,\n query: TypedDocumentNode<TResult, TVariables>,\n token: string,\n appId: string,\n variables?: TVariables,\n): Promise<TResult> {\n const result = await limiter.schedule<TResult>(async () => {\n return graphqlRequestDoc<TResult, TVariables>({\n ...(await setupRequest(orgId, token, appId)),\n query,\n variables,\n })\n })\n\n return result\n}\n"]}
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../../src/public/node/api/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAsB,MAAM,cAAc,CAAA;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAC,iBAAiB,EAAC,MAAM,oBAAoB,CAAA;AAGpD,OAAO,UAAU,MAAM,YAAY,CAAA;AAEnC,sEAAsE;AACtE,yEAAyE;AACzE,iDAAiD;AACjD,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC;IAC7B,OAAO,EAAE,GAAG;IACZ,aAAa,EAAE,EAAE;CAClB,CAAC,CAAA;AAEF;;;;;;;GAOG;AACH,KAAK,UAAU,YAAY,CAAC,KAAa,EAAE,KAAa,EAAE,KAAa;IACrE,MAAM,GAAG,GAAG,WAAW,CAAA;IACvB,MAAM,IAAI,GAAG,MAAM,iBAAiB,EAAE,CAAA;IACtC,MAAM,GAAG,GAAG,WAAW,IAAI,qCAAqC,KAAK,IAAI,KAAK,UAAU,CAAA;IAExF,OAAO;QACL,KAAK;QACL,GAAG;QACH,GAAG;QACH,eAAe,EAAE,EAAC,UAAU,EAAE,kBAAkB,EAAC;KAClD,CAAA;AACH,CAAC;AAmBD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,OAAqD;IAErD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAU,KAAK,IAAI,EAAE;QACxD,OAAO,iBAAiB,CAAsB;YAC5C,GAAG,CAAC,MAAM,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;YAC7E,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;SACjD,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import {graphqlRequestDoc, UnauthorizedHandler} from './graphql.js'\nimport {handleDeprecations} from './app-management.js'\nimport {appManagementFqdn} from '../context/fqdn.js'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\nimport {Variables} from 'graphql-request'\nimport Bottleneck from 'bottleneck'\n\n// API Rate limiter for partners API (Limit is 10 requests per second)\n// Jobs are launched every 150ms to add an extra 50ms margin per request.\n// Only 10 requests can be executed concurrently.\nconst limiter = new Bottleneck({\n minTime: 150,\n maxConcurrent: 10,\n})\n\n/**\n * Prepares the request configuration for the App Management Functions API.\n *\n * @param orgId - Organization identifier.\n * @param token - Authentication token.\n * @param appId - App identifier.\n * @returns Request configuration object.\n */\nasync function setupRequest(orgId: string, token: string, appId: string) {\n const api = 'Functions'\n const fqdn = await appManagementFqdn()\n const url = `https://${fqdn}/functions/unstable/organizations/${orgId}/${appId}/graphql`\n\n return {\n token,\n api,\n url,\n responseOptions: {onResponse: handleDeprecations},\n }\n}\n\n/**\n * @param orgId - Organization identifier.\n * @param query - Typed GraphQL document node.\n * @param token - Authentication token.\n * @param appId - App identifier.\n * @param variables - Optional query variables.\n * @param unauthorizedHandler - Optional handler for unauthorized requests.\n */\nexport interface FunctionsRequestOptions<TResult, TVariables extends Variables> {\n organizationId: string\n query: TypedDocumentNode<TResult, TVariables>\n token: string\n appId: string\n unauthorizedHandler: UnauthorizedHandler\n variables?: TVariables\n}\n\n/**\n * Executes a rate-limited GraphQL request against the App Management Functions API.\n *\n * @param options - Request options.\n * @returns Promise resolving to the typed query result.\n */\nexport async function functionsRequestDoc<TResult, TVariables extends Variables>(\n options: FunctionsRequestOptions<TResult, TVariables>,\n): Promise<TResult> {\n const result = await limiter.schedule<TResult>(async () => {\n return graphqlRequestDoc<TResult, TVariables>({\n ...(await setupRequest(options.organizationId, options.token, options.appId)),\n query: options.query,\n variables: options.variables,\n unauthorizedHandler: options.unauthorizedHandler,\n })\n })\n\n return result\n}\n"]}
@@ -17,6 +17,14 @@ export interface CacheOptions {
17
17
  cacheExtraKey?: string;
18
18
  cacheStore?: LocalStorage<ConfSchema>;
19
19
  }
20
+ interface RefreshedTokenOnAuthorizedResponse {
21
+ token?: string;
22
+ }
23
+ export type RefreshTokenOnAuthorizedResponse = Promise<RefreshedTokenOnAuthorizedResponse>;
24
+ export interface UnauthorizedHandler {
25
+ type: 'token_refresh';
26
+ handler: () => RefreshTokenOnAuthorizedResponse;
27
+ }
20
28
  interface GraphQLRequestBaseOptions<TResult> {
21
29
  api: string;
22
30
  url: string;
@@ -31,7 +39,7 @@ interface GraphQLRequestBaseOptions<TResult> {
31
39
  export type GraphQLRequestOptions<T> = GraphQLRequestBaseOptions<T> & {
32
40
  query: RequestDocument;
33
41
  variables?: Variables;
34
- unauthorizedHandler?: () => Promise<void>;
42
+ unauthorizedHandler?: UnauthorizedHandler;
35
43
  requestBehaviour?: RequestModeInput;
36
44
  };
37
45
  export type GraphQLRequestDocOptions<TResult, TVariables> = GraphQLRequestBaseOptions<TResult> & {
@@ -39,7 +47,7 @@ export type GraphQLRequestDocOptions<TResult, TVariables> = GraphQLRequestBaseOp
39
47
  [key: string]: never;
40
48
  }>>;
41
49
  variables?: TVariables;
42
- unauthorizedHandler?: () => Promise<void>;
50
+ unauthorizedHandler?: UnauthorizedHandler;
43
51
  requestBehaviour?: RequestModeInput;
44
52
  };
45
53
  export interface GraphQLResponseOptions<T> {