Skip to content

Commit

Permalink
Release release-1_2_0
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasMcDonnell committed Dec 8, 2023
1 parent c4140ad commit 376690e
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SwrveCoreSDK/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swrve/web-core",
"version": "1.1.0",
"version": "1.2.0",
"description": "Swrve marketing engagement platform web core SDK",
"keywords": [
"swrve",
Expand Down
16 changes: 16 additions & 0 deletions SwrveCoreSDK/src/Swrve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
} from "./utils/SwrveConstants";
import { IQueryParams } from "./interfaces/IQueryParams";
import IRestClient from "./interfaces/IRestClient";
import IPushEvent from "./interfaces/IPushEvent";
import SwrveConfig from "./Config/SwrveConfig";
import { generateUuid } from "./utils/uuid";
import { QALogging } from "./Events/QALogging";
Expand Down Expand Up @@ -471,6 +472,21 @@ export class Swrve {
this.qaLogging.namedEvent(evt);
}

public enqueuePushEvents(events: IPushEvent[]): void {
events.forEach((evt) => {
const wrapped = this.eventFactory.getNamedEvent(
evt.event,
{},
this.profileManager.getNextSequenceNumber(),
evt.timestamp
);

this.queueEvent(wrapped);

this.qaLogging.namedEvent(wrapped);
})
}

//******************************************** Embedded Campaigns ********************************************/

public embeddedMessageWasShownToUser(message: ISwrveEmbeddedMessage): void {
Expand Down
5 changes: 5 additions & 0 deletions SwrveCoreSDK/src/SwrveCoreSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import IDictionary from "./interfaces/IDictionary";
import IReadonlyDictionary from "./interfaces/IReadonlyDictionary";
import { GET_INSTANCE_ERROR } from "./utils/SwrveConstants";
import IReward from "./interfaces/IReward";
import IPushEvent from "./interfaces/IPushEvent";
import { IPlatform } from "./interfaces/IPlatform";
import SwrveEvent from "./WebApi/Events/SwrveEvent";

Expand Down Expand Up @@ -320,4 +321,8 @@ export class SwrveCoreSDK {
public static notificationEngagedEvent(campaignId: number): void {
SwrveCoreSDK.checkInstance().notificationEngagedEvent(campaignId);
}

public static enqueuePushEvents(events: IPushEvent[]): void {
SwrveCoreSDK.checkInstance().enqueuePushEvents(events);
}
}
2 changes: 2 additions & 0 deletions SwrveCoreSDK/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { IUserInfo } from "./interfaces/IUser";
import IDictionary from "./interfaces/IDictionary";
import IReadonlyDictionary from "./interfaces/IReadonlyDictionary";
import IReward from "./interfaces/IReward";
import IPushEvent from "./interfaces/IPushEvent";
import { IAsset } from "./interfaces/IAsset";
import { IKeyMapping } from "./interfaces/IKeymapping";
import { generateUuid } from "./utils/uuid";
Expand Down Expand Up @@ -59,6 +60,7 @@ export {
SwrveResource,
ISwrveMessage,
IReward,
IPushEvent,
IAsset,
IKeyMapping,
DevicePropertyName,
Expand Down
7 changes: 7 additions & 0 deletions SwrveCoreSDK/src/interfaces/IPushEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default interface IPushEvent {
event_type: string;
event: string;
user_id: string;
id: number;
timestamp: number;
}
65 changes: 65 additions & 0 deletions SwrveCoreSDK/tests/Swrve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,71 @@ describe("SWRVE SDK TESTS", () => {
}, 1000);
});

it("Notification Delivery and Engagement Batch Events queue correctly", (done) => {
restClient.changeResponse({ json: () => qaUser });

const sdk = new Swrve(
{ appId: 30512, apiKey: "1234" },
{ restClient, platform: pal }
);
sdk.init();
setTimeout(() => {
const pushEvents = [
{
id: 1,
event_type: "swrve.push_received",
event: "Swrve.Messages.Push-1.delivered",
user_id: "4e56eddb-2930-4119-8f93-75304588a5ec",
timestamp: 1701873418769
},
{
id: 2,
event_type: "swrve.push_clicked",
event: "Swrve.Messages.Push-1.engaged",
user_id: "4e56eddb-2930-4119-8f93-75304588a5ec",
timestamp: 1701873421827
}
];

sdk.enqueuePushEvents(pushEvents);

const eventQueue = sdk.getQueuedEvents();
const qaQueue = sdk.getQALogging().getQueue();

const deliveredEvents = eventQueue.filter(
(evt) =>
evt.type === "event" && evt.name === "Swrve.Messages.Push-1.delivered"
);
expect(deliveredEvents.length).toBe(1);

const deliveredQAEvents = qaQueue.filter(
(evt) =>
evt.type === "qa_log_event" &&
JSON.stringify(evt.log_details).indexOf(
"Swrve.Messages.Push-1.delivered"
) !== -1
);
expect(deliveredQAEvents.length).toBe(1);

const engagedEvents = eventQueue.filter(
(evt) =>
evt.type === "event" && evt.name === "Swrve.Messages.Push-1.engaged"
);
expect(engagedEvents.length).toBe(1);

const engagedQAEvents = qaQueue.filter(
(evt) =>
evt.type === "qa_log_event" &&
JSON.stringify(evt.log_details).indexOf(
"Swrve.Messages.Push-1.engaged"
) !== -1
);
expect(engagedQAEvents.length).toBe(1);

done();
}, 1000);
});

it("Embedded Campaign callback API in config was fired on trigger", (done) => {
restClient.changeResponse({ json: () => embeddedMessageTriggered });

Expand Down

0 comments on commit 376690e

Please sign in to comment.