Skip to content

[MOB-11549] creates iterableEmbeddedMetadata class #641

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

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,36 @@ public void updateVisibleRows(ReadableArray visibleRows) {
// ---------------------------------------------------------------------------------------
// endregion

// ---------------------------------------------------------------------------------------
// region Embedded APIs

@ReactMethod
public void getEmbeddedPlacements(Promise promise) {
IterableLogger.d(TAG, "getEmbeddedPlacements");

JSONArray testPlacements = new JSONArray();
int[] testPlacementIds = {808, 1121, 112};

try {
for (int placementId : testPlacementIds) {
testPlacements.put(createTestPlacement(placementId));
}

promise.resolve(Serialization.convertJsonToArray(testPlacements));
} catch (JSONException e) {
promise.reject("", "Failed to create test placements");
}
}

private JSONObject createTestPlacement(int placementId) throws JSONException {
JSONObject placement = new JSONObject();
placement.put("placementId", placementId);
return placement;
}

// ---------------------------------------------------------------------------------------
// endregion

// ---------------------------------------------------------------------------------------
// region Private Serialization Functions

Expand Down
5 changes: 5 additions & 0 deletions ios/RNIterableAPI/RNIterableAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ @interface RCT_EXTERN_REMAP_MODULE(RNIterableAPI, ReactIterableAPI, NSObject)

RCT_EXTERN_METHOD(updateVisibleRows: (nonnull NSArray *) visibleRows)

// MARK: - SDK Embedded Manager Functions

RCT_EXTERN_METHOD(getEmbeddedPlacements: (RCTPromiseResolveBlock) resolve
rejecter: (RCTPromiseRejectBlock) reject)

// MARK: - SDK Auth Manager Functions

RCT_EXTERN_METHOD(passAlongAuthToken: (NSString *) authToken)
Expand Down
18 changes: 17 additions & 1 deletion ios/RNIterableAPI/ReactIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,22 @@ class ReactIterableAPI: RCTEventEmitter {

inboxSessionManager.updateVisibleRows(visibleRows: serializedRows)
}

// MARK: - SDK Embedded Manager Functions

@objc(getEmbeddedPlacements:rejecter:)
func getEmbeddedPlacements(resolver: @escaping RCTPromiseResolveBlock,
rejecter: @escaping RCTPromiseRejectBlock) {
ITBInfo()

// Create test data
let testPlacements: [[String: Any]] = [
["placementId": "meow"],
["placementId": "woof woof"]
]

resolver(testPlacements)
}

// MARK: - SDK Auth Manager Functions

Expand All @@ -481,7 +497,7 @@ class ReactIterableAPI: RCTEventEmitter {

authHandlerSemaphore.signal()
}

// MARK: Private
private var shouldEmit = false
private let _methodQueue = DispatchQueue(label: String(describing: ReactIterableAPI.self))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iterable/react-native-sdk",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.1-rc.19",
"description": "Iterable SDK for React Native.",
"source": "./src/index.tsx",
"main": "./lib/module/index.js",
Expand Down
58 changes: 58 additions & 0 deletions src/__tests__/IterableEmbeddedMessageMetadata.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { IterableEmbeddedMessageMetadata } from '../embedded/classes/IterableEmbeddedMessageMetadata';
Copy link

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]

Copy link

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]

Copy link

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 { Iterable } from '../core';

describe('IterableEmbeddedMessage', () => {
test('should create an instance of IterableEmbeddedMessageMetadata from a dictionary', () => {
Iterable.logger.log(
'iterableEmbeddedMessageMetadata_fromDict_valid_dictionary'
);

const dict = {
messageId: '123',
placementId: 456,
campaignId: 789,
isProof: false,
};

const result = IterableEmbeddedMessageMetadata.fromDict(dict);

expect(result).toBeInstanceOf(IterableEmbeddedMessageMetadata);
expect(result.messageId).toBe('123');
expect(result.placementId).toBe(456);
expect(result.campaignId).toBe(789);
expect(result.isProof).toBe(false);
});

test('should handle optional fields', () => {
Iterable.logger.log(
'iterableEmbeddedMessageMetadata_fromDict_optional_fields_omitted'
);

const dict = {
messageId: '123',
placementId: 456,
};

const result = IterableEmbeddedMessageMetadata.fromDict(dict);

expect(result).toBeInstanceOf(IterableEmbeddedMessageMetadata);
expect(result.messageId).toBe('123');
expect(result.placementId).toBe(456);
expect(result.campaignId).toBeUndefined();
expect(result.isProof).toBe(false);
});

test('should throw an error if messageId is not provided', () => {
Iterable.logger.log(
'iterableEmbeddedMessageMetadata_fromDict_missing_messageId'
);

const dict = {
placementId: 456,
};

expect(() => {
IterableEmbeddedMessageMetadata.fromDict(dict);
}).toThrow('messageId and placementId are required');
});
});
24 changes: 24 additions & 0 deletions src/embedded/classes/IterableEmbeddedManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NativeModules } from 'react-native';
Copy link

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]

Copy link

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 { Iterable } from '../../core/classes/Iterable';
import { IterableEmbeddedPlacement } from './IterableEmbeddedPlacement';

const RNIterableAPI = NativeModules.RNIterableAPI;

/**
* Manages embedded messages for the current user.
*
* This class provides methods to interact with embedded messages, including retrieving placements.
*/
export class IterableEmbeddedManager {
/**
* Retrieve the current user's list of embedded placements.
*
* @returns A Promise that resolves to an array of embedded placements.
*/
getPlacements(): Promise<IterableEmbeddedPlacement[]> {
Iterable?.logger?.log('EmbeddedManager.getPlacements');

return RNIterableAPI.getEmbeddedPlacements();
}
}
65 changes: 65 additions & 0 deletions src/embedded/classes/IterableEmbeddedMessageMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
Copy link

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]

Copy link

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]

Copy link

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]

* Metadata for an embedded message.
*/
export class IterableEmbeddedMessageMetadata {
/** The ID for the embedded message */
readonly messageId: string;
/** The placement ID for the embedded message */
readonly placementId: number;
/** The campaign ID for the embedded message */
readonly campaignId?: number;
/** Whether the embedded message is a proof */
readonly isProof: boolean;

/**
* Constructs an instance of IterableEmbeddedMessageMetadata.
*
* @param messageId - The ID for the embedded message.
* @param placementId - The placement ID for the embedded message.
* @param campaignId - The campaign ID for the embedded message.
* @param isProof - Whether the embedded message is a proof.
*/
constructor(
messageId: string,
placementId: number,
campaignId: number | undefined,
isProof: boolean = false
Comment on lines +22 to +26
Copy link

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 = 4): constructor [qlty:function-parameters]

Comment on lines +22 to +26
Copy link

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 = 4): constructor [qlty:function-parameters]

Comment on lines +22 to +26
Copy link

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 = 4): constructor [qlty:function-parameters]

) {
this.messageId = messageId;
this.placementId = placementId;
this.campaignId = campaignId;
this.isProof = isProof;
}

/**
* Creates an instance of `IterableEmbeddedMessageMetadata` from a dictionary object.
*
* @param dict - The dictionary objectcontaining the metadata properties.
* This corresponds to the properties in {@link IterableEmbeddedMessageMetadata}
*
* @returns A new instance of `IterableEmbeddedMessageMetadata` with the provided properties.
*/
static fromDict(
dict: Partial<EmbeddedMessageMetadataDict>
): IterableEmbeddedMessageMetadata {
if (!dict.messageId || !dict.placementId) {
throw new Error('messageId and placementId are required');
}
return new IterableEmbeddedMessageMetadata(
dict.messageId,
dict.placementId,
dict.campaignId,
dict.isProof
);
}
}

/**
* An interface defining the dictionary object containing the metadata properties for an embedded message.
*/
export interface EmbeddedMessageMetadataDict {
messageId: string;
placementId: number;
campaignId?: number;
isProof?: boolean;
}
11 changes: 11 additions & 0 deletions src/embedded/classes/IterableEmbeddedPlacement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
Copy link

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]

Copy link

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]

* Iterable embedded placement
* Contains placement id and the associated embedded messages
*/
export class IterableEmbeddedPlacement {
readonly placementId: number;

constructor(placementId: number) {
this.placementId = placementId;
}
}
2 changes: 2 additions & 0 deletions src/embedded/classes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './IterableEmbeddedManager';
Copy link

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]

Copy link

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]

export * from './IterableEmbeddedPlacement';
1 change: 1 addition & 0 deletions src/embedded/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './classes';
Copy link

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]

Copy link

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]

2 changes: 1 addition & 1 deletion src/inApp/classes/IterableInAppManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class IterableInAppManager {
* });
* ```
*
* @param message - The message to show (an {@link_IterableInAppMessage} object)
* @param message - The message to show (an {@link IterableInAppMessage} object)
* @param consume - Whether or not the message should be consumed from the user's message queue after being shown. This should be defaulted to true.
*
* @returns A Promise that resolves to the URL of the button or link the user tapped to close the in-app message.
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export {
type IterableDeviceOrientation,
} from './core/hooks';
export { type IterableEdgeInsetDetails } from './core/types';
export { IterableEmbeddedManager, IterableEmbeddedPlacement } from './embedded';
export {
IterableHtmlInAppContent,
IterableInAppCloseSource,
Expand Down
2 changes: 1 addition & 1 deletion src/itblBuildInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* It contains the version of the package
*/
export const buildInfo = {
version: '2.0.0-beta.1',
version: '2.0.0-beta.1-rc.19',
};
Loading