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

ringcentral / ringcentral-js / 8814160190

24 Apr 2024 09:17AM UTC coverage: 93.418%. Remained the same
8814160190

push

github

web-flow
Merge pull request #255 from ringcentral/attachGitHubPageUrl

Attach Js Github Page link in readme file

574 of 702 branches covered (81.77%)

Branch coverage included in aggregate %.

1924 of 1972 relevant lines covered (97.57%)

42.59 hits per line

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

92.0
/sdk/src/SDK.ts
1
import {EventEmitter} from 'events';
4✔
2
import Cache from './core/Cache';
4✔
3
import Externals, {ExternalsOptions} from './core/Externals';
4✔
4
import * as Constants from './core/Constants';
4✔
5
import Client, {ApiError, CreateRequestOptions} from './http/Client';
4✔
6
import Platform, {
4✔
7
    CreateUrlOptions,
8
    LoginOptions,
9
    LoginUrlOptions,
10
    LoginWindowOptions,
11
    PlatformOptions,
12
    SendOptions,
13
} from './platform/Platform';
14
import {AuthData} from './platform/Auth';
15

16
export {
17
    Cache,
4✔
18
    Externals,
4✔
19
    LoginOptions,
20
    LoginUrlOptions,
21
    LoginWindowOptions,
22
    CreateUrlOptions,
23
    SendOptions,
24
    AuthData,
25
    ExternalsOptions,
26
    CreateRequestOptions,
27
    ApiError,
28
};
29

30
let defaultExternals: ExternalsOptions = {};
4✔
31

32
export const setDefaultExternals = (externals: ExternalsOptions) => (defaultExternals = externals);
4✔
33

34
export class SDK {
4✔
35
    private _externals: Externals;
36

37
    private _cache: Cache;
38

39
    private _client: Client;
40

41
    private _platform: Platform;
42

43
    public static version = Constants.version;
4✔
44

45
    public static EventEmitter = EventEmitter;
4✔
46

47
    public static server = {
4✔
48
        sandbox: 'https://platform.devtest.ringcentral.com',
49
        production: 'https://platform.ringcentral.com',
50
    };
51
    public static handleLoginRedirect(origin, win) {
4✔
52
        win = win || window;
2!
53
        const response = win.location.search ? win.location.search : win.location.hash;
2✔
54
        const msg = {};
2✔
55
        msg[Constants.authResponseProperty] = response;
2✔
56
        win.opener.postMessage(msg, origin || win.location.origin);
2✔
57
    }
58

59
    public constructor(options: SDKOptions = {}) {
98✔
60
        const {cachePrefix, defaultRequestInit, handleRateLimit} = options;
291✔
61
        if (options?.server === SDK.server.sandbox) {
97!
62
            // eslint-disable-next-line no-console
63
            console.warn('Sandbox support is deprecated. Please migrate your application to Production Server.');
×
64
        }
65
        this._externals = new Externals({
97✔
66
            ...defaultExternals,
67
            ...options,
68
        });
69

70
        this._cache = new Cache({
97✔
71
            externals: this._externals,
72
            prefix: cachePrefix,
73
        });
74

75
        this._client = new Client({
97✔
76
            externals: this._externals,
77
            defaultRequestInit,
78
        });
79

80
        this._platform = new Platform({
97✔
81
            ...options,
82
            externals: this._externals,
83
            client: this._client,
84
            cache: this._cache,
85
            handleRateLimit,
86
        });
87
    }
88

89
    public platform() {
4✔
90
        return this._platform;
153✔
91
    }
92

93
    public client() {
4✔
94
        return this._client;
30✔
95
    }
96

97
    public cache() {
4✔
98
        return this._cache;
149✔
99
    }
100

101
    public externals() {
4✔
102
        return this._externals;
1✔
103
    }
104

105
    /* istanbul ignore next */
106
    public send = async (options: SendOptions): Promise<Response> => this.platform().send(options);
107

108
    /* istanbul ignore next */
109
    public get = async (url, query?, options?: SendOptions): Promise<Response> =>
110
        this.platform().send({method: 'GET', url, query, ...options});
111

112
    /* istanbul ignore next */
113
    public post = async (url, body?, query?, options?: SendOptions): Promise<Response> =>
114
        this.platform().send({method: 'POST', url, query, body, ...options});
115

116
    /* istanbul ignore next */
117
    public put = async (url, body?, query?, options?: SendOptions): Promise<Response> =>
118
        this.platform().send({method: 'PUT', url, query, body, ...options});
119

120
    /* istanbul ignore next */
121
    public patch = async (url, body?, query?, options?: SendOptions): Promise<Response> =>
122
        this.platform().send({method: 'PATCH', url, query, body, ...options});
123

124
    /* istanbul ignore next */
125
    public delete = async (url, query?, options?: SendOptions): Promise<Response> =>
126
        this.platform().send({method: 'DELETE', url, query, ...options});
127

128
    /* istanbul ignore next */
129
    public login = async (options: LoginOptions): Promise<Response> => this.platform().login(options);
130

131
    /* istanbul ignore next */
132
    public ensureLoggedIn = async (): Promise<Response> => this.platform().ensureLoggedIn();
133

134
    /* istanbul ignore next */
135
    public loginUrl = (options: LoginUrlOptions): string => this.platform().loginUrl(options);
136

137
    /* istanbul ignore next */
138
    public createUrl = (path, options: CreateUrlOptions): string => this.platform().createUrl(path, options);
139

140
    /* istanbul ignore next */
141
    public signUrl = async (path): Promise<string> => this.platform().signUrl(path);
142

143
    /* istanbul ignore next */
144
    public parseLoginRedirect = (url): any => this.platform().parseLoginRedirect(url);
145

146
    /* istanbul ignore next */
147
    public logout = async (): Promise<Response> => this.platform().logout();
148

149
    /* istanbul ignore next */
150
    public loginWindow = async (options: LoginWindowOptions): Promise<LoginOptions> =>
151
        this.platform().loginWindow(options);
152

153
    /* istanbul ignore next */
154
    public refresh = async (): Promise<Response> => this.platform().refresh();
155

156
    /* istanbul ignore next */
157
    public multipart = async (response: Response): Promise<Response[]> => this.client().multipart(response);
158

159
    /* istanbul ignore next */
160
    public getContentType = (response: Response): string => this.client().getContentType(response);
161

162
    /* istanbul ignore next */
163
    public isMultipart = (response: Response) => this.client().isMultipart(response);
164

165
    /* istanbul ignore next */
166
    public isJson = (response: Response) => this.client().isJson(response);
167

168
    /* istanbul ignore next */
169
    public error = (response: Response): Promise<string> => this.client().error(response);
170
}
4✔
171
export interface SDKOptions extends PlatformOptions, ExternalsOptions {
172
    cachePrefix?: string;
173
    defaultRequestInit?: CreateRequestOptions;
174
    handleRateLimit?: boolean | number;
175
}
176

177
export default SDK;
4✔
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

© 2025 Coveralls, Inc