@rbaileysr/zephyr-managed-api 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +618 -0
- package/dist/error-strategy.d.ts +69 -0
- package/dist/error-strategy.d.ts.map +1 -0
- package/dist/error-strategy.js +125 -0
- package/dist/groups/All.d.ts +90 -0
- package/dist/groups/All.d.ts.map +1 -0
- package/dist/groups/All.js +236 -0
- package/dist/groups/Automation.d.ts +75 -0
- package/dist/groups/Automation.d.ts.map +1 -0
- package/dist/groups/Automation.js +133 -0
- package/dist/groups/Environment.d.ts +73 -0
- package/dist/groups/Environment.d.ts.map +1 -0
- package/dist/groups/Environment.js +93 -0
- package/dist/groups/Folder.d.ts +55 -0
- package/dist/groups/Folder.d.ts.map +1 -0
- package/dist/groups/Folder.js +68 -0
- package/dist/groups/IssueLink.d.ts +59 -0
- package/dist/groups/IssueLink.d.ts.map +1 -0
- package/dist/groups/IssueLink.js +70 -0
- package/dist/groups/Link.d.ts +23 -0
- package/dist/groups/Link.d.ts.map +1 -0
- package/dist/groups/Link.js +34 -0
- package/dist/groups/Priority.d.ts +77 -0
- package/dist/groups/Priority.d.ts.map +1 -0
- package/dist/groups/Priority.js +97 -0
- package/dist/groups/Project.d.ts +36 -0
- package/dist/groups/Project.d.ts.map +1 -0
- package/dist/groups/Project.js +42 -0
- package/dist/groups/Status.d.ts +82 -0
- package/dist/groups/Status.d.ts.map +1 -0
- package/dist/groups/Status.js +102 -0
- package/dist/groups/TestCase.d.ts +254 -0
- package/dist/groups/TestCase.d.ts.map +1 -0
- package/dist/groups/TestCase.js +327 -0
- package/dist/groups/TestCycle.d.ts +127 -0
- package/dist/groups/TestCycle.d.ts.map +1 -0
- package/dist/groups/TestCycle.js +166 -0
- package/dist/groups/TestExecution.d.ts +176 -0
- package/dist/groups/TestExecution.d.ts.map +1 -0
- package/dist/groups/TestExecution.js +239 -0
- package/dist/groups/TestPlan.d.ts +103 -0
- package/dist/groups/TestPlan.d.ts.map +1 -0
- package/dist/groups/TestPlan.js +137 -0
- package/dist/index.d.ts +119 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +124 -0
- package/dist/types.d.ts +1353 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/utils-api-call.d.ts +22 -0
- package/dist/utils-api-call.d.ts.map +1 -0
- package/dist/utils-api-call.js +80 -0
- package/dist/utils.d.ts +144 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +432 -0
- package/package.json +54 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zephyr Managed API
|
|
3
|
+
*
|
|
4
|
+
* A comprehensive Managed API wrapper for Zephyr Cloud REST API v2
|
|
5
|
+
* Provides type-safe, hierarchical access to all Zephyr API endpoints
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createZephyrApi } from './zephyr';
|
|
10
|
+
* import ZephyrApiConnection from '../api/zephyr';
|
|
11
|
+
*
|
|
12
|
+
* // Using API Connection (ScriptRunner Connect)
|
|
13
|
+
* const Zephyr = createZephyrApi(ZephyrApiConnection, 'us');
|
|
14
|
+
*
|
|
15
|
+
* // Using OAuth Token
|
|
16
|
+
* const Zephyr = createZephyrApi('oauth-token-string', 'us');
|
|
17
|
+
*
|
|
18
|
+
* // Use the API
|
|
19
|
+
* const testCase = await Zephyr.TestCase.getTestCase({ testCaseKey: 'PROJ-T1' });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { TestCaseGroup } from './groups/TestCase';
|
|
23
|
+
import { TestCycleGroup } from './groups/TestCycle';
|
|
24
|
+
import { TestExecutionGroup } from './groups/TestExecution';
|
|
25
|
+
import { TestPlanGroup } from './groups/TestPlan';
|
|
26
|
+
import { FolderGroup } from './groups/Folder';
|
|
27
|
+
import { ProjectGroup } from './groups/Project';
|
|
28
|
+
import { StatusGroup } from './groups/Status';
|
|
29
|
+
import { PriorityGroup } from './groups/Priority';
|
|
30
|
+
import { EnvironmentGroup } from './groups/Environment';
|
|
31
|
+
import { LinkGroup } from './groups/Link';
|
|
32
|
+
import { IssueLinkGroup } from './groups/IssueLink';
|
|
33
|
+
import { AutomationGroup } from './groups/Automation';
|
|
34
|
+
import { AllGroup } from './groups/All';
|
|
35
|
+
/**
|
|
36
|
+
* OAuth-based API connection implementation
|
|
37
|
+
* Retrieves OAuth token and adds it to requests
|
|
38
|
+
*/
|
|
39
|
+
class OAuthZephyrConnection {
|
|
40
|
+
constructor(oauthToken, baseUrl) {
|
|
41
|
+
this.oauthToken = oauthToken;
|
|
42
|
+
this.baseUrl = baseUrl;
|
|
43
|
+
}
|
|
44
|
+
async fetch(path, options) {
|
|
45
|
+
const headers = new Headers(options?.headers);
|
|
46
|
+
headers.set('Authorization', `Bearer ${this.oauthToken}`);
|
|
47
|
+
if (!headers.has('Content-Type') && options?.body && typeof options.body === 'string') {
|
|
48
|
+
headers.set('Content-Type', 'application/json');
|
|
49
|
+
}
|
|
50
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
51
|
+
...options,
|
|
52
|
+
headers,
|
|
53
|
+
});
|
|
54
|
+
// Return structural type compatible with ZephyrApiConnection
|
|
55
|
+
return {
|
|
56
|
+
ok: response.ok,
|
|
57
|
+
status: response.status,
|
|
58
|
+
statusText: response.statusText,
|
|
59
|
+
json: () => response.json(),
|
|
60
|
+
headers: {
|
|
61
|
+
get: (name) => response.headers.get(name),
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
get connectionId() {
|
|
66
|
+
return `oauth-zephyr-${this.baseUrl}`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get base URL for region
|
|
71
|
+
*/
|
|
72
|
+
function getBaseUrl(region) {
|
|
73
|
+
return region === 'us'
|
|
74
|
+
? 'https://api.zephyrscale.smartbear.com/v2'
|
|
75
|
+
: 'https://eu.api.zephyrscale.smartbear.com/v2';
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Main Zephyr API class
|
|
79
|
+
* Provides hierarchical access to all Zephyr API groups
|
|
80
|
+
*/
|
|
81
|
+
export class ZephyrApi {
|
|
82
|
+
constructor(apiConnection) {
|
|
83
|
+
this.fetch = apiConnection.fetch.bind(apiConnection);
|
|
84
|
+
this.connectionId = apiConnection.connectionId;
|
|
85
|
+
// Initialize all API groups
|
|
86
|
+
this.TestCase = new TestCaseGroup(apiConnection);
|
|
87
|
+
this.TestCycle = new TestCycleGroup(apiConnection);
|
|
88
|
+
this.TestExecution = new TestExecutionGroup(apiConnection);
|
|
89
|
+
this.TestPlan = new TestPlanGroup(apiConnection);
|
|
90
|
+
this.Folder = new FolderGroup(apiConnection);
|
|
91
|
+
this.Project = new ProjectGroup(apiConnection);
|
|
92
|
+
this.Status = new StatusGroup(apiConnection);
|
|
93
|
+
this.Priority = new PriorityGroup(apiConnection);
|
|
94
|
+
this.Environment = new EnvironmentGroup(apiConnection);
|
|
95
|
+
this.Link = new LinkGroup(apiConnection);
|
|
96
|
+
this.IssueLink = new IssueLinkGroup(apiConnection);
|
|
97
|
+
this.Automation = new AutomationGroup(apiConnection);
|
|
98
|
+
this.All = new AllGroup(apiConnection);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Implementation
|
|
102
|
+
export function createZephyrApi(apiConnectionOrOAuthToken, region, baseUrl) {
|
|
103
|
+
const finalRegion = region ?? 'us';
|
|
104
|
+
let apiConnection;
|
|
105
|
+
if (typeof apiConnectionOrOAuthToken === 'string') {
|
|
106
|
+
// OAuth mode - create OAuth connection
|
|
107
|
+
const finalBaseUrl = baseUrl ?? getBaseUrl(finalRegion);
|
|
108
|
+
apiConnection = new OAuthZephyrConnection(apiConnectionOrOAuthToken, finalBaseUrl);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// Connector mode - use provided connection
|
|
112
|
+
// Note: Region is ignored when using API Connection as it's configured in the connection
|
|
113
|
+
apiConnection = apiConnectionOrOAuthToken;
|
|
114
|
+
}
|
|
115
|
+
return new ZephyrApi(apiConnection);
|
|
116
|
+
}
|
|
117
|
+
// Export all types for use in scripts
|
|
118
|
+
export * from './types';
|
|
119
|
+
// Export error strategy utilities
|
|
120
|
+
export * from './error-strategy';
|
|
121
|
+
// Export pagination utilities
|
|
122
|
+
export { getAllPages, getAllPagesCursor } from './utils';
|
|
123
|
+
// Export error types
|
|
124
|
+
export { HttpError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, TooManyRequestsError, ServerError, UnexpectedError, } from './utils';
|