Skip to content
This repository was archived by the owner on Sep 17, 2019. It is now read-only.

Convert JS code to TypeScript #9

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
node_modules/
npm-debug.log
yarn-error.log

# build output

index.js
index.d.ts


# Xcode
Expand All @@ -29,4 +34,3 @@ DerivedData
*.ipa
*.xcuserstate
project.xcworkspace

6 changes: 0 additions & 6 deletions index.js

This file was deleted.

201 changes: 201 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import { NativeModules, requireNativeComponent } from 'react-native';
import { ComponentType } from 'react';

export interface SignInWithAppleOptions {
/**
* The scopes that you are requesting. Supply an array. Defaults to an empty array (no scopes).
*/
requestedScopes?: SignInWithAppleScope[];

/**
* The operation that you would like to perform.
*/
requestedOperation?: SignInWithAppleOperation;

/**
* Typically you leave this property set to nil the first time you authenticate a user.
* Otherwise, if you previously received an SignInWithAppleCredential set this property to the value from the user property.
* Must be set for Refresh and Logout operations.
*/
user?: string;

/**
* Data that’s returned to you unmodified in the corresponding credential after a successful authentication.
* Used to verify that the response was from the request you made. Can be used to avoid replay attacks.
*/
state?: string;
}

export interface SignInWithAppleCredential {
/**
* A JSON Web Token (JWT) that securely communicates information about the user to your app.
*/
identityToken: string;

/**
* A short-lived token used by your app for proof of authorization when interacting with the app’s server counterpart.
*/
authorizationCode: string;

/**
* An arbitrary string that your app provided to the request that generated the credential.
* You can set this in SignInWithAppleOptions.
*/
user: string;

/**
* An identifier associated with the authenticated user.
* You can use this to check if the user is still authenticated later.
* This is stable and can be shared across apps released under the same development team.
* The same user will have a different identifier for apps released by other developers.
*/
state?: string;

/**
* The contact information the user authorized your app to access.
*/
authorizedScopes: SignInWithAppleScope[];

/**
* The user’s name. Might not present if you didn't request access or if the user denied access.
*/
fullName?: string;

/**
* The user’s email address. Might not present if you didn't request access or if the user denied access.
*/
email?: string;

/**
* A value that indicates whether the user appears to be a real person.
*/
realUserStatus: SignInWithAppleUserDetectionStatus;
}

export interface SignInWithAppleScopes {
/**
* A scope that includes the user’s full name.
*/
FULL_NAME: string;

/**
* A scope that includes the user’s email address.
*/
EMAIL: string;
}

export type SignInWithAppleScope = keyof SignInWithAppleScopes;

export interface SignInWithAppleOperations {
/**
* An operation used to authenticate a user.
*/
LOGIN: string;

/**
* An operation that ends an authenticated session.
*/
LOGOUT: string;

/**
* An operation that refreshes the logged-in user’s credentials.
*/
REFRESH: string;

/**
* An operation that depends on the particular kind of credential provider.
*/
IMPLICIT: string;
}

export type SignInWithAppleOperation = keyof SignInWithAppleOperations;

export interface SignInWithAppleUserDetectionStatuses {
/**
* The user appears to be a real person.
*/
LIKELY_REAL: string;

/**
* The system hasn’t determined whether the user might be a real person.
*/
UNKNOWN: string;

/**
* The system can’t determine this user’s status as a real person.
*/
UNSUPPORTED: string;
}

export type SignInWithAppleUserDetectionStatus = keyof SignInWithAppleUserDetectionStatuses;


export interface ISignInWithApple {
/**
* Perform a Sign In with Apple request with the given SignInWithAppleOptions.
* The method will return a Promise which will resolve to a SignInWithAppleCredential on success.
* You should make sure you include error handling.
*/
requestAsync: (signInWithAppleOptions: SignInWithAppleOptions) => Promise<SignInWithAppleCredential>;
/**
* Controls which scopes you are requesting when the call SignInWithApple.requestAsync().
*/
Scope: SignInWithAppleScopes;
/**
* Controls what operation you are requesting when the call SignInWithApple.requestAsync().
*/
Operation: SignInWithAppleOperations;
/**
* A value that indicates whether the user appears to be a real person.
* You get this in the realUserStatus property of a SignInWithAppleCredential object.
* It can be used as one metric to help prevent fraud.
*/
UserDetectionStatus: SignInWithAppleUserDetectionStatuses;
}

export const SignInWithApple: ISignInWithApple = NativeModules.RNCAppleAuthentication;

export interface SignInWithAppleButtonProps {
/**
* The callback which is called when the user pressed the button.
*/
onPress: () => void;

/**
* Controls the text that is shown on the button.
*/
type?: SignInWithAppleButtonType;

/**
* Controls the style of the button.
*/
style?: SignInWithAppleButtonStyle;

/**
* The radius of the corners of the button.
*/
cornerRadius?: number;
}

export interface SignInWithAppleButtonTypes {
DEFAULT: string;
SIGN_UP: string;
CONTINUE: string;
}

export type SignInWithAppleButtonType = keyof SignInWithAppleButtonTypes;

export interface SignInWithAppleButtonStyles {
BLACK: string;
WHITE: string;
WHITE_OUTLINE: string;
}

export type SignInWithAppleButtonStyle = keyof SignInWithAppleButtonStyles;

export type ISignInWithAppleButton = ComponentType<SignInWithAppleButtonProps> & {
Type: SignInWithAppleButtonTypes;
Style: SignInWithAppleButtonStyles;
}

export const SignInWithAppleButton: ISignInWithAppleButton = requireNativeComponent('RNCSignInWithAppleButton');
46 changes: 46 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"
},
"keywords": [
"react-native"
Expand All @@ -13,5 +14,9 @@
"license": "MIT",
"peerDependencies": {
"react-native": "^0.59.9"
},
"devDependencies": {
"@types/react-native": "^0.60.11",
"typescript": "^3.6.2"
}
}
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"files": [
"./index.ts"
],
"compilerOptions": {
"target": "es6",
"module": "es2015",
"lib": ["es2015"],
"moduleResolution": "node",
"strict": true,
"declaration": true
}
}