Skip to content

Force all requests in app management to have an unauthorizedHandler #5886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 05-22-remove_refreshtokens
Choose a base branch
from

Conversation

isaacroldan
Copy link
Contributor

@isaacroldan isaacroldan commented May 22, 2025

WHY are these changes introduced?

This PR refactors the API request functions to use a more consistent object parameter pattern instead of positional parameters.

WHAT is this pull request doing?

Refactors API request functions across multiple client implementations to use a single object parameter pattern instead of multiple positional parameters. This change:

  • Converts functions like appManagementRequestDoc, businessPlatformRequest, and others to accept a single options object
  • Adds proper TypeScript interfaces for these request options
  • Centralizes the creation of unauthorized handlers
  • Makes parameter passing more explicit and less error-prone
  • Improves code readability by making it clear which parameters are being passed

How to test your changes?

Just use the CLI, no behavior change in this PR.

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor Author

isaacroldan commented May 22, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@isaacroldan isaacroldan force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch from 13dfe69 to 1ea4356 Compare May 22, 2025 13:28
@gonzaloriestra gonzaloriestra force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch from 1ea4356 to aca8ccc Compare May 22, 2025 14:12
@gonzaloriestra gonzaloriestra force-pushed the 05-22-remove_refreshtokens branch from 941f8b1 to 9bfc070 Compare May 22, 2025 14:12
@gonzaloriestra gonzaloriestra force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch from aca8ccc to 9ede791 Compare May 22, 2025 14:22
@gonzaloriestra gonzaloriestra force-pushed the 05-22-remove_refreshtokens branch from 9bfc070 to 5c11314 Compare May 22, 2025 14:22
@isaacroldan isaacroldan force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch from 9ede791 to c97d4b2 Compare May 22, 2025 15:48
@isaacroldan isaacroldan force-pushed the 05-22-remove_refreshtokens branch from 5c11314 to bb18dc1 Compare May 22, 2025 15:48
@isaacroldan isaacroldan marked this pull request as ready for review May 22, 2025 15:51
@isaacroldan isaacroldan requested review from a team as code owners May 22, 2025 15:51
@isaacroldan isaacroldan force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch from c97d4b2 to 20763e7 Compare May 22, 2025 15:51
Copy link
Contributor

We detected some changes at packages/*/src and there are no updates in the .changeset.
If the changes are user-facing, run pnpm changeset add to track your changes and include them in the next release CHANGELOG.

Caution

DO NOT create changesets for features which you do not wish to be included in the public changelog of the next CLI release.

@isaacroldan isaacroldan force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch from 20763e7 to ce1f36b Compare May 22, 2025 16:01
@isaacroldan isaacroldan force-pushed the 05-22-remove_refreshtokens branch from 54c4aca to f664992 Compare May 22, 2025 16:04
@isaacroldan isaacroldan force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch 2 times, most recently from 6ee3132 to f147856 Compare May 22, 2025 16:11
@isaacroldan isaacroldan force-pushed the 05-22-remove_refreshtokens branch from f664992 to 7b973d3 Compare May 22, 2025 16:11
@isaacroldan isaacroldan force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch 2 times, most recently from 8c6deac to cf44586 Compare May 22, 2025 16:32
Copy link
Contributor

github-actions bot commented May 22, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
78.07% (+0% 🔼)
12481/15987
🟡 Branches 72.24% 6055/8382
🟡 Functions
78.27% (-0.04% 🔻)
3270/4178
🟡 Lines
78.51% (+0% 🔼)
11810/15043

Test suite run success

2870 tests passing in 1254 suites.

Report generated by 🧪jest coverage report action from 16a3be0

@isaacroldan isaacroldan force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch from cf44586 to 3030250 Compare May 22, 2025 16:42
@isaacroldan isaacroldan force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch from 3030250 to 56921b4 Compare May 23, 2025 08:56
@isaacroldan isaacroldan force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch from 56921b4 to 428e381 Compare May 23, 2025 10:32
Copy link
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/api/app-dev.d.ts
@@ -1,13 +1,25 @@
+import { UnauthorizedHandler } from './graphql.js';
 import { Variables } from 'graphql-request';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
 /**
- * Executes an org-scoped GraphQL query against the App Management API.
- * Uses typed documents.
- *
  * @param query - GraphQL query to execute.
  * @param shopFqdn - The shop fqdn.
  * @param token - Partners token.
  * @param variables - GraphQL variables to pass to the query.
+ * @param unauthorizedHandler - Unauthorized handler to use.
+ */
+export interface AppDevRequestOptions<TResult, TVariables extends Variables> {
+    query: TypedDocumentNode<TResult, TVariables>;
+    shopFqdn: string;
+    token: string;
+    unauthorizedHandler: UnauthorizedHandler;
+    variables?: TVariables;
+}
+/**
+ * Executes an org-scoped GraphQL query against the App Management API.
+ * Uses typed documents.
+ *
+ * @param options - The options for the request.
  * @returns The response of the query of generic type <T>.
  */
-export declare function appDevRequest<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, shopFqdn: string, token: string, variables?: TVariables): Promise<TResult>;
\ No newline at end of file
+export declare function appDevRequestDoc<TResult, TVariables extends Variables>(options: AppDevRequestOptions<TResult, TVariables>): Promise<TResult>;
\ No newline at end of file
packages/cli-kit/dist/public/node/api/app-management.d.ts
@@ -1,4 +1,4 @@
-import { CacheOptions, GraphQLResponse } from './graphql.js';
+import { CacheOptions, GraphQLResponse, UnauthorizedHandler } from './graphql.js';
 import { RequestModeInput } from '../http.js';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
 import { Variables } from 'graphql-request';
@@ -13,17 +13,30 @@ export interface RequestOptions {
     requestMode: RequestModeInput;
 }
 /**
- * Executes an org-scoped GraphQL query against the App Management API. Uses typed documents.
- *
  * @param orgId - The organization ID.
  * @param query - GraphQL query to execute.
  * @param token - Partners 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.
  * @param requestOptions - Preferred behaviour for the request.
+ * @param unauthorizedHandler - Optional handler for unauthorized requests.
+ */
+export interface AppManagementRequestOptions<TResult, TVariables extends Variables> {
+    organizationId: string;
+    query: TypedDocumentNode<TResult, TVariables>;
+    token: string;
+    variables?: TVariables;
+    cacheOptions?: CacheOptions;
+    requestOptions?: RequestOptions;
+    unauthorizedHandler: UnauthorizedHandler;
+}
+/**
+ * Executes an org-scoped GraphQL query against the App Management API. Uses typed documents.
+ *
+ * @param options - The options for the request.
  * @returns The response of the query of generic type <T>.
  */
-export declare function appManagementRequestDoc<TResult, TVariables extends Variables>(orgId: string, query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, cacheOptions?: CacheOptions, requestOptions?: RequestOptions): Promise<TResult>;
+export declare function appManagementRequestDoc<TResult, TVariables extends Variables>(options: AppManagementRequestOptions<TResult, TVariables>): Promise<TResult>;
 /**
  * Sets the next deprecation date from [GraphQL response extensions](https://www.apollographql.com/docs/resources/graphql-glossary/#extensions)
  * if  objects contain a  (ISO 8601-formatted string).
packages/cli-kit/dist/public/node/api/business-platform.d.ts
@@ -1,4 +1,4 @@
-import { CacheOptions, Exact, GraphQLVariables } from './graphql.js';
+import { CacheOptions, GraphQLVariables, UnauthorizedHandler } from './graphql.js';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
 import { Variables } from 'graphql-request';
 /**
@@ -12,34 +12,46 @@ import { Variables } from 'graphql-request';
  */
 export declare function businessPlatformRequest<T>(query: string, token: string, variables?: GraphQLVariables, cacheOptions?: CacheOptions): Promise<T>;
 /**
- * Executes a GraphQL query against the Business Platform Destinations API. Uses typed documents.
- *
  * @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.
+ */
+export interface BusinessPlatformRequestOptions<TResult, TVariables extends Variables> {
+    query: TypedDocumentNode<TResult, TVariables>;
+    token: string;
+    variables?: TVariables;
+    cacheOptions?: CacheOptions;
+    unauthorizedHandler: UnauthorizedHandler;
+}
+/**
+ * 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 declare function businessPlatformRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, cacheOptions?: CacheOptions): Promise<TResult>;
+export declare function businessPlatformRequestDoc<TResult, TVariables extends Variables>(options: BusinessPlatformRequestOptions<TResult, TVariables>): Promise<TResult>;
+export interface BusinessPlatformOrganizationsRequestNonTypedOptions {
+    query: string;
+    token: string;
+    organizationId: string;
+    unauthorizedHandler: UnauthorizedHandler;
+    variables?: GraphQLVariables;
+}
 /**
  * Executes a GraphQL query against the Business Platform Organizations API.
  *
- * @param query - GraphQL query to execute.
- * @param token - Business Platform token.
- * @param organizationId - Organization ID as a numeric (non-GID) value.
- * @param variables - GraphQL variables to pass to the query.
+ * @param options - The options for the request.
  * @returns The response of the query of generic type <T>.
  */
-export declare function businessPlatformOrganizationsRequest<T>(query: string, token: string, organizationId: string, variables?: GraphQLVariables): Promise<T>;
+export declare function businessPlatformOrganizationsRequest<T>(options: BusinessPlatformOrganizationsRequestNonTypedOptions): Promise<T>;
+export interface BusinessPlatformOrganizationsRequestOptions<TResult, TVariables extends Variables> extends BusinessPlatformRequestOptions<TResult, TVariables> {
+    organizationId: string;
+}
 /**
  * Executes a GraphQL query against the Business Platform Organizations API. Uses typed documents.
  *
- * @param query - GraphQL query to execute.
- * @param token - Business Platform token.
- * @param organizationId - Organization ID as a numeric value.
- * @param variables - GraphQL variables to pass to the query.
+ * @param options - The options for the request.
  * @returns The response of the query of generic type <T>.
  */
-export declare function businessPlatformOrganizationsRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables> | TypedDocumentNode<TResult, Exact<{
-    [key: string]: never;
-}>>, token: string, organizationId: string, variables?: TVariables): Promise<TResult>;
\ No newline at end of file
+export declare function businessPlatformOrganizationsRequestDoc<TResult, TVariables extends Variables>(options: BusinessPlatformOrganizationsRequestOptions<TResult, TVariables>): Promise<TResult>;
\ No newline at end of file
packages/cli-kit/dist/public/node/api/functions.d.ts
@@ -1,13 +1,26 @@
+import { UnauthorizedHandler } from './graphql.js';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
 import { Variables } from 'graphql-request';
 /**
- * Executes a rate-limited GraphQL request against the App Management Functions API.
- *
  * @param orgId - Organization identifier.
  * @param query - Typed GraphQL document node.
  * @param token - Authentication token.
  * @param appId - App identifier.
  * @param variables - Optional query variables.
+ * @param unauthorizedHandler - Optional handler for unauthorized requests.
+ */
+export interface FunctionsRequestOptions<TResult, TVariables extends Variables> {
+    organizationId: string;
+    query: TypedDocumentNode<TResult, TVariables>;
+    token: string;
+    appId: string;
+    unauthorizedHandler: UnauthorizedHandler;
+    variables?: TVariables;
+}
+/**
+ * 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 declare function functionsRequestDoc<TResult, TVariables extends Variables>(orgId: string, query: TypedDocumentNode<TResult, TVariables>, token: string, appId: string, variables?: TVariables): Promise<TResult>;
\ No newline at end of file
+export declare function functionsRequestDoc<TResult, TVariables extends Variables>(options: FunctionsRequestOptions<TResult, TVariables>): Promise<TResult>;
\ No newline at end of file
packages/cli-kit/dist/public/node/api/graphql.d.ts
@@ -17,6 +17,19 @@ export interface CacheOptions {
     cacheExtraKey?: string;
     cacheStore?: LocalStorage<ConfSchema>;
 }
+interface RefreshedTokenOnAuthorizedResponse {
+    token?: string;
+}
+export type RefreshTokenOnAuthorizedResponse = Promise<RefreshedTokenOnAuthorizedResponse>;
+interface SimpleUnauthorizedHandler {
+    type: 'simple';
+    handler: () => Promise<void>;
+}
+interface TokenRefreshHandler {
+    type: 'token_refresh';
+    handler: () => RefreshTokenOnAuthorizedResponse;
+}
+export type UnauthorizedHandler = SimpleUnauthorizedHandler | TokenRefreshHandler;
 interface GraphQLRequestBaseOptions<TResult> {
     api: string;
     url: string;
@@ -31,7 +44,7 @@ interface GraphQLRequestBaseOptions<TResult> {
 export type GraphQLRequestOptions<T> = GraphQLRequestBaseOptions<T> & {
     query: RequestDocument;
     variables?: Variables;
-    unauthorizedHandler?: () => Promise<void>;
+    unauthorizedHandler?: UnauthorizedHandler;
     requestBehaviour?: RequestModeInput;
 };
 export type GraphQLRequestDocOptions<TResult, TVariables> = GraphQLRequestBaseOptions<TResult> & {
@@ -39,7 +52,7 @@ export type GraphQLRequestDocOptions<TResult, TVariables> = GraphQLRequestBaseOp
         [key: string]: never;
     }>>;
     variables?: TVariables;
-    unauthorizedHandler?: () => Promise<void>;
+    unauthorizedHandler?: UnauthorizedHandler;
     requestBehaviour?: RequestModeInput;
 };
 export interface GraphQLResponseOptions<T> {
packages/cli-kit/dist/public/node/api/partners.d.ts
@@ -1,4 +1,4 @@
-import { GraphQLVariables, GraphQLResponse, CacheOptions } from './graphql.js';
+import { GraphQLVariables, GraphQLResponse, CacheOptions, UnauthorizedHandler } from './graphql.js';
 import { RequestModeInput } from '../http.js';
 import { Variables } from 'graphql-request';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
@@ -10,9 +10,10 @@ import { TypedDocumentNode } from '@graphql-typed-document-node/core';
  * @param variables - GraphQL variables to pass to the query.
  * @param cacheOptions - Cache options.
  * @param preferredBehaviour - Preferred behaviour for the request.
+ * @param unauthorizedHandler - Optional handler for unauthorized requests.
  * @returns The response of the query of generic type <T>.
  */
-export declare function partnersRequest<T>(query: string, token: string, variables?: GraphQLVariables, cacheOptions?: CacheOptions, preferredBehaviour?: RequestModeInput): Promise<T>;
+export declare function partnersRequest<T>(query: string, token: string, variables?: GraphQLVariables, cacheOptions?: CacheOptions, preferredBehaviour?: RequestModeInput, unauthorizedHandler?: UnauthorizedHandler): Promise<T>;
 export declare const generateFetchAppLogUrl: (cursor?: string, filters?: {
     status?: string;
     source?: string;
@@ -24,9 +25,10 @@ export declare const generateFetchAppLogUrl: (cursor?: string, filters?: {
  * @param token - Partners token.
  * @param variables - GraphQL variables to pass to the query.
  * @param preferredBehaviour - Preferred behaviour for the request.
+ * @param unauthorizedHandler - Optional handler for unauthorized requests.
  * @returns The response of the query of generic type <TResult>.
  */
-export declare function partnersRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, preferredBehaviour?: RequestModeInput): Promise<TResult>;
+export declare function partnersRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, preferredBehaviour?: RequestModeInput, unauthorizedHandler?: UnauthorizedHandler): Promise<TResult>;
 /**
  * Sets the next deprecation date from [GraphQL response extensions](https://www.apollographql.com/docs/resources/graphql-glossary/#extensions)
  * if  objects contain a  (ISO 8601-formatted string).
packages/cli-kit/dist/public/node/api/webhooks.d.ts
@@ -1,13 +1,21 @@
+import { UnauthorizedHandler } from './graphql.js';
 import { Variables } from 'graphql-request';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
+/**
+ * Options for making requests to the Webhooks API.
+ */
+export interface WebhooksRequestOptions<TResult, TVariables extends Variables> {
+    organizationId: string;
+    query: TypedDocumentNode<TResult, TVariables>;
+    token: string;
+    unauthorizedHandler: UnauthorizedHandler;
+    variables?: TVariables;
+}
 /**
  * Executes an org-scoped GraphQL query against the App Management API.
  * Uses typed documents.
  *
- * @param organizationId - Organization ID required to check permissions.
- * @param query - GraphQL query to execute.
- * @param token - Partners token.
- * @param variables - GraphQL variables to pass to the query.
+ * @param options - The options for the request.
  * @returns The response of the query of generic type <T>.
  */
-export declare function webhooksRequest<TResult, TVariables extends Variables>(organizationId: string, query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables): Promise<TResult>;
\ No newline at end of file
+export declare function webhooksRequestDoc<TResult, TVariables extends Variables>(options: WebhooksRequestOptions<TResult, TVariables>): Promise<TResult>;
\ No newline at end of file

@isaacroldan isaacroldan force-pushed the 05-22-force_all_requests_in_app_management_to_have_an_unauthorizedhandler branch from 428e381 to 16a3be0 Compare May 23, 2025 10:45
Copy link
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/api/app-dev.d.ts
@@ -1,13 +1,25 @@
+import { UnauthorizedHandler } from './graphql.js';
 import { Variables } from 'graphql-request';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
 /**
- * Executes an org-scoped GraphQL query against the App Management API.
- * Uses typed documents.
- *
  * @param query - GraphQL query to execute.
  * @param shopFqdn - The shop fqdn.
  * @param token - Partners token.
  * @param variables - GraphQL variables to pass to the query.
+ * @param unauthorizedHandler - Unauthorized handler to use.
+ */
+export interface AppDevRequestOptions<TResult, TVariables extends Variables> {
+    query: TypedDocumentNode<TResult, TVariables>;
+    shopFqdn: string;
+    token: string;
+    unauthorizedHandler: UnauthorizedHandler;
+    variables?: TVariables;
+}
+/**
+ * Executes an org-scoped GraphQL query against the App Management API.
+ * Uses typed documents.
+ *
+ * @param options - The options for the request.
  * @returns The response of the query of generic type <T>.
  */
-export declare function appDevRequest<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, shopFqdn: string, token: string, variables?: TVariables): Promise<TResult>;
\ No newline at end of file
+export declare function appDevRequestDoc<TResult, TVariables extends Variables>(options: AppDevRequestOptions<TResult, TVariables>): Promise<TResult>;
\ No newline at end of file
packages/cli-kit/dist/public/node/api/app-management.d.ts
@@ -1,4 +1,4 @@
-import { CacheOptions, GraphQLResponse } from './graphql.js';
+import { CacheOptions, GraphQLResponse, UnauthorizedHandler } from './graphql.js';
 import { RequestModeInput } from '../http.js';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
 import { Variables } from 'graphql-request';
@@ -13,17 +13,30 @@ export interface RequestOptions {
     requestMode: RequestModeInput;
 }
 /**
- * Executes an org-scoped GraphQL query against the App Management API. Uses typed documents.
- *
  * @param orgId - The organization ID.
  * @param query - GraphQL query to execute.
  * @param token - Partners 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.
  * @param requestOptions - Preferred behaviour for the request.
+ * @param unauthorizedHandler - Optional handler for unauthorized requests.
+ */
+export interface AppManagementRequestOptions<TResult, TVariables extends Variables> {
+    organizationId: string;
+    query: TypedDocumentNode<TResult, TVariables>;
+    token: string;
+    variables?: TVariables;
+    cacheOptions?: CacheOptions;
+    requestOptions?: RequestOptions;
+    unauthorizedHandler: UnauthorizedHandler;
+}
+/**
+ * Executes an org-scoped GraphQL query against the App Management API. Uses typed documents.
+ *
+ * @param options - The options for the request.
  * @returns The response of the query of generic type <T>.
  */
-export declare function appManagementRequestDoc<TResult, TVariables extends Variables>(orgId: string, query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, cacheOptions?: CacheOptions, requestOptions?: RequestOptions): Promise<TResult>;
+export declare function appManagementRequestDoc<TResult, TVariables extends Variables>(options: AppManagementRequestOptions<TResult, TVariables>): Promise<TResult>;
 /**
  * Sets the next deprecation date from [GraphQL response extensions](https://www.apollographql.com/docs/resources/graphql-glossary/#extensions)
  * if  objects contain a  (ISO 8601-formatted string).
packages/cli-kit/dist/public/node/api/business-platform.d.ts
@@ -1,4 +1,4 @@
-import { CacheOptions, Exact, GraphQLVariables } from './graphql.js';
+import { CacheOptions, GraphQLVariables, UnauthorizedHandler } from './graphql.js';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
 import { Variables } from 'graphql-request';
 /**
@@ -12,34 +12,46 @@ import { Variables } from 'graphql-request';
  */
 export declare function businessPlatformRequest<T>(query: string, token: string, variables?: GraphQLVariables, cacheOptions?: CacheOptions): Promise<T>;
 /**
- * Executes a GraphQL query against the Business Platform Destinations API. Uses typed documents.
- *
  * @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.
+ */
+export interface BusinessPlatformRequestOptions<TResult, TVariables extends Variables> {
+    query: TypedDocumentNode<TResult, TVariables>;
+    token: string;
+    variables?: TVariables;
+    cacheOptions?: CacheOptions;
+    unauthorizedHandler: UnauthorizedHandler;
+}
+/**
+ * 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 declare function businessPlatformRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, cacheOptions?: CacheOptions): Promise<TResult>;
+export declare function businessPlatformRequestDoc<TResult, TVariables extends Variables>(options: BusinessPlatformRequestOptions<TResult, TVariables>): Promise<TResult>;
+export interface BusinessPlatformOrganizationsRequestNonTypedOptions {
+    query: string;
+    token: string;
+    organizationId: string;
+    unauthorizedHandler: UnauthorizedHandler;
+    variables?: GraphQLVariables;
+}
 /**
  * Executes a GraphQL query against the Business Platform Organizations API.
  *
- * @param query - GraphQL query to execute.
- * @param token - Business Platform token.
- * @param organizationId - Organization ID as a numeric (non-GID) value.
- * @param variables - GraphQL variables to pass to the query.
+ * @param options - The options for the request.
  * @returns The response of the query of generic type <T>.
  */
-export declare function businessPlatformOrganizationsRequest<T>(query: string, token: string, organizationId: string, variables?: GraphQLVariables): Promise<T>;
+export declare function businessPlatformOrganizationsRequest<T>(options: BusinessPlatformOrganizationsRequestNonTypedOptions): Promise<T>;
+export interface BusinessPlatformOrganizationsRequestOptions<TResult, TVariables extends Variables> extends BusinessPlatformRequestOptions<TResult, TVariables> {
+    organizationId: string;
+}
 /**
  * Executes a GraphQL query against the Business Platform Organizations API. Uses typed documents.
  *
- * @param query - GraphQL query to execute.
- * @param token - Business Platform token.
- * @param organizationId - Organization ID as a numeric value.
- * @param variables - GraphQL variables to pass to the query.
+ * @param options - The options for the request.
  * @returns The response of the query of generic type <T>.
  */
-export declare function businessPlatformOrganizationsRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables> | TypedDocumentNode<TResult, Exact<{
-    [key: string]: never;
-}>>, token: string, organizationId: string, variables?: TVariables): Promise<TResult>;
\ No newline at end of file
+export declare function businessPlatformOrganizationsRequestDoc<TResult, TVariables extends Variables>(options: BusinessPlatformOrganizationsRequestOptions<TResult, TVariables>): Promise<TResult>;
\ No newline at end of file
packages/cli-kit/dist/public/node/api/functions.d.ts
@@ -1,13 +1,26 @@
+import { UnauthorizedHandler } from './graphql.js';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
 import { Variables } from 'graphql-request';
 /**
- * Executes a rate-limited GraphQL request against the App Management Functions API.
- *
  * @param orgId - Organization identifier.
  * @param query - Typed GraphQL document node.
  * @param token - Authentication token.
  * @param appId - App identifier.
  * @param variables - Optional query variables.
+ * @param unauthorizedHandler - Optional handler for unauthorized requests.
+ */
+export interface FunctionsRequestOptions<TResult, TVariables extends Variables> {
+    organizationId: string;
+    query: TypedDocumentNode<TResult, TVariables>;
+    token: string;
+    appId: string;
+    unauthorizedHandler: UnauthorizedHandler;
+    variables?: TVariables;
+}
+/**
+ * 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 declare function functionsRequestDoc<TResult, TVariables extends Variables>(orgId: string, query: TypedDocumentNode<TResult, TVariables>, token: string, appId: string, variables?: TVariables): Promise<TResult>;
\ No newline at end of file
+export declare function functionsRequestDoc<TResult, TVariables extends Variables>(options: FunctionsRequestOptions<TResult, TVariables>): Promise<TResult>;
\ No newline at end of file
packages/cli-kit/dist/public/node/api/graphql.d.ts
@@ -17,6 +17,19 @@ export interface CacheOptions {
     cacheExtraKey?: string;
     cacheStore?: LocalStorage<ConfSchema>;
 }
+interface RefreshedTokenOnAuthorizedResponse {
+    token?: string;
+}
+export type RefreshTokenOnAuthorizedResponse = Promise<RefreshedTokenOnAuthorizedResponse>;
+interface SimpleUnauthorizedHandler {
+    type: 'simple';
+    handler: () => Promise<void>;
+}
+interface TokenRefreshHandler {
+    type: 'token_refresh';
+    handler: () => RefreshTokenOnAuthorizedResponse;
+}
+export type UnauthorizedHandler = SimpleUnauthorizedHandler | TokenRefreshHandler;
 interface GraphQLRequestBaseOptions<TResult> {
     api: string;
     url: string;
@@ -31,7 +44,7 @@ interface GraphQLRequestBaseOptions<TResult> {
 export type GraphQLRequestOptions<T> = GraphQLRequestBaseOptions<T> & {
     query: RequestDocument;
     variables?: Variables;
-    unauthorizedHandler?: () => Promise<void>;
+    unauthorizedHandler?: UnauthorizedHandler;
     requestBehaviour?: RequestModeInput;
 };
 export type GraphQLRequestDocOptions<TResult, TVariables> = GraphQLRequestBaseOptions<TResult> & {
@@ -39,7 +52,7 @@ export type GraphQLRequestDocOptions<TResult, TVariables> = GraphQLRequestBaseOp
         [key: string]: never;
     }>>;
     variables?: TVariables;
-    unauthorizedHandler?: () => Promise<void>;
+    unauthorizedHandler?: UnauthorizedHandler;
     requestBehaviour?: RequestModeInput;
 };
 export interface GraphQLResponseOptions<T> {
packages/cli-kit/dist/public/node/api/partners.d.ts
@@ -1,4 +1,4 @@
-import { GraphQLVariables, GraphQLResponse, CacheOptions } from './graphql.js';
+import { GraphQLVariables, GraphQLResponse, CacheOptions, UnauthorizedHandler } from './graphql.js';
 import { RequestModeInput } from '../http.js';
 import { Variables } from 'graphql-request';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
@@ -10,9 +10,10 @@ import { TypedDocumentNode } from '@graphql-typed-document-node/core';
  * @param variables - GraphQL variables to pass to the query.
  * @param cacheOptions - Cache options.
  * @param preferredBehaviour - Preferred behaviour for the request.
+ * @param unauthorizedHandler - Optional handler for unauthorized requests.
  * @returns The response of the query of generic type <T>.
  */
-export declare function partnersRequest<T>(query: string, token: string, variables?: GraphQLVariables, cacheOptions?: CacheOptions, preferredBehaviour?: RequestModeInput): Promise<T>;
+export declare function partnersRequest<T>(query: string, token: string, variables?: GraphQLVariables, cacheOptions?: CacheOptions, preferredBehaviour?: RequestModeInput, unauthorizedHandler?: UnauthorizedHandler): Promise<T>;
 export declare const generateFetchAppLogUrl: (cursor?: string, filters?: {
     status?: string;
     source?: string;
@@ -24,9 +25,10 @@ export declare const generateFetchAppLogUrl: (cursor?: string, filters?: {
  * @param token - Partners token.
  * @param variables - GraphQL variables to pass to the query.
  * @param preferredBehaviour - Preferred behaviour for the request.
+ * @param unauthorizedHandler - Optional handler for unauthorized requests.
  * @returns The response of the query of generic type <TResult>.
  */
-export declare function partnersRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, preferredBehaviour?: RequestModeInput): Promise<TResult>;
+export declare function partnersRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, preferredBehaviour?: RequestModeInput, unauthorizedHandler?: UnauthorizedHandler): Promise<TResult>;
 /**
  * Sets the next deprecation date from [GraphQL response extensions](https://www.apollographql.com/docs/resources/graphql-glossary/#extensions)
  * if  objects contain a  (ISO 8601-formatted string).
packages/cli-kit/dist/public/node/api/webhooks.d.ts
@@ -1,13 +1,21 @@
+import { UnauthorizedHandler } from './graphql.js';
 import { Variables } from 'graphql-request';
 import { TypedDocumentNode } from '@graphql-typed-document-node/core';
+/**
+ * Options for making requests to the Webhooks API.
+ */
+export interface WebhooksRequestOptions<TResult, TVariables extends Variables> {
+    organizationId: string;
+    query: TypedDocumentNode<TResult, TVariables>;
+    token: string;
+    unauthorizedHandler: UnauthorizedHandler;
+    variables?: TVariables;
+}
 /**
  * Executes an org-scoped GraphQL query against the App Management API.
  * Uses typed documents.
  *
- * @param organizationId - Organization ID required to check permissions.
- * @param query - GraphQL query to execute.
- * @param token - Partners token.
- * @param variables - GraphQL variables to pass to the query.
+ * @param options - The options for the request.
  * @returns The response of the query of generic type <T>.
  */
-export declare function webhooksRequest<TResult, TVariables extends Variables>(organizationId: string, query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables): Promise<TResult>;
\ No newline at end of file
+export declare function webhooksRequestDoc<TResult, TVariables extends Variables>(options: WebhooksRequestOptions<TResult, TVariables>): Promise<TResult>;
\ No newline at end of file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants