diff --git a/types/apple-signin-api/apple-signin-api-tests.ts b/types/apple-signin-api/apple-signin-api-tests.ts new file mode 100644 index 0000000000..e899b26908 --- /dev/null +++ b/types/apple-signin-api/apple-signin-api-tests.ts @@ -0,0 +1,42 @@ +const ClientConfig: AppleSignInAPI.ClientConfigI = { + clientId: '', + redirectURI: '', + scope: '', + state: '', + usePopup: false, +}; + +const signInResponse: AppleSignInAPI.SignInResponseI = { + authorization: { + state: '[STATE]', + code: '[CODE]', + id_token: '[ID_TOKEN]', + }, + user: { + email: '[EMAIL]', + name: { + firstName: '[FIRST_NAME]', + lastName: '[LAST_NAME]', + }, + }, +}; + +const signInError: AppleSignInAPI.SignInErrorI = { + error: '[ERROR]', +}; + +const AuthGood: AppleSignInAPI.AppleID = { + auth: { + init: () => new Promise(() => {}), + signIn: () => new Promise(() => signInResponse), + renderButton: () => {}, + }, +}; + +const AuthBad: AppleSignInAPI.AppleID = { + auth: { + init: () => new Promise(() => {}), + signIn: () => new Promise(() => signInError), + renderButton: () => {}, + }, +}; diff --git a/types/apple-signin-api/index.d.ts b/types/apple-signin-api/index.d.ts new file mode 100644 index 0000000000..64443bea19 --- /dev/null +++ b/types/apple-signin-api/index.d.ts @@ -0,0 +1,49 @@ +// Type definitions for non-npm package Apple Sign in API 1.4 +// Project: https://developer.apple.com/documentation/signinwithapplejs +// Definitions by: Julius Lungys +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace AppleSignInAPI { + // https://developer.apple.com/documentation/signinwithapplejs/authorizationi + interface AuthorizationI { + code: string; + id_token: string; + state: string; + } + // https://developer.apple.com/documentation/signinwithapplejs/namei + interface NameI { + firstName: string; + lastName: string; + } + // https://developer.apple.com/documentation/signinwithapplejs/signinerrori + interface SignInErrorI { + error: string; + } + // https://developer.apple.com/documentation/signinwithapplejs/signinresponsei + interface SignInResponseI { + authorization: AuthorizationI; + user?: UserI; + } + // https://developer.apple.com/documentation/signinwithapplejs/useri + interface UserI { + email: string; + name: NameI; + } + // https://developer.apple.com/documentation/signinwithapplejs/authi + interface AuthI { + init: (config: ClientConfigI) => Promise; + signIn: (signInConfig?: ClientConfigI) => Promise; + renderButton: () => void; + } + // https://developer.apple.com/documentation/signinwithapplejs/clientconfigi + interface ClientConfigI { + clientId: string; + redirectURI: string; + scope: string; + state: string; + usePopup: boolean; + } + interface AppleID { + auth: AuthI; + } +} diff --git a/types/apple-signin-api/tsconfig.json b/types/apple-signin-api/tsconfig.json new file mode 100644 index 0000000000..fb8304e521 --- /dev/null +++ b/types/apple-signin-api/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "apple-signin-api-tests.ts" + ] +} diff --git a/types/apple-signin-api/tslint.json b/types/apple-signin-api/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/apple-signin-api/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }