@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/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as languageHelper from "./helper/language.js";
|
|
2
|
+
(async () => {
|
|
3
|
+
languageHelper.initializeErrorLanguage();
|
|
4
|
+
})();
|
|
5
|
+
export { config } from "./modules/configurator";
|
|
6
|
+
export { templates } from "./modules/templates";
|
|
7
|
+
export { items } from "./modules/items";
|
|
8
|
+
export { allocations } from "./modules/allocations.js";
|
|
9
|
+
export { dcs } from "./modules/dcs";
|
|
10
|
+
export { analytics } from "./modules/analytics.js";
|
|
11
|
+
export { language } from "./modules/language";
|
|
12
|
+
export { events } from "./modules/events";
|
|
13
|
+
export { needs } from "./modules/needs";
|
|
14
|
+
export { packages } from "./modules/packages";
|
|
15
|
+
export { translations } from "./modules/translations";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AllocFilter, AllocOptions, AllocSort, AllocationResult, AllocationResult3, BulkCommand, BulkOperationOptions, BulkOperationResult, CreateAlloc, CreateResult, DeleteResult, EditOrDeletionType, RepetitionCreateResult, RepetitionInfo, SpreadAllocationResult, SpreadAllocationResult3, UpdateAlloc } from "../types/types.js";
|
|
2
|
+
declare function getAllocations2(filter?: AllocFilter, paging?: AllocOptions, sort?: AllocSort): Promise<AllocationResult[] | SpreadAllocationResult[]>;
|
|
3
|
+
declare function getAllocations3(filter?: AllocFilter, paging?: AllocOptions, sort?: AllocSort): Promise<AllocationResult3[] | SpreadAllocationResult3[]>;
|
|
4
|
+
export declare function bulkOperation(operations: BulkCommand, options?: BulkOperationOptions): Promise<BulkOperationResult>;
|
|
5
|
+
declare function createAllocation(itemId1: string, itemId2: string, allocationInfo: CreateAlloc): Promise<CreateResult>;
|
|
6
|
+
declare function updateAllocation(allocationId?: string, allocationInfo?: UpdateAlloc): Promise<CreateResult>;
|
|
7
|
+
declare function deleteAllocation(allocationId?: string): Promise<BulkOperationResult>;
|
|
8
|
+
/**
|
|
9
|
+
* DEPRECATED: use getAllocations2
|
|
10
|
+
*/
|
|
11
|
+
declare function getAllocations(filter?: {}, paging?: {}): Promise<AllocationResult[]>;
|
|
12
|
+
declare function updateAllocations(file: File, keepData?: boolean): Promise<DeleteResult>;
|
|
13
|
+
declare function createRepeatedAllocations(itemId1: string, itemId2: string, allocationInfo: CreateAlloc, repetitionInfo: RepetitionInfo): Promise<RepetitionCreateResult>;
|
|
14
|
+
declare function deleteRepeatedAllocations(repetitionId: string, deletionType: EditOrDeletionType, timestamp: number): Promise<DeleteResult>;
|
|
15
|
+
declare function updateRepeatedAllocations(repetitionId: string, editType: EditOrDeletionType, timestamp: number, allocationInfo: UpdateAlloc): Promise<RepetitionCreateResult>;
|
|
16
|
+
export declare const allocations: {
|
|
17
|
+
getAllocations2: typeof getAllocations2;
|
|
18
|
+
getAllocations3: typeof getAllocations3;
|
|
19
|
+
bulkOperation: typeof bulkOperation;
|
|
20
|
+
createAllocation: typeof createAllocation;
|
|
21
|
+
getAllocations: typeof getAllocations;
|
|
22
|
+
deleteAllocation: typeof deleteAllocation;
|
|
23
|
+
updateAllocation: typeof updateAllocation;
|
|
24
|
+
updateAllocations: typeof updateAllocations;
|
|
25
|
+
createRepeatedAllocations: typeof createRepeatedAllocations;
|
|
26
|
+
deleteRepeatedAllocations: typeof deleteRepeatedAllocations;
|
|
27
|
+
updateRepeatedAllocations: typeof updateRepeatedAllocations;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { getToken } from "../helper/token.js";
|
|
2
|
+
import { getRequestOptions, getData, getFileUploadRequestOptions, } from "../helper/httpHelper.js";
|
|
3
|
+
import { validateString, validateObject, validateNumber, } from "../helper/validate.js";
|
|
4
|
+
import { generateError } from "../helper/language.js";
|
|
5
|
+
import { transformToSpreadAllocations, transformToSpreadAllocations3 } from "../helper/transform.js";
|
|
6
|
+
// the new getAllocations function that allows advanced filtering
|
|
7
|
+
// will replace the existing call once all clients have updated their
|
|
8
|
+
// code to this function
|
|
9
|
+
async function getAllocations2(filter = {}, paging = {}, sort = {}) {
|
|
10
|
+
validateObject(filter, "Function: getAllocations2, Value: filter");
|
|
11
|
+
validateObject(paging, "Function: getAllocations2, Value: paging");
|
|
12
|
+
validateObject(sort, "Function: getAllocations2, Value: sort");
|
|
13
|
+
const token = await getToken();
|
|
14
|
+
const bodyObj = {
|
|
15
|
+
filter,
|
|
16
|
+
paging,
|
|
17
|
+
sort,
|
|
18
|
+
};
|
|
19
|
+
const requestOptions = getRequestOptions("POST", token, bodyObj);
|
|
20
|
+
// specify v2 in call
|
|
21
|
+
const result = (await getData(`/allocations/allocation`, requestOptions, "v2"));
|
|
22
|
+
if (paging.spreadAllocations) {
|
|
23
|
+
return transformToSpreadAllocations(result);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
// v3 getAllocations - same as v2 but without automatic _datatype: "item" filter
|
|
28
|
+
// allows querying allocations for non-item types (e.g. packages, needs)
|
|
29
|
+
async function getAllocations3(filter = {}, paging = {}, sort = {}) {
|
|
30
|
+
validateObject(filter, "Function: getAllocations3, Value: filter");
|
|
31
|
+
validateObject(paging, "Function: getAllocations3, Value: paging");
|
|
32
|
+
validateObject(sort, "Function: getAllocations3, Value: sort");
|
|
33
|
+
const token = await getToken();
|
|
34
|
+
const bodyObj = {
|
|
35
|
+
filter,
|
|
36
|
+
paging,
|
|
37
|
+
sort,
|
|
38
|
+
};
|
|
39
|
+
const requestOptions = getRequestOptions("POST", token, bodyObj);
|
|
40
|
+
const result = (await getData(`/allocations/allocation`, requestOptions, "v3"));
|
|
41
|
+
if (paging.spreadAllocations) {
|
|
42
|
+
return transformToSpreadAllocations3(result);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
export async function bulkOperation(operations, options = {}) {
|
|
47
|
+
// options can be "type": "package", "bulk"
|
|
48
|
+
validateObject(operations, "Function: bulkOperation, Value: operations");
|
|
49
|
+
validateObject(options, "Function: bulkOperation, Value: options");
|
|
50
|
+
const token = await getToken();
|
|
51
|
+
const bodyObj = operations;
|
|
52
|
+
const requestOptions = getRequestOptions("POST", token, bodyObj);
|
|
53
|
+
return (await getData(`/allocations/bulk${options.skipUndefined ? "?skipundefined=true" : ""}`, requestOptions, "v1", options.type === "package", options));
|
|
54
|
+
}
|
|
55
|
+
async function createAllocation(itemId1, itemId2, allocationInfo) {
|
|
56
|
+
validateString(itemId1, "Function: createAllocation, Value: itemId1");
|
|
57
|
+
validateString(itemId2, "Function: createAllocation, Value: itemId2");
|
|
58
|
+
validateObject(allocationInfo, "Function: createAllocation, Value: allocationInfo");
|
|
59
|
+
const token = await getToken();
|
|
60
|
+
const requestOptions = getRequestOptions("POST", token, allocationInfo);
|
|
61
|
+
return (await getData(`/allocations/allocation/${encodeURIComponent(itemId1)}/${encodeURIComponent(itemId2)}`, requestOptions));
|
|
62
|
+
}
|
|
63
|
+
async function updateAllocation(allocationId = "", allocationInfo = {}) {
|
|
64
|
+
validateString(allocationId, "Function: updateAllocation, Value: allocationId");
|
|
65
|
+
validateObject(allocationInfo, "Function: updateAllocation, Value: allocationInfo");
|
|
66
|
+
const token = await getToken();
|
|
67
|
+
const requestOptions = getRequestOptions("POST", token, allocationInfo);
|
|
68
|
+
return (await getData(`/allocations/allocation/${encodeURIComponent(allocationId)}`, requestOptions));
|
|
69
|
+
}
|
|
70
|
+
async function deleteAllocation(allocationId = "") {
|
|
71
|
+
validateString(allocationId, "Function: deleteAllocation, Value: allocationId");
|
|
72
|
+
const token = await getToken();
|
|
73
|
+
const requestOptions = getRequestOptions("DELETE", token);
|
|
74
|
+
return (await getData(`/allocations/allocation/${encodeURIComponent(allocationId)}`, requestOptions));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* DEPRECATED: use getAllocations2
|
|
78
|
+
*/
|
|
79
|
+
async function getAllocations(filter = {}, paging = {}) {
|
|
80
|
+
validateObject(filter, "getItems: filter");
|
|
81
|
+
validateObject(paging, "getItems: paging");
|
|
82
|
+
const token = await getToken();
|
|
83
|
+
const bodyObj = {
|
|
84
|
+
filter: filter,
|
|
85
|
+
paging: paging,
|
|
86
|
+
};
|
|
87
|
+
const requestOptions = getRequestOptions("POST", token, bodyObj);
|
|
88
|
+
return (await getData(`/allocations/allocation`, requestOptions));
|
|
89
|
+
}
|
|
90
|
+
async function updateAllocations(file, keepData = false) {
|
|
91
|
+
if (typeof file === "undefined") {
|
|
92
|
+
throw generateError("fileNotSupplied");
|
|
93
|
+
}
|
|
94
|
+
const token = await getToken();
|
|
95
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
96
|
+
const requestOptions = getFileUploadRequestOptions(token, file, { timezone });
|
|
97
|
+
return (await getData(`/allocations/csv${keepData ? "?keep=true" : ""}`, requestOptions));
|
|
98
|
+
}
|
|
99
|
+
async function createRepeatedAllocations(itemId1, itemId2, allocationInfo, repetitionInfo) {
|
|
100
|
+
validateString(itemId1, "Function: createRepeatedAllocations, Value: itemId1");
|
|
101
|
+
validateString(itemId2, "Function: createRepeatedAllocations, Value: itemId2");
|
|
102
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
103
|
+
allocationInfo.timezone = timezone;
|
|
104
|
+
const params = {
|
|
105
|
+
type: "repetition",
|
|
106
|
+
repetition_info: {
|
|
107
|
+
...repetitionInfo,
|
|
108
|
+
...allocationInfo,
|
|
109
|
+
timezone,
|
|
110
|
+
},
|
|
111
|
+
itemId1,
|
|
112
|
+
itemId2,
|
|
113
|
+
};
|
|
114
|
+
//validate repetitionInfo
|
|
115
|
+
const token = await getToken();
|
|
116
|
+
const requestOptions = getRequestOptions("POST", token, allocationInfo);
|
|
117
|
+
return (await getData(`/allocations/allocations/${encodeURIComponent(itemId1)}/${encodeURIComponent(itemId2)}/${encodeURIComponent(repetitionInfo.pattern)}/${encodeURIComponent(repetitionInfo.durationType)}/${encodeURIComponent(String(repetitionInfo.durationValue))}/${encodeURIComponent(repetitionInfo.originalId ?? "")}/`, requestOptions, "v1", true, params));
|
|
118
|
+
}
|
|
119
|
+
async function deleteRepeatedAllocations(repetitionId, deletionType, timestamp) {
|
|
120
|
+
validateString(repetitionId, "Function: deleteRepeatedAllocations, Value: repetitionId");
|
|
121
|
+
validateString(deletionType, "Function: deleteRepeatedAllocations, Value: deletionType");
|
|
122
|
+
validateNumber(timestamp, "Function: deleteRepeatedAllocations, Value: timestamp");
|
|
123
|
+
const token = await getToken();
|
|
124
|
+
const requestOptions = getRequestOptions("DELETE", token);
|
|
125
|
+
return (await getData(`/allocations/allocations/${encodeURIComponent(repetitionId)}/${encodeURIComponent(deletionType)}/${encodeURIComponent(String(timestamp))}`, requestOptions));
|
|
126
|
+
}
|
|
127
|
+
async function updateRepeatedAllocations(repetitionId, editType, timestamp, allocationInfo) {
|
|
128
|
+
validateString(repetitionId, "Function: updateRepeatedAllocations, Value: repetitionId");
|
|
129
|
+
validateString(editType, "Function: updateRepeatedAllocations, Value: editType");
|
|
130
|
+
validateNumber(timestamp, "Function: updateRepeatedAllocations, Value: timestamp");
|
|
131
|
+
validateObject(allocationInfo, "Function: updateRepeatedAllocations, Value: allocationInfo");
|
|
132
|
+
const token = await getToken();
|
|
133
|
+
const requestOptions = getRequestOptions("POST", token, allocationInfo);
|
|
134
|
+
return (await getData(`/allocations/allocations/${encodeURIComponent(repetitionId)}/${encodeURIComponent(editType)}/${encodeURIComponent(String(timestamp))}`, requestOptions));
|
|
135
|
+
}
|
|
136
|
+
export const allocations = {
|
|
137
|
+
getAllocations2,
|
|
138
|
+
getAllocations3,
|
|
139
|
+
bulkOperation,
|
|
140
|
+
createAllocation,
|
|
141
|
+
getAllocations,
|
|
142
|
+
deleteAllocation,
|
|
143
|
+
updateAllocation,
|
|
144
|
+
updateAllocations,
|
|
145
|
+
createRepeatedAllocations,
|
|
146
|
+
deleteRepeatedAllocations,
|
|
147
|
+
updateRepeatedAllocations,
|
|
148
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare function jqQuery2(paging?: {}, jqQuery?: string, filter?: {}): Promise<unknown>;
|
|
2
|
+
declare function jqQuery(itemIds?: string[], jqQuery?: string, options?: {}): Promise<unknown>;
|
|
3
|
+
export declare const analytics: {
|
|
4
|
+
jqQuery: typeof jqQuery;
|
|
5
|
+
jqQuery2: typeof jqQuery2;
|
|
6
|
+
};
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getToken } from "../helper/token.js";
|
|
2
|
+
import { getRequestOptions, getData } from "../helper/httpHelper.js";
|
|
3
|
+
import { validateString, validateObject, validateArray, } from "../helper/validate.js";
|
|
4
|
+
async function jqQuery2(paging = {}, jqQuery = "", filter = {}) {
|
|
5
|
+
validateObject(paging, "jqQuery: paging");
|
|
6
|
+
validateString(jqQuery, "jqQuery: jqQuery");
|
|
7
|
+
validateObject(filter, "jqQuery: filter");
|
|
8
|
+
const token = await getToken();
|
|
9
|
+
const bodyObj = {
|
|
10
|
+
paging: paging,
|
|
11
|
+
jqQuery: jqQuery,
|
|
12
|
+
filter: filter,
|
|
13
|
+
};
|
|
14
|
+
const requestOptions = getRequestOptions("POST", token, bodyObj);
|
|
15
|
+
return await getData("/analytics/jq", requestOptions, "v2");
|
|
16
|
+
}
|
|
17
|
+
async function jqQuery(itemIds = [], jqQuery = "", options = {}) {
|
|
18
|
+
validateArray(itemIds, "jqQuery: itemIds");
|
|
19
|
+
validateString(jqQuery, "jqQuery: jqQuery");
|
|
20
|
+
validateObject(options, "jqQuery: options");
|
|
21
|
+
const token = await getToken();
|
|
22
|
+
const bodyObj = {
|
|
23
|
+
itemIds: itemIds,
|
|
24
|
+
jqQuery: jqQuery,
|
|
25
|
+
paging: options,
|
|
26
|
+
};
|
|
27
|
+
const requestOptions = getRequestOptions("POST", token, bodyObj);
|
|
28
|
+
return await getData("/analytics/jq", requestOptions);
|
|
29
|
+
}
|
|
30
|
+
export const analytics = {
|
|
31
|
+
jqQuery,
|
|
32
|
+
jqQuery2,
|
|
33
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CalendarInfo, CalendarResult, CompanySettingsInput, CompanySettingsResult, ExportAllocConfig, ExportItemsConfig, FileInfoResult, GetCalendarOptions, RestoreResult, UpdateCalendarInfo, UpdateResult, UserInfo } from "../types/types.js";
|
|
2
|
+
declare function getCompanySettings(): Promise<CompanySettingsResult[]>;
|
|
3
|
+
declare function setCompanySettings(companySettings: CompanySettingsInput): Promise<CompanySettingsResult>;
|
|
4
|
+
declare function deleteCompanySettings(): Promise<unknown>;
|
|
5
|
+
declare function backupDatabase(download?: boolean): Promise<void>;
|
|
6
|
+
declare function restoreDatabase(file: File): Promise<RestoreResult>;
|
|
7
|
+
declare function exportDatabase(itemSettings?: ExportItemsConfig, allocationSettings?: ExportAllocConfig, xlsx?: string, download?: boolean): Promise<void>;
|
|
8
|
+
declare function detectLanguage(supportedLanguages: string[], defaultLanguage: string): string;
|
|
9
|
+
declare function getUserInfo(): Promise<UserInfo>;
|
|
10
|
+
declare function getFileInfo(url: string): Promise<FileInfoResult>;
|
|
11
|
+
declare function createCalendarInfo(data: CalendarInfo): Promise<CalendarResult>;
|
|
12
|
+
declare function bulkCreateCalendarInfo(data: CalendarInfo[], overwrite?: boolean): Promise<CalendarResult[]>;
|
|
13
|
+
declare function getCalendarInfo(options?: GetCalendarOptions): Promise<CalendarResult[]>;
|
|
14
|
+
declare function updateCalendarInfo(id: string, data: UpdateCalendarInfo): Promise<UpdateResult>;
|
|
15
|
+
declare function deleteCalendarInfo(id: string): Promise<UpdateResult>;
|
|
16
|
+
export declare const dcs: {
|
|
17
|
+
getCompanySettings: typeof getCompanySettings;
|
|
18
|
+
setCompanySettings: typeof setCompanySettings;
|
|
19
|
+
deleteCompanySettings: typeof deleteCompanySettings;
|
|
20
|
+
backupDatabase: typeof backupDatabase;
|
|
21
|
+
restoreDatabase: typeof restoreDatabase;
|
|
22
|
+
exportDatabase: typeof exportDatabase;
|
|
23
|
+
detectLanguage: typeof detectLanguage;
|
|
24
|
+
getUserInfo: typeof getUserInfo;
|
|
25
|
+
getFileInfo: typeof getFileInfo;
|
|
26
|
+
createCalendarInfo: typeof createCalendarInfo;
|
|
27
|
+
bulkCreateCalendarInfo: typeof bulkCreateCalendarInfo;
|
|
28
|
+
getCalendarInfo: typeof getCalendarInfo;
|
|
29
|
+
updateCalendarInfo: typeof updateCalendarInfo;
|
|
30
|
+
deleteCalendarInfo: typeof deleteCalendarInfo;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { getToken } from "../helper/token.js";
|
|
2
|
+
import { getRequestOptions, getData, getZip, getFileUploadRequestOptions, getFile, } from "../helper/httpHelper.js";
|
|
3
|
+
import { validateObject, validateArray, validateString, } from "../helper/validate.js";
|
|
4
|
+
import { getMostSuitedLanguage } from "../helper/language.js";
|
|
5
|
+
import { generateError } from "../helper/language.js";
|
|
6
|
+
async function getCompanySettings() {
|
|
7
|
+
const token = await getToken();
|
|
8
|
+
const requestOptions = getRequestOptions("GET", token);
|
|
9
|
+
return (await getData(`/dcs/companysettings`, requestOptions));
|
|
10
|
+
}
|
|
11
|
+
async function setCompanySettings(companySettings) {
|
|
12
|
+
validateObject(companySettings, "Function: updateCompanySettings, Value: companySettings");
|
|
13
|
+
const token = await getToken();
|
|
14
|
+
const requestOptions = getRequestOptions("POST", token, companySettings);
|
|
15
|
+
return (await getData(`/dcs/companySettings`, requestOptions));
|
|
16
|
+
}
|
|
17
|
+
async function deleteCompanySettings() {
|
|
18
|
+
const token = await getToken();
|
|
19
|
+
const requestOptions = getRequestOptions("DELETE", token);
|
|
20
|
+
return await getData(`/dcs/companySettings`, requestOptions);
|
|
21
|
+
}
|
|
22
|
+
async function backupDatabase(download = true) {
|
|
23
|
+
const token = await getToken();
|
|
24
|
+
const requestOptions = getRequestOptions("GET", token, undefined, "zip");
|
|
25
|
+
if (download === true) {
|
|
26
|
+
const backupName = `planisyBackup_${new Date().toISOString()}`;
|
|
27
|
+
await getZip(`/dcs/backup?file=true`, requestOptions, backupName);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
console.log("DB backup without download has not been implemented. ");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function restoreDatabase(file) {
|
|
34
|
+
if (typeof file === "undefined") {
|
|
35
|
+
throw generateError("fileNotSupplied");
|
|
36
|
+
}
|
|
37
|
+
const token = await getToken();
|
|
38
|
+
const requestOptions = getFileUploadRequestOptions(token, file);
|
|
39
|
+
return (await getData(`/dcs/restore`, requestOptions));
|
|
40
|
+
}
|
|
41
|
+
async function exportDatabase(itemSettings = "none", allocationSettings = "none", xlsx = "false", download = true) {
|
|
42
|
+
const requestSettings = {};
|
|
43
|
+
requestSettings.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
44
|
+
if (!(typeof itemSettings === "string")) {
|
|
45
|
+
validateArray(itemSettings, "exportDatabase: itemSettings");
|
|
46
|
+
requestSettings.items = itemSettings;
|
|
47
|
+
}
|
|
48
|
+
if (!(allocationSettings === "none")) {
|
|
49
|
+
validateObject(allocationSettings, "exportDatabase: allocationSettings");
|
|
50
|
+
requestSettings.allocations = allocationSettings;
|
|
51
|
+
}
|
|
52
|
+
const token = await getToken();
|
|
53
|
+
const requestOptions = getRequestOptions("POST", token, requestSettings, "json");
|
|
54
|
+
if (download === true) {
|
|
55
|
+
const exportName = `planisyExport_${new Date().toISOString()}`;
|
|
56
|
+
await getZip(`/dcs/export${xlsx ? "?xlsx=true" : ""}`, requestOptions, exportName);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.log("Exporting without downloading has not yet been implemented.");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function detectLanguage(supportedLanguages, defaultLanguage) {
|
|
63
|
+
return getMostSuitedLanguage(supportedLanguages, defaultLanguage);
|
|
64
|
+
}
|
|
65
|
+
async function getUserInfo() {
|
|
66
|
+
const token = await getToken();
|
|
67
|
+
const requestOptions = getRequestOptions("GET", token);
|
|
68
|
+
return (await getData(`/dcs/userinfo`, requestOptions));
|
|
69
|
+
}
|
|
70
|
+
async function getFileInfo(url) {
|
|
71
|
+
const token = await getToken();
|
|
72
|
+
const requestOptions = getRequestOptions("GET", token);
|
|
73
|
+
return await getFile(url, requestOptions);
|
|
74
|
+
}
|
|
75
|
+
async function createCalendarInfo(data) {
|
|
76
|
+
validateObject(data, "Function: createCalendarInfo, Value: calendarInfo");
|
|
77
|
+
const token = await getToken();
|
|
78
|
+
const requestOptions = getRequestOptions("POST", token, data);
|
|
79
|
+
return (await getData(`/dcs/calendarinfo`, requestOptions));
|
|
80
|
+
}
|
|
81
|
+
async function bulkCreateCalendarInfo(data, overwrite = false) {
|
|
82
|
+
validateArray(data, "Function: bulkCreateCalendarInfo, Value: data");
|
|
83
|
+
const token = await getToken();
|
|
84
|
+
const requestOptions = getRequestOptions("POST", token, data);
|
|
85
|
+
return (await getData(`/dcs/calendarinfo/bulk${overwrite ? "?overwrite=true" : ""}`, requestOptions));
|
|
86
|
+
}
|
|
87
|
+
async function getCalendarInfo(options = {}) {
|
|
88
|
+
validateObject(options, "Function: getCalendarInfo, Value: options");
|
|
89
|
+
const token = await getToken();
|
|
90
|
+
const requestOptions = getRequestOptions("GET", token);
|
|
91
|
+
const params = new URLSearchParams();
|
|
92
|
+
if (options.id)
|
|
93
|
+
params.set("id", options.id);
|
|
94
|
+
if (options.start)
|
|
95
|
+
params.set("start", String(options.start));
|
|
96
|
+
if (options.end)
|
|
97
|
+
params.set("end", String(options.end));
|
|
98
|
+
const queryString = params.toString();
|
|
99
|
+
const url = queryString ? `?${queryString}` : "";
|
|
100
|
+
return (await getData(`/dcs/calendarinfo${url}`, requestOptions));
|
|
101
|
+
}
|
|
102
|
+
async function updateCalendarInfo(id, data) {
|
|
103
|
+
validateString(id, "Function: updateCalendarInfo, Value: id");
|
|
104
|
+
validateObject(data, "Function: updateCalendarInfo, Value: data");
|
|
105
|
+
const token = await getToken();
|
|
106
|
+
const requestOptions = getRequestOptions("PUT", token, data);
|
|
107
|
+
return (await getData(`/dcs/calendarinfo/${id}`, requestOptions));
|
|
108
|
+
}
|
|
109
|
+
async function deleteCalendarInfo(id) {
|
|
110
|
+
validateString(id, "Function: deleteCalendarInfo, Value: id");
|
|
111
|
+
const token = await getToken();
|
|
112
|
+
const requestOptions = getRequestOptions("DELETE", token);
|
|
113
|
+
return (await getData(`/dcs/calendarinfo/${id}`, requestOptions));
|
|
114
|
+
}
|
|
115
|
+
export const dcs = {
|
|
116
|
+
getCompanySettings,
|
|
117
|
+
setCompanySettings,
|
|
118
|
+
deleteCompanySettings,
|
|
119
|
+
backupDatabase,
|
|
120
|
+
restoreDatabase,
|
|
121
|
+
exportDatabase,
|
|
122
|
+
detectLanguage,
|
|
123
|
+
getUserInfo,
|
|
124
|
+
getFileInfo,
|
|
125
|
+
createCalendarInfo,
|
|
126
|
+
bulkCreateCalendarInfo,
|
|
127
|
+
getCalendarInfo,
|
|
128
|
+
updateCalendarInfo,
|
|
129
|
+
deleteCalendarInfo,
|
|
130
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getToken } from "../helper/token.js";
|
|
2
|
+
import { getRequestOptions, getData } from "../helper/httpHelper.js";
|
|
3
|
+
async function getLastChange() {
|
|
4
|
+
const token = await getToken();
|
|
5
|
+
const requestOptions = getRequestOptions("GET", token);
|
|
6
|
+
return (await getData(`/events/lastchange`, requestOptions));
|
|
7
|
+
}
|
|
8
|
+
export const events = {
|
|
9
|
+
getLastChange,
|
|
10
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CsvImportResult, Filter, Input, CreateResult, ItemOptions, ItemResult } from "../types/types.js";
|
|
2
|
+
declare function createItem(templateName: string, itemProperties: Input): Promise<CreateResult>;
|
|
3
|
+
declare function updateItem(itemId: string, itemProperties: Input): Promise<ItemResult[]>;
|
|
4
|
+
/**
|
|
5
|
+
* DEPRECATED, use getItems2
|
|
6
|
+
*/
|
|
7
|
+
declare function getItems(filter?: {}, paging?: {}): Promise<ItemResult[]>;
|
|
8
|
+
declare function getItems2(filter?: Filter | {}, paging?: ItemOptions): Promise<ItemResult[]>;
|
|
9
|
+
declare function deleteItem(itemId: string): Promise<{}>;
|
|
10
|
+
declare function updateItems(file: File, templateName: string, primaryKey: string, keepData?: boolean): Promise<CsvImportResult>;
|
|
11
|
+
declare function attachFile(itemId: string | undefined, attributeId: string | undefined, file: File): Promise<string>;
|
|
12
|
+
export declare const items: {
|
|
13
|
+
createItem: typeof createItem;
|
|
14
|
+
updateItem: typeof updateItem;
|
|
15
|
+
getItems: typeof getItems;
|
|
16
|
+
getItems2: typeof getItems2;
|
|
17
|
+
updateItems: typeof updateItems;
|
|
18
|
+
attachFile: typeof attachFile;
|
|
19
|
+
deleteItem: typeof deleteItem;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { getToken } from "../helper/token.js";
|
|
2
|
+
import { getData, getFileUploadRequestOptions, getRequestOptions, } from "../helper/httpHelper.js";
|
|
3
|
+
import { validateObject, validateString } from "../helper/validate.js";
|
|
4
|
+
async function createItem(templateName, itemProperties) {
|
|
5
|
+
validateString(templateName, "Function: createItem, Value: templateName");
|
|
6
|
+
validateObject(itemProperties, "Function: createItem, Value: itemProperties");
|
|
7
|
+
const token = await getToken();
|
|
8
|
+
const requestOptions = getRequestOptions("POST", token, itemProperties);
|
|
9
|
+
return (await getData(`/items/template/${encodeURIComponent(templateName)}`, requestOptions));
|
|
10
|
+
}
|
|
11
|
+
async function updateItem(itemId, itemProperties) {
|
|
12
|
+
validateString(itemId, "Function: updateItem, Value: itemId");
|
|
13
|
+
validateObject(itemProperties, "Function: updateItem, Value: itemProperties");
|
|
14
|
+
const token = await getToken();
|
|
15
|
+
const requestOptions = getRequestOptions("POST", token, itemProperties);
|
|
16
|
+
return (await getData(`/items/item/${encodeURIComponent(itemId)}`, requestOptions));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* DEPRECATED, use getItems2
|
|
20
|
+
*/
|
|
21
|
+
async function getItems(filter = {}, paging = {}) {
|
|
22
|
+
const token = await getToken();
|
|
23
|
+
const bodyObj = {
|
|
24
|
+
filter: filter,
|
|
25
|
+
paging: paging,
|
|
26
|
+
};
|
|
27
|
+
const requestOptions = getRequestOptions("POST", token, bodyObj);
|
|
28
|
+
return (await getData("/items/item", requestOptions));
|
|
29
|
+
}
|
|
30
|
+
async function getItems2(filter = {}, paging = {}) {
|
|
31
|
+
validateObject(filter, "Function: getItems2, Value: filter");
|
|
32
|
+
validateObject(paging, "Function: getItems2, Value: options");
|
|
33
|
+
const token = await getToken();
|
|
34
|
+
const bodyObj = {
|
|
35
|
+
...(Object.keys(filter ?? {}).length ? { filter } : {}),
|
|
36
|
+
paging: paging,
|
|
37
|
+
};
|
|
38
|
+
const requestOptions = getRequestOptions("POST", token, bodyObj);
|
|
39
|
+
return (await getData("/items/item", requestOptions, "v2"));
|
|
40
|
+
}
|
|
41
|
+
async function deleteItem(itemId) {
|
|
42
|
+
validateString(itemId, "Function: deleteItem, Value: itemId");
|
|
43
|
+
const token = await getToken();
|
|
44
|
+
const requestOptions = getRequestOptions("DELETE", token);
|
|
45
|
+
return (await getData(`/items/item/${encodeURIComponent(itemId)}`, requestOptions));
|
|
46
|
+
}
|
|
47
|
+
async function updateItems(file, templateName, primaryKey, keepData = false) {
|
|
48
|
+
validateString(templateName, "Function: updateItems, Value: templateName");
|
|
49
|
+
validateString(primaryKey, "Function: updateItems, Value: primaryKey");
|
|
50
|
+
const token = await getToken();
|
|
51
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
52
|
+
const requestOptions = getFileUploadRequestOptions(token, file, { timezone });
|
|
53
|
+
return (await getData(`/items/csv/${encodeURIComponent(templateName)}/${encodeURIComponent(primaryKey)}${keepData ? "?keep=true" : ""}`, requestOptions));
|
|
54
|
+
}
|
|
55
|
+
async function attachFile(itemId = "", attributeId = "", file) {
|
|
56
|
+
validateString(itemId, "Function: attachFile, Value: itemId");
|
|
57
|
+
validateString(attributeId, "Function: attachFile, Value: attributeId");
|
|
58
|
+
const token = await getToken();
|
|
59
|
+
const requestOptions = getFileUploadRequestOptions(token, file, {}, "PUT", attributeId);
|
|
60
|
+
return (await getData(`/items/item/${encodeURIComponent(itemId)}/fileattribute`, requestOptions));
|
|
61
|
+
}
|
|
62
|
+
export const items = {
|
|
63
|
+
createItem,
|
|
64
|
+
updateItem,
|
|
65
|
+
getItems,
|
|
66
|
+
getItems2,
|
|
67
|
+
updateItems,
|
|
68
|
+
attachFile,
|
|
69
|
+
deleteItem
|
|
70
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LanguageObj, StringParams } from "../types/types.js";
|
|
2
|
+
declare function loadLanguageFile(languages?: string[]): Promise<void>;
|
|
3
|
+
declare function detectCompanyLanguage(): Promise<void>;
|
|
4
|
+
declare function getTranslatedLabel(languageObject: LanguageObj): string;
|
|
5
|
+
declare function translateHTML(): void;
|
|
6
|
+
declare function translateString(key: string, params?: StringParams): string;
|
|
7
|
+
declare function getCompanyLanguage(): string;
|
|
8
|
+
declare function getUILanguage(): string;
|
|
9
|
+
export declare const language: {
|
|
10
|
+
loadLanguageFile: typeof loadLanguageFile;
|
|
11
|
+
detectCompanyLanguage: typeof detectCompanyLanguage;
|
|
12
|
+
getTranslatedLabel: typeof getTranslatedLabel;
|
|
13
|
+
translateHTML: typeof translateHTML;
|
|
14
|
+
translateString: typeof translateString;
|
|
15
|
+
getCompanyLanguage: typeof getCompanyLanguage;
|
|
16
|
+
getUILanguage: typeof getUILanguage;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { getMostSuitedLanguage, getProgramLanguage, } from "../helper/language.js";
|
|
2
|
+
import { dcs } from "./dcs.js";
|
|
3
|
+
let languageData = {};
|
|
4
|
+
let defaultCompanyLanguage;
|
|
5
|
+
let uiLanguage;
|
|
6
|
+
// this version of the function is used when the language files are hosted on the server
|
|
7
|
+
async function loadLanguageFile(languages = []) {
|
|
8
|
+
try {
|
|
9
|
+
languageData = await getProgramLanguage();
|
|
10
|
+
// this is to set the ui language locally
|
|
11
|
+
const finalLanguages = languages.length
|
|
12
|
+
? languages
|
|
13
|
+
: ["en", "de", "it", "fr", "es"];
|
|
14
|
+
// "en" is the currently hardcoded fallback language, in the future it will come from the company settings.
|
|
15
|
+
uiLanguage = getMostSuitedLanguage(finalLanguages, "en");
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.log(e);
|
|
19
|
+
console.warn(`Using fallback language files for ${bundle?.identifier}. Please make sure that this dizmo exists on the translation service and the most recent language files are deployed.`);
|
|
20
|
+
await fallbackLoadLanguageFile(languages);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Loads the correct language data json from assets folder and stores it in languageData
|
|
24
|
+
// This is the language used for UI elements.
|
|
25
|
+
async function fallbackLoadLanguageFile(languages = []) {
|
|
26
|
+
try {
|
|
27
|
+
// This array has to be set manually according to the available files in assets/locales
|
|
28
|
+
const finalLanguages = languages.length
|
|
29
|
+
? languages
|
|
30
|
+
: ["en", "de", "it", "fr", "es"];
|
|
31
|
+
// "en" is the currently hardcoded fallback language, in the future it will come from the company settings.
|
|
32
|
+
uiLanguage = getMostSuitedLanguage(finalLanguages, "en");
|
|
33
|
+
const languageFileResponse = await fetch(`assets/locales/translation.${uiLanguage}.json`);
|
|
34
|
+
if (!languageFileResponse.ok) {
|
|
35
|
+
throw new Error(`Failed to load language file: ${languageFileResponse.status} ${languageFileResponse.statusText}`);
|
|
36
|
+
}
|
|
37
|
+
// sets the global language file
|
|
38
|
+
languageData = await languageFileResponse.json();
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
console.error("Error loading fallback language file:", e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function detectCompanyLanguage() {
|
|
45
|
+
// based on the available languages in the companySettings
|
|
46
|
+
// this is the language that is used to display the correct labels for the templates
|
|
47
|
+
// "en" is the currently hardcoded fallback language, in the future it will come from the company settings.
|
|
48
|
+
try {
|
|
49
|
+
const companySettings = await dcs.getCompanySettings();
|
|
50
|
+
defaultCompanyLanguage =
|
|
51
|
+
companySettings[0]?.properties?.default_language ?? "en";
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
defaultCompanyLanguage = "en";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function getTranslatedLabel(languageObject) {
|
|
58
|
+
// accepts a label object like:
|
|
59
|
+
/*
|
|
60
|
+
{
|
|
61
|
+
"en": "Car",
|
|
62
|
+
"de": "Auto"
|
|
63
|
+
}
|
|
64
|
+
*/
|
|
65
|
+
// from a template and returns the label in the correct language
|
|
66
|
+
const supportedLanguages = Object.keys(languageObject).filter((language) => languageObject[language]);
|
|
67
|
+
const languageToUse = getMostSuitedLanguage(supportedLanguages, defaultCompanyLanguage);
|
|
68
|
+
return languageObject[languageToUse];
|
|
69
|
+
}
|
|
70
|
+
function translateHTML() {
|
|
71
|
+
// replaces all hardcoded strings in HTML with data from the languageData object,
|
|
72
|
+
// the json keys must match with the HTML ids
|
|
73
|
+
// except the ones that start with 'js_'
|
|
74
|
+
Object.keys(languageData).forEach((id) => {
|
|
75
|
+
if (!id.startsWith("js_")) {
|
|
76
|
+
const elem = document.getElementById(id);
|
|
77
|
+
if (elem)
|
|
78
|
+
elem.textContent = languageData[id];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function translateString(key, params = {}) {
|
|
83
|
+
// translates a single string from the languageData file, based on its key
|
|
84
|
+
// used when for example a HTML element is generated in JS and its textContent is set dynamically
|
|
85
|
+
// accepts parameters that will be placed in the translated strings.
|
|
86
|
+
let finalString = languageData[key];
|
|
87
|
+
Object.keys(params).forEach((paramName) => {
|
|
88
|
+
finalString = finalString.replace(`{${paramName}}`, params[paramName].toString());
|
|
89
|
+
});
|
|
90
|
+
return finalString;
|
|
91
|
+
}
|
|
92
|
+
function getCompanyLanguage() {
|
|
93
|
+
return defaultCompanyLanguage;
|
|
94
|
+
}
|
|
95
|
+
function getUILanguage() {
|
|
96
|
+
return uiLanguage;
|
|
97
|
+
}
|
|
98
|
+
export const language = {
|
|
99
|
+
loadLanguageFile,
|
|
100
|
+
detectCompanyLanguage,
|
|
101
|
+
getTranslatedLabel,
|
|
102
|
+
translateHTML,
|
|
103
|
+
translateString,
|
|
104
|
+
getCompanyLanguage,
|
|
105
|
+
getUILanguage,
|
|
106
|
+
};
|