@crowdin/app-project-module
Version:
Module that generates for you all common endpoints for serving standalone Crowdin App
72 lines (71 loc) • 2.27 kB
TypeScript
import { JwtPayload, VerifyOptions } from '../../types';
interface FetchAppTokenArgs {
appId: string;
appSecret: string;
clientId: string;
clientSecret: string;
domain: string;
userId: number;
url?: string;
}
export declare function fetchAppToken(options: FetchAppTokenArgs): Promise<AppToken>;
interface FetchAgentTokenArgs extends FetchAppTokenArgs {
agentId: number;
}
export declare function fetchAgentToken(args: FetchAgentTokenArgs): Promise<AppToken>;
interface FetchAppWithCodeTokenArgs extends FetchAppTokenArgs {
code: string;
}
export declare function fetchAppWithCodeToken(args: FetchAppWithCodeTokenArgs): Promise<AppToken>;
interface GenerateOAuthTokenArgs {
clientId: string;
clientSecret: string;
code: string;
url?: string;
}
export declare function generateOAuthToken(options: GenerateOAuthTokenArgs): Promise<Token>;
interface RefreshOAuthTokenArgs {
clientId: string;
clientSecret: string;
refreshToken: string;
url?: string;
}
export declare function refreshOAuthToken(options: RefreshOAuthTokenArgs): Promise<Token>;
/**
*
* @param jwtPayload jwt token payload
* @returns unique identifier of crowdin user and project context
*/
export declare function constructCrowdinIdFromJwtPayload(jwtPayload: JwtPayload): string;
/**
*
* @param crowdinId crowdin id (from {@link constructCrowdinIdFromJwtPayload})
* @returns crowdin project id
*/
export declare function getProjectId(crowdinId: string): number;
/**
*
* @param crowdinId crowdin id (from {@link constructCrowdinIdFromJwtPayload})
* @returns object with organization(id|domain), project id and user id
*/
export declare function parseCrowdinId(crowdinId: string): {
organization: string;
projectId: number;
userId: number;
};
/**
*
* @param jwtToken jwt token which Crowdin adds to app iframe
* @param clientSecret OAuth client secret of the app
* @param options extra options for verification
* @returns jwt payload
*/
export declare function validateJwtToken(jwtToken: string, clientSecret: string, options?: VerifyOptions): Promise<JwtPayload>;
interface AppToken {
accessToken: string;
expiresIn: number;
}
interface Token extends AppToken {
refreshToken: string;
}
export {};