UNPKG

9.98 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 isLegacyAndroidBuildOutputFile(obj) {
27 if (!Array.isArray(obj)) {
28 return false;
29 }
30 if (obj.length === 0) {
31 return true;
32 }
33 return obj[0]
34 && typeof obj[0].path === 'string'
35 && typeof obj[0].outputType === 'object'
36 && typeof obj[0].outputType.type === 'string';
37}
38exports.isLegacyAndroidBuildOutputFile = isLegacyAndroidBuildOutputFile;
39function isAndroidBuildOutputFile(obj) {
40 return obj &&
41 typeof obj.artifactType === 'object' &&
42 typeof obj.artifactType.type === 'string' &&
43 Array.isArray(obj.elements);
44}
45exports.isAndroidBuildOutputFile = isAndroidBuildOutputFile;
46function isExitCodeException(err) {
47 return err && typeof err.exitCode === 'number' && err.exitCode >= 0 && err.exitCode <= 255;
48}
49exports.isExitCodeException = isExitCodeException;
50function isSuperAgentError(err) {
51 return err && err.response && typeof err.response === 'object';
52}
53exports.isSuperAgentError = isSuperAgentError;
54function isAPIResponseSuccess(res) {
55 return res && (typeof res.data === 'object' || typeof res.data === 'string');
56}
57exports.isAPIResponseSuccess = isAPIResponseSuccess;
58function isAPIResponseError(res) {
59 return res && typeof res.error === 'object';
60}
61exports.isAPIResponseError = isAPIResponseError;
62function isOrg(org) {
63 return org && typeof org.name === 'string';
64}
65exports.isOrg = isOrg;
66function isGithubRepo(repo) {
67 return repo
68 && typeof repo.full_name === 'string'
69 && typeof repo.id === 'number';
70}
71exports.isGithubRepo = isGithubRepo;
72function isGithubBranch(branch) {
73 return branch && typeof branch.name === 'string';
74}
75exports.isGithubBranch = isGithubBranch;
76function isGithubRepoListResponse(res) {
77 if (!isAPIResponseSuccess(res) || !Array.isArray(res.data)) {
78 return false;
79 }
80 if (res.data.length === 0) {
81 return true;
82 }
83 return isGithubRepo(res.data[0]);
84}
85exports.isGithubRepoListResponse = isGithubRepoListResponse;
86function isGithubBranchListResponse(res) {
87 if (!isAPIResponseSuccess(res) || !Array.isArray(res.data)) {
88 return false;
89 }
90 if (res.data.length === 0) {
91 return true;
92 }
93 return isGithubBranch(res.data[0]);
94}
95exports.isGithubBranchListResponse = isGithubBranchListResponse;
96function isAppAssociation(association) {
97 return (association &&
98 typeof association.repository === 'object' &&
99 typeof association.repository.html_url === 'string' &&
100 (isGithubRepoAssociation(association.repository) ||
101 isBitbucketCloudRepoAssociation(association.repository) ||
102 isBitbucketServerRepoAssociation(association.repository)));
103}
104exports.isAppAssociation = isAppAssociation;
105function isAppAssociationResponse(res) {
106 return isAPIResponseSuccess(res)
107 && typeof res.data === 'object'
108 && isAppAssociation(res.data);
109}
110exports.isAppAssociationResponse = isAppAssociationResponse;
111function isGithubRepoAssociation(association) {
112 return association
113 && association.type === 'github'
114 && typeof association.id === 'number';
115}
116exports.isGithubRepoAssociation = isGithubRepoAssociation;
117function isBitbucketCloudRepoAssociation(association) {
118 return association
119 && association.type === 'bitbucket_cloud'
120 && typeof association.id === 'string';
121}
122exports.isBitbucketCloudRepoAssociation = isBitbucketCloudRepoAssociation;
123function isBitbucketServerRepoAssociation(association) {
124 return association
125 && association.type === 'bitbucket_server'
126 && typeof association.id === 'number';
127}
128exports.isBitbucketServerRepoAssociation = isBitbucketServerRepoAssociation;
129function isApp(app) {
130 return app
131 && typeof app === 'object'
132 && typeof app.id === 'string'
133 && typeof app.name === 'string'
134 && typeof app.slug === 'string'
135 && (!app.org || isOrg(app.org))
136 && (!app.association || isAppAssociation(app.association));
137}
138exports.isApp = isApp;
139function isAppResponse(res) {
140 return isAPIResponseSuccess(res)
141 && typeof res.data === 'object'
142 && isApp(res.data);
143}
144exports.isAppResponse = isAppResponse;
145function isAppsResponse(res) {
146 if (!isAPIResponseSuccess(res) || !Array.isArray(res.data)) {
147 return false;
148 }
149 if (res.data.length === 0) {
150 return true;
151 }
152 return isApp(res.data[0]);
153}
154exports.isAppsResponse = isAppsResponse;
155function isOAuthLogin(login) {
156 return login && typeof login.redirect_url === 'string';
157}
158exports.isOAuthLogin = isOAuthLogin;
159function isOAuthLoginResponse(res) {
160 return isAPIResponseSuccess(res) && isOAuthLogin(res.data);
161}
162exports.isOAuthLoginResponse = isOAuthLoginResponse;
163function isOpenIDToken(tokenObj) {
164 return tokenObj
165 && typeof tokenObj.access_token === 'string'
166 && typeof tokenObj.expires_in === 'number'
167 && (tokenObj.id_token ? typeof tokenObj.id_token === 'string' : true)
168 && (tokenObj.refresh_token ? typeof tokenObj.refresh_token === 'string' : true)
169 && tokenObj.scope === 'openid profile email offline_access'
170 && tokenObj.token_type === 'Bearer';
171}
172exports.isOpenIDToken = isOpenIDToken;
173function isOpenIDTokenExchangeResponse(res) {
174 return res && typeof res.body === 'object' && isOpenIDToken(res.body);
175}
176exports.isOpenIDTokenExchangeResponse = isOpenIDTokenExchangeResponse;
177function isSnapshot(snapshot) {
178 return snapshot
179 && typeof snapshot.id === 'string'
180 && typeof snapshot.sha === 'string'
181 && typeof snapshot.ref === 'string'
182 && typeof snapshot.state === 'string'
183 && typeof snapshot.created === 'string'
184 && typeof snapshot.note === 'string';
185}
186exports.isSnapshot = isSnapshot;
187function isSnapshotResponse(res) {
188 return isAPIResponseSuccess(res) && isSnapshot(res.data);
189}
190exports.isSnapshotResponse = isSnapshotResponse;
191function isSnapshotListResponse(res) {
192 if (!isAPIResponseSuccess(res) || !Array.isArray(res.data)) {
193 return false;
194 }
195 if (res.data.length === 0) {
196 return true;
197 }
198 return isSnapshot(res.data[0]);
199}
200exports.isSnapshotListResponse = isSnapshotListResponse;
201function isLogin(login) {
202 return login
203 && isUser(login.user)
204 && typeof login.token === 'string';
205}
206exports.isLogin = isLogin;
207function isLoginResponse(res) {
208 return isAPIResponseSuccess(res) && isLogin(res.data);
209}
210exports.isLoginResponse = isLoginResponse;
211function isAuthConnection(connection) {
212 return connection && typeof connection.uuid === 'string';
213}
214exports.isAuthConnection = isAuthConnection;
215function isAuthConnectionResponse(res) {
216 return isAPIResponseSuccess(res) && isAuthConnection(res.data);
217}
218exports.isAuthConnectionResponse = isAuthConnectionResponse;
219function isUser(user) {
220 return user
221 && typeof user.id === 'number'
222 && typeof user.email === 'string';
223}
224exports.isUser = isUser;
225function isUserResponse(res) {
226 return isAPIResponseSuccess(res) && isUser(res.data);
227}
228exports.isUserResponse = isUserResponse;
229function isSSHKey(key) {
230 return key
231 && typeof key.id === 'string'
232 && typeof key.pubkey === 'string'
233 && typeof key.fingerprint === 'string'
234 && typeof key.annotation === 'string'
235 && typeof key.name === 'string'
236 && typeof key.created === 'string'
237 && typeof key.updated === 'string';
238}
239exports.isSSHKey = isSSHKey;
240function isSSHKeyListResponse(res) {
241 if (!isAPIResponseSuccess(res) || !Array.isArray(res.data)) {
242 return false;
243 }
244 if (res.data.length === 0) {
245 return true;
246 }
247 return isSSHKey(res.data[0]);
248}
249exports.isSSHKeyListResponse = isSSHKeyListResponse;
250function isSSHKeyResponse(res) {
251 return isAPIResponseSuccess(res) && isSSHKey(res.data);
252}
253exports.isSSHKeyResponse = isSSHKeyResponse;
254function isSecurityProfile(obj) {
255 return obj
256 && typeof obj.name === 'string'
257 && typeof obj.tag === 'string'
258 && typeof obj.type === 'string'
259 && typeof obj.created === 'string'
260 && typeof obj.credentials === 'object';
261}
262exports.isSecurityProfile = isSecurityProfile;
263function isSecurityProfileResponse(r) {
264 const res = r;
265 return isAPIResponseSuccess(res) && isSecurityProfile(res.data);
266}
267exports.isSecurityProfileResponse = isSecurityProfileResponse;
268function isTreatableAilment(ailment) {
269 return ailment && ailment.treatable && typeof ailment.getTreatmentSteps === 'function';
270}
271exports.isTreatableAilment = isTreatableAilment;
272function isIntegrationName(name) {
273 return exports.INTEGRATION_NAMES.includes(name);
274}
275exports.isIntegrationName = isIntegrationName;
276function isProjectConfig(configFile) {
277 return configFile
278 && typeof configFile.name === 'string'
279 && typeof configFile.projects === 'undefined';
280}
281exports.isProjectConfig = isProjectConfig;
282function isMultiProjectConfig(configFile) {
283 return configFile
284 && typeof configFile.name === 'undefined'
285 && typeof configFile.projects === 'object';
286}
287exports.isMultiProjectConfig = isMultiProjectConfig;