@mapcreator/api 2.3.6 → 2.5.0

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.
@@ -150,4 +150,4 @@ const promise = api.jobs.select(123456).downloadPreview();
150
150
  promise.cancel();
151
151
  ```
152
152
 
153
- [api documentation]: https://docs.maps4news.com/
153
+ [api documentation]: https://docs.mapcreator.io/
@@ -16,7 +16,7 @@ var m4n = require('@mapcreator/api');
16
16
 
17
17
  // Do stuff
18
18
  var auth = new m4n.ImplicitFlow(1);
19
- var api = new m4n.Maps4News(auth);
19
+ var api = new m4n.Mapcreator(auth);
20
20
  ```
21
21
 
22
22
  or using ES6 import statements:
@@ -30,4 +30,4 @@ var api = new Mapcreator(auth);
30
30
  ```
31
31
 
32
32
  [npm]: https://npmjs.com
33
- [yarn]: https://yarnpkg.com
33
+ [yarn]: https://yarnpkg.com
@@ -1,26 +1,26 @@
1
1
  (function() {
2
2
  if (window.name) {
3
- new window.maps4news.ImplicitFlowPopup(1);
3
+ new window.mapcrator.ImplicitFlowPopup(1);
4
4
  }
5
5
  })();
6
6
 
7
7
 
8
8
  function easyAuth() {
9
- var m4n = window.maps4news;
9
+ var mc = window.mapcreator;
10
10
 
11
11
  var clientId = 3;
12
- var docsUrl = 'https://docs.maps4news.com/wrapper/';
13
- var auth = new m4n.ImplicitFlowPopup(clientId, docsUrl);
14
- var api = new m4n.Maps4News(auth);
12
+ var docsUrl = 'https://docs.mapcreator.io/wrapper/';
13
+ var auth = new mc.ImplicitFlowPopup(clientId, docsUrl);
14
+ var api = new mc.Mapcreator(auth);
15
15
 
16
- api.host = 'https://api.beta.maps4news.com/';
16
+ api.host = 'https://api.beta.mapcreator.io/';
17
17
 
18
18
  return api.authenticate();
19
19
  }
20
20
 
21
- console.log('You can play around with the api in here, the library is bound to window.maps4news. Authentication ');
21
+ console.log('You can play around with the api in here, the library is bound to window.mapcreator. Authentication ');
22
22
  console.log('can easily be done by running the command easyAuth(). See the docs for more information here: ');
23
- console.log('https://docs.maps4news.com/wrapper/manual/example/examples.authentication.html');
23
+ console.log('https://docs.mapcreator.io/wrapper/manual/example/examples.authentication.html');
24
24
  console.log('Example: easyAuth().then(api => window.api = api);');
25
- console.log('window.maps4news =', window.maps4news);
25
+ console.log('window.mapcreator =', window.mapcreator);
26
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapcreator/api",
3
- "version": "2.3.6",
3
+ "version": "2.5.0",
4
4
  "description": "Mapcreator JavaScript API",
5
5
  "main": "dist/bundle.js",
6
6
  "repository": "https://gitlab.com/mapcreator/api-wrapper.git",
@@ -76,7 +76,7 @@
76
76
  "esdoc": {
77
77
  "source": "./src",
78
78
  "destination": "./docs",
79
- "name": "maps4news",
79
+ "name": "mapcreator",
80
80
  "plugins": [
81
81
  {
82
82
  "name": "esdoc-standard-plugin",
@@ -98,8 +98,8 @@
98
98
  "enable": true
99
99
  },
100
100
  "brand": {
101
- "title": "Maps4News Api Wrapper",
102
- "description": "Maps4News Api Javascript Wrapper"
101
+ "title": "Mapcreator Api Wrapper",
102
+ "description": "Mapcreator Api Javascript Wrapper"
103
103
  },
104
104
  "manual": {
105
105
  "asset": "./manual/assets",
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}
@@ -216,8 +216,11 @@ export default class ImplicitFlow extends OAuth {
216
216
  }
217
217
 
218
218
  const params = this._getAnchorParams();
219
- const message = params.message ?? titleCase(params.error);
220
219
 
221
- return new OAuthError(params.error, message);
220
+ if (params.message) {
221
+ return new OAuthError(params.error, params.message);
222
+ }
223
+
224
+ return new OAuthError(params.error, titleCase(params.error));
222
225
  }
223
226
  }
@@ -0,0 +1,48 @@
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
+
36
+ export default class Message extends CrudBase {
37
+ static get resourceName () {
38
+ return 'messages';
39
+ }
40
+
41
+ _guessType (name, value) {
42
+ if (name === 'variants') {
43
+ return Array.from(value).map(data => new MessageVariant(this.api, data));
44
+ }
45
+
46
+ return super._guessType(name, value);
47
+ }
48
+ }
@@ -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
+ }
@@ -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,14 @@ export default class User extends CrudBase {
101
102
  return this._proxyResourceList(Notification);
102
103
  }
103
104
 
105
+ /**
106
+ * Get the list messagse linked to the user
107
+ * @returns {SimpleResourceProxy} - A proxy for accessing the resource
108
+ */
109
+ get messages () {
110
+ return this._proxyResourceList(Message);
111
+ }
112
+
104
113
  /**
105
114
  * Get the list mapstyle sets linked to the user
106
115
  * @returns {SimpleResourceProxy} - A proxy for accessing the resource
@@ -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 = { ...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.constructor._guessType(newKey, data[key]);
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] = ResourceBase._guessType(key, val);
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
- * @private
312
+ * @protected
313
313
  * @returns {*} - Original or converted value
314
314
  */
315
- static _guessType (name, value) {
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) {
@@ -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';
@@ -67,15 +67,6 @@ export default class FileDriver extends DataStoreContract {
67
67
  this._path = value;
68
68
  }
69
69
 
70
- get realPath () {
71
- if (this.path.startsWith('/')) {
72
- return this.path;
73
- }
74
-
75
- // eslint-disable-next-line no-undef
76
- return this._fs.realpathSync(this.path);
77
- }
78
-
79
70
  /**
80
71
  * @inheritDoc
81
72
  */
@@ -142,7 +133,7 @@ export default class FileDriver extends DataStoreContract {
142
133
  let data;
143
134
 
144
135
  try {
145
- data = this._fs.readFileSync(this.realPath).toString();
136
+ data = this._fs.readFileSync(this.path).toString();
146
137
  } catch (e) {
147
138
  data = '{}';
148
139
  }
@@ -161,7 +152,7 @@ export default class FileDriver extends DataStoreContract {
161
152
  */
162
153
  _write (obj) {
163
154
  const data = JSON.stringify(obj);
164
- const fd = this._fs.openSync(this.realPath, 'w');
155
+ const fd = this._fs.openSync(this.path, 'w');
165
156
 
166
157
  this._fs.writeSync(fd, data);
167
158
  this._fs.closeSync(fd);
@@ -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
+ }