diff --git a/package.json b/package.json index 878f9ba..5075b06 100644 --- a/package.json +++ b/package.json @@ -56,23 +56,18 @@ }, "homepage": "https://github.com/qiwi/event-transmitter#readme", "dependencies": { - "is-mobile": "^3.0.0", "@qiwi/substrate": "^1.20.11", "@types/lodash.once": "^4.1.6", "@types/lodash.set": "^4.3.6", "@types/safe-json-stringify": "^1.1.2", - "@types/platform": "^1.3.4", "fast-luhn": "^2.0.0", "lodash.once": "^4.1.1", "lodash.set": "^4.3.2", - "platform": "^1.3.6", "safe-json-stringify": "^1.2.0", "stacktrace-js": "^2.0.2", "tslib": "^2.3.1" }, "devDependencies": { - "user-agents": "^1.0.843", - "@types/user-agents": "^1.0.2", "@qiwi/libdefkit": "^2.1.8", "@qiwi/npm-run-all": "^4.1.7", "@swissquote/crafty-preset-jest": "^1.17.2", diff --git a/src/main/ts/index.ts b/src/main/ts/index.ts index ee94f49..ec3b086 100644 --- a/src/main/ts/index.ts +++ b/src/main/ts/index.ts @@ -3,7 +3,7 @@ export { createHttpPipeFallback } from './pipes/httpFallback' export { createMaskerPipe, panMaskerPipe } from './pipes/masker' export { createHttpBatchPipe } from './pipes/httpBatch' export { createFlpPipeline, eventifyPipe } from './pipes/flp' -export { createDeviceInfoPipe, getDeviceInfo } from './pipes/deviceInfo' +export { createDeviceInfoPipe } from './pipes/deviceInfo' export { createTransmitter, createTransmittable } from './transmitter' export * from './interfaces' diff --git a/src/main/ts/pipes/deviceInfo.ts b/src/main/ts/pipes/deviceInfo.ts index 5155d91..64b58b3 100644 --- a/src/main/ts/pipes/deviceInfo.ts +++ b/src/main/ts/pipes/deviceInfo.ts @@ -1,33 +1,14 @@ -import { IDeviceInfo, IPromise } from '@qiwi/substrate' -import platform from 'platform' +import { IPromise } from '@qiwi/substrate' import { IPipe, IPipeOutput, ITransmittable } from '../interfaces' -import { clone, isMobile, set } from '../utils' +import { clone, set } from '../utils' export const type = 'device-info' -export const getDeviceInfo = (userAgent?: string): IDeviceInfo => { - const parsedData = userAgent ? platform.parse(userAgent) : platform - const { name, version, layout, product, manufacturer, os } = parsedData - return { - browser: { - name, - version, - layout, - }, - isMobile: isMobile(userAgent || window.navigator.userAgent), - model: { - name: product, - manufacturer, - }, - os, - } -} - export const createDeviceInfoPipe = (): IPipe => ({ type, execute({ data }: ITransmittable): IPromise { - const output = set(clone(data), 'meta.deviceInfo', getDeviceInfo()) + const output = set(clone(data), 'meta.userAgent', window.navigator.userAgent) return Promise.resolve([null, output]) }, }) diff --git a/src/main/ts/utils/deviceTypes.ts b/src/main/ts/utils/deviceTypes.ts deleted file mode 100644 index c2f5e7d..0000000 --- a/src/main/ts/utils/deviceTypes.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { isMobile as _isMobile } from 'is-mobile' - -export const isMobile = (ua: string): ReturnType => _isMobile({ ua, tablet: true }) diff --git a/src/main/ts/utils/index.ts b/src/main/ts/utils/index.ts index 521929f..f120e37 100644 --- a/src/main/ts/utils/index.ts +++ b/src/main/ts/utils/index.ts @@ -3,5 +3,4 @@ export { deepMap } from './deepmap' export { executeFailproof } from './executeFailproof' export { clone } from './clone' export { set } -export { isMobile } from './deviceTypes' export { identity } from './identity' diff --git a/src/test/ts/pipes/deviceInfo.ts b/src/test/ts/pipes/deviceInfo.ts index 02d8823..2bb9a3b 100644 --- a/src/test/ts/pipes/deviceInfo.ts +++ b/src/test/ts/pipes/deviceInfo.ts @@ -1,6 +1,4 @@ -import { IDeviceInfo } from '@qiwi/substrate' - -import { createDeviceInfoPipe, getDeviceInfo } from '../../../main/ts' +import { createDeviceInfoPipe } from '../../../main/ts' describe('deviceInfoPipe', () => { it('is returned by factory', () => { @@ -10,28 +8,3 @@ describe('deviceInfoPipe', () => { expect(maskerPipe.execute).toEqual(expect.any(Function)) }) }) - -describe('getDeviceInfo', () => { - it('returns device info', () => { - const userAgent = - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' - const expected: IDeviceInfo = { - browser: { - name: 'Chrome', - version: '83.0.4103.116', - layout: 'Blink', - }, - model: { - name: null, - manufacturer: null, - }, - isMobile: false, - os: { - architecture: 64, - family: 'OS X', - version: '10.14.6', - }, - } - expect(getDeviceInfo(userAgent)).toMatchObject(expected) - }) -}) diff --git a/src/test/ts/pipes/flp.ts b/src/test/ts/pipes/flp.ts index 96f2eff..9026616 100644 --- a/src/test/ts/pipes/flp.ts +++ b/src/test/ts/pipes/flp.ts @@ -164,13 +164,7 @@ describe('flpPipeline', () => { // @ts-ignore expect(JSON.parse(spy.mock.calls[0][1].body)).toMatchObject({ message: '0000 **** **** 0000', - meta: { - deviceInfo: { - browser: expect.any(Object), - model: expect.any(Object), - os: expect.any(Object), - }, - }, + meta: {}, level: 'info', }) @@ -199,13 +193,7 @@ describe('flpPipeline', () => { // @ts-ignore expect(JSON.parse(spy.mock.calls[0][1].body)).toMatchObject({ message: 'message', - meta: { - deviceInfo: { - browser: expect.any(Object), - model: expect.any(Object), - os: expect.any(Object), - }, - }, + meta: {}, level: 'info', data: 'data', }) diff --git a/src/test/ts/utils/deviceTypes.ts b/src/test/ts/utils/deviceTypes.ts deleted file mode 100644 index 6b653fc..0000000 --- a/src/test/ts/utils/deviceTypes.ts +++ /dev/null @@ -1,56 +0,0 @@ -import UserAgent from 'user-agents' - -import { isMobile } from '../../../main/ts/utils' - -interface ITestCase { - description: string - userAgents: string[] - expected: boolean[] -} - -const testCasesCount = 100 -const testArray = new Array(testCasesCount).fill('') - -const checkTestCase = (functionToTest: (ua: string) => boolean) => ({ - description, - userAgents, - expected, -}: ITestCase) => { - describe(description, () => { - userAgents.forEach((userAgent, i) => { - test(userAgent, () => - expect(functionToTest(userAgent)).toEqual(expected[i]), - ) - }) - }) -} - -const mobileUaFactory = () => new UserAgent({ deviceCategory: 'mobile' }) -const desktopUaFactory = () => new UserAgent({ deviceCategory: 'desktop' }) -const tabletUaFactory = () => new UserAgent({ deviceCategory: 'tablet' }) - -const mobileUserAgents = testArray.map(() => mobileUaFactory().data.userAgent) -const desktopUserAgents = testArray.map(() => desktopUaFactory().data.userAgent) -const tabletUserAgents = testArray.map(() => tabletUaFactory().data.userAgent) - -describe('isMobile', () => { - const testCases: ITestCase[] = [ - { - description: 'returns true for all mobile userAgents', - userAgents: mobileUserAgents, - expected: new Array(testCasesCount).fill(true), - }, - { - description: 'returns false for all desktop userAgents', - userAgents: desktopUserAgents, - expected: new Array(testCasesCount).fill(false), - }, - { - description: 'returns true for all tablet userAgents', - userAgents: tabletUserAgents, - expected: new Array(testCasesCount).fill(true), - }, - ] - - testCases.forEach(checkTestCase(isMobile)) -}) diff --git a/yarn.lock b/yarn.lock index 36a60b5..54c9c0e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1950,11 +1950,6 @@ resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA== -"@types/platform@^1.3.4": - version "1.3.4" - resolved "https://registry.yarnpkg.com/@types/platform/-/platform-1.3.4.tgz#0d3a4254863afaa89d6f02d73c2806271d13415d" - integrity sha512-U0o4K+GNiK0PNxoDwd8xRnvLVe4kzei6opn3/FCjAriqaP+rfrDdSl1kP/hLL6Y3/Y3hhGnBwD4dCkkAqs1W/Q== - "@types/prettier@^2.1.5": version "2.4.2" resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.4.2.tgz#4c62fae93eb479660c3bd93f9d24d561597a8281" @@ -1982,11 +1977,6 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff" integrity sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw== -"@types/user-agents@^1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@types/user-agents/-/user-agents-1.0.2.tgz#3499d4aaf01a004ae9cab4e52b8d8c8b32637733" - integrity sha512-WOoL2UJTI6RxV8RB2kS3ZhxjjijI5G1i7mgU7mtlm4LsC1XGCfiV56h+GV4VZnAUkkkLQ4gbFGR/dggT01n0RA== - "@types/yargs-parser@*": version "15.0.0" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-15.0.0.tgz#cb3f9f741869e20cce330ffbeb9271590483882d" @@ -3269,7 +3259,7 @@ delayed-stream@~1.0.0: resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk= -detect-indent@^6.0.0, detect-indent@~6.0.0: +detect-indent@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-6.0.0.tgz#0abd0f549f69fc6659a254fe96786186b6f528fd" integrity sha512-oSyFlqaTHCItVRGK5RmrmjB+CmaMOW7IaNA/kdxqhoa6d17j/5ce9O9eWXmV/KEdRwqpQA+Vqe8a8Bsybu4YnA== @@ -3298,11 +3288,6 @@ dir-glob@^3.0.1: dependencies: path-type "^4.0.0" -docopt@~0.6.2: - version "0.6.2" - resolved "https://registry.yarnpkg.com/docopt/-/docopt-0.6.2.tgz#b28e9e2220da5ec49f7ea5bb24a47787405eeb11" - integrity sha1-so6eIiDaXsSffqW7JKR3h0Be6xE= - doctrine@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d" @@ -3350,15 +3335,6 @@ domutils@^1.7.0: dom-serializer "0" domelementtype "1" -dot-json@^1.2.2: - version "1.2.2" - resolved "https://registry.yarnpkg.com/dot-json/-/dot-json-1.2.2.tgz#7d35abece4aa22aa75a761388953f98495401bcc" - integrity sha512-AKL+GsO4wSEU4LU+fAk/PqN4nQ6PB1vT3HpMiZous9xCzK5S0kh4DzfUY0EfU67jsIXLlu0ty71659N9Nmg+Tw== - dependencies: - detect-indent "~6.0.0" - docopt "~0.6.2" - underscore-keypath "~0.0.22" - dot-prop@^5.2.0: version "5.3.0" resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-5.3.0.tgz#90ccce708cd9cd82cc4dc8c3ddd9abdd55b20e88" @@ -4878,11 +4854,6 @@ is-glob@^4.0.3: dependencies: is-extglob "^2.1.1" -is-mobile@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/is-mobile/-/is-mobile-3.0.0.tgz#683005f3a40adbc0ca5867e1d5e75d7bbf66d764" - integrity sha512-UruBjgykgDJ5zRpJ8Zgh9ZUe4jQaHD8klX9FlkOt0oPyu3FpwJpxHvKg4+lhJOWGxSrMKsRuPFk60xeltvyliQ== - is-module@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591" @@ -5782,11 +5753,6 @@ lodash.camelcase@^4.3.0: resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" integrity sha1-soqmKIorn8ZRA1x3EfZathkDMaY= -lodash.clonedeep@^4.5.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" - integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8= - lodash.debounce@^4.0.8: version "4.0.8" resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" @@ -6684,11 +6650,6 @@ pkg-dir@^5.0.0: dependencies: find-up "^5.0.0" -platform@^1.3.6: - version "1.3.6" - resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.6.tgz#48b4ce983164b209c2d45a107adb31f473a6e7a7" - integrity sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg== - pluralize@^8.0.0: version "8.0.0" resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-8.0.0.tgz#1a6fa16a38d12a1901e0320fa017051c539ce3b1" @@ -8347,18 +8308,6 @@ unbox-primitive@^1.0.1: has-symbols "^1.0.2" which-boxed-primitive "^1.0.2" -underscore-keypath@~0.0.22: - version "0.0.22" - resolved "https://registry.yarnpkg.com/underscore-keypath/-/underscore-keypath-0.0.22.tgz#48a528392bb6efc424be1caa56da4b5faccf264d" - integrity sha1-SKUoOSu278QkvhyqVtpLX6zPJk0= - dependencies: - underscore "*" - -underscore@*: - version "1.11.0" - resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.11.0.tgz#dd7c23a195db34267186044649870ff1bab5929e" - integrity sha512-xY96SsN3NA461qIRKZ/+qox37YXPtSBswMGfiNptr+wrt6ds4HaMw23TP612fEyGekRE6LNRiLYr/aqbHXNedw== - unicode-canonical-property-names-ecmascript@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818" @@ -8442,14 +8391,6 @@ use@^3.1.0: resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ== -user-agents@^1.0.843: - version "1.0.843" - resolved "https://registry.yarnpkg.com/user-agents/-/user-agents-1.0.843.tgz#ce03a22aed087bc630cc5a1d5f6b9d189848e66a" - integrity sha512-ba59PphdJ1y59XkHpi9+CYzZwrLA5E7d8UpNhnkc6iKlP3PzdlnipzBXZbM+0wsKb9fCJuozoLTFUawirusFJQ== - dependencies: - dot-json "^1.2.2" - lodash.clonedeep "^4.5.0" - util-deprecate@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"