@resolution/jira-api-client 0.4.6 → 0.5.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/CHANGELOG.md +11 -0
- package/README.md +27 -4
- package/lib/index.d.ts +13 -0
- package/lib/index.js +17 -1
- package/lib/index.js.map +1 -1
- package/lib/openapi/platform/BaseJiraPlatformApiClient.d.ts +1 -1
- package/lib/openapi/platform/BaseJiraPlatformApiClient.js +1 -1
- package/lib/openapi/platform/services/DashboardsService.d.ts +7 -1
- package/lib/openapi/platform/services/DashboardsService.js +4 -1
- package/lib/openapi/platform/services/DashboardsService.js.map +1 -1
- package/lib/openapi/platform/services/IssueSearchService.d.ts +8 -1
- package/lib/openapi/platform/services/IssueSearchService.js +2 -1
- package/lib/openapi/platform/services/IssueSearchService.js.map +1 -1
- package/lib/openapi/platform/services/IssuesService.d.ts +8 -1
- package/lib/openapi/platform/services/IssuesService.js +2 -1
- package/lib/openapi/platform/services/IssuesService.js.map +1 -1
- package/lib/openapi/platform/services/PermissionsService.d.ts +7 -0
- package/lib/openapi/platform/services/PermissionsService.js +7 -0
- package/lib/openapi/platform/services/PermissionsService.js.map +1 -1
- package/lib/openapi/serviceManagement/BaseJiraServiceManagementApiClient.d.ts +46 -0
- package/lib/openapi/serviceManagement/BaseJiraServiceManagementApiClient.js +78 -0
- package/lib/openapi/serviceManagement/BaseJiraServiceManagementApiClient.js.map +1 -0
- package/lib/openapi/serviceManagement/core/CommonHttpClient.d.ts +196 -0
- package/lib/openapi/serviceManagement/core/CommonHttpClient.js +390 -0
- package/lib/openapi/serviceManagement/core/CommonHttpClient.js.map +1 -0
- package/lib/openapi/serviceManagement/core/CommonHttpService.d.ts +9 -0
- package/lib/openapi/serviceManagement/core/CommonHttpService.js +29 -0
- package/lib/openapi/serviceManagement/core/CommonHttpService.js.map +1 -0
- package/lib/openapi/serviceManagement/core/CommonValidationSchemaStorage.d.ts +35 -0
- package/lib/openapi/serviceManagement/core/CommonValidationSchemaStorage.js +65 -0
- package/lib/openapi/serviceManagement/core/CommonValidationSchemaStorage.js.map +1 -0
- package/lib/openapi/serviceManagement/models/assets.d.ts +54 -0
- package/lib/openapi/serviceManagement/models/assets.js +60 -0
- package/lib/openapi/serviceManagement/models/assets.js.map +1 -0
- package/lib/openapi/serviceManagement/models/common.d.ts +228 -0
- package/lib/openapi/serviceManagement/models/common.js +172 -0
- package/lib/openapi/serviceManagement/models/common.js.map +1 -0
- package/lib/openapi/serviceManagement/models/customer.d.ts +30 -0
- package/lib/openapi/serviceManagement/models/customer.js +27 -0
- package/lib/openapi/serviceManagement/models/customer.js.map +1 -0
- package/lib/openapi/serviceManagement/models/info.d.ts +18 -0
- package/lib/openapi/serviceManagement/models/info.js +24 -0
- package/lib/openapi/serviceManagement/models/info.js.map +1 -0
- package/lib/openapi/serviceManagement/models/knowledgebase.d.ts +24 -0
- package/lib/openapi/serviceManagement/models/knowledgebase.js +32 -0
- package/lib/openapi/serviceManagement/models/knowledgebase.js.map +1 -0
- package/lib/openapi/serviceManagement/models/organization.d.ts +76 -0
- package/lib/openapi/serviceManagement/models/organization.js +65 -0
- package/lib/openapi/serviceManagement/models/organization.js.map +1 -0
- package/lib/openapi/serviceManagement/models/request.d.ts +594 -0
- package/lib/openapi/serviceManagement/models/request.js +516 -0
- package/lib/openapi/serviceManagement/models/request.js.map +1 -0
- package/lib/openapi/serviceManagement/models/servicedesk.d.ts +525 -0
- package/lib/openapi/serviceManagement/models/servicedesk.js +442 -0
- package/lib/openapi/serviceManagement/models/servicedesk.js.map +1 -0
- package/lib/openapi/serviceManagement/services/AssetsService.d.ts +61 -0
- package/lib/openapi/serviceManagement/services/AssetsService.js +113 -0
- package/lib/openapi/serviceManagement/services/AssetsService.js.map +1 -0
- package/lib/openapi/serviceManagement/services/CustomerService.d.ts +63 -0
- package/lib/openapi/serviceManagement/services/CustomerService.js +93 -0
- package/lib/openapi/serviceManagement/services/CustomerService.js.map +1 -0
- package/lib/openapi/serviceManagement/services/InfoService.d.ts +34 -0
- package/lib/openapi/serviceManagement/services/InfoService.js +71 -0
- package/lib/openapi/serviceManagement/services/InfoService.js.map +1 -0
- package/lib/openapi/serviceManagement/services/KnowledgebaseService.d.ts +81 -0
- package/lib/openapi/serviceManagement/services/KnowledgebaseService.js +106 -0
- package/lib/openapi/serviceManagement/services/KnowledgebaseService.js.map +1 -0
- package/lib/openapi/serviceManagement/services/OrganizationService.d.ts +589 -0
- package/lib/openapi/serviceManagement/services/OrganizationService.js +762 -0
- package/lib/openapi/serviceManagement/services/OrganizationService.js.map +1 -0
- package/lib/openapi/serviceManagement/services/RequestService.d.ts +2736 -0
- package/lib/openapi/serviceManagement/services/RequestService.js +3056 -0
- package/lib/openapi/serviceManagement/services/RequestService.js.map +1 -0
- package/lib/openapi/serviceManagement/services/RequesttypeService.d.ts +166 -0
- package/lib/openapi/serviceManagement/services/RequesttypeService.js +190 -0
- package/lib/openapi/serviceManagement/services/RequesttypeService.js.map +1 -0
- package/lib/openapi/serviceManagement/services/ServicedeskService.d.ts +1268 -0
- package/lib/openapi/serviceManagement/services/ServicedeskService.js +1510 -0
- package/lib/openapi/serviceManagement/services/ServicedeskService.js.map +1 -0
- package/lib/openapi/serviceManagement/validationSchemaStorage.d.ts +3 -0
- package/lib/openapi/serviceManagement/validationSchemaStorage.js +144 -0
- package/lib/openapi/serviceManagement/validationSchemaStorage.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseJiraServiceManagementApiClient = exports.BaseJiraServiceManagementApiClientError = void 0;
|
|
4
|
+
// DO NOT EDIT!
|
|
5
|
+
// This file is generated by "api-typescript-generator".
|
|
6
|
+
// To update this file run "yarn build:openapi".
|
|
7
|
+
const commonHttpClient = require("./core/CommonHttpClient");
|
|
8
|
+
const CommonHttpService_1 = require("./core/CommonHttpService");
|
|
9
|
+
const AssetsService_1 = require("./services/AssetsService");
|
|
10
|
+
const CustomerService_1 = require("./services/CustomerService");
|
|
11
|
+
const InfoService_1 = require("./services/InfoService");
|
|
12
|
+
const KnowledgebaseService_1 = require("./services/KnowledgebaseService");
|
|
13
|
+
const OrganizationService_1 = require("./services/OrganizationService");
|
|
14
|
+
const RequestService_1 = require("./services/RequestService");
|
|
15
|
+
const RequesttypeService_1 = require("./services/RequesttypeService");
|
|
16
|
+
const ServicedeskService_1 = require("./services/ServicedeskService");
|
|
17
|
+
const validationSchemaStorage_1 = require("./validationSchemaStorage");
|
|
18
|
+
class BaseJiraServiceManagementApiClientError extends commonHttpClient.CommonHttpClientError {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
this.name = "BaseJiraServiceManagementApiClientError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.BaseJiraServiceManagementApiClientError = BaseJiraServiceManagementApiClientError;
|
|
25
|
+
/**
|
|
26
|
+
* Service Management Public REST API
|
|
27
|
+
*
|
|
28
|
+
* Public REST API for Jira Service Management
|
|
29
|
+
*
|
|
30
|
+
* @version 1001.0.0-SNAPSHOT-7a4eaa71561009e58ded1503889be69ca87a407d
|
|
31
|
+
*/
|
|
32
|
+
class BaseJiraServiceManagementApiClient extends CommonHttpService_1.CommonHttpService {
|
|
33
|
+
/** @see https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-assets */
|
|
34
|
+
get assets() {
|
|
35
|
+
return this.getServiceInstance(AssetsService_1.AssetsService);
|
|
36
|
+
}
|
|
37
|
+
/** @see https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-customer */
|
|
38
|
+
get customer() {
|
|
39
|
+
return this.getServiceInstance(CustomerService_1.CustomerService);
|
|
40
|
+
}
|
|
41
|
+
/** @see https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-info */
|
|
42
|
+
get info() {
|
|
43
|
+
return this.getServiceInstance(InfoService_1.InfoService);
|
|
44
|
+
}
|
|
45
|
+
/** @see https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-knowledgebase */
|
|
46
|
+
get knowledgebase() {
|
|
47
|
+
return this.getServiceInstance(KnowledgebaseService_1.KnowledgebaseService);
|
|
48
|
+
}
|
|
49
|
+
/** @see https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-organization */
|
|
50
|
+
get organization() {
|
|
51
|
+
return this.getServiceInstance(OrganizationService_1.OrganizationService);
|
|
52
|
+
}
|
|
53
|
+
/** @see https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-request */
|
|
54
|
+
get request() {
|
|
55
|
+
return this.getServiceInstance(RequestService_1.RequestService);
|
|
56
|
+
}
|
|
57
|
+
/** @see https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-requesttype */
|
|
58
|
+
get requesttype() {
|
|
59
|
+
return this.getServiceInstance(RequesttypeService_1.RequesttypeService);
|
|
60
|
+
}
|
|
61
|
+
/** @see https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-servicedesk */
|
|
62
|
+
get servicedesk() {
|
|
63
|
+
return this.getServiceInstance(ServicedeskService_1.ServicedeskService);
|
|
64
|
+
}
|
|
65
|
+
constructor(options) {
|
|
66
|
+
super(() => this.client);
|
|
67
|
+
this.client = new commonHttpClient.CommonHttpClient({
|
|
68
|
+
baseUrl: "https://your-domain.atlassian.net",
|
|
69
|
+
binaryResponseType: "blob",
|
|
70
|
+
errorClass: BaseJiraServiceManagementApiClientError,
|
|
71
|
+
});
|
|
72
|
+
this.getClient = () => this.client;
|
|
73
|
+
this.client.setOptions(Object.assign(Object.assign({}, this.client.getOptions()), options));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.BaseJiraServiceManagementApiClient = BaseJiraServiceManagementApiClient;
|
|
77
|
+
validationSchemaStorage_1.validationSchemaStorage.setErrorClass(BaseJiraServiceManagementApiClientError);
|
|
78
|
+
//# sourceMappingURL=BaseJiraServiceManagementApiClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseJiraServiceManagementApiClient.js","sourceRoot":"","sources":["../../../src/openapi/serviceManagement/BaseJiraServiceManagementApiClient.ts"],"names":[],"mappings":";;;AAAA,eAAe;AACf,wDAAwD;AACxD,gDAAgD;AAChD,4DAA4D;AAC5D,gEAA6D;AAI7D,4DAAyD;AACzD,gEAA6D;AAC7D,wDAAqD;AACrD,0EAAuE;AACvE,wEAAqE;AACrE,8DAA2D;AAC3D,sEAAmE;AACnE,sEAAmE;AACnE,uEAAoE;AAGpE,MAAa,uCAAwC,SAAQ,gBAAgB,CAAC,qBAAqB;IAAnG;;QACE,SAAI,GAAG,yCAAyC,CAAC;IACnD,CAAC;CAAA;AAFD,0FAEC;AACD;;;;;;GAMG;AACH,MAAa,kCAAmC,SAAQ,qCAAiB;IAOvE,yFAAyF;IACzF,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,kBAAkB,CAAC,6BAAa,CAAC,CAAC;IAChD,CAAC;IACD,2FAA2F;IAC3F,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,kBAAkB,CAAC,iCAAe,CAAC,CAAC;IAClD,CAAC;IACD,uFAAuF;IACvF,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,kBAAkB,CAAC,yBAAW,CAAC,CAAC;IAC9C,CAAC;IACD,gGAAgG;IAChG,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,kBAAkB,CAAC,2CAAoB,CAAC,CAAC;IACvD,CAAC;IACD,+FAA+F;IAC/F,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,kBAAkB,CAAC,yCAAmB,CAAC,CAAC;IACtD,CAAC;IACD,0FAA0F;IAC1F,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,kBAAkB,CAAC,+BAAc,CAAC,CAAC;IACjD,CAAC;IACD,8FAA8F;IAC9F,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,kBAAkB,CAAC,uCAAkB,CAAC,CAAC;IACrD,CAAC;IACD,8FAA8F;IAC9F,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,kBAAkB,CAAC,uCAAkB,CAAC,CAAC;IACrD,CAAC;IACD,YAAY,OAAmD;QAC7D,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAvC3B,WAAM,GAAG,IAAI,gBAAgB,CAAC,gBAAgB,CAAC;YAC7C,OAAO,EAAE,mCAAmC;YAC5C,kBAAkB,EAAE,MAAM;YAC1B,UAAU,EAAE,uCAAuC;SACpD,CAAC,CAAC;QACH,cAAS,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC;QAmC5B,IAAI,CAAC,MAAM,CAAC,UAAU,iCACjB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,GACxB,OAAO,EACV,CAAC;IACL,CAAC;CACF;AA9CD,gFA8CC;AACD,iDAAuB,CAAC,aAAa,CAAC,uCAAuC,CAAC,CAAC"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
export interface CommonHttpClientOptions {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
errorClass: {
|
|
4
|
+
new (url: URL, request: CommonHttpClientFetchRequest | undefined, response: CommonHttpClientFetchResponse | undefined, options: CommonHttpClientOptions | undefined, message: string): Error;
|
|
5
|
+
};
|
|
6
|
+
headers?: CommonHttpClientRequestHeaders;
|
|
7
|
+
preprocessRequest?: (request: CommonHttpClientRequest) => Promise<CommonHttpClientRequest>;
|
|
8
|
+
preprocessFetchResponse?: (response: CommonHttpClientFetchResponse, request: CommonHttpClientFetchRequest) => Promise<CommonHttpClientFetchResponse>;
|
|
9
|
+
fetch?: (url: URL, request: CommonHttpClientFetchRequest) => Promise<CommonHttpClientFetchResponse>;
|
|
10
|
+
binaryResponseType: "blob" | "readableStream";
|
|
11
|
+
formatHttpErrorMessage?: (response: CommonHttpClientFetchResponse, request: CommonHttpClientFetchRequest) => string;
|
|
12
|
+
}
|
|
13
|
+
export interface CommonHttpClientRequestHeaders {
|
|
14
|
+
[headerName: string]: string | undefined | null;
|
|
15
|
+
}
|
|
16
|
+
export interface CommonHttpClientFetchRequestHeaders {
|
|
17
|
+
[headerName: string]: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Request prepared for the fetch function.
|
|
21
|
+
*/
|
|
22
|
+
export interface CommonHttpClientFetchRequest {
|
|
23
|
+
/**
|
|
24
|
+
* HTTP Method.
|
|
25
|
+
*/
|
|
26
|
+
method: "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "PATCH";
|
|
27
|
+
/**
|
|
28
|
+
* Request headers.
|
|
29
|
+
*/
|
|
30
|
+
headers: CommonHttpClientFetchRequestHeaders;
|
|
31
|
+
/**
|
|
32
|
+
* Request body.
|
|
33
|
+
*/
|
|
34
|
+
body?: BodyInit;
|
|
35
|
+
/**
|
|
36
|
+
* Cache mode.
|
|
37
|
+
*/
|
|
38
|
+
cache: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload";
|
|
39
|
+
/**
|
|
40
|
+
* Credentials mode.
|
|
41
|
+
*/
|
|
42
|
+
credentials: "include" | "omit" | "same-origin";
|
|
43
|
+
/**
|
|
44
|
+
* Redirect mode.
|
|
45
|
+
*/
|
|
46
|
+
redirect: "error" | "follow" | "manual";
|
|
47
|
+
/**
|
|
48
|
+
* Custom request properties. Can be used to pass metadata to the fetch function.
|
|
49
|
+
*/
|
|
50
|
+
customRequestProps?: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Request in terms of OpenAPI.
|
|
54
|
+
*/
|
|
55
|
+
export type CommonHttpClientRequest = Omit<CommonHttpClientFetchRequest, "body" | "headers" | "cache" | "credentials" | "redirect"> & {
|
|
56
|
+
/**
|
|
57
|
+
* Path to the resource.
|
|
58
|
+
*/
|
|
59
|
+
path: string;
|
|
60
|
+
/**
|
|
61
|
+
* Path parameters, i.e. {id}.
|
|
62
|
+
*/
|
|
63
|
+
pathParams?: Record<string, unknown>;
|
|
64
|
+
/**
|
|
65
|
+
* Query parameters.
|
|
66
|
+
*/
|
|
67
|
+
query?: Record<string, unknown>;
|
|
68
|
+
/**
|
|
69
|
+
* Request body.
|
|
70
|
+
*/
|
|
71
|
+
body?: unknown;
|
|
72
|
+
/**
|
|
73
|
+
* Request headers.
|
|
74
|
+
*/
|
|
75
|
+
headers?: CommonHttpClientRequestHeaders;
|
|
76
|
+
} & Partial<Pick<CommonHttpClientFetchRequest, "cache" | "credentials" | "redirect">>;
|
|
77
|
+
/**
|
|
78
|
+
* Response of the fetch function.
|
|
79
|
+
*/
|
|
80
|
+
export interface CommonHttpClientFetchResponse {
|
|
81
|
+
/**
|
|
82
|
+
* HTTP status code.
|
|
83
|
+
*/
|
|
84
|
+
status: number;
|
|
85
|
+
/**
|
|
86
|
+
* HTTP status code explanation.
|
|
87
|
+
*/
|
|
88
|
+
statusText: string;
|
|
89
|
+
/**
|
|
90
|
+
* Response body.
|
|
91
|
+
*/
|
|
92
|
+
body: CommonHttpClientFetchResponseBody;
|
|
93
|
+
/**
|
|
94
|
+
* Whether the request was successful. True for 2xx status codes.
|
|
95
|
+
*/
|
|
96
|
+
ok: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* The final URL of the request (after redirects).
|
|
99
|
+
*/
|
|
100
|
+
url: string;
|
|
101
|
+
/**
|
|
102
|
+
* Response headers.
|
|
103
|
+
*/
|
|
104
|
+
headers: CommonHttpClientResponseHeaders;
|
|
105
|
+
/**
|
|
106
|
+
* Custom request properties. Can be used to pass metadata outside the fetch function.
|
|
107
|
+
*/
|
|
108
|
+
customRequestProps?: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
export type CommonHttpClientResponseHeaders = Record<string, string> & {
|
|
111
|
+
"set-cookie"?: string[];
|
|
112
|
+
};
|
|
113
|
+
export type CommonHttpClientFetchResponseBody = {
|
|
114
|
+
type: "json";
|
|
115
|
+
data: unknown;
|
|
116
|
+
} | {
|
|
117
|
+
type: "blob";
|
|
118
|
+
data: Blob;
|
|
119
|
+
} | {
|
|
120
|
+
type: "readableStream";
|
|
121
|
+
data: ReadableStream<Uint8Array>;
|
|
122
|
+
};
|
|
123
|
+
export interface CommonHttpClientResponse<T> {
|
|
124
|
+
status: number;
|
|
125
|
+
mediaType?: string;
|
|
126
|
+
body: T;
|
|
127
|
+
response: CommonHttpClientFetchResponse;
|
|
128
|
+
}
|
|
129
|
+
export declare class CommonHttpClientError extends Error {
|
|
130
|
+
readonly url: URL;
|
|
131
|
+
readonly request: CommonHttpClientFetchRequest | undefined;
|
|
132
|
+
readonly response: CommonHttpClientFetchResponse | undefined;
|
|
133
|
+
readonly options: CommonHttpClientOptions | undefined;
|
|
134
|
+
constructor(url: URL, request: CommonHttpClientFetchRequest | undefined, response: CommonHttpClientFetchResponse | undefined, options: CommonHttpClientOptions | undefined, message: string);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* `extends unknown` is a trick to split the union into individual types.
|
|
138
|
+
*/
|
|
139
|
+
type ResponseByMediaType<T extends CommonHttpClientResponse<unknown>, K extends string> = T extends unknown ? ((a: T) => void) extends (a: {
|
|
140
|
+
mediaType: K;
|
|
141
|
+
status: infer _Status;
|
|
142
|
+
body: infer _Body;
|
|
143
|
+
response: CommonHttpClientFetchResponse;
|
|
144
|
+
}) => void ? T : never : never;
|
|
145
|
+
export declare function checkReponseMediaType<T extends CommonHttpClientResponse<unknown>, K extends string>(response: T, mediaType: K): response is ResponseByMediaType<T, K> extends never ? ResponseByMediaType<T, "*/*"> : ResponseByMediaType<T, K>;
|
|
146
|
+
export declare function isJsonMediaType(mediaType: string): boolean;
|
|
147
|
+
type AsCreatedResponseFunction<KCreated extends string, KOther extends string> = <T extends CommonHttpClientResponse<unknown>>(response: T) => ({
|
|
148
|
+
[K in KCreated]: Extract<T, {
|
|
149
|
+
status: 201;
|
|
150
|
+
}>["body"];
|
|
151
|
+
} & {
|
|
152
|
+
created: true;
|
|
153
|
+
}) | ({
|
|
154
|
+
[K in KOther]: Extract<T, {
|
|
155
|
+
status: 200;
|
|
156
|
+
}>["body"];
|
|
157
|
+
} & {
|
|
158
|
+
created: false;
|
|
159
|
+
});
|
|
160
|
+
export declare function asCreatedResponse<KCreated extends string>(keyCreated: KCreated): AsCreatedResponseFunction<KCreated, KCreated>;
|
|
161
|
+
export declare function asCreatedResponse<KCreated extends string, KOther extends string>(keyCreated: KCreated, keyOther: KOther): AsCreatedResponseFunction<KCreated, KOther>;
|
|
162
|
+
export declare const getBody: <T>({ body }: CommonHttpClientResponse<T>) => T;
|
|
163
|
+
export declare const castResponse: <T extends Omit<CommonHttpClientResponse<unknown>, "response">>() => (response: CommonHttpClientResponse<unknown>) => WithResponse<T>;
|
|
164
|
+
export declare const discardResult: () => void;
|
|
165
|
+
export type WithResponse<T> = T & {
|
|
166
|
+
response: CommonHttpClientFetchResponse;
|
|
167
|
+
};
|
|
168
|
+
export declare function createClientWithServices<TOptions, TClient extends {
|
|
169
|
+
getClient(): CommonHttpClient;
|
|
170
|
+
}, TServices extends Record<string, {
|
|
171
|
+
new (client: CommonHttpClient): unknown;
|
|
172
|
+
}>>(this: {
|
|
173
|
+
new (options?: TOptions): TClient;
|
|
174
|
+
}, services: TServices, options?: TOptions): TClient & {
|
|
175
|
+
[K in keyof TServices as K extends string ? Uncapitalize<K extends `${infer TName}Service` ? TName : K> : K]: InstanceType<TServices[K]>;
|
|
176
|
+
};
|
|
177
|
+
export declare class CommonHttpClient {
|
|
178
|
+
protected options: CommonHttpClientOptions;
|
|
179
|
+
constructor(options: CommonHttpClientOptions);
|
|
180
|
+
setOptions(options: CommonHttpClientOptions): void;
|
|
181
|
+
getOptions(): CommonHttpClientOptions;
|
|
182
|
+
protected getSearchParams(params: Record<string, unknown>): URLSearchParams;
|
|
183
|
+
protected buildUrlPath(request: CommonHttpClientRequest): string;
|
|
184
|
+
protected buildUrl(request: CommonHttpClientRequest): URL;
|
|
185
|
+
protected fetch(url: URL, request: CommonHttpClientFetchRequest): Promise<CommonHttpClientFetchResponse>;
|
|
186
|
+
request(request: CommonHttpClientRequest): Promise<CommonHttpClientFetchResponse>;
|
|
187
|
+
responseHandler(distribution: {
|
|
188
|
+
[statusCode: string]: {
|
|
189
|
+
[mediaType: string]: CommonHttpClientFetchResponseBody["type"];
|
|
190
|
+
};
|
|
191
|
+
}): (response: CommonHttpClientFetchResponse) => Promise<CommonHttpClientResponse<unknown>>;
|
|
192
|
+
private cleanupHeaders;
|
|
193
|
+
protected getRequestBody(request: CommonHttpClientRequest): BodyInit | undefined;
|
|
194
|
+
protected preprocessRequest(request: CommonHttpClientRequest): Promise<CommonHttpClientRequest>;
|
|
195
|
+
}
|
|
196
|
+
export {};
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.CommonHttpClient = exports.createClientWithServices = exports.discardResult = exports.castResponse = exports.getBody = exports.asCreatedResponse = exports.isJsonMediaType = exports.checkReponseMediaType = exports.CommonHttpClientError = void 0;
|
|
24
|
+
class CommonHttpClientError extends Error {
|
|
25
|
+
constructor(url, request, response, options, message) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = "OpenApiClientError";
|
|
28
|
+
this.url = url;
|
|
29
|
+
this.request = request;
|
|
30
|
+
this.response = response;
|
|
31
|
+
this.options = options;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.CommonHttpClientError = CommonHttpClientError;
|
|
35
|
+
const jsonContentTypeRegExp = /^application\/(\w+\+)?json/;
|
|
36
|
+
function readableStreamToBlob(stream) {
|
|
37
|
+
const chunks = [];
|
|
38
|
+
const reader = stream.getReader();
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
reader.read().then(function process({ done, value }) {
|
|
41
|
+
if (value) {
|
|
42
|
+
chunks.push(value);
|
|
43
|
+
}
|
|
44
|
+
if (done) {
|
|
45
|
+
resolve(new Blob(chunks));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
reader.read().then(process, reject);
|
|
49
|
+
}, reject);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function convertResponseBody(body, destType) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
if (body.type === destType) {
|
|
55
|
+
return body;
|
|
56
|
+
}
|
|
57
|
+
if (body.type === "json") {
|
|
58
|
+
const blob = new Blob([JSON.stringify(body.data)]);
|
|
59
|
+
if (destType === "blob") {
|
|
60
|
+
return {
|
|
61
|
+
type: "blob",
|
|
62
|
+
data: blob,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
else if (destType === "readableStream") {
|
|
66
|
+
return {
|
|
67
|
+
type: "readableStream",
|
|
68
|
+
data: blob.stream(),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
throw new Error("Invalid destination type.");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (body.type === "blob") {
|
|
76
|
+
if (destType === "json") {
|
|
77
|
+
return {
|
|
78
|
+
type: "json",
|
|
79
|
+
data: JSON.parse(yield body.data.text()),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
else if (destType === "readableStream") {
|
|
83
|
+
return {
|
|
84
|
+
type: "readableStream",
|
|
85
|
+
data: body.data.stream(),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw new Error("Invalid destination type.");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (body.type === "readableStream") {
|
|
93
|
+
if (destType === "json") {
|
|
94
|
+
return {
|
|
95
|
+
type: "json",
|
|
96
|
+
data: JSON.parse(yield (yield readableStreamToBlob(body.data)).text()),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else if (destType === "blob") {
|
|
100
|
+
return {
|
|
101
|
+
type: "blob",
|
|
102
|
+
data: yield readableStreamToBlob(body.data),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
throw new Error("Invalid destination type.");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
throw new Error("Invalid response body type.");
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function checkReponseMediaType(response, mediaType) {
|
|
113
|
+
return response.mediaType === mediaType;
|
|
114
|
+
}
|
|
115
|
+
exports.checkReponseMediaType = checkReponseMediaType;
|
|
116
|
+
function isJsonMediaType(mediaType) {
|
|
117
|
+
return Boolean(mediaType.match(jsonContentTypeRegExp));
|
|
118
|
+
}
|
|
119
|
+
exports.isJsonMediaType = isJsonMediaType;
|
|
120
|
+
function asCreatedResponse(...keys) {
|
|
121
|
+
var _a;
|
|
122
|
+
const keyCreated = keys[0];
|
|
123
|
+
const keyOther = (_a = keys[1]) !== null && _a !== void 0 ? _a : keyCreated;
|
|
124
|
+
return (response) => {
|
|
125
|
+
if (response.status === 201) {
|
|
126
|
+
return {
|
|
127
|
+
created: true,
|
|
128
|
+
[keyCreated]: response.body,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return {
|
|
133
|
+
created: false,
|
|
134
|
+
[keyOther]: response.body,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
exports.asCreatedResponse = asCreatedResponse;
|
|
140
|
+
const getBody = ({ body }) => body;
|
|
141
|
+
exports.getBody = getBody;
|
|
142
|
+
const castResponse = () => (response) => response;
|
|
143
|
+
exports.castResponse = castResponse;
|
|
144
|
+
const discardResult = () => { };
|
|
145
|
+
exports.discardResult = discardResult;
|
|
146
|
+
function createClientWithServices(services, options) {
|
|
147
|
+
const client = new this(options);
|
|
148
|
+
const extension = {};
|
|
149
|
+
for (const serviceName in services) {
|
|
150
|
+
if (Object.prototype.hasOwnProperty.call(services, serviceName)) {
|
|
151
|
+
extension[serviceName
|
|
152
|
+
.replace(/[^\b]Service$/, "")
|
|
153
|
+
.replace(/^\w/, (s) => s.toLowerCase())] = new services[serviceName](client.getClient());
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return Object.assign(client, extension);
|
|
157
|
+
}
|
|
158
|
+
exports.createClientWithServices = createClientWithServices;
|
|
159
|
+
function getErrorMessage(e) {
|
|
160
|
+
return e instanceof Error ? e.message : String(e);
|
|
161
|
+
}
|
|
162
|
+
class CommonHttpClient {
|
|
163
|
+
constructor(options) {
|
|
164
|
+
this.options = options;
|
|
165
|
+
}
|
|
166
|
+
setOptions(options) {
|
|
167
|
+
this.options = options;
|
|
168
|
+
}
|
|
169
|
+
getOptions() {
|
|
170
|
+
return this.options;
|
|
171
|
+
}
|
|
172
|
+
getSearchParams(params) {
|
|
173
|
+
const result = new URLSearchParams();
|
|
174
|
+
const process = (key, value) => {
|
|
175
|
+
if (value !== undefined && value !== null) {
|
|
176
|
+
if (Array.isArray(value)) {
|
|
177
|
+
for (const arrayVal of value) {
|
|
178
|
+
process(key, arrayVal);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else if (typeof value === "object") {
|
|
182
|
+
for (const [subKey, subValue] of Object.entries(params)) {
|
|
183
|
+
process(`${key}[${subKey}]`, subValue);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
result.append(key, String(value));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
for (const [key, value] of Object.entries(params)) {
|
|
192
|
+
process(key, value);
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
buildUrlPath(request) {
|
|
197
|
+
const pathParams = request.pathParams;
|
|
198
|
+
if (pathParams) {
|
|
199
|
+
return request.path.replace(/\{(.*?)}/g, (original, paramName) => {
|
|
200
|
+
if (Object.prototype.hasOwnProperty.call(pathParams, paramName)) {
|
|
201
|
+
return encodeURI(String(pathParams[paramName]));
|
|
202
|
+
}
|
|
203
|
+
return original;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return request.path;
|
|
207
|
+
}
|
|
208
|
+
buildUrl(request) {
|
|
209
|
+
const url = new URL(this.buildUrlPath(request).replace(/^\//, ""), this.options.baseUrl.replace(/\/?$/, "/"));
|
|
210
|
+
if (request.query) {
|
|
211
|
+
for (const [key, value] of this.getSearchParams(request.query)) {
|
|
212
|
+
url.searchParams.append(key, value);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return url;
|
|
216
|
+
}
|
|
217
|
+
fetch(url, request) {
|
|
218
|
+
var _a;
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
const requestProps = __rest(request, []);
|
|
221
|
+
const requestInit = requestProps;
|
|
222
|
+
const response = yield fetch(url, requestInit);
|
|
223
|
+
const body = isJsonMediaType((_a = response.headers.get("content-type")) !== null && _a !== void 0 ? _a : "")
|
|
224
|
+
? {
|
|
225
|
+
type: "json",
|
|
226
|
+
data: yield response.json(),
|
|
227
|
+
}
|
|
228
|
+
: {
|
|
229
|
+
type: "blob",
|
|
230
|
+
data: yield response.blob(),
|
|
231
|
+
};
|
|
232
|
+
const headers = {};
|
|
233
|
+
response.headers.forEach((value, key) => {
|
|
234
|
+
headers[key] = value;
|
|
235
|
+
});
|
|
236
|
+
if (response.headers.has("set-cookie") &&
|
|
237
|
+
"getSetCookie" in response.headers) {
|
|
238
|
+
headers["set-cookie"] = response.headers.getSetCookie();
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
status: response.status,
|
|
242
|
+
statusText: response.statusText,
|
|
243
|
+
body,
|
|
244
|
+
url: response.url,
|
|
245
|
+
headers,
|
|
246
|
+
ok: response.ok,
|
|
247
|
+
customRequestProps: request.customRequestProps,
|
|
248
|
+
};
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
request(request) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
try {
|
|
254
|
+
request = yield this.preprocessRequest(request);
|
|
255
|
+
}
|
|
256
|
+
catch (e) {
|
|
257
|
+
let url;
|
|
258
|
+
try {
|
|
259
|
+
url = this.buildUrl(request);
|
|
260
|
+
}
|
|
261
|
+
catch (e) {
|
|
262
|
+
throw new this.options.errorClass(new URL(request.path, this.options.baseUrl), undefined, undefined, this.options, `Error building request URL: ${getErrorMessage(e)}`);
|
|
263
|
+
}
|
|
264
|
+
throw new this.options.errorClass(url, undefined, undefined, this.options, `preprocessRequest error: ${getErrorMessage(e)}`);
|
|
265
|
+
}
|
|
266
|
+
let url;
|
|
267
|
+
try {
|
|
268
|
+
url = this.buildUrl(request);
|
|
269
|
+
}
|
|
270
|
+
catch (e) {
|
|
271
|
+
throw new this.options.errorClass(new URL(request.path, this.options.baseUrl), undefined, undefined, this.options, `Error building request URL: ${getErrorMessage(e)}`);
|
|
272
|
+
}
|
|
273
|
+
const { body, path: _path, pathParams: _pathParams, query: _query, headers: requestHeaders, cache, credentials, redirect } = request, otherRequestProps = __rest(request, ["body", "path", "pathParams", "query", "headers", "cache", "credentials", "redirect"]);
|
|
274
|
+
const headers = this.cleanupHeaders(requestHeaders);
|
|
275
|
+
const fetchRequest = Object.assign(Object.assign({}, otherRequestProps), { headers, cache: cache !== null && cache !== void 0 ? cache : "default", credentials: credentials !== null && credentials !== void 0 ? credentials : "same-origin", redirect: redirect !== null && redirect !== void 0 ? redirect : "follow", body: this.getRequestBody(request) });
|
|
276
|
+
let fetchResponse;
|
|
277
|
+
try {
|
|
278
|
+
if (this.options.fetch) {
|
|
279
|
+
fetchResponse = yield this.options.fetch(url, fetchRequest);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
fetchResponse = yield this.fetch(url, fetchRequest);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
catch (e) {
|
|
286
|
+
throw new this.options.errorClass(url, fetchRequest, undefined, this.options, getErrorMessage(e));
|
|
287
|
+
}
|
|
288
|
+
if (this.options.preprocessFetchResponse) {
|
|
289
|
+
try {
|
|
290
|
+
fetchResponse = yield this.options.preprocessFetchResponse(fetchResponse, fetchRequest);
|
|
291
|
+
}
|
|
292
|
+
catch (e) {
|
|
293
|
+
throw new this.options.errorClass(url, fetchRequest, fetchResponse, this.options, `preprocessFetchResponse error: ${getErrorMessage(e)}`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (!fetchResponse.ok) {
|
|
297
|
+
throw new this.options.errorClass(url, fetchRequest, fetchResponse, this.options, this.options.formatHttpErrorMessage
|
|
298
|
+
? this.options.formatHttpErrorMessage(fetchResponse, fetchRequest)
|
|
299
|
+
: `HTTP Error ${fetchResponse.status} (${fetchResponse.statusText})`);
|
|
300
|
+
}
|
|
301
|
+
return fetchResponse;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
responseHandler(distribution) {
|
|
305
|
+
return (response) => __awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
var _a;
|
|
307
|
+
const body = response.body;
|
|
308
|
+
const contentType = response.headers["content-type"];
|
|
309
|
+
const mediaType = contentType
|
|
310
|
+
? contentType.replace(/;.*$/, "")
|
|
311
|
+
: undefined;
|
|
312
|
+
const mediaTypes = (_a = distribution[response.status]) !== null && _a !== void 0 ? _a : {};
|
|
313
|
+
let destType;
|
|
314
|
+
if (mediaType) {
|
|
315
|
+
destType = mediaTypes[mediaType];
|
|
316
|
+
if (!destType) {
|
|
317
|
+
destType = mediaTypes[mediaType.replace(/\/.*$/, "/*")];
|
|
318
|
+
}
|
|
319
|
+
if (!destType) {
|
|
320
|
+
destType = mediaTypes[mediaType.replace(/^.*\//, "*/")];
|
|
321
|
+
}
|
|
322
|
+
if (!destType) {
|
|
323
|
+
destType = mediaTypes["*/*"];
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
destType = mediaTypes["*/*"];
|
|
328
|
+
}
|
|
329
|
+
if (!destType) {
|
|
330
|
+
let binaryBody;
|
|
331
|
+
try {
|
|
332
|
+
binaryBody = yield convertResponseBody(body, this.options.binaryResponseType);
|
|
333
|
+
}
|
|
334
|
+
catch (e) {
|
|
335
|
+
throw new this.options.errorClass(new URL(response.url), undefined, response, this.options, `Error converting response body: ${getErrorMessage(e)}`);
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
mediaType,
|
|
339
|
+
status: response.status,
|
|
340
|
+
body: binaryBody,
|
|
341
|
+
response,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
try {
|
|
345
|
+
const convertedBody = yield convertResponseBody(body, destType);
|
|
346
|
+
return {
|
|
347
|
+
mediaType,
|
|
348
|
+
status: response.status,
|
|
349
|
+
body: convertedBody.data,
|
|
350
|
+
response,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
catch (e) {
|
|
354
|
+
throw new this.options.errorClass(new URL(response.url), undefined, response, this.options, `Error converting response body: ${getErrorMessage(e)}`);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
cleanupHeaders(headers) {
|
|
359
|
+
if (headers === undefined) {
|
|
360
|
+
return {};
|
|
361
|
+
}
|
|
362
|
+
return Object.fromEntries(Object.entries(headers !== null && headers !== void 0 ? headers : {})
|
|
363
|
+
.filter((header) => header[1] !== undefined && header[1] !== null)
|
|
364
|
+
.map(([key, value]) => [key.toLowerCase(), value]));
|
|
365
|
+
}
|
|
366
|
+
getRequestBody(request) {
|
|
367
|
+
var _a;
|
|
368
|
+
if (request.body === undefined) {
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
for (const [key, value] of Object.entries((_a = request.headers) !== null && _a !== void 0 ? _a : {})) {
|
|
372
|
+
if (key.toLowerCase() === "content-type" &&
|
|
373
|
+
value &&
|
|
374
|
+
isJsonMediaType(value)) {
|
|
375
|
+
return JSON.stringify(request.body);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return request.body;
|
|
379
|
+
}
|
|
380
|
+
preprocessRequest(request) {
|
|
381
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
382
|
+
const requestWithHeaders = Object.assign(Object.assign({}, request), { headers: Object.assign(Object.assign({}, this.options.headers), this.cleanupHeaders(request.headers)) });
|
|
383
|
+
return this.options.preprocessRequest
|
|
384
|
+
? this.options.preprocessRequest(requestWithHeaders)
|
|
385
|
+
: requestWithHeaders;
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
exports.CommonHttpClient = CommonHttpClient;
|
|
390
|
+
//# sourceMappingURL=CommonHttpClient.js.map
|