• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SmoothIntegration / sdk-node / 12971037142

26 Jan 2025 03:25AM UTC coverage: 81.188%. Remained the same
12971037142

push

github

thimovss
added validation to the SDK Client constructor

37 of 51 branches covered (72.55%)

Branch coverage included in aggregate %.

17 of 18 new or added lines in 1 file covered. (94.44%)

127 of 151 relevant lines covered (84.11%)

21.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/src/Client.ts
1
import CDC from './CDC';
14✔
2
import { SIError } from './Errors';
14✔
3
import FreeAgent from './FreeAgent';
14✔
4
import HTTP from './HTTP';
14✔
5
import MYOB from './MYOB';
14✔
6
import QuickBooks from './QuickBooks';
14✔
7
import Request from './Request';
14✔
8
import Xero from './Xero';
14✔
9
import type { ClientConfig } from './types';
10

11
const UUID_REGEX: RegExp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
14✔
12

13
/**
14
 * The main client class that provides access to all the Smooth Integration APIs.
15
 */
16
export default class Client {
14✔
17
    public clientId: string;
18
    public clientSecret: string;
19
    public apiUrl: string;
20

21
    public http: HTTP;
22

23
    public cdc: CDC;
24
    public request: Request;
25

26
    public xero: Xero;
27
    public quickBooks: QuickBooks;
28
    public freeAgent: FreeAgent;
29
    public myob: MYOB;
30

31
    /**
32
     * Create a new Smooth Integration client.
33
     * @param { ClientConfig } config - Required, the client configuration.
34
     * @param { string } config.clientId - Required, your Smooth Integration client ID.
35
     * @param { string } config.clientSecret - Required, your Smooth Integration client Secret.
36
     *
37
     * @throws {SIError} If the configuration provided is invalid.
38
     *
39
     * @example
40
     * ```typescript
41
     * const client = new Client({
42
     *    clientId: 'your_client_id',
43
     *    clientSecret: 'your_client_secret',
44
     * });
45
     */
46
    constructor(config: ClientConfig) {
47
        if (!config) {
68✔
48
            throw new SIError('Failed to create client: missing config');
1✔
49
        }
50
        // noinspection SuspiciousTypeOfGuard
51
        if (typeof config !== 'object') {
67✔
52
            throw new SIError('Failed to create client: config is not of type object');
1✔
53
        }
54
        if (!config.clientId) {
66✔
55
            throw new SIError('Failed to create client: missing clientId');
1✔
56
        }
57
        // noinspection SuspiciousTypeOfGuard
58
        if (typeof config.clientId !== 'string') {
65✔
59
            throw new SIError('Failed to create client: clientId is not of type string');
1✔
60
        }
61
        if (!config.clientId.match(UUID_REGEX)) {
64✔
62
            throw new SIError('Failed to create client: clientId is not a valid UUID string');
1✔
63
        }
64
        if (!config.clientSecret) {
63✔
65
            throw new SIError('Failed to create client: missing clientSecret');
1✔
66
        }
67
        // noinspection SuspiciousTypeOfGuard
68
        if (typeof config.clientSecret !== 'string') {
62✔
69
            throw new SIError('Failed to create client: clientSecret is not of type string');
1✔
70
        }
71

72
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
73
        // @ts-ignore: Only for debugging purposes, will be deleted without any warning in the near future. Do not use!
74
        if (config.apiUrl) {
61!
NEW
75
            console.log(
×
76
                "Warning! You're providing a apiUrl in your client initialization. This is only for debugging purposes and will be removed in the near future. Do not use!",
77
            );
78
        }
79

80
        this.clientId = config.clientId;
61✔
81
        this.clientSecret = config.clientSecret;
61✔
82
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
83
        // @ts-ignore: Only for debugging purposes, will be deleted without any warning in the near future. Do not use!
84
        this.apiUrl = config.apiUrl || 'https://api.smooth-integration.com';
61✔
85

86
        this.http = new HTTP(this);
61✔
87

88
        this.cdc = new CDC(this);
61✔
89
        this.request = new Request(this);
61✔
90

91
        this.xero = new Xero(this);
61✔
92
        this.quickBooks = new QuickBooks(this);
61✔
93
        this.freeAgent = new FreeAgent(this);
61✔
94
        this.myob = new MYOB(this);
61✔
95
    }
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc