cozy-client 38.7.1 → 38.8.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.
- package/dist/CozyClient.js +1 -1
- package/dist/models/bitwarden.js +63 -0
- package/dist/models/capability.js +35 -0
- package/dist/models/instance.js +58 -2
- package/dist/models/user.js +58 -0
- package/dist/models/user.spec.js +61 -0
- package/dist/queries/dsl.js +1 -3
- package/dist/store/queries.js +1 -3
- package/package.json +2 -2
- package/types/models/bitwarden.d.ts +1 -0
- package/types/models/capability.d.ts +2 -0
- package/types/models/instance.d.ts +1 -0
- package/types/models/user.d.ts +1 -0
package/dist/CozyClient.js
CHANGED
|
@@ -2677,7 +2677,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2677
2677
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2678
2678
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2679
2679
|
|
|
2680
|
-
CozyClient.version = "38.
|
|
2680
|
+
CozyClient.version = "38.8.1";
|
|
2681
2681
|
|
|
2682
2682
|
_microee.default.mixin(CozyClient);
|
|
2683
2683
|
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.hasExtensionInstalledAttribute = void 0;
|
|
9
|
+
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
+
|
|
14
|
+
var _dsl = require("../queries/dsl");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Checks the value of the extension_installed attribute
|
|
18
|
+
*
|
|
19
|
+
* @param {import("../CozyClient").default} client - The CozyClient instance
|
|
20
|
+
* @returns {Promise<boolean>} - Returns the value of the extension_installed attribute
|
|
21
|
+
*/
|
|
22
|
+
var hasExtensionInstalledAttribute = /*#__PURE__*/function () {
|
|
23
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client) {
|
|
24
|
+
var _yield$client$fetchQu, extension_installed;
|
|
25
|
+
|
|
26
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
27
|
+
while (1) {
|
|
28
|
+
switch (_context.prev = _context.next) {
|
|
29
|
+
case 0:
|
|
30
|
+
_context.prev = 0;
|
|
31
|
+
_context.next = 3;
|
|
32
|
+
return client.fetchQueryAndGetFromState({
|
|
33
|
+
definition: (0, _dsl.Q)('io.cozy.settings').getById('io.cozy.settings.bitwarden'),
|
|
34
|
+
options: {
|
|
35
|
+
as: 'io.cozy.settings/io.cozy.settings.bitwarden',
|
|
36
|
+
singleDocData: true
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
case 3:
|
|
41
|
+
_yield$client$fetchQu = _context.sent;
|
|
42
|
+
extension_installed = _yield$client$fetchQu.data.extension_installed;
|
|
43
|
+
return _context.abrupt("return", Boolean(extension_installed));
|
|
44
|
+
|
|
45
|
+
case 8:
|
|
46
|
+
_context.prev = 8;
|
|
47
|
+
_context.t0 = _context["catch"](0);
|
|
48
|
+
return _context.abrupt("return", false);
|
|
49
|
+
|
|
50
|
+
case 11:
|
|
51
|
+
case "end":
|
|
52
|
+
return _context.stop();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, _callee, null, [[0, 8]]);
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
return function hasExtensionInstalledAttribute(_x) {
|
|
59
|
+
return _ref.apply(this, arguments);
|
|
60
|
+
};
|
|
61
|
+
}();
|
|
62
|
+
|
|
63
|
+
exports.hasExtensionInstalledAttribute = hasExtensionInstalledAttribute;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isMagicLink = exports.isOIDC = void 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Checks if the instance can auth with OIDC
|
|
10
|
+
*
|
|
11
|
+
* @param {import("../CozyClient").default} client - The CozyClient instance
|
|
12
|
+
* @returns {boolean} - Returns true if the instance can auth with OIDC
|
|
13
|
+
*/
|
|
14
|
+
var isOIDC = function isOIDC(client) {
|
|
15
|
+
var _client$capabilities$;
|
|
16
|
+
|
|
17
|
+
return (_client$capabilities$ = client.capabilities.can_auth_with_oidc) !== null && _client$capabilities$ !== void 0 ? _client$capabilities$ : false;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Checks if the instance can auth with magic link
|
|
21
|
+
*
|
|
22
|
+
* @param {import("../CozyClient").default} client - The CozyClient instance
|
|
23
|
+
* @returns {boolean} - Returns true if the instance can auth with magic link
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
exports.isOIDC = isOIDC;
|
|
28
|
+
|
|
29
|
+
var isMagicLink = function isMagicLink(client) {
|
|
30
|
+
var _client$capabilities$2;
|
|
31
|
+
|
|
32
|
+
return (_client$capabilities$2 = client.capabilities.can_auth_with_magic_links) !== null && _client$capabilities$2 !== void 0 ? _client$capabilities$2 : false;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.isMagicLink = isMagicLink;
|
package/dist/models/instance.js
CHANGED
|
@@ -5,10 +5,16 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.buildPremiumLink = exports.hasAnOffer = exports.shouldDisplayOffers = exports.getUuid = exports.isFreemiumUser = exports.arePremiumLinksEnabled = exports.isSelfHosted = void 0;
|
|
8
|
+
exports.hasPasswordDefinedAttribute = exports.buildPremiumLink = exports.hasAnOffer = exports.shouldDisplayOffers = exports.getUuid = exports.isFreemiumUser = exports.arePremiumLinksEnabled = exports.isSelfHosted = void 0;
|
|
9
|
+
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
9
13
|
|
|
10
14
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
11
15
|
|
|
16
|
+
var _dsl = require("../queries/dsl");
|
|
17
|
+
|
|
12
18
|
var GB = 1000 * 1000 * 1000;
|
|
13
19
|
var PREMIUM_QUOTA = 50 * GB;
|
|
14
20
|
/**
|
|
@@ -92,5 +98,55 @@ var buildPremiumLink = function buildPremiumLink(instanceInfo) {
|
|
|
92
98
|
return null;
|
|
93
99
|
}
|
|
94
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* Checks the value of the password_defined attribute
|
|
103
|
+
*
|
|
104
|
+
* @param {import("../CozyClient").default} client - The CozyClient instance
|
|
105
|
+
* @returns {Promise<boolean>} - Returns the value of the password_defined attribute
|
|
106
|
+
*/
|
|
107
|
+
|
|
95
108
|
|
|
96
|
-
exports.buildPremiumLink = buildPremiumLink;
|
|
109
|
+
exports.buildPremiumLink = buildPremiumLink;
|
|
110
|
+
|
|
111
|
+
var hasPasswordDefinedAttribute = /*#__PURE__*/function () {
|
|
112
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client) {
|
|
113
|
+
var _yield$client$fetchQu, password_defined;
|
|
114
|
+
|
|
115
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
116
|
+
while (1) {
|
|
117
|
+
switch (_context.prev = _context.next) {
|
|
118
|
+
case 0:
|
|
119
|
+
_context.prev = 0;
|
|
120
|
+
_context.next = 3;
|
|
121
|
+
return client.fetchQueryAndGetFromState({
|
|
122
|
+
definition: (0, _dsl.Q)('io.cozy.settings').getById('io.cozy.settings.instance'),
|
|
123
|
+
options: {
|
|
124
|
+
as: 'io.cozy.settings/io.cozy.settings.instance',
|
|
125
|
+
singleDocData: true
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
case 3:
|
|
130
|
+
_yield$client$fetchQu = _context.sent;
|
|
131
|
+
password_defined = _yield$client$fetchQu.data.attributes.password_defined;
|
|
132
|
+
return _context.abrupt("return", password_defined);
|
|
133
|
+
|
|
134
|
+
case 8:
|
|
135
|
+
_context.prev = 8;
|
|
136
|
+
_context.t0 = _context["catch"](0);
|
|
137
|
+
return _context.abrupt("return", false);
|
|
138
|
+
|
|
139
|
+
case 11:
|
|
140
|
+
case "end":
|
|
141
|
+
return _context.stop();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, _callee, null, [[0, 8]]);
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
return function hasPasswordDefinedAttribute(_x) {
|
|
148
|
+
return _ref.apply(this, arguments);
|
|
149
|
+
};
|
|
150
|
+
}();
|
|
151
|
+
|
|
152
|
+
exports.hasPasswordDefinedAttribute = hasPasswordDefinedAttribute;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.hasPassword = void 0;
|
|
9
|
+
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
+
|
|
14
|
+
var _instance = require("./instance");
|
|
15
|
+
|
|
16
|
+
var _bitwarden = require("./bitwarden");
|
|
17
|
+
|
|
18
|
+
var _capability = require("./capability");
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Checks whether the user has a password
|
|
22
|
+
*
|
|
23
|
+
* @param {import("../CozyClient").default} client - The CozyClient instance
|
|
24
|
+
* @returns {Promise<boolean>} - Returns true if the user has a password
|
|
25
|
+
*/
|
|
26
|
+
var hasPassword = /*#__PURE__*/function () {
|
|
27
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client) {
|
|
28
|
+
var hasExtensionInstalled, hasPasswordDefined;
|
|
29
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
30
|
+
while (1) {
|
|
31
|
+
switch (_context.prev = _context.next) {
|
|
32
|
+
case 0:
|
|
33
|
+
_context.next = 2;
|
|
34
|
+
return (0, _bitwarden.hasExtensionInstalledAttribute)(client);
|
|
35
|
+
|
|
36
|
+
case 2:
|
|
37
|
+
hasExtensionInstalled = _context.sent;
|
|
38
|
+
_context.next = 5;
|
|
39
|
+
return (0, _instance.hasPasswordDefinedAttribute)(client);
|
|
40
|
+
|
|
41
|
+
case 5:
|
|
42
|
+
hasPasswordDefined = _context.sent;
|
|
43
|
+
return _context.abrupt("return", !((0, _capability.isMagicLink)(client) || (0, _capability.isOIDC)(client)) || hasExtensionInstalled || hasPasswordDefined);
|
|
44
|
+
|
|
45
|
+
case 7:
|
|
46
|
+
case "end":
|
|
47
|
+
return _context.stop();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, _callee);
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
return function hasPassword(_x) {
|
|
54
|
+
return _ref.apply(this, arguments);
|
|
55
|
+
};
|
|
56
|
+
}();
|
|
57
|
+
|
|
58
|
+
exports.hasPassword = hasPassword;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { hasPasswordDefinedAttribute } from './instance'
|
|
2
|
+
import { hasExtensionInstalledAttribute } from './bitwarden'
|
|
3
|
+
import { hasPassword } from './user'
|
|
4
|
+
|
|
5
|
+
jest.mock('./instance', () => ({
|
|
6
|
+
hasPasswordDefinedAttribute: jest.fn(() => false)
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
jest.mock('./bitwarden', () => ({
|
|
10
|
+
hasExtensionInstalledAttribute: jest.fn(() => false)
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
const setup = ({
|
|
14
|
+
isOIDC = false,
|
|
15
|
+
isMagicLink = false,
|
|
16
|
+
passwordDefined = false,
|
|
17
|
+
extensionInstalled = false
|
|
18
|
+
} = {}) => {
|
|
19
|
+
hasPasswordDefinedAttribute.mockReturnValue(passwordDefined)
|
|
20
|
+
hasExtensionInstalledAttribute.mockReturnValue(extensionInstalled)
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
client: {
|
|
24
|
+
capabilities: {
|
|
25
|
+
can_auth_with_oidc: isOIDC,
|
|
26
|
+
can_auth_with_magic_links: isMagicLink
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('hasPassword', () => {
|
|
33
|
+
it('return true by default', async () => {
|
|
34
|
+
const { client } = setup()
|
|
35
|
+
expect(await hasPassword(client)).toBe(true)
|
|
36
|
+
})
|
|
37
|
+
it('return true when password defined', async () => {
|
|
38
|
+
const { client } = setup({ passwordDefined: true })
|
|
39
|
+
expect(await hasPassword(client)).toBe(true)
|
|
40
|
+
})
|
|
41
|
+
it('return true when extension installed', async () => {
|
|
42
|
+
const { client } = setup({ extensionInstalled: true })
|
|
43
|
+
expect(await hasPassword(client)).toBe(true)
|
|
44
|
+
})
|
|
45
|
+
it('return false when magic link without password', async () => {
|
|
46
|
+
const { client } = setup({ isMagicLink: true })
|
|
47
|
+
expect(await hasPassword(client)).toBe(false)
|
|
48
|
+
})
|
|
49
|
+
it('return true when magic link with password', async () => {
|
|
50
|
+
const { client } = setup({ isMagicLink: true, passwordDefined: true })
|
|
51
|
+
expect(await hasPassword(client)).toBe(true)
|
|
52
|
+
})
|
|
53
|
+
it('return false when OIDC without password', async () => {
|
|
54
|
+
const { client } = setup({ isOIDC: true })
|
|
55
|
+
expect(await hasPassword(client)).toBe(false)
|
|
56
|
+
})
|
|
57
|
+
it('return true when OIDC with password', async () => {
|
|
58
|
+
const { client } = setup({ isOIDC: true, passwordDefined: true })
|
|
59
|
+
expect(await hasPassword(client)).toBe(true)
|
|
60
|
+
})
|
|
61
|
+
})
|
package/dist/queries/dsl.js
CHANGED
|
@@ -13,8 +13,6 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
13
13
|
|
|
14
14
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
15
|
|
|
16
|
-
var _isArray = _interopRequireDefault(require("lodash/isArray"));
|
|
17
|
-
|
|
18
16
|
var _findKey = _interopRequireDefault(require("lodash/findKey"));
|
|
19
17
|
|
|
20
18
|
var _logger = _interopRequireDefault(require("../logger"));
|
|
@@ -313,7 +311,7 @@ var QueryDefinition = /*#__PURE__*/function () {
|
|
|
313
311
|
}, {
|
|
314
312
|
key: "sortBy",
|
|
315
313
|
value: function sortBy(sort) {
|
|
316
|
-
if (!
|
|
314
|
+
if (!Array.isArray(sort)) {
|
|
317
315
|
throw new Error("Invalid sort, should be an array ([{ label: \"desc\"}, { name: \"asc\"}]), you passed ".concat(JSON.stringify(sort), "."));
|
|
318
316
|
}
|
|
319
317
|
|
package/dist/store/queries.js
CHANGED
|
@@ -33,8 +33,6 @@ var _uniq = _interopRequireDefault(require("lodash/uniq"));
|
|
|
33
33
|
|
|
34
34
|
var _orderBy = _interopRequireDefault(require("lodash/orderBy"));
|
|
35
35
|
|
|
36
|
-
var _isArray = _interopRequireDefault(require("lodash/isArray"));
|
|
37
|
-
|
|
38
36
|
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
39
37
|
|
|
40
38
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
@@ -389,7 +387,7 @@ var makeSorterFromDefinition = function makeSorterFromDefinition(definition) {
|
|
|
389
387
|
return function (docs) {
|
|
390
388
|
return docs;
|
|
391
389
|
};
|
|
392
|
-
} else if (!
|
|
390
|
+
} else if (!Array.isArray(definition.sort)) {
|
|
393
391
|
_logger.default.warn('Correct update of queries with a sort that is not an array is not supported. Use an array as argument of QueryDefinition::sort');
|
|
394
392
|
|
|
395
393
|
return function (docs) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "38.
|
|
3
|
+
"version": "38.8.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -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": "a3d435b06a5326ed24dcdc9f2d2dc24efb8b9466"
|
|
77
77
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function hasExtensionInstalledAttribute(client: import("../CozyClient").default): Promise<boolean>;
|
|
@@ -5,6 +5,7 @@ export function getUuid(instanceInfo: any): any;
|
|
|
5
5
|
export function shouldDisplayOffers(data: SettingsInfo): boolean;
|
|
6
6
|
export function hasAnOffer(data: SettingsInfo): boolean;
|
|
7
7
|
export function buildPremiumLink(instanceInfo: InstanceInfo): string;
|
|
8
|
+
export function hasPasswordDefinedAttribute(client: import("../CozyClient").default): Promise<boolean>;
|
|
8
9
|
export type InstanceInfo = any;
|
|
9
10
|
export type ContextInfo = any;
|
|
10
11
|
export type DiskUsageInfo = any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function hasPassword(client: import("../CozyClient").default): Promise<boolean>;
|