From 376690e3ea24137501700f21999a5853a118060c Mon Sep 17 00:00:00 2001 From: Thomas McDonnell Date: Fri, 8 Dec 2023 10:00:39 +0000 Subject: [PATCH] Release release-1_2_0 --- SwrveCoreSDK/package.json | 2 +- SwrveCoreSDK/src/Swrve.ts | 16 ++++++ SwrveCoreSDK/src/SwrveCoreSDK.ts | 5 ++ SwrveCoreSDK/src/index.ts | 2 + SwrveCoreSDK/src/interfaces/IPushEvent.ts | 7 +++ SwrveCoreSDK/tests/Swrve.test.ts | 65 +++++++++++++++++++++++ 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 SwrveCoreSDK/src/interfaces/IPushEvent.ts diff --git a/SwrveCoreSDK/package.json b/SwrveCoreSDK/package.json index b9bf149..dcdf3d8 100644 --- a/SwrveCoreSDK/package.json +++ b/SwrveCoreSDK/package.json @@ -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", diff --git a/SwrveCoreSDK/src/Swrve.ts b/SwrveCoreSDK/src/Swrve.ts index b1d2ffd..64c7f75 100644 --- a/SwrveCoreSDK/src/Swrve.ts +++ b/SwrveCoreSDK/src/Swrve.ts @@ -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"; @@ -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 { diff --git a/SwrveCoreSDK/src/SwrveCoreSDK.ts b/SwrveCoreSDK/src/SwrveCoreSDK.ts index e9f38c5..89a9698 100644 --- a/SwrveCoreSDK/src/SwrveCoreSDK.ts +++ b/SwrveCoreSDK/src/SwrveCoreSDK.ts @@ -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"; @@ -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); + } } diff --git a/SwrveCoreSDK/src/index.ts b/SwrveCoreSDK/src/index.ts index 9002159..654059a 100644 --- a/SwrveCoreSDK/src/index.ts +++ b/SwrveCoreSDK/src/index.ts @@ -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"; @@ -59,6 +60,7 @@ export { SwrveResource, ISwrveMessage, IReward, + IPushEvent, IAsset, IKeyMapping, DevicePropertyName, diff --git a/SwrveCoreSDK/src/interfaces/IPushEvent.ts b/SwrveCoreSDK/src/interfaces/IPushEvent.ts new file mode 100644 index 0000000..ccd94d5 --- /dev/null +++ b/SwrveCoreSDK/src/interfaces/IPushEvent.ts @@ -0,0 +1,7 @@ +export default interface IPushEvent { + event_type: string; + event: string; + user_id: string; + id: number; + timestamp: number; +} diff --git a/SwrveCoreSDK/tests/Swrve.test.ts b/SwrveCoreSDK/tests/Swrve.test.ts index 3f6edc9..0d6ab44 100644 --- a/SwrveCoreSDK/tests/Swrve.test.ts +++ b/SwrveCoreSDK/tests/Swrve.test.ts @@ -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 });