@grandlinex/swagger-mate 1.2.2 → 1.3.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.
Files changed (37) hide show
  1. package/dist/cjs/Swagger/Client/ClientUtil.d.ts +18 -4
  2. package/dist/cjs/Swagger/Client/ClientUtil.js +51 -8
  3. package/dist/cjs/Swagger/Client/InterfaceTemplate.js +1 -1
  4. package/dist/cjs/Swagger/Client/SwaggerClient.js +5 -5
  5. package/dist/cjs/Swagger/Meta/SwaggerTypes.d.ts +1 -0
  6. package/dist/cjs/Swagger/Path/SPathUtil.d.ts +173 -2
  7. package/dist/cjs/Swagger/Path/SPathUtil.js +261 -5
  8. package/dist/cjs/Swagger/SwaggerUtil.d.ts +18 -2
  9. package/dist/cjs/Swagger/SwaggerUtil.js +32 -5
  10. package/dist/cjs/Swagger/annotation/index.d.ts +8 -3
  11. package/dist/cjs/Swagger/debug/BaseCon.d.ts +115 -11
  12. package/dist/cjs/Swagger/debug/BaseCon.js +142 -38
  13. package/dist/cjs/cli.js +5 -1
  14. package/dist/mjs/Swagger/Client/ClientUtil.d.ts +18 -4
  15. package/dist/mjs/Swagger/Client/ClientUtil.js +50 -8
  16. package/dist/mjs/Swagger/Client/InterfaceTemplate.js +2 -2
  17. package/dist/mjs/Swagger/Client/SwaggerClient.js +5 -5
  18. package/dist/mjs/Swagger/Meta/SwaggerTypes.d.ts +1 -0
  19. package/dist/mjs/Swagger/Path/SPathUtil.d.ts +173 -2
  20. package/dist/mjs/Swagger/Path/SPathUtil.js +261 -5
  21. package/dist/mjs/Swagger/SwaggerUtil.d.ts +18 -2
  22. package/dist/mjs/Swagger/SwaggerUtil.js +33 -6
  23. package/dist/mjs/Swagger/annotation/index.d.ts +8 -3
  24. package/dist/mjs/Swagger/debug/BaseCon.d.ts +115 -11
  25. package/dist/mjs/Swagger/debug/BaseCon.js +142 -38
  26. package/dist/mjs/cli.js +5 -1
  27. package/package.json +10 -8
  28. package/res/html/rapi-doc/index.html +28 -0
  29. package/res/html/rapi-doc/rapidoc-min.js +3915 -0
  30. package/res/html/{index.html → swagger-ui/index.html} +11 -3
  31. package/res/html/swagger-ui/swagger-ui-bundle.js +2 -0
  32. package/res/html/swagger-ui/swagger-ui-standalone-preset.js +2 -0
  33. package/res/html/swagger-ui/swagger-ui.css +3 -0
  34. package/res/templates/class/BaseCon.ts +160 -61
  35. package/res/html/swagger-ui-bundle.js +0 -2
  36. package/res/html/swagger-ui-standalone-preset.js +0 -2
  37. package/res/html/swagger-ui.css +0 -3
@@ -5,9 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const core_1 = require("@grandlinex/core");
7
7
  const SUtilMap_js_1 = __importDefault(require("./SUtilMap.js"));
8
+ const SwaggerTypes_js_1 = require("../Meta/SwaggerTypes.js");
8
9
  function resolveDBType(dType) {
9
10
  switch (dType) {
10
11
  case 'int':
12
+ case 'long':
11
13
  return 'integer';
12
14
  case 'double':
13
15
  case 'float':
@@ -29,6 +31,11 @@ function resolveDBType(dType) {
29
31
  }
30
32
  }
31
33
  class SPathUtil {
34
+ /**
35
+ * Generates a default response mapping for the specified HTTP status types.
36
+ *
37
+ * @param {HttpStatusTypes[]} types - The HTTP status types for which default responses should be created.
38
+ * @return {SwaggerRPathConfResponse} An object mapping each provided status type to its default response definition. */
32
39
  static defaultResponse(...types) {
33
40
  const res = {};
34
41
  types.forEach((el) => {
@@ -36,6 +43,12 @@ class SPathUtil {
36
43
  });
37
44
  return res;
38
45
  }
46
+ /**
47
+ * Creates a request body definition for JSON content type using the provided schema.
48
+ *
49
+ * @param {SSchemaEl} schema - The JSON schema used for validating the request body.
50
+ * @return {SwaggerRPathReqBody} A Swagger path request body object specifying application/json content type with the provided schema.
51
+ */
39
52
  static jsonBody(schema) {
40
53
  return {
41
54
  content: {
@@ -45,6 +58,13 @@ class SPathUtil {
45
58
  },
46
59
  };
47
60
  }
61
+ /**
62
+ * Builds a Swagger request body for `multipart/form-data` requests.
63
+ *
64
+ * @param {SSchemaEl} [schema] Optional schema describing the form data.
65
+ * If omitted, a default schema with a single binary `file` field is provided.
66
+ * @return {SwaggerRPathReqBody} Swagger request body definition with
67
+ * `multipart/form-data` content and the supplied or default schema. */
48
68
  static formBody(schema) {
49
69
  return {
50
70
  content: {
@@ -63,6 +83,14 @@ class SPathUtil {
63
83
  },
64
84
  };
65
85
  }
86
+ /**
87
+ * Generates a Swagger content definition for the provided entity.
88
+ *
89
+ * @param {T} entity - The entity instance to derive the Swagger schema from.
90
+ * @param {boolean} [list] - When true, the schema will be wrapped in an array type, representing a list of entities.
91
+ *
92
+ * @returns {SwaggerContent|undefined} The Swagger content object for the entity, or `undefined` if the entity does not have a schema.
93
+ */
66
94
  static entityContent(entity, list) {
67
95
  const schema = this.schemaFromEntity(entity);
68
96
  if (!schema) {
@@ -84,6 +112,13 @@ class SPathUtil {
84
112
  },
85
113
  };
86
114
  }
115
+ /**
116
+ * @template T extends CoreEntity
117
+ * @param {T} entity - The entity instance for which to build the response configuration.
118
+ * @param {boolean} [list] - Indicates whether the response should represent a list of entities.
119
+ * @param {boolean} [create] - Indicates whether the response corresponds to a creation operation (status code 201); otherwise 200.
120
+ * @returns {SwaggerRPathConfResponse} The Swagger response configuration object containing the appropriate status code and content.
121
+ */
87
122
  static entityResponse(entity, list, create) {
88
123
  const code = create ? '201' : '200';
89
124
  const an = {};
@@ -93,9 +128,58 @@ class SPathUtil {
93
128
  };
94
129
  return an;
95
130
  }
131
+ /**
132
+ * Builds a JSON schema reference path for the given component name.
133
+ *
134
+ * @param {string} inp - The name of the schema component.
135
+ * @return {string} The JSON reference path formatted as `#/components/schemas/<inp>`.
136
+ */
96
137
  static schemaPath(inp) {
97
138
  return `#/components/schemas/${inp}`;
98
139
  }
140
+ /**
141
+ * Creates a Swagger request body definition that references a schema.
142
+ *
143
+ * @param {string | CoreEntity} $ref
144
+ * Either the string reference to a schema or a `CoreEntity` instance whose
145
+ * class name will be used to build the reference path.
146
+ * @param {boolean} list
147
+ * If true, the referenced schema is wrapped in an array; otherwise the
148
+ * schema is used directly.
149
+ * @returns {SwaggerRPathReqBody}
150
+ * The request body object containing the appropriate content and schema
151
+ * configuration.
152
+ */
153
+ static refRequest($ref, list) {
154
+ const t = typeof $ref === 'string'
155
+ ? { $ref }
156
+ : {
157
+ $ref: this.schemaPath(core_1.XUtil.getEntityNames($ref).className),
158
+ };
159
+ if (list) {
160
+ return {
161
+ content: {
162
+ 'application/json': {
163
+ schema: {
164
+ type: 'array',
165
+ items: t,
166
+ },
167
+ },
168
+ },
169
+ };
170
+ }
171
+ return {
172
+ content: {
173
+ 'application/json': {
174
+ schema: t,
175
+ },
176
+ },
177
+ };
178
+ }
179
+ /**
180
+ * Creates a Swagger response configuration for a given HTTP status code.
181
+ *
182
+ * @param {HttpStatusTypes} code - The primary HTTP status code for */
99
183
  static refResponse(code, $ref, list, ...addCodes) {
100
184
  const an = {
101
185
  ...this.defaultResponse(...addCodes),
@@ -130,6 +214,15 @@ class SPathUtil {
130
214
  }
131
215
  return an;
132
216
  }
217
+ /**
218
+ * Builds a Swagger response configuration object for a given HTTP status code and schema.
219
+ *
220
+ * @param {HttpStatusTypes} code - The primary HTTP status code for the response.
221
+ * @param {SSchemaEl} schema - The JSON schema definition for the response body.
222
+ * @param {boolean} list - If true, the schema is wrapped in an array for list responses.
223
+ * @param {...HttpStatusTypes} addCodes - Additional HTTP status codes for default responses.
224
+ * @return {SwaggerRPathConfResponse} The constructed response configuration object.
225
+ */
133
226
  static jsonResponse(code, schema, list, ...addCodes) {
134
227
  const an = {
135
228
  ...this.defaultResponse(...addCodes),
@@ -159,6 +252,23 @@ class SPathUtil {
159
252
  }
160
253
  return an;
161
254
  }
255
+ /**
256
+ * Generates a JSON schema representation from a CoreEntity instance.
257
+ *
258
+ * This method inspects the entity's metadata to construct a schema object
259
+ * describing the entity's shape. The resulting schema contains:
260
+ * - `type`: always `"object"`.
261
+ * - `description`: a string indicating the entity name.
262
+ * - `required`: an array of property names that are defined on the entity.
263
+ * - `properties`: an object mapping each property name to an object that
264
+ * includes the resolved database type and its nullability.
265
+ *
266
+ * If no metadata is found for the provided entity, the method returns `undefined`.
267
+ *
268
+ * @param {T} entity - The entity instance for which to create a schema.
269
+ * @returns {SSchemaEl | undefined} The generated schema object, or `undefined`
270
+ * if the entity's metadata could not be retrieved.
271
+ */
162
272
  static schemaFromEntity(entity) {
163
273
  const schema = {
164
274
  type: 'object',
@@ -174,16 +284,21 @@ class SPathUtil {
174
284
  keys.forEach((k) => {
175
285
  const cMeta = (0, core_1.getColumnMeta)(entity, k);
176
286
  if (cMeta && schema.properties) {
177
- if (!cMeta.canBeNull) {
178
- schema.required?.push(k);
179
- }
287
+ schema.required.push(k);
180
288
  schema.properties[k] = {
181
289
  type: resolveDBType(cMeta.dataType),
290
+ nullable: cMeta.canBeNull,
182
291
  };
183
292
  }
184
293
  });
185
294
  return schema;
186
295
  }
296
+ /**
297
+ * Generates a content schema object for the given entity. The schema contains a description derived from the entity metadata and a JSON content schema based on the entity's structure.
298
+ *
299
+ * @param {T} entity - The entity instance for which to generate the content schema. The generic type `T` must extend {@link CoreEntity}.
300
+ * @returns {{ description: string; content: { 'application/json': { schema: SSchemaEl } }; } | undefined} An object containing the content schema, or `undefined` if no metadata is available for the entity.
301
+ */
187
302
  static contentSchemaFromEntity(entity) {
188
303
  const meta = (0, core_1.getEntityMeta)(entity);
189
304
  if (!meta) {
@@ -199,8 +314,10 @@ class SPathUtil {
199
314
  };
200
315
  }
201
316
  /**
202
- * generate global schema
203
- * @param e
317
+ * Generates a mapping from entity names to their corresponding schema objects.
318
+ *
319
+ * @param {CoreEntity[]} e The entities for which schema entries should be generated.
320
+ * @return {SKey<SSchemaEl>} An object whose keys are entity names and values are the schemas derived from those entities.
204
321
  */
205
322
  static schemaEntryGen(...e) {
206
323
  const out = {};
@@ -212,6 +329,14 @@ class SPathUtil {
212
329
  });
213
330
  return out;
214
331
  }
332
+ /**
333
+ * Builds a JSON schema representation for an entity view that includes both the
334
+ * entity data and its related entity map.
335
+ *
336
+ * @param entity The primary entity used to construct the `dat` portion of the schema.
337
+ * @param entityMap The related entity map used to construct the `join_map` portion of the schema.
338
+ * @returns A {@link SSchemaEl} object schema with properties `i`, `dat`, and `join_map`.
339
+ */
215
340
  static schemaFromEntityView(entity, entityMap) {
216
341
  return {
217
342
  type: 'object',
@@ -224,5 +349,136 @@ class SPathUtil {
224
349
  },
225
350
  };
226
351
  }
352
+ /**
353
+ * Extends an entity schema object by merging additional schema options.
354
+ *
355
+ * @param {CoreEntity} entity
356
+ * The entity for which the schema should be extended.
357
+ *
358
+ * @param {...Object} options
359
+ * One or more objects defining schema extensions. Each object may contain:
360
+ * - `key` (string): The property key to add or extend.
361
+ * - `list` (boolean, optional): Indicates whether the property is a list.
362
+ * - `entity` (CoreEntity, optional): The entity type for the property.
363
+ * - `schema` (SSchemaEl, optional): A custom schema definition for the property.
364
+ * - `required` (boolean, optional): Whether the property is required.
365
+ *
366
+ * @return {SSchemaEl}
367
+ * The resulting schema element. If a single property is returned by
368
+ * `extendEntitySchema`, its schema is returned directly; otherwise an
369
+ * object schema with a type of `'object'` is returned.
370
+ */
371
+ static extendEntitySchemaObject(entity, ...options) {
372
+ const schema = this.extendEntitySchema(entity, ...options);
373
+ const ent = Object.entries(schema);
374
+ if (ent.length === 1) {
375
+ return ent[0][1];
376
+ }
377
+ return {
378
+ type: 'object',
379
+ };
380
+ }
381
+ /**
382
+ * Extends the schema of a given {@link CoreEntity} with additional properties.
383
+ *
384
+ * @param {CoreEntity} entity
385
+ * The entity whose schema will be extended.
386
+ *
387
+ * @param {...{
388
+ * key: string,
389
+ * list?: boolean,
390
+ * entity?: CoreEntity,
391
+ * schema?: SSchemaEl,
392
+ * required?: boolean
393
+ * }} options
394
+ * One or more option objects specifying the extensions to apply. Each option
395
+ * may provide either a direct schema (`schema`) or an entity reference
396
+ * (`entity`). The `list` flag indicates whether the property should be
397
+ * represented as an array of the provided schema. The `required` flag
398
+ * adds the property to the schema’s required list.
399
+ *
400
+ * @returns {SKey<SSchemaEl>}
401
+ * An object containing the updated schema for the entity, keyed by the
402
+ * entity’s name. If the entity metadata cannot be found, an empty
403
+ * object is returned.
404
+ */
405
+ static extendEntitySchema(entity, ...options) {
406
+ const meta = (0, core_1.getEntityMeta)(entity);
407
+ if (meta) {
408
+ const schema = SPathUtil.schemaEntryGen(entity)[meta.name];
409
+ if (schema && !(0, SwaggerTypes_js_1.isSwaggerRef)(schema) && schema.properties) {
410
+ for (const option of options) {
411
+ if (option.schema) {
412
+ if (option.list) {
413
+ schema.properties[option.key] = {
414
+ type: 'array',
415
+ items: option.schema,
416
+ };
417
+ }
418
+ else {
419
+ schema.properties[option.key] = option.schema;
420
+ }
421
+ }
422
+ else if (option.entity) {
423
+ const eMeta = (0, core_1.getEntityMeta)(option.entity);
424
+ if (eMeta) {
425
+ const scheme = SPathUtil.schemaEntryGen(option.entity)[eMeta.name];
426
+ if (option.list) {
427
+ schema.properties[option.key] = {
428
+ type: 'array',
429
+ items: scheme,
430
+ };
431
+ }
432
+ else {
433
+ schema.properties[option.key] = scheme;
434
+ }
435
+ }
436
+ }
437
+ if (option.required) {
438
+ schema.required = [...(schema.required || []), option.key];
439
+ }
440
+ }
441
+ }
442
+ return {
443
+ [meta.name]: schema,
444
+ };
445
+ }
446
+ return {};
447
+ }
448
+ /**
449
+ * Reduces the entity schema to a single schema element or a generic object.
450
+ *
451
+ * @param entity The entity whose schema should be reduced.
452
+ * @param keys Optional list of keys to include in the reduced schema. If omitted, all keys are considered.
453
+ * @return Returns the schema element of the sole key if only one key is present; otherwise, returns a generic object schema with type `'object'`. */
454
+ static reduceEntitySchemaObject(entity, ...keys) {
455
+ const schema = this.reduceEntitySchema(entity, ...keys);
456
+ const ent = Object.entries(schema);
457
+ if (ent.length === 1) {
458
+ return ent[0][1];
459
+ }
460
+ return {
461
+ type: 'object',
462
+ };
463
+ }
464
+ /**
465
+ * Creates a reduced version of an entity's schema by excluding specified properties.
466
+ *
467
+ * @param {CoreEntity} entity - The entity whose schema is to be processed.
468
+ * @param {...string} keys - Property names to remove from the schema's `properties` and `required` lists.
469
+ *
470
+ * @returns */
471
+ static reduceEntitySchema(entity, ...keys) {
472
+ const meta = (0, core_1.getEntityMeta)(entity);
473
+ if (meta) {
474
+ const schema = SPathUtil.schemaEntryGen(entity)[meta.name];
475
+ if (schema && !(0, SwaggerTypes_js_1.isSwaggerRef)(schema) && schema.properties) {
476
+ schema.properties = Object.fromEntries(Object.entries(schema.properties).filter(([e]) => !keys.includes(e)));
477
+ schema.required = (schema.required || []).filter((e) => !keys.includes(e));
478
+ }
479
+ return { [meta.name]: schema };
480
+ }
481
+ return {};
482
+ }
227
483
  }
228
484
  exports.default = SPathUtil;
@@ -1,11 +1,27 @@
1
- import { ObjectLike } from '@grandlinex/core';
1
+ import { CoreLogChannel, ObjectLike } from '@grandlinex/core';
2
2
  import { Server } from 'net';
3
3
  import { MergeInputType, SwaggerConfig, SwaggerRPath } from './Meta/SwaggerTypes.js';
4
4
  import { RouteData } from './annotation/index.js';
5
5
  export default class SwaggerUtil {
6
+ static logger: CoreLogChannel | null;
7
+ static getLogger(): CoreLogChannel;
6
8
  static writeMeta(conf: SwaggerConfig, kind: 'JSON' | 'YAML', path?: string): void;
7
9
  static readMeta(path: string): any;
8
- static serveMeta(conf: SwaggerConfig, port?: number, auth?: string): Promise<Server | null>;
10
+ /**
11
+ * Serves a meta page for Swagger UI or rapi-doc.
12
+ *
13
+ * @param {SwaggerConfig} conf The swagger configuration to expose via `/spec`.
14
+ * @param {Object} [option] Options for serving the meta page.
15
+ * @param {'swagger-ui'|'rapi-doc'} [option.type='swagger-ui'] The type of UI to serve.
16
+ * @param {number} [option.port] The port to listen on. Defaults to 9000.
17
+ * @param {string} [option.auth] Optional authentication key appended to the URL.
18
+ * @returns {Promise<Server|null>} A promise that resolves with the created server instance or null.
19
+ */
20
+ static serveMeta(conf: SwaggerConfig, option?: {
21
+ type?: 'swagger-ui' | 'rapi-doc';
22
+ port?: number;
23
+ auth?: string;
24
+ }): Promise<Server | null>;
9
25
  static metaExtractor(root: ObjectLike, npmPackageVersion: boolean, ...path: ObjectLike[]): SwaggerConfig | undefined;
10
26
  static routeToSwaggerPath(route: RouteData): SwaggerRPath;
11
27
  static merge(root: SwaggerConfig, data: MergeInputType[]): SwaggerConfig;
@@ -47,6 +47,13 @@ const PathHelp_js_1 = __importStar(require("../PathHelp.js"));
47
47
  const index_js_1 = require("./annotation/index.js");
48
48
  const index_js_2 = require("../index.js");
49
49
  class SwaggerUtil {
50
+ static getLogger() {
51
+ if (!this.logger) {
52
+ const logger = new core_1.DefaultLogger();
53
+ this.logger = new core_1.CoreLogChannel('SwaggerUtil', logger);
54
+ }
55
+ return this.logger;
56
+ }
50
57
  static writeMeta(conf, kind, path) {
51
58
  if (kind === 'JSON') {
52
59
  const p = Path.join(path || process.cwd(), 'openapi.json');
@@ -63,11 +70,25 @@ class SwaggerUtil {
63
70
  return JSON.parse(file);
64
71
  }
65
72
  catch (e) {
73
+ this.getLogger().error(e);
66
74
  return null;
67
75
  }
68
76
  }
69
- static async serveMeta(conf, port, auth) {
70
- const resFiles = (0, PathHelp_js_1.default)((0, PathHelp_js_1.getBaseFolder)(), '..', 'res', 'html');
77
+ /**
78
+ * Serves a meta page for Swagger UI or rapi-doc.
79
+ *
80
+ * @param {SwaggerConfig} conf The swagger configuration to expose via `/spec`.
81
+ * @param {Object} [option] Options for serving the meta page.
82
+ * @param {'swagger-ui'|'rapi-doc'} [option.type='swagger-ui'] The type of UI to serve.
83
+ * @param {number} [option.port] The port to listen on. Defaults to 9000.
84
+ * @param {string} [option.auth] Optional authentication key appended to the URL.
85
+ * @returns {Promise<Server|null>} A promise that resolves with the created server instance or null.
86
+ */
87
+ static async serveMeta(conf, option) {
88
+ const type = option?.type ?? 'swagger-ui';
89
+ const port = option?.port || 9000;
90
+ const auth = option?.auth;
91
+ const resFiles = (0, PathHelp_js_1.default)((0, PathHelp_js_1.getBaseFolder)(), '..', 'res', 'html', type);
71
92
  const key = auth ? `?auth=${auth}` : '';
72
93
  const app = (0, express_1.default)();
73
94
  app.use('/', express_1.default.static(resFiles));
@@ -75,8 +96,8 @@ class SwaggerUtil {
75
96
  res.status(200).send(conf);
76
97
  });
77
98
  return new Promise((resolve) => {
78
- const s = app.listen(port || 9000, () => {
79
- console.log(`listen on http://localhost:${port || 9000}${key}#`);
99
+ const s = app.listen(port, () => {
100
+ this.getLogger().log(`${type} listen on http://localhost:${port}${key}#`);
80
101
  resolve(s);
81
102
  });
82
103
  });
@@ -121,7 +142,13 @@ class SwaggerUtil {
121
142
  // Handle requestBody
122
143
  if (!conf.requestBody) {
123
144
  if (route.meta.requestSchema) {
124
- conf.requestBody = index_js_2.SPathUtil.jsonBody(route.meta.requestSchema);
145
+ if (typeof route.meta.requestSchema === 'string' ||
146
+ (0, core_1.instanceOfEntity)(route.meta.requestSchema)) {
147
+ conf.requestBody = index_js_2.SPathUtil.refRequest(route.meta.requestSchema, route.meta.responseType === 'LIST');
148
+ }
149
+ else {
150
+ conf.requestBody = index_js_2.SPathUtil.jsonBody(route.meta.requestSchema);
151
+ }
125
152
  }
126
153
  }
127
154
  // Handle responses
@@ -8,13 +8,18 @@ export declare enum ActionMode {
8
8
  'DMZ_WITH_USER' = 2
9
9
  }
10
10
  export type ActionTypes = 'POST' | 'GET' | 'USE' | 'PATCH' | 'DELETE';
11
- export type ResponseTypes = 'LIST';
11
+ /**
12
+ * LIST - Response is an array of items
13
+ * SINGLE - Response is a single item (default)
14
+ */
15
+ export type ResponseRequestTypes = 'LIST' | 'SINGLE';
12
16
  export type RouteMeta = {
13
17
  pathOverride?: string;
14
18
  mode?: ActionMode;
15
- requestSchema?: SSchemaEl;
19
+ requestSchema?: SSchemaEl | CoreEntity | string;
16
20
  responseSchema?: SSchemaEl | CoreEntity | string;
17
- responseType?: ResponseTypes;
21
+ requestType?: ResponseRequestTypes;
22
+ responseType?: ResponseRequestTypes;
18
23
  responseCodes?: HttpStatusTypes[];
19
24
  } & SwaggerRPathConf;
20
25
  export type RouteData = {
@@ -38,13 +38,20 @@ export interface ConHandle {
38
38
  patch<T, J>(url: string, body?: J, config?: ConHandleConfig): Promise<ConHandleResponse<T>>;
39
39
  delete<T>(url: string, config?: ConHandleConfig): Promise<ConHandleResponse<T>>;
40
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
+ */
41
48
  export default class BaseCon {
42
- api: string;
43
- permanentHeader: undefined | Record<string, string>;
44
- authorization: string | null;
45
- disconnected: boolean;
46
- failFlag: boolean;
47
- logger: (arg: any) => void;
49
+ private api;
50
+ private permanentHeader;
51
+ private authorization;
52
+ private noAuth;
53
+ private disconnected;
54
+ private readonly logger;
48
55
  con: ConHandle;
49
56
  reconnect: () => Promise<boolean>;
50
57
  onReconnect: (con: BaseCon) => Promise<boolean>;
@@ -53,16 +60,113 @@ export default class BaseCon {
53
60
  endpoint: string;
54
61
  logger?: (arg: any) => void;
55
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
+ */
56
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
+ */
57
91
  token(): string;
58
- p(path: string, config?: ConHandleConfig): 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
+ */
59
98
  ping(): Promise<boolean>;
60
- test(email: string, password: string): 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
+ */
61
112
  testToken(): Promise<boolean>;
62
- connect(email: string, pw: string): Promise<boolean>;
63
113
  /**
64
- * Enable client before auth
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.
65
170
  */
66
- fakeEnableClient(): void;
67
171
  handle<T, J>(type: 'POST' | 'GET' | 'PATCH' | 'DELETE', path: string, body?: J, config?: ConHandleConfig): Promise<HandleRes<T>>;
68
172
  }