diff --git a/Examples/DestinationFiltersExample/DestinationFiltersExample/AppDelegate.swift b/Examples/DestinationFiltersExample/DestinationFiltersExample/AppDelegate.swift index 1fd61c0..7f8cb41 100644 --- a/Examples/DestinationFiltersExample/DestinationFiltersExample/AppDelegate.swift +++ b/Examples/DestinationFiltersExample/DestinationFiltersExample/AppDelegate.swift @@ -7,7 +7,7 @@ import UIKit import Segment -import DestinationFilters_Swift +import AnalyticsFilters extension Analytics { static let config = Configuration(writeKey: "93EMLzmXzP6EJ3cJOhdaAgEVNnZjwRqA") diff --git a/Package.resolved b/Package.resolved index 27102e2..a503cd9 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,17 +5,17 @@ "kind" : "remoteSourceControl", "location" : "git@github.com:segmentio/analytics-swift.git", "state" : { - "revision" : "ddbe8ef9f15b4e8f2f61ddf713f421702f0d2a52", - "version" : "1.3.1" + "revision" : "c8fd5fdf59299f00b3e4303a1b12a6d88893bf56", + "version" : "1.4.7" } }, { - "identity" : "edgefn-swift", + "identity" : "analytics-swift-live", "kind" : "remoteSourceControl", - "location" : "git@github.com:segmentio/EdgeFn-Swift.git", + "location" : "git@github.com:segment-integrations/analytics-swift-live.git", "state" : { - "branch" : "main", - "revision" : "ec883df24c99b647c4c231c24ce31d8ff311297f" + "revision" : "3b07681d498595aa8e06cd814003db53661abb88", + "version" : "0.2.3" } }, { @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/segmentio/Sovran-Swift.git", "state" : { - "revision" : "944c17d7c46bd95fc37f09136cabd172be5b413b", - "version" : "1.0.3" + "revision" : "64f3b5150c282a34af4578188dce2fd597e600e3", + "version" : "1.1.0" } }, { @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "git@github.com:segmentio/substrata-swift.git", "state" : { - "branch" : "main", - "revision" : "b0fc14b6a454bd2138af55110d108e487f2b2d1b" + "revision" : "a673d773d0a6dab86a31cadcb771b45022e0c5ac", + "version" : "0.0.2" } } ], diff --git a/Package.swift b/Package.swift index f2d6d12..9b88be7 100644 --- a/Package.swift +++ b/Package.swift @@ -1,10 +1,10 @@ -// swift-tools-version: 5.6 +// swift-tools-version: 5.8 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( - name: "DestinationFilters-Swift", + name: "AnalyticsFilters", platforms: [ .macOS("10.15"), .iOS("13.0") @@ -12,35 +12,27 @@ let package = Package( products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( - name: "DestinationFilters-Swift", - targets: ["DestinationFilters-Swift"]), + name: "AnalyticsFilters", + targets: ["AnalyticsFilters"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. - .package( - name: "EdgeFn", - url: "git@github.com:segmentio/EdgeFn-Swift.git", - .upToNextMajor(from: "0.1.1") - ), - .package( - name: "Segment", - url: "git@github.com:segmentio/analytics-swift.git", - from: "1.3.1" - ), - .package( - name: "Substrata", - url: "git@github.com:segmentio/substrata-swift.git", - .upToNextMajor(from: "0.0.2") - ), + .package(url: "git@github.com:segment-integrations/analytics-swift-live.git", .upToNextMajor(from: "0.2.3")), + .package(url: "git@github.com:segmentio/analytics-swift.git", from: "1.4.7"), + .package(url: "git@github.com:segmentio/substrata-swift.git", .upToNextMajor(from: "0.0.2")), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( - name: "DestinationFilters-Swift", - dependencies: ["Segment", "EdgeFn", "Substrata"]), + name: "AnalyticsFilters", + dependencies: [ + .product(name: "Segment", package: "analytics-swift"), + .product(name: "Substrata", package: "substrata-swift"), + .product(name: "AnalyticsLive", package: "analytics-swift-live"), + ]), .testTarget( - name: "DestinationFilters-SwiftTests", - dependencies: ["DestinationFilters-Swift"]), + name: "AnalyticsFilters-Tests", + dependencies: ["AnalyticsFilters"]), ] ) diff --git a/Sources/DestinationFilters-Swift/DestinationFilters.swift b/Sources/AnalyticsFilters/DestinationFilters.swift similarity index 92% rename from Sources/DestinationFilters-Swift/DestinationFilters.swift rename to Sources/AnalyticsFilters/DestinationFilters.swift index 397a413..f3567ac 100644 --- a/Sources/DestinationFilters-Swift/DestinationFilters.swift +++ b/Sources/AnalyticsFilters/DestinationFilters.swift @@ -6,7 +6,7 @@ import Foundation import Segment -import EdgeFn +import AnalyticsLive import Substrata public class DestinationFilters: UtilityPlugin { @@ -18,15 +18,17 @@ public class DestinationFilters: UtilityPlugin { var dest_filters=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=5)}([function(e,r,t){e.exports=function(e,r,t,n,o){for(r=r.split?r.split("."):r,n=0;n1?(s.pop(),c=o(t,s.join("."))):c=e,"object"==typeof c){if(i.copy){var f=o(t,i.copy);void 0!==f&&u(e,n,f)}else if(i.move){var l=o(t,i.move);void 0!==l&&u(e,n,l),a.unset(e,i.move)}else i.hasOwnProperty("set")&&u(e,n,i.set);if(i.to_string){var p=o(e,n);if("string"==typeof p||"object"==typeof p&&null!==p)continue;u(e,n,void 0!==p?JSON.stringify(p):"undefined")}}}}function l(e,r){return!(r.sample.percent<=0)&&(r.sample.percent>=1||(r.sample.path?function(e,r){var t=o(e,r.sample.path),u=n(JSON.stringify(t)),a=-64,s=[];p(u.slice(0,8),s);for(var c=0,f=0;f<64&&1!==s[f];f++)c++;if(0!==c){var l=[];p(u.slice(9,16),l),a-=c,s.splice(0,c),l.splice(64-c),s=s.concat(l)}return s[63]=0===s[63]?1:0,i(parseInt(s.join(""),2),a)=1;o/=2)n-o>=0?(n-=o,r.push(1)):r.push(0)}r.default=function(e,r){for(var t=e,n=0,o=r;n>2]|=s.charCodeAt(c)<<8*c--;for(o=s=0;o>4]+n[s]+~~a[o|15&[s,5*s+1,3*s+5,7*s][c]])<<(c=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*c+s++%4])|i>>>-c),r,t])r=0|c[1],t=c[2];for(s=4;s;)u[--s]+=c[s]}for(e="";s<32;)e+=(u[s>>3]>>4*(1^s++)&15).toString(16);return e}},function(e,r,t){"use strict";var n=t(10),o=t(11),i=t(12),u=t(17),a=t(20),s=t(3),c=t(4);e.exports=function(e,r){var t,f,l,p;return 0===e||e!=e||e===n||e===o?e:(e=(f=i(e))[0],r+=f[1],(r+=u(e))<-1074?a(0,e):r>1023?e<0?o:n:(r<=-1023?(r+=52,p=2220446049250313e-31):p=1,t=(l=s(e))[0],t&=2148532223,p*c(t|=r+1023<<20,l[1])))}},function(e,r,t){"use strict";e.exports=Number.POSITIVE_INFINITY},function(e,r,t){"use strict";e.exports=Number.NEGATIVE_INFINITY},function(e,r,t){"use strict";var n=t(13).VALUE,o=t(15),i=t(16);e.exports=function(e){return e!=e||o(e)?[e,0]:0!==e&&i(e)>>20)-1023}},function(e,r,t){"use strict";var n;n=!0===t(1)?1:0,e.exports=n},function(e,r,t){"use strict";var n={uint16:Uint16Array,uint8:Uint8Array};e.exports=n},function(e,r,t){"use strict";var n=t(3),o=t(2),i=t(4);e.exports=function(e,r){var t,u;return t=(e=n(e))[0],t&=2147483647,u=o(r),i(t|=u&=2147483648,e[1])}},function(e,r,t){"use strict";var n,o;t(1)?(n=1,o=0):(n=0,o=1),e.exports={HIGH:n,LOW:o}},function(e,r,t){"use strict";var n,o;!0===t(1)?(n=1,o=0):(n=0,o=1),e.exports={HIGH:n,LOW:o}},function(e,r){e.exports=function(e,r,t){r.split&&(r=r.split("."));for(var n,o,i=0,u=r.length,a=e;i":case">=":return function(e,r,t,n){u(e)&&(e=o(e,n));u(r)&&(r=o(r,n));if("number"!=typeof e||"number"!=typeof r)return!1;switch(t){case"<=":return e<=r;case">=":return e>=r;case"<":return e":return e>r;default:throw new Error("Invalid operator in compareNumbers: "+t)}}(i(e[1],r),i(e[2],r),t,r);case"contains":return function(e,r){if("string"!=typeof e||"string"!=typeof r)return!1;return-1!==e.indexOf(r)}(i(e[1],r),i(e[2],r));case"match":return function(e,r){if("string"!=typeof e||"string"!=typeof r)return!1;return function(e,r){var t,n;e:for(;e.length>0;){var o,i;if(t=a(e),o=t.star,i=t.chunk,e=t.pattern,o&&""===i)return!0;var u=s(i,r),c=u.t,f=u.ok,l=u.err;if(l)return!1;if(!f||!(0===c.length||e.length>0)){if(o)for(var p=0;p0)continue;r=c;continue e}if(l)return!1}return!1}r=c}return 0===r.length}(r,e)}(i(e[1],r),i(e[2],r));case"lowercase":var c=i(e[1],r);return"string"!=typeof c?null:c.toLowerCase();case"typeof":return typeof i(e[1],r);case"length":return function(e){if(null===e)return 0;if(!Array.isArray(e)&&"string"!=typeof e)return NaN;return e.length}(i(e[1],r));default:throw new Error("FQL IR could not evaluate for token: "+t)}}function i(e,r){return Array.isArray(e)?e:"object"==typeof e?e.value:n(r,e)}function u(e){return!!Array.isArray(e)&&(("lowercase"===e[0]||"length"===e[0]||"typeof"===e[0])&&2===e.length||("contains"===e[0]||"match"===e[0])&&3===e.length)}function a(e){for(var r={star:!1,chunk:"",pattern:""};e.length>0&&"*"===e[0];)e=e.slice(1),r.star=!0;var t,n=!1;e:for(t=0;t0;){if(0===r.length)return o;switch(e[0]){case"[":var i=r[0];r=r.slice(1);var u=!0;(e=e.slice(1)).length>0&&"^"===e[0]&&(u=!1,e=e.slice(1));for(var a=!1,s=0;;){if(e.length>0&&"]"===e[0]&&s>0){e=e.slice(1);break}var f,l="";if(f=(t=c(e)).char,e=t.newChunk,t.err)return o;if(l=f,"-"===e[0]&&(l=(n=c(e.slice(1))).char,e=n.newChunk,n.err))return o;f<=i&&i<=l&&(a=!0),s++}if(a!==u)return o;break;case"?":r=r.slice(1),e=e.slice(1);break;case"\\":if(0===(e=e.slice(1)).length)return o.err=!0,o;default:if(e[0]!==r[0])return o;r=r.slice(1),e=e.slice(1)}}return o.t=r,o.ok=!0,o.err=!1,o}function c(e){var r={char:"",newChunk:"",err:!1};return 0===e.length||"-"===e[0]||"]"===e[0]||"\\"===e[0]&&0===(e=e.slice(1)).length?(r.err=!0,r):(r.char=e[0],r.newChunk=e.slice(1),0===r.newChunk.length&&(r.err=!0),r)}r.default=function(e,r){if(!r)throw new Error("No matcher supplied!");switch(r.type){case"all":return!0;case"fql":return function(e,r){if(!e)return!1;try{e=JSON.parse(e)}catch(r){throw new Error('Failed to JSON.parse FQL intermediate representation "'+e+'": '+r)}var t=o(e,r);if("boolean"!=typeof t)return!1;return t}(r.ir,e);default:throw new Error("Matcher of type "+r.type+" unsupported.")}}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e){this.rules=[],this.rules=e||[]}return e.prototype.getRulesByDestinationName=function(e){for(var r=[],t=0,n=this.rules;t(event: T?) -> T? where T : RawEvent { + lastEvent = event + if let t = lastEvent as? TrackEvent { + events.append(t) + print("EVENT: \(t.event)") + } + return event + } +} + +func waitUntilStarted(analytics: Analytics?) { + guard let analytics = analytics else { return } + // wait until the startup queue has emptied it's events. + if let startupQueue = analytics.find(pluginType: StartupQueue.self) { + while startupQueue.running != true { + RunLoop.main.run(until: Date.distantPast) + } + } +} diff --git a/Tests/DestinationFilters-SwiftTests/DestinationFilters_SwiftTests.swift b/Tests/DestinationFilters-SwiftTests/DestinationFilters_SwiftTests.swift deleted file mode 100644 index b19a124..0000000 --- a/Tests/DestinationFilters-SwiftTests/DestinationFilters_SwiftTests.swift +++ /dev/null @@ -1,11 +0,0 @@ -import XCTest -@testable import DestinationFilters_Swift - -final class DestinationFilters_SwiftTests: XCTestCase { - func testExample() throws { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - XCTAssertEqual(DestinationFilters_Swift().text, "Hello, World!") - } -}