@grandlinex/swagger-mate 1.3.3 → 1.3.5

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.
Files changed (33) hide show
  1. package/dist/cjs/Swagger/Client/SwaggerClient.d.ts +0 -3
  2. package/dist/cjs/Swagger/Client/SwaggerClient.js +5 -38
  3. package/dist/cjs/index.d.ts +0 -1
  4. package/dist/cjs/index.js +0 -1
  5. package/dist/mjs/Swagger/Client/SwaggerClient.d.ts +0 -3
  6. package/dist/mjs/Swagger/Client/SwaggerClient.js +5 -38
  7. package/dist/mjs/index.d.ts +0 -1
  8. package/dist/mjs/index.js +0 -1
  9. package/package.json +7 -7
  10. package/res/templates/class/ApiCon.ts +1 -1
  11. package/res/templates/class/CApiCon.ts +1 -1
  12. package/res/templates/class/IApiCon.ts +1 -1
  13. package/res/templates/class/index.ts +2 -3
  14. package/dist/cjs/Swagger/debug/BaseCon.d.ts +0 -172
  15. package/dist/cjs/Swagger/debug/BaseCon.js +0 -380
  16. package/dist/cjs/Swagger/debug/FetchCon.d.ts +0 -3
  17. package/dist/cjs/Swagger/debug/FetchCon.js +0 -79
  18. package/dist/cjs/Swagger/debug/NodeCon.d.ts +0 -3
  19. package/dist/cjs/Swagger/debug/NodeCon.js +0 -158
  20. package/dist/cjs/Swagger/debug/index.d.ts +0 -5
  21. package/dist/cjs/Swagger/debug/index.js +0 -27
  22. package/dist/mjs/Swagger/debug/BaseCon.d.ts +0 -172
  23. package/dist/mjs/Swagger/debug/BaseCon.js +0 -373
  24. package/dist/mjs/Swagger/debug/FetchCon.d.ts +0 -3
  25. package/dist/mjs/Swagger/debug/FetchCon.js +0 -77
  26. package/dist/mjs/Swagger/debug/NodeCon.d.ts +0 -3
  27. package/dist/mjs/Swagger/debug/NodeCon.js +0 -120
  28. package/dist/mjs/Swagger/debug/index.d.ts +0 -5
  29. package/dist/mjs/Swagger/debug/index.js +0 -5
  30. package/res/templates/class/AxiosCon.ts +0 -49
  31. package/res/templates/class/BaseCon.ts +0 -476
  32. package/res/templates/class/FetchCon.ts +0 -93
  33. package/res/templates/class/NodeCon.ts +0 -172
@@ -1,172 +0,0 @@
1
- /**
2
- * THIS FILE IS AUTOMATICALLY GENERATED
3
- * DO NOT EDIT THIS FILE
4
- */
5
- export type ErrorType = {
6
- type: string;
7
- global?: string[];
8
- field?: {
9
- key: string;
10
- message: string;
11
- }[];
12
- };
13
- export type HeaderType = string | string[] | number | undefined;
14
- export type HandleRes<T> = {
15
- success: boolean;
16
- data: T | null;
17
- code?: number;
18
- error?: ErrorType;
19
- headers?: Record<string, HeaderType>;
20
- };
21
- export type PathParam = {
22
- [key: string]: string | number | undefined;
23
- };
24
- export declare function isErrorType(x: any): x is ErrorType;
25
- export interface ConHandleConfig {
26
- headers?: Record<string, string>;
27
- param?: PathParam;
28
- query?: PathParam;
29
- }
30
- export interface ConHandleResponse<T> {
31
- code: number;
32
- data: T | null;
33
- headers: Record<string, HeaderType>;
34
- }
35
- export interface ConHandle {
36
- get<T>(url: string, config?: ConHandleConfig): Promise<ConHandleResponse<T>>;
37
- post<T, J>(url: string, body?: J, config?: ConHandleConfig): Promise<ConHandleResponse<T>>;
38
- patch<T, J>(url: string, body?: J, config?: ConHandleConfig): Promise<ConHandleResponse<T>>;
39
- delete<T>(url: string, config?: ConHandleConfig): Promise<ConHandleResponse<T>>;
40
- }
41
- /**
42
- * BaseCon provides a minimal client for interacting with an HTTP backend.
43
- * It manages connection state, authentication tokens, and reconnection
44
- * logic while delegating actual HTTP requests to a supplied {@link ConHandle}.
45
- *
46
- * @class
47
- */
48
- export default class BaseCon {
49
- private api;
50
- private permanentHeader;
51
- private authorization;
52
- private noAuth;
53
- private disconnected;
54
- private readonly logger;
55
- con: ConHandle;
56
- reconnect: () => Promise<boolean>;
57
- onReconnect: (con: BaseCon) => Promise<boolean>;
58
- constructor(conf: {
59
- con: ConHandle;
60
- endpoint: string;
61
- logger?: (arg: any) => void;
62
- });
63
- /**
64
- * Retrieves the API endpoint.
65
- *
66
- * @return {string} The API endpoint string.
67
- */
68
- getApiEndpoint(): string;
69
- /**
70
- * Sets the API endpoint URL used by the client.
71
- *
72
- * @param {string} endpoint - The full URL of the API endpoint.
73
- * @returns {void}
74
- */
75
- setApiEndpoint(endpoint: string): void;
76
- /**
77
- * Indicates whether the instance is considered connected.
78
- *
79
- * The instance is regarded as connected when it either does not require authentication
80
- * (`noAuth` is true) or it has an authorization token set (`authorization` is not null),
81
- * and it is not currently marked as disconnected.
82
- *
83
- * @return {boolean} `true` if the instance is connected, `false` otherwise.
84
- */
85
- isConnected(): boolean;
86
- /**
87
- * Returns the current authorization token.
88
- *
89
- * @return {string} The authorization token or an empty string if none is set.
90
- */
91
- token(): string;
92
- private p;
93
- /**
94
- * Sends a ping request to the API to verify connectivity and version availability.
95
- *
96
- * @return {boolean} `true` if the API responded with a 200 status code and a valid version object; `false` otherwise.
97
- */
98
- ping(): Promise<boolean>;
99
- /**
100
- * Validates the current authentication token by performing a ping and a test request
101
- * to the backend. The method first ensures connectivity via {@link ping}. If the ping
102
- * succeeds, it attempts to retrieve a token from the `/test/auth` endpoint using the
103
- * current token in the `Authorization` header. The operation is considered successful
104
- * if the response status code is 200 or 201.
105
- *
106
- * If any step fails, an error is logged and the method returns {@code false}. On
107
- * success, it returns {@code true}.
108
- *
109
- * @return {Promise<boolean>} A promise that resolves to {@code true} if the token
110
- * test succeeds, otherwise {@code false}.
111
- */
112
- testToken(): Promise<boolean>;
113
- /**
114
- * Attempts to establish a connection to the backend without authentication.
115
- *
116
- * This method sends a ping request. If the ping succeeds, it clears any
117
- * existing authorization data, marks the instance as connected,
118
- * enables the no‑authentication mode, and returns `true`. If the ping
119
- * fails, it logs a warning, clears authorization, marks the instance
120
- * as disconnected, and returns `false`.
121
- *
122
- * @return {Promise<boolean>} `true` when a connection is successfully
123
- * established without authentication, otherwise `false`.
124
- */
125
- connectNoAuth(): Promise<boolean>;
126
- /**
127
- * Forces a connection using the provided bearer token.
128
- *
129
- * @param {string} token The token to be used for authentication.
130
- * @returns {void}
131
- */
132
- forceConnectWithToken(token: string): void;
133
- /**
134
- * Establishes a connection to the backend using the supplied credentials.
135
- * Performs a health‑check ping first; if successful, it requests an authentication
136
- * token from the `/token` endpoint. When the token is obtained, the method
137
- * updates internal state (authorization header, connection flags) and, unless
138
- * a dry run is requested, sets up a reconnection routine. Any errors are
139
- * logged and the method resolves to `false`.
140
- *
141
- * @param {string} email - The user's email address for authentication.
142
- * @param {string} pw - The password (or token) for the specified user.
143
- * @param {boolean} [dry=false] - If `true`, the method performs a dry run
144
- * without persisting credentials or configuring reconnection logic.
145
- *
146
- * @returns Promise<boolean> `true` if the connection was successfully
147
- * established, otherwise `false`.
148
- */
149
- connect(email: string, pw: string, dry?: boolean): Promise<boolean>;
150
- /**
151
- * Performs an HTTP request using the client’s internal connection.
152
- *
153
- * The method verifies that the client is connected before attempting a request.
154
- * It automatically injects the authorization token, permanent headers, and any
155
- * headers supplied in `config`. If the request body is a `FormData` instance
156
- * (or provides a `getHeaders` method), the appropriate form headers are added.
157
- *
158
- * Response handling:
159
- * - `200` or `201`: returns `success: true` with the received data.
160
- * - `498`: attempts to reconnect and retries the request once.
161
- * - `401`: logs an authentication error, marks the client as disconnected.
162
- * - `403` and other status codes: return `success: false` with the status code.
163
- *
164
- * @param {'POST'|'GET'|'PATCH'|'DELETE'} type The HTTP method to use.
165
- * @param {string} path The endpoint path relative to the base URL.
166
- * @param {J} [body] Optional request payload. May be `FormData` or a plain object.
167
- * @param {ConHandleConfig} [config] Optional Axios-like configuration for the request.
168
- * @returns {Promise<HandleRes<T>>} A promise that resolves to a `HandleRes` object
169
- * containing the response data, status code, any error information, and headers.
170
- */
171
- handle<T, J>(type: 'POST' | 'GET' | 'PATCH' | 'DELETE', path: string, body?: J, config?: ConHandleConfig): Promise<HandleRes<T>>;
172
- }
@@ -1,373 +0,0 @@
1
- /**
2
- * THIS FILE IS AUTOMATICALLY GENERATED
3
- * DO NOT EDIT THIS FILE
4
- */
5
- import FormData from 'form-data';
6
- export function isErrorType(x) {
7
- return x && typeof x === 'object' && x.type === 'error';
8
- }
9
- /**
10
- * BaseCon provides a minimal client for interacting with an HTTP backend.
11
- * It manages connection state, authentication tokens, and reconnection
12
- * logic while delegating actual HTTP requests to a supplied {@link ConHandle}.
13
- *
14
- * @class
15
- */
16
- export default class BaseCon {
17
- constructor(conf) {
18
- this.api = conf.endpoint;
19
- this.logger = conf.logger ?? console.log;
20
- this.disconnected = true;
21
- this.noAuth = false;
22
- this.authorization = null;
23
- this.con = conf.con;
24
- this.reconnect = async () => {
25
- this.disconnected = true;
26
- return false;
27
- };
28
- this.onReconnect = () => Promise.resolve(true);
29
- this.handle = this.handle.bind(this);
30
- }
31
- /**
32
- * Retrieves the API endpoint.
33
- *
34
- * @return {string} The API endpoint string.
35
- */
36
- getApiEndpoint() {
37
- return this.api;
38
- }
39
- /**
40
- * Sets the API endpoint URL used by the client.
41
- *
42
- * @param {string} endpoint - The full URL of the API endpoint.
43
- * @returns {void}
44
- */
45
- setApiEndpoint(endpoint) {
46
- this.api = endpoint;
47
- }
48
- /**
49
- * Indicates whether the instance is considered connected.
50
- *
51
- * The instance is regarded as connected when it either does not require authentication
52
- * (`noAuth` is true) or it has an authorization token set (`authorization` is not null),
53
- * and it is not currently marked as disconnected.
54
- *
55
- * @return {boolean} `true` if the instance is connected, `false` otherwise.
56
- */
57
- isConnected() {
58
- return (this.noAuth || this.authorization !== null) && !this.disconnected;
59
- }
60
- /**
61
- * Returns the current authorization token.
62
- *
63
- * @return {string} The authorization token or an empty string if none is set.
64
- */
65
- token() {
66
- return this.authorization || '';
67
- }
68
- p(path, config) {
69
- let pp = path;
70
- if (config?.param) {
71
- const e = Object.keys(config.param);
72
- for (const d of e) {
73
- pp = pp.replace(`{${d}}`, `${config.param[d]}`);
74
- }
75
- }
76
- if (config?.query) {
77
- const e = Object.keys(config.query);
78
- const slices = [];
79
- for (const d of e) {
80
- if (config.query[d]) {
81
- slices.push(`${d}=${config.query[d]}`);
82
- }
83
- }
84
- if (slices.length > 0) {
85
- pp += `?${slices.join('&')}`;
86
- }
87
- }
88
- return `${this.api}${pp}`;
89
- }
90
- /**
91
- * Sends a ping request to the API to verify connectivity and version availability.
92
- *
93
- * @return {boolean} `true` if the API responded with a 200 status code and a valid version object; `false` otherwise.
94
- */
95
- async ping() {
96
- try {
97
- const version = await this.con.get(this.p('/version'));
98
- return version.data?.api !== undefined && version.code === 200;
99
- }
100
- catch (e) {
101
- this.logger('ping failed');
102
- return false;
103
- }
104
- }
105
- /**
106
- * Validates the current authentication token by performing a ping and a test request
107
- * to the backend. The method first ensures connectivity via {@link ping}. If the ping
108
- * succeeds, it attempts to retrieve a token from the `/test/auth` endpoint using the
109
- * current token in the `Authorization` header. The operation is considered successful
110
- * if the response status code is 200 or 201.
111
- *
112
- * If any step fails, an error is logged and the method returns {@code false}. On
113
- * success, it returns {@code true}.
114
- *
115
- * @return {Promise<boolean>} A promise that resolves to {@code true} if the token
116
- * test succeeds, otherwise {@code false}.
117
- */
118
- async testToken() {
119
- const ping = await this.ping();
120
- if (ping) {
121
- try {
122
- const con = await this.con.get(this.p('/test/auth'), {
123
- headers: {
124
- Authorization: this.token(),
125
- },
126
- });
127
- return con.code === 200 || con.code === 201;
128
- }
129
- catch (e) {
130
- this.logger(e);
131
- this.logger('cant connect to backend');
132
- }
133
- }
134
- this.logger('test ping failed');
135
- return false;
136
- }
137
- /**
138
- * Attempts to establish a connection to the backend without authentication.
139
- *
140
- * This method sends a ping request. If the ping succeeds, it clears any
141
- * existing authorization data, marks the instance as connected,
142
- * enables the no‑authentication mode, and returns `true`. If the ping
143
- * fails, it logs a warning, clears authorization, marks the instance
144
- * as disconnected, and returns `false`.
145
- *
146
- * @return {Promise<boolean>} `true` when a connection is successfully
147
- * established without authentication, otherwise `false`.
148
- */
149
- async connectNoAuth() {
150
- const ping = await this.ping();
151
- if (ping) {
152
- this.authorization = null;
153
- this.disconnected = false;
154
- this.noAuth = true;
155
- return true;
156
- }
157
- this.logger('cant connect to backend');
158
- this.authorization = null;
159
- this.disconnected = true;
160
- return false;
161
- }
162
- /**
163
- * Forces a connection using the provided bearer token.
164
- *
165
- * @param {string} token The token to be used for authentication.
166
- * @returns {void}
167
- */
168
- forceConnectWithToken(token) {
169
- this.authorization = `Bearer ${token}`;
170
- this.disconnected = false;
171
- this.noAuth = false;
172
- }
173
- /**
174
- * Establishes a connection to the backend using the supplied credentials.
175
- * Performs a health‑check ping first; if successful, it requests an authentication
176
- * token from the `/token` endpoint. When the token is obtained, the method
177
- * updates internal state (authorization header, connection flags) and, unless
178
- * a dry run is requested, sets up a reconnection routine. Any errors are
179
- * logged and the method resolves to `false`.
180
- *
181
- * @param {string} email - The user's email address for authentication.
182
- * @param {string} pw - The password (or token) for the specified user.
183
- * @param {boolean} [dry=false] - If `true`, the method performs a dry run
184
- * without persisting credentials or configuring reconnection logic.
185
- *
186
- * @returns Promise<boolean> `true` if the connection was successfully
187
- * established, otherwise `false`.
188
- */
189
- async connect(email, pw, dry = false) {
190
- const ping = await this.ping();
191
- if (ping) {
192
- try {
193
- const token = await this.con.post(this.p('/token'), {
194
- username: email,
195
- token: pw,
196
- });
197
- if (token.code === 200 || token.code === 201) {
198
- if (!dry) {
199
- this.authorization = `Bearer ${token.data?.token}`;
200
- this.disconnected = false;
201
- this.noAuth = false;
202
- this.reconnect = async () => {
203
- return ((await this.connect(email, pw)) && (await this.testToken()));
204
- };
205
- }
206
- return true;
207
- }
208
- }
209
- catch (e) {
210
- this.logger(e);
211
- }
212
- }
213
- this.logger('cant connect to backend');
214
- this.authorization = null;
215
- this.disconnected = true;
216
- this.noAuth = false;
217
- return false;
218
- }
219
- /**
220
- * Performs an HTTP request using the client’s internal connection.
221
- *
222
- * The method verifies that the client is connected before attempting a request.
223
- * It automatically injects the authorization token, permanent headers, and any
224
- * headers supplied in `config`. If the request body is a `FormData` instance
225
- * (or provides a `getHeaders` method), the appropriate form headers are added.
226
- *
227
- * Response handling:
228
- * - `200` or `201`: returns `success: true` with the received data.
229
- * - `498`: attempts to reconnect and retries the request once.
230
- * - `401`: logs an authentication error, marks the client as disconnected.
231
- * - `403` and other status codes: return `success: false` with the status code.
232
- *
233
- * @param {'POST'|'GET'|'PATCH'|'DELETE'} type The HTTP method to use.
234
- * @param {string} path The endpoint path relative to the base URL.
235
- * @param {J} [body] Optional request payload. May be `FormData` or a plain object.
236
- * @param {ConHandleConfig} [config] Optional Axios-like configuration for the request.
237
- * @returns {Promise<HandleRes<T>>} A promise that resolves to a `HandleRes` object
238
- * containing the response data, status code, any error information, and headers.
239
- */
240
- async handle(type, path, body, config) {
241
- if (!this.isConnected()) {
242
- this.logger('Disconnected');
243
- return {
244
- success: false,
245
- data: null,
246
- code: -1,
247
- };
248
- }
249
- let formHeader = null;
250
- const cK = body;
251
- if (cK &&
252
- (cK instanceof FormData || typeof cK?.getHeaders === 'function')) {
253
- formHeader = cK?.getHeaders?.() || {};
254
- }
255
- else {
256
- formHeader = {};
257
- }
258
- let dat;
259
- switch (type) {
260
- case 'GET':
261
- dat = await this.con.get(this.p(path, config), {
262
- ...config,
263
- headers: {
264
- Authorization: this.token(),
265
- ...formHeader,
266
- ...config?.headers,
267
- ...this.permanentHeader,
268
- },
269
- });
270
- break;
271
- case 'POST':
272
- dat = await this.con.post(this.p(path, config), body, {
273
- ...config,
274
- headers: {
275
- Authorization: this.token(),
276
- ...formHeader,
277
- ...config?.headers,
278
- ...this.permanentHeader,
279
- },
280
- });
281
- break;
282
- case 'PATCH':
283
- dat = await this.con.patch(this.p(path, config), body, {
284
- ...config,
285
- headers: {
286
- Authorization: this.token(),
287
- ...formHeader,
288
- ...config?.headers,
289
- ...this.permanentHeader,
290
- },
291
- });
292
- break;
293
- case 'DELETE':
294
- dat = await this.con.delete(this.p(path, config), {
295
- ...config,
296
- headers: {
297
- Authorization: this.token(),
298
- ...formHeader,
299
- ...config?.headers,
300
- ...this.permanentHeader,
301
- },
302
- });
303
- break;
304
- default:
305
- return {
306
- success: false,
307
- data: null,
308
- code: -1,
309
- };
310
- }
311
- let error;
312
- if (isErrorType(dat.data)) {
313
- error = dat.data;
314
- }
315
- let x = false;
316
- switch (dat.code) {
317
- case 200:
318
- case 201:
319
- return {
320
- success: true,
321
- data: dat.data,
322
- code: dat.code,
323
- error,
324
- headers: dat.headers,
325
- };
326
- case 498:
327
- x = await this.reconnect();
328
- if (x) {
329
- this.onReconnect(this).catch((dx) => {
330
- this.logger(dx);
331
- });
332
- return this.handle(type, path, body, config);
333
- }
334
- this.reconnect = async () => {
335
- this.disconnected = true;
336
- return false;
337
- };
338
- this.disconnected = true;
339
- return {
340
- success: false,
341
- data: null,
342
- code: dat.code,
343
- error,
344
- headers: dat.headers,
345
- };
346
- case 401:
347
- this.logger('AUTH NOT VALID');
348
- return {
349
- success: false,
350
- data: null,
351
- code: dat.code,
352
- error,
353
- headers: dat.headers,
354
- };
355
- case 403:
356
- return {
357
- success: false,
358
- data: null,
359
- error,
360
- code: dat.code,
361
- headers: dat.headers,
362
- };
363
- default:
364
- return {
365
- success: false,
366
- data: null,
367
- error,
368
- code: dat.code,
369
- headers: dat.headers,
370
- };
371
- }
372
- }
373
- }
@@ -1,3 +0,0 @@
1
- import { ConHandle } from './BaseCon.js';
2
- declare const FetchCon: ConHandle;
3
- export default FetchCon;
@@ -1,77 +0,0 @@
1
- async function fcTransform(r) {
2
- const res = await r;
3
- const head = {};
4
- res.headers.forEach((val, key) => {
5
- head[key] = val;
6
- });
7
- let data = null;
8
- if (head['content-type']?.includes('application/json')) {
9
- data = await res.json();
10
- }
11
- else if (head['content-type']?.includes('form-data')) {
12
- data = await res.formData();
13
- }
14
- else if (head['content-type']?.includes('octet-stream')) {
15
- data = await res.arrayBuffer();
16
- }
17
- else if (head['content-type']?.includes('text/plain')) {
18
- data = await res.text();
19
- }
20
- return {
21
- code: res.status,
22
- data,
23
- headers: head,
24
- };
25
- }
26
- function bodyTransform(r, headers) {
27
- if (!r) {
28
- return {
29
- headers,
30
- };
31
- }
32
- if (r instanceof FormData) {
33
- return {
34
- body: r,
35
- headers: {
36
- ...headers,
37
- },
38
- };
39
- }
40
- return {
41
- body: JSON.stringify(r),
42
- headers: {
43
- ...headers,
44
- 'content-type': 'application/json',
45
- },
46
- };
47
- }
48
- const FetchCon = {
49
- get: async (url, config) => {
50
- return fcTransform(fetch(url, {
51
- method: 'GET',
52
- headers: {
53
- accept: 'application/json, text/plain, */*',
54
- ...config?.headers,
55
- },
56
- }));
57
- },
58
- post: async (url, body, config) => {
59
- return fcTransform(fetch(url, {
60
- method: 'POST',
61
- ...bodyTransform(body, config?.headers),
62
- }));
63
- },
64
- patch: async (url, body, config) => {
65
- return fcTransform(fetch(url, {
66
- method: 'PATCH',
67
- ...bodyTransform(body, config?.headers),
68
- }));
69
- },
70
- delete: async (url, config) => {
71
- return fcTransform(fetch(url, {
72
- method: 'DELETE',
73
- headers: config?.headers,
74
- }));
75
- },
76
- };
77
- export default FetchCon;
@@ -1,3 +0,0 @@
1
- import { ConHandle } from './BaseCon.js';
2
- declare const NodeCon: ConHandle;
3
- export default NodeCon;