@quandis/qbo4.configuration 4.0.1-CI-20241017-182709 → 4.0.1-CI-20241019-132152
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/package.json +2 -2
- package/src/IApiService.d.ts +21 -0
- package/src/IApiService.js +5 -0
- package/src/IApiService.js.map +1 -0
- package/src/IApiService.ts +27 -0
- package/src/Library.d.ts +7 -0
- package/src/Library.js +87 -0
- package/src/Library.js.map +1 -0
- package/src/Library.ts +94 -0
- package/src/Program.d.ts +11 -4
- package/src/Program.js +26 -1
- package/src/Program.js.map +1 -1
- package/src/Program.ts +32 -4
- package/src/RestApiService.d.ts +11 -0
- package/src/RestApiService.js +39 -0
- package/src/RestApiService.js.map +1 -0
- package/src/RestApiService.ts +52 -0
- package/src/qbo-api.d.ts +8 -0
- package/src/qbo-api.js +66 -0
- package/src/qbo-api.js.map +1 -0
- package/src/qbo-api.ts +54 -0
- package/src/qbo-template.js +3 -1
- package/src/qbo-template.js.map +1 -1
- package/src/qbo-template.ts +3 -1
- package/wwwroot/js/esm/qbo4.configuration.js +324 -23
- package/wwwroot/js/esm/qbo4.configuration.min.js +12 -12
- package/wwwroot/js/esm/qbo4.configuration.min.js.map +1 -1
- package/wwwroot/js/qbo4.configuration.js +320 -22
- package/wwwroot/js/qbo4.configuration.min.js +12 -12
- package/wwwroot/js/qbo4.configuration.min.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quandis/qbo4.configuration",
|
|
3
|
-
"version": "4.0.1-CI-
|
|
3
|
+
"version": "4.0.1-CI-20241019-132152",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./src/Program.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"mini-css-extract-plugin": "^2.9.1",
|
|
36
36
|
"postcss-cli": "^11.0.0",
|
|
37
37
|
"postcss-loader": "^8.1.1",
|
|
38
|
-
"sass": "^1.80.
|
|
38
|
+
"sass": "^1.80.3",
|
|
39
39
|
"sass-loader": "^16.0.2",
|
|
40
40
|
"style-loader": "^4.0.0",
|
|
41
41
|
"typescript": "^5.6.3",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InjectionToken } from "tsyringe";
|
|
2
|
+
/**
|
|
3
|
+
* Defines a contract for API calls.
|
|
4
|
+
*/
|
|
5
|
+
export interface IApiService {
|
|
6
|
+
/**
|
|
7
|
+
* The relative path to the API endpoint.
|
|
8
|
+
*/
|
|
9
|
+
relativePath: string;
|
|
10
|
+
/**
|
|
11
|
+
* Fetch data from the API.
|
|
12
|
+
* @param relativePath The relative path to the API endpoint.
|
|
13
|
+
* @param payload The payload to send to the API.
|
|
14
|
+
*/
|
|
15
|
+
fetch(relativePath: string | null, payload?: Record<string, string> | null | undefined): Promise<any>;
|
|
16
|
+
clone(relativePath: string | null): IApiService;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Define a token for the IApiService interface
|
|
20
|
+
*/
|
|
21
|
+
export declare const IApiServiceToken: InjectionToken<IApiService>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IApiService.js","sourceRoot":"","sources":["IApiService.ts"],"names":[],"mappings":"AAsBA;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAgC,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { InjectionToken } from "tsyringe";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Defines a contract for API calls.
|
|
5
|
+
*/
|
|
6
|
+
export interface IApiService {
|
|
7
|
+
/**
|
|
8
|
+
* The relative path to the API endpoint.
|
|
9
|
+
*/
|
|
10
|
+
relativePath: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Fetch data from the API.
|
|
14
|
+
* @param relativePath The relative path to the API endpoint.
|
|
15
|
+
* @param payload The payload to send to the API.
|
|
16
|
+
*/
|
|
17
|
+
fetch(relativePath: string | null, payload?: Record<string, string> | null | undefined): Promise<any>;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
clone(relativePath: string | null): IApiService;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Define a token for the IApiService interface
|
|
25
|
+
*/
|
|
26
|
+
export const IApiServiceToken: InjectionToken<IApiService> = 'ApiServiceToken';
|
|
27
|
+
|
package/src/Library.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function getArray(json: any, arrayName?: string): Array<{
|
|
2
|
+
[key: string]: string;
|
|
3
|
+
}> | null;
|
|
4
|
+
export declare function substitute(inputString: string, ...jsonData: any): string;
|
|
5
|
+
export declare function replicate(target: HTMLElement | null, template: HTMLTemplateElement | null, sourceData: Array<{
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
}>, emptyContent?: boolean): void;
|
package/src/Library.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* @description Find an array in a JSON object
|
|
2
|
+
* @param json {object} A Json object or array.
|
|
3
|
+
* @param arrayName {array} The name of a key that represents an array to use. If not specified, the first array found will be returned.
|
|
4
|
+
* @returns {Array} An array if found, otherwise null.
|
|
5
|
+
*/
|
|
6
|
+
export function getArray(json, arrayName) {
|
|
7
|
+
if (typeof json === 'string') {
|
|
8
|
+
try {
|
|
9
|
+
json = JSON.parse(json);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
console.error('Error parsing JSON string:', error);
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(json)) {
|
|
17
|
+
return json;
|
|
18
|
+
}
|
|
19
|
+
if (typeof json === 'object' && json !== null) {
|
|
20
|
+
for (const key in json) {
|
|
21
|
+
const value = json[key];
|
|
22
|
+
if (Array.isArray(value)) {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
else if (typeof value === 'object') {
|
|
26
|
+
const nestedResult = getArray(value, arrayName);
|
|
27
|
+
if (nestedResult) {
|
|
28
|
+
return nestedResult;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null; // No array found
|
|
34
|
+
}
|
|
35
|
+
/* @description Perform string substitution on a template using a JSON object
|
|
36
|
+
*/
|
|
37
|
+
function interpolate(template, data) {
|
|
38
|
+
try {
|
|
39
|
+
return new Function("return `" + template + "`;").call(data);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
document.dispatchEvent(new CustomEvent('qbo-warning', { detail: { 'error': err, 'message': 'Unable to substitute template.', 'template': template, 'data': data } }));
|
|
43
|
+
return template;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/* @description Perform string substitution of ${expression} using one or more JSON objects.
|
|
47
|
+
* @example substitute('Hello ${name}!', { name: 'World' }) => 'Hello World!'
|
|
48
|
+
*/
|
|
49
|
+
export function substitute(inputString, ...jsonData) {
|
|
50
|
+
// Use a regular expression to match ${key} expressions
|
|
51
|
+
const regex = /\${(.*?)}/g;
|
|
52
|
+
let resultString = inputString;
|
|
53
|
+
for (let i = 0; i < jsonData.length; i++) {
|
|
54
|
+
const data = jsonData[i];
|
|
55
|
+
resultString = resultString.replace(regex, (match, expression) => {
|
|
56
|
+
const parts = expression.split(/\.|\[|\]/).filter(part => part !== '');
|
|
57
|
+
let currentValue = data;
|
|
58
|
+
// Iterate over the parts to access the desired value
|
|
59
|
+
for (let part of parts) {
|
|
60
|
+
if (currentValue[part] === undefined)
|
|
61
|
+
return match;
|
|
62
|
+
currentValue = currentValue[part];
|
|
63
|
+
}
|
|
64
|
+
return currentValue;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
resultString = resultString.replace(regex, () => '');
|
|
68
|
+
return resultString;
|
|
69
|
+
}
|
|
70
|
+
/* @description Replicates content in a target element for each item in a JSON array.
|
|
71
|
+
*/
|
|
72
|
+
export function replicate(target, template, sourceData, emptyContent = true) {
|
|
73
|
+
if (target != null && template != null) {
|
|
74
|
+
while (emptyContent && target.firstChild) {
|
|
75
|
+
target.removeChild(target.firstChild);
|
|
76
|
+
}
|
|
77
|
+
sourceData.map((data, index) => {
|
|
78
|
+
const row = template.content.cloneNode(true);
|
|
79
|
+
if (row.firstElementChild != null) {
|
|
80
|
+
row.firstElementChild.setAttribute("data-index", `${index}`);
|
|
81
|
+
row.firstElementChild.innerHTML = substitute(row.firstElementChild?.innerHTML ?? '', data);
|
|
82
|
+
}
|
|
83
|
+
target.appendChild(row);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=Library.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Library.js","sourceRoot":"","sources":["Library.ts"],"names":[],"mappings":"AACA;;;;EAIE;AACF,MAAM,UAAU,QAAQ,CAAC,IAAS,EAAE,SAAkB;IAClD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,IAAI,CAAC;YACD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;YACnD,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC5C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACrB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YACxB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC;YACjB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,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC"}
|
package/src/Library.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
|
|
2
|
+
/* @description Find an array in a JSON object
|
|
3
|
+
* @param json {object} A Json object or array.
|
|
4
|
+
* @param arrayName {array} The name of a key that represents an array to use. If not specified, the first array found will be returned.
|
|
5
|
+
* @returns {Array} An array if found, otherwise null.
|
|
6
|
+
*/
|
|
7
|
+
export function getArray(json: any, arrayName?: string): Array<{ [key: string]: string }> | null {
|
|
8
|
+
if (typeof json === 'string') {
|
|
9
|
+
try {
|
|
10
|
+
json = JSON.parse(json);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error('Error parsing JSON string:', error);
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (Array.isArray(json)) {
|
|
18
|
+
return json;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (typeof json === 'object' && json !== null) {
|
|
22
|
+
for (const key in json) {
|
|
23
|
+
const value = json[key];
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
return value;
|
|
26
|
+
} else if (typeof value === 'object') {
|
|
27
|
+
const nestedResult = getArray(value, arrayName);
|
|
28
|
+
if (nestedResult) {
|
|
29
|
+
return nestedResult;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return null; // No array found
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* @description Perform string substitution on a template using a JSON object
|
|
39
|
+
*/
|
|
40
|
+
function interpolate(template: string, data: { [key: string]: string }) {
|
|
41
|
+
try {
|
|
42
|
+
return new Function("return `" + template + "`;").call(data);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
document.dispatchEvent(new CustomEvent('qbo-warning', { detail: { 'error': err, 'message': 'Unable to substitute template.', 'template': template, 'data': data } }));
|
|
45
|
+
return template;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* @description Perform string substitution of ${expression} using one or more JSON objects.
|
|
50
|
+
* @example substitute('Hello ${name}!', { name: 'World' }) => 'Hello World!'
|
|
51
|
+
*/
|
|
52
|
+
export function substitute(inputString: string, ...jsonData: any): string {
|
|
53
|
+
// Use a regular expression to match ${key} expressions
|
|
54
|
+
const regex = /\${(.*?)}/g;
|
|
55
|
+
let resultString = inputString;
|
|
56
|
+
for (let i = 0; i < jsonData.length; i++) {
|
|
57
|
+
const data = jsonData[i] as Record<string, any>;
|
|
58
|
+
resultString = resultString.replace(regex, (match: string, expression: string) => {
|
|
59
|
+
const parts = expression.split(/\.|\[|\]/).filter(part => part !== '');
|
|
60
|
+
let currentValue: any = data;
|
|
61
|
+
|
|
62
|
+
// Iterate over the parts to access the desired value
|
|
63
|
+
for (let part of parts) {
|
|
64
|
+
if (currentValue[part] === undefined)
|
|
65
|
+
return match;
|
|
66
|
+
currentValue = currentValue[part];
|
|
67
|
+
}
|
|
68
|
+
return currentValue;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
resultString = resultString.replace(regex, () => '');
|
|
72
|
+
|
|
73
|
+
return resultString;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
/* @description Replicates content in a target element for each item in a JSON array.
|
|
78
|
+
*/
|
|
79
|
+
export function replicate(target: HTMLElement | null, template: HTMLTemplateElement | null, sourceData: Array<{ [key: string]: string }>, emptyContent: boolean = true) {
|
|
80
|
+
if (target != null && template != null) {
|
|
81
|
+
while (emptyContent && target.firstChild) {
|
|
82
|
+
target.removeChild(target.firstChild);
|
|
83
|
+
}
|
|
84
|
+
sourceData.map((data, index) => {
|
|
85
|
+
const row = template.content.cloneNode(true) as DocumentFragment;
|
|
86
|
+
if (row.firstElementChild != null) {
|
|
87
|
+
row.firstElementChild.setAttribute("data-index", `${index}`);
|
|
88
|
+
row.firstElementChild.innerHTML = substitute(row.firstElementChild?.innerHTML ?? '', data)
|
|
89
|
+
}
|
|
90
|
+
target.appendChild(row);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
package/src/Program.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Services } from './Services.js';
|
|
1
|
+
import 'reflect-metadata';
|
|
3
2
|
declare global {
|
|
4
3
|
interface HTMLElement {
|
|
5
4
|
attachInternals(): ElementInternals;
|
|
@@ -10,15 +9,23 @@ declare global {
|
|
|
10
9
|
configuration?: {
|
|
11
10
|
templates?: Map<string, Map<string, TemplateFunction>>;
|
|
12
11
|
html?: any;
|
|
12
|
+
css?: any;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
import '
|
|
18
|
-
|
|
17
|
+
import { IApiService } from './IApiService.js';
|
|
18
|
+
import { TemplateFunction } from './qbo-template.js';
|
|
19
|
+
import { Services } from './Services.js';
|
|
20
|
+
export { html, css } from 'lit';
|
|
21
|
+
export * from './IApiService.js';
|
|
22
|
+
export * from './RestApiService.js';
|
|
19
23
|
export * from './Services.js';
|
|
20
24
|
export * from './IConfiguration.js';
|
|
21
25
|
export * from './Configuration.js';
|
|
22
26
|
export * from './qbo-config-editor.js';
|
|
23
27
|
export * from './qbo-template.js';
|
|
24
28
|
export * from './qbo-css.js';
|
|
29
|
+
export * from './qbo-api.js';
|
|
30
|
+
export declare function getApiService(url: string): IApiService;
|
|
31
|
+
export declare function redefineCustomElements(): void;
|
package/src/Program.js
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
|
|
2
|
+
import { RestApiService } from './RestApiService.js';
|
|
3
|
+
import { services } from './Services.js';
|
|
4
|
+
export { html, css } from 'lit';
|
|
5
|
+
export * from './IApiService.js';
|
|
6
|
+
export * from './RestApiService.js';
|
|
3
7
|
export * from './Services.js';
|
|
4
8
|
export * from './IConfiguration.js';
|
|
5
9
|
export * from './Configuration.js';
|
|
6
10
|
export * from './qbo-config-editor.js';
|
|
7
11
|
export * from './qbo-template.js';
|
|
8
12
|
export * from './qbo-css.js';
|
|
13
|
+
export * from './qbo-api.js';
|
|
14
|
+
export function getApiService(url) {
|
|
15
|
+
const parts = url.match(/api:\/\/([^/]+)/);
|
|
16
|
+
const name = parts ? parts[1] : url;
|
|
17
|
+
const relativePath = parts ? url.substring(`api://${name}`.length + 1) : '';
|
|
18
|
+
const service = services.container.isRegistered(name)
|
|
19
|
+
? services.container.resolve(name)
|
|
20
|
+
: new RestApiService(url);
|
|
21
|
+
return (relativePath) ? service.clone(relativePath) : service;
|
|
22
|
+
}
|
|
23
|
+
export function redefineCustomElements() {
|
|
24
|
+
// Store the original customElements.define method
|
|
25
|
+
const originalDefine = window.customElements.define;
|
|
26
|
+
// Override customElements.define
|
|
27
|
+
window.customElements.define = function (tagName, elementClass, options) {
|
|
28
|
+
if (!window.customElements.get(tagName))
|
|
29
|
+
originalDefine.call(this, tagName, elementClass, options);
|
|
30
|
+
else
|
|
31
|
+
console.error(`Custom element ${tagName} already defined`);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
9
34
|
//# sourceMappingURL=Program.js.map
|
package/src/Program.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Program.js","sourceRoot":"","sources":["Program.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Program.js","sourceRoot":"","sources":["Program.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAqB1B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAY,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CA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ACnE,CAAC,CAAC;AACN,CAAC"}
|
package/src/Program.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Services } from './Services.js';
|
|
1
|
+
import 'reflect-metadata';
|
|
3
2
|
|
|
4
3
|
// Extend the HTMLElement interface to include attachInternals
|
|
5
4
|
declare global {
|
|
@@ -12,18 +11,47 @@ declare global {
|
|
|
12
11
|
configuration?: {
|
|
13
12
|
templates?: Map<string, Map<string, TemplateFunction>>;
|
|
14
13
|
html?: any;
|
|
14
|
+
css?: any;
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
import '
|
|
20
|
+
import { IApiService } from './IApiService.js';
|
|
21
|
+
import { TemplateFunction, templates } from './qbo-template.js';
|
|
22
|
+
import { RestApiService } from './RestApiService.js';
|
|
23
|
+
import { services, Services } from './Services.js';
|
|
21
24
|
|
|
22
|
-
export { html } from 'lit';
|
|
25
|
+
export { html, css } from 'lit';
|
|
26
|
+
export * from './IApiService.js';
|
|
27
|
+
export * from './RestApiService.js';
|
|
23
28
|
export * from './Services.js';
|
|
24
29
|
export * from './IConfiguration.js';
|
|
25
30
|
export * from './Configuration.js';
|
|
26
31
|
export * from './qbo-config-editor.js';
|
|
27
32
|
export * from './qbo-template.js';
|
|
28
33
|
export * from './qbo-css.js';
|
|
34
|
+
export * from './qbo-api.js';
|
|
35
|
+
export function getApiService(url: string) {
|
|
36
|
+
const parts = url.match(/api:\/\/([^/]+)/);
|
|
37
|
+
const name = parts ? parts[1] : url;
|
|
38
|
+
const relativePath = parts ? url.substring(`api://${name}`.length + 1) : '';
|
|
39
|
+
const service: IApiService = services.container.isRegistered(name)
|
|
40
|
+
? services.container.resolve<IApiService>(name)
|
|
41
|
+
: new RestApiService(url);
|
|
29
42
|
|
|
43
|
+
return (relativePath) ? service.clone(relativePath) : service;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function redefineCustomElements() {
|
|
47
|
+
// Store the original customElements.define method
|
|
48
|
+
const originalDefine = window.customElements.define;
|
|
49
|
+
|
|
50
|
+
// Override customElements.define
|
|
51
|
+
window.customElements.define = function (tagName, elementClass, options) {
|
|
52
|
+
if (!window.customElements.get(tagName))
|
|
53
|
+
originalDefine.call(this, tagName, elementClass, options);
|
|
54
|
+
else
|
|
55
|
+
console.error(`Custom element ${tagName} already defined`);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IApiService } from "./IApiService.js";
|
|
2
|
+
export declare class RestApiService implements IApiService {
|
|
3
|
+
private headers;
|
|
4
|
+
private apiEndpoint;
|
|
5
|
+
private method;
|
|
6
|
+
relativePath: string;
|
|
7
|
+
constructor(apiEndpoint: string, headers?: HeadersInit, method?: string | null);
|
|
8
|
+
fetch(relativePath: string | null, payload?: Record<string, string> | null | undefined): Promise<any>;
|
|
9
|
+
clone(relativePath: string | null): IApiService;
|
|
10
|
+
}
|
|
11
|
+
export declare function registerRestApi(name: string, apiEndpoint: string, headers?: HeadersInit, method?: string | null): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { substitute } from "./Library.js";
|
|
2
|
+
import { services } from "./Services.js";
|
|
3
|
+
export class RestApiService {
|
|
4
|
+
constructor(apiEndpoint, headers = { 'Content-Type': 'application/json' }, method = null) {
|
|
5
|
+
this.relativePath = '';
|
|
6
|
+
this.apiEndpoint = apiEndpoint;
|
|
7
|
+
this.headers = headers;
|
|
8
|
+
this.method = method;
|
|
9
|
+
}
|
|
10
|
+
async fetch(relativePath, payload) {
|
|
11
|
+
const endpoint = substitute(new URL(relativePath ?? this.relativePath, this.apiEndpoint).href, payload);
|
|
12
|
+
const method = this.method ?? (payload ? 'POST' : 'GET');
|
|
13
|
+
const headers = new Headers(this.headers || {});
|
|
14
|
+
if (payload && !headers.has('Content-Type')) {
|
|
15
|
+
headers.append('Content-Type', 'application/json');
|
|
16
|
+
}
|
|
17
|
+
const response = await fetch(endpoint, {
|
|
18
|
+
method: method,
|
|
19
|
+
headers: headers,
|
|
20
|
+
body: (method === 'POST' && payload) ? JSON.stringify(payload) : null
|
|
21
|
+
});
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw new Error(`API request failed with status ${response.status}`);
|
|
24
|
+
}
|
|
25
|
+
return response.json();
|
|
26
|
+
}
|
|
27
|
+
clone(relativePath) {
|
|
28
|
+
const clone = new RestApiService(this.apiEndpoint, this.headers, this.method);
|
|
29
|
+
clone.relativePath = relativePath ?? '';
|
|
30
|
+
return clone;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Register a RestApiService with the default name 'default' and the base URL of the current page
|
|
34
|
+
services.container.registerInstance('default', new RestApiService(document.querySelector('base[href]')?.getAttribute('href') || window.location.origin));
|
|
35
|
+
// Sugar for registering a RestApiService with registerRestApi('myName', 'https://my.api.com')
|
|
36
|
+
export function registerRestApi(name, apiEndpoint, headers = { 'Content-Type': 'application/json' }, method) {
|
|
37
|
+
services.container.registerInstance(name, new RestApiService(apiEndpoint, headers, method));
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=RestApiService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RestApiService.js","sourceRoot":"","sources":["RestApiService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,cAAc;IAOvB,YAAY,WAAmB,EAAE,UAAuB,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,SAAwB,IAAI;QAFrH,iBAAY,GAAW,EAAE,CAAC;QAG7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC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AAiG;AACjG,QAAQ,CAAC,SAAS,CAAC,gBAAgB,CAAc,SAAS,EAAE,IAAI,cAAc,CAAC,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtK,8FAA8F;AAC9F,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,WAAmB,EAAE,UAAuB,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,MAAsB;IACpJ,QAAQ,CAAC,SAAS,CAAC,gBAAgB,CAAc,IAAI,EAAE,IAAI,cAAc,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAC7G,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { IApiService } from "./IApiService.js";
|
|
2
|
+
import { substitute } from "./Library.js";
|
|
3
|
+
import { services } from "./Services.js";
|
|
4
|
+
|
|
5
|
+
export class RestApiService implements IApiService {
|
|
6
|
+
|
|
7
|
+
private headers: HeadersInit;
|
|
8
|
+
private apiEndpoint: string;
|
|
9
|
+
private method: string | null;
|
|
10
|
+
public relativePath: string = '';
|
|
11
|
+
|
|
12
|
+
constructor(apiEndpoint: string, headers: HeadersInit = { 'Content-Type': 'application/json' }, method: string | null = null) {
|
|
13
|
+
this.apiEndpoint = apiEndpoint;
|
|
14
|
+
this.headers = headers;
|
|
15
|
+
this.method = method;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async fetch(relativePath: string | null, payload?: Record<string, string> | null | undefined): Promise<any> {
|
|
19
|
+
const endpoint = substitute(new URL(relativePath ?? this.relativePath, this.apiEndpoint).href, payload);
|
|
20
|
+
const method = this.method ?? (payload ? 'POST' : 'GET');
|
|
21
|
+
const headers = new Headers(this.headers || {});
|
|
22
|
+
if (payload && !headers.has('Content-Type')) {
|
|
23
|
+
headers.append('Content-Type', 'application/json');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const response = await fetch(endpoint, {
|
|
27
|
+
method: method,
|
|
28
|
+
headers: headers,
|
|
29
|
+
body: (method === 'POST' && payload) ? JSON.stringify(payload) : null
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new Error(`API request failed with status ${response.status}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return response.json();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
clone(relativePath: string | null): IApiService {
|
|
40
|
+
const clone = new RestApiService(this.apiEndpoint, this.headers, this.method);
|
|
41
|
+
clone.relativePath = relativePath ?? '';
|
|
42
|
+
return clone;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Register a RestApiService with the default name 'default' and the base URL of the current page
|
|
47
|
+
services.container.registerInstance<IApiService>('default', new RestApiService(document.querySelector('base[href]')?.getAttribute('href') || window.location.origin));
|
|
48
|
+
|
|
49
|
+
// Sugar for registering a RestApiService with registerRestApi('myName', 'https://my.api.com')
|
|
50
|
+
export function registerRestApi(name: string, apiEndpoint: string, headers: HeadersInit = { 'Content-Type': 'application/json' }, method?: string | null) {
|
|
51
|
+
services.container.registerInstance<IApiService>(name, new RestApiService(apiEndpoint, headers, method));
|
|
52
|
+
}
|
package/src/qbo-api.d.ts
ADDED
package/src/qbo-api.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { LitElement, html } from 'lit';
|
|
11
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
12
|
+
import { registerRestApi } from './RestApiService.js';
|
|
13
|
+
let QboApiElement = class QboApiElement extends LitElement {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.name = null;
|
|
17
|
+
this.apiEndpoint = null;
|
|
18
|
+
}
|
|
19
|
+
connectedCallback() {
|
|
20
|
+
super.connectedCallback();
|
|
21
|
+
const headers = {};
|
|
22
|
+
if (this.name == null)
|
|
23
|
+
console.error('qbo-api name is required.');
|
|
24
|
+
if (this.apiEndpoint == null)
|
|
25
|
+
console.error('qbo-api apiEndpoint is required.');
|
|
26
|
+
const headerElements = this.querySelectorAll('header');
|
|
27
|
+
headerElements.forEach(header => {
|
|
28
|
+
const name = header.getAttribute('name');
|
|
29
|
+
const value = header.textContent;
|
|
30
|
+
if (name && value) {
|
|
31
|
+
headers[name] = value;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
// Adjust for correct header naming convention, if necessary
|
|
35
|
+
if (headers['ContentType']) {
|
|
36
|
+
headers['Content-Type'] = headers['ContentType'];
|
|
37
|
+
delete headers['ContentType'];
|
|
38
|
+
}
|
|
39
|
+
// container.registerInstance<IApiService>(this.name!, new RestApiService(this.apiEndpoint!, headers, this.method));
|
|
40
|
+
// Call the registerRestApi function with the extracted configuration
|
|
41
|
+
if (!this.apiEndpoint?.startsWith("http"))
|
|
42
|
+
this.apiEndpoint = new URL(this.apiEndpoint ?? '', document.location.origin).href;
|
|
43
|
+
registerRestApi(this.name, this.apiEndpoint, headers, this.method);
|
|
44
|
+
}
|
|
45
|
+
render() {
|
|
46
|
+
// Render nothing, as this component is for configuration purposes only
|
|
47
|
+
return html ``;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
__decorate([
|
|
51
|
+
property({ type: String }),
|
|
52
|
+
__metadata("design:type", Object)
|
|
53
|
+
], QboApiElement.prototype, "name", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
property({ type: String }),
|
|
56
|
+
__metadata("design:type", Object)
|
|
57
|
+
], QboApiElement.prototype, "apiEndpoint", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
property(),
|
|
60
|
+
__metadata("design:type", Object)
|
|
61
|
+
], QboApiElement.prototype, "method", void 0);
|
|
62
|
+
QboApiElement = __decorate([
|
|
63
|
+
customElement('qbo-api')
|
|
64
|
+
], QboApiElement);
|
|
65
|
+
export { QboApiElement };
|
|
66
|
+
//# sourceMappingURL=qbo-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qbo-api.js","sourceRoot":"","sources":["qbo-api.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG/C,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,UAAU;IAAtC;;QAEH,SAAI,GAAkB,IAAI,CAAC;QAG3B,gBAAW,GAAkB,IAAI,CAAC;IA0CtC,CAAC;IArCG,iBAAiB;QACb,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAE1B,MAAM,OAAO,GAAgB,EAAE,CAAC;QAEhC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI;YACjB,OAAO,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI;YACxB,OAAO,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAEtD,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAA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
import { LitElement, html } from 'lit';
|
|
2
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
3
|
+
import { registerRestApi } from './RestApiService.js';
|
|
4
|
+
|
|
5
|
+
@customElement('qbo-api')
|
|
6
|
+
export class QboApiElement extends LitElement {
|
|
7
|
+
@property({ type: String })
|
|
8
|
+
name: string | null = null;
|
|
9
|
+
|
|
10
|
+
@property({ type: String })
|
|
11
|
+
apiEndpoint: string | null = null;
|
|
12
|
+
|
|
13
|
+
@property()
|
|
14
|
+
method: string | undefined;
|
|
15
|
+
|
|
16
|
+
connectedCallback() {
|
|
17
|
+
super.connectedCallback();
|
|
18
|
+
|
|
19
|
+
const headers: HeadersInit = {};
|
|
20
|
+
|
|
21
|
+
if (this.name == null)
|
|
22
|
+
console.error('qbo-api name is required.');
|
|
23
|
+
if (this.apiEndpoint == null)
|
|
24
|
+
console.error('qbo-api apiEndpoint is required.');
|
|
25
|
+
|
|
26
|
+
const headerElements = this.querySelectorAll('header');
|
|
27
|
+
headerElements.forEach(header => {
|
|
28
|
+
const name = header.getAttribute('name');
|
|
29
|
+
const value = header.textContent;
|
|
30
|
+
if (name && value) {
|
|
31
|
+
headers[name] = value;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Adjust for correct header naming convention, if necessary
|
|
36
|
+
if (headers['ContentType']) {
|
|
37
|
+
headers['Content-Type'] = headers['ContentType'];
|
|
38
|
+
delete headers['ContentType'];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// container.registerInstance<IApiService>(this.name!, new RestApiService(this.apiEndpoint!, headers, this.method));
|
|
42
|
+
|
|
43
|
+
// Call the registerRestApi function with the extracted configuration
|
|
44
|
+
if (!this.apiEndpoint?.startsWith("http"))
|
|
45
|
+
this.apiEndpoint = new URL(this.apiEndpoint ?? '', document.location.origin).href;
|
|
46
|
+
registerRestApi(this.name!, this.apiEndpoint!, headers, this.method);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
render() {
|
|
50
|
+
// Render nothing, as this component is for configuration purposes only
|
|
51
|
+
return html``;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|