mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
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:
committed by
Andy
parent
e94c84bd5e
commit
4df7adcb42
87
types/react-native-keychain/index.d.ts
vendored
Normal file
87
types/react-native-keychain/index.d.ts
vendored
Normal 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>;
|
||||
39
types/react-native-keychain/react-native-keychain-tests.ts
Normal file
39
types/react-native-keychain/react-native-keychain-tests.ts
Normal 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();
|
||||
};
|
||||
23
types/react-native-keychain/tsconfig.json
Normal file
23
types/react-native-keychain/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/react-native-keychain/tslint.json
Normal file
1
types/react-native-keychain/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user