@grandlinex/swagger-mate 1.3.2 → 1.3.4

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.
@@ -56,7 +56,7 @@ export interface SwaggerRInfo {
56
56
  version: string;
57
57
  license?: SwaggerRInfoLicence;
58
58
  }
59
- export type SSchemaEl = {
59
+ export type SSchemaElObj = {
60
60
  type: SDataType;
61
61
  example?: string;
62
62
  format?: SDataFormat;
@@ -68,7 +68,8 @@ export type SSchemaEl = {
68
68
  required?: string[];
69
69
  enum?: string[];
70
70
  nullable?: boolean;
71
- } | SwaggerRRef;
71
+ };
72
+ export type SSchemaEl = SSchemaElObj | SwaggerRRef;
72
73
  export type SwaggerContent = {
73
74
  [K in SMediaType]?: {
74
75
  schema: SSchemaEl;
@@ -0,0 +1,51 @@
1
+ import { CoreEntity } from '@grandlinex/core';
2
+ import { SKey, SSchemaEl, SSchemaElObj } from '../Meta/SwaggerTypes.js';
3
+ export type ESchemaAddOption = {
4
+ key: string;
5
+ list?: boolean;
6
+ entity?: CoreEntity;
7
+ schema?: SSchemaEl;
8
+ required?: boolean;
9
+ nullable?: boolean;
10
+ };
11
+ export declare class ESchemaEditor<T extends CoreEntity> {
12
+ private data;
13
+ private name;
14
+ private constructor();
15
+ /**
16
+ * Removes the specified keys from the schema's properties and updates the required list.
17
+ *
18
+ * @param {...(keyof T)} keys - The keys of the properties to remove.
19
+ * @returns {ESchemaEditor<T>} The editor instance for method chaining.
20
+ */
21
+ remove(...keys: (keyof T)[]): ESchemaEditor<T>;
22
+ /**
23
+ * Adds properties to the schema based on the provided options.
24
+ *
25
+ * @param {...ESchemaAddOption} options The options describing the properties to add. Each option may specify a
26
+ * `key`, a `schema` or an `entity`, and optionally whether the property is a `list`, `nullable`, or `required`.
27
+ * @returns {ESchemaEditor<T>} The editor instance for chaining.
28
+ */
29
+ add(...options: ESchemaAddOption[]): ESchemaEditor<T>;
30
+ getSchema(): SSchemaElObj;
31
+ getSKeySchema(): SKey<SSchemaElObj>;
32
+ static fromEntity<J extends CoreEntity>(e: J): ESchemaEditor<J>;
33
+ /**
34
+ * Generates a JSON schema representation from a CoreEntity instance.
35
+ *
36
+ * This method inspects the entity's metadata to construct a schema object
37
+ * describing the entity's shape. The resulting schema contains:
38
+ * - `type`: always `"object"`.
39
+ * - `description`: a string indicating the entity name.
40
+ * - `required`: an array of property names that are defined on the entity.
41
+ * - `properties`: an object mapping each property name to an object that
42
+ * includes the resolved database type and its nullability.
43
+ *
44
+ * If no metadata is found for the provided entity, the method returns `undefined`.
45
+ *
46
+ * @param {T} entity - The entity instance for which to create a schema.
47
+ * @returns {SSchemaElObj | undefined} The generated schema object, or `undefined`
48
+ * if the entity's metadata could not be retrieved.
49
+ */
50
+ static schemaFromEntity<T extends CoreEntity>(entity: T): SSchemaElObj | undefined;
51
+ }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ESchemaEditor = void 0;
4
+ const core_1 = require("@grandlinex/core");
5
+ function resolveDBType(dType) {
6
+ switch (dType) {
7
+ case 'int':
8
+ case 'long':
9
+ return 'integer';
10
+ case 'double':
11
+ case 'float':
12
+ return 'number';
13
+ case 'blob':
14
+ return 'string';
15
+ case 'string':
16
+ case 'text':
17
+ case 'uuid':
18
+ return 'string';
19
+ case 'boolean':
20
+ return 'boolean';
21
+ case 'date':
22
+ return 'string';
23
+ case 'json':
24
+ return 'object';
25
+ default:
26
+ throw Error('TypeNotSupported');
27
+ }
28
+ }
29
+ class ESchemaEditor {
30
+ constructor(entity, name) {
31
+ this.data = ESchemaEditor.schemaFromEntity(entity);
32
+ this.name = name;
33
+ }
34
+ /**
35
+ * Removes the specified keys from the schema's properties and updates the required list.
36
+ *
37
+ * @param {...(keyof T)} keys - The keys of the properties to remove.
38
+ * @returns {ESchemaEditor<T>} The editor instance for method chaining.
39
+ */
40
+ remove(...keys) {
41
+ if (this.data.properties) {
42
+ for (const key of keys) {
43
+ this.data.properties = Object.fromEntries(Object.entries(this.data.properties).filter(([e]) => key !== e));
44
+ this.data.required = (this.data.required || []).filter((e) => key !== e);
45
+ }
46
+ }
47
+ return this;
48
+ }
49
+ /**
50
+ * Adds properties to the schema based on the provided options.
51
+ *
52
+ * @param {...ESchemaAddOption} options The options describing the properties to add. Each option may specify a
53
+ * `key`, a `schema` or an `entity`, and optionally whether the property is a `list`, `nullable`, or `required`.
54
+ * @returns {ESchemaEditor<T>} The editor instance for chaining.
55
+ */
56
+ add(...options) {
57
+ if (!this.data.properties) {
58
+ return this;
59
+ }
60
+ for (const option of options) {
61
+ if (option.schema) {
62
+ if (option.list) {
63
+ this.data.properties[option.key] = {
64
+ type: 'array',
65
+ items: option.schema,
66
+ nullable: option.nullable,
67
+ };
68
+ }
69
+ else {
70
+ this.data.properties[option.key] = option.schema;
71
+ }
72
+ }
73
+ else if (option.entity) {
74
+ const scheme = ESchemaEditor.fromEntity(option.entity).getSchema();
75
+ if (option.nullable) {
76
+ scheme.nullable = true;
77
+ }
78
+ if (option.list) {
79
+ this.data.properties[option.key] = {
80
+ type: 'array',
81
+ items: scheme,
82
+ };
83
+ }
84
+ else {
85
+ this.data.properties[option.key] = scheme;
86
+ }
87
+ }
88
+ if (option.required) {
89
+ this.data.required = [...(this.data.required || []), option.key];
90
+ }
91
+ }
92
+ return this;
93
+ }
94
+ getSchema() {
95
+ return this.data;
96
+ }
97
+ getSKeySchema() {
98
+ return {
99
+ [this.name]: this.data,
100
+ };
101
+ }
102
+ static fromEntity(e) {
103
+ const meta = (0, core_1.getEntityMeta)(e);
104
+ if (meta) {
105
+ return new ESchemaEditor(e, meta.name);
106
+ }
107
+ throw new Error('Entity metadata not found');
108
+ }
109
+ /**
110
+ * Generates a JSON schema representation from a CoreEntity instance.
111
+ *
112
+ * This method inspects the entity's metadata to construct a schema object
113
+ * describing the entity's shape. The resulting schema contains:
114
+ * - `type`: always `"object"`.
115
+ * - `description`: a string indicating the entity name.
116
+ * - `required`: an array of property names that are defined on the entity.
117
+ * - `properties`: an object mapping each property name to an object that
118
+ * includes the resolved database type and its nullability.
119
+ *
120
+ * If no metadata is found for the provided entity, the method returns `undefined`.
121
+ *
122
+ * @param {T} entity - The entity instance for which to create a schema.
123
+ * @returns {SSchemaElObj | undefined} The generated schema object, or `undefined`
124
+ * if the entity's metadata could not be retrieved.
125
+ */
126
+ static schemaFromEntity(entity) {
127
+ const schema = {
128
+ type: 'object',
129
+ properties: {},
130
+ };
131
+ const meta = (0, core_1.getEntityMeta)(entity);
132
+ if (!meta) {
133
+ return undefined;
134
+ }
135
+ schema.description = `Entity: ${meta.name}`;
136
+ schema.required = [];
137
+ const keys = Object.keys(entity);
138
+ keys.forEach((k) => {
139
+ const cMeta = (0, core_1.getColumnMeta)(entity, k);
140
+ if (cMeta && schema.properties) {
141
+ schema.required.push(k);
142
+ schema.properties[k] = {
143
+ type: resolveDBType(cMeta.dataType),
144
+ nullable: cMeta.canBeNull,
145
+ };
146
+ }
147
+ });
148
+ return schema;
149
+ }
150
+ }
151
+ exports.ESchemaEditor = ESchemaEditor;
@@ -1,6 +1,7 @@
1
1
  import { CoreEntity } from '@grandlinex/core';
2
2
  import { HttpStatusTypes } from '../Meta/SwaggerTypesStatic.js';
3
- import { SKey, SSchemaEl, SwaggerContent, SwaggerRPathConfResponse, SwaggerRPathReqBody } from '../Meta/SwaggerTypes.js';
3
+ import { SKey, SSchemaEl, SSchemaElObj, SwaggerContent, SwaggerRPathConfResponse, SwaggerRPathReqBody } from '../Meta/SwaggerTypes.js';
4
+ import { ESchemaEditor } from './ESchemaEditor.js';
4
5
  export default class SPathUtil {
5
6
  /**
6
7
  * Generates a default response mapping for the specified HTTP status types.
@@ -90,10 +91,11 @@ export default class SPathUtil {
90
91
  * If no metadata is found for the provided entity, the method returns `undefined`.
91
92
  *
92
93
  * @param {T} entity - The entity instance for which to create a schema.
93
- * @returns {SSchemaEl | undefined} The generated schema object, or `undefined`
94
+ * @returns {SSchemaElObj | undefined} The generated schema object, or `undefined`
94
95
  * if the entity's metadata could not be retrieved.
96
+ * @deprecated Use {@link ESchemaEditor.schemaFromEntity} instead.
95
97
  */
96
- static schemaFromEntity<T extends CoreEntity>(entity: T): SSchemaEl | undefined;
98
+ static schemaFromEntity<T extends CoreEntity>(entity: T): SSchemaElObj | undefined;
97
99
  /**
98
100
  * 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.
99
101
  *
@@ -114,7 +116,7 @@ export default class SPathUtil {
114
116
  * @param {CoreEntity[]} e The entities for which schema entries should be generated.
115
117
  * @return {SKey<SSchemaEl>} An object whose keys are entity names and values are the schemas derived from those entities.
116
118
  */
117
- static schemaEntryGen(...e: CoreEntity[]): SKey<SSchemaEl>;
119
+ static schemaEntryGen(...e: CoreEntity[]): SKey<SSchemaElObj>;
118
120
  /**
119
121
  * Builds a JSON schema representation for an entity view that includes both the
120
122
  * entity data and its related entity map.
@@ -124,76 +126,5 @@ export default class SPathUtil {
124
126
  * @returns A {@link SSchemaEl} object schema with properties `i`, `dat`, and `join_map`.
125
127
  */
126
128
  static schemaFromEntityView<A extends CoreEntity, B extends CoreEntity>(entity: A, entityMap: B): SSchemaEl;
127
- /**
128
- * Extends an entity schema object by merging additional schema options.
129
- *
130
- * @param {CoreEntity} entity
131
- * The entity for which the schema should be extended.
132
- *
133
- * @param {...Object} options
134
- * One or more objects defining schema extensions. Each object may contain:
135
- * - `key` (string): The property key to add or extend.
136
- * - `list` (boolean, optional): Indicates whether the property is a list.
137
- * - `entity` (CoreEntity, optional): The entity type for the property.
138
- * - `schema` (SSchemaEl, optional): A custom schema definition for the property.
139
- * - `required` (boolean, optional): Whether the property is required.
140
- *
141
- * @return {SSchemaEl}
142
- * The resulting schema element. If a single property is returned by
143
- * `extendEntitySchema`, its schema is returned directly; otherwise an
144
- * object schema with a type of `'object'` is returned.
145
- */
146
- static extendEntitySchemaObject(entity: CoreEntity, ...options: {
147
- key: string;
148
- list?: boolean;
149
- entity?: CoreEntity;
150
- schema?: SSchemaEl;
151
- required?: boolean;
152
- }[]): SSchemaEl;
153
- /**
154
- * Extends the schema of a given {@link CoreEntity} with additional properties.
155
- *
156
- * @param {CoreEntity} entity
157
- * The entity whose schema will be extended.
158
- *
159
- * @param {...{
160
- * key: string,
161
- * list?: boolean,
162
- * entity?: CoreEntity,
163
- * schema?: SSchemaEl,
164
- * required?: boolean
165
- * }} options
166
- * One or more option objects specifying the extensions to apply. Each option
167
- * may provide either a direct schema (`schema`) or an entity reference
168
- * (`entity`). The `list` flag indicates whether the property should be
169
- * represented as an array of the provided schema. The `required` flag
170
- * adds the property to the schema’s required list.
171
- *
172
- * @returns {SKey<SSchemaEl>}
173
- * An object containing the updated schema for the entity, keyed by the
174
- * entity’s name. If the entity metadata cannot be found, an empty
175
- * object is returned.
176
- */
177
- static extendEntitySchema(entity: CoreEntity, ...options: {
178
- key: string;
179
- list?: boolean;
180
- entity?: CoreEntity;
181
- schema?: SSchemaEl;
182
- required?: boolean;
183
- }[]): SKey<SSchemaEl>;
184
- /**
185
- * Reduces the entity schema to a single schema element or a generic object.
186
- *
187
- * @param entity The entity whose schema should be reduced.
188
- * @param keys Optional list of keys to include in the reduced schema. If omitted, all keys are considered.
189
- * @return Returns the schema element of the sole key if only one key is present; otherwise, returns a generic object schema with type `'object'`. */
190
- static reduceEntitySchemaObject<T extends CoreEntity>(entity: T, ...keys: (keyof T)[]): SSchemaEl;
191
- /**
192
- * Creates a reduced version of an entity's schema by excluding specified properties.
193
- *
194
- * @param {CoreEntity} entity - The entity whose schema is to be processed.
195
- * @param {...string} keys - Property names to remove from the schema's `properties` and `required` lists.
196
- *
197
- * @returns */
198
- static reduceEntitySchema<T extends CoreEntity>(entity: T, ...keys: (keyof T)[]): SKey<SSchemaEl>;
129
+ static editor<J extends CoreEntity>(e: J): ESchemaEditor<J>;
199
130
  }
@@ -5,31 +5,7 @@ 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");
9
- function resolveDBType(dType) {
10
- switch (dType) {
11
- case 'int':
12
- case 'long':
13
- return 'integer';
14
- case 'double':
15
- case 'float':
16
- return 'number';
17
- case 'blob':
18
- return 'string';
19
- case 'string':
20
- case 'text':
21
- case 'uuid':
22
- return 'string';
23
- case 'boolean':
24
- return 'boolean';
25
- case 'date':
26
- return 'string';
27
- case 'json':
28
- return 'object';
29
- default:
30
- throw Error('TypeNotSupported');
31
- }
32
- }
8
+ const ESchemaEditor_js_1 = require("./ESchemaEditor.js");
33
9
  class SPathUtil {
34
10
  /**
35
11
  * Generates a default response mapping for the specified HTTP status types.
@@ -266,32 +242,12 @@ class SPathUtil {
266
242
  * If no metadata is found for the provided entity, the method returns `undefined`.
267
243
  *
268
244
  * @param {T} entity - The entity instance for which to create a schema.
269
- * @returns {SSchemaEl | undefined} The generated schema object, or `undefined`
245
+ * @returns {SSchemaElObj | undefined} The generated schema object, or `undefined`
270
246
  * if the entity's metadata could not be retrieved.
247
+ * @deprecated Use {@link ESchemaEditor.schemaFromEntity} instead.
271
248
  */
272
249
  static schemaFromEntity(entity) {
273
- const schema = {
274
- type: 'object',
275
- properties: {},
276
- };
277
- const meta = (0, core_1.getEntityMeta)(entity);
278
- if (!meta) {
279
- return undefined;
280
- }
281
- schema.description = `Entity: ${meta.name}`;
282
- schema.required = [];
283
- const keys = Object.keys(entity);
284
- keys.forEach((k) => {
285
- const cMeta = (0, core_1.getColumnMeta)(entity, k);
286
- if (cMeta && schema.properties) {
287
- schema.required.push(k);
288
- schema.properties[k] = {
289
- type: resolveDBType(cMeta.dataType),
290
- nullable: cMeta.canBeNull,
291
- };
292
- }
293
- });
294
- return schema;
250
+ return ESchemaEditor_js_1.ESchemaEditor.schemaFromEntity(entity);
295
251
  }
296
252
  /**
297
253
  * 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.
@@ -308,7 +264,7 @@ class SPathUtil {
308
264
  description: `Entity: ${meta.name}`,
309
265
  content: {
310
266
  'application/json': {
311
- schema: this.schemaFromEntity(entity),
267
+ schema: ESchemaEditor_js_1.ESchemaEditor.schemaFromEntity(entity),
312
268
  },
313
269
  },
314
270
  };
@@ -324,7 +280,7 @@ class SPathUtil {
324
280
  e.forEach((el) => {
325
281
  const meta = (0, core_1.getEntityMeta)(el);
326
282
  if (meta) {
327
- out[meta.name] = SPathUtil.schemaFromEntity(el);
283
+ out[meta.name] = ESchemaEditor_js_1.ESchemaEditor.schemaFromEntity(el);
328
284
  }
329
285
  });
330
286
  return out;
@@ -344,141 +300,13 @@ class SPathUtil {
344
300
  i: {
345
301
  type: 'integer',
346
302
  },
347
- dat: this.schemaFromEntity(entity),
348
- join_map: this.schemaFromEntity(entityMap),
303
+ dat: ESchemaEditor_js_1.ESchemaEditor.schemaFromEntity(entity),
304
+ join_map: ESchemaEditor_js_1.ESchemaEditor.schemaFromEntity(entityMap),
349
305
  },
350
306
  };
351
307
  }
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 {};
308
+ static editor(e) {
309
+ return ESchemaEditor_js_1.ESchemaEditor.fromEntity(e);
482
310
  }
483
311
  }
484
312
  exports.default = SPathUtil;
@@ -55,10 +55,21 @@ export default class BaseCon {
55
55
  con: ConHandle;
56
56
  reconnect: () => Promise<boolean>;
57
57
  onReconnect: (con: BaseCon) => Promise<boolean>;
58
+ /**
59
+ * Initializes a new instance of the client.
60
+ *
61
+ * @param {Object} conf Configuration object.
62
+ * @param {ConHandle} conf.con - Connection handle.
63
+ * @param {string} conf.endpoint - API endpoint URL.
64
+ * @param {(arg: any) => void} [conf.logger] - Optional logger function; defaults to console.log.
65
+ * @param {Record<string, string>} [conf.permanentHeader] - Optional permanent headers to include in requests.
66
+ * @return {void}
67
+ */
58
68
  constructor(conf: {
59
69
  con: ConHandle;
60
70
  endpoint: string;
61
71
  logger?: (arg: any) => void;
72
+ permanentHeader?: Record<string, string>;
62
73
  });
63
74
  /**
64
75
  * Retrieves the API endpoint.
@@ -84,11 +95,17 @@ export default class BaseCon {
84
95
  */
85
96
  isConnected(): boolean;
86
97
  /**
87
- * Returns the current authorization token.
98
+ * Retrieves the current authorization token.
99
+ *
100
+ * @return {string|null} The token string used for authorization, or {@code null} if no token is set.
101
+ */
102
+ token(): string | null;
103
+ /**
104
+ * Returns the bearer token string if an authorization value has been set.
88
105
  *
89
- * @return {string} The authorization token or an empty string if none is set.
106
+ * @return {string|null} The bearer token prefixed with "Bearer ", or {@code null} when no authorization is present.
90
107
  */
91
- token(): string;
108
+ getBearer(): string | null;
92
109
  private p;
93
110
  /**
94
111
  * Sends a ping request to the API to verify connectivity and version availability.
@@ -96,6 +113,18 @@ export default class BaseCon {
96
113
  * @return {boolean} `true` if the API responded with a 200 status code and a valid version object; `false` otherwise.
97
114
  */
98
115
  ping(): Promise<boolean>;
116
+ /**
117
+ * Builds the Authorization header for HTTP requests.
118
+ *
119
+ * If the instance has an authorization token, this method returns an object
120
+ * containing a single `Authorization` header with the Bearer token value.
121
+ * When no token is available, an empty header object is returned.
122
+ *
123
+ * @return {Record<string, string>} The headers object containing the
124
+ * `Authorization` header when applicable, otherwise an empty object.
125
+ */
126
+ private tokenHeader;
127
+ setPermanentHeader(header: Record<string, string>): void;
99
128
  /**
100
129
  * Validates the current authentication token by performing a ping and a test request
101
130
  * to the backend. The method first ensures connectivity via {@link ping}. If the ping
@@ -126,10 +155,11 @@ export default class BaseCon {
126
155
  /**
127
156
  * Forces a connection using the provided bearer token.
128
157
  *
129
- * @param {string} token The token to be used for authentication.
158
+ * @param {string|null} token The token to be used for authentication.
130
159
  * @returns {void}
131
160
  */
132
- forceConnectWithToken(token: string): void;
161
+ forceConnect(token: string | null): void;
162
+ coppyFrom(con: BaseCon): void;
133
163
  /**
134
164
  * Establishes a connection to the backend using the supplied credentials.
135
165
  * Performs a health‑check ping first; if successful, it requests an authentication