Skip to content

Commit 849461b

Browse files
Jaissica HoraJaissica Hora
authored andcommitted
feat: added use method for rokt kit
1 parent 77a04ee commit 849461b

5 files changed

Lines changed: 89 additions & 27 deletions

File tree

snippet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
'selectPlacements',
5050
'hashAttributes',
5151
'setExtensionData',
52+
'use',
5253
];
5354

5455
// iterates through methods above to create stubs

snippet.rokt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
'selectPlacements',
5050
'hashAttributes',
5151
'setExtensionData',
52+
'use',
5253
];
5354

5455
// iterates through methods above to create stubs

src/roktManager.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface IRoktSelection {
3838
export interface IRoktLauncher {
3939
selectPlacements: (options: IRoktSelectPlacementsOptions) => Promise<IRoktSelection>;
4040
hashAttributes: (attributes: IRoktPartnerAttributes) => Promise<Record<string, string>>;
41+
use: <T = any>(name: string) => Promise<T>;
4142
}
4243

4344
export interface IRoktMessage {
@@ -62,6 +63,7 @@ export interface IRoktKit {
6263
hashAttributes: (attributes: IRoktPartnerAttributes) => Promise<Record<string, string>>;
6364
selectPlacements: (options: IRoktSelectPlacementsOptions) => Promise<IRoktSelection>;
6465
setExtensionData<T>(extensionData: IRoktPartnerExtensionData<T>): void;
66+
use: <T = any>(name: string) => Promise<T>;
6567
launcherOptions?: Dictionary<any>;
6668
}
6769

@@ -251,6 +253,18 @@ export default class RoktManager {
251253
}
252254
}
253255

256+
public use<T = any>(name: string): Promise<T> {
257+
if (!this.isReady()) {
258+
return this.deferredCall<T>('use', name);
259+
}
260+
261+
try {
262+
return this.kit.use<T>(name);
263+
} catch (error) {
264+
return Promise.reject(error instanceof Error ? error : new Error('Unknown error occurred'));
265+
}
266+
}
267+
254268
public getLocalSessionAttributes(): LocalSessionAttributes {
255269
return this.store.getLocalSessionAttributes();
256270
}

0 commit comments

Comments
 (0)