@tapis/tapis-typescript-sk 0.0.2
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/.openapi-generator/FILES +67 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/README.md +45 -0
- package/dist/apis/GeneralApi.d.ts +45 -0
- package/dist/apis/GeneralApi.js +199 -0
- package/dist/apis/RoleApi.d.ts +205 -0
- package/dist/apis/RoleApi.js +861 -0
- package/dist/apis/UserApi.d.ts +276 -0
- package/dist/apis/UserApi.js +1166 -0
- package/dist/apis/VaultApi.d.ts +195 -0
- package/dist/apis/VaultApi.js +740 -0
- package/dist/apis/index.d.ts +4 -0
- package/dist/apis/index.js +11 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +10 -0
- package/dist/models/Options.d.ts +27 -0
- package/dist/models/Options.js +41 -0
- package/dist/models/ReqAddChildRole.d.ts +39 -0
- package/dist/models/ReqAddChildRole.js +45 -0
- package/dist/models/ReqAddRolePermission.d.ts +39 -0
- package/dist/models/ReqAddRolePermission.js +45 -0
- package/dist/models/ReqCreateRole.d.ts +39 -0
- package/dist/models/ReqCreateRole.js +45 -0
- package/dist/models/ReqGrantAdminRole.d.ts +33 -0
- package/dist/models/ReqGrantAdminRole.js +43 -0
- package/dist/models/ReqGrantUserPermission.d.ts +39 -0
- package/dist/models/ReqGrantUserPermission.js +45 -0
- package/dist/models/ReqGrantUserRole.d.ts +39 -0
- package/dist/models/ReqGrantUserRole.js +45 -0
- package/dist/models/ReqGrantUserRoleWithPermission.d.ts +45 -0
- package/dist/models/ReqGrantUserRoleWithPermission.js +47 -0
- package/dist/models/ReqPreviewPathPrefix.d.ts +63 -0
- package/dist/models/ReqPreviewPathPrefix.js +53 -0
- package/dist/models/ReqRemoveChildRole.d.ts +39 -0
- package/dist/models/ReqRemoveChildRole.js +45 -0
- package/dist/models/ReqRemoveRolePermission.d.ts +39 -0
- package/dist/models/ReqRemoveRolePermission.js +45 -0
- package/dist/models/ReqReplacePathPrefix.d.ts +63 -0
- package/dist/models/ReqReplacePathPrefix.js +53 -0
- package/dist/models/ReqRevokeAdminRole.d.ts +33 -0
- package/dist/models/ReqRevokeAdminRole.js +43 -0
- package/dist/models/ReqRevokeUserPermission.d.ts +39 -0
- package/dist/models/ReqRevokeUserPermission.js +45 -0
- package/dist/models/ReqRevokeUserRole.d.ts +39 -0
- package/dist/models/ReqRevokeUserRole.js +45 -0
- package/dist/models/ReqUpdateRoleDescription.d.ts +33 -0
- package/dist/models/ReqUpdateRoleDescription.js +43 -0
- package/dist/models/ReqUpdateRoleName.d.ts +33 -0
- package/dist/models/ReqUpdateRoleName.js +43 -0
- package/dist/models/ReqUpdateRoleOwner.d.ts +39 -0
- package/dist/models/ReqUpdateRoleOwner.js +45 -0
- package/dist/models/ReqUserHasRole.d.ts +45 -0
- package/dist/models/ReqUserHasRole.js +47 -0
- package/dist/models/ReqUserHasRoleMulti.d.ts +45 -0
- package/dist/models/ReqUserHasRoleMulti.js +47 -0
- package/dist/models/ReqUserIsAdmin.d.ts +33 -0
- package/dist/models/ReqUserIsAdmin.js +43 -0
- package/dist/models/ReqUserIsPermitted.d.ts +45 -0
- package/dist/models/ReqUserIsPermitted.js +47 -0
- package/dist/models/ReqUserIsPermittedMulti.d.ts +45 -0
- package/dist/models/ReqUserIsPermittedMulti.js +47 -0
- package/dist/models/ReqValidateServicePwd.d.ts +39 -0
- package/dist/models/ReqValidateServicePwd.js +45 -0
- package/dist/models/ReqVersions.d.ts +39 -0
- package/dist/models/ReqVersions.js +45 -0
- package/dist/models/ReqWriteSecret.d.ts +48 -0
- package/dist/models/ReqWriteSecret.js +48 -0
- package/dist/models/RespAuthorized.d.ts +46 -0
- package/dist/models/RespAuthorized.js +48 -0
- package/dist/models/RespBasic.d.ts +45 -0
- package/dist/models/RespBasic.js +47 -0
- package/dist/models/RespChangeCount.d.ts +46 -0
- package/dist/models/RespChangeCount.js +48 -0
- package/dist/models/RespName.d.ts +46 -0
- package/dist/models/RespName.js +48 -0
- package/dist/models/RespNameArray.d.ts +46 -0
- package/dist/models/RespNameArray.js +48 -0
- package/dist/models/RespPathPrefixes.d.ts +46 -0
- package/dist/models/RespPathPrefixes.js +48 -0
- package/dist/models/RespProbe.d.ts +46 -0
- package/dist/models/RespProbe.js +48 -0
- package/dist/models/RespResourceUrl.d.ts +46 -0
- package/dist/models/RespResourceUrl.js +48 -0
- package/dist/models/RespRole.d.ts +46 -0
- package/dist/models/RespRole.js +48 -0
- package/dist/models/RespSecret.d.ts +46 -0
- package/dist/models/RespSecret.js +48 -0
- package/dist/models/RespSecretList.d.ts +46 -0
- package/dist/models/RespSecretList.js +48 -0
- package/dist/models/RespSecretMeta.d.ts +46 -0
- package/dist/models/RespSecretMeta.js +48 -0
- package/dist/models/RespSecretVersionMetadata.d.ts +46 -0
- package/dist/models/RespSecretVersionMetadata.js +48 -0
- package/dist/models/RespVersions.d.ts +45 -0
- package/dist/models/RespVersions.js +47 -0
- package/dist/models/ResultAuthorized.d.ts +27 -0
- package/dist/models/ResultAuthorized.js +41 -0
- package/dist/models/ResultChangeCount.d.ts +27 -0
- package/dist/models/ResultChangeCount.js +41 -0
- package/dist/models/ResultName.d.ts +27 -0
- package/dist/models/ResultName.js +41 -0
- package/dist/models/ResultNameArray.d.ts +27 -0
- package/dist/models/ResultNameArray.js +41 -0
- package/dist/models/ResultResourceUrl.d.ts +27 -0
- package/dist/models/ResultResourceUrl.js +41 -0
- package/dist/models/SkProbe.d.ts +45 -0
- package/dist/models/SkProbe.js +47 -0
- package/dist/models/SkRole.d.ts +93 -0
- package/dist/models/SkRole.js +63 -0
- package/dist/models/SkSecret.d.ts +36 -0
- package/dist/models/SkSecret.js +44 -0
- package/dist/models/SkSecretList.d.ts +33 -0
- package/dist/models/SkSecretList.js +43 -0
- package/dist/models/SkSecretMetadata.d.ts +45 -0
- package/dist/models/SkSecretMetadata.js +47 -0
- package/dist/models/SkSecretVersion.d.ts +45 -0
- package/dist/models/SkSecretVersion.js +47 -0
- package/dist/models/SkSecretVersionMetadata.d.ts +58 -0
- package/dist/models/SkSecretVersionMetadata.js +52 -0
- package/dist/models/Transformation.d.ts +39 -0
- package/dist/models/Transformation.js +45 -0
- package/dist/models/index.d.ts +53 -0
- package/dist/models/index.js +60 -0
- package/dist/runtime.d.ts +140 -0
- package/dist/runtime.js +420 -0
- package/package.json +15 -0
- package/src/apis/GeneralApi.ts +117 -0
- package/src/apis/RoleApi.ts +782 -0
- package/src/apis/UserApi.ts +1047 -0
- package/src/apis/VaultApi.ts +802 -0
- package/src/apis/index.ts +6 -0
- package/src/index.ts +5 -0
- package/src/models/Options.ts +56 -0
- package/src/models/ReqAddChildRole.ts +72 -0
- package/src/models/ReqAddRolePermission.ts +72 -0
- package/src/models/ReqCreateRole.ts +72 -0
- package/src/models/ReqGrantAdminRole.ts +64 -0
- package/src/models/ReqGrantUserPermission.ts +72 -0
- package/src/models/ReqGrantUserRole.ts +72 -0
- package/src/models/ReqGrantUserRoleWithPermission.ts +80 -0
- package/src/models/ReqPreviewPathPrefix.ts +104 -0
- package/src/models/ReqRemoveChildRole.ts +72 -0
- package/src/models/ReqRemoveRolePermission.ts +72 -0
- package/src/models/ReqReplacePathPrefix.ts +104 -0
- package/src/models/ReqRevokeAdminRole.ts +64 -0
- package/src/models/ReqRevokeUserPermission.ts +72 -0
- package/src/models/ReqRevokeUserRole.ts +72 -0
- package/src/models/ReqUpdateRoleDescription.ts +64 -0
- package/src/models/ReqUpdateRoleName.ts +64 -0
- package/src/models/ReqUpdateRoleOwner.ts +72 -0
- package/src/models/ReqUserHasRole.ts +80 -0
- package/src/models/ReqUserHasRoleMulti.ts +80 -0
- package/src/models/ReqUserIsAdmin.ts +64 -0
- package/src/models/ReqUserIsPermitted.ts +80 -0
- package/src/models/ReqUserIsPermittedMulti.ts +80 -0
- package/src/models/ReqValidateServicePwd.ts +72 -0
- package/src/models/ReqVersions.ts +72 -0
- package/src/models/ReqWriteSecret.ts +87 -0
- package/src/models/RespAuthorized.ts +87 -0
- package/src/models/RespBasic.ts +80 -0
- package/src/models/RespChangeCount.ts +87 -0
- package/src/models/RespName.ts +87 -0
- package/src/models/RespNameArray.ts +87 -0
- package/src/models/RespPathPrefixes.ts +87 -0
- package/src/models/RespProbe.ts +87 -0
- package/src/models/RespResourceUrl.ts +87 -0
- package/src/models/RespRole.ts +87 -0
- package/src/models/RespSecret.ts +87 -0
- package/src/models/RespSecretList.ts +87 -0
- package/src/models/RespSecretMeta.ts +87 -0
- package/src/models/RespSecretVersionMetadata.ts +87 -0
- package/src/models/RespVersions.ts +80 -0
- package/src/models/ResultAuthorized.ts +56 -0
- package/src/models/ResultChangeCount.ts +56 -0
- package/src/models/ResultName.ts +56 -0
- package/src/models/ResultNameArray.ts +56 -0
- package/src/models/ResultResourceUrl.ts +56 -0
- package/src/models/SkProbe.ts +80 -0
- package/src/models/SkRole.ts +144 -0
- package/src/models/SkSecret.ts +71 -0
- package/src/models/SkSecretList.ts +64 -0
- package/src/models/SkSecretMetadata.ts +80 -0
- package/src/models/SkSecretVersion.ts +80 -0
- package/src/models/SkSecretVersionMetadata.ts +103 -0
- package/src/models/Transformation.ts +72 -0
- package/src/models/index.ts +55 -0
- package/src/runtime.ts +320 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export * from './Options';
|
|
4
|
+
export * from './ReqAddChildRole';
|
|
5
|
+
export * from './ReqAddRolePermission';
|
|
6
|
+
export * from './ReqCreateRole';
|
|
7
|
+
export * from './ReqGrantAdminRole';
|
|
8
|
+
export * from './ReqGrantUserPermission';
|
|
9
|
+
export * from './ReqGrantUserRole';
|
|
10
|
+
export * from './ReqGrantUserRoleWithPermission';
|
|
11
|
+
export * from './ReqPreviewPathPrefix';
|
|
12
|
+
export * from './ReqRemoveChildRole';
|
|
13
|
+
export * from './ReqRemoveRolePermission';
|
|
14
|
+
export * from './ReqReplacePathPrefix';
|
|
15
|
+
export * from './ReqRevokeAdminRole';
|
|
16
|
+
export * from './ReqRevokeUserPermission';
|
|
17
|
+
export * from './ReqRevokeUserRole';
|
|
18
|
+
export * from './ReqUpdateRoleDescription';
|
|
19
|
+
export * from './ReqUpdateRoleName';
|
|
20
|
+
export * from './ReqUpdateRoleOwner';
|
|
21
|
+
export * from './ReqUserHasRole';
|
|
22
|
+
export * from './ReqUserHasRoleMulti';
|
|
23
|
+
export * from './ReqUserIsAdmin';
|
|
24
|
+
export * from './ReqUserIsPermitted';
|
|
25
|
+
export * from './ReqUserIsPermittedMulti';
|
|
26
|
+
export * from './ReqValidateServicePwd';
|
|
27
|
+
export * from './ReqVersions';
|
|
28
|
+
export * from './ReqWriteSecret';
|
|
29
|
+
export * from './RespAuthorized';
|
|
30
|
+
export * from './RespBasic';
|
|
31
|
+
export * from './RespChangeCount';
|
|
32
|
+
export * from './RespName';
|
|
33
|
+
export * from './RespNameArray';
|
|
34
|
+
export * from './RespPathPrefixes';
|
|
35
|
+
export * from './RespProbe';
|
|
36
|
+
export * from './RespResourceUrl';
|
|
37
|
+
export * from './RespRole';
|
|
38
|
+
export * from './RespSecret';
|
|
39
|
+
export * from './RespSecretList';
|
|
40
|
+
export * from './RespSecretMeta';
|
|
41
|
+
export * from './RespSecretVersionMetadata';
|
|
42
|
+
export * from './RespVersions';
|
|
43
|
+
export * from './ResultAuthorized';
|
|
44
|
+
export * from './ResultChangeCount';
|
|
45
|
+
export * from './ResultName';
|
|
46
|
+
export * from './ResultNameArray';
|
|
47
|
+
export * from './ResultResourceUrl';
|
|
48
|
+
export * from './SkProbe';
|
|
49
|
+
export * from './SkRole';
|
|
50
|
+
export * from './SkSecret';
|
|
51
|
+
export * from './SkSecretList';
|
|
52
|
+
export * from './SkSecretMetadata';
|
|
53
|
+
export * from './SkSecretVersion';
|
|
54
|
+
export * from './SkSecretVersionMetadata';
|
|
55
|
+
export * from './Transformation';
|
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Tapis Security API
|
|
5
|
+
* The Tapis Security API provides access to the Tapis Security Kernel authorization and secrets facilities.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 0.1
|
|
8
|
+
* Contact: cicsupport@tacc.utexas.edu
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export const BASE_PATH = "http://localhost:8080/v3".replace(/\/+$/, "");
|
|
17
|
+
|
|
18
|
+
const isBlob = (value: any) => typeof Blob !== 'undefined' && value instanceof Blob;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This is the base class for all generated API classes.
|
|
22
|
+
*/
|
|
23
|
+
export class BaseAPI {
|
|
24
|
+
|
|
25
|
+
private middleware: Middleware[];
|
|
26
|
+
|
|
27
|
+
constructor(protected configuration = new Configuration()) {
|
|
28
|
+
this.middleware = configuration.middleware;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
|
|
32
|
+
const next = this.clone<T>();
|
|
33
|
+
next.middleware = next.middleware.concat(...middlewares);
|
|
34
|
+
return next;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
|
|
38
|
+
const middlewares = preMiddlewares.map((pre) => ({ pre }));
|
|
39
|
+
return this.withMiddleware<T>(...middlewares);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
|
|
43
|
+
const middlewares = postMiddlewares.map((post) => ({ post }));
|
|
44
|
+
return this.withMiddleware<T>(...middlewares);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected async request(context: RequestOpts, initOverrides?: RequestInit): Promise<Response> {
|
|
48
|
+
const { url, init } = this.createFetchParams(context, initOverrides);
|
|
49
|
+
const response = await this.fetchApi(url, init);
|
|
50
|
+
if (response.status >= 200 && response.status < 300) {
|
|
51
|
+
return response;
|
|
52
|
+
}
|
|
53
|
+
throw response;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) {
|
|
57
|
+
let url = this.configuration.basePath + context.path;
|
|
58
|
+
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
59
|
+
// only add the querystring to the URL if there are query parameters.
|
|
60
|
+
// this is done to avoid urls ending with a "?" character which buggy webservers
|
|
61
|
+
// do not handle correctly sometimes.
|
|
62
|
+
url += '?' + this.configuration.queryParamsStringify(context.query);
|
|
63
|
+
}
|
|
64
|
+
const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body))
|
|
65
|
+
? context.body
|
|
66
|
+
: JSON.stringify(context.body);
|
|
67
|
+
|
|
68
|
+
const headers = Object.assign({}, this.configuration.headers, context.headers);
|
|
69
|
+
const init = {
|
|
70
|
+
method: context.method,
|
|
71
|
+
headers: headers,
|
|
72
|
+
body,
|
|
73
|
+
credentials: this.configuration.credentials,
|
|
74
|
+
...initOverrides
|
|
75
|
+
};
|
|
76
|
+
return { url, init };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private fetchApi = async (url: string, init: RequestInit) => {
|
|
80
|
+
let fetchParams = { url, init };
|
|
81
|
+
for (const middleware of this.middleware) {
|
|
82
|
+
if (middleware.pre) {
|
|
83
|
+
fetchParams = await middleware.pre({
|
|
84
|
+
fetch: this.fetchApi,
|
|
85
|
+
...fetchParams,
|
|
86
|
+
}) || fetchParams;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
|
|
90
|
+
for (const middleware of this.middleware) {
|
|
91
|
+
if (middleware.post) {
|
|
92
|
+
response = await middleware.post({
|
|
93
|
+
fetch: this.fetchApi,
|
|
94
|
+
url: fetchParams.url,
|
|
95
|
+
init: fetchParams.init,
|
|
96
|
+
response: response.clone(),
|
|
97
|
+
}) || response;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return response;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Create a shallow clone of `this` by constructing a new instance
|
|
105
|
+
* and then shallow cloning data members.
|
|
106
|
+
*/
|
|
107
|
+
private clone<T extends BaseAPI>(this: T): T {
|
|
108
|
+
const constructor = this.constructor as any;
|
|
109
|
+
const next = new constructor(this.configuration);
|
|
110
|
+
next.middleware = this.middleware.slice();
|
|
111
|
+
return next;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export class RequiredError extends Error {
|
|
116
|
+
name: "RequiredError" = "RequiredError";
|
|
117
|
+
constructor(public field: string, msg?: string) {
|
|
118
|
+
super(msg);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export const COLLECTION_FORMATS = {
|
|
123
|
+
csv: ",",
|
|
124
|
+
ssv: " ",
|
|
125
|
+
tsv: "\t",
|
|
126
|
+
pipes: "|",
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export type FetchAPI = GlobalFetch['fetch'];
|
|
130
|
+
|
|
131
|
+
export interface ConfigurationParameters {
|
|
132
|
+
basePath?: string; // override base path
|
|
133
|
+
fetchApi?: FetchAPI; // override for fetch implementation
|
|
134
|
+
middleware?: Middleware[]; // middleware to apply before/after fetch requests
|
|
135
|
+
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
|
|
136
|
+
username?: string; // parameter for basic security
|
|
137
|
+
password?: string; // parameter for basic security
|
|
138
|
+
apiKey?: string | ((name: string) => string); // parameter for apiKey security
|
|
139
|
+
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
|
|
140
|
+
headers?: HTTPHeaders; //header params we want to use on every request
|
|
141
|
+
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export class Configuration {
|
|
145
|
+
constructor(private configuration: ConfigurationParameters = {}) {}
|
|
146
|
+
|
|
147
|
+
get basePath(): string {
|
|
148
|
+
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
get fetchApi(): FetchAPI | undefined {
|
|
152
|
+
return this.configuration.fetchApi;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
get middleware(): Middleware[] {
|
|
156
|
+
return this.configuration.middleware || [];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
get queryParamsStringify(): (params: HTTPQuery) => string {
|
|
160
|
+
return this.configuration.queryParamsStringify || querystring;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
get username(): string | undefined {
|
|
164
|
+
return this.configuration.username;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
get password(): string | undefined {
|
|
168
|
+
return this.configuration.password;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
get apiKey(): ((name: string) => string) | undefined {
|
|
172
|
+
const apiKey = this.configuration.apiKey;
|
|
173
|
+
if (apiKey) {
|
|
174
|
+
return typeof apiKey === 'function' ? apiKey : () => apiKey;
|
|
175
|
+
}
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
get accessToken(): ((name?: string, scopes?: string[]) => string | Promise<string>) | undefined {
|
|
180
|
+
const accessToken = this.configuration.accessToken;
|
|
181
|
+
if (accessToken) {
|
|
182
|
+
return typeof accessToken === 'function' ? accessToken : async () => accessToken;
|
|
183
|
+
}
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
get headers(): HTTPHeaders | undefined {
|
|
188
|
+
return this.configuration.headers;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
get credentials(): RequestCredentials | undefined {
|
|
192
|
+
return this.configuration.credentials;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type Json = any;
|
|
197
|
+
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
198
|
+
export type HTTPHeaders = { [key: string]: string };
|
|
199
|
+
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | HTTPQuery };
|
|
200
|
+
export type HTTPBody = Json | FormData | URLSearchParams;
|
|
201
|
+
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';
|
|
202
|
+
|
|
203
|
+
export interface FetchParams {
|
|
204
|
+
url: string;
|
|
205
|
+
init: RequestInit;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface RequestOpts {
|
|
209
|
+
path: string;
|
|
210
|
+
method: HTTPMethod;
|
|
211
|
+
headers: HTTPHeaders;
|
|
212
|
+
query?: HTTPQuery;
|
|
213
|
+
body?: HTTPBody;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function exists(json: any, key: string) {
|
|
217
|
+
const value = json[key];
|
|
218
|
+
return value !== null && value !== undefined;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function querystring(params: HTTPQuery, prefix: string = ''): string {
|
|
222
|
+
return Object.keys(params)
|
|
223
|
+
.map((key) => {
|
|
224
|
+
const fullKey = prefix + (prefix.length ? `[${key}]` : key);
|
|
225
|
+
const value = params[key];
|
|
226
|
+
if (value instanceof Array) {
|
|
227
|
+
const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
|
|
228
|
+
.join(`&${encodeURIComponent(fullKey)}=`);
|
|
229
|
+
return `${encodeURIComponent(fullKey)}=${multiValue}`;
|
|
230
|
+
}
|
|
231
|
+
if (value instanceof Date) {
|
|
232
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
|
|
233
|
+
}
|
|
234
|
+
if (value instanceof Object) {
|
|
235
|
+
return querystring(value as HTTPQuery, fullKey);
|
|
236
|
+
}
|
|
237
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
|
238
|
+
})
|
|
239
|
+
.filter(part => part.length > 0)
|
|
240
|
+
.join('&');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function mapValues(data: any, fn: (item: any) => any) {
|
|
244
|
+
return Object.keys(data).reduce(
|
|
245
|
+
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
|
|
246
|
+
{}
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function canConsumeForm(consumes: Consume[]): boolean {
|
|
251
|
+
for (const consume of consumes) {
|
|
252
|
+
if ('multipart/form-data' === consume.contentType) {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export interface Consume {
|
|
260
|
+
contentType: string
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface RequestContext {
|
|
264
|
+
fetch: FetchAPI;
|
|
265
|
+
url: string;
|
|
266
|
+
init: RequestInit;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface ResponseContext {
|
|
270
|
+
fetch: FetchAPI;
|
|
271
|
+
url: string;
|
|
272
|
+
init: RequestInit;
|
|
273
|
+
response: Response;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface Middleware {
|
|
277
|
+
pre?(context: RequestContext): Promise<FetchParams | void>;
|
|
278
|
+
post?(context: ResponseContext): Promise<Response | void>;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface ApiResponse<T> {
|
|
282
|
+
raw: Response;
|
|
283
|
+
value(): Promise<T>;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export interface ResponseTransformer<T> {
|
|
287
|
+
(json: any): T;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export class JSONApiResponse<T> {
|
|
291
|
+
constructor(public raw: Response, private transformer: ResponseTransformer<T> = (jsonValue: any) => jsonValue) {}
|
|
292
|
+
|
|
293
|
+
async value(): Promise<T> {
|
|
294
|
+
return this.transformer(await this.raw.json());
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export class VoidApiResponse {
|
|
299
|
+
constructor(public raw: Response) {}
|
|
300
|
+
|
|
301
|
+
async value(): Promise<void> {
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export class BlobApiResponse {
|
|
307
|
+
constructor(public raw: Response) {}
|
|
308
|
+
|
|
309
|
+
async value(): Promise<Blob> {
|
|
310
|
+
return await this.raw.blob();
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export class TextApiResponse {
|
|
315
|
+
constructor(public raw: Response) {}
|
|
316
|
+
|
|
317
|
+
async value(): Promise<string> {
|
|
318
|
+
return await this.raw.text();
|
|
319
|
+
};
|
|
320
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": true,
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"lib": [
|
|
9
|
+
"es6",
|
|
10
|
+
"dom"
|
|
11
|
+
],
|
|
12
|
+
"typeRoots": [
|
|
13
|
+
"node_modules/@types"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"exclude": [
|
|
17
|
+
"dist",
|
|
18
|
+
"node_modules"
|
|
19
|
+
]
|
|
20
|
+
}
|