UNPKG

@crowdin/crowdin-apps-functions

Version:

Utility library to easily and quickly develop Crowdin App

103 lines (102 loc) 3.62 kB
import { AppToken, JwtPayload, Token } from './models'; /** * Crowdin App Authentication */ interface FetchAppTokenArgs { appId: string; appSecret: string; clientId: string; clientSecret: string; domain: string; userId: number; url?: string; } /** * * @param appId Crowdin app identifier * @param appSecret Crowdin app secret received from install event * @param clientId OAuth client id of the app * @param clientSecret OAuth client secret of the app * @param domain Crowdin organization domain * @param userId The user who installed the application * @param url Custom url for token exchange * @returns token object which is needed to establish communication between app and Crowdin API */ export declare function fetchAppToken(appId: string, appSecret: string, clientId: string, clientSecret: string, domain: string, userId: number, url?: string): Promise<AppToken>; export declare function fetchAppToken(args: FetchAppTokenArgs): Promise<AppToken>; /** * Crowdin Agent Authentication */ interface FetchAgentTokenArgs extends FetchAppTokenArgs { agentId: number; } export declare function fetchAgentToken(args: FetchAgentTokenArgs): Promise<AppToken>; /** * Crowdin OAuth App Authentication */ interface GenerateOAuthTokenArgs { clientId: string; clientSecret: string; code: string; url?: string; } /** * * @param clientId OAuth client id of the app * @param clientSecret OAuth client secret of the app * @param code code used for authorization of your Crowdin app (returned in install event payload) * @param url Custom url for token exchange * @returns token object which is needed to establish communication between app and Crowdin API */ export declare function generateOAuthToken(clientId: string, clientSecret: string, code: string, url?: string): Promise<Token>; export declare function generateOAuthToken(args: GenerateOAuthTokenArgs): Promise<Token>; interface RefreshOAuthTokenArgs { clientId: string; clientSecret: string; refreshToken: string; url?: string; } /** * * @param clientId OAuth client id of the app * @param clientSecret OAuth client secret of the app * @param refreshToken {@link Token#refreshToken} * @param url Custom url for token exchange * @returns updated token object */ export declare function refreshOAuthToken(clientId: string, clientSecret: string, refreshToken: string, url?: string): Promise<Token>; export declare function refreshOAuthToken(args: 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>; export interface VerifyOptions { ignoreExpiration: boolean; } export {};