@mapcreator/api 2.4.1 → 2.6.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/dist/bundle.browser.js +682 -472
- package/dist/bundle.browser.js.map +1 -1
- package/dist/bundle.browser.min.js +1 -1
- package/dist/bundle.browser.min.js.LICENSE.txt +2 -2
- package/dist/bundle.browser.min.js.map +1 -1
- package/dist/bundle.js +432 -222
- package/dist/bundle.js.map +1 -1
- package/dist/bundle.min.js +1 -1
- package/dist/bundle.min.js.LICENSE.txt +1 -1
- package/dist/bundle.min.js.map +1 -1
- package/package.json +1 -1
- package/src/Mapcreator.js +10 -0
- package/src/resources/Message.js +94 -0
- package/src/resources/MessageVariant.js +37 -0
- package/src/resources/User.js +18 -0
- package/src/resources/base/CrudBase.js +1 -1
- package/src/resources/base/ResourceBase.js +6 -6
- package/src/resources/index.js +1 -0
- package/src/utils/helpers.js +22 -0
package/package.json
CHANGED
package/src/Mapcreator.js
CHANGED
|
@@ -58,6 +58,7 @@ import {
|
|
|
58
58
|
Layer,
|
|
59
59
|
Mapstyle,
|
|
60
60
|
MapstyleSet,
|
|
61
|
+
Message,
|
|
61
62
|
Notification,
|
|
62
63
|
Organisation,
|
|
63
64
|
Permission,
|
|
@@ -559,6 +560,15 @@ export default class Mapcreator extends mix(EventEmitter, Injectable) {
|
|
|
559
560
|
return this.static(Notification);
|
|
560
561
|
}
|
|
561
562
|
|
|
563
|
+
/**
|
|
564
|
+
* Message accessor
|
|
565
|
+
* @see {@link Message}
|
|
566
|
+
* @returns {ResourceProxy} - A proxy for accessing the resource
|
|
567
|
+
*/
|
|
568
|
+
get messages () {
|
|
569
|
+
return this.static(Message);
|
|
570
|
+
}
|
|
571
|
+
|
|
562
572
|
/**
|
|
563
573
|
* Organisation accessor
|
|
564
574
|
* @see {@link Organisation}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* BSD 3-Clause License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020, Mapcreator
|
|
5
|
+
* All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
|
9
|
+
*
|
|
10
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
11
|
+
* list of conditions and the following disclaimer.
|
|
12
|
+
*
|
|
13
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
* and/or other materials provided with the distribution.
|
|
16
|
+
*
|
|
17
|
+
* Neither the name of the copyright holder nor the names of its
|
|
18
|
+
* contributors may be used to endorse or promote products derived from
|
|
19
|
+
* this software without specific prior written permission.
|
|
20
|
+
*
|
|
21
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
24
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
25
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
26
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
27
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
28
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
29
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import CrudBase from './base/CrudBase';
|
|
34
|
+
import MessageVariant from './MessageVariant';
|
|
35
|
+
import { makeCancelable } from '../utils/helpers';
|
|
36
|
+
import { camel as camelCase, snake as snakeCase } from 'case';
|
|
37
|
+
|
|
38
|
+
export default class Message extends CrudBase {
|
|
39
|
+
static get resourceName () {
|
|
40
|
+
return 'messages';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
toObject (camelCaseKeys = false) {
|
|
44
|
+
const superObject = super.toObject(camelCaseKeys);
|
|
45
|
+
|
|
46
|
+
superObject.variants = superObject.variants.map(variant => {
|
|
47
|
+
if (variant instanceof MessageVariant) {
|
|
48
|
+
return variant.toObject(camelCaseKeys);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const caseFn = camelCaseKeys ? camelCase : snakeCase;
|
|
52
|
+
const res = {};
|
|
53
|
+
const fields = Object.keys(variant);
|
|
54
|
+
|
|
55
|
+
for (const field of fields) {
|
|
56
|
+
res[caseFn(field)] = variant[field];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return res;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return superObject;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_guessType (name, value) {
|
|
66
|
+
if (name === 'variants') {
|
|
67
|
+
return Array.from(value).map(data => new MessageVariant(this.api, data));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return super._guessType(name, value);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
_buildCreateData () {
|
|
74
|
+
return this.toObject();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
_update () {
|
|
78
|
+
return makeCancelable(async signal => {
|
|
79
|
+
const json = this.toObject();
|
|
80
|
+
|
|
81
|
+
await this.api.ky.patch(this.url, { json, signal });
|
|
82
|
+
|
|
83
|
+
// Reset changes
|
|
84
|
+
Object.assign(this._baseProperties, this._properties);
|
|
85
|
+
this._properties = {};
|
|
86
|
+
|
|
87
|
+
if ('updated_at' in this._baseProperties) {
|
|
88
|
+
this._baseProperties['updated_at'] = new Date();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return this;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* BSD 3-Clause License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020, Mapcreator
|
|
5
|
+
* All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
|
9
|
+
*
|
|
10
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
11
|
+
* list of conditions and the following disclaimer.
|
|
12
|
+
*
|
|
13
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
* and/or other materials provided with the distribution.
|
|
16
|
+
*
|
|
17
|
+
* Neither the name of the copyright holder nor the names of its
|
|
18
|
+
* contributors may be used to endorse or promote products derived from
|
|
19
|
+
* this software without specific prior written permission.
|
|
20
|
+
*
|
|
21
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
24
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
25
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
26
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
27
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
28
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
29
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
import ResourceBase from './base/ResourceBase';
|
|
35
|
+
|
|
36
|
+
export default class MessageVariant extends ResourceBase {
|
|
37
|
+
}
|
package/src/resources/User.js
CHANGED
|
@@ -46,6 +46,7 @@ import Language from './Language';
|
|
|
46
46
|
import Layer from './Layer';
|
|
47
47
|
import Mapstyle from './Mapstyle';
|
|
48
48
|
import MapstyleSet from './MapstyleSet';
|
|
49
|
+
import Message from './Message';
|
|
49
50
|
import Notification from './Notification';
|
|
50
51
|
import Organisation from './Organisation';
|
|
51
52
|
import Permission from './Permission';
|
|
@@ -101,6 +102,23 @@ export default class User extends CrudBase {
|
|
|
101
102
|
return this._proxyResourceList(Notification);
|
|
102
103
|
}
|
|
103
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Get a list of read/unread messages for the user
|
|
107
|
+
* @returns {CancelablePromise<{read: Message[], unread: Message[]}>} - Read and unread messages
|
|
108
|
+
*/
|
|
109
|
+
messages () {
|
|
110
|
+
const url = `${this.url}/messages`;
|
|
111
|
+
|
|
112
|
+
return makeCancelable(async signal => {
|
|
113
|
+
const { data } = await this.api.ky.get(url, { signal }).json();
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
read: data.read.map(o => new Message(this.api, o)),
|
|
117
|
+
unread: data.unread.map(o => new Message(this.api, o)),
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
104
122
|
/**
|
|
105
123
|
* Get the list mapstyle sets linked to the user
|
|
106
124
|
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
|
|
@@ -111,7 +111,7 @@ export default class CrudBase extends ResourceBase {
|
|
|
111
111
|
* @returns {CancelablePromise<CrudBase>} - Current instance
|
|
112
112
|
* @throws {ApiError} - If the api returns errors
|
|
113
113
|
* @throws {ValidationError} - If the submitted data isn't valid
|
|
114
|
-
* @
|
|
114
|
+
* @protected
|
|
115
115
|
*/
|
|
116
116
|
_update () {
|
|
117
117
|
this._updateProperties();
|
|
@@ -37,7 +37,7 @@ import SimpleResourceProxy from '../../proxy/SimpleResourceProxy';
|
|
|
37
37
|
import Injectable from '../../traits/Injectable';
|
|
38
38
|
import { fnv32b } from '../../utils/hash';
|
|
39
39
|
import { isParentOf, mix } from '../../utils/reflection';
|
|
40
|
-
import { makeCancelable } from '../../utils/helpers';
|
|
40
|
+
import { clone, makeCancelable } from '../../utils/helpers';
|
|
41
41
|
|
|
42
42
|
function unique (input) {
|
|
43
43
|
return input.filter((v, i) => input.findIndex(vv => vv === v) === i);
|
|
@@ -62,7 +62,7 @@ export default class ResourceBase extends mix(null, Injectable) {
|
|
|
62
62
|
this.api = api;
|
|
63
63
|
|
|
64
64
|
// De-reference
|
|
65
|
-
data =
|
|
65
|
+
data = clone(data);
|
|
66
66
|
|
|
67
67
|
// Normalize keys to snake_case
|
|
68
68
|
// Fix data types
|
|
@@ -75,7 +75,7 @@ export default class ResourceBase extends mix(null, Injectable) {
|
|
|
75
75
|
continue;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
data[newKey] = this.
|
|
78
|
+
data[newKey] = this._guessType(newKey, data[key]);
|
|
79
79
|
|
|
80
80
|
if (newKey !== key) {
|
|
81
81
|
delete data[key];
|
|
@@ -295,7 +295,7 @@ export default class ResourceBase extends mix(null, Injectable) {
|
|
|
295
295
|
|
|
296
296
|
if (!this.constructor.protectedFields.includes(key) && !this.constructor.readonly) {
|
|
297
297
|
desc.set = val => {
|
|
298
|
-
this._properties[key] =
|
|
298
|
+
this._properties[key] = this._guessType(key, val);
|
|
299
299
|
delete this._url; // Clears url cache
|
|
300
300
|
};
|
|
301
301
|
}
|
|
@@ -309,10 +309,10 @@ export default class ResourceBase extends mix(null, Injectable) {
|
|
|
309
309
|
* Guess type based on property name
|
|
310
310
|
* @param {string} name - Field name
|
|
311
311
|
* @param {*} value - Field Value
|
|
312
|
-
* @
|
|
312
|
+
* @protected
|
|
313
313
|
* @returns {*} - Original or converted value
|
|
314
314
|
*/
|
|
315
|
-
|
|
315
|
+
_guessType (name, value) {
|
|
316
316
|
if (name.endsWith('_at') || name.startsWith('date_')) {
|
|
317
317
|
return typeof value === 'string' ? new Date(value.replace(' ', 'T')) : value;
|
|
318
318
|
} else if (/(_|^)id$/.test(name) && value !== null) {
|
package/src/resources/index.js
CHANGED
|
@@ -51,6 +51,7 @@ export Language from './Language';
|
|
|
51
51
|
export Layer from './Layer';
|
|
52
52
|
export Mapstyle from './Mapstyle';
|
|
53
53
|
export MapstyleSet from './MapstyleSet';
|
|
54
|
+
export Message from './Message';
|
|
54
55
|
export Notification from './Notification';
|
|
55
56
|
export Organisation from './Organisation';
|
|
56
57
|
export Permission from './Permission';
|
package/src/utils/helpers.js
CHANGED
|
@@ -154,3 +154,25 @@ export function serializeUTCDate (date) {
|
|
|
154
154
|
|
|
155
155
|
return out;
|
|
156
156
|
}
|
|
157
|
+
|
|
158
|
+
export function clone (input, clonePrivate = true) {
|
|
159
|
+
const _clone = value => clone(value, clonePrivate);
|
|
160
|
+
|
|
161
|
+
if (typeof input !== 'object' || input === null) {
|
|
162
|
+
return input;
|
|
163
|
+
} else if (Array.isArray(input)) {
|
|
164
|
+
return input.map(_clone);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const output = {};
|
|
168
|
+
|
|
169
|
+
for (const key of Object.keys(input)) {
|
|
170
|
+
if (!clonePrivate && key.startsWith('_')) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
output[key] = _clone(input[key]);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return output;
|
|
178
|
+
}
|