@dizmo/dcs-client-library 4.0.1
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/LICENSE +13 -0
- package/README.md +67 -0
- package/dist/data/errorTypes/errorTypes.de.d.ts +3 -0
- package/dist/data/errorTypes/errorTypes.de.js +20 -0
- package/dist/data/errorTypes/errorTypes.en.d.ts +3 -0
- package/dist/data/errorTypes/errorTypes.en.js +20 -0
- package/dist/data/errorTypes/errorTypes.es.d.ts +3 -0
- package/dist/data/errorTypes/errorTypes.es.js +4 -0
- package/dist/data/errorTypes/errorTypes.fr.d.ts +3 -0
- package/dist/data/errorTypes/errorTypes.fr.js +4 -0
- package/dist/data/errorTypes/errorTypes.it.d.ts +3 -0
- package/dist/data/errorTypes/errorTypes.it.js +4 -0
- package/dist/data/errorTypes.dev.d.ts +3 -0
- package/dist/data/errorTypes.dev.js +71 -0
- package/dist/helper/api.d.ts +2 -0
- package/dist/helper/api.js +25 -0
- package/dist/helper/httpHelper.d.ts +32 -0
- package/dist/helper/httpHelper.js +145 -0
- package/dist/helper/language.d.ts +5 -0
- package/dist/helper/language.js +69 -0
- package/dist/helper/parse.d.ts +8 -0
- package/dist/helper/parse.js +28 -0
- package/dist/helper/token.d.ts +1 -0
- package/dist/helper/token.js +28 -0
- package/dist/helper/transform.d.ts +3 -0
- package/dist/helper/transform.js +18 -0
- package/dist/helper/validate.d.ts +4 -0
- package/dist/helper/validate.js +21 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +15 -0
- package/dist/modules/allocations.d.ts +29 -0
- package/dist/modules/allocations.js +148 -0
- package/dist/modules/analytics.d.ts +7 -0
- package/dist/modules/analytics.js +33 -0
- package/dist/modules/configurator.d.ts +8 -0
- package/dist/modules/configurator.js +10 -0
- package/dist/modules/dcs.d.ts +32 -0
- package/dist/modules/dcs.js +130 -0
- package/dist/modules/events.d.ts +5 -0
- package/dist/modules/events.js +10 -0
- package/dist/modules/items.d.ts +21 -0
- package/dist/modules/items.js +70 -0
- package/dist/modules/language.d.ts +18 -0
- package/dist/modules/language.js +106 -0
- package/dist/modules/needs.d.ts +12 -0
- package/dist/modules/needs.js +35 -0
- package/dist/modules/packages.d.ts +16 -0
- package/dist/modules/packages.js +71 -0
- package/dist/modules/templates.d.ts +19 -0
- package/dist/modules/templates.js +64 -0
- package/dist/modules/translations.d.ts +6 -0
- package/dist/modules/translations.js +17 -0
- package/dist/types/types.d.ts +589 -0
- package/dist/types/types.js +1 -0
- package/package.json +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright (c) 2026 dizmo AG, Switzerland. All rights reserved.
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
4
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
|
5
|
+
and this permission notice appear in all copies.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
9
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
11
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
12
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
13
|
+
THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# DCS Client Library
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
Add the following dependency to the dizmo's package.json file.
|
|
5
|
+
```json
|
|
6
|
+
"@dizmo/dcs-client-library": "^4.0.0"
|
|
7
|
+
```
|
|
8
|
+
Or install with
|
|
9
|
+
```
|
|
10
|
+
npm i @dizmo/dcs-client-library
|
|
11
|
+
```
|
|
12
|
+
## Usage
|
|
13
|
+
The modules for the different data types are separated and can be individually imported
|
|
14
|
+
```js
|
|
15
|
+
import { templates, items, allocations, dcs, config, events, analytics, language, needs, packages, translations } from '@dizmo/dcs-client-library'
|
|
16
|
+
|
|
17
|
+
// Most functions throw errors, so they can be caught when they are called
|
|
18
|
+
try {
|
|
19
|
+
const allItems = await items.getItems2()
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error(e)
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
## API Documentation
|
|
25
|
+
The modules all have separate documentation files to keep this main README short and concise.
|
|
26
|
+
|
|
27
|
+
### Templates Module
|
|
28
|
+
Contains all template-related functions of the DCS.
|
|
29
|
+
Documentation can be found [here](./documentation/templates/templates.md).
|
|
30
|
+
### Items Module
|
|
31
|
+
Contains all item-related functions of the DCS.
|
|
32
|
+
Documentation can be found [here](./documentation/items/items.md).
|
|
33
|
+
### Allocations Module
|
|
34
|
+
Contains all allocation-related functions of the DCS.
|
|
35
|
+
Documentation can be found [here](./documentation/allocations/allocations.md).
|
|
36
|
+
### DCS Module
|
|
37
|
+
Contains all company and system-related functions of the DCS.
|
|
38
|
+
Documentation can be found [here](./documentation/dcs/dcs.md).
|
|
39
|
+
### Analytics Module
|
|
40
|
+
Contains the analytics functionality to process database data.
|
|
41
|
+
Documentation can be found [here](./documentation/analytics/analytics.md).
|
|
42
|
+
### Config Module
|
|
43
|
+
Contains library configuration functions.
|
|
44
|
+
Documentation can be found [here](./documentation/config/config.md).
|
|
45
|
+
### Language Module
|
|
46
|
+
Contains all language and translation related functions.
|
|
47
|
+
Documentation can be found [here](./documentation/language/language.md).
|
|
48
|
+
|
|
49
|
+
### Events Module
|
|
50
|
+
Contains the function that informs the client on database updates.
|
|
51
|
+
Documentation can be found [here](./documentation/events/events.md).
|
|
52
|
+
|
|
53
|
+
### Needs Module
|
|
54
|
+
Contains functions for creating and managing needs (requirements/demands).
|
|
55
|
+
Documentation can be found [here](./documentation/needs/needs.md).
|
|
56
|
+
|
|
57
|
+
### Packages Module
|
|
58
|
+
Contains functions for creating and managing allocation packages (reusable allocation templates).
|
|
59
|
+
Documentation can be found [here](./documentation/packages/packages.md).
|
|
60
|
+
|
|
61
|
+
### Translations Module
|
|
62
|
+
Contains DeepL translation API integration for translating text content.
|
|
63
|
+
Documentation can be found [here](./documentation/translations/translations.md).
|
|
64
|
+
|
|
65
|
+
### Data Structures
|
|
66
|
+
Common data structures used across modules.
|
|
67
|
+
Documentation can be found [here](./documentation/datastructures/datastructures.md).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const messages = {
|
|
2
|
+
fileNotSupplied: "Datei muss bereitgestellt werden",
|
|
3
|
+
invalidApiURL: "Keine gültige URL, um als API-Endpunkt festgelegt zu werden",
|
|
4
|
+
noProgramSpecified: "Der Programmname muss angegeben werden, wenn die Sprache für eine Nicht-Dizmo-Anwendung abgerufen wird.",
|
|
5
|
+
updateItemsInvalidArguments: "Datei, Vorlagenname und Primärschlüssel müssen bereitgestellt werden",
|
|
6
|
+
stringError: "{param1} muss ein nicht leerer String sein.",
|
|
7
|
+
objectError: "{param1} muss ein Objekt sein.",
|
|
8
|
+
numberError: "{param1} muss eine positive Zahl sein.",
|
|
9
|
+
arrayError: "{param1} muss ein Array sein.",
|
|
10
|
+
dzaccessTokenNotFound: "dzaccess-Token nicht gefunden",
|
|
11
|
+
loginBundleNotFound: "Das Login-Dizmo-Bundle konnte nicht gefunden werden. Ist es in Ihrer Sitzung installiert?",
|
|
12
|
+
tokenGetError: "Fehler beim Abrufen des Tokens aus dem Login-Dizmo-Bundle.",
|
|
13
|
+
notLoggedIn: "Das aus dem Login-Dizmo-Bundle abgerufene Token existiert nicht. Sind Sie im Login-Dizmo angemeldet?",
|
|
14
|
+
invalidToken: "Kann keine Anfrage an die API mit dem Token durchführen: {param1}",
|
|
15
|
+
bodyParseError: "Kann den bereitgestellten Anfragekörper nicht verarbeiten.",
|
|
16
|
+
fileError: "Kann die bereitgestellte Datei nicht verarbeiten.",
|
|
17
|
+
apiUnreachable: "Kann den API-Server nicht erreichen.",
|
|
18
|
+
itemIdNotExists: "Die Ressource die Sie zuweisen möchten wurde noch nicht gespeichert. Bitte speichern Sie Ihre Änderungen in der Ressource bevor Sie die Zuweisung erstellen.",
|
|
19
|
+
};
|
|
20
|
+
export default messages;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const messages = {
|
|
2
|
+
fileNotSupplied: "File must be supplied",
|
|
3
|
+
invalidApiURL: "Not a valid URL to be set as API Endpoint",
|
|
4
|
+
noProgramSpecified: "The program name must be specified when getting the language for a non-dizmo application.",
|
|
5
|
+
updateItemsInvalidArguments: "File, templateName and PrimaryKey must be supplied",
|
|
6
|
+
stringError: "{param1} must be a non-empty string.",
|
|
7
|
+
objectError: "{param1} must be an object.",
|
|
8
|
+
numberError: "{param1} must be a positive number.",
|
|
9
|
+
arrayError: "{param1} must be an array.",
|
|
10
|
+
dzaccessTokenNotFound: "dzaccess token not found",
|
|
11
|
+
loginBundleNotFound: "Login dizmo bundle could not be found. Is it installed in your session?",
|
|
12
|
+
tokenGetError: "Error getting token from login dizmo bundle.",
|
|
13
|
+
notLoggedIn: "Token retrieved from login dizmo bundle does not exist. Are you logged in on the login dizmo?",
|
|
14
|
+
invalidToken: "Cannot make a request to the API with the token: {param1}",
|
|
15
|
+
bodyParseError: "Cannot process the supplied request body.",
|
|
16
|
+
fileError: "Cannot process the supplied file.",
|
|
17
|
+
apiUnreachable: "Cannot reach the API server.",
|
|
18
|
+
itemIdNotExists: "The Resource you tried to allocate has not yet been saved. Please save your changes in the resource before creating an allocation",
|
|
19
|
+
};
|
|
20
|
+
export default messages;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const messages = {
|
|
2
|
+
fileNotSupplied: {
|
|
3
|
+
message: "File must be supplied",
|
|
4
|
+
number: 100,
|
|
5
|
+
},
|
|
6
|
+
invalidApiURL: {
|
|
7
|
+
message: "Not a valid URL to be set as API Endpoint",
|
|
8
|
+
number: 101,
|
|
9
|
+
},
|
|
10
|
+
noProgramSpecified: {
|
|
11
|
+
message: "The program name must be specified when getting the language for a non-dizmo application.",
|
|
12
|
+
number: 102,
|
|
13
|
+
},
|
|
14
|
+
updateItemsInvalidArguments: {
|
|
15
|
+
message: "File, templateName and PrimaryKey must be supplied",
|
|
16
|
+
number: 103,
|
|
17
|
+
},
|
|
18
|
+
stringError: {
|
|
19
|
+
message: "{param1} must be a non-empty string.",
|
|
20
|
+
number: 104,
|
|
21
|
+
},
|
|
22
|
+
objectError: {
|
|
23
|
+
message: "{param1} must be an object.",
|
|
24
|
+
number: 105,
|
|
25
|
+
},
|
|
26
|
+
numberError: {
|
|
27
|
+
message: "{param1} must be a positive number.",
|
|
28
|
+
number: 106,
|
|
29
|
+
},
|
|
30
|
+
arrayError: {
|
|
31
|
+
message: "{param1} must be an array.",
|
|
32
|
+
number: 107,
|
|
33
|
+
},
|
|
34
|
+
dzaccessTokenNotFound: {
|
|
35
|
+
message: "dzaccess token not found",
|
|
36
|
+
number: 108,
|
|
37
|
+
},
|
|
38
|
+
loginBundleNotFound: {
|
|
39
|
+
message: "Login dizmo bundle could not be found. Is it installed in your session?",
|
|
40
|
+
number: 109,
|
|
41
|
+
},
|
|
42
|
+
tokenGetError: {
|
|
43
|
+
message: "Error getting token from login dizmo bundle.",
|
|
44
|
+
number: 110,
|
|
45
|
+
},
|
|
46
|
+
notLoggedIn: {
|
|
47
|
+
message: "Token retrieved from login dizmo bundle does not exist. Are you logged in on the login dizmo?",
|
|
48
|
+
number: 111,
|
|
49
|
+
},
|
|
50
|
+
invalidToken: {
|
|
51
|
+
message: "Cannot make a request to the API with the token: {param1}",
|
|
52
|
+
number: 112,
|
|
53
|
+
},
|
|
54
|
+
bodyParseError: {
|
|
55
|
+
message: "Cannot process the supplied request body.",
|
|
56
|
+
number: 113,
|
|
57
|
+
},
|
|
58
|
+
fileError: {
|
|
59
|
+
message: "Cannot process the supplied file.",
|
|
60
|
+
number: 114,
|
|
61
|
+
},
|
|
62
|
+
apiUnreachable: {
|
|
63
|
+
message: "Cannot reach the API server.",
|
|
64
|
+
number: 115,
|
|
65
|
+
},
|
|
66
|
+
itemIdNotExists: {
|
|
67
|
+
message: "The Resource you tried to allocate does not yet exist. Please save your changes before creating an allocation",
|
|
68
|
+
number: 116,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
export default messages;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { generateError } from "./language";
|
|
2
|
+
const APIURL = "/dcsapi";
|
|
3
|
+
let customAPIURL = "";
|
|
4
|
+
export function baseUrl(apiVersion = "v1") {
|
|
5
|
+
if (!customAPIURL) {
|
|
6
|
+
return `${APIURL}/${apiVersion}`;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
return `${customAPIURL}/${apiVersion}`;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function setCustomAPIURL(url) {
|
|
13
|
+
if (url.startsWith("/")) {
|
|
14
|
+
// relative url
|
|
15
|
+
customAPIURL = url;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const parsedURL = new URL(url);
|
|
20
|
+
customAPIURL = parsedURL.href;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw generateError("invalidApiURL");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
|
|
2
|
+
export declare function getRequestOptions(type: HttpMethod, token: string, body?: unknown, contentType?: string): RequestInit;
|
|
3
|
+
export declare function getFileUploadRequestOptions(token: string, file: File, body?: {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
}, method?: HttpMethod, filename?: string): {
|
|
6
|
+
method: HttpMethod;
|
|
7
|
+
cache: "no-cache";
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization?: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
body: FormData;
|
|
12
|
+
};
|
|
13
|
+
export declare function getData(url: string, options: RequestInit, apiVersion?: string, throwFullError?: boolean, addlErrorData?: Record<string, unknown>): Promise<unknown>;
|
|
14
|
+
export declare function getZip(url: string, options: RequestInit, filename?: string): Promise<void>;
|
|
15
|
+
export declare function getFile(url: string, options: RequestInit): Promise<{
|
|
16
|
+
successOnAPI: boolean;
|
|
17
|
+
isDCSFile: boolean;
|
|
18
|
+
fileCategory: undefined;
|
|
19
|
+
fileType: undefined;
|
|
20
|
+
originalURL: string;
|
|
21
|
+
blobURL: undefined;
|
|
22
|
+
previewURL: string;
|
|
23
|
+
} | {
|
|
24
|
+
successOnAPI: boolean;
|
|
25
|
+
isDCSFile: boolean;
|
|
26
|
+
fileCategory: string | undefined;
|
|
27
|
+
fileType: string | null;
|
|
28
|
+
originalURL: string;
|
|
29
|
+
blobURL: string;
|
|
30
|
+
previewURL: string;
|
|
31
|
+
}>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as api from "./api.js";
|
|
2
|
+
import { generateError } from "./language.js";
|
|
3
|
+
function handleNetworkError(_error) {
|
|
4
|
+
throw generateError("apiUnreachable");
|
|
5
|
+
}
|
|
6
|
+
async function parseResponseBody(response) {
|
|
7
|
+
const text = await response.text();
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(text);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return text;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function getRequestOptions(type, token, body, contentType = "json") {
|
|
16
|
+
let requestOptions = {
|
|
17
|
+
method: type,
|
|
18
|
+
cache: "no-cache",
|
|
19
|
+
headers: {
|
|
20
|
+
"Content-Type": `application/${contentType}`,
|
|
21
|
+
...(token.trim() && { Authorization: `Bearer ${token}` }),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
if (body) {
|
|
25
|
+
try {
|
|
26
|
+
requestOptions.body = JSON.stringify(body);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
throw generateError("bodyParseError");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return requestOptions;
|
|
33
|
+
}
|
|
34
|
+
export function getFileUploadRequestOptions(token, file, body = {}, method = "POST", filename = "") {
|
|
35
|
+
let formdata;
|
|
36
|
+
try {
|
|
37
|
+
formdata = new FormData();
|
|
38
|
+
formdata.append(filename ?? "", file, file.name ?? "undefined");
|
|
39
|
+
Object.keys(body).forEach((param) => {
|
|
40
|
+
formdata.append(param, body[param]);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
throw generateError("fileError");
|
|
45
|
+
}
|
|
46
|
+
const requestOptions = {
|
|
47
|
+
method: method,
|
|
48
|
+
cache: "no-cache",
|
|
49
|
+
headers: {
|
|
50
|
+
...(token.trim() && { Authorization: `Bearer ${token}` }),
|
|
51
|
+
},
|
|
52
|
+
body: formdata,
|
|
53
|
+
};
|
|
54
|
+
return requestOptions;
|
|
55
|
+
}
|
|
56
|
+
export async function getData(url, options, apiVersion = "v1", throwFullError = false, addlErrorData = {}) {
|
|
57
|
+
let response;
|
|
58
|
+
try {
|
|
59
|
+
response = await fetch(api.baseUrl(apiVersion) + url, options);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
handleNetworkError(error);
|
|
63
|
+
}
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
const body = await parseResponseBody(response);
|
|
66
|
+
if (typeof body === "object" && body !== null) {
|
|
67
|
+
const errorObj = body;
|
|
68
|
+
if (throwFullError) {
|
|
69
|
+
if (errorObj.data) {
|
|
70
|
+
const throwThing = errorObj;
|
|
71
|
+
throwThing.clientErrorData = addlErrorData;
|
|
72
|
+
throwThing.clientErrorData.conflicting_allocations = errorObj.data;
|
|
73
|
+
throw throwThing;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
throw errorObj.userMessage ?? body;
|
|
77
|
+
}
|
|
78
|
+
throw body;
|
|
79
|
+
}
|
|
80
|
+
return await parseResponseBody(response);
|
|
81
|
+
}
|
|
82
|
+
export async function getZip(url, options, filename = "backup") {
|
|
83
|
+
let response;
|
|
84
|
+
try {
|
|
85
|
+
response = await fetch(api.baseUrl() + url, options);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
handleNetworkError(error);
|
|
89
|
+
}
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
const body = await parseResponseBody(response);
|
|
92
|
+
if (typeof body === "object" && body !== null) {
|
|
93
|
+
throw body.userMessage ?? body;
|
|
94
|
+
}
|
|
95
|
+
throw body;
|
|
96
|
+
}
|
|
97
|
+
const file = await response.blob();
|
|
98
|
+
const elm = document.createElement("a");
|
|
99
|
+
elm.href = URL.createObjectURL(file);
|
|
100
|
+
elm.setAttribute("download", `${filename}.zip`);
|
|
101
|
+
elm.click();
|
|
102
|
+
}
|
|
103
|
+
export async function getFile(url, options) {
|
|
104
|
+
if (!url.startsWith(window.location.origin)) {
|
|
105
|
+
return {
|
|
106
|
+
successOnAPI: false,
|
|
107
|
+
isDCSFile: false,
|
|
108
|
+
fileCategory: undefined,
|
|
109
|
+
fileType: undefined,
|
|
110
|
+
originalURL: url,
|
|
111
|
+
blobURL: undefined,
|
|
112
|
+
previewURL: url,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
let response;
|
|
116
|
+
try {
|
|
117
|
+
response = await fetch(url, options);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
handleNetworkError(error);
|
|
121
|
+
}
|
|
122
|
+
if (!response.ok) {
|
|
123
|
+
return {
|
|
124
|
+
successOnAPI: false,
|
|
125
|
+
isDCSFile: true,
|
|
126
|
+
fileCategory: undefined,
|
|
127
|
+
fileType: undefined,
|
|
128
|
+
originalURL: url,
|
|
129
|
+
blobURL: undefined,
|
|
130
|
+
previewURL: url,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const contentType = response.headers.get("content-type");
|
|
134
|
+
const blob = await response.blob();
|
|
135
|
+
const fileURL = URL.createObjectURL(blob);
|
|
136
|
+
return {
|
|
137
|
+
successOnAPI: true,
|
|
138
|
+
isDCSFile: true,
|
|
139
|
+
fileCategory: contentType?.split("/")[0] ?? undefined,
|
|
140
|
+
fileType: contentType,
|
|
141
|
+
originalURL: url,
|
|
142
|
+
blobURL: fileURL,
|
|
143
|
+
previewURL: fileURL,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ErrorParams, LanguageObj } from "../types/types.js";
|
|
2
|
+
export declare function initializeErrorLanguage(): void;
|
|
3
|
+
export declare function getMostSuitedLanguage(supportedLanguages: string[], defaultLanguage: string): string;
|
|
4
|
+
export declare function generateError(type: string, params?: ErrorParams): string;
|
|
5
|
+
export declare function getProgramLanguage(programName?: string): Promise<LanguageObj>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import devMessages from "../data/errorTypes.dev.js";
|
|
2
|
+
import enMessages from "../data/errorTypes/errorTypes.en.js";
|
|
3
|
+
import deMessages from "../data/errorTypes/errorTypes.de.js";
|
|
4
|
+
import frMessages from "../data/errorTypes/errorTypes.fr.js";
|
|
5
|
+
import itMessages from "../data/errorTypes/errorTypes.it.js";
|
|
6
|
+
import esMessages from "../data/errorTypes/errorTypes.es.js";
|
|
7
|
+
import { getData, getRequestOptions } from "./httpHelper.js";
|
|
8
|
+
let rawErrorData = {
|
|
9
|
+
en: enMessages,
|
|
10
|
+
de: deMessages,
|
|
11
|
+
fr: frMessages,
|
|
12
|
+
it: itMessages,
|
|
13
|
+
es: esMessages,
|
|
14
|
+
};
|
|
15
|
+
const errorData = {};
|
|
16
|
+
export function initializeErrorLanguage() {
|
|
17
|
+
try {
|
|
18
|
+
const languages = ["en", "de", "fr", "es", "it"];
|
|
19
|
+
const language = getMostSuitedLanguage(languages, "en");
|
|
20
|
+
for (const errorType of Object.keys(devMessages)) {
|
|
21
|
+
if (!devMessages[errorType]) {
|
|
22
|
+
console.warn(`Missing dcs client library devMessages for errorType: ${errorType}`);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
errorData[errorType] = {
|
|
26
|
+
...errorData[errorType], // Retain any existing data in errorData[errorType]
|
|
27
|
+
errorName: errorType,
|
|
28
|
+
userMessage: rawErrorData[language]?.[errorType] || devMessages[errorType].message,
|
|
29
|
+
devMessage: devMessages[errorType].message,
|
|
30
|
+
errorNumber: devMessages[errorType].number,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
//throw e // Re-throw to allow higher-level handling if necessary
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function getMostSuitedLanguage(supportedLanguages, defaultLanguage) {
|
|
39
|
+
const supportedBrowserLanguages = navigator.languages || [];
|
|
40
|
+
for (const browserLanguage of supportedBrowserLanguages) {
|
|
41
|
+
for (const supportedLanguage of supportedLanguages) {
|
|
42
|
+
if (browserLanguage.startsWith(supportedLanguage.toLowerCase())) {
|
|
43
|
+
return supportedLanguage.toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return defaultLanguage.toLowerCase();
|
|
48
|
+
}
|
|
49
|
+
export function generateError(type, params = {}) {
|
|
50
|
+
const errorType = { ...errorData[type] };
|
|
51
|
+
Object.keys(params).forEach((paramName) => {
|
|
52
|
+
errorType.userMessage = errorType.userMessage.replace(`{${paramName}}`, String(params[paramName]));
|
|
53
|
+
errorType.devMessage = errorType.devMessage.replace(`{${paramName}}`, String(params[paramName]));
|
|
54
|
+
});
|
|
55
|
+
// TODO: change this to the full object once dizmos can handle error object.
|
|
56
|
+
return errorType.userMessage;
|
|
57
|
+
}
|
|
58
|
+
export async function getProgramLanguage(programName = "") {
|
|
59
|
+
const requestOptions = getRequestOptions("GET", "token");
|
|
60
|
+
let programVersion = "";
|
|
61
|
+
if (programName === "") {
|
|
62
|
+
if (typeof bundle === 'undefined') {
|
|
63
|
+
throw generateError("noProgramSpecified");
|
|
64
|
+
}
|
|
65
|
+
programName = bundle.identifier;
|
|
66
|
+
programVersion = bundle.getAttribute("version");
|
|
67
|
+
}
|
|
68
|
+
return (await getData(`/languages/translation/${programName}/${programVersion}`, requestOptions));
|
|
69
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RawTemplate, TemplateResult } from "../types/types.js";
|
|
2
|
+
declare function templates(templateResponseArray: RawTemplate[]): TemplateResult[];
|
|
3
|
+
declare function template(templateResponseArray: RawTemplate[]): TemplateResult;
|
|
4
|
+
declare const _default: {
|
|
5
|
+
templates: typeof templates;
|
|
6
|
+
template: typeof template;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { generateError } from "./language.js";
|
|
2
|
+
function parseTemplateData(data) {
|
|
3
|
+
try {
|
|
4
|
+
return JSON.parse(data);
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
throw generateError("parseTemplateError");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function templates(templateResponseArray) {
|
|
11
|
+
if (!Array.isArray(templateResponseArray)) {
|
|
12
|
+
throw generateError("parseTemplateError");
|
|
13
|
+
}
|
|
14
|
+
return templateResponseArray.map((template) => parseTemplateData(template.properties.data));
|
|
15
|
+
}
|
|
16
|
+
function template(templateResponseArray) {
|
|
17
|
+
if (Array.isArray(templateResponseArray) &&
|
|
18
|
+
templateResponseArray.length === 1) {
|
|
19
|
+
return parseTemplateData(templateResponseArray[0].properties.data);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
throw generateError("parseTemplateError");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default {
|
|
26
|
+
templates,
|
|
27
|
+
template
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getToken(): Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { generateError } from "./language.js";
|
|
2
|
+
export async function getToken() {
|
|
3
|
+
// check if in viewer, else read cookie from browser
|
|
4
|
+
if (typeof viewer === 'undefined') {
|
|
5
|
+
// in webapp. no cookie required.
|
|
6
|
+
return "";
|
|
7
|
+
}
|
|
8
|
+
let token = "";
|
|
9
|
+
let loginBundle;
|
|
10
|
+
try {
|
|
11
|
+
loginBundle = viewer.getBundleById("com.dizmo.dcs.login");
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
throw generateError("loginBundleNotFound");
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const cacheId = await loginBundle.cacheProperty("token", { public: true });
|
|
18
|
+
token = loginBundle.getProperty("token", { public: true });
|
|
19
|
+
loginBundle.uncacheProperty(cacheId, { public: true });
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
throw generateError("tokenGetError");
|
|
23
|
+
}
|
|
24
|
+
if (!Boolean(token)) {
|
|
25
|
+
throw generateError("notLoggedIn");
|
|
26
|
+
}
|
|
27
|
+
return token;
|
|
28
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AllocationResult, AllocationResult3, SpreadAllocationResult, SpreadAllocationResult3 } from "../types/types";
|
|
2
|
+
export declare function transformToSpreadAllocations(allocations: AllocationResult[]): SpreadAllocationResult[];
|
|
3
|
+
export declare function transformToSpreadAllocations3(allocations: AllocationResult3[]): SpreadAllocationResult3[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function transformToSpreadAllocations(allocations) {
|
|
2
|
+
return allocations.map(({ root, relationships }) => ({
|
|
3
|
+
root,
|
|
4
|
+
relationships: relationships.flatMap(({ allocations, leaf, }) => allocations.map((allocation) => ({
|
|
5
|
+
leaf,
|
|
6
|
+
allocation,
|
|
7
|
+
}))),
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
export function transformToSpreadAllocations3(allocations) {
|
|
11
|
+
return allocations.map(({ root, relationships }) => ({
|
|
12
|
+
root,
|
|
13
|
+
relationships: relationships.flatMap(({ allocations, leaf, }) => allocations.map((allocation) => ({
|
|
14
|
+
leaf,
|
|
15
|
+
allocation,
|
|
16
|
+
}))),
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function validateString(input: string, data: string): void;
|
|
2
|
+
export declare function validateObject(object: unknown, data: string): void;
|
|
3
|
+
export declare function validateNumber(input: number, data: string): void;
|
|
4
|
+
export declare function validateArray(array: unknown, data: string): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { generateError } from "./language.js";
|
|
2
|
+
export function validateString(input, data) {
|
|
3
|
+
if (!(typeof input === "string" && input.trim() !== "")) {
|
|
4
|
+
throw generateError("stringError", { param1: data ?? "unknown" });
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export function validateObject(object, data) {
|
|
8
|
+
if (!(typeof object === "object" && object !== null && !Array.isArray(object))) {
|
|
9
|
+
throw generateError("objectError", { param1: data ?? "unknown" });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function validateNumber(input, data) {
|
|
13
|
+
if (!(typeof input === "number" && input > 0)) {
|
|
14
|
+
throw generateError("numberError", { param1: data ?? "unknown" });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function validateArray(array, data) {
|
|
18
|
+
if (!Array.isArray(array)) {
|
|
19
|
+
throw generateError("arrayError", { param1: data ?? "unknown" });
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { config } from "./modules/configurator";
|
|
2
|
+
export { templates } from "./modules/templates";
|
|
3
|
+
export { items } from "./modules/items";
|
|
4
|
+
export { allocations } from "./modules/allocations.js";
|
|
5
|
+
export { dcs } from "./modules/dcs";
|
|
6
|
+
export { analytics } from "./modules/analytics.js";
|
|
7
|
+
export { language } from "./modules/language";
|
|
8
|
+
export { events } from "./modules/events";
|
|
9
|
+
export { needs } from "./modules/needs";
|
|
10
|
+
export { packages } from "./modules/packages";
|
|
11
|
+
export { translations } from "./modules/translations";
|