cozy-client 35.7.0 → 36.0.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.
@@ -2669,7 +2669,7 @@ var CozyClient = /*#__PURE__*/function () {
2669
2669
  CozyClient.hooks = CozyClient.hooks || {};
2670
2670
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2671
2671
 
2672
- CozyClient.version = "35.7.0";
2672
+ CozyClient.version = "36.0.0";
2673
2673
 
2674
2674
  _microee.default.mixin(CozyClient);
2675
2675
 
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "rootCozyUrl", {
33
33
  return _urlHelper.rootCozyUrl;
34
34
  }
35
35
  });
36
+ Object.defineProperty(exports, "InvalidRedirectLinkError", {
37
+ enumerable: true,
38
+ get: function get() {
39
+ return _urlHelper.InvalidRedirectLinkError;
40
+ }
41
+ });
36
42
  Object.defineProperty(exports, "InvalidCozyUrlError", {
37
43
  enumerable: true,
38
44
  get: function get() {
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.rootCozyUrl = exports.InvalidCozyUrlError = exports.InvalidProtocolError = exports.deconstructRedirectLink = exports.deconstructCozyWebLinkWithSlug = exports.generateWebLink = exports.ensureFirstSlash = void 0;
8
+ exports.rootCozyUrl = exports.InvalidCozyUrlError = exports.InvalidProtocolError = exports.InvalidRedirectLinkError = exports.deconstructRedirectLink = exports.deconstructCozyWebLinkWithSlug = exports.generateWebLink = exports.ensureFirstSlash = void 0;
9
9
 
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
 
@@ -131,16 +131,21 @@ var deconstructCozyWebLinkWithSlug = function deconstructCozyWebLinkWithSlug(web
131
131
  slug: slug
132
132
  };
133
133
  };
134
+
135
+ exports.deconstructCozyWebLinkWithSlug = deconstructCozyWebLinkWithSlug;
136
+
137
+ var isValidSlug = function isValidSlug(slug) {
138
+ return slug.match(/^[a-z0-9]+$/);
139
+ };
134
140
  /**
135
- * Deconstruct the given redirect link in order to retrieve slug and hash
141
+ * Deconstruct the given redirect link in order to retrieve slug, pathname and hash
136
142
  *
137
- * @param {string} redirectLink - redirect link to deconstruct (i.e. 'slug/#/path')
143
+ * @param {string} redirectLink - redirect link to deconstruct (i.e. 'drive/public/#/folder/SOME_ID')
138
144
  * @returns {RedirectLinkData} Deconstructed link
145
+ * @throws {InvalidRedirectLinkError} Thrown when redirect link is invalid
139
146
  */
140
147
 
141
148
 
142
- exports.deconstructCozyWebLinkWithSlug = deconstructCozyWebLinkWithSlug;
143
-
144
149
  var deconstructRedirectLink = function deconstructRedirectLink(redirectLink) {
145
150
  var _redirectLink$split = redirectLink.split('#'),
146
151
  _redirectLink$split2 = (0, _slicedToArray2.default)(_redirectLink$split, 2),
@@ -150,48 +155,71 @@ var deconstructRedirectLink = function deconstructRedirectLink(redirectLink) {
150
155
  var _splits$split = splits.split(/\/(.*)/),
151
156
  _splits$split2 = (0, _slicedToArray2.default)(_splits$split, 2),
152
157
  slug = _splits$split2[0],
153
- path = _splits$split2[1];
158
+ pathname = _splits$split2[1];
159
+
160
+ if (!isValidSlug(slug)) {
161
+ throw new InvalidRedirectLinkError(redirectLink);
162
+ }
154
163
 
155
164
  return {
156
165
  slug: slug,
157
- path: path,
166
+ pathname: pathname,
158
167
  hash: hash
159
168
  };
160
169
  };
161
170
 
162
171
  exports.deconstructRedirectLink = deconstructRedirectLink;
163
172
 
164
- var InvalidProtocolError = /*#__PURE__*/function (_Error) {
165
- (0, _inherits2.default)(InvalidProtocolError, _Error);
173
+ var InvalidRedirectLinkError = /*#__PURE__*/function (_Error) {
174
+ (0, _inherits2.default)(InvalidRedirectLinkError, _Error);
166
175
 
167
- var _super = _createSuper(InvalidProtocolError);
176
+ var _super = _createSuper(InvalidRedirectLinkError);
168
177
 
169
- function InvalidProtocolError(url) {
178
+ function InvalidRedirectLinkError(redirectLink) {
170
179
  var _this;
171
180
 
172
- (0, _classCallCheck2.default)(this, InvalidProtocolError);
173
- _this = _super.call(this, "Invalid URL protocol ".concat(url.protocol));
174
- _this.url = url;
181
+ (0, _classCallCheck2.default)(this, InvalidRedirectLinkError);
182
+ _this = _super.call(this, "Invalid redirect link ".concat(redirectLink));
183
+ _this.redirectLink = redirectLink;
175
184
  return _this;
176
185
  }
177
186
 
187
+ return InvalidRedirectLinkError;
188
+ }( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
189
+
190
+ exports.InvalidRedirectLinkError = InvalidRedirectLinkError;
191
+
192
+ var InvalidProtocolError = /*#__PURE__*/function (_Error2) {
193
+ (0, _inherits2.default)(InvalidProtocolError, _Error2);
194
+
195
+ var _super2 = _createSuper(InvalidProtocolError);
196
+
197
+ function InvalidProtocolError(url) {
198
+ var _this2;
199
+
200
+ (0, _classCallCheck2.default)(this, InvalidProtocolError);
201
+ _this2 = _super2.call(this, "Invalid URL protocol ".concat(url.protocol));
202
+ _this2.url = url;
203
+ return _this2;
204
+ }
205
+
178
206
  return InvalidProtocolError;
179
207
  }( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
180
208
 
181
209
  exports.InvalidProtocolError = InvalidProtocolError;
182
210
 
183
- var InvalidCozyUrlError = /*#__PURE__*/function (_Error2) {
184
- (0, _inherits2.default)(InvalidCozyUrlError, _Error2);
211
+ var InvalidCozyUrlError = /*#__PURE__*/function (_Error3) {
212
+ (0, _inherits2.default)(InvalidCozyUrlError, _Error3);
185
213
 
186
- var _super2 = _createSuper(InvalidCozyUrlError);
214
+ var _super3 = _createSuper(InvalidCozyUrlError);
187
215
 
188
216
  function InvalidCozyUrlError(url) {
189
- var _this2;
217
+ var _this3;
190
218
 
191
219
  (0, _classCallCheck2.default)(this, InvalidCozyUrlError);
192
- _this2 = _super2.call(this, "URL ".concat(url.toString(), " does not seem to be a valid Cozy URL"));
193
- _this2.url = url;
194
- return _this2;
220
+ _this3 = _super3.call(this, "URL ".concat(url.toString(), " does not seem to be a valid Cozy URL"));
221
+ _this3.url = url;
222
+ return _this3;
195
223
  }
196
224
 
197
225
  return InvalidCozyUrlError;
@@ -5,6 +5,7 @@ import {
5
5
  deconstructRedirectLink,
6
6
  generateWebLink,
7
7
  rootCozyUrl,
8
+ InvalidRedirectLinkError,
8
9
  InvalidCozyUrlError,
9
10
  InvalidProtocolError
10
11
  } from './urlHelper'
@@ -124,7 +125,7 @@ describe('deconstructRedirectLink', () => {
124
125
  'contacts/#/',
125
126
  {
126
127
  slug: 'contacts',
127
- path: '',
128
+ pathname: '',
128
129
  hash: '/'
129
130
  }
130
131
  ],
@@ -132,7 +133,7 @@ describe('deconstructRedirectLink', () => {
132
133
  'contacts/#/hash',
133
134
  {
134
135
  slug: 'contacts',
135
- path: '',
136
+ pathname: '',
136
137
  hash: '/hash'
137
138
  }
138
139
  ],
@@ -140,29 +141,38 @@ describe('deconstructRedirectLink', () => {
140
141
  'contacts/#/long/hash',
141
142
  {
142
143
  slug: 'contacts',
143
- path: '',
144
+ pathname: '',
144
145
  hash: '/long/hash'
145
146
  }
146
147
  ],
147
148
  [
148
- 'contacts/path/#/long/hash',
149
+ 'contacts/pathname/#/long/hash',
149
150
  {
150
151
  slug: 'contacts',
151
- path: 'path/',
152
+ pathname: 'pathname/',
152
153
  hash: '/long/hash'
153
154
  }
154
155
  ],
155
156
  [
156
- 'contacts/long/path/#/long/hash',
157
+ 'contacts/long/pathname/#/long/hash',
157
158
  {
158
159
  slug: 'contacts',
159
- path: 'long/path/',
160
+ pathname: 'long/pathname/',
160
161
  hash: '/long/hash'
161
162
  }
162
163
  ]
163
164
  ])('should deconstruct %p redirect link', (link, result) => {
164
165
  expect(deconstructRedirectLink(link)).toEqual(result)
165
166
  })
167
+
168
+ it.each([
169
+ ['camillenimbus-photos.mycozy.cloud'],
170
+ ['http://camillenimbus-photos.mycozy.cloud']
171
+ ])('should throw when redirect link is invalid', link => {
172
+ expect(() => deconstructRedirectLink(link)).toThrow(
173
+ InvalidRedirectLinkError
174
+ )
175
+ })
166
176
  })
167
177
 
168
178
  describe('rootCozyUrl', () => {
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ var _exportNames = {
32
32
  generateWebLink: true,
33
33
  ensureFirstSlash: true,
34
34
  rootCozyUrl: true,
35
+ InvalidRedirectLinkError: true,
35
36
  InvalidCozyUrlError: true,
36
37
  InvalidProtocolError: true,
37
38
  cancelable: true,
@@ -202,6 +203,12 @@ Object.defineProperty(exports, "rootCozyUrl", {
202
203
  return _helpers2.rootCozyUrl;
203
204
  }
204
205
  });
206
+ Object.defineProperty(exports, "InvalidRedirectLinkError", {
207
+ enumerable: true,
208
+ get: function get() {
209
+ return _helpers2.InvalidRedirectLinkError;
210
+ }
211
+ });
205
212
  Object.defineProperty(exports, "InvalidCozyUrlError", {
206
213
  enumerable: true,
207
214
  get: function get() {
package/dist/types.js CHANGED
@@ -501,7 +501,7 @@ var _dsl = require("./queries/dsl");
501
501
  *
502
502
  * @typedef {object} RedirectLinkData
503
503
  * @property {string} slug - The redirect link's slug (i.e. 'drive')
504
- * @property {string} path - The redirect link's path (i.e. 'public')
504
+ * @property {string} pathname - The redirect link's path (i.e. 'public')
505
505
  * @property {string} hash - The redirect link's path (i.e. '/folder/SOME_FOLDER_ID')
506
506
  */
507
507
  var _default = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "35.7.0",
3
+ "version": "36.0.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "@types/jest": "^26.0.20",
19
19
  "@types/lodash": "^4.14.170",
20
20
  "btoa": "^1.2.1",
21
- "cozy-stack-client": "^35.6.0",
21
+ "cozy-stack-client": "^36.0.0",
22
22
  "date-fns": "2.29.3",
23
23
  "json-stable-stringify": "^1.0.1",
24
24
  "lodash": "^4.17.13",
@@ -73,5 +73,5 @@
73
73
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
74
74
  },
75
75
  "sideEffects": false,
76
- "gitHead": "c8a78aaac3777dfe4763274c3e92218e5a222864"
76
+ "gitHead": "66475ed97922a875fc12439aee820568ae9d023c"
77
77
  }
@@ -1,2 +1,2 @@
1
1
  export { dehydrate } from "./dehydrateHelper";
2
- export { deconstructCozyWebLinkWithSlug, deconstructRedirectLink, generateWebLink, ensureFirstSlash, rootCozyUrl, InvalidCozyUrlError, InvalidProtocolError } from "./urlHelper";
2
+ export { deconstructCozyWebLinkWithSlug, deconstructRedirectLink, generateWebLink, ensureFirstSlash, rootCozyUrl, InvalidRedirectLinkError, InvalidCozyUrlError, InvalidProtocolError } from "./urlHelper";
@@ -9,6 +9,10 @@ export function generateWebLink({ cozyUrl, searchParams: searchParamsOption, pat
9
9
  }): string;
10
10
  export function deconstructCozyWebLinkWithSlug(webLink: string, subDomainType?: SubdomainType): CozyLinkData;
11
11
  export function deconstructRedirectLink(redirectLink: string): RedirectLinkData;
12
+ export class InvalidRedirectLinkError extends Error {
13
+ constructor(redirectLink: any);
14
+ redirectLink: any;
15
+ }
12
16
  export class InvalidProtocolError extends Error {
13
17
  constructor(url: any);
14
18
  url: any;
package/types/index.d.ts CHANGED
@@ -19,6 +19,6 @@ export { manifest, models };
19
19
  export { QueryDefinition, Q, Mutations, MutationTypes, getDoctypeFromOperation } from "./queries/dsl";
20
20
  export { Association, HasMany, HasOne, HasOneInPlace, HasManyInPlace, HasManyTriggers } from "./associations";
21
21
  export { isReferencedBy, isReferencedById, getReferencedBy, getReferencedById } from "./associations/helpers";
22
- export { deconstructCozyWebLinkWithSlug, deconstructRedirectLink, dehydrate, generateWebLink, ensureFirstSlash, rootCozyUrl, InvalidCozyUrlError, InvalidProtocolError } from "./helpers";
22
+ export { deconstructCozyWebLinkWithSlug, deconstructRedirectLink, dehydrate, generateWebLink, ensureFirstSlash, rootCozyUrl, InvalidRedirectLinkError, InvalidCozyUrlError, InvalidProtocolError } from "./helpers";
23
23
  export { cancelable, isQueryLoading, hasQueryBeenLoaded } from "./utils";
24
24
  export { queryConnect, queryConnectFlat, withClient } from "./hoc";
package/types/types.d.ts CHANGED
@@ -746,7 +746,7 @@ export type RedirectLinkData = {
746
746
  /**
747
747
  * - The redirect link's path (i.e. 'public')
748
748
  */
749
- path: string;
749
+ pathname: string;
750
750
  /**
751
751
  * - The redirect link's path (i.e. '/folder/SOME_FOLDER_ID')
752
752
  */