@prosopo/api 0.2.11 → 0.2.14
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/dist/api/HttpClientBase.d.ts +5 -4
- package/dist/api/HttpClientBase.d.ts.map +1 -1
- package/dist/api/HttpClientBase.js +50 -9
- package/dist/api/HttpClientBase.js.map +1 -1
- package/dist/api/HttpError.d.ts +7 -0
- package/dist/api/HttpError.d.ts.map +1 -0
- package/dist/api/HttpError.js +10 -0
- package/dist/api/HttpError.js.map +1 -0
- package/dist/api/ProviderApi.d.ts +1 -1
- package/dist/api/ProviderApi.d.ts.map +1 -1
- package/dist/api/ProviderApi.js +5 -5
- package/dist/api/ProviderApi.js.map +1 -1
- package/dist/cjs/api/HttpClientBase.cjs +46 -9
- package/dist/cjs/api/HttpError.cjs +12 -0
- package/dist/cjs/api/ProviderApi.cjs +5 -5
- package/package.json +4 -5
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
1
|
export declare class HttpClientBase {
|
|
3
|
-
protected readonly
|
|
2
|
+
protected readonly baseURL: string;
|
|
4
3
|
constructor(baseURL: string, prefix?: string);
|
|
5
|
-
protected
|
|
6
|
-
protected
|
|
4
|
+
protected fetch<T>(input: RequestInfo, init?: RequestInit): Promise<T>;
|
|
5
|
+
protected post<T, U>(input: RequestInfo, body: U, init?: RequestInit): Promise<T>;
|
|
6
|
+
protected responseHandler<T>(response: Response): Promise<T>;
|
|
7
|
+
protected errorHandler(error: Error): Promise<never>;
|
|
7
8
|
}
|
|
8
9
|
export default HttpClientBase;
|
|
9
10
|
//# sourceMappingURL=HttpClientBase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClientBase.d.ts","sourceRoot":"","sources":["../../src/api/HttpClientBase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpClientBase.d.ts","sourceRoot":"","sources":["../../src/api/HttpClientBase.ts"],"names":[],"mappings":"AAeA,qBAAa,cAAc;IACvB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;gBAEtB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAK;cAIxB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;cAY5D,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;cAkBvE,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC;IASlE,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;CAQvD;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -11,17 +11,58 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
import {
|
|
14
|
+
import { HttpError } from './HttpError.js';
|
|
15
15
|
export class HttpClientBase {
|
|
16
16
|
constructor(baseURL, prefix = '') {
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
this.baseURL = baseURL + prefix;
|
|
18
|
+
}
|
|
19
|
+
async fetch(input, init) {
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(this.baseURL + input, init);
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw new HttpError(response.status, response.statusText, response.url);
|
|
24
|
+
}
|
|
25
|
+
return this.responseHandler(response);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return this.errorHandler(error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async post(input, body, init) {
|
|
32
|
+
const headers = { 'Content-Type': 'application/json', ...(init?.headers || {}) };
|
|
33
|
+
try {
|
|
34
|
+
const response = await fetch(this.baseURL + input, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
body: JSON.stringify(body),
|
|
37
|
+
headers,
|
|
38
|
+
...init,
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new HttpError(response.status, response.statusText, response.url);
|
|
42
|
+
}
|
|
43
|
+
return this.responseHandler(response);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
return this.errorHandler(error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async responseHandler(response) {
|
|
50
|
+
try {
|
|
51
|
+
return await response.json();
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('Error parsing JSON:', error);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
errorHandler(error) {
|
|
59
|
+
if (error instanceof HttpError) {
|
|
60
|
+
console.error('HTTP error:', error);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.error('API request error:', error);
|
|
64
|
+
}
|
|
65
|
+
return Promise.reject(error);
|
|
25
66
|
}
|
|
26
67
|
}
|
|
27
68
|
export default HttpClientBase;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClientBase.js","sourceRoot":"","sources":["../../src/api/HttpClientBase.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"HttpClientBase.js","sourceRoot":"","sources":["../../src/api/HttpClientBase.ts"],"names":[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;aACV,CAAC,CAAA;YACF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;gBACd,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAA;aAC1E;YACD,OAAO,IAAI,CAAC,eAAe,CAAI,QAAQ,CAAC,CAAA;SAC3C;QAAC,OAAO,KAAK,EAAE;YACZ,OAAO,IAAI,CAAC,YAAY,CAAC,KAAc,CAAC,CAAA;SAC3C;IACL,CAAC;IAES,KAAK,CAAC,eAAe,CAAI,QAAkB;QACjD,IAAI;YACA,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;SAC/B;QAAC,OAAO,KAAK,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAA;YAC3C,MAAM,KAAK,CAAA;SACd;IACL,CAAC;IAES,YAAY,CAAC,KAAY;QAC/B,IAAI,KAAK,YAAY,SAAS,EAAE;YAC5B,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAA;SACtC;aAAM;YACH,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAA;SAC7C;QACD,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAChC,CAAC;CACJ;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpError.d.ts","sourceRoot":"","sources":["../../src/api/HttpError.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;IAErB,MAAM,EAAE,MAAM;IACd,UAAU,EAAE,MAAM;IAClB,GAAG,EAAE,MAAM;gBAFX,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM;CAKzB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class HttpError extends Error {
|
|
2
|
+
constructor(status, statusText, url) {
|
|
3
|
+
super(`HTTP error! status: ${status} (${statusText}) for URL: ${url}`);
|
|
4
|
+
this.status = status;
|
|
5
|
+
this.statusText = statusText;
|
|
6
|
+
this.url = url;
|
|
7
|
+
this.name = 'HttpError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=HttpError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../../src/api/HttpError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAU,SAAQ,KAAK;IAChC,YACW,MAAc,EACd,UAAkB,EAClB,GAAW;QAElB,KAAK,CAAC,uBAAuB,MAAM,KAAK,UAAU,cAAc,GAAG,EAAE,CAAC,CAAA;QAJ/D,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,QAAG,GAAH,GAAG,CAAQ;QAGlB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;IAC3B,CAAC;CACJ"}
|
|
@@ -2,7 +2,7 @@ import { AccountId } from '@prosopo/types';
|
|
|
2
2
|
import { CaptchaSolution } from '@prosopo/types';
|
|
3
3
|
import { CaptchaSolutionResponse, GetCaptchaResponse, ProviderRegistered, VerificationResponse } from '../types/index.js';
|
|
4
4
|
import { NetworkConfig } from '@prosopo/types';
|
|
5
|
-
import { Provider, RandomProvider } from '@prosopo/captcha-contract';
|
|
5
|
+
import { Provider, RandomProvider } from '@prosopo/captcha-contract/types-returns';
|
|
6
6
|
import HttpClientBase from './HttpClientBase.js';
|
|
7
7
|
export default class ProviderApi extends HttpClientBase {
|
|
8
8
|
private network;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderApi.d.ts","sourceRoot":"","sources":["../../src/api/ProviderApi.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAEH,eAAe,EAIlB,MAAM,gBAAgB,C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AAO,CAAC,kBAAkB,CAAC;IAIhD,kBAAkB,IAAI,OAAO,CAAC,QAAQ,CAAC;CAGjD"}
|
package/dist/api/ProviderApi.js
CHANGED
|
@@ -18,7 +18,7 @@ export default class ProviderApi extends HttpClientBase {
|
|
|
18
18
|
.toString()
|
|
19
19
|
.replace(/,/g, '')}`;
|
|
20
20
|
console.log(url);
|
|
21
|
-
return this.
|
|
21
|
+
return this.fetch(url);
|
|
22
22
|
}
|
|
23
23
|
submitCaptchaSolution(captchas, requestHash, userAccount, salt, signature) {
|
|
24
24
|
const captchaSolutionBody = CaptchaSolutionBody.parse({
|
|
@@ -29,20 +29,20 @@ export default class ProviderApi extends HttpClientBase {
|
|
|
29
29
|
salt,
|
|
30
30
|
signature,
|
|
31
31
|
});
|
|
32
|
-
return this.
|
|
32
|
+
return this.post(ApiPaths.SubmitCaptchaSolution, captchaSolutionBody);
|
|
33
33
|
}
|
|
34
34
|
verifyDappUser(userAccount, commitmentId) {
|
|
35
35
|
const payload = { user: userAccount };
|
|
36
36
|
if (commitmentId) {
|
|
37
37
|
payload['commitmentId'] = commitmentId;
|
|
38
38
|
}
|
|
39
|
-
return this.
|
|
39
|
+
return this.post(ApiPaths.VerifyCaptchaSolution, payload);
|
|
40
40
|
}
|
|
41
41
|
getProviderStatus() {
|
|
42
|
-
return this.
|
|
42
|
+
return this.fetch(ApiPaths.GetProviderStatus);
|
|
43
43
|
}
|
|
44
44
|
getProviderDetails() {
|
|
45
|
-
return this.
|
|
45
|
+
return this.fetch(ApiPaths.GetProviderDetails);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
//# sourceMappingURL=ProviderApi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderApi.js","sourceRoot":"","sources":["../../src/api/ProviderApi.ts"],"names":[],"mappings":"AAcA,OAAO,EACH,QAAQ,EAER,mBAAmB,GAGtB,MAAM,gBAAgB,CAAA;AASvB,OAAO,cAAc,MAAM,qBAAqB,CAA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CAAA;SACzC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE,OAAiC,CAAC,CAAA;IACvF,CAAC;IAEM,iBAAiB;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAA;IACjD,CAAC;IAEM,kBAAkB;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAA;IAClD,CAAC;CACJ"}
|
|
@@ -1,16 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const
|
|
3
|
+
const HttpError = require("./HttpError.cjs");
|
|
4
4
|
class HttpClientBase {
|
|
5
5
|
constructor(baseURL, prefix = "") {
|
|
6
|
-
this.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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) {
|
|
12
|
+
throw new HttpError.HttpError(response.status, response.statusText, response.url);
|
|
13
|
+
}
|
|
14
|
+
return this.responseHandler(response);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
return this.errorHandler(error);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async post(input, body, init) {
|
|
20
|
+
const headers = { "Content-Type": "application/json", ...(init == null ? void 0 : init.headers) || {} };
|
|
21
|
+
try {
|
|
22
|
+
const response = await fetch(this.baseURL + input, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
body: JSON.stringify(body),
|
|
25
|
+
headers,
|
|
26
|
+
...init
|
|
27
|
+
});
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
throw new HttpError.HttpError(response.status, response.statusText, response.url);
|
|
30
|
+
}
|
|
31
|
+
return this.responseHandler(response);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return this.errorHandler(error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async responseHandler(response) {
|
|
37
|
+
try {
|
|
38
|
+
return await response.json();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error("Error parsing JSON:", error);
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
errorHandler(error) {
|
|
45
|
+
if (error instanceof HttpError.HttpError) {
|
|
46
|
+
console.error("HTTP error:", error);
|
|
47
|
+
} else {
|
|
48
|
+
console.error("API request error:", error);
|
|
49
|
+
}
|
|
50
|
+
return Promise.reject(error);
|
|
14
51
|
}
|
|
15
52
|
}
|
|
16
53
|
exports.HttpClientBase = 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;
|
|
@@ -17,7 +17,7 @@ class ProviderApi extends HttpClientBase.HttpClientBase {
|
|
|
17
17
|
const dappAccount = this.account;
|
|
18
18
|
const url = `${types.ApiPaths.GetCaptchaChallenge}/${provider.datasetId}/${userAccount}/${dappAccount}/${blockNumber.toString().replace(/,/g, "")}`;
|
|
19
19
|
console.log(url);
|
|
20
|
-
return this.
|
|
20
|
+
return this.fetch(url);
|
|
21
21
|
}
|
|
22
22
|
submitCaptchaSolution(captchas, requestHash, userAccount, salt, signature) {
|
|
23
23
|
const captchaSolutionBody = types.CaptchaSolutionBody.parse({
|
|
@@ -28,20 +28,20 @@ class ProviderApi extends HttpClientBase.HttpClientBase {
|
|
|
28
28
|
salt,
|
|
29
29
|
signature
|
|
30
30
|
});
|
|
31
|
-
return this.
|
|
31
|
+
return this.post(types.ApiPaths.SubmitCaptchaSolution, captchaSolutionBody);
|
|
32
32
|
}
|
|
33
33
|
verifyDappUser(userAccount, commitmentId) {
|
|
34
34
|
const payload = { user: userAccount };
|
|
35
35
|
if (commitmentId) {
|
|
36
36
|
payload["commitmentId"] = commitmentId;
|
|
37
37
|
}
|
|
38
|
-
return this.
|
|
38
|
+
return this.post(types.ApiPaths.VerifyCaptchaSolution, payload);
|
|
39
39
|
}
|
|
40
40
|
getProviderStatus() {
|
|
41
|
-
return this.
|
|
41
|
+
return this.fetch(types.ApiPaths.GetProviderStatus);
|
|
42
42
|
}
|
|
43
43
|
getProviderDetails() {
|
|
44
|
-
return this.
|
|
44
|
+
return this.fetch(types.ApiPaths.GetProviderDetails);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
module.exports = ProviderApi;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"description": "Wrapper for the provider API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,12 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/prosopo/captcha#readme",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@prosopo/types": "0.2.
|
|
36
|
-
"axios": "^1.5.0"
|
|
35
|
+
"@prosopo/types": "0.2.14"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
|
-
"@prosopo/captcha-contract": "0.2.
|
|
40
|
-
"@prosopo/config": "0.2.
|
|
38
|
+
"@prosopo/captcha-contract": "0.2.14",
|
|
39
|
+
"@prosopo/config": "0.2.14",
|
|
41
40
|
"tslib": "2.6.2",
|
|
42
41
|
"typescript": "5.1.6"
|
|
43
42
|
},
|