diff --git a/SwrveCoreSDK/package.json b/SwrveCoreSDK/package.json index 8281aa0..b9bf149 100644 --- a/SwrveCoreSDK/package.json +++ b/SwrveCoreSDK/package.json @@ -1,6 +1,6 @@ { "name": "@swrve/web-core", - "version": "1.0.2", + "version": "1.1.0", "description": "Swrve marketing engagement platform web core SDK", "keywords": [ "swrve", @@ -46,7 +46,7 @@ "worker-loader": "^2.0.0" }, "dependencies": { - "@types/crypto-js": "4.0.2", - "crypto-js": "4.1.1" + "@types/crypto-js": "4.2.0", + "crypto-js": "4.2.0" } } diff --git a/SwrveCoreSDK/src/Swrve.ts b/SwrveCoreSDK/src/Swrve.ts index 554c6c1..b1d2ffd 100644 --- a/SwrveCoreSDK/src/Swrve.ts +++ b/SwrveCoreSDK/src/Swrve.ts @@ -92,7 +92,7 @@ export class Swrve { private campaignNetworkMonitorHandle?: NetworkListener; private identifiedOnAnotherDevice: boolean = false; private webPushApiKey: string = ""; - + public constructor( config: Readonly, @@ -326,6 +326,22 @@ export class Swrve { this.qaLogging.userUpdateWithDate(evt); } + public deviceUpdate( + attributes: IReadonlyDictionary + ): void { + if (this.pauseSDK) return; + + const evt = this.eventFactory.getDeviceUpdate( + attributes, + this.profileManager.getNextSequenceNumber(), + DateHelper.nowInUtcTime(), + ); + + this.queueEvent(evt); + + this.qaLogging.deviceUpdate(evt); + } + public userUpdate( attributes: IReadonlyDictionary ): void { diff --git a/SwrveCoreSDK/src/SwrveCoreSDK.ts b/SwrveCoreSDK/src/SwrveCoreSDK.ts index 3ba1c64..e9f38c5 100644 --- a/SwrveCoreSDK/src/SwrveCoreSDK.ts +++ b/SwrveCoreSDK/src/SwrveCoreSDK.ts @@ -174,6 +174,10 @@ export class SwrveCoreSDK { SwrveCoreSDK.checkInstance().event(name, payload); } + public static deviceUpdate(attributes: IReadonlyDictionary): void { + SwrveCoreSDK.checkInstance().deviceUpdate(attributes); + } + public static userUpdate( attributes: IReadonlyDictionary ): void { diff --git a/SwrveCoreSDK/tests/Swrve.test.ts b/SwrveCoreSDK/tests/Swrve.test.ts index 4638eac..3f6edc9 100644 --- a/SwrveCoreSDK/tests/Swrve.test.ts +++ b/SwrveCoreSDK/tests/Swrve.test.ts @@ -567,6 +567,7 @@ describe("SWRVE SDK TESTS", () => { sdk.stop(); sdk.event("test", {}); + sdk.deviceUpdate({web_push_token: "test"}); sdk.iap(1, "sword", 5, "gold"); sdk.userUpdate({ name: "test" }); sdk.userUpdateWithDate("test", new Date()); @@ -602,6 +603,7 @@ describe("SWRVE SDK TESTS", () => { sdk.identify("", () => {}, () => {}); sdk.event("test", {}); + sdk.deviceUpdate({web_push_token: "test"}); sdk.iap(1, "sword", 5, "gold"); sdk.userUpdate({ name: "test" }); sdk.userUpdateWithDate("test", new Date()); @@ -609,7 +611,7 @@ describe("SWRVE SDK TESTS", () => { sdk.purchase("sword", "gold", 10, 10); expect(sdk["pauseSDK"]).toBeFalsy; - expect(queueEvent.mock.calls.length).toBeGreaterThan(6); + expect(queueEvent.mock.calls.length).toBeGreaterThan(7); expect(sdk["eventLoopTimer"]).toBeGreaterThan(0); done(); @@ -631,6 +633,7 @@ describe("SWRVE SDK TESTS", () => { evtMgr.queueEvent = queueEvent; sdk.event("test", {}); + sdk.deviceUpdate({web_push_token: "test"}); sdk.iap(1, "sword", 5, "gold"); sdk.userUpdate({ name: "test" }); sdk.userUpdateWithDate("test", new Date()); @@ -638,9 +641,9 @@ describe("SWRVE SDK TESTS", () => { sdk.purchase("sword", "gold", 10, 10); const qaQueue = sdk.getQALogging().getQueue(); - expect(queueEvent.mock.calls.length).toBe(6); + expect(queueEvent.mock.calls.length).toBe(7); // there will be more than 6 due to specific QA events. - expect(qaQueue.length).toBeGreaterThan(6); + expect(qaQueue.length).toBeGreaterThan(7); done(); }, 1000); @@ -886,7 +889,7 @@ describe("SWRVE SDK TESTS", () => { const personalizationProvider = ( eventPayload: IDictionary ): IDictionary => { - + expect(eventPayload).toBeDefined(); return eventPayload; }; diff --git a/SwrveCoreSDK/yarn.lock b/SwrveCoreSDK/yarn.lock index 32fff32..9c4fd07 100644 --- a/SwrveCoreSDK/yarn.lock +++ b/SwrveCoreSDK/yarn.lock @@ -544,10 +544,10 @@ dependencies: "@babel/types" "^7.3.0" -"@types/crypto-js@^4.0.2": - version "4.0.2" - resolved "https://registry.yarnpkg.com/@types/crypto-js/-/crypto-js-4.0.2.tgz#4524325a175bf819fec6e42560c389ce1fb92c97" - integrity sha512-sCVniU+h3GcGqxOmng11BRvf9TfN9yIs8KKjB8C8d75W69cpTfZG80gau9yTx5SxF3gvHGbJhdESzzvnjtf3Og== +"@types/crypto-js@4.2.0": + version "4.2.0" + resolved "https://registry.yarnpkg.com/@types/crypto-js/-/crypto-js-4.2.0.tgz#01918d35ec66aa806887435c44a67d7a749cf545" + integrity sha512-LW9TlhpMeoQKOu6I6HvOp7eInNNnvd7B+ndAfZb826HUl7eHJJApofbHnlAxrIVS/uiCjkkHGNEaKHoGxB5IHw== "@types/eslint-scope@^3.7.0": version "3.7.1" @@ -1189,10 +1189,10 @@ cross-spawn@^7.0.3: shebang-command "^2.0.0" which "^2.0.1" -crypto-js@^4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf" - integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw== +crypto-js@4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631" + integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q== cssom@^0.4.4: version "0.4.4"