UNPKG

@shopify/cli-kit

Version:

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

137 lines (136 loc) 5.84 kB
import { AdminAPIScope, AppManagementAPIScope, BusinessPlatformScope, EnsureAuthenticatedAdditionalOptions, PartnersAPIScope, StorefrontRendererScope } from '../../private/node/session.js'; /** * Session Object to access the Admin API, includes the token and the store FQDN. */ export interface AdminSession { token: string; storeFqdn: string; } /** * Session Object for Partners API and App Management API access. */ export interface Session { token: string; businessPlatformToken: string; accountInfo: AccountInfo; userId: string; } export type AccountInfo = UserAccountInfo | ServiceAccountInfo | UnknownAccountInfo; interface UserAccountInfo { type: 'UserAccount'; email: string; } interface ServiceAccountInfo { type: 'ServiceAccount'; orgName: string; } interface UnknownAccountInfo { type: 'UnknownAccount'; } /** * Type guard to check if an account is a UserAccount. * * @param account - The account to check. * @returns True if the account is a UserAccount. */ export declare function isUserAccount(account: AccountInfo): account is UserAccountInfo; /** * Type guard to check if an account is a ServiceAccount. * * @param account - The account to check. * @returns True if the account is a ServiceAccount. */ export declare function isServiceAccount(account: AccountInfo): account is ServiceAccountInfo; /** * Ensure that we have a valid session with no particular scopes. * * @param env - Optional environment variables to use. * @param options - Optional extra options to use. * @returns The user ID. */ export declare function ensureAuthenticatedUser(env?: NodeJS.ProcessEnv, options?: EnsureAuthenticatedAdditionalOptions): Promise<{ userId: string; }>; /** * Ensure that we have a valid session to access the Partners API. * If SHOPIFY_CLI_PARTNERS_TOKEN exists, that token will be used to obtain a valid Partners Token * If SHOPIFY_CLI_PARTNERS_TOKEN exists, scopes will be ignored. * * @param scopes - Optional array of extra scopes to authenticate with. * @param env - Optional environment variables to use. * @param options - Optional extra options to use. * @returns The access token for the Partners API. */ export declare function ensureAuthenticatedPartners(scopes?: PartnersAPIScope[], env?: NodeJS.ProcessEnv, options?: EnsureAuthenticatedAdditionalOptions): Promise<{ token: string; userId: string; }>; /** * Ensure that we have a valid session to access the App Management API. * * @param options - Optional extra options to use. * @param appManagementScopes - Optional array of extra scopes to authenticate with. * @param businessPlatformScopes - Optional array of extra scopes to authenticate with. * @param env - Optional environment variables to use. * @returns The access token for the App Management API. */ export declare function ensureAuthenticatedAppManagementAndBusinessPlatform(options?: EnsureAuthenticatedAdditionalOptions, appManagementScopes?: AppManagementAPIScope[], businessPlatformScopes?: BusinessPlatformScope[], env?: NodeJS.ProcessEnv): Promise<{ appManagementToken: string; userId: string; businessPlatformToken: string; }>; /** * Ensure that we have a valid session to access the Storefront API. * * @param scopes - Optional array of extra scopes to authenticate with. * @param password - Optional password to use. * @param options - Optional extra options to use. * @returns The access token for the Storefront API. */ export declare function ensureAuthenticatedStorefront(scopes?: StorefrontRendererScope[], password?: string | undefined, options?: EnsureAuthenticatedAdditionalOptions): Promise<string>; /** * Ensure that we have a valid Admin session for the given store. * * @param store - Store fqdn to request auth for. * @param scopes - Optional array of extra scopes to authenticate with. * @param options - Optional extra options to use. * @returns The access token for the Admin API. */ export declare function ensureAuthenticatedAdmin(store: string, scopes?: AdminAPIScope[], options?: EnsureAuthenticatedAdditionalOptions): Promise<AdminSession>; /** * Ensure that we have a valid session to access the Theme API. * If a password is provided, that token will be used against Theme Access API. * Otherwise, it will ensure that the user is authenticated with the Admin API. * * @param store - Store fqdn to request auth for. * @param password - Password generated from Theme Access app. * @param scopes - Optional array of extra scopes to authenticate with. * @param options - Optional extra options to use. * @returns The access token and store. */ export declare function ensureAuthenticatedThemes(store: string, password: string | undefined, scopes?: AdminAPIScope[], options?: EnsureAuthenticatedAdditionalOptions): Promise<AdminSession>; /** * Ensure that we have a valid session to access the Business Platform API. * * @param scopes - Optional array of extra scopes to authenticate with. * @returns The access token for the Business Platform API. */ export declare function ensureAuthenticatedBusinessPlatform(scopes?: BusinessPlatformScope[]): Promise<string>; /** * Logout from Shopify. * * @returns A promise that resolves when the logout is complete. */ export declare function logout(): Promise<void>; /** * Ensure that we have a valid Admin session for the given store, with access on behalf of the app. * * See `ensureAuthenticatedAdmin` for access on behalf of a user. * * @param storeFqdn - Store fqdn to request auth for. * @param clientId - Client ID of the app. * @param clientSecret - Client secret of the app. * @returns The access token for the Admin API. */ export declare function ensureAuthenticatedAdminAsApp(storeFqdn: string, clientId: string, clientSecret: string): Promise<AdminSession>; export {};