Skip to content

Commit

Permalink
feat: generate types using OpenAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
ilfa committed Jun 30, 2022
1 parent 4c62d93 commit 3136d5a
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 126 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
205 changes: 205 additions & 0 deletions src/generatedApiTypes.ts
Original file line number Diff line number Diff line change
@@ -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 {}
131 changes: 5 additions & 126 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type fetchFn from 'node-fetch';
import { components, paths } from './generatedApiTypes';

export enum Region {
EU = 'EU',
Expand Down Expand Up @@ -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'];
Loading

0 comments on commit 3136d5a

Please sign in to comment.