-
Notifications
You must be signed in to change notification settings - Fork 39
Mob 10946 ts layer #723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Mob 10946 ts layer #723
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
zipStorePath=wrapper/dists |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import { | |
|
||
import { Route } from '../constants/routes'; | ||
import type { RootStackParamList } from '../types/navigation'; | ||
import type { IterableAuthFailure } from '../../../src/core'; | ||
|
||
type Navigation = StackNavigationProp<RootStackParamList>; | ||
|
||
|
@@ -149,6 +150,15 @@ export const IterableAppProvider: FunctionComponent< | |
|
||
config.inAppHandler = () => IterableInAppShowResponse.show; | ||
|
||
config.authHandler = () => { | ||
console.log('!!!Auth is being requested!!! and app is going to pass null'); | ||
return Promise.resolve({authToken:"SomethingNotValid"}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
config.onJWTError = (err: IterableAuthFailure) => { | ||
console.log('!!!JWT Error!!! '+ err.failureReason.toString(), err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
setItblConfig(config); | ||
|
||
const key = apiKey ?? process.env.ITBL_API_KEY; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import type { IterableCommerceItem } from './IterableCommerceItem'; | |
import { IterableConfig } from './IterableConfig'; | ||
import { IterableLogger } from './IterableLogger'; | ||
import { RNIterableAPI } from './RNIterableAPI'; | ||
import type { IterableAuthFailure } from '../types'; | ||
|
||
const RNEventEmitter = new NativeEventEmitter(RNIterableAPI); | ||
|
||
|
@@ -952,12 +953,16 @@ export class Iterable { | |
RNEventEmitter.addListener(IterableEventName.handleAuthCalled, () => { | ||
// MOB-10423: Check if we can use chain operator (?.) here instead | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
//This is where RN SDK asks front end of the client/app to pass authToken | ||
Iterable.savedConfig.authHandler!() | ||
.then((promiseResult) => { | ||
// Promise result can be either just String OR of type AuthResponse. | ||
// If type AuthReponse, authToken will be parsed looking for `authToken` within promised object. Two additional listeners will be registered for success and failure callbacks sent by native bridge layer. | ||
// Else it will be looked for as a String. | ||
if (typeof promiseResult === typeof new IterableAuthResponse()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// Set authToken at bridge layer | ||
RNIterableAPI.passAlongAuthToken( | ||
(promiseResult as IterableAuthResponse).authToken | ||
); | ||
|
@@ -972,6 +977,9 @@ export class Iterable { | |
} else if ( | ||
authResponseCallback === IterableAuthResponseResult.FAILURE | ||
) { | ||
// We are currently only reporting JWT related errors. In | ||
// the future, we should handle other types of errors as | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// well. | ||
if ((promiseResult as IterableAuthResponse).failureCallback) { | ||
(promiseResult as IterableAuthResponse).failureCallback?.(); | ||
} | ||
|
@@ -997,10 +1005,16 @@ export class Iterable { | |
authResponseCallback = IterableAuthResponseResult.SUCCESS; | ||
} | ||
); | ||
|
||
RNEventEmitter.addListener( | ||
IterableEventName.handleAuthFailureCalled, | ||
() => { | ||
(authFailureResponse: IterableAuthFailure) => { | ||
// This line will just mark the flag for above listener to indicate something failed | ||
// catch(err) will only indicate failure on high level. No actions should be taken inside catch(err) | ||
authResponseCallback = IterableAuthResponseResult.FAILURE; | ||
|
||
// This line will call the actual JWT error with authFailure objec | ||
Iterable.savedConfig?.onJWTError?.(authFailureResponse); | ||
} | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,7 +7,7 @@ import { | |||||||||
import { IterableAction } from './IterableAction'; | ||||||||||
import type { IterableActionContext } from './IterableActionContext'; | ||||||||||
import type { IterableAuthResponse } from './IterableAuthResponse'; | ||||||||||
|
||||||||||
import type { IterableAuthFailure } from '../types/IterableAuthFailure'; | ||||||||||
/** | ||||||||||
* An IterableConfig object sets various properties of the SDK. | ||||||||||
* | ||||||||||
|
@@ -203,7 +203,16 @@ export class IterableConfig { | |||||||||
* @returns A promise that resolves to an `IterableAuthResponse`, a `string`, | ||||||||||
* or `undefined`. | ||||||||||
*/ | ||||||||||
authHandler?: () => Promise<IterableAuthResponse | string | undefined>; | ||||||||||
authHandler?: () => Promise<IterableAuthResponse | string | IterableAuthFailure | undefined>; | ||||||||||
|
||||||||||
Comment on lines
+206
to
+207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace
Suggested change
|
||||||||||
/** | ||||||||||
* A callback function that is called when the SDK encounters an error while | ||||||||||
* validing the JWT. | ||||||||||
* | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
* The retry for JWT should be automatically handled by the native SDK, so | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
* this is just for logging/transparency purposes. | ||||||||||
*/ | ||||||||||
onJWTError?: (authFailure: IterableAuthFailure) => void; | ||||||||||
|
||||||||||
/** | ||||||||||
* Set the verbosity of Android and iOS project's log system. | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* The reason for the failure of an authentication attempt. | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* This is generally related to JWT token validation. | ||
*/ | ||
export enum IterableAuthFailureReason { | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* An auth token's expiration must be less than one year from its issued-at | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* time. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
*/ | ||
AUTH_TOKEN_EXPIRATION_INVALID, | ||
/** The token has expired. */ | ||
AUTH_TOKEN_EXPIRED, | ||
/** Token has an invalid format (failed a regular expression check). */ | ||
AUTH_TOKEN_FORMAT_INVALID, | ||
/** `onAuthTokenRequested` threw an exception. */ | ||
AUTH_TOKEN_GENERATION_ERROR, | ||
/** Any other error not captured by another constant. */ | ||
AUTH_TOKEN_GENERIC_ERROR, | ||
/** Iterable has invalidated this token and it cannot be used. */ | ||
AUTH_TOKEN_INVALIDATED, | ||
/** The request to Iterable's API did not include a JWT authorization header. */ | ||
AUTH_TOKEN_MISSING, | ||
/** `onAuthTokenRequested` returned a null JWT token. */ | ||
AUTH_TOKEN_NULL, | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* Iterable could not decode the token's payload (`iat`, `exp`, `email`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* or `userId`). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
*/ | ||
AUTH_TOKEN_PAYLOAD_INVALID, | ||
/** Iterable could not validate the token's authenticity. */ | ||
AUTH_TOKEN_SIGNATURE_INVALID, | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* The token doesn't include an `email` or a `userId`. Or, one of these | ||
* values is included, but it references a user that isn't in the Iterable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* project. | ||
*/ | ||
AUTH_TOKEN_USER_KEY_INVALID, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||
import type { IterableAuthFailureReason } from "../enums/IterableAuthFailureReason"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found 2 issues:
Suggested change
|
||||||
|
||||||
/** | ||||||
* Represents an auth failure object. | ||||||
*/ | ||||||
export interface IterableAuthFailure { | ||||||
/** userId or email of the signed-in user */ | ||||||
userKey: string; | ||||||
|
||||||
/** the authToken which caused the failure */ | ||||||
failedAuthToken: string; | ||||||
|
||||||
/** the timestamp of the failed request */ | ||||||
failedRequestTime: number; | ||||||
|
||||||
/** indicates a reason for failure */ | ||||||
failureReason: IterableAuthFailureReason; | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './IterableEdgeInsetDetails'; | ||
export * from './IterableAuthFailure'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace
'!!!Auth·is·being·requested!!!·and·app·is·going·to·pass·null'
with⏎··········'!!!Auth·is·being·requested!!!·and·app·is·going·to·pass·null'⏎········
[eslint:prettier/prettier]