Skip to content

Commit 5f51dcf

Browse files
author
Dominik Hošic
committed
Package json git, bugs and homepage urls, endpoints loading bugfix
1 parent 549a837 commit 5f51dcf

File tree

7 files changed

+42
-22
lines changed

7 files changed

+42
-22
lines changed

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@foxentry/js-sdk",
3-
"version": "1.0.0",
3+
"version": "1.0.3",
44
"main": "dist/index.js",
55
"module": "dist/index.m.js",
66
"unpkg": "dist/index.umd.js",
@@ -20,6 +20,15 @@
2020
"sdk"
2121
],
2222
"author": "Foxentry",
23+
"homepage": "https://github.com/Foxentry/js-sdk#readme",
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/Foxentry/js-sdk.git"
27+
},
28+
"bugs": {
29+
"url": "https://github.com/Foxentry/js-sdk/issues",
30+
"email": "[email protected]"
31+
},
2332
"license": "MIT",
2433
"description": "JS SDK for Foxentry.com",
2534
"devDependencies": {

src/Resource/BaseResource.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import Request from '../Request'
22
import { Response } from '../Response';
33

4+
export enum Endpoint {
5+
CompanyValidate = "company/validate",
6+
CompanySearch = "company/search",
7+
CompanyGet = "company/get",
8+
LocationValidate = "location/validate",
9+
LocationSearch = "location/search",
10+
LocationGet = "location/get",
11+
LocationLocalize = "location/localize",
12+
NameValidate = "name/validate",
13+
EmailValidate = "email/validate",
14+
EmailSearch = "email/search",
15+
PhoneValidate = "phone/validate"
16+
}
17+
418
/**
519
* Base resource class for handling common resource functionality.
620
*/
@@ -76,13 +90,10 @@ export default abstract class BaseResource {
7690
* Sends a request to the specified endpoint with the given query parameters.
7791
*
7892
* @param {Record<string, any>} query - The query parameters to send with the request.
79-
* @param {string} methodName - The name of the method to call on the endpoint.
93+
* @param {string} endpoint - The endpoint to call e.g. "email/validate".
8094
* @return {Promise<Response>} A promise that resolves to the response from the request.
8195
*/
82-
protected async send(query: Record<string, any>, methodName: string): Promise<Response> {
83-
const callerClass = this.constructor.name.toLowerCase();
84-
const endpoint = `${callerClass}/${methodName}`;
85-
96+
protected async send(query: Record<string, any>, endpoint: Endpoint): Promise<Response> {
8697
this.request.setEndpoint(endpoint);
8798
this.request.setQuery(query);
8899
const r = await this.request.send()

src/Resource/Company.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import BaseResource from './BaseResource';
1+
import BaseResource, {Endpoint} from './BaseResource';
22
import { Response } from '../Response';
33

44
/**
@@ -13,7 +13,7 @@ export default class Company extends BaseResource {
1313
* @returns A promise resolving to the response from the validation request
1414
*/
1515
public validate(query: Record<string, any>): Promise<Response> {
16-
return super.send(query, 'validate');
16+
return super.send(query, Endpoint.CompanyValidate);
1717
}
1818

1919
/**
@@ -24,7 +24,7 @@ export default class Company extends BaseResource {
2424
* @returns A promise resolving to the response from the API
2525
*/
2626
public search(query: Record<string, any>): Promise<Response> {
27-
return super.send(query, 'search');
27+
return super.send(query, Endpoint.CompanySearch);
2828
}
2929

3030
/**
@@ -35,6 +35,6 @@ export default class Company extends BaseResource {
3535
* @returns A promise resolving to the response from the API
3636
*/
3737
public get(query: Record<string, any>): Promise<Response> {
38-
return super.send(query, 'get');
38+
return super.send(query, Endpoint.CompanyGet);
3939
}
4040
}

src/Resource/Email.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Response } from '../Response';
2-
import BaseResource from './BaseResource';
2+
import BaseResource, { Endpoint } from './BaseResource';
33

44
/**
55
* Email resource class for validating and searching email addresses.
@@ -14,7 +14,7 @@ export default class Email extends BaseResource {
1414
*/
1515
public validate(query: string | Record<string, any>): Promise<Response> {
1616
const emailQuery = typeof query === 'string' ? { email: query } : query;
17-
return super.send(emailQuery, 'validate');
17+
return super.send(emailQuery, Endpoint.EmailValidate);
1818
}
1919

2020

@@ -26,6 +26,6 @@ export default class Email extends BaseResource {
2626
*/
2727
public search(query: string | Record<string, any>): Promise<Response> {
2828
const searchQuery = typeof query === 'string' ? { value: query } : query;
29-
return super.send(searchQuery, 'search');
29+
return super.send(searchQuery, Endpoint.EmailSearch);
3030
}
3131
}

src/Resource/Location.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import BaseResource from './BaseResource';
1+
import BaseResource, {Endpoint} from './BaseResource';
22
import { Response } from '../Response';
33

44
/**
@@ -13,7 +13,7 @@ export default class Location extends BaseResource {
1313
* @returns A promise resolving to the response from the validation request
1414
*/
1515
public validate(query: Record<string, any>): Promise<Response> {
16-
return super.send(query, 'validate');
16+
return super.send(query, Endpoint.LocationValidate);
1717
}
1818

1919
/**
@@ -24,7 +24,7 @@ export default class Location extends BaseResource {
2424
* @returns A promise resolving to the response from the API
2525
*/
2626
public search(query: Record<string, any>): Promise<Response> {
27-
return super.send(query, 'search');
27+
return super.send(query, Endpoint.LocationSearch);
2828
}
2929

3030
/**
@@ -35,7 +35,7 @@ export default class Location extends BaseResource {
3535
* @returns A promise resolving to the response from the API
3636
*/
3737
public get(query: Record<string, any>): Promise<Response> {
38-
return super.send(query, 'get');
38+
return super.send(query, Endpoint.LocationGet);
3939
}
4040

4141
/**
@@ -46,6 +46,6 @@ export default class Location extends BaseResource {
4646
* @returns A promise resolving to the response from the API
4747
*/
4848
public localize(query: Record<string, any>): Promise<Response> {
49-
return super.send(query, 'localize');
49+
return super.send(query, Endpoint.LocationLocalize);
5050
}
5151
}

src/Resource/Name.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import BaseResource from './BaseResource';
1+
import BaseResource, {Endpoint} from './BaseResource';
22
import { Response } from '../Response';
33

44
/**
@@ -13,6 +13,6 @@ export default class Name extends BaseResource {
1313
* @returns The response from the validation request
1414
*/
1515
public validate(query: Record<string, any>): Promise<Response> {
16-
return super.send(query, 'validate');
16+
return super.send(query, Endpoint.NameValidate);
1717
}
1818
}

src/Resource/Phone.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import BaseResource from './BaseResource';
1+
import BaseResource, {Endpoint} from './BaseResource';
22
import { Response } from '../Response';
33

44
/**
@@ -13,6 +13,6 @@ export default class Phone extends BaseResource {
1313
* @returns The response from the validation request
1414
*/
1515
public validate(query: Record<string, any>): Promise<Response> {
16-
return super.send(query, 'validate');
16+
return super.send(query, Endpoint.PhoneValidate);
1717
}
1818
}

0 commit comments

Comments
 (0)