Creating type definitions for "react-native-keychain" (#25419)

* Creating type definitions for "react-native-keychain"

* Updating index.d.ts to include Promise<string> on getGenericPassword()

* Fixing all tslint and dts-lint errors and issues.

* Removing duplicate "Definitions by"

* Updating index.d.ts, improving tests.

-Updating index.d.ts to include type definitions for canImplyAuthentication and getSupportedBiometryType.
-Updating index.d.ts to fix type definitions for setInternetCredentials and resetGenericPassword.
-Adding full type test coverage to all exposed methods on react-native-keychain.

* Updating type definitions for setGenericPassword, getGenericPassword.

-Updating index.d.ts to update type definitions for setGenericPassword, getGenericPassword.
-Updating type definition tests to reflect new type definition updates.

* Updating type definitions for setGenericPassword

-Updating index.d.ts to include correct setGenericPassword parameter types.
This commit is contained in:
David Andre Evans Farinha
2018-05-07 17:51:22 +03:00
committed by Andy
parent e94c84bd5e
commit 4df7adcb42
4 changed files with 150 additions and 0 deletions

87
types/react-native-keychain/index.d.ts vendored Normal file
View File

@@ -0,0 +1,87 @@
// Type definitions for react-native-keychain 3.0
// Project: https://github.com/oblador/react-native-keychain
// Definitions by: David Evans Farinha <https://github.com/DavidFarinha>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
export interface UserCredentials {
username: string;
password: string;
}
export interface SharedWebCredentials {
server: string;
username: string;
password: string;
}
export interface Options {
accessControl?: SecAccessControl;
accessGroup?: string;
accessible?: SecAccessible;
authenticationPrompt?: string;
authenticationType?: LAPolicy;
service?: string;
}
export type SecAccessible =
'AccessibleWhenUnlocked'
| 'AccessibleAfterFirstUnlock'
| 'AccessibleAlways'
| 'AccessibleWhenPasscodeSetThisDeviceOnly'
| 'AccessibleWhenUnlockedThisDeviceOnly'
| 'AccessibleAfterFirstUnlockThisDeviceOnly'
| 'AccessibleAlwaysThisDeviceOnly';
export type SecAccessControl =
'UserPresence'
| 'BiometryAny'
| 'BiometryCurrentSet'
| 'DevicePasscode'
| 'ApplicationPassword'
| 'BiometryAnyOrDevicePasscode'
| 'BiometryCurrentSetOrDevicePasscode';
export type LAPolicy = 'Authentication' | 'AuthenticationWithBiometrics';
export function canImplyAuthentication(options?: Options): Promise<boolean>;
export function getSupportedBiometryType(): Promise<string | null>;
export function setInternetCredentials(
server: string,
username: string,
password: string,
options?: Options
): Promise<boolean>;
export function getInternetCredentials(
server: string
): Promise<UserCredentials>;
export function resetInternetCredentials(
server: string
): Promise<boolean>;
export function setGenericPassword(
username: string,
password: string,
serviceOrOptions?: string | Options
): Promise<boolean>;
export function getGenericPassword(
serviceOrOptions?: string | Options
): Promise<boolean | {service: string, username: string, password: string}>;
export function resetGenericPassword(
serviceOrOptions?: string | Options
): Promise<boolean>;
export function requestSharedWebCredentials(
): Promise<SharedWebCredentials>;
export function setSharedWebCredentials(
server: string,
username: string,
password: string
): Promise<boolean>;

View File

@@ -0,0 +1,39 @@
import * as Keychain from 'react-native-keychain';
async () => {
const username = 'username';
const password = 'password';
const service: string | undefined = "test.service";
const server = "test.server";
const serviceOrOptions: string | Keychain.Options | undefined = {};
const options: Keychain.Options = {};
const keychainServicePassword: boolean | {
service: string;
username: string;
password: string;
} = await Keychain.getGenericPassword(service);
const keychainPassword: boolean | {
service: string;
username: string;
password: string;
} = await Keychain.getGenericPassword();
const keychainServerPassword: Keychain.UserCredentials = await Keychain.getInternetCredentials(server);
const keychainSharedWebPassword: Keychain.SharedWebCredentials = await Keychain.requestSharedWebCredentials();
const keychainResetGenericPassword: boolean = await Keychain.resetGenericPassword(serviceOrOptions);
const keychainSetGenericPassword: boolean = await Keychain.setGenericPassword(username, password, options);
const keychainSetServerPassword: boolean = await Keychain.setInternetCredentials(server, username, password, serviceOrOptions);
const keychainSetSharedWebPassword: boolean = await Keychain.setSharedWebCredentials(server, username, password);
const canImplyAuthentication: boolean = await Keychain.canImplyAuthentication(serviceOrOptions);
const supportedBiometryType: string | null = await Keychain.getSupportedBiometryType();
};

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strictFunctionTypes": true
},
"files": [
"index.d.ts",
"react-native-keychain-tests.ts"
]
}

View File

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