Skip to content

Commit d22eb3a

Browse files
refactor: enhance API documentation and improve code organization (#425)
- Updated JSDoc comments to include `@memberof` annotations for better clarity on class methods. - Removed unnecessary entries from .gitignore and improved organization. - Deleted obsolete test file for the Access API, streamlining the test suite. - Corrected typos in test descriptions for consistency and clarity. - Improved error handling and response processing across various API clients. These changes aim to enhance maintainability and readability of the codebase while ensuring accurate documentation for developers.
1 parent 1c187d5 commit d22eb3a

18 files changed

Lines changed: 255 additions & 252 deletions

File tree

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ out
5050
/dist/
5151
.tmp.*
5252

53-
.github/skills/
53+
.github/skills
5454

5555
docs/
56-
*_REVIEW.md
5756

58-
swagger-spec.json
5957
swagger.*

src/api/access/access.js

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
1-
import { determineError } from '../../services/errors.js';
2-
import { createAccessToken } from '../../services/http.js';
3-
4-
/**
5-
* Class dealing with the access api
6-
*
7-
* @export
8-
* @class Access
9-
*/
10-
export default class Access {
11-
constructor(config) {
12-
this.config = config;
13-
}
14-
15-
/**
16-
* Request an access token
17-
*
18-
* @param {Object} body Access object body.
19-
* @return {Promise<Object>} A promise to the Access response.
20-
*/
21-
async request(body) {
22-
try {
23-
const response = await createAccessToken(this.config, this.config.httpClient, body);
24-
return await response.json;
25-
} catch (err) {
26-
throw await determineError(err);
27-
}
28-
}
29-
30-
/**
31-
* Update the access details in the config.
32-
*
33-
* @param {Object} body Access response body.
34-
* @return {void}
35-
*/
36-
updateAccessToken(body) {
37-
this.config.access = {
38-
token: body.access_token,
39-
type: body.token_type,
40-
scope: body.scope,
41-
expires: new Date(new Date().getTime() + body.expires_in),
42-
};
43-
}
44-
}
1+
import { determineError } from '../../services/errors.js';
2+
import { createAccessToken } from '../../services/http.js';
3+
4+
/**
5+
* Class dealing with the access api
6+
*
7+
* @export
8+
* @class Access
9+
*/
10+
export default class Access {
11+
constructor(config) {
12+
this.config = config;
13+
}
14+
15+
/**
16+
* Request an access token
17+
*
18+
* @memberof Access
19+
* @param {Object} body Access object body.
20+
* @return {Promise<Object>} A promise to the Access response.
21+
*/
22+
async request(body) {
23+
try {
24+
const response = await createAccessToken(this.config, this.config.httpClient, body);
25+
return await response.json;
26+
} catch (err) {
27+
throw await determineError(err);
28+
}
29+
}
30+
31+
/**
32+
* Update the access details in the config.
33+
*
34+
* @memberof Access
35+
* @param {Object} body Access response body.
36+
* @return {void}
37+
*/
38+
updateAccessToken(body) {
39+
this.config.access = {
40+
token: body.access_token,
41+
type: body.token_type,
42+
scope: body.scope,
43+
expires: new Date(new Date().getTime() + body.expires_in),
44+
};
45+
}
46+
}

src/api/apple-pay/apple-pay.js

Lines changed: 90 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,90 @@
1-
import { determineError } from '../../services/errors.js';
2-
import { post } from '../../services/http.js';
3-
4-
/**
5-
* Class dealing with the Apple Pay api
6-
*
7-
* @export
8-
* @class Apple Pay
9-
*/
10-
export default class ApplePay {
11-
constructor(config) {
12-
this.config = config;
13-
}
14-
15-
/**
16-
* Upload a payment processing certificate.
17-
* This will allow you to start processing payments via Apple Pay.
18-
*
19-
* @param {Object} body Apple Pay certificate request.
20-
* @param {string} body.content The payment processing certificate content.
21-
* @return {Promise<Object>} A promise to the Apple Pay certificate response.
22-
*/
23-
async upload(body) {
24-
try {
25-
const response = await post(
26-
this.config.httpClient,
27-
`${this.config.host}/applepay/certificates`,
28-
this.config,
29-
this.config.pk,
30-
body
31-
);
32-
return await response.json;
33-
} catch (err) {
34-
throw await determineError(err);
35-
}
36-
}
37-
38-
/**
39-
* Generate a certificate signing request.
40-
* You'll need to upload this to your Apple Developer account to download a payment processing certificate.
41-
*
42-
* @param {Object} body Apple Pay signing request (optional).
43-
* @param {string} [body.protocol_version] The protocol version (ec_v1 or rsa_v1). Default: ec_v1.
44-
* @return {Promise<Object>} A promise to the Apple Pay signing request response.
45-
*/
46-
async generate(body) {
47-
try {
48-
const response = await post(
49-
this.config.httpClient,
50-
`${this.config.host}/applepay/signing-requests`,
51-
this.config,
52-
this.config.pk,
53-
body
54-
);
55-
return await response.json;
56-
} catch (err) {
57-
throw await determineError(err);
58-
}
59-
}
60-
61-
/**
62-
* Enroll a domain to the Apple Pay Service.
63-
* Requires OAuth authentication with scope: vault:apme-enrollment
64-
*
65-
* @param {Object} body Apple Pay enrollment request.
66-
* @param {string} body.domain The domain to enroll (e.g., 'https://example.com').
67-
* @return {Promise<void>} A promise that resolves when enrollment is successful (204 No Content).
68-
*/
69-
async enroll(body) {
70-
try {
71-
const response = await post(
72-
this.config.httpClient,
73-
`${this.config.host}/applepay/enrollments`,
74-
this.config,
75-
null,
76-
body
77-
);
78-
// 204 No Content - return undefined
79-
if (response.status === 204) {
80-
return undefined;
81-
}
82-
return await response.json;
83-
} catch (err) {
84-
throw await determineError(err);
85-
}
86-
}
87-
}
1+
import { determineError } from '../../services/errors.js';
2+
import { post } from '../../services/http.js';
3+
4+
/**
5+
* Class dealing with the Apple Pay api
6+
*
7+
* @export
8+
* @class Apple Pay
9+
*/
10+
export default class ApplePay {
11+
constructor(config) {
12+
this.config = config;
13+
}
14+
15+
/**
16+
* Upload a payment processing certificate.
17+
* This will allow you to start processing payments via Apple Pay.
18+
*
19+
* @memberof ApplePay
20+
* @param {Object} body Apple Pay certificate request.
21+
* @param {string} body.content The payment processing certificate content.
22+
* @return {Promise<Object>} A promise to the Apple Pay certificate response.
23+
*/
24+
async upload(body) {
25+
try {
26+
const response = await post(
27+
this.config.httpClient,
28+
`${this.config.host}/applepay/certificates`,
29+
this.config,
30+
this.config.pk,
31+
body
32+
);
33+
return await response.json;
34+
} catch (err) {
35+
throw await determineError(err);
36+
}
37+
}
38+
39+
/**
40+
* Generate a certificate signing request.
41+
* You'll need to upload this to your Apple Developer account to download a payment processing certificate.
42+
*
43+
* @memberof ApplePay
44+
* @param {Object} body Apple Pay signing request (optional).
45+
* @param {string} [body.protocol_version] The protocol version (ec_v1 or rsa_v1). Default: ec_v1.
46+
* @return {Promise<Object>} A promise to the Apple Pay signing request response.
47+
*/
48+
async generate(body) {
49+
try {
50+
const response = await post(
51+
this.config.httpClient,
52+
`${this.config.host}/applepay/signing-requests`,
53+
this.config,
54+
this.config.pk,
55+
body
56+
);
57+
return await response.json;
58+
} catch (err) {
59+
throw await determineError(err);
60+
}
61+
}
62+
63+
/**
64+
* Enroll a domain to the Apple Pay Service.
65+
* Requires OAuth authentication with scope: vault:apme-enrollment
66+
*
67+
* @memberof ApplePay
68+
* @param {Object} body Apple Pay enrollment request.
69+
* @param {string} body.domain The domain to enroll (e.g., 'https://example.com').
70+
* @return {Promise<void>} A promise that resolves when enrollment is successful (204 No Content).
71+
*/
72+
async enroll(body) {
73+
try {
74+
const response = await post(
75+
this.config.httpClient,
76+
`${this.config.host}/applepay/enrollments`,
77+
this.config,
78+
null,
79+
body
80+
);
81+
// 204 No Content - return undefined
82+
if (response.status === 204) {
83+
return undefined;
84+
}
85+
return await response.json;
86+
} catch (err) {
87+
throw await determineError(err);
88+
}
89+
}
90+
}
Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
1-
import { determineError } from '../../services/errors.js';
2-
import { post } from '../../services/http.js';
3-
4-
/**
5-
* Class dealing with the /metadata/card endpoint
6-
*
7-
* @export
8-
* @class CardMetadata
9-
*/
10-
export default class CardMetadata {
11-
constructor(config) {
12-
this.config = config;
13-
}
14-
15-
/**
16-
* Returns a single metadata record for the card specified by the Primary Account Number (PAN),
17-
* Bank Identification Number (BIN), token, or instrument supplied.
18-
*
19-
* @param {Object} body Card Metadata request body.
20-
* @return {Promise<Object>} A promise to the add Card Metadata response.
21-
*/
22-
async get(body) {
23-
try {
24-
const response = await post(
25-
this.config.httpClient,
26-
`${this.config.host}/metadata/card`,
27-
this.config,
28-
this.config.sk,
29-
body
30-
);
31-
return await response.json;
32-
} catch (err) {
33-
throw await determineError(err);
34-
}
35-
}
36-
}
1+
import { determineError } from '../../services/errors.js';
2+
import { post } from '../../services/http.js';
3+
4+
/**
5+
* Class dealing with the /metadata/card endpoint
6+
*
7+
* @export
8+
* @class CardMetadata
9+
*/
10+
export default class CardMetadata {
11+
constructor(config) {
12+
this.config = config;
13+
}
14+
15+
/**
16+
* Returns a single metadata record for the card specified by the Primary Account Number (PAN),
17+
* Bank Identification Number (BIN), token, or instrument supplied.
18+
*
19+
* @memberof CardMetadata
20+
* @param {Object} body Card Metadata request body.
21+
* @return {Promise<Object>} A promise to the Card Metadata response.
22+
*/
23+
async get(body) {
24+
try {
25+
const response = await post(
26+
this.config.httpClient,
27+
`${this.config.host}/metadata/card`,
28+
this.config,
29+
this.config.sk,
30+
body
31+
);
32+
return await response.json;
33+
} catch (err) {
34+
throw await determineError(err);
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)