cozy-client 35.4.0 → 35.5.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.
- package/dist/CozyClient.js +1 -1
- package/dist/context.js +1 -1
- package/dist/hooks/useClient.js +1 -1
- package/dist/models/account.js +47 -2
- package/dist/models/account.spec.js +18 -1
- package/package.json +2 -2
- package/types/context.d.ts +2 -2
- package/types/hooks/useClient.d.ts +2 -2
- package/types/models/account.d.ts +1 -0
package/dist/CozyClient.js
CHANGED
|
@@ -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.
|
|
2672
|
+
CozyClient.version = "35.5.0";
|
|
2673
2673
|
|
|
2674
2674
|
_microee.default.mixin(CozyClient);
|
|
2675
2675
|
|
package/dist/context.js
CHANGED
|
@@ -12,7 +12,7 @@ var _react = require("react");
|
|
|
12
12
|
var _CozyClient = _interopRequireDefault(require("./CozyClient"));
|
|
13
13
|
|
|
14
14
|
var clientContext = /*#__PURE__*/(0, _react.createContext)({
|
|
15
|
-
/** @type {CozyClient} */
|
|
15
|
+
/** @type {CozyClient|null} */
|
|
16
16
|
client: null,
|
|
17
17
|
store: null
|
|
18
18
|
});
|
package/dist/hooks/useClient.js
CHANGED
|
@@ -16,7 +16,7 @@ var _CozyClient = _interopRequireDefault(require("../CozyClient"));
|
|
|
16
16
|
/**
|
|
17
17
|
* Returns the cozy client from the context
|
|
18
18
|
*
|
|
19
|
-
* @returns {CozyClient} - Current cozy client
|
|
19
|
+
* @returns {CozyClient|null} - Current cozy client
|
|
20
20
|
*/
|
|
21
21
|
var useClient = function useClient() {
|
|
22
22
|
var _useContext = (0, _react.useContext)(_context.default),
|
package/dist/models/account.js
CHANGED
|
@@ -5,12 +5,18 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.buildAccount = exports.getAccountName = exports.getAccountLogin = exports.setContractSyncStatusInAccount = exports.getContractSyncStatusFromAccount = exports.muteError = exports.getMutedErrors = void 0;
|
|
8
|
+
exports.isAccountWithTrigger = exports.buildAccount = exports.getAccountName = exports.getAccountLogin = exports.setContractSyncStatusInAccount = exports.getContractSyncStatusFromAccount = exports.muteError = exports.getMutedErrors = 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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
15
|
|
|
12
16
|
var _merge = _interopRequireDefault(require("lodash/merge"));
|
|
13
17
|
|
|
18
|
+
var _dsl = require("../queries/dsl");
|
|
19
|
+
|
|
14
20
|
var _HasMany = require("../associations/HasMany");
|
|
15
21
|
|
|
16
22
|
var _manifest = require("./manifest");
|
|
@@ -171,5 +177,44 @@ var buildAccount = function buildAccount(konnector, authData) {
|
|
|
171
177
|
state: null
|
|
172
178
|
};
|
|
173
179
|
};
|
|
180
|
+
/**
|
|
181
|
+
* Look if the given account has an associated trigger or not.
|
|
182
|
+
*
|
|
183
|
+
* @param {import('../CozyClient').default} client - CozyClient instance
|
|
184
|
+
* @param {import('../types').IOCozyAccount} account - account document
|
|
185
|
+
* @returns {Promise<Boolean>}
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
exports.buildAccount = buildAccount;
|
|
190
|
+
|
|
191
|
+
var isAccountWithTrigger = /*#__PURE__*/function () {
|
|
192
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, account) {
|
|
193
|
+
var result;
|
|
194
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
195
|
+
while (1) {
|
|
196
|
+
switch (_context.prev = _context.next) {
|
|
197
|
+
case 0:
|
|
198
|
+
_context.next = 2;
|
|
199
|
+
return client.query((0, _dsl.Q)('io.cozy.triggers').where({
|
|
200
|
+
'message.account': account._id
|
|
201
|
+
}).indexFields(['message.account']).limitBy(1));
|
|
202
|
+
|
|
203
|
+
case 2:
|
|
204
|
+
result = _context.sent;
|
|
205
|
+
return _context.abrupt("return", result.data.length > 0);
|
|
206
|
+
|
|
207
|
+
case 4:
|
|
208
|
+
case "end":
|
|
209
|
+
return _context.stop();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}, _callee);
|
|
213
|
+
}));
|
|
214
|
+
|
|
215
|
+
return function isAccountWithTrigger(_x, _x2) {
|
|
216
|
+
return _ref.apply(this, arguments);
|
|
217
|
+
};
|
|
218
|
+
}();
|
|
174
219
|
|
|
175
|
-
exports.
|
|
220
|
+
exports.isAccountWithTrigger = isAccountWithTrigger;
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
muteError,
|
|
7
7
|
getAccountLogin,
|
|
8
8
|
getAccountName,
|
|
9
|
-
buildAccount
|
|
9
|
+
buildAccount,
|
|
10
|
+
isAccountWithTrigger
|
|
10
11
|
} from './account'
|
|
11
12
|
|
|
12
13
|
const fixtures = {
|
|
@@ -257,4 +258,20 @@ describe('account model', () => {
|
|
|
257
258
|
})
|
|
258
259
|
})
|
|
259
260
|
})
|
|
261
|
+
describe('isAccountWithTrigger', () => {
|
|
262
|
+
it('should return true if an account is connected or not', async () => {
|
|
263
|
+
const client = {
|
|
264
|
+
query: jest.fn()
|
|
265
|
+
}
|
|
266
|
+
client.query.mockResolvedValueOnce({ data: [{ _id: 'testaccountid' }] })
|
|
267
|
+
expect(
|
|
268
|
+
await isAccountWithTrigger(client, { _id: 'testaccountid' })
|
|
269
|
+
).toStrictEqual(true)
|
|
270
|
+
|
|
271
|
+
client.query.mockResolvedValueOnce({ data: [] })
|
|
272
|
+
expect(
|
|
273
|
+
await isAccountWithTrigger(client, { _id: 'testaccountid' })
|
|
274
|
+
).toStrictEqual(false)
|
|
275
|
+
})
|
|
276
|
+
})
|
|
260
277
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "35.
|
|
3
|
+
"version": "35.5.0",
|
|
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": "e97498920aeb449ef4a095ecbc3af3c2a7c30297"
|
|
77
77
|
}
|
package/types/context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export default useClient;
|
|
|
2
2
|
/**
|
|
3
3
|
* Returns the cozy client from the context
|
|
4
4
|
*
|
|
5
|
-
* @returns {CozyClient} - Current cozy client
|
|
5
|
+
* @returns {CozyClient|null} - Current cozy client
|
|
6
6
|
*/
|
|
7
|
-
declare function useClient(): CozyClient;
|
|
7
|
+
declare function useClient(): CozyClient | null;
|
|
8
8
|
import CozyClient from "../CozyClient";
|
|
@@ -5,3 +5,4 @@ export function setContractSyncStatusInAccount(account: import('../types').IOCoz
|
|
|
5
5
|
export function getAccountLogin(account: import('../types').IOCozyAccount): string | null;
|
|
6
6
|
export function getAccountName(account: import('../types').IOCozyAccount): string | null;
|
|
7
7
|
export function buildAccount(konnector: import('../types').IOCozyKonnector, authData: object): import('../types').IOCozyAccount;
|
|
8
|
+
export function isAccountWithTrigger(client: import('../CozyClient').default, account: import('../types').IOCozyAccount): Promise<boolean>;
|