-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { IDeviceInfo, IPipe, IPipeOutput, ITransmittable } from '../interfaces' | ||
import { IPromise } from '@qiwi/substrate' | ||
import platform from 'platform' | ||
import { set, clone } 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 | ||
}, | ||
model: { | ||
product, | ||
manufacturer | ||
}, | ||
os | ||
} | ||
} | ||
|
||
export const createDeviceInfoPipe = (): IPipe => ({ | ||
type, | ||
execute ({ data }: ITransmittable): IPromise<IPipeOutput> { | ||
const output = set(clone(data), 'meta.deviceInfo', getDeviceInfo()) | ||
|
||
return Promise.resolve([null, output]) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { deepMap } from './deepmap' | ||
|
||
export const clone = (src: any): any => deepMap(src, (v) => v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
import set from 'lodash.set' | ||
export { deepMap } from './deepmap' | ||
export { clone } from './clone' | ||
export { set } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createDeviceInfoPipe, getDeviceInfo, IDeviceInfo } from '../../../main/ts' | ||
|
||
describe('deviceInfoPipe', () => { | ||
it('is returned by factory', () => { | ||
const maskerPipe = createDeviceInfoPipe() | ||
|
||
expect(maskerPipe.type).toBe('device-info') | ||
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: { | ||
product: null, | ||
manufacturer: null | ||
}, | ||
os: { | ||
architecture: 64, | ||
family: 'OS X', | ||
version: '10.14.6' | ||
} | ||
} | ||
expect<IDeviceInfo>(getDeviceInfo(userAgent)).toMatchObject(expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ describe('httpPipe', () => { | |
const transmittable: ITransmittable = { data: null, meta: { history: [] } } | ||
|
||
return expect(httpPipe.execute(transmittable, noop)) | ||
.resolves.toEqual([null, { | ||
.resolves.toMatchObject([null, { | ||
data: { | ||
id: 2, | ||
email: '[email protected]', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -729,6 +729,13 @@ | |
dependencies: | ||
"@types/lodash" "*" | ||
|
||
"@types/lodash.set@^4.3.6": | ||
version "4.3.6" | ||
resolved "https://registry.yarnpkg.com/@types/lodash.set/-/lodash.set-4.3.6.tgz#33e635c2323f855359225df6a5c8c6f1f1908264" | ||
integrity sha512-ZeGDDlnRYTvS31Laij0RsSaguIUSBTYIlJFKL3vm3T2OAZAQj2YpSvVWJc0WiG4jqg9fGX6PAPGvDqBcHfSgFg== | ||
dependencies: | ||
"@types/lodash" "*" | ||
|
||
"@types/lodash@*": | ||
version "4.14.149" | ||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440" | ||
|
@@ -764,6 +771,11 @@ | |
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.2": | ||
version "1.3.2" | ||
resolved "https://registry.yarnpkg.com/@types/platform/-/platform-1.3.2.tgz#c0404c4e2a08e04295ab3d1241a856c2a3cab06e" | ||
integrity sha512-Tn6OuJDAG7bJbyi4R7HqcxXp1w2lmIxVXqyNhPt1Bm0FO2EWIi3CI87JVzF7ncqK0ZMPuUycS3wTMIk85EeF1Q== | ||
|
||
"@types/qs@^6.2.31": | ||
version "6.9.1" | ||
resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.1.tgz#937fab3194766256ee09fcd40b781740758617e7" | ||
|
@@ -4820,6 +4832,11 @@ lodash.once@^4.1.1: | |
resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac" | ||
integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w= | ||
|
||
lodash.set@^4.3.2: | ||
version "4.3.2" | ||
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23" | ||
integrity sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM= | ||
|
||
lodash.snakecase@^4.1.1: | ||
version "4.1.1" | ||
resolved "https://registry.yarnpkg.com/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz#39d714a35357147837aefd64b5dcbb16becd8f8d" | ||
|
@@ -6155,6 +6172,11 @@ pkg-dir@^4.2.0: | |
dependencies: | ||
find-up "^4.0.0" | ||
|
||
platform@^1.3.5: | ||
version "1.3.5" | ||
resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.5.tgz#fb6958c696e07e2918d2eeda0f0bc9448d733444" | ||
integrity sha512-TuvHS8AOIZNAlE77WUDiR4rySV/VMptyMfcfeoMgs4P8apaZM3JrnbzBiixKUv+XR6i+BXrQh8WAnjaSPFO65Q== | ||
|
||
pn@^1.1.0: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb" | ||
|
@@ -7888,11 +7910,16 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.5.tgz#0692e21f65fd4108b9330238aac11dd2e177a1ae" | ||
integrity sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw== | ||
|
||
typescript@^3.4, typescript@^3.8.3: | ||
typescript@^3.4: | ||
version "3.8.3" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061" | ||
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w== | ||
|
||
typescript@^3.8.3: | ||
version "3.9.6" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a" | ||
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw== | ||
|
||
uglify-js@^3.1.4: | ||
version "3.8.0" | ||
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.8.0.tgz#f3541ae97b2f048d7e7e3aa4f39fd8a1f5d7a805" | ||
|