Add definitions for apple-signin-api (#42454)

* Add definitions for apple-signin-api

* change signInResponse user to be optional
apple returns user object only on first login

* update to 1.4.1 version
This commit is contained in:
Julius Lungys
2020-02-22 04:06:42 +02:00
committed by GitHub
parent 9b9aed92fe
commit 22a48822fe
4 changed files with 115 additions and 0 deletions

View File

@@ -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: () => {},
},
};

49
types/apple-signin-api/index.d.ts vendored Normal file
View File

@@ -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 <https://github.com/voidpumpkin>
// 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<void>;
signIn: (signInConfig?: ClientConfigI) => Promise<SignInResponseI | SignInErrorI>;
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;
}
}

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }