@allthings/sdk 10.0.0-beta.1 → 10.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/lib.cjs.js +1 -1
- package/dist/src/cli.js +15 -0
- package/dist/src/constants.js +25 -0
- package/dist/src/index.js +4 -0
- package/dist/src/oauth/authorizationCodeGrant.js +56 -0
- package/dist/src/oauth/clientCredentialsGrant.js +25 -0
- package/dist/src/oauth/createTokenStore.js +8 -0
- package/dist/src/oauth/implicitGrant.js +24 -0
- package/dist/src/oauth/makeFetchTokenRequester.js +38 -0
- package/dist/src/oauth/maybeUpdateToken.js +44 -0
- package/dist/src/oauth/passwordGrant.js +30 -0
- package/dist/src/oauth/refreshTokenGrant.js +26 -0
- package/dist/src/oauth/requestAndSaveToStore.js +5 -0
- package/dist/src/oauth/types.js +1 -0
- package/dist/src/rest/delete.js +3 -0
- package/dist/src/rest/get.js +3 -0
- package/dist/src/rest/index.js +160 -0
- package/dist/src/rest/methods/agent.js +26 -0
- package/dist/src/rest/methods/app.js +10 -0
- package/dist/src/rest/methods/booking.js +6 -0
- package/dist/src/rest/methods/bucket.js +22 -0
- package/dist/src/rest/methods/conversation.js +28 -0
- package/dist/src/rest/methods/file.js +11 -0
- package/dist/src/rest/methods/group.js +22 -0
- package/dist/src/rest/methods/idLookup.js +12 -0
- package/dist/src/rest/methods/notification.js +57 -0
- package/dist/src/rest/methods/notificationSettings.js +19 -0
- package/dist/src/rest/methods/property.js +17 -0
- package/dist/src/rest/methods/registrationCode.js +24 -0
- package/dist/src/rest/methods/serviceProvider.js +9 -0
- package/dist/src/rest/methods/ticket.js +34 -0
- package/dist/src/rest/methods/unit.js +95 -0
- package/dist/src/rest/methods/user.js +134 -0
- package/dist/src/rest/methods/userRelation.js +22 -0
- package/dist/src/rest/methods/utilisationPeriod.js +49 -0
- package/dist/src/rest/patch.js +3 -0
- package/dist/src/rest/post.js +3 -0
- package/dist/src/rest/put.js +3 -0
- package/dist/src/rest/request.js +159 -0
- package/dist/src/rest/types.js +62 -0
- package/dist/src/utils/environment.js +1 -0
- package/dist/src/utils/functional.js +14 -0
- package/dist/src/utils/logger.js +15 -0
- package/dist/src/utils/object.js +6 -0
- package/dist/src/utils/queryString.js +13 -0
- package/dist/src/utils/random.js +7 -0
- package/dist/src/utils/sleep.js +3 -0
- package/dist/src/utils/string.js +6 -0
- package/dist/src/utils/stringToDate.js +6 -0
- package/dist/src/utils/upload.js +24 -0
- package/package.json +10 -8
- package/dist/lib.esm.js +0 -1350
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { dateToString, stringToDate } from '../../utils/stringToDate';
|
|
2
|
+
export var EnumNotificationCategory;
|
|
3
|
+
(function (EnumNotificationCategory) {
|
|
4
|
+
EnumNotificationCategory["events"] = "events";
|
|
5
|
+
EnumNotificationCategory["hintsAndTips"] = "hints-and-tips";
|
|
6
|
+
EnumNotificationCategory["lostAndFound"] = "lost-and-found";
|
|
7
|
+
EnumNotificationCategory["localDeals"] = "local-deals";
|
|
8
|
+
EnumNotificationCategory["localEvents"] = "local-events";
|
|
9
|
+
EnumNotificationCategory["miscellaneous"] = "miscellaneous";
|
|
10
|
+
EnumNotificationCategory["deals"] = "deals";
|
|
11
|
+
EnumNotificationCategory["messages"] = "messages";
|
|
12
|
+
EnumNotificationCategory["adminMessages"] = "admin-messages";
|
|
13
|
+
EnumNotificationCategory["newThingsToGive"] = "new-things-to-give";
|
|
14
|
+
EnumNotificationCategory["newThingsForSale"] = "new-things-for-sale";
|
|
15
|
+
EnumNotificationCategory["surveys"] = "surveys";
|
|
16
|
+
EnumNotificationCategory["supportOffer"] = "support-offer";
|
|
17
|
+
EnumNotificationCategory["supportRequest"] = "support-request";
|
|
18
|
+
EnumNotificationCategory["sustainability"] = "sustainability";
|
|
19
|
+
EnumNotificationCategory["localServices"] = "local-services";
|
|
20
|
+
EnumNotificationCategory["services"] = "services";
|
|
21
|
+
EnumNotificationCategory["ticketDigestEmail"] = "ticket-digest-email";
|
|
22
|
+
EnumNotificationCategory["appDigestEmail"] = "app-digest-email";
|
|
23
|
+
EnumNotificationCategory["newFile"] = "new-file";
|
|
24
|
+
})(EnumNotificationCategory || (EnumNotificationCategory = {}));
|
|
25
|
+
export var EnumNotificationType;
|
|
26
|
+
(function (EnumNotificationType) {
|
|
27
|
+
EnumNotificationType["clipboardThing"] = "clipboard-thing";
|
|
28
|
+
EnumNotificationType["comment"] = "comment";
|
|
29
|
+
EnumNotificationType["communityArticle"] = "community-article";
|
|
30
|
+
EnumNotificationType["newFile"] = "new-file";
|
|
31
|
+
EnumNotificationType["ticketComment"] = "ticket-comment";
|
|
32
|
+
EnumNotificationType["welcomeNotification"] = "welcome-notification";
|
|
33
|
+
})(EnumNotificationType || (EnumNotificationType = {}));
|
|
34
|
+
function remapNotificationResult({ createdAt, objectID, referencedObjectID, ...restNotification }) {
|
|
35
|
+
return {
|
|
36
|
+
createdAt: stringToDate(createdAt),
|
|
37
|
+
objectId: objectID,
|
|
38
|
+
referencedObjectId: referencedObjectID,
|
|
39
|
+
...restNotification,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export async function notificationsGetByUser(client, userId, page = 1, limit = -1) {
|
|
43
|
+
const { _embedded: { items: notifications }, total, metaData, } = await client.get(`/v1/users/${userId}/notifications?page=${page}&limit=${limit}`);
|
|
44
|
+
return {
|
|
45
|
+
_embedded: { items: notifications.map(remapNotificationResult) },
|
|
46
|
+
metaData,
|
|
47
|
+
total,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export async function notificationsUpdateReadByUser(client, userId, lastReadAt = new Date()) {
|
|
51
|
+
return client.patch(`/v1/users/${userId}/notifications`, {
|
|
52
|
+
lastReadAt: dateToString(lastReadAt),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
export async function notificationUpdateRead(client, notificationId) {
|
|
56
|
+
return remapNotificationResult(await client.patch(`/v1/notifications/${notificationId}`, { read: true }));
|
|
57
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { remapKeys } from '../../utils/object';
|
|
2
|
+
import { camelCaseToDash, dashCaseToCamel } from '../../utils/string';
|
|
3
|
+
export var EnumNotificationSettingsValue;
|
|
4
|
+
(function (EnumNotificationSettingsValue) {
|
|
5
|
+
EnumNotificationSettingsValue["never"] = "never";
|
|
6
|
+
EnumNotificationSettingsValue["immediately"] = "immediately";
|
|
7
|
+
EnumNotificationSettingsValue["daily"] = "daily";
|
|
8
|
+
EnumNotificationSettingsValue["weekly"] = "weekly";
|
|
9
|
+
EnumNotificationSettingsValue["biweekly"] = "biweekly";
|
|
10
|
+
EnumNotificationSettingsValue["monthly"] = "monthly";
|
|
11
|
+
})(EnumNotificationSettingsValue || (EnumNotificationSettingsValue = {}));
|
|
12
|
+
export async function notificationSettingsUpdateByUser(client, userId, data) {
|
|
13
|
+
const result = await client.patch(`/v1/users/${userId}/notification-settings`, { notificationSettings: remapKeys(data, camelCaseToDash) });
|
|
14
|
+
return remapKeys(result, dashCaseToCamel);
|
|
15
|
+
}
|
|
16
|
+
export async function notificationSettingsResetByUser(client, userId) {
|
|
17
|
+
const result = await client.delete(`/v1/users/${userId}/notification-settings`);
|
|
18
|
+
return remapKeys(result, dashCaseToCamel);
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export async function propertyCreate(client, appId, data) {
|
|
2
|
+
return client.post(`/v1/apps/${appId}/properties`, data);
|
|
3
|
+
}
|
|
4
|
+
export async function propertyGetById(client, propertyId) {
|
|
5
|
+
return client.get(`/v1/properties/${propertyId}`);
|
|
6
|
+
}
|
|
7
|
+
export async function propertyUpdateById(client, propertyId, data) {
|
|
8
|
+
return client.patch(`/v1/properties/${propertyId}`, data);
|
|
9
|
+
}
|
|
10
|
+
export async function getProperties(client, page = 1, limit = -1, filter = {}) {
|
|
11
|
+
const { _embedded: { items: properties }, total, } = await client.get('/v1/properties', {
|
|
12
|
+
filter: JSON.stringify(filter),
|
|
13
|
+
limit,
|
|
14
|
+
page,
|
|
15
|
+
});
|
|
16
|
+
return { _embedded: { items: properties }, total };
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const remapRegistationCodeResult = (registrationCode) => {
|
|
2
|
+
const { tenantID: externalId, ...result } = registrationCode;
|
|
3
|
+
return { ...result, externalId };
|
|
4
|
+
};
|
|
5
|
+
export async function registrationCodeCreate(client, code, utilisationPeriods, options = { permanent: false }) {
|
|
6
|
+
const { externalId, ...moreOptions } = options;
|
|
7
|
+
return remapRegistationCodeResult(await client.post('/v1/registration-codes', {
|
|
8
|
+
code,
|
|
9
|
+
utilisationPeriods: typeof utilisationPeriods === 'string'
|
|
10
|
+
? [utilisationPeriods]
|
|
11
|
+
: utilisationPeriods,
|
|
12
|
+
...(externalId ? { externalId, tenantID: externalId } : {}),
|
|
13
|
+
...moreOptions,
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
export async function registrationCodeUpdateById(client, registrationCodeId, data) {
|
|
17
|
+
return remapRegistationCodeResult(await client.patch(`/v1/registration-codes/${registrationCodeId}`, data));
|
|
18
|
+
}
|
|
19
|
+
export async function registrationCodeGetById(client, registrationCodeId) {
|
|
20
|
+
return remapRegistationCodeResult(await client.get(`/v1/invitations/${registrationCodeId}`));
|
|
21
|
+
}
|
|
22
|
+
export async function registrationCodeDelete(client, registrationCodeId) {
|
|
23
|
+
return (await client.delete(`/v1/invitations/${registrationCodeId}`)) === '';
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export async function serviceProviderCreate(client, data) {
|
|
2
|
+
return client.post('/v1/service-providers', data);
|
|
3
|
+
}
|
|
4
|
+
export async function serviceProviderGetById(client, serviceProviderId) {
|
|
5
|
+
return client.get(`/v1/service-providers/${serviceProviderId}`);
|
|
6
|
+
}
|
|
7
|
+
export async function serviceProviderUpdateById(client, serviceProviderId, data) {
|
|
8
|
+
return client.patch(`/v1/service-providers/${serviceProviderId}`, data);
|
|
9
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createManyFilesSorted } from '../../utils/upload';
|
|
2
|
+
export var ETicketStatus;
|
|
3
|
+
(function (ETicketStatus) {
|
|
4
|
+
ETicketStatus["CLOSED"] = "closed";
|
|
5
|
+
ETicketStatus["WAITING_FOR_AGENT"] = "waiting-for-agent";
|
|
6
|
+
ETicketStatus["WAITING_FOR_CUSTOMER"] = "waiting-for-customer";
|
|
7
|
+
ETicketStatus["WAITING_FOR_EXTERNAL"] = "waiting-for-external";
|
|
8
|
+
})(ETicketStatus || (ETicketStatus = {}));
|
|
9
|
+
export var ETrafficLightColor;
|
|
10
|
+
(function (ETrafficLightColor) {
|
|
11
|
+
ETrafficLightColor["GREEN"] = "green";
|
|
12
|
+
ETrafficLightColor["RED"] = "red";
|
|
13
|
+
ETrafficLightColor["YELLOW"] = "yellow";
|
|
14
|
+
})(ETrafficLightColor || (ETrafficLightColor = {}));
|
|
15
|
+
export async function ticketGetById(client, ticketId) {
|
|
16
|
+
return client.get(`/v1/tickets/${ticketId}`);
|
|
17
|
+
}
|
|
18
|
+
export async function ticketCreateOnUser(client, userId, utilisationPeriodId, payload) {
|
|
19
|
+
return client.post(`/v1/users/${userId}/tickets`, {
|
|
20
|
+
...payload,
|
|
21
|
+
files: payload.files
|
|
22
|
+
? (await createManyFilesSorted(payload.files, client)).success
|
|
23
|
+
: [],
|
|
24
|
+
utilisationPeriod: utilisationPeriodId,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export async function ticketCreateOnServiceProvider(client, serviceProviderId, payload) {
|
|
28
|
+
return client.post(`/v1/property-managers/${serviceProviderId}/tickets`, {
|
|
29
|
+
...payload,
|
|
30
|
+
files: payload.files
|
|
31
|
+
? (await createManyFilesSorted(payload.files, client)).success
|
|
32
|
+
: [],
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export var EnumUnitObjectType;
|
|
2
|
+
(function (EnumUnitObjectType) {
|
|
3
|
+
EnumUnitObjectType["adjoiningRoom"] = "adjoining-room";
|
|
4
|
+
EnumUnitObjectType["advertisingSpace"] = "advertising-space";
|
|
5
|
+
EnumUnitObjectType["aerial"] = "aerial";
|
|
6
|
+
EnumUnitObjectType["apartmentBuilding"] = "apartment-building";
|
|
7
|
+
EnumUnitObjectType["atm"] = "atm";
|
|
8
|
+
EnumUnitObjectType["atmRoom"] = "atm-room";
|
|
9
|
+
EnumUnitObjectType["attic"] = "attic";
|
|
10
|
+
EnumUnitObjectType["atticFlat"] = "attic-flat";
|
|
11
|
+
EnumUnitObjectType["bank"] = "bank";
|
|
12
|
+
EnumUnitObjectType["basment"] = "basment";
|
|
13
|
+
EnumUnitObjectType["bikeShed"] = "bike-shed";
|
|
14
|
+
EnumUnitObjectType["buildingLaw"] = "building-law";
|
|
15
|
+
EnumUnitObjectType["cafeteria"] = "cafeteria";
|
|
16
|
+
EnumUnitObjectType["caretakerRoom"] = "caretaker-room";
|
|
17
|
+
EnumUnitObjectType["carport"] = "carport";
|
|
18
|
+
EnumUnitObjectType["cellar"] = "cellar";
|
|
19
|
+
EnumUnitObjectType["commercialProperty"] = "commercial-property";
|
|
20
|
+
EnumUnitObjectType["commonRoom"] = "common-room";
|
|
21
|
+
EnumUnitObjectType["deliveryZone"] = "delivery-zone";
|
|
22
|
+
EnumUnitObjectType["diverse"] = "diverse";
|
|
23
|
+
EnumUnitObjectType["doubleParkingSpace"] = "double-parking-space";
|
|
24
|
+
EnumUnitObjectType["engineeringRoom"] = "engineering-room";
|
|
25
|
+
EnumUnitObjectType["entertainment"] = "entertainment";
|
|
26
|
+
EnumUnitObjectType["environment"] = "environment";
|
|
27
|
+
EnumUnitObjectType["estate"] = "estate";
|
|
28
|
+
EnumUnitObjectType["fillingStation"] = "filling-station";
|
|
29
|
+
EnumUnitObjectType["fitnessCenter"] = "fitness-center";
|
|
30
|
+
EnumUnitObjectType["flat"] = "flat";
|
|
31
|
+
EnumUnitObjectType["freeZone"] = "free-zone";
|
|
32
|
+
EnumUnitObjectType["garage"] = "garage";
|
|
33
|
+
EnumUnitObjectType["garden"] = "garden";
|
|
34
|
+
EnumUnitObjectType["gardenFlat"] = "garden-flat";
|
|
35
|
+
EnumUnitObjectType["heatingFacilities"] = "heating-facilities";
|
|
36
|
+
EnumUnitObjectType["hotel"] = "hotel";
|
|
37
|
+
EnumUnitObjectType["incidentalRentalExpenses"] = "incidental-rental-expenses";
|
|
38
|
+
EnumUnitObjectType["industry"] = "industry";
|
|
39
|
+
EnumUnitObjectType["kiosk"] = "kiosk";
|
|
40
|
+
EnumUnitObjectType["kitchen"] = "kitchen";
|
|
41
|
+
EnumUnitObjectType["loft"] = "loft";
|
|
42
|
+
EnumUnitObjectType["machine"] = "machine";
|
|
43
|
+
EnumUnitObjectType["maisonette"] = "maisonette";
|
|
44
|
+
EnumUnitObjectType["medicalPractice"] = "medical-practice";
|
|
45
|
+
EnumUnitObjectType["mopedShed"] = "moped-shed";
|
|
46
|
+
EnumUnitObjectType["motorcycleParkingSpace"] = "motorcycle-parking-space";
|
|
47
|
+
EnumUnitObjectType["office"] = "office";
|
|
48
|
+
EnumUnitObjectType["oneFamilyHouse"] = "one-family-house";
|
|
49
|
+
EnumUnitObjectType["parkingBox"] = "parking-box";
|
|
50
|
+
EnumUnitObjectType["parkingGarage"] = "parking-garage";
|
|
51
|
+
EnumUnitObjectType["parkingSpace"] = "parking-space";
|
|
52
|
+
EnumUnitObjectType["parkingSpaces"] = "parking-spaces";
|
|
53
|
+
EnumUnitObjectType["penthouse"] = "penthouse";
|
|
54
|
+
EnumUnitObjectType["productionPlant"] = "production-plant";
|
|
55
|
+
EnumUnitObjectType["pub"] = "pub";
|
|
56
|
+
EnumUnitObjectType["publicArea"] = "public-area";
|
|
57
|
+
EnumUnitObjectType["restaurant"] = "restaurant";
|
|
58
|
+
EnumUnitObjectType["retirementHome"] = "retirement-home";
|
|
59
|
+
EnumUnitObjectType["salesFloor"] = "sales-floor";
|
|
60
|
+
EnumUnitObjectType["school"] = "school";
|
|
61
|
+
EnumUnitObjectType["shelter"] = "shelter";
|
|
62
|
+
EnumUnitObjectType["storage"] = "storage";
|
|
63
|
+
EnumUnitObjectType["store"] = "store";
|
|
64
|
+
EnumUnitObjectType["storeroom"] = "storeroom";
|
|
65
|
+
EnumUnitObjectType["studio"] = "studio";
|
|
66
|
+
EnumUnitObjectType["terrace"] = "terrace";
|
|
67
|
+
EnumUnitObjectType["toilets"] = "toilets";
|
|
68
|
+
EnumUnitObjectType["utilityRoom"] = "utility-room";
|
|
69
|
+
EnumUnitObjectType["variableParkingSpace"] = "variable-parking-space";
|
|
70
|
+
EnumUnitObjectType["variableRoom"] = "variable-room";
|
|
71
|
+
EnumUnitObjectType["visitorParkingSpace"] = "visitor-parking-space";
|
|
72
|
+
EnumUnitObjectType["workshop"] = "workshop";
|
|
73
|
+
})(EnumUnitObjectType || (EnumUnitObjectType = {}));
|
|
74
|
+
export var EnumUnitType;
|
|
75
|
+
(function (EnumUnitType) {
|
|
76
|
+
EnumUnitType["rented"] = "rented";
|
|
77
|
+
EnumUnitType["owned"] = "owned";
|
|
78
|
+
})(EnumUnitType || (EnumUnitType = {}));
|
|
79
|
+
export async function unitCreate(client, groupId, data) {
|
|
80
|
+
return client.post(`/v1/groups/${groupId}/units`, data);
|
|
81
|
+
}
|
|
82
|
+
export async function unitGetById(client, unitId) {
|
|
83
|
+
return client.get(`/v1/units/${unitId}`);
|
|
84
|
+
}
|
|
85
|
+
export async function unitUpdateById(client, unitId, data) {
|
|
86
|
+
return client.patch(`/v1/units/${unitId}`, data);
|
|
87
|
+
}
|
|
88
|
+
export async function getUnits(client, page = 1, limit = -1, filter = {}) {
|
|
89
|
+
const { _embedded: { items: units }, total, } = await client.get('/v1/units', {
|
|
90
|
+
filter: JSON.stringify(filter),
|
|
91
|
+
limit,
|
|
92
|
+
page,
|
|
93
|
+
});
|
|
94
|
+
return { _embedded: { items: units }, total };
|
|
95
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
export var EnumGender;
|
|
2
|
+
(function (EnumGender) {
|
|
3
|
+
EnumGender["female"] = "female";
|
|
4
|
+
EnumGender["male"] = "male";
|
|
5
|
+
})(EnumGender || (EnumGender = {}));
|
|
6
|
+
export var EnumUserType;
|
|
7
|
+
(function (EnumUserType) {
|
|
8
|
+
EnumUserType["allthingsUser"] = "allthings_user";
|
|
9
|
+
EnumUserType["allthingsContent"] = "allthings_content";
|
|
10
|
+
EnumUserType["customer"] = "customer";
|
|
11
|
+
EnumUserType["demoContent"] = "demo_content";
|
|
12
|
+
EnumUserType["demoPublic"] = "demo_public";
|
|
13
|
+
EnumUserType["partner"] = "partner";
|
|
14
|
+
})(EnumUserType || (EnumUserType = {}));
|
|
15
|
+
export var EnumCommunicationPreferenceChannel;
|
|
16
|
+
(function (EnumCommunicationPreferenceChannel) {
|
|
17
|
+
EnumCommunicationPreferenceChannel["push"] = "push";
|
|
18
|
+
EnumCommunicationPreferenceChannel["email"] = "email";
|
|
19
|
+
})(EnumCommunicationPreferenceChannel || (EnumCommunicationPreferenceChannel = {}));
|
|
20
|
+
export var EnumUserPermissionRole;
|
|
21
|
+
(function (EnumUserPermissionRole) {
|
|
22
|
+
EnumUserPermissionRole["appAdmin"] = "app-admin";
|
|
23
|
+
EnumUserPermissionRole["appOwner"] = "app-owner";
|
|
24
|
+
EnumUserPermissionRole["articlesAgent"] = "articles-agent";
|
|
25
|
+
EnumUserPermissionRole["articlesViewOnly"] = "articles-view-only";
|
|
26
|
+
EnumUserPermissionRole["bookableAssetAgent"] = "bookable-asset-agent";
|
|
27
|
+
EnumUserPermissionRole["bookingAgent"] = "booking-agent";
|
|
28
|
+
EnumUserPermissionRole["cockpitManager"] = "cockpit-manager";
|
|
29
|
+
EnumUserPermissionRole["dataConnectorAdmin"] = "data-connector-admin";
|
|
30
|
+
EnumUserPermissionRole["documentAdmin"] = "doc-admin";
|
|
31
|
+
EnumUserPermissionRole["externalAgent"] = "external-agent";
|
|
32
|
+
EnumUserPermissionRole["globalOrgAdmin"] = "global-org-admin";
|
|
33
|
+
EnumUserPermissionRole["globalUserAdmin"] = "global-user-admin";
|
|
34
|
+
EnumUserPermissionRole["orgAdmin"] = "org-admin";
|
|
35
|
+
EnumUserPermissionRole["orgTeamManager"] = "org-team-manager";
|
|
36
|
+
EnumUserPermissionRole["pinboardAgent"] = "pinboard-agent";
|
|
37
|
+
EnumUserPermissionRole["platformOwner"] = "platform-owner";
|
|
38
|
+
EnumUserPermissionRole["qa"] = "qa";
|
|
39
|
+
EnumUserPermissionRole["serviceCenterAgent"] = "service-center-agent";
|
|
40
|
+
EnumUserPermissionRole["serviceCenterManager"] = "service-center-manager";
|
|
41
|
+
EnumUserPermissionRole["setup"] = "setup";
|
|
42
|
+
EnumUserPermissionRole["tenantManager"] = "tenant-manager";
|
|
43
|
+
})(EnumUserPermissionRole || (EnumUserPermissionRole = {}));
|
|
44
|
+
export var EnumUserPermissionObjectType;
|
|
45
|
+
(function (EnumUserPermissionObjectType) {
|
|
46
|
+
EnumUserPermissionObjectType["app"] = "App";
|
|
47
|
+
EnumUserPermissionObjectType["group"] = "Group";
|
|
48
|
+
EnumUserPermissionObjectType["property"] = "Property";
|
|
49
|
+
EnumUserPermissionObjectType["unit"] = "Unit";
|
|
50
|
+
})(EnumUserPermissionObjectType || (EnumUserPermissionObjectType = {}));
|
|
51
|
+
const remapUserResult = (user) => {
|
|
52
|
+
const { tenantIDs: tenantIds, ...result } = user;
|
|
53
|
+
return { ...result, tenantIds };
|
|
54
|
+
};
|
|
55
|
+
export const remapEmbeddedUser = (embedded) => embedded.users ? embedded.users.map(remapUserResult) : [];
|
|
56
|
+
export async function userCreate(client, appId, username, data) {
|
|
57
|
+
return client.post('/v1/users', {
|
|
58
|
+
...data,
|
|
59
|
+
creationContext: appId,
|
|
60
|
+
username,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export async function getUsers(client, page = 1, limit = -1, filter = {}) {
|
|
64
|
+
const { _embedded: { items: users }, total, } = await client.get('/v1/users', {
|
|
65
|
+
filter: JSON.stringify(filter),
|
|
66
|
+
limit,
|
|
67
|
+
page,
|
|
68
|
+
});
|
|
69
|
+
return { _embedded: { items: users.map(remapUserResult) }, total };
|
|
70
|
+
}
|
|
71
|
+
export async function getCurrentUser(client) {
|
|
72
|
+
return remapUserResult(await client.get('/v1/me'));
|
|
73
|
+
}
|
|
74
|
+
export async function userGetById(client, userId) {
|
|
75
|
+
return remapUserResult(await client.get(`/v1/users/${userId}`));
|
|
76
|
+
}
|
|
77
|
+
export async function userUpdateById(client, userId, data) {
|
|
78
|
+
const { tenantIds: tenantIDs, ...rest } = data;
|
|
79
|
+
return remapUserResult(await client.patch(`/v1/users/${userId}`, { ...rest, tenantIDs }));
|
|
80
|
+
}
|
|
81
|
+
export async function userCreatePermission(client, userId, data) {
|
|
82
|
+
const { objectId: objectID, ...rest } = data;
|
|
83
|
+
const { objectID: resultObjectId, ...result } = await client.post(`/v1/users/${userId}/permissions`, {
|
|
84
|
+
...rest,
|
|
85
|
+
objectID,
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
...result,
|
|
89
|
+
objectId: resultObjectId,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export async function userCreatePermissionBatch(client, userId, permissions) {
|
|
93
|
+
const { objectId, objectType, roles, startDate, endDate } = permissions;
|
|
94
|
+
const batch = {
|
|
95
|
+
batch: roles.map((role) => ({
|
|
96
|
+
endDate: endDate?.toISOString(),
|
|
97
|
+
objectID: objectId,
|
|
98
|
+
objectType,
|
|
99
|
+
restrictions: [],
|
|
100
|
+
role,
|
|
101
|
+
startDate: startDate?.toISOString(),
|
|
102
|
+
})),
|
|
103
|
+
};
|
|
104
|
+
return !(await client.post(`/v1/users/${userId}/permissions`, batch));
|
|
105
|
+
}
|
|
106
|
+
export async function userGetPermissions(client, userId) {
|
|
107
|
+
const { _embedded: { items: permissions }, } = await client.get(`/v1/users/${userId}/roles?limit=-1`);
|
|
108
|
+
return permissions.map(({ objectID: objectId, ...result }) => ({
|
|
109
|
+
...result,
|
|
110
|
+
objectId,
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
export async function userDeletePermission(client, permissionId) {
|
|
114
|
+
return !(await client.delete(`/v1/permissions/${permissionId}`));
|
|
115
|
+
}
|
|
116
|
+
export async function userGetUtilisationPeriods(client, userId) {
|
|
117
|
+
const { _embedded: { items: utilisationPeriods }, } = await client.get(`/v1/users/${userId}/utilisation-periods`);
|
|
118
|
+
return utilisationPeriods;
|
|
119
|
+
}
|
|
120
|
+
export async function userCheckInToUtilisationPeriod(client, userId, utilisationPeriodId) {
|
|
121
|
+
const { email: userEmail } = await client.userGetById(userId);
|
|
122
|
+
return client.utilisationPeriodCheckInUser(utilisationPeriodId, {
|
|
123
|
+
email: userEmail,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
export async function userGetByEmail(client, email, page = 1, limit = 1000) {
|
|
127
|
+
return client.getUsers(page, limit, { email });
|
|
128
|
+
}
|
|
129
|
+
export async function userChangePassword(client, userId, currentPassword, newPassword) {
|
|
130
|
+
return !(await client.put(`/v1/users/${userId}/password`, {
|
|
131
|
+
currentPassword,
|
|
132
|
+
plainPassword: newPassword,
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export var EnumUserRelationType;
|
|
2
|
+
(function (EnumUserRelationType) {
|
|
3
|
+
EnumUserRelationType["isResponsible"] = "is-responsible";
|
|
4
|
+
})(EnumUserRelationType || (EnumUserRelationType = {}));
|
|
5
|
+
export async function userRelationCreate(client, userId, data) {
|
|
6
|
+
return client.post(`/v1/users/${userId}/user-relations/${data.type}`, {
|
|
7
|
+
ids: data.ids,
|
|
8
|
+
level: data.level,
|
|
9
|
+
readOnly: data.readOnly,
|
|
10
|
+
role: data.role,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export async function userRelationDelete(client, userId, data) {
|
|
14
|
+
return client.delete(`/v1/users/${userId}/user-relations/${data.type}`, {
|
|
15
|
+
ids: data.ids,
|
|
16
|
+
level: data.level,
|
|
17
|
+
role: data.role,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export async function userRelationsGetByUser(client, userId) {
|
|
21
|
+
return client.get(`/v1/users/${userId}/user-relations`);
|
|
22
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { remapRegistationCodeResult, } from './registrationCode';
|
|
2
|
+
import { remapEmbeddedUser } from './user';
|
|
3
|
+
export var EnumUtilisationPeriodType;
|
|
4
|
+
(function (EnumUtilisationPeriodType) {
|
|
5
|
+
EnumUtilisationPeriodType["tenant"] = "tenant";
|
|
6
|
+
EnumUtilisationPeriodType["ownership"] = "ownership";
|
|
7
|
+
EnumUtilisationPeriodType["vacant"] = "vacant";
|
|
8
|
+
})(EnumUtilisationPeriodType || (EnumUtilisationPeriodType = {}));
|
|
9
|
+
export async function utilisationPeriodCreate(client, unitId, data) {
|
|
10
|
+
const { tenantIDs: tenantIds, _embedded, ...result } = await client.post(`/v1/units/${unitId}/utilisation-periods`, data);
|
|
11
|
+
return {
|
|
12
|
+
...result,
|
|
13
|
+
invitations: _embedded.invitations.map(remapRegistationCodeResult),
|
|
14
|
+
tenantIds,
|
|
15
|
+
users: remapEmbeddedUser(_embedded),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export async function utilisationPeriodGetById(client, utilisationPeriodId) {
|
|
19
|
+
const { tenantIDs: tenantIds, _embedded, ...result } = await client.get(`/v1/utilisation-periods/${utilisationPeriodId}`);
|
|
20
|
+
return {
|
|
21
|
+
...result,
|
|
22
|
+
invitations: _embedded.invitations.map(remapRegistationCodeResult),
|
|
23
|
+
tenantIds,
|
|
24
|
+
users: remapEmbeddedUser(_embedded),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export async function utilisationPeriodUpdateById(client, utilisationPeriodId, data) {
|
|
28
|
+
const { tenantIDs: tenantIds, _embedded, ...result } = await client.patch(`/v1/utilisation-periods/${utilisationPeriodId}`, data);
|
|
29
|
+
return {
|
|
30
|
+
...result,
|
|
31
|
+
invitations: _embedded.invitations.map(remapRegistationCodeResult),
|
|
32
|
+
tenantIds,
|
|
33
|
+
users: remapEmbeddedUser(_embedded),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export async function utilisationPeriodDelete(client, utilisationPeriodId) {
|
|
37
|
+
return !(await client.delete(`/v1/utilisation-periods/${utilisationPeriodId}/soft`));
|
|
38
|
+
}
|
|
39
|
+
export async function utilisationPeriodCheckInUser(client, utilisationPeriodId, data) {
|
|
40
|
+
return ((await client.post(`/v1/utilisation-periods/${utilisationPeriodId}/users`, {
|
|
41
|
+
email: data.email,
|
|
42
|
+
})) && client.utilisationPeriodGetById(utilisationPeriodId));
|
|
43
|
+
}
|
|
44
|
+
export async function utilisationPeriodCheckOutUser(client, utilisationPeriodId, userId) {
|
|
45
|
+
return ((await client.delete(`/v1/utilisation-periods/${utilisationPeriodId}/users/${userId}`)) === '');
|
|
46
|
+
}
|
|
47
|
+
export async function utilisationPeriodAddRegistrationCode(client, utilisationPeriodId, code, tenant, permanent = false) {
|
|
48
|
+
return client.post(`/v1/utilisation-periods/${utilisationPeriodId}/registration-codes`, { code, permanent, tenant });
|
|
49
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import Bottleneck from 'bottleneck';
|
|
2
|
+
import { QUEUE_CONCURRENCY, QUEUE_DELAY, QUEUE_RESERVOIR, QUEUE_RESERVOIR_REFILL_INTERVAL, USER_AGENT, } from '../constants';
|
|
3
|
+
import maybeUpdateToken from '../oauth/maybeUpdateToken';
|
|
4
|
+
import { environment } from '../utils/environment';
|
|
5
|
+
import { clearIntervalFunction, until } from '../utils/functional';
|
|
6
|
+
import makeLogger from '../utils/logger';
|
|
7
|
+
import { buildQueryString } from '../utils/queryString';
|
|
8
|
+
import sleep from '../utils/sleep';
|
|
9
|
+
const requestLogger = makeLogger('REST API Request');
|
|
10
|
+
const responseLogger = makeLogger('REST API Response');
|
|
11
|
+
const RETRYABLE_STATUS_CODES = [401, 408, 429, 502, 503, 504];
|
|
12
|
+
const TOKEN_REFRESH_STATUS_CODES = [401];
|
|
13
|
+
const queue = new Bottleneck({
|
|
14
|
+
maxConcurrent: QUEUE_CONCURRENCY,
|
|
15
|
+
minTime: QUEUE_DELAY,
|
|
16
|
+
reservoir: QUEUE_RESERVOIR,
|
|
17
|
+
});
|
|
18
|
+
const refillIntervalSet = new Set();
|
|
19
|
+
function isFormData(body) {
|
|
20
|
+
return typeof body !== 'undefined' && body.formData !== undefined;
|
|
21
|
+
}
|
|
22
|
+
function refillReservoir() {
|
|
23
|
+
if (refillIntervalSet.size === 0) {
|
|
24
|
+
const interval = setInterval(async () => {
|
|
25
|
+
const reservoir = (await queue.currentReservoir());
|
|
26
|
+
if (queue.empty() && (await queue.running()) === 0 && reservoir > 10) {
|
|
27
|
+
return ((await queue.incrementReservoir(1)) &&
|
|
28
|
+
clearIntervalFunction(interval) &&
|
|
29
|
+
refillIntervalSet.delete(interval));
|
|
30
|
+
}
|
|
31
|
+
return reservoir < QUEUE_RESERVOIR
|
|
32
|
+
? queue.incrementReservoir(1)
|
|
33
|
+
: clearIntervalFunction(interval) && refillIntervalSet.delete(interval);
|
|
34
|
+
}, QUEUE_RESERVOIR_REFILL_INTERVAL);
|
|
35
|
+
return refillIntervalSet.add(interval);
|
|
36
|
+
}
|
|
37
|
+
return refillIntervalSet;
|
|
38
|
+
}
|
|
39
|
+
async function makeResultFromResponse(response) {
|
|
40
|
+
if (RETRYABLE_STATUS_CODES.includes(response.status)) {
|
|
41
|
+
return response.clone();
|
|
42
|
+
}
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
return new Error(`${response.status} ${response.statusText}\n\n${await response.text()}`);
|
|
45
|
+
}
|
|
46
|
+
if (response.headers.get('content-type') !== 'application/json' &&
|
|
47
|
+
response.status !== 204) {
|
|
48
|
+
return new Error(`Response content type was "${response.headers.get('content-type')}" but expected JSON`);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
body: response.status === 204 ? '' : await response.json(),
|
|
52
|
+
status: response.status,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function responseWasSuccessful(response) {
|
|
56
|
+
return !RETRYABLE_STATUS_CODES.includes(response.status);
|
|
57
|
+
}
|
|
58
|
+
export function makeApiRequest(oauthTokenStore, oauthTokenRequester, options, httpMethod, apiMethod, payload, returnRawResultObject) {
|
|
59
|
+
return async (previousResult, retryCount) => {
|
|
60
|
+
if (retryCount > 0) {
|
|
61
|
+
if (retryCount > options.requestMaxRetries) {
|
|
62
|
+
const error = `Maximum number of retries reached while retrying ${previousResult.method} request ${previousResult.path}.`;
|
|
63
|
+
requestLogger.error(error);
|
|
64
|
+
throw new Error(error);
|
|
65
|
+
}
|
|
66
|
+
requestLogger.warn(`Warning: encountered ${previousResult.status}. Retrying ${previousResult.method} request ${previousResult.path} (retry #${retryCount}).`);
|
|
67
|
+
await sleep(Math.ceil(Math.random() *
|
|
68
|
+
options.requestBackOffInterval *
|
|
69
|
+
2 ** retryCount));
|
|
70
|
+
}
|
|
71
|
+
await maybeUpdateToken(oauthTokenStore, oauthTokenRequester, options, retryCount > 0 &&
|
|
72
|
+
TOKEN_REFRESH_STATUS_CODES.includes(previousResult.status));
|
|
73
|
+
const payloadQuery = payload?.query
|
|
74
|
+
? (apiMethod.includes('?') ? '&' : '?') + buildQueryString(payload.query)
|
|
75
|
+
: '';
|
|
76
|
+
const url = `${options.apiUrl}/api${apiMethod}${payloadQuery}`;
|
|
77
|
+
if (!oauthTokenStore.get('accessToken')) {
|
|
78
|
+
throw new Error(`Unable to get OAuth2 access token. Error trying to call endpoint: ${url}`);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return (refillReservoir() &&
|
|
82
|
+
(await queue.schedule(async () => {
|
|
83
|
+
const method = httpMethod.toUpperCase();
|
|
84
|
+
const body = payload?.body;
|
|
85
|
+
const hasForm = isFormData(body);
|
|
86
|
+
const form = isFormData(body) ? body.formData : {};
|
|
87
|
+
const formData = Object.entries(form).reduce((previous, [name, value]) => {
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
const [content, filename] = value;
|
|
90
|
+
const blobContent = content instanceof Blob ? content : new Blob([content]);
|
|
91
|
+
previous.append(name, blobContent, filename);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
previous.append(name, value);
|
|
95
|
+
}
|
|
96
|
+
return previous;
|
|
97
|
+
}, new FormData());
|
|
98
|
+
const headers = {
|
|
99
|
+
accept: 'application/json',
|
|
100
|
+
authorization: `Bearer ${oauthTokenStore.get('accessToken')}`,
|
|
101
|
+
'X-Allthings-Caller': `${options.serviceName
|
|
102
|
+
? options.serviceName
|
|
103
|
+
:
|
|
104
|
+
environment.SEVICE_NAME
|
|
105
|
+
? environment.SEVICE_NAME
|
|
106
|
+
: 'unknown service name'} --- clientID ${options.clientId?.split('_')[0] ??
|
|
107
|
+
options.clientId ??
|
|
108
|
+
'no client id present'}`,
|
|
109
|
+
...(hasForm ? {} : { 'content-type': 'application/json' }),
|
|
110
|
+
...(typeof window === 'undefined' &&
|
|
111
|
+
typeof document === 'undefined' && { 'user-agent': USER_AGENT }),
|
|
112
|
+
...payload?.headers,
|
|
113
|
+
};
|
|
114
|
+
if (environment.LOG_REQUEST) {
|
|
115
|
+
console.log({ sdkLogs: { method, url } });
|
|
116
|
+
}
|
|
117
|
+
requestLogger.log(method, url, {
|
|
118
|
+
body,
|
|
119
|
+
headers,
|
|
120
|
+
});
|
|
121
|
+
const requestBody = {
|
|
122
|
+
body: hasForm ? formData : JSON.stringify(body),
|
|
123
|
+
};
|
|
124
|
+
const response = await fetch(url, {
|
|
125
|
+
cache: 'no-cache',
|
|
126
|
+
credentials: 'omit',
|
|
127
|
+
headers,
|
|
128
|
+
method,
|
|
129
|
+
mode: 'cors',
|
|
130
|
+
...(hasForm || body ? requestBody : {}),
|
|
131
|
+
});
|
|
132
|
+
const result = await makeResultFromResponse(response);
|
|
133
|
+
responseLogger.log(method, url, result instanceof Error
|
|
134
|
+
? { error: result }
|
|
135
|
+
: {
|
|
136
|
+
body: result.body,
|
|
137
|
+
status: response.status,
|
|
138
|
+
});
|
|
139
|
+
return result instanceof Error && returnRawResultObject
|
|
140
|
+
? {
|
|
141
|
+
body: result.message,
|
|
142
|
+
status: response.status,
|
|
143
|
+
}
|
|
144
|
+
: result;
|
|
145
|
+
})));
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
return error;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export default async function request(oauthTokenStore, oauthTokenRequester, options, httpMethod, apiMethod, payload, returnRawResultObject) {
|
|
153
|
+
const result = await until(responseWasSuccessful, makeApiRequest(oauthTokenStore, oauthTokenRequester, options, httpMethod, apiMethod, payload, returnRawResultObject));
|
|
154
|
+
if (result instanceof Error) {
|
|
155
|
+
requestLogger.log('Request Error', result, payload);
|
|
156
|
+
throw result;
|
|
157
|
+
}
|
|
158
|
+
return returnRawResultObject ? result : result.body;
|
|
159
|
+
}
|