Skip to content
Merged
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
2 changes: 1 addition & 1 deletion example/src/components/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const Login = ({ navigation }: RootStackScreenProps<Route.Login>) => {
<TextInput
style={styles.input}
onChangeText={setUserId}
value={userId}
value={userId ?? ''}
placeholder="eg: [email protected] or 1234567890"
autoCapitalize="none"
autoCorrect={false}
Expand Down
10 changes: 5 additions & 5 deletions example/src/hooks/useIterableApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface IterableAppProps {
/** Sets the user ID for the user */
setUserId: (value: string) => void;
/** The user ID for the user */
userId?: string;
userId?: string | null;
}

const IterableAppContext = createContext<IterableAppProps>({
Expand All @@ -79,7 +79,7 @@ const IterableAppContext = createContext<IterableAppProps>({
setLoginInProgress: () => undefined,
setReturnToInboxTrigger: () => undefined,
setUserId: () => undefined,
userId: undefined,
userId: null,
});

const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
Expand All @@ -96,7 +96,7 @@ export const IterableAppProvider: FunctionComponent<
const [apiKey, setApiKey] = useState<string | undefined>(
process.env.ITBL_API_KEY
);
const [userId, setUserId] = useState<string | undefined>(process.env.ITBL_ID);
const [userId, setUserId] = useState<string | null>(process.env.ITBL_ID ?? null);
const [loginInProgress, setLoginInProgress] = useState<boolean>(false);

const getUserId = useCallback(() => userId ?? process.env.ITBL_ID, [userId]);
Expand Down Expand Up @@ -196,8 +196,8 @@ export const IterableAppProvider: FunctionComponent<
);

const logout = useCallback(() => {
Iterable.setEmail(undefined);
Iterable.setUserId(undefined);
Iterable.setEmail(null);
Iterable.setUserId(null);
setIsLoggedIn(false);
}, []);

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@
]
},
"codegenConfig": {
"name": "RNIterableSpec",
"name": "RNIterableAPISpec",
"type": "modules",
"jsSrcsDir": "src",
"jsSrcsDir": "src/api/",
"android": {
"javaPackageName": "com.iterable.reactnative"
}
Expand Down
140 changes: 140 additions & 0 deletions src/api/NativeRNIterableAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import type { TurboModule } from 'react-native';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

import { TurboModuleRegistry } from 'react-native';

export interface Spec extends TurboModule {
// Initialization
initializeWithApiKey(
apiKey: string,
config: { [key: string]: string | number | boolean | undefined | string[] },
version: string
): Promise<boolean>;

initialize2WithApiKey(
apiKey: string,
config: { [key: string]: string | number | boolean | undefined | string[] },
apiEndPointOverride: string,
version: string
): Promise<boolean>;

// User management
setEmail(email: string | null, authToken?: string | null): void;
getEmail(): Promise<string | null>;
setUserId(userId?: string | null, authToken?: string | null): void;
getUserId(): Promise<string | null | undefined>;

// In-app messaging
setInAppShowResponse(number: number): void;
getInAppMessages(): Promise<{ [key: string]: string | number | boolean }[]>;
getInboxMessages(): Promise<{ [key: string]: string | number | boolean }[]>;
getUnreadInboxMessagesCount(): Promise<number>;
showMessage(messageId: string, consume: boolean): Promise<string | null>;
removeMessage(messageId: string, location: number, source: number): void;
setReadForMessage(messageId: string, read: boolean): void;
setAutoDisplayPaused(autoDisplayPaused: boolean): void;

// Tracking
trackEvent(
name: string,
dataFields?: { [key: string]: string | number | boolean }
): void;
trackPushOpenWithCampaignId(
campaignId: number,
templateId: number | null,
messageId: string,
appAlreadyRunning: boolean,
dataFields?: { [key: string]: string | number | boolean }
): void;
trackInAppOpen(messageId: string, location: number): void;
trackInAppClick(
messageId: string,
location: number,
clickedUrl: string
): void;
trackInAppClose(
messageId: string,
location: number,
source: number,
clickedUrl?: string
): void;
inAppConsume(messageId: string, location: number, source: number): void;

// Commerce
updateCart(items: { [key: string]: string | number | boolean }[]): void;
trackPurchase(
total: number,
items: { [key: string]: string | number | boolean }[],
dataFields?: { [key: string]: string | number | boolean }
): void;

// User data
updateUser(
dataFields: { [key: string]: string | number | boolean },
mergeNestedObjects: boolean
): void;
updateEmail(email: string, authToken?: string): void;

// Attribution
getAttributionInfo(): Promise<{
[key: string]: string | number | boolean;
} | null>;
setAttributionInfo(
dict: { [key: string]: string | number | boolean } | null
): void;

// Device management
disableDeviceForCurrentUser(): void;
getLastPushPayload(): Promise<{
[key: string]: string | number | boolean;
} | null>;

// Content
getHtmlInAppContentForMessage(
messageId: string
): Promise<{ [key: string]: string | number | boolean }>;

// App links
handleAppLink(appLink: string): Promise<boolean>;

// Subscriptions
updateSubscriptions(
emailListIds: number[] | null,
unsubscribedChannelIds: number[] | null,
unsubscribedMessageTypeIds: number[] | null,
subscribedMessageTypeIds: number[] | null,
campaignId: number,
templateId: number
): void;

// Session tracking
startSession(
visibleRows: { [key: string]: string | number | boolean }[]
): void;
endSession(): void;
updateVisibleRows(
visibleRows: { [key: string]: string | number | boolean }[]
): void;

// Auth
passAlongAuthToken(authToken?: string | null): void;

// Wake app -- android only
wakeApp(): void;


// REQUIRED for RCTEventEmitter
addListener(eventName: string): void;
removeListeners(count: number): void;
}

// Check if we're in a test environment
const isTestEnvironment = () => {
return (
typeof jest !== 'undefined' ||
process.env.NODE_ENV === 'test' ||
process.env.JEST_WORKER_ID !== undefined
);
};

export default isTestEnvironment()
? undefined
: TurboModuleRegistry.getEnforcing<Spec>('RNIterableAPI');
6 changes: 6 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { NativeModules } from 'react-native';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

import BridgelessModule from './NativeRNIterableAPI';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where the BridgelessModule specifically comes from.


export const RNIterableAPI = BridgelessModule ?? NativeModules.RNIterableAPI;

export default RNIterableAPI;
39 changes: 19 additions & 20 deletions src/core/classes/Iterable.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
Linking,
NativeEventEmitter,
NativeModules,
Platform,
} from 'react-native';

import { buildInfo } from '../../itblBuildInfo';

import { RNIterableAPI } from '../../api';
// TODO: Organize these so that there are no circular dependencies
// See https://github.com/expo/expo/issues/35100
import { IterableInAppMessage } from '../../inApp/classes/IterableInAppMessage';
Expand All @@ -23,7 +23,6 @@ import type { IterableCommerceItem } from './IterableCommerceItem';
import { IterableConfig } from './IterableConfig';
import { IterableLogger } from './IterableLogger';

const RNIterableAPI = NativeModules.RNIterableAPI;
const RNEventEmitter = new NativeEventEmitter(RNIterableAPI);

/* eslint-disable tsdoc/syntax */
Expand Down Expand Up @@ -181,7 +180,7 @@ export class Iterable {
* Iterable.setEmail('[email protected]');
* ```
*/
static setEmail(email?: string | null, authToken?: string | null) {
static setEmail(email: string | null, authToken?: string | null) {
Iterable?.logger?.log('setEmail: ' + email);

RNIterableAPI.setEmail(email, authToken);
Expand All @@ -197,7 +196,7 @@ export class Iterable {
* });
* ```
*/
static getEmail(): Promise<string | undefined> {
static getEmail(): Promise<string | null> {
Iterable?.logger?.log('getEmail');

return RNIterableAPI.getEmail();
Expand Down Expand Up @@ -262,7 +261,7 @@ export class Iterable {
* });
* ```
*/
static getUserId(): Promise<string | undefined> {
static getUserId(): Promise<string | null | undefined> {
Iterable?.logger?.log('getUserId');

return RNIterableAPI.getUserId();
Expand Down Expand Up @@ -325,12 +324,12 @@ export class Iterable {
Iterable?.logger?.log('getAttributionInfo');

return RNIterableAPI.getAttributionInfo().then(
(dict?: IterableAttributionInfo) => {
(dict: { campaignId: number; templateId: number; messageId: string } | null) => {
if (dict) {
return new IterableAttributionInfo(
dict.campaignId,
dict.templateId,
dict.messageId
dict.campaignId as number,
dict.templateId as number,
dict.messageId as string
);
} else {
return undefined;
Expand Down Expand Up @@ -366,7 +365,7 @@ export class Iterable {
static setAttributionInfo(attributionInfo?: IterableAttributionInfo) {
Iterable?.logger?.log('setAttributionInfo');

RNIterableAPI.setAttributionInfo(attributionInfo);
RNIterableAPI.setAttributionInfo(attributionInfo as unknown as { [key: string]: string | number | boolean; } | null);
}

/**
Expand Down Expand Up @@ -410,9 +409,9 @@ export class Iterable {
RNIterableAPI.trackPushOpenWithCampaignId(
campaignId,
templateId,
messageId,
messageId as string,
appAlreadyRunning,
dataFields
dataFields as { [key: string]: string | number | boolean } | undefined
);
}

Expand Down Expand Up @@ -445,7 +444,7 @@ export class Iterable {
static updateCart(items: IterableCommerceItem[]) {
Iterable?.logger?.log('updateCart');

RNIterableAPI.updateCart(items);
RNIterableAPI.updateCart(items as unknown as { [key: string]: string | number | boolean }[]);
}

/**
Expand Down Expand Up @@ -497,7 +496,7 @@ export class Iterable {
) {
Iterable?.logger?.log('trackPurchase');

RNIterableAPI.trackPurchase(total, items, dataFields);
RNIterableAPI.trackPurchase(total, items as unknown as { [key: string]: string | number | boolean }[], dataFields as { [key: string]: string | number | boolean } | undefined);
}

/**
Expand Down Expand Up @@ -666,7 +665,7 @@ export class Iterable {
static trackEvent(name: string, dataFields?: unknown) {
Iterable?.logger?.log('trackEvent');

RNIterableAPI.trackEvent(name, dataFields);
RNIterableAPI.trackEvent(name, dataFields as { [key: string]: string | number | boolean } | undefined);
}

/**
Expand Down Expand Up @@ -714,7 +713,7 @@ export class Iterable {
) {
Iterable?.logger?.log('updateUser');

RNIterableAPI.updateUser(dataFields, mergeNestedObjects);
RNIterableAPI.updateUser(dataFields as { [key: string]: string | number | boolean }, mergeNestedObjects);
}

/**
Expand Down Expand Up @@ -859,10 +858,10 @@ export class Iterable {
* ```
*/
static updateSubscriptions(
emailListIds: number[] | undefined,
unsubscribedChannelIds: number[] | undefined,
unsubscribedMessageTypeIds: number[] | undefined,
subscribedMessageTypeIds: number[] | undefined,
emailListIds: number[] | null,
unsubscribedChannelIds: number[] | null,
unsubscribedMessageTypeIds: number[] | null,
subscribedMessageTypeIds: number[] | null,
campaignId: number,
templateId: number
Comment on lines 860 to 866

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with many parameters (count = 6): updateSubscriptions [qlty:function-parameters]

Comment on lines 860 to 866

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with many parameters (count = 6): updateSubscriptions [qlty:function-parameters]

) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/classes/IterableAuthResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
export class IterableAuthResponse {
/** JWT Token */
authToken?: string = '';
authToken?: string | null = '';
/** Callback when the authentication to Iterable succeeds */
successCallback?: () => void;
/** Callback when the authentication to Iterable fails */
Expand Down
Loading