@prosopo/api 2.5.5 → 2.6.1
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.
- package/CHANGELOG.md +19 -0
- package/dist/cjs/api/HttpClientBase.cjs +59 -0
- package/dist/cjs/api/HttpError.cjs +12 -0
- package/dist/cjs/api/ProviderApi.cjs +190 -0
- package/dist/cjs/api/index.cjs +6 -0
- package/dist/cjs/index.cjs +7 -0
- package/package.json +5 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @prosopo/api
|
|
2
|
+
|
|
3
|
+
## 2.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [52feffc]
|
|
8
|
+
- @prosopo/types@2.6.1
|
|
9
|
+
|
|
10
|
+
## 2.6.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- a0bfc8a: bump all pkg versions since independent versioning applied
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [a0bfc8a]
|
|
19
|
+
- @prosopo/types@2.6.0
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const HttpError = require("./HttpError.cjs");
|
|
4
|
+
class HttpClientBase {
|
|
5
|
+
constructor(baseURL, prefix = "") {
|
|
6
|
+
this.baseURL = baseURL + prefix;
|
|
7
|
+
}
|
|
8
|
+
async fetch(input, init) {
|
|
9
|
+
try {
|
|
10
|
+
const response = await fetch(this.baseURL + input, init);
|
|
11
|
+
if (!response.ok && // Only throw an error if the response is not JSON and not a 400 error
|
|
12
|
+
response.status !== 400 && !response.headers.get("content-type")?.includes("application/json")) {
|
|
13
|
+
throw new HttpError.HttpError(response.status, response.statusText, response.url);
|
|
14
|
+
}
|
|
15
|
+
return this.responseHandler(response);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
return this.errorHandler(error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async post(input, body, init) {
|
|
21
|
+
const headers = {
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
...init?.headers || {}
|
|
24
|
+
};
|
|
25
|
+
try {
|
|
26
|
+
const response = await fetch(this.baseURL + input, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
body: JSON.stringify(body),
|
|
29
|
+
...init,
|
|
30
|
+
headers
|
|
31
|
+
});
|
|
32
|
+
if (!response.ok && // Only throw an error if the response is not JSON and not a 400 error
|
|
33
|
+
response.status !== 400 && !response.headers.get("content-type")?.includes("application/json")) {
|
|
34
|
+
throw new HttpError.HttpError(response.status, response.statusText, response.url);
|
|
35
|
+
}
|
|
36
|
+
return this.responseHandler(response);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return this.errorHandler(error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async responseHandler(response) {
|
|
42
|
+
try {
|
|
43
|
+
return await response.json();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error("Error parsing JSON:", error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
errorHandler(error) {
|
|
50
|
+
if (error instanceof HttpError.HttpError) {
|
|
51
|
+
console.error("HTTP error:", error);
|
|
52
|
+
} else {
|
|
53
|
+
console.error("API request error:", error);
|
|
54
|
+
}
|
|
55
|
+
return Promise.reject(error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.HttpClientBase = HttpClientBase;
|
|
59
|
+
exports.default = HttpClientBase;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
class HttpError extends Error {
|
|
4
|
+
constructor(status, statusText, url) {
|
|
5
|
+
super(`HTTP error! status: ${status} (${statusText}) for URL: ${url}`);
|
|
6
|
+
this.status = status;
|
|
7
|
+
this.statusText = statusText;
|
|
8
|
+
this.url = url;
|
|
9
|
+
this.name = "HttpError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.HttpError = HttpError;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const types = require("@prosopo/types");
|
|
3
|
+
const HttpClientBase = require("./HttpClientBase.cjs");
|
|
4
|
+
class ProviderApi extends HttpClientBase.HttpClientBase {
|
|
5
|
+
constructor(providerUrl, account) {
|
|
6
|
+
const providerUrlWithProtocol = !providerUrl.startsWith("http") ? `https://${providerUrl}` : providerUrl;
|
|
7
|
+
super(providerUrlWithProtocol);
|
|
8
|
+
this.account = account;
|
|
9
|
+
}
|
|
10
|
+
getCaptchaChallenge(userAccount, randomProvider, sessionId) {
|
|
11
|
+
const { provider } = randomProvider;
|
|
12
|
+
const dappAccount = this.account;
|
|
13
|
+
const body = {
|
|
14
|
+
[types.ApiParams.dapp]: dappAccount,
|
|
15
|
+
[types.ApiParams.user]: userAccount,
|
|
16
|
+
[types.ApiParams.datasetId]: provider.datasetId
|
|
17
|
+
};
|
|
18
|
+
if (sessionId) {
|
|
19
|
+
body[types.ApiParams.sessionId] = sessionId;
|
|
20
|
+
}
|
|
21
|
+
return this.post(types.ClientApiPaths.GetImageCaptchaChallenge, body, {
|
|
22
|
+
headers: {
|
|
23
|
+
"Prosopo-Site-Key": this.account,
|
|
24
|
+
"Prosopo-User": userAccount
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
submitCaptchaSolution(captchas, requestHash, userAccount, timestamp, providerRequestHashSignature, userTimestampSignature) {
|
|
29
|
+
const body = {
|
|
30
|
+
[types.ApiParams.user]: userAccount,
|
|
31
|
+
[types.ApiParams.dapp]: this.account,
|
|
32
|
+
[types.ApiParams.captchas]: captchas,
|
|
33
|
+
[types.ApiParams.requestHash]: requestHash,
|
|
34
|
+
[types.ApiParams.timestamp]: timestamp,
|
|
35
|
+
[types.ApiParams.signature]: {
|
|
36
|
+
[types.ApiParams.user]: {
|
|
37
|
+
[types.ApiParams.timestamp]: userTimestampSignature
|
|
38
|
+
},
|
|
39
|
+
[types.ApiParams.provider]: {
|
|
40
|
+
[types.ApiParams.requestHash]: providerRequestHashSignature
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return this.post(types.ClientApiPaths.SubmitImageCaptchaSolution, body, {
|
|
45
|
+
headers: {
|
|
46
|
+
"Prosopo-Site-Key": this.account,
|
|
47
|
+
"Prosopo-User": userAccount
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
verifyDappUser(token, signature, userAccount, maxVerifiedTime) {
|
|
52
|
+
const payload = {
|
|
53
|
+
[types.ApiParams.token]: token,
|
|
54
|
+
[types.ApiParams.dappSignature]: signature
|
|
55
|
+
};
|
|
56
|
+
if (maxVerifiedTime) {
|
|
57
|
+
payload[types.ApiParams.maxVerifiedTime] = maxVerifiedTime;
|
|
58
|
+
}
|
|
59
|
+
return this.post(types.ClientApiPaths.VerifyImageCaptchaSolutionDapp, payload, {
|
|
60
|
+
headers: {
|
|
61
|
+
"Prosopo-Site-Key": this.account,
|
|
62
|
+
"Prosopo-User": userAccount
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
getPowCaptchaChallenge(user, dapp, sessionId) {
|
|
67
|
+
const body = {
|
|
68
|
+
[types.ApiParams.user]: user.toString(),
|
|
69
|
+
[types.ApiParams.dapp]: dapp.toString(),
|
|
70
|
+
...sessionId && { [types.ApiParams.sessionId]: sessionId }
|
|
71
|
+
};
|
|
72
|
+
return this.post(types.ClientApiPaths.GetPowCaptchaChallenge, body, {
|
|
73
|
+
headers: {
|
|
74
|
+
"Prosopo-Site-Key": this.account,
|
|
75
|
+
"Prosopo-User": user
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
submitPowCaptchaSolution(challenge, userAccount, dappAccount, nonce, userTimestampSignature, timeout) {
|
|
80
|
+
const body = types.SubmitPowCaptchaSolutionBody.parse({
|
|
81
|
+
[types.ApiParams.challenge]: challenge.challenge,
|
|
82
|
+
[types.ApiParams.difficulty]: challenge.difficulty,
|
|
83
|
+
[types.ApiParams.timestamp]: challenge.timestamp,
|
|
84
|
+
[types.ApiParams.user]: userAccount.toString(),
|
|
85
|
+
[types.ApiParams.dapp]: dappAccount.toString(),
|
|
86
|
+
[types.ApiParams.nonce]: nonce,
|
|
87
|
+
[types.ApiParams.verifiedTimeout]: timeout,
|
|
88
|
+
[types.ApiParams.signature]: {
|
|
89
|
+
[types.ApiParams.provider]: challenge[types.ApiParams.signature][types.ApiParams.provider],
|
|
90
|
+
[types.ApiParams.user]: {
|
|
91
|
+
[types.ApiParams.timestamp]: userTimestampSignature
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return this.post(types.ClientApiPaths.SubmitPowCaptchaSolution, body, {
|
|
96
|
+
headers: {
|
|
97
|
+
"Prosopo-Site-Key": this.account,
|
|
98
|
+
"Prosopo-User": userAccount
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
getFrictionlessCaptcha(token, dapp, user) {
|
|
103
|
+
const body = {
|
|
104
|
+
[types.ApiParams.token]: token,
|
|
105
|
+
[types.ApiParams.dapp]: dapp,
|
|
106
|
+
[types.ApiParams.user]: user
|
|
107
|
+
};
|
|
108
|
+
return this.post(types.ClientApiPaths.GetFrictionlessCaptchaChallenge, body, {
|
|
109
|
+
headers: {
|
|
110
|
+
"Prosopo-Site-Key": this.account,
|
|
111
|
+
"Prosopo-User": user
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
submitUserEvents(events, string) {
|
|
116
|
+
return this.post(
|
|
117
|
+
types.ClientApiPaths.SubmitUserEvents,
|
|
118
|
+
{ events, string },
|
|
119
|
+
{
|
|
120
|
+
headers: {
|
|
121
|
+
"Prosopo-Site-Key": this.account
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
getProviderStatus() {
|
|
127
|
+
return this.fetch(types.ClientApiPaths.GetProviderStatus, {
|
|
128
|
+
headers: {
|
|
129
|
+
"Prosopo-Site-Key": this.account
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
getProviderDetails() {
|
|
134
|
+
return this.fetch(types.PublicApiPaths.GetProviderDetails, {
|
|
135
|
+
headers: {
|
|
136
|
+
"Prosopo-Site-Key": this.account
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
submitPowCaptchaVerify(token, signatureHex, recencyLimit, user) {
|
|
141
|
+
const body = {
|
|
142
|
+
[types.ApiParams.token]: token,
|
|
143
|
+
[types.ApiParams.dappSignature]: signatureHex,
|
|
144
|
+
[types.ApiParams.verifiedTimeout]: recencyLimit
|
|
145
|
+
};
|
|
146
|
+
return this.post(types.ClientApiPaths.VerifyPowCaptchaSolution, body, {
|
|
147
|
+
headers: {
|
|
148
|
+
"Prosopo-Site-Key": this.account,
|
|
149
|
+
"Prosopo-User": user
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
registerSiteKey(siteKey, tier, settings, timestamp, signature) {
|
|
154
|
+
const body = { siteKey, tier, settings };
|
|
155
|
+
return this.post(types.AdminApiPaths.SiteKeyRegister, body, {
|
|
156
|
+
headers: {
|
|
157
|
+
"Prosopo-Site-Key": this.account,
|
|
158
|
+
timestamp,
|
|
159
|
+
signature
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
updateDetectorKey(detectorKey, timestamp, signature) {
|
|
164
|
+
return this.post(
|
|
165
|
+
types.AdminApiPaths.UpdateDetectorKey,
|
|
166
|
+
types.UpdateDetectorKeyBody.parse({ detectorKey }),
|
|
167
|
+
{
|
|
168
|
+
headers: {
|
|
169
|
+
"Prosopo-Site-Key": this.account,
|
|
170
|
+
timestamp,
|
|
171
|
+
signature
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
removeDetectorKey(detectorKey, timestamp, signature) {
|
|
177
|
+
return this.post(
|
|
178
|
+
types.AdminApiPaths.RemoveDetectorKey,
|
|
179
|
+
types.UpdateDetectorKeyBody.parse({ detectorKey }),
|
|
180
|
+
{
|
|
181
|
+
headers: {
|
|
182
|
+
"Prosopo-Site-Key": this.account,
|
|
183
|
+
timestamp,
|
|
184
|
+
signature
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
module.exports = ProviderApi;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const HttpClientBase = require("./HttpClientBase.cjs");
|
|
4
|
+
const ProviderApi = require("./ProviderApi.cjs");
|
|
5
|
+
exports.HttpClientBase = HttpClientBase.HttpClientBase;
|
|
6
|
+
exports.ProviderApi = ProviderApi;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
require("./api/index.cjs");
|
|
4
|
+
const ProviderApi = require("./api/ProviderApi.cjs");
|
|
5
|
+
const HttpClientBase = require("./api/HttpClientBase.cjs");
|
|
6
|
+
exports.ProviderApi = ProviderApi;
|
|
7
|
+
exports.HttpClientBase = HttpClientBase.HttpClientBase;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "Wrapper for the provider API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/prosopo/captcha.git"
|
|
25
|
+
"url": "git+https://github.com/prosopo/captcha.git",
|
|
26
|
+
"directory": "packages/api"
|
|
26
27
|
},
|
|
27
28
|
"author": "PROSOPO LIMITED <info@prosopo.io>",
|
|
28
29
|
"license": "Apache-2.0",
|
|
@@ -31,11 +32,11 @@
|
|
|
31
32
|
},
|
|
32
33
|
"homepage": "https://github.com/prosopo/captcha#readme",
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@prosopo/types": "2.
|
|
35
|
+
"@prosopo/types": "2.6.1",
|
|
35
36
|
"express": "4.21.2"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@prosopo/config": "2.
|
|
39
|
+
"@prosopo/config": "2.6.0",
|
|
39
40
|
"@vitest/coverage-v8": "3.0.9",
|
|
40
41
|
"concurrently": "9.0.1",
|
|
41
42
|
"del-cli": "6.0.0",
|