cozy-client 32.8.1 → 33.0.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/dist/CozyClient.js +69 -14
- package/dist/CozyClient.spec.js +12 -0
- package/dist/hooks/useCapabilities.js +9 -2
- package/dist/hooks/useCapabilities.spec.jsx +20 -7
- package/dist/models/file.js +2 -0
- package/dist/types.js +17 -1
- package/package.json +3 -3
- package/types/CozyClient.d.ts +8 -0
- package/types/types.d.ts +22 -1
package/dist/CozyClient.js
CHANGED
|
@@ -266,9 +266,11 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
266
266
|
|
|
267
267
|
this.plugins = {};
|
|
268
268
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
269
|
+
if (!(this.stackClient instanceof _cozyStackClient.OAuthClient)) {
|
|
270
|
+
try {
|
|
271
|
+
this.loadInstanceOptionsFromDOM();
|
|
272
|
+
} catch (err) {// not a critical error, we may be in node or the instance options are not on the default HTML element
|
|
273
|
+
}
|
|
272
274
|
}
|
|
273
275
|
|
|
274
276
|
if (_options.uri && _options.token) {
|
|
@@ -513,9 +515,19 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
513
515
|
case 21:
|
|
514
516
|
this.isLogged = true;
|
|
515
517
|
this.isRevoked = false;
|
|
518
|
+
|
|
519
|
+
if (!(this.stackClient instanceof _cozyStackClient.OAuthClient)) {
|
|
520
|
+
_context2.next = 26;
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
_context2.next = 26;
|
|
525
|
+
return this.loadInstanceOptionsFromStack();
|
|
526
|
+
|
|
527
|
+
case 26:
|
|
516
528
|
this.emit('login');
|
|
517
529
|
|
|
518
|
-
case
|
|
530
|
+
case 27:
|
|
519
531
|
case "end":
|
|
520
532
|
return _context2.stop();
|
|
521
533
|
}
|
|
@@ -2382,6 +2394,49 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2382
2394
|
this.instanceOptions = _objectSpread(_objectSpread({}, JSON.parse(cozy)), dataset);
|
|
2383
2395
|
this.capabilities = this.instanceOptions.capabilities || null;
|
|
2384
2396
|
}
|
|
2397
|
+
/**
|
|
2398
|
+
* loadInstanceOptionsFromStack - Loads the instance options from cozy-stack and exposes it through getInstanceOptions
|
|
2399
|
+
*
|
|
2400
|
+
* For now only retrieving capabilities is supported
|
|
2401
|
+
*
|
|
2402
|
+
* @returns {Promise<void>}
|
|
2403
|
+
*/
|
|
2404
|
+
|
|
2405
|
+
}, {
|
|
2406
|
+
key: "loadInstanceOptionsFromStack",
|
|
2407
|
+
value: function () {
|
|
2408
|
+
var _loadInstanceOptionsFromStack = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee18() {
|
|
2409
|
+
var _yield$this$query, data;
|
|
2410
|
+
|
|
2411
|
+
return _regenerator.default.wrap(function _callee18$(_context18) {
|
|
2412
|
+
while (1) {
|
|
2413
|
+
switch (_context18.prev = _context18.next) {
|
|
2414
|
+
case 0:
|
|
2415
|
+
_context18.next = 2;
|
|
2416
|
+
return this.query((0, _dsl.Q)('io.cozy.settings').getById('capabilities'));
|
|
2417
|
+
|
|
2418
|
+
case 2:
|
|
2419
|
+
_yield$this$query = _context18.sent;
|
|
2420
|
+
data = _yield$this$query.data;
|
|
2421
|
+
this.instanceOptions = {
|
|
2422
|
+
capabilities: data.attributes
|
|
2423
|
+
};
|
|
2424
|
+
this.capabilities = this.instanceOptions.capabilities || null;
|
|
2425
|
+
|
|
2426
|
+
case 6:
|
|
2427
|
+
case "end":
|
|
2428
|
+
return _context18.stop();
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
}, _callee18, this);
|
|
2432
|
+
}));
|
|
2433
|
+
|
|
2434
|
+
function loadInstanceOptionsFromStack() {
|
|
2435
|
+
return _loadInstanceOptionsFromStack.apply(this, arguments);
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2438
|
+
return loadInstanceOptionsFromStack;
|
|
2439
|
+
}()
|
|
2385
2440
|
/**
|
|
2386
2441
|
* Directly set the data in the store, without using a query
|
|
2387
2442
|
* This is useful for cases like Pouch replication, which wants to
|
|
@@ -2451,28 +2506,28 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2451
2506
|
}, {
|
|
2452
2507
|
key: "fromOldOAuthClient",
|
|
2453
2508
|
value: function () {
|
|
2454
|
-
var _fromOldOAuthClient = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2509
|
+
var _fromOldOAuthClient = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee19(oldClient, options) {
|
|
2455
2510
|
var credentials, oauthOptions;
|
|
2456
|
-
return _regenerator.default.wrap(function
|
|
2511
|
+
return _regenerator.default.wrap(function _callee19$(_context19) {
|
|
2457
2512
|
while (1) {
|
|
2458
|
-
switch (
|
|
2513
|
+
switch (_context19.prev = _context19.next) {
|
|
2459
2514
|
case 0:
|
|
2460
2515
|
if (!oldClient._oauth) {
|
|
2461
|
-
|
|
2516
|
+
_context19.next = 8;
|
|
2462
2517
|
break;
|
|
2463
2518
|
}
|
|
2464
2519
|
|
|
2465
|
-
|
|
2520
|
+
_context19.next = 3;
|
|
2466
2521
|
return oldClient.authorize();
|
|
2467
2522
|
|
|
2468
2523
|
case 3:
|
|
2469
|
-
credentials =
|
|
2524
|
+
credentials = _context19.sent;
|
|
2470
2525
|
oauthOptions = {
|
|
2471
2526
|
oauth: credentials.client,
|
|
2472
2527
|
token: credentials.token,
|
|
2473
2528
|
scope: credentials.token.scope
|
|
2474
2529
|
};
|
|
2475
|
-
return
|
|
2530
|
+
return _context19.abrupt("return", new CozyClient(_objectSpread(_objectSpread({
|
|
2476
2531
|
uri: oldClient._url
|
|
2477
2532
|
}, oauthOptions), options)));
|
|
2478
2533
|
|
|
@@ -2481,10 +2536,10 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2481
2536
|
|
|
2482
2537
|
case 9:
|
|
2483
2538
|
case "end":
|
|
2484
|
-
return
|
|
2539
|
+
return _context19.stop();
|
|
2485
2540
|
}
|
|
2486
2541
|
}
|
|
2487
|
-
},
|
|
2542
|
+
}, _callee19);
|
|
2488
2543
|
}));
|
|
2489
2544
|
|
|
2490
2545
|
function fromOldOAuthClient(_x17, _x18) {
|
|
@@ -2581,7 +2636,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2581
2636
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2582
2637
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2583
2638
|
|
|
2584
|
-
CozyClient.version = "
|
|
2639
|
+
CozyClient.version = "33.0.2";
|
|
2585
2640
|
|
|
2586
2641
|
_microee.default.mixin(CozyClient);
|
|
2587
2642
|
|
package/dist/CozyClient.spec.js
CHANGED
|
@@ -493,6 +493,9 @@ describe('CozyClient logout', () => {
|
|
|
493
493
|
})
|
|
494
494
|
|
|
495
495
|
it('should call reset on each link that can be reset', async () => {
|
|
496
|
+
client.query = jest.fn().mockResolvedValueOnce({
|
|
497
|
+
data: { attributes: { file_versioning: true, flat_subdomains: true } }
|
|
498
|
+
})
|
|
496
499
|
links[0].reset = jest.fn()
|
|
497
500
|
links[2].reset = jest.fn()
|
|
498
501
|
await client.login()
|
|
@@ -510,6 +513,9 @@ describe('CozyClient logout', () => {
|
|
|
510
513
|
})
|
|
511
514
|
|
|
512
515
|
it('should call all reset even if a reset throws an error', async () => {
|
|
516
|
+
client.query = jest.fn().mockResolvedValueOnce({
|
|
517
|
+
data: { attributes: { file_versioning: true, flat_subdomains: true } }
|
|
518
|
+
})
|
|
513
519
|
links[0].reset = jest.fn().mockRejectedValue(new Error('Async error'))
|
|
514
520
|
links[2].reset = jest.fn()
|
|
515
521
|
await client.login()
|
|
@@ -519,6 +525,9 @@ describe('CozyClient logout', () => {
|
|
|
519
525
|
})
|
|
520
526
|
|
|
521
527
|
it('should emit events', async () => {
|
|
528
|
+
client.query = jest.fn().mockResolvedValueOnce({
|
|
529
|
+
data: { attributes: { file_versioning: true, flat_subdomains: true } }
|
|
530
|
+
})
|
|
522
531
|
const originalLogout = client.logout
|
|
523
532
|
links[0].reset = jest.fn()
|
|
524
533
|
links[2].reset = jest.fn()
|
|
@@ -537,6 +546,9 @@ describe('CozyClient logout', () => {
|
|
|
537
546
|
})
|
|
538
547
|
|
|
539
548
|
it('should unregister an oauth client', async () => {
|
|
549
|
+
client.query = jest.fn().mockResolvedValueOnce({
|
|
550
|
+
data: { attributes: { file_versioning: true, flat_subdomains: true } }
|
|
551
|
+
})
|
|
540
552
|
await client.login()
|
|
541
553
|
stackClient.isRegistered.mockReturnValue(true)
|
|
542
554
|
|
|
@@ -15,6 +15,8 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
15
15
|
|
|
16
16
|
var _react = require("react");
|
|
17
17
|
|
|
18
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
19
|
+
|
|
18
20
|
var _dsl = require("../queries/dsl");
|
|
19
21
|
|
|
20
22
|
var useCapabilities = function useCapabilities(client) {
|
|
@@ -43,7 +45,7 @@ var useCapabilities = function useCapabilities(client) {
|
|
|
43
45
|
|
|
44
46
|
case 4:
|
|
45
47
|
capabilitiesResult = _context.sent;
|
|
46
|
-
setCapabilities(capabilitiesResult);
|
|
48
|
+
setCapabilities((0, _get.default)(capabilitiesResult, 'data.attributes', {}));
|
|
47
49
|
setFetchStatus('loaded');
|
|
48
50
|
_context.next = 12;
|
|
49
51
|
break;
|
|
@@ -66,7 +68,12 @@ var useCapabilities = function useCapabilities(client) {
|
|
|
66
68
|
};
|
|
67
69
|
}();
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
if (client.capabilities) {
|
|
72
|
+
setCapabilities(client.capabilities);
|
|
73
|
+
setFetchStatus('loaded');
|
|
74
|
+
} else {
|
|
75
|
+
fetchData();
|
|
76
|
+
}
|
|
70
77
|
}, [client]);
|
|
71
78
|
return {
|
|
72
79
|
capabilities: capabilities,
|
|
@@ -3,6 +3,10 @@ import useCapabilities from './useCapabilities'
|
|
|
3
3
|
describe('useCapabilities', () => {
|
|
4
4
|
const mockClient = { query: jest.fn(), get: jest.fn() }
|
|
5
5
|
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
jest.clearAllMocks()
|
|
8
|
+
})
|
|
9
|
+
|
|
6
10
|
it('should change loading status', async () => {
|
|
7
11
|
mockClient.query.mockResolvedValue({ data: [] })
|
|
8
12
|
const { result, waitForNextUpdate } = renderHook(() =>
|
|
@@ -40,13 +44,22 @@ describe('useCapabilities', () => {
|
|
|
40
44
|
|
|
41
45
|
await waitForNextUpdate()
|
|
42
46
|
expect(result.current.capabilities).toEqual({
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
file_versioning: true,
|
|
48
|
+
flat_subdomains: true
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it(`should return client's capabilities if defined`, async () => {
|
|
53
|
+
mockClient.capabilities = {
|
|
54
|
+
file_versioning: false,
|
|
55
|
+
flat_subdomains: false
|
|
56
|
+
}
|
|
57
|
+
const { result } = renderHook(() => useCapabilities(mockClient))
|
|
58
|
+
|
|
59
|
+
expect(result.current.capabilities).toEqual({
|
|
60
|
+
file_versioning: false,
|
|
61
|
+
flat_subdomains: false
|
|
50
62
|
})
|
|
63
|
+
expect(mockClient.query).not.toHaveBeenCalled()
|
|
51
64
|
})
|
|
52
65
|
})
|
package/dist/models/file.js
CHANGED
package/dist/types.js
CHANGED
|
@@ -163,12 +163,28 @@ var _dsl = require("./queries/dsl");
|
|
|
163
163
|
* @property {object} [cozyMetadata] - Cozy Metadata
|
|
164
164
|
*/
|
|
165
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Metadata on io.cozy.files documents
|
|
168
|
+
*
|
|
169
|
+
* This is a first step, to continue
|
|
170
|
+
*
|
|
171
|
+
* Filled according to:
|
|
172
|
+
* https://docs.cozy.io/en/cozy-doctypes/docs/io.cozy.files_metadata/
|
|
173
|
+
* https://docs.cozy.io/en/cozy-doctypes/docs/io.cozy.notes/
|
|
174
|
+
*
|
|
175
|
+
* @typedef {object} FileMetadata - A io.cozy.files document's metadata
|
|
176
|
+
* @property {object} [content] - The Note's content. See https://prosemirror.net/docs/ref/#model for more informations
|
|
177
|
+
* @property {object} [schema] - the schema used by prosemirror (with notes and marks serialized as arrays to preserve the order).
|
|
178
|
+
* @property {string} [title] - the initial title of the note (that will also be used for the file name)
|
|
179
|
+
* @property {number} [version] - Number of a note
|
|
180
|
+
*/
|
|
181
|
+
|
|
166
182
|
/**
|
|
167
183
|
* @typedef {object} FileDocument - An io.cozy.files document
|
|
168
184
|
* @property {string} _id - Id of the file
|
|
169
185
|
* @property {FilesDoctype} _type - Doctype of the file
|
|
170
186
|
* @property {string} name - Name of the file
|
|
171
|
-
* @property {
|
|
187
|
+
* @property {FileMetadata} metadata - Metadata of the file
|
|
172
188
|
* @property {string} type - Type of the file
|
|
173
189
|
* @property {string} class - Class of the file
|
|
174
190
|
* @property {string} mime - Mime of the file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "33.0.2",
|
|
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": "^
|
|
21
|
+
"cozy-stack-client": "^33.0.0",
|
|
22
22
|
"json-stable-stringify": "^1.0.1",
|
|
23
23
|
"lodash": "^4.17.13",
|
|
24
24
|
"microee": "^0.0.6",
|
|
@@ -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": "
|
|
76
|
+
"gitHead": "c00ba115384a2ba0f562adb4fa5e141ea64dbe45"
|
|
77
77
|
}
|
package/types/CozyClient.d.ts
CHANGED
|
@@ -684,6 +684,14 @@ declare class CozyClient {
|
|
|
684
684
|
* @returns {void}
|
|
685
685
|
*/
|
|
686
686
|
loadInstanceOptionsFromDOM(selector?: string): void;
|
|
687
|
+
/**
|
|
688
|
+
* loadInstanceOptionsFromStack - Loads the instance options from cozy-stack and exposes it through getInstanceOptions
|
|
689
|
+
*
|
|
690
|
+
* For now only retrieving capabilities is supported
|
|
691
|
+
*
|
|
692
|
+
* @returns {Promise<void>}
|
|
693
|
+
*/
|
|
694
|
+
loadInstanceOptionsFromStack(): Promise<void>;
|
|
687
695
|
/**
|
|
688
696
|
* Directly set the data in the store, without using a query
|
|
689
697
|
* This is useful for cases like Pouch replication, which wants to
|
package/types/types.d.ts
CHANGED
|
@@ -174,6 +174,27 @@ export type CozyClientDocument = {
|
|
|
174
174
|
*/
|
|
175
175
|
cozyMetadata?: object;
|
|
176
176
|
};
|
|
177
|
+
/**
|
|
178
|
+
* - A io.cozy.files document's metadata
|
|
179
|
+
*/
|
|
180
|
+
export type FileMetadata = {
|
|
181
|
+
/**
|
|
182
|
+
* - The Note's content. See https://prosemirror.net/docs/ref/#model for more informations
|
|
183
|
+
*/
|
|
184
|
+
content?: object;
|
|
185
|
+
/**
|
|
186
|
+
* - the schema used by prosemirror (with notes and marks serialized as arrays to preserve the order).
|
|
187
|
+
*/
|
|
188
|
+
schema?: object;
|
|
189
|
+
/**
|
|
190
|
+
* - the initial title of the note (that will also be used for the file name)
|
|
191
|
+
*/
|
|
192
|
+
title?: string;
|
|
193
|
+
/**
|
|
194
|
+
* - Number of a note
|
|
195
|
+
*/
|
|
196
|
+
version?: number;
|
|
197
|
+
};
|
|
177
198
|
/**
|
|
178
199
|
* - An io.cozy.files document
|
|
179
200
|
*/
|
|
@@ -193,7 +214,7 @@ export type FileDocument = {
|
|
|
193
214
|
/**
|
|
194
215
|
* - Metadata of the file
|
|
195
216
|
*/
|
|
196
|
-
metadata:
|
|
217
|
+
metadata: FileMetadata;
|
|
197
218
|
/**
|
|
198
219
|
* - Type of the file
|
|
199
220
|
*/
|