cozy-client 28.2.3 → 29.0.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.
@@ -116,6 +116,18 @@ var referencesUnsupportedError = function referencesUnsupportedError(relationshi
116
116
  return new Error("The \"".concat(relationshipClassName, "\" relationship does not support references. If you need to add references to a document, its relationship class must have the methods {add,remove}References"));
117
117
  };
118
118
 
119
+ var securiseUri = function securiseUri(uri) {
120
+ var _window$cozy;
121
+
122
+ if (uri && window && (_window$cozy = window['cozy']) !== null && _window$cozy !== void 0 && _window$cozy.isSecureProtocol) {
123
+ var secureUrl = new URL(uri);
124
+ secureUrl.protocol = 'https:';
125
+ return secureUrl.toString();
126
+ }
127
+
128
+ return uri;
129
+ };
130
+
119
131
  var DOC_CREATION = 'creation';
120
132
  var DOC_UPDATE = 'update';
121
133
  /**
@@ -220,6 +232,7 @@ var CozyClient = /*#__PURE__*/function () {
220
232
  }
221
233
 
222
234
  this.appMetadata = appMetadata;
235
+ options.uri = securiseUri(options.uri);
223
236
  this.options = options;
224
237
  this.queryIdGenerator = new _queries.QueryIDGenerator();
225
238
  this.isLogged = false;
@@ -2537,7 +2550,7 @@ var CozyClient = /*#__PURE__*/function () {
2537
2550
  CozyClient.hooks = CozyClient.hooks || {};
2538
2551
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2539
2552
 
2540
- CozyClient.version = "28.2.3";
2553
+ CozyClient.version = "29.0.1";
2541
2554
 
2542
2555
  _microee.default.mixin(CozyClient);
2543
2556
 
@@ -72,6 +72,8 @@ describe('CozyClient initialization', () => {
72
72
  })
73
73
 
74
74
  client = new CozyClient({ links, schema: SCHEMA })
75
+
76
+ delete window.cozy
75
77
  })
76
78
 
77
79
  it('should autologin when provided token and uri', () => {
@@ -250,6 +252,47 @@ describe('CozyClient initialization', () => {
250
252
  document.querySelector = globalQuerySelectorBefore
251
253
  })
252
254
 
255
+ it('should secure the URL if window.cozy.isSecureProtocol is true', () => {
256
+ window.cozy = {
257
+ isSecureProtocol: true
258
+ }
259
+
260
+ const client = new CozyClient({
261
+ uri: 'http://cozy.tools',
262
+ schema: '',
263
+ token: 'SOME_TOKEN'
264
+ })
265
+
266
+ expect(client.options.uri).toBe('https://cozy.tools/')
267
+ })
268
+
269
+ it('should NOT secure the URL if window.cozy.isSecureProtocol is false', () => {
270
+ window.cozy = {
271
+ isSecureProtocol: false
272
+ }
273
+
274
+ const client = new CozyClient({
275
+ uri: 'http://cozy.tools',
276
+ schema: '',
277
+ token: 'SOME_TOKEN'
278
+ })
279
+
280
+ expect(client.options.uri).toBe('http://cozy.tools')
281
+ })
282
+
283
+ it('should not secure the URL if window is undefined (node env)', () => {
284
+ let windowSpy = jest.spyOn(window, 'window', 'get')
285
+ windowSpy.mockImplementation(() => undefined)
286
+ const client = new CozyClient({
287
+ uri: 'http://cozy.tools',
288
+ schema: '',
289
+ token: 'SOME_TOKEN'
290
+ })
291
+
292
+ expect(client.options.uri).toBe('http://cozy.tools')
293
+ windowSpy.mockRestore()
294
+ })
295
+
253
296
  describe('capabilities', () => {
254
297
  it('should instanciate Client with capabilities', () => {
255
298
  const options = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "28.2.3",
3
+ "version": "29.0.1",
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": "^28.2.1",
21
+ "cozy-stack-client": "^29.0.0",
22
22
  "json-stable-stringify": "^1.0.1",
23
23
  "lodash": "^4.17.13",
24
24
  "microee": "^0.0.6",
@@ -47,7 +47,7 @@
47
47
  "@testing-library/react-hooks": "3.7.0",
48
48
  "babel-plugin-search-and-replace": "1.1.0",
49
49
  "btoa": "1.2.1",
50
- "cozy-device-helper": "1.12.0",
50
+ "cozy-device-helper": "2.1.0",
51
51
  "cozy-flags": "2.8.6",
52
52
  "cozy-logger": "1.7.0",
53
53
  "cozy-ui": "48.0.0",
@@ -62,7 +62,7 @@
62
62
  "typescript": "4.1.5"
63
63
  },
64
64
  "peerDependencies": {
65
- "cozy-device-helper": ">1.12.0",
65
+ "cozy-device-helper": ">=2.1.0",
66
66
  "cozy-flags": ">2.8.6",
67
67
  "cozy-logger": ">1.7.0",
68
68
  "cozy-ui": ">34.0.0",
@@ -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": "cab01cb8509a7c88a01a7766e43064f025bf6cc8"
76
+ "gitHead": "2f377563187a5bf3b89d8c3044c72615452bfc01"
77
77
  }