UNPKG

8.64 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.INTEGRATION_NAMES = ['capacitor', 'cordova', 'enterprise'];
4function isCommand(cmd) {
5 return cmd && typeof cmd.run === 'function';
6}
7exports.isCommand = isCommand;
8function isCommandPreRun(cmd) {
9 return cmd && typeof cmd.preRun === 'function';
10}
11exports.isCommandPreRun = isCommandPreRun;
12function isStarterManifest(obj) {
13 return obj &&
14 typeof obj.name === 'string' &&
15 typeof obj.baseref === 'string';
16}
17exports.isStarterManifest = isStarterManifest;
18function isCordovaPackageJson(obj) {
19 return obj &&
20 typeof obj.name === 'string' &&
21 typeof obj.cordova === 'object' &&
22 Array.isArray(obj.cordova.platforms) &&
23 typeof obj.cordova.plugins === 'object';
24}
25exports.isCordovaPackageJson = isCordovaPackageJson;
26function isExitCodeException(err) {
27 return err && typeof err.exitCode === 'number' && err.exitCode >= 0 && err.exitCode <= 255;
28}
29exports.isExitCodeException = isExitCodeException;
30function isSuperAgentError(err) {
31 return err && err.response && typeof err.response === 'object';
32}
33exports.isSuperAgentError = isSuperAgentError;
34function isAPIResponseSuccess(res) {
35 return res && (typeof res.data === 'object' || typeof res.data === 'string');
36}
37exports.isAPIResponseSuccess = isAPIResponseSuccess;
38function isAPIResponseError(res) {
39 return res && typeof res.error === 'object';
40}
41exports.isAPIResponseError = isAPIResponseError;
42function isOrg(org) {
43 return org && typeof org.name === 'string';
44}
45exports.isOrg = isOrg;
46function isGithubRepo(repo) {
47 return repo
48 && typeof repo.full_name === 'string'
49 && typeof repo.id === 'number';
50}
51exports.isGithubRepo = isGithubRepo;
52function isGithubBranch(branch) {
53 return branch && typeof branch.name === 'string';
54}
55exports.isGithubBranch = isGithubBranch;
56function isGithubRepoListResponse(res) {
57 if (!isAPIResponseSuccess(res) || !Array.isArray(res.data)) {
58 return false;
59 }
60 if (res.data.length === 0) {
61 return true;
62 }
63 return isGithubRepo(res.data[0]);
64}
65exports.isGithubRepoListResponse = isGithubRepoListResponse;
66function isGithubBranchListResponse(res) {
67 if (!isAPIResponseSuccess(res) || !Array.isArray(res.data)) {
68 return false;
69 }
70 if (res.data.length === 0) {
71 return true;
72 }
73 return isGithubBranch(res.data[0]);
74}
75exports.isGithubBranchListResponse = isGithubBranchListResponse;
76function isAppAssociation(association) {
77 return (association &&
78 typeof association.repository === 'object' &&
79 typeof association.repository.html_url === 'string' &&
80 (isGithubRepoAssociation(association.repository) ||
81 isBitbucketCloudRepoAssociation(association.repository) ||
82 isBitbucketServerRepoAssociation(association.repository)));
83}
84exports.isAppAssociation = isAppAssociation;
85function isAppAssociationResponse(res) {
86 return isAPIResponseSuccess(res)
87 && typeof res.data === 'object'
88 && isAppAssociation(res.data);
89}
90exports.isAppAssociationResponse = isAppAssociationResponse;
91function isGithubRepoAssociation(association) {
92 return association
93 && association.type === 'github'
94 && typeof association.id === 'number';
95}
96exports.isGithubRepoAssociation = isGithubRepoAssociation;
97function isBitbucketCloudRepoAssociation(association) {
98 return association
99 && association.type === 'bitbucket_cloud'
100 && typeof association.id === 'string';
101}
102exports.isBitbucketCloudRepoAssociation = isBitbucketCloudRepoAssociation;
103function isBitbucketServerRepoAssociation(association) {
104 return association
105 && association.type === 'bitbucket_server'
106 && typeof association.id === 'number';
107}
108exports.isBitbucketServerRepoAssociation = isBitbucketServerRepoAssociation;
109function isApp(app) {
110 return app
111 && typeof app === 'object'
112 && typeof app.id === 'string'
113 && typeof app.name === 'string'
114 && typeof app.slug === 'string'
115 && (!app.org || isOrg(app.org))
116 && (!app.association || isAppAssociation(app.association));
117}
118exports.isApp = isApp;
119function isAppResponse(res) {
120 return isAPIResponseSuccess(res)
121 && typeof res.data === 'object'
122 && isApp(res.data);
123}
124exports.isAppResponse = isAppResponse;
125function isAppsResponse(res) {
126 if (!isAPIResponseSuccess(res) || !Array.isArray(res.data)) {
127 return false;
128 }
129 if (res.data.length === 0) {
130 return true;
131 }
132 return isApp(res.data[0]);
133}
134exports.isAppsResponse = isAppsResponse;
135function isOAuthLogin(login) {
136 return login && typeof login.redirect_url === 'string';
137}
138exports.isOAuthLogin = isOAuthLogin;
139function isOAuthLoginResponse(res) {
140 return isAPIResponseSuccess(res) && isOAuthLogin(res.data);
141}
142exports.isOAuthLoginResponse = isOAuthLoginResponse;
143function isSnapshot(snapshot) {
144 return snapshot
145 && typeof snapshot.id === 'string'
146 && typeof snapshot.sha === 'string'
147 && typeof snapshot.ref === 'string'
148 && typeof snapshot.state === 'string'
149 && typeof snapshot.created === 'string'
150 && typeof snapshot.note === 'string';
151}
152exports.isSnapshot = isSnapshot;
153function isSnapshotResponse(res) {
154 return isAPIResponseSuccess(res) && isSnapshot(res.data);
155}
156exports.isSnapshotResponse = isSnapshotResponse;
157function isSnapshotListResponse(res) {
158 if (!isAPIResponseSuccess(res) || !Array.isArray(res.data)) {
159 return false;
160 }
161 if (res.data.length === 0) {
162 return true;
163 }
164 return isSnapshot(res.data[0]);
165}
166exports.isSnapshotListResponse = isSnapshotListResponse;
167function isLogin(login) {
168 return login
169 && isUser(login.user)
170 && typeof login.token === 'string';
171}
172exports.isLogin = isLogin;
173function isLoginResponse(res) {
174 return isAPIResponseSuccess(res) && isLogin(res.data);
175}
176exports.isLoginResponse = isLoginResponse;
177function isAuthConnection(connection) {
178 return connection && typeof connection.uuid === 'string';
179}
180exports.isAuthConnection = isAuthConnection;
181function isAuthConnectionResponse(res) {
182 return isAPIResponseSuccess(res) && isAuthConnection(res.data);
183}
184exports.isAuthConnectionResponse = isAuthConnectionResponse;
185function isUser(user) {
186 return user
187 && typeof user.id === 'number'
188 && typeof user.email === 'string';
189}
190exports.isUser = isUser;
191function isUserResponse(res) {
192 return isAPIResponseSuccess(res) && isUser(res.data);
193}
194exports.isUserResponse = isUserResponse;
195function isSSHKey(key) {
196 return key
197 && typeof key.id === 'string'
198 && typeof key.pubkey === 'string'
199 && typeof key.fingerprint === 'string'
200 && typeof key.annotation === 'string'
201 && typeof key.name === 'string'
202 && typeof key.created === 'string'
203 && typeof key.updated === 'string';
204}
205exports.isSSHKey = isSSHKey;
206function isSSHKeyListResponse(res) {
207 if (!isAPIResponseSuccess(res) || !Array.isArray(res.data)) {
208 return false;
209 }
210 if (res.data.length === 0) {
211 return true;
212 }
213 return isSSHKey(res.data[0]);
214}
215exports.isSSHKeyListResponse = isSSHKeyListResponse;
216function isSSHKeyResponse(res) {
217 return isAPIResponseSuccess(res) && isSSHKey(res.data);
218}
219exports.isSSHKeyResponse = isSSHKeyResponse;
220function isSecurityProfile(obj) {
221 return obj
222 && typeof obj.name === 'string'
223 && typeof obj.tag === 'string'
224 && typeof obj.type === 'string'
225 && typeof obj.created === 'string'
226 && typeof obj.credentials === 'object';
227}
228exports.isSecurityProfile = isSecurityProfile;
229function isSecurityProfileResponse(r) {
230 const res = r;
231 return isAPIResponseSuccess(res) && isSecurityProfile(res.data);
232}
233exports.isSecurityProfileResponse = isSecurityProfileResponse;
234function isTreatableAilment(ailment) {
235 return ailment && ailment.treatable && typeof ailment.getTreatmentSteps === 'function';
236}
237exports.isTreatableAilment = isTreatableAilment;
238function isIntegrationName(name) {
239 return exports.INTEGRATION_NAMES.includes(name);
240}
241exports.isIntegrationName = isIntegrationName;
242function isProjectConfig(configFile) {
243 return configFile
244 && typeof configFile.name === 'string'
245 && typeof configFile.projects === 'undefined';
246}
247exports.isProjectConfig = isProjectConfig;
248function isMultiProjectConfig(configFile) {
249 return configFile
250 && typeof configFile.name === 'undefined'
251 && typeof configFile.projects === 'object';
252}
253exports.isMultiProjectConfig = isMultiProjectConfig;