@serptech/api 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/LICENSE.md +21 -0
  2. package/Makefile +12 -0
  3. package/README.md +39 -0
  4. package/dist/SerpApi.node.js +65 -0
  5. package/dist/SerpApi.web.js +65 -0
  6. package/eslint.config.mjs +51 -0
  7. package/mychange.diff +50452 -0
  8. package/package.json +62 -0
  9. package/packages/serp-rest-api/LICENSE.md +21 -0
  10. package/packages/serp-rest-api/README.md +30 -0
  11. package/packages/serp-rest-api/dist/index.node.js +1752 -0
  12. package/packages/serp-rest-api/dist/index.web.js +1282 -0
  13. package/packages/serp-rest-api/package.json +59 -0
  14. package/packages/serp-rest-api/src/base/api.ts +15 -0
  15. package/packages/serp-rest-api/src/base/auth-api.ts +25 -0
  16. package/packages/serp-rest-api/src/base/types.ts +33 -0
  17. package/packages/serp-rest-api/src/constants/index.js +13 -0
  18. package/packages/serp-rest-api/src/http-client.ts +207 -0
  19. package/packages/serp-rest-api/src/index.ts +3 -0
  20. package/packages/serp-rest-api/src/serp-rest-api/api-facade/auth/index.ts +50 -0
  21. package/packages/serp-rest-api/src/serp-rest-api/api-facade/base.ts +58 -0
  22. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/entries/index.ts +87 -0
  23. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/index.ts +106 -0
  24. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/licenses/index.ts +28 -0
  25. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/notifications/index.ts +40 -0
  26. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/persons/index.ts +60 -0
  27. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/persons-groups/index.ts +54 -0
  28. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/sources/index.ts +46 -0
  29. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/spaces/index.ts +27 -0
  30. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/stream-tokens/index.ts +37 -0
  31. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/thresholds/index.ts +17 -0
  32. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/tokens/index.ts +32 -0
  33. package/packages/serp-rest-api/src/serp-rest-api/api-facade/v1/utilities/index.ts +82 -0
  34. package/packages/serp-rest-api/src/serp-rest-api/features/auth/v1/index.ts +58 -0
  35. package/packages/serp-rest-api/src/serp-rest-api/features/entries/v1/index.ts +70 -0
  36. package/packages/serp-rest-api/src/serp-rest-api/features/licenses/v1/index.ts +82 -0
  37. package/packages/serp-rest-api/src/serp-rest-api/features/notifications/v1/index.ts +100 -0
  38. package/packages/serp-rest-api/src/serp-rest-api/features/persons/v1/index.ts +110 -0
  39. package/packages/serp-rest-api/src/serp-rest-api/features/persons-groups/v1/index.ts +128 -0
  40. package/packages/serp-rest-api/src/serp-rest-api/features/sources/v1/index.ts +113 -0
  41. package/packages/serp-rest-api/src/serp-rest-api/features/spaces/v1/index.ts +65 -0
  42. package/packages/serp-rest-api/src/serp-rest-api/features/stream-tokens/v1/index.ts +76 -0
  43. package/packages/serp-rest-api/src/serp-rest-api/features/thresholds/v1/index.ts +32 -0
  44. package/packages/serp-rest-api/src/serp-rest-api/features/tokens/v1/index.ts +61 -0
  45. package/packages/serp-rest-api/src/serp-rest-api/features/utilities/v1/index.ts +114 -0
  46. package/packages/serp-rest-api/src/serp-rest-api/index.ts +82 -0
  47. package/packages/serp-rest-api/src/utils/data.ts +13 -0
  48. package/packages/serp-rest-api/src/utils/files.ts +83 -0
  49. package/packages/serp-rest-api/src/utils/index.ts +2 -0
  50. package/packages/serp-websocket/LICENSE.md +21 -0
  51. package/packages/serp-websocket/README.md +32 -0
  52. package/packages/serp-websocket/dist/index.node.js +400 -0
  53. package/packages/serp-websocket/dist/index.web.js +158 -0
  54. package/packages/serp-websocket/package.json +60 -0
  55. package/packages/serp-websocket/src/constants/index.ts +7 -0
  56. package/packages/serp-websocket/src/index.ts +43 -0
  57. package/packages/serp-websocket/src/v1/index.ts +183 -0
  58. package/src/index.js +7 -0
@@ -0,0 +1,114 @@
1
+ import { Api, ApiSettingsInterface } from "../../../../base/api";
2
+
3
+ import { addFileToFormData, addDataToFormData } from "../../../../utils";
4
+ import {
5
+ UtilitiesInterface,
6
+ ComparePhotosParamsInterface,
7
+ ComparePhotosResponseInterface,
8
+ ComparePersonPhotoWithDocumentPhotoParamsInterface,
9
+ VerifyPersonPhotoWithDocumentPhotoParamsInterface,
10
+ VerifyPersonPhotoWithDocumentPhotoResponseInterface,
11
+ FindOutCustomerParamsInterface,
12
+ FindOutCustomerResponseInterface,
13
+ GetApiVersionResponseInterface,
14
+ CheckAsmParamsInterface,
15
+ CheckAsmResponseInterface,
16
+ } from "../../../api-facade/v1/utilities";
17
+
18
+ class Utilities extends Api implements UtilitiesInterface {
19
+ constructor(settings: ApiSettingsInterface) {
20
+ super(settings);
21
+ this.comparePhotos = this.comparePhotos.bind(this);
22
+ this.comparePersonPhotoWithDocumentPhoto = this.comparePersonPhotoWithDocumentPhoto.bind(
23
+ this
24
+ );
25
+ this.verifyPersonPhotoWithDocumentPhoto = this.verifyPersonPhotoWithDocumentPhoto.bind(
26
+ this
27
+ );
28
+ this.findOutCustomer = this.findOutCustomer.bind(this);
29
+ this.checkAsm = this.checkAsm.bind(this);
30
+ this.getSupportedIdTypes = this.getSupportedIdTypes.bind(this);
31
+ this.getApiVersion = this.getApiVersion.bind(this);
32
+ }
33
+
34
+ comparePhotos({
35
+ image1,
36
+ image2,
37
+ result,
38
+ }: ComparePhotosParamsInterface): Promise<ComparePhotosResponseInterface> {
39
+ const fieldsData = { result };
40
+ const data = new FormData();
41
+
42
+ addFileToFormData(data, image1, "image1");
43
+ addFileToFormData(data, image2, "image2");
44
+ addDataToFormData(data, fieldsData);
45
+
46
+ return this.httpClient.post("compare/", data);
47
+ }
48
+
49
+ comparePersonPhotoWithDocumentPhoto({
50
+ photo,
51
+ facesize,
52
+ result,
53
+ }: ComparePersonPhotoWithDocumentPhotoParamsInterface): Promise<
54
+ ComparePhotosResponseInterface
55
+ > {
56
+ const fieldsData = { facesize, result };
57
+ const data = new FormData();
58
+
59
+ addFileToFormData(data, photo, "photo");
60
+ addDataToFormData(data, fieldsData);
61
+
62
+ return this.httpClient.post("faceid/compare/", data);
63
+ }
64
+
65
+ verifyPersonPhotoWithDocumentPhoto({
66
+ photo_face,
67
+ photo_face_facesize,
68
+ photo_id,
69
+ photo_id_facesize,
70
+ id_code,
71
+ result,
72
+ }: VerifyPersonPhotoWithDocumentPhotoParamsInterface): Promise<
73
+ VerifyPersonPhotoWithDocumentPhotoResponseInterface
74
+ > {
75
+ const fieldsData = {
76
+ photo_face_facesize,
77
+ photo_id_facesize,
78
+ id_code,
79
+ result,
80
+ };
81
+ const data = new FormData();
82
+
83
+ addFileToFormData(data, photo_face, "photo_face");
84
+ addFileToFormData(data, photo_id, "photo_id");
85
+ addDataToFormData(data, fieldsData);
86
+
87
+ return this.httpClient.post("faceid/verification/", data);
88
+ }
89
+
90
+ findOutCustomer({
91
+ source,
92
+ offset,
93
+ }: FindOutCustomerParamsInterface): Promise<
94
+ FindOutCustomerResponseInterface
95
+ > {
96
+ return this.httpClient.get("utility/customer/", { source, offset });
97
+ }
98
+
99
+ checkAsm({
100
+ image,
101
+ }: CheckAsmParamsInterface): Promise<CheckAsmResponseInterface> {
102
+ return this.httpClient.post("compare/", { image });
103
+ }
104
+
105
+ getSupportedIdTypes(): Promise<null> {
106
+ return this.httpClient.get("faceid/id-codes/");
107
+ }
108
+
109
+ getApiVersion(): Promise<GetApiVersionResponseInterface> {
110
+ return this.httpClient.get("version/");
111
+ }
112
+ }
113
+
114
+ export { Utilities };
@@ -0,0 +1,82 @@
1
+ import "isomorphic-form-data";
2
+
3
+ import axios from "axios";
4
+ import { createHttpClient } from "../http-client";
5
+
6
+ import { ApiFacadeV1, ApiFacadeV1Interface } from "./api-facade/v1";
7
+ import { Auth as AuthV1 } from "./features/auth/v1";
8
+ import { Entries as EntriesV1 } from "./features/entries/v1";
9
+ import { Notifications as NotificationsV1 } from "./features/notifications/v1";
10
+ import { Persons as PersonsV1 } from "./features/persons/v1";
11
+ import { Sources as SourcesV1 } from "./features/sources/v1";
12
+ import { Tokens as TokensV1 } from "./features/tokens/v1";
13
+ import { Spaces as SpacesV1 } from "./features/spaces/v1";
14
+ import { Utilities as UtilitiesV1 } from "./features/utilities/v1";
15
+ import { PersonsGroups as PersonsGroupsV1 } from "./features/persons-groups/v1";
16
+ import { Thresholds as ThresholdsV1 } from "./features/thresholds/v1";
17
+ import { StreamTokens as StreamTokensV1 } from "./features/stream-tokens/v1";
18
+ import { Licenses as LicensesV1 } from "./features/licenses/v1";
19
+
20
+ import { apiEndpoints, apiVersions } from "../constants";
21
+
22
+ interface SerpRestApiSettingsInterface {
23
+ token?: string;
24
+ version?: number;
25
+ }
26
+
27
+ function createSerpRestApiV1({
28
+ token,
29
+ }: {
30
+ token?: string;
31
+ } = {}): ApiFacadeV1Interface {
32
+ const HttpClient = createHttpClient({ client: axios });
33
+ const httpClient = new HttpClient({
34
+ baseURL: apiEndpoints.v1.base,
35
+ token,
36
+ });
37
+
38
+ return new ApiFacadeV1({
39
+ httpClient,
40
+ auth: new AuthV1({ httpClient, authURL: apiEndpoints.v1.auth }),
41
+ tokens: new TokensV1({ httpClient, authURL: apiEndpoints.v1.auth }),
42
+ spaces: new SpacesV1({ httpClient, authURL: apiEndpoints.v1.auth }),
43
+ licenses: new LicensesV1({ httpClient, authURL: apiEndpoints.v1.auth }),
44
+ notifications: new NotificationsV1({ httpClient }),
45
+ entries: new EntriesV1({ httpClient }),
46
+ persons: new PersonsV1({ httpClient }),
47
+ sources: new SourcesV1({ httpClient }),
48
+ utilities: new UtilitiesV1({ httpClient }),
49
+ personsGroups: new PersonsGroupsV1({ httpClient }),
50
+ thresholds: new ThresholdsV1({ httpClient }),
51
+ streamTokens: new StreamTokensV1({ httpClient }),
52
+ });
53
+ }
54
+
55
+ function createSerpRestApi(
56
+ settings: SerpRestApiSettingsInterface = {}
57
+ ): ApiFacadeV1Interface | undefined {
58
+ const { version, token } = settings;
59
+
60
+ if (!version) {
61
+ throw new Error(
62
+ `You did not specify Serp API version.
63
+ Available versions: ${apiVersions.join(", ")}`
64
+ );
65
+ }
66
+
67
+ const numVersion = Number(version);
68
+
69
+ if (!apiVersions.includes(numVersion)) {
70
+ throw new Error(
71
+ `You have specified a non-existent version of Serp API: ${version}.
72
+ Available versions: ${apiVersions.join(", ")}`
73
+ );
74
+ }
75
+
76
+ switch (numVersion) {
77
+ case 1:
78
+ return createSerpRestApiV1({ token });
79
+ }
80
+ }
81
+
82
+ export { createSerpRestApi };
@@ -0,0 +1,13 @@
1
+ export function removeEmpty(obj: { [key: string]: any }): any {
2
+ if (typeof obj !== "object" || obj === null || obj instanceof Array) {
3
+ return obj;
4
+ }
5
+
6
+ return Object.keys(obj)
7
+ .filter((key) => obj[key] !== undefined)
8
+ .reduce((newObj, key) => ({ ...newObj, [key]: obj[key] }), {});
9
+ }
10
+
11
+ export function isEmpty(obj: {}): boolean {
12
+ return Object.keys(obj).length === 0;
13
+ }
@@ -0,0 +1,83 @@
1
+ import { removeEmpty } from "./index";
2
+
3
+ // convert base64/URLEncoded data component to raw binary data held in a string
4
+ function dataURItoBlob(dataURI: string): Blob {
5
+ let byteString;
6
+
7
+ if (dataURI.split(",")[0].indexOf("base64") >= 0) {
8
+ byteString = atob(dataURI.split(",")[1]);
9
+ } else {
10
+ byteString = unescape(dataURI.split(",")[1]);
11
+ }
12
+
13
+ // separate out the mime component
14
+ const mimeString = dataURI.split(",")[0].split(":")[1].split(";")[0];
15
+ // write the bytes of the string to a typed array
16
+ const ia = new Uint8Array(byteString.length);
17
+
18
+ for (let i = 0; i < byteString.length; i++) {
19
+ ia[i] = byteString.charCodeAt(i);
20
+ }
21
+
22
+ return new Blob([ia], { type: mimeString });
23
+ }
24
+
25
+ function getFileExtensionFromBase64String(base64: string): string {
26
+ return base64.substring("data:image/".length, base64.indexOf(";base64"));
27
+ }
28
+
29
+ export function addFileToFormData(
30
+ formData: FormData,
31
+ file: File | string,
32
+ fieldName: string,
33
+ fileName?: string
34
+ ): FormData {
35
+ if (!file) return formData;
36
+
37
+ if (typeof file === "string") {
38
+ const formFieldName =
39
+ fileName || `${fieldName}.${getFileExtensionFromBase64String(file)}`;
40
+
41
+ formData.append(fieldName, dataURItoBlob(file), formFieldName);
42
+ } else {
43
+ const formFieldName = fileName || file.name;
44
+
45
+ formData.append(fieldName, file, formFieldName);
46
+ }
47
+
48
+ return formData;
49
+ }
50
+
51
+ interface FieldsData {
52
+ [key: string]: any;
53
+ }
54
+
55
+ export function addDataToFormData(
56
+ formData: FormData,
57
+ fieldsData: FieldsData
58
+ ): FormData {
59
+ if (!formData) return formData;
60
+
61
+ Object.keys(removeEmpty(fieldsData)).forEach((key) => {
62
+ const value = fieldsData[key];
63
+
64
+ formData.append(key, value);
65
+ });
66
+
67
+ return formData;
68
+ }
69
+
70
+ export function getFormDataSize(formData: FormData): number {
71
+ if (!formData) return 0;
72
+
73
+ return Array.from(formData.entries(), ([_, prop]) => {
74
+ if (typeof prop === "string") {
75
+ return prop.length;
76
+ }
77
+ if (prop.size) {
78
+ return prop.size;
79
+ }
80
+
81
+ return 0;
82
+ }).reduce((resultLength, length) => resultLength + length, 0);
83
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./data";
2
+ export * from "./files";
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (C) 2024, Serptech, d@serptech.ru
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # Serp WebSocket Client TS/JS library
2
+
3
+ ## Installation
4
+
5
+ ### NPM
6
+
7
+ ```bash
8
+ npm i --save @serp/websocket
9
+ ```
10
+
11
+ ### Yarn
12
+
13
+ ```bash
14
+ yarn add @serp/websocket
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```js
20
+ // ES2015 module import:
21
+ import { createSerpWsApi } from "@serp/websocket";
22
+
23
+ // CommonJS module require:
24
+ const { createSerpWsApi } = require("@serp/websocket");
25
+
26
+ const SerpWsApi = createSerpWsApi({
27
+ version: 1,
28
+ token: SERP_TOKEN,
29
+ });
30
+
31
+ SerpWsApi.connect();
32
+ ```