diff --git a/package.json b/package.json index 153f61a7..25c07ea1 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "lint": "eslint --ext .js,.ts --ignore-path .gitignore --max-warnings 0 .", "lint:fix": "yarn lint --fix", "test": "jest", + "generateTypes": "yarn openapi-typescript https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi/schemes/fingerprint-server-api.yaml --output ./src/generatedApiTypes.ts -c .prettierrc.json", "release:major": "changelog -M && git add CHANGELOG.md && yarn version --major --no-git-tag-version", "release:minor": "changelog -m && git add CHANGELOG.md && yarn version --minor --no-git-tag-version", "release:patch": "changelog -p && git add CHANGELOG.md && yarn version --patch --no-git-tag-version" @@ -32,6 +33,7 @@ "eslint-plugin-prettier": "^4.0.0", "generate-changelog": "^1.8.0", "jest": "^27.0.6", + "openapi-typescript": "^5.4.0", "prettier": "^2.6.0", "ts-jest": "^27.1.3", "typescript": "^4.5.5" diff --git a/src/generatedApiTypes.ts b/src/generatedApiTypes.ts new file mode 100644 index 00000000..219bd514 --- /dev/null +++ b/src/generatedApiTypes.ts @@ -0,0 +1,205 @@ +/** + * This file was auto-generated by openapi-typescript. + * Do not make direct changes to the file. + */ + +export interface paths { + '/visitors/{visitor_id}': { + /** This endpoint allows you to get a history of visits with all available information. Use the visitorID as a URL path parameter. This API method is scoped to a visitor, i.e. all returned information is by visitorId. */ + get: { + parameters: { + path: { + visitor_id: string; + }; + query: { + /** Filter events by requestId */ + request_id?: string; + /** Filter events by custom identifier */ + linked_id?: string; + /** Limit scanned results */ + limit?: number; + /** Used to paginate results */ + before?: number; + }; + }; + responses: { + /** Auto generated using Swagger Inspector */ + 200: { + content: { + 'application/json': components['schemas']['Response']; + }; + }; + 429: { + content: { + 'application/json': components['schemas']['ManyRequestsResponse']; + }; + }; + }; + }; + }; +} + +export interface components { + schemas: { + Response: components['schemas']['BaseResponse'] | components['schemas']['PaginatedResponse']; + /** BaseResponse */ + BaseResponse: { + visitorId: string; + visits: components['schemas']['Visit'][]; + }; + /** + * PaginatedResponse + * @description Fields `lastTimestamp` and `paginationKey` added when `limit` or `before` parameter provided and there is more data to show + */ + PaginatedResponse: { + visitorId: string; + visits: components['schemas']['Visit'][]; + /** + * Format: int64 + * @example 1654815517198 + */ + lastTimestamp: number; + /** @example 1654815517198.azN4IZ */ + paginationKey: string; + }; + ManyRequestsResponse: { + /** @example request throttled */ + error: string; + }; + /** Visit */ + Visit: { + /** @example 1654815516083.OX6kx8 */ + requestId: string; + browserDetails: components['schemas']['BrowserDetails']; + incognito: boolean; + /** + * Format: ipv4 + * @example 8.8.8.8 + */ + ip: string; + ipLocation: components['schemas']['IPLocation']; + /** + * Format: int64 + * @example 1654815516086 + */ + timestamp: number; + /** + * Format: date-time + * @example 2022-06-09T22:58:36Z + */ + time: string; + /** + * Format: uri + * @example https://some.website/path?query=params + */ + url: string; + tag: { [key: string]: unknown }; + /** @example someID */ + linkedId?: string; + confidence: components['schemas']['Confidence']; + visitorFound: boolean; + /** + * @example { + * "global": "2022-05-05T18:28:54.535Z", + * "subscription": "2022-06-09T22:58:05.576Z" + * } + */ + firstSeenAt: components['schemas']['StSeenAt']; + /** + * @example { + * "global": "2022-06-09T22:58:35.795Z", + * "subscription": null + * } + */ + lastSeenAt: components['schemas']['StSeenAt']; + }; + /** BrowserDetails */ + BrowserDetails: { + /** @example Chrome */ + browserName: string; + /** @example 101 */ + browserMajorVersion: string; + /** @example 101.0.4951 */ + browserFullVersion: string; + /** @example Windows */ + os: string; + /** @example 10 */ + osVersion: string; + /** @example Other */ + device: string; + /** @example Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36 */ + userAgent: string; + botProbability: number; + }; + /** Confidence */ + Confidence: { + /** Format: float */ + score: number; + }; + /** StSeenAt */ + StSeenAt: { + /** Format: date-time */ + global: string; + /** Format: date-time */ + subscription: string | null; + }; + /** IPLocation */ + IPLocation: { + /** @example 1000 */ + accuracyRadius: number; + /** + * Format: double + * @example 37.75 + */ + latitude: number; + /** + * Format: double + * @example -97.82 + */ + longitude: number; + /** @example 130 00 */ + postalCode?: string; + /** + * Format: timezone + * @example America/Chicago + */ + timezone: string; + city?: { + /** @example Prague */ + name?: string; + }; + /** + * @example { + * "code": "US", + * "name": "United States" + * } + */ + country: components['schemas']['Location']; + /** + * @example { + * "code": "NA", + * "name": "North America" + * } + */ + continent: components['schemas']['Location']; + subdivisions?: components['schemas']['Subdivision'][]; + }; + /** Continent */ + Location: { + /** @example US */ + code: string; + /** @example United States */ + name: string; + }; + Subdivision: { + /** @example 10 */ + isoCode?: string; + /** @example Hlavni mesto Praha */ + name?: string; + }; + }; +} + +export interface operations {} + +export interface external {} diff --git a/src/types.ts b/src/types.ts index 4842148c..7dd9b105 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ import type fetchFn from 'node-fetch'; +import { components, paths } from './generatedApiTypes'; export enum Region { EU = 'EU', @@ -38,137 +39,15 @@ export interface Options { /** * More info: https://dev.fingerprintjs.com/docs/server-api#query-parameters */ -export type VisitorHistoryFilter = { - request_id?: string; - linked_id?: string; - limit?: number; - before?: number; -}; +export type VisitorHistoryFilter = paths['/visitors/{visitor_id}']['get']['parameters']['query']; /** * More info: https://dev.fingerprintjs.com/docs/server-api#response */ -export interface VisitorsResponse { - visitorId: string; - visits: Visit[]; - lastTimestamp?: number; -} - -export interface Visit { - requestId: string; - incognito: string; - linkedId: string; - time: Date; - timestamp: number; - url: string; - ip: string; - ipLocation: IpLocation; - browserDetails: BrowserDetails; - confidence: Confidence; - visitorFound: boolean; - firstSeenAt: SeenAt; - lastSeenAt: SeenAt; -} - -export interface IpLocation { - accuracyRadius: number; - latitude: number; - longitude: number; - postalCode: string; - timezone: string; - city: City; - continent: Continent; - country: Country; - subdivisions: Subdivision[]; -} - -export interface City { - name: string; -} - -export interface Continent { - code: string; - name: string; -} - -export interface Country { - code: string; - name: string; -} - -export interface Subdivision { - isoCode: string; - name: string; -} - -export interface BrowserDetails { - browserName: string; - browserMajorVersion: string; - browserFullVersion: string; - os: string; - osVersion: string; - device: string; - userAgents: string; -} - -export interface Confidence { - score: number; -} - -export interface SeenAt { - global: Date | null; - subscription: Date | null; -} +export type VisitorsResponse = + paths['/visitors/{visitor_id}']['get']['responses']['200']['content']['application/json']; /** * More info: https://dev.fingerprintjs.com/docs/webhooks#identification-webhook-object-format */ -export interface VisitWebhook { - requestId: string; - tag: any | null; - linkedId: string | null; - visitorId: string; - visitorFound: boolean | null; - timestamp: number; - time: Date; - incognito: boolean; - url: string; - clientReferrer: string | null; - ip: string; - ipLocation: { - accuracyRadius: number | null; - city: { - name: string | null; - } | null; - continent: { - code: string | null; - name: string | null; - } | null; - country: { - code: string | null; - name: string | null; - } | null; - latitude: number | null; - longitude: number | null; - postalCode: string | null; - subdivisions: - | { - isoCode: string | null; - name: string | null; - }[] - | null; - timezone: string | null; - }; - browserDetails: { - browserName: string | null; - browserFullVersion: string | null; - browserMajorVersion: string | null; - os: string | null; - osVersion: string | null; - device: string | null; - userAgent: string | null; - }; - confidence: Confidence | null; - firstSeenAt: SeenAt; - lastSeenAt: SeenAt; -} +export type VisitWebhook = components['schemas']['Visit']; diff --git a/yarn.lock b/yarn.lock index f338b58c..5889bba7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1595,6 +1595,11 @@ globals@^13.6.0, globals@^13.9.0: dependencies: type-fest "^0.20.2" +globalyzer@0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/globalyzer/-/globalyzer-0.1.0.tgz#cb76da79555669a1519d5a8edf093afaa0bf1465" + integrity sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q== + globby@^11.0.4: version "11.1.0" resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b" @@ -1607,6 +1612,11 @@ globby@^11.0.4: merge2 "^1.4.1" slash "^3.0.0" +globrex@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/globrex/-/globrex-0.1.2.tgz#dd5d9ec826232730cd6793a5e33a9302985e6098" + integrity sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg== + graceful-fs@^4.2.9: version "4.2.9" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96" @@ -2402,6 +2412,11 @@ mime-types@^2.1.12: dependencies: mime-db "1.52.0" +mime@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/mime/-/mime-3.0.0.tgz#b374550dca3a0c18443b0c950a6a58f1931cf7a7" + integrity sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A== + mimic-fn@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" @@ -2472,6 +2487,18 @@ onetime@^5.1.2: dependencies: mimic-fn "^2.1.0" +openapi-typescript@^5.4.0: + version "5.4.0" + resolved "https://registry.yarnpkg.com/openapi-typescript/-/openapi-typescript-5.4.0.tgz#9e4016c0e08be7d13ba7f83344f9940521721001" + integrity sha512-YUtsWQ01igvx0xRmJvtzpHsxtvnSORrGMDTXFY1zs3znljsJDvhsUe7XrKoNP2eUmiOIwBXQMoM8M5V+nEnIrw== + dependencies: + js-yaml "^4.1.0" + mime "^3.0.0" + prettier "^2.6.2" + tiny-glob "^0.2.9" + undici "^5.4.0" + yargs-parser "^21.0.1" + optionator@^0.8.1: version "0.8.3" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495" @@ -2606,6 +2633,11 @@ prettier@^2.6.0: resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.0.tgz#12f8f504c4d8ddb76475f441337542fa799207d4" integrity sha512-m2FgJibYrBGGgQXNzfd0PuDGShJgRavjUoRCw1mZERIWVSXF0iLzLm+aOqTAbLnC3n6JzUhAA8uZnFVghHJ86A== +prettier@^2.6.2: + version "2.7.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64" + integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g== + pretty-format@^27.0.0, pretty-format@^27.5.1: version "27.5.1" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.1.tgz#2181879fdea51a7a5851fb39d920faa63f01d88e" @@ -2899,6 +2931,14 @@ throat@^6.0.1: resolved "https://registry.yarnpkg.com/throat/-/throat-6.0.1.tgz#d514fedad95740c12c2d7fc70ea863eb51ade375" integrity sha512-8hmiGIJMDlwjg7dlJ4yKGLK8EsYqKgPWbG3b4wjJddKNwc7N7Dpn08Df4szr/sZdMVeOstrdYSsqzX6BYbcB+w== +tiny-glob@^0.2.9: + version "0.2.9" + resolved "https://registry.yarnpkg.com/tiny-glob/-/tiny-glob-0.2.9.tgz#2212d441ac17928033b110f8b3640683129d31e2" + integrity sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg== + dependencies: + globalyzer "0.1.0" + globrex "^0.1.2" + tmpl@1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.5.tgz#8683e0b902bb9c20c4f726e3c0b69f36518c07cc" @@ -3004,6 +3044,11 @@ typescript@^4.5.5: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.2.tgz#fe12d2727b708f4eef40f51598b3398baa9611d4" integrity sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg== +undici@^5.4.0: + version "5.5.1" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.5.1.tgz#baaf25844a99eaa0b22e1ef8d205bffe587c8f43" + integrity sha512-MEvryPLf18HvlCbLSzCW0U00IMftKGI5udnjrQbC5D4P0Hodwffhv+iGfWuJwg16Y/TK11ZFK8i+BPVW2z/eAw== + universalify@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" @@ -3161,6 +3206,11 @@ yargs-parser@20.x, yargs-parser@^20.2.2: resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== +yargs-parser@^21.0.1: + version "21.0.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35" + integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg== + yargs@^16.2.0: version "16.2.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66"