@mapcreator/api 2.5.0 → 2.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapcreator/api",
3
- "version": "2.5.0",
3
+ "version": "2.6.2",
4
4
  "description": "Mapcreator JavaScript API",
5
5
  "main": "dist/bundle.js",
6
6
  "repository": "https://gitlab.com/mapcreator/api-wrapper.git",
@@ -56,7 +56,7 @@
56
56
  "scripts": {
57
57
  "build": "APP_ENV=production npx webpack",
58
58
  "watch": "npx webpack --progress --watch",
59
- "docs": "npx esdoc",
59
+ "docs": "npx esdoc && ./scripts/inject_docs_viewport.sh",
60
60
  "lint": "npx eslint --no-color --format checkstyle --output-file build/checkstyle.xml src",
61
61
  "clean": "rm -fr dist docs build || true",
62
62
  "all": "npm run clean && npm run lint && npm run build && npm run test && npm run docs",
package/src/Mapcreator.js CHANGED
@@ -70,6 +70,8 @@ import {
70
70
  User,
71
71
  VectorHighlight,
72
72
  VectorChoropleth,
73
+ ProductTour,
74
+ ProductTourStep,
73
75
  } from './resources';
74
76
  import ResourceBase from './resources/base/ResourceBase';
75
77
  import Injectable from './traits/Injectable';
@@ -587,6 +589,14 @@ export default class Mapcreator extends mix(EventEmitter, Injectable) {
587
589
  return this.static(Permission);
588
590
  }
589
591
 
592
+ get productTours () {
593
+ return this.static(ProductTour);
594
+ }
595
+
596
+ get productTourSteps () {
597
+ return this.static(ProductTourStep);
598
+ }
599
+
590
600
  /**
591
601
  * Role accessor
592
602
  * @see {@link Role}
@@ -32,12 +32,36 @@
32
32
 
33
33
  import CrudBase from './base/CrudBase';
34
34
  import MessageVariant from './MessageVariant';
35
+ import { makeCancelable } from '../utils/helpers';
36
+ import { camel as camelCase, snake as snakeCase } from 'case';
35
37
 
36
38
  export default class Message extends CrudBase {
37
39
  static get resourceName () {
38
40
  return 'messages';
39
41
  }
40
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
+
41
65
  _guessType (name, value) {
42
66
  if (name === 'variants') {
43
67
  return Array.from(value).map(data => new MessageVariant(this.api, data));
@@ -45,4 +69,26 @@ export default class Message extends CrudBase {
45
69
 
46
70
  return super._guessType(name, value);
47
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
+ }
48
94
  }
@@ -0,0 +1,53 @@
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 { mix } from '../utils/reflection';
34
+ import CrudSetBase from './base/CrudSetBase';
35
+ import ProductTourStep from './ProductTourStep';
36
+
37
+ /**
38
+ * Mapstyle set
39
+ * @extends CrudSetBase
40
+ */
41
+ export default class ProductTour extends mix(CrudSetBase) {
42
+ static get resourcePath () {
43
+ return '/product-tours/{id}';
44
+ }
45
+
46
+ static get resourceName () {
47
+ return 'product-tours';
48
+ }
49
+
50
+ get _Child () {
51
+ return ProductTourStep;
52
+ }
53
+ }
@@ -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 { mix } from '../utils/reflection';
34
+ import CrudSetItemBase from './base/CrudSetItemBase';
35
+
36
+ /**
37
+ * @extends CrudSetItemBase
38
+ */
39
+ export default class ProductTourStep extends mix(CrudSetItemBase) {
40
+ static get resourceName () {
41
+ return 'product-tours/steps';
42
+ }
43
+
44
+ static get parentKey () {
45
+ return 'product_tour_id';
46
+ }
47
+ }
48
+
@@ -103,11 +103,20 @@ export default class User extends CrudBase {
103
103
  }
104
104
 
105
105
  /**
106
- * Get the list messagse linked to the user
107
- * @returns {SimpleResourceProxy} - A proxy for accessing the resource
106
+ * Get a list of read/unread messages for the user
107
+ * @returns {CancelablePromise<{read: Message[], unread: Message[]}>} - Read and unread messages
108
108
  */
109
- get messages () {
110
- return this._proxyResourceList(Message);
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
+ });
111
120
  }
112
121
 
113
122
  /**
@@ -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
- * @private
114
+ * @protected
115
115
  */
116
116
  _update () {
117
117
  this._updateProperties();
@@ -55,6 +55,8 @@ export Message from './Message';
55
55
  export Notification from './Notification';
56
56
  export Organisation from './Organisation';
57
57
  export Permission from './Permission';
58
+ export ProductTour from './ProductTour';
59
+ export ProductTourStep from './ProductTourStep';
58
60
  export Role from './Role';
59
61
  export Svg from './Svg';
60
62
  export SvgSet from './SvgSet';