Skip to content

Commit 8e551bc

Browse files
committed
Refactor config API
Removed builder and added static create methods
1 parent 9059b21 commit 8e551bc

File tree

4 files changed

+126
-67
lines changed

4 files changed

+126
-67
lines changed

js/index.d.ts

Lines changed: 108 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
Rokt,
3-
RoktConfigBuilder,
4-
CacheConfig,
5-
IRoktConfig,
6-
ColorMode,
7-
} from './rokt/rokt';
1+
import { Rokt, CacheConfig, IRoktConfig, ColorMode } from './rokt/rokt';
82
import RoktLayoutView, { RoktLayoutViewProps } from './rokt/rokt-layout-view';
93

104
// ******** Types ********
@@ -57,16 +51,16 @@ export declare const EventType: {
5751
};
5852

5953
export declare const UserAttributeType: {
60-
readonly FirstName: "$FirstName";
61-
readonly LastName: "$LastName";
62-
readonly Address: "$Address";
63-
readonly State: "$State";
64-
readonly City: "$City";
65-
readonly Zipcode: "$Zip";
66-
readonly Country: "$Country";
67-
readonly Age: "$Age";
68-
readonly Gender: "$Gender";
69-
readonly MobileNumber: "$Mobile";
54+
readonly FirstName: '$FirstName';
55+
readonly LastName: '$LastName';
56+
readonly Address: '$Address';
57+
readonly State: '$State';
58+
readonly City: '$City';
59+
readonly Zipcode: '$Zip';
60+
readonly Country: '$Country';
61+
readonly Age: '$Age';
62+
readonly Gender: '$Gender';
63+
readonly MobileNumber: '$Mobile';
7064
};
7165

7266
export declare const UserIdentityType: {
@@ -126,30 +120,63 @@ export declare const ATTAuthStatus: {
126120
// ******** Main API ********
127121
export declare const upload: () => void;
128122
export declare const setUploadInterval: (uploadInterval: number) => void;
129-
export declare const logEvent: (eventName: string, type?: number, attributes?: CustomAttributes | null) => void;
123+
export declare const logEvent: (
124+
eventName: string,
125+
type?: number,
126+
attributes?: CustomAttributes | null
127+
) => void;
130128
export declare const logMPEvent: (event: Event) => void;
131129
export declare const logCommerceEvent: (commerceEvent: CommerceEvent) => void;
132-
export declare const logScreenEvent: (screenName: string, attributes?: CustomAttributes | null, shouldUploadEvent?: boolean) => void;
130+
export declare const logScreenEvent: (
131+
screenName: string,
132+
attributes?: CustomAttributes | null,
133+
shouldUploadEvent?: boolean
134+
) => void;
133135
export declare const setATTStatus: (status: number) => void;
134-
export declare const setATTStatusWithCustomTimestamp: (status: number, timestamp: number) => void;
136+
export declare const setATTStatusWithCustomTimestamp: (
137+
status: number,
138+
timestamp: number
139+
) => void;
135140
export declare const setOptOut: (optOut: boolean) => void;
136-
export declare const getOptOut: (completion: CompletionCallback<boolean>) => void;
137-
export declare const addGDPRConsentState: (newConsentState: GDPRConsent, purpose: string) => void;
138-
export declare const removeGDPRConsentStateWithPurpose: (purpose: string) => void;
139-
export declare const setCCPAConsentState: (newConsentState: CCPAConsent) => void;
141+
export declare const getOptOut: (
142+
completion: CompletionCallback<boolean>
143+
) => void;
144+
export declare const addGDPRConsentState: (
145+
newConsentState: GDPRConsent,
146+
purpose: string
147+
) => void;
148+
export declare const removeGDPRConsentStateWithPurpose: (
149+
purpose: string
150+
) => void;
151+
export declare const setCCPAConsentState: (
152+
newConsentState: CCPAConsent
153+
) => void;
140154
export declare const removeCCPAConsentState: () => void;
141-
export declare const isKitActive: (kitId: number, completion: CompletionCallback<boolean>) => void;
142-
export declare const getAttributions: (completion: CompletionCallback<AttributionResult>) => void;
143-
export declare const logPushRegistration: (registrationField1: string, registrationField2: string) => void;
144-
export declare const getSession: (completion: CompletionCallback<SessionInfo>) => void;
155+
export declare const isKitActive: (
156+
kitId: number,
157+
completion: CompletionCallback<boolean>
158+
) => void;
159+
export declare const getAttributions: (
160+
completion: CompletionCallback<AttributionResult>
161+
) => void;
162+
export declare const logPushRegistration: (
163+
registrationField1: string,
164+
registrationField2: string
165+
) => void;
166+
export declare const getSession: (
167+
completion: CompletionCallback<SessionInfo>
168+
) => void;
145169
export declare const setLocation: (latitude: number, longitude: number) => void;
146170

147171
// ******** Identity ********
148172
export declare class User {
149173
readonly userId: string;
150174
constructor(userId: string);
151175
getMpid(): string;
152-
setUserAttribute(key: string, value: string | string[] | number | boolean): void;
176+
setUserAttribute(
177+
key: string,
178+
value: string | string[] | number | boolean
179+
): void;
153180
setUserAttributeArray(key: string, value: string[]): void;
154181
getUserAttributes(completion: CompletionCallback<UserAttributes>): void;
155182
setUserTag(value: string): void;
@@ -170,11 +197,26 @@ export declare class IdentityRequest {
170197

171198
export declare class Identity {
172199
static getCurrentUser(completion: CompletionCallback<User>): void;
173-
static identify(identityRequest: IdentityRequest, completion: IdentityCallback): void;
174-
static login(identityRequest: IdentityRequest, completion: IdentityCallback): void;
175-
static logout(identityRequest: IdentityRequest, completion: IdentityCallback): void;
176-
static modify(identityRequest: IdentityRequest, completion: IdentityCallback): void;
177-
static aliasUsers(aliasRequest: AliasRequest, completion: CompletionCallback<void>): void;
200+
static identify(
201+
identityRequest: IdentityRequest,
202+
completion: IdentityCallback
203+
): void;
204+
static login(
205+
identityRequest: IdentityRequest,
206+
completion: IdentityCallback
207+
): void;
208+
static logout(
209+
identityRequest: IdentityRequest,
210+
completion: IdentityCallback
211+
): void;
212+
static modify(
213+
identityRequest: IdentityRequest,
214+
completion: IdentityCallback
215+
): void;
216+
static aliasUsers(
217+
aliasRequest: AliasRequest,
218+
completion: CompletionCallback<void>
219+
): void;
178220
}
179221

180222
// ******** Commerce ********
@@ -240,7 +282,13 @@ export declare class GDPRConsent {
240282
timestamp?: number;
241283
location?: string;
242284
hardwareId?: string;
243-
constructor(consented?: boolean, doc?: string, timestamp?: number, location?: string, hardwareId?: string);
285+
constructor(
286+
consented?: boolean,
287+
doc?: string,
288+
timestamp?: number,
289+
location?: string,
290+
hardwareId?: string
291+
);
244292
setConsented(consented: boolean): this;
245293
setDocument(doc: string): this;
246294
setTimestamp(timestamp: number): this;
@@ -254,7 +302,13 @@ export declare class CCPAConsent {
254302
timestamp?: number;
255303
location?: string;
256304
hardwareId?: string;
257-
constructor(consented?: boolean, doc?: string, timestamp?: number, location?: string, hardwareId?: string);
305+
constructor(
306+
consented?: boolean,
307+
doc?: string,
308+
timestamp?: number,
309+
location?: string,
310+
hardwareId?: string
311+
);
258312
setConsented(consented: boolean): this;
259313
setDocument(doc: string): this;
260314
setTimestamp(timestamp: number): this;
@@ -278,8 +332,15 @@ export declare class CommerceEvent {
278332
checkoutStep?: number;
279333
nonInteractive?: boolean;
280334
shouldUploadEvent?: boolean;
281-
static createProductActionEvent(productActionType: number, products: Product[], transactionAttributes?: TransactionAttributes): CommerceEvent;
282-
static createPromotionEvent(promotionActionType: number, promotions: Promotion[]): CommerceEvent;
335+
static createProductActionEvent(
336+
productActionType: number,
337+
products: Product[],
338+
transactionAttributes?: TransactionAttributes
339+
): CommerceEvent;
340+
static createPromotionEvent(
341+
promotionActionType: number,
342+
promotions: Promotion[]
343+
): CommerceEvent;
283344
static createImpressionEvent(impressions: Impression[]): CommerceEvent;
284345
setTransactionAttributes(transactionAttributes: TransactionAttributes): this;
285346
setProductActionType(productActionType: number): this;
@@ -326,7 +387,14 @@ export declare class MParticleError {
326387
}
327388

328389
// Export Rokt functionality
329-
export { Rokt, RoktConfigBuilder, CacheConfig, IRoktConfig, ColorMode, RoktLayoutView, RoktLayoutViewProps };
390+
export {
391+
Rokt,
392+
CacheConfig,
393+
IRoktConfig,
394+
ColorMode,
395+
RoktLayoutView,
396+
RoktLayoutViewProps,
397+
};
330398

331399
// Default export
332400
declare const _default: {
@@ -369,9 +437,8 @@ declare const _default: {
369437
Event: typeof Event;
370438
MParticleError: typeof MParticleError;
371439
Rokt: typeof Rokt;
372-
RoktConfigBuilder: typeof RoktConfigBuilder;
373440
CacheConfig: typeof CacheConfig;
374441
RoktLayoutView: typeof RoktLayoutView;
375442
};
376443

377-
export default _default;
444+
export default _default;

js/rokt/rokt.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ export abstract class Rokt {
2626
fontFilesMap
2727
);
2828
}
29+
30+
static createRoktConfig(colorMode?: ColorMode, cacheConfig?: CacheConfig) {
31+
return new RoktConfig(colorMode ?? 'system', cacheConfig);
32+
}
33+
34+
static createCacheConfig(
35+
cacheDurationInSeconds: number,
36+
cacheAttributes: Record<string, string>
37+
) {
38+
return new CacheConfig(cacheDurationInSeconds, cacheAttributes);
39+
}
2940
}
3041

3142
// Define the interface that matches the native module for cleaner code
@@ -49,29 +60,12 @@ export class CacheConfig {
4960
}
5061

5162
class RoktConfig implements IRoktConfig {
52-
constructor(roktConfig: RoktConfig) {
53-
Object.assign(this, roktConfig);
54-
}
55-
}
56-
57-
export class RoktConfigBuilder implements Partial<IRoktConfig> {
58-
readonly colorMode?: ColorMode;
59-
readonly cacheConfig?: CacheConfig;
60-
61-
public withColorMode(
62-
value: ColorMode
63-
): this & Pick<IRoktConfig, 'colorMode'> {
64-
return Object.assign(this, { colorMode: value });
65-
}
66-
67-
public withCacheConfig(
68-
value: CacheConfig
69-
): this & Pick<IRoktConfig, 'cacheConfig'> {
70-
return Object.assign(this, { cacheConfig: value });
71-
}
63+
public readonly colorMode: ColorMode;
64+
public readonly cacheConfig?: CacheConfig;
7265

73-
public build(this: IRoktConfig) {
74-
return new RoktConfig(this);
66+
constructor(colorMode: ColorMode, cacheConfig?: CacheConfig) {
67+
this.colorMode = colorMode;
68+
this.cacheConfig = cacheConfig;
7569
}
7670
}
7771

sample/babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: ["module:@react-native/babel-preset"],
2+
presets: ['module:@react-native/babel-preset'],
33
};

sample/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ export default class MParticleSample extends Component {
177177
// Select attributes based on platform
178178
const attributes = Platform.OS === 'ios' ? iosAttributes : androidAttributes;
179179
console.log(`Platform detected: ${Platform.OS}, using ${Platform.OS === 'ios' ? 'iOS' : 'Android'} attributes:`, attributes);
180-
const config = new RoktConfigBuilder()
181-
.withColorMode('light')
182-
.build();
180+
const config = MParticle.Rokt.createRoktConfig('system')
183181
const placeholderMap = {
184182
'Location1': findNodeHandle(this.placeholder1.current),
185183
}

0 commit comments

Comments
 (0)