cozy-client 32.3.2 → 32.3.3

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.
@@ -189,35 +189,38 @@ var CozyClient = /*#__PURE__*/function () {
189
189
  var rawOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
190
190
  (0, _classCallCheck2.default)(this, CozyClient);
191
191
  (0, _defineProperty2.default)(this, "fetchQueryAndGetFromState", /*#__PURE__*/function () {
192
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(query) {
192
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
193
+ var definition, options;
193
194
  return _regenerator.default.wrap(function _callee$(_context) {
194
195
  while (1) {
195
196
  switch (_context.prev = _context.next) {
196
197
  case 0:
197
- _context.prev = 0;
198
- _context.next = 3;
199
- return _this.query(query.definition, query.options);
198
+ definition = _ref.definition, options = _ref.options;
199
+ _context.prev = 1;
200
+ _context.next = 4;
201
+ return _this.query(definition, options);
200
202
 
201
- case 3:
202
- return _context.abrupt("return", _this.getQueryFromState(query.options.as));
203
+ case 4:
204
+ return _context.abrupt("return", _this.getQueryFromState(options.as));
203
205
 
204
- case 6:
205
- _context.prev = 6;
206
- _context.t0 = _context["catch"](0);
206
+ case 7:
207
+ _context.prev = 7;
208
+ _context.t0 = _context["catch"](1);
207
209
  throw _context.t0;
208
210
 
209
- case 9:
211
+ case 10:
210
212
  case "end":
211
213
  return _context.stop();
212
214
  }
213
215
  }
214
- }, _callee, null, [[0, 6]]);
216
+ }, _callee, null, [[1, 7]]);
215
217
  }));
216
218
 
217
219
  return function (_x) {
218
- return _ref.apply(this, arguments);
220
+ return _ref2.apply(this, arguments);
219
221
  };
220
222
  }());
223
+
221
224
  var link = rawOptions.link,
222
225
  links = rawOptions.links,
223
226
  _rawOptions$schema = rawOptions.schema,
@@ -225,15 +228,15 @@ var CozyClient = /*#__PURE__*/function () {
225
228
  _rawOptions$appMetada = rawOptions.appMetadata,
226
229
  appMetadata = _rawOptions$appMetada === void 0 ? {} : _rawOptions$appMetada,
227
230
  capabilities = rawOptions.capabilities,
228
- options = (0, _objectWithoutProperties2.default)(rawOptions, ["link", "links", "schema", "appMetadata", "capabilities"]);
231
+ _options = (0, _objectWithoutProperties2.default)(rawOptions, ["link", "links", "schema", "appMetadata", "capabilities"]);
229
232
 
230
233
  if (link) {
231
234
  console.warn('`link` is deprecated, use `links`');
232
235
  }
233
236
 
234
237
  this.appMetadata = appMetadata;
235
- options.uri = securiseUri(options.uri);
236
- this.options = options;
238
+ _options.uri = securiseUri(_options.uri);
239
+ this.options = _options;
237
240
  this.queryIdGenerator = new _queries.QueryIDGenerator();
238
241
  this.isLogged = false;
239
242
  this.instanceOptions = {}; // Bind handlers
@@ -266,7 +269,7 @@ var CozyClient = /*#__PURE__*/function () {
266
269
  } catch (err) {// not a critical error, we may be in node or the instance options are not on the default HTML element
267
270
  }
268
271
 
269
- if (options.uri && options.token) {
272
+ if (_options.uri && _options.token) {
270
273
  this.login();
271
274
  }
272
275
  /**
@@ -276,7 +279,7 @@ var CozyClient = /*#__PURE__*/function () {
276
279
 
277
280
  this.storeAccesors = null;
278
281
 
279
- if (options.store !== false) {
282
+ if (_options.store !== false) {
280
283
  this.ensureStore();
281
284
  }
282
285
  /**
@@ -951,6 +954,13 @@ var CozyClient = /*#__PURE__*/function () {
951
954
 
952
955
  return saveAll;
953
956
  }()
957
+ /**
958
+ * @param {CozyClientDocument} document - Document that will be saved
959
+ * @param {object} [options={event: DOC_CREATION}] - Event
960
+ * @param {string} [options.event] - Mutation type
961
+ * @returns {CozyClientDocument}
962
+ */
963
+
954
964
  }, {
955
965
  key: "ensureCozyMetadata",
956
966
  value: function ensureCozyMetadata(document) {
@@ -1035,7 +1045,7 @@ var CozyClient = /*#__PURE__*/function () {
1035
1045
  * ```
1036
1046
  *
1037
1047
  *
1038
- * @param {object} document - Document to create
1048
+ * @param {CozyClientDocument} document - Document to create
1039
1049
  * @param {ReferenceMap} [referencesByName] - References to the created document. The
1040
1050
  * relationship class associated to each reference list should support references, otherwise this
1041
1051
  * method will throw.
@@ -1077,10 +1087,10 @@ var CozyClient = /*#__PURE__*/function () {
1077
1087
  return [saveMutation, function (response) {
1078
1088
  var doc = _this3.hydrateDocument(response.data);
1079
1089
 
1080
- return Object.entries(referencesByName).map(function (_ref2) {
1081
- var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
1082
- relName = _ref3[0],
1083
- references = _ref3[1];
1090
+ return Object.entries(referencesByName).map(function (_ref3) {
1091
+ var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
1092
+ relName = _ref4[0],
1093
+ references = _ref4[1];
1084
1094
 
1085
1095
  var relationship = doc[relName];
1086
1096
  return relationship.addReferences(references);
@@ -1217,7 +1227,7 @@ var CozyClient = /*#__PURE__*/function () {
1217
1227
  var _query = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(queryDefinition) {
1218
1228
  var _this4 = this;
1219
1229
 
1220
- var _ref4,
1230
+ var _ref5,
1221
1231
  update,
1222
1232
  options,
1223
1233
  queryId,
@@ -1230,8 +1240,8 @@ var CozyClient = /*#__PURE__*/function () {
1230
1240
  while (1) {
1231
1241
  switch (_context8.prev = _context8.next) {
1232
1242
  case 0:
1233
- _ref4 = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
1234
- update = _ref4.update, options = (0, _objectWithoutProperties2.default)(_ref4, ["update"]);
1243
+ _ref5 = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
1244
+ update = _ref5.update, options = (0, _objectWithoutProperties2.default)(_ref5, ["update"]);
1235
1245
  this.ensureStore();
1236
1246
  queryId = options.as || this.queryIdGenerator.generateId(queryDefinition);
1237
1247
  existingQuery = this.getQueryFromState(queryId);
@@ -1449,7 +1459,7 @@ var CozyClient = /*#__PURE__*/function () {
1449
1459
  key: "mutate",
1450
1460
  value: function () {
1451
1461
  var _mutate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(mutationDefinition) {
1452
- var _ref5,
1462
+ var _ref6,
1453
1463
  update,
1454
1464
  updateQueries,
1455
1465
  options,
@@ -1461,8 +1471,8 @@ var CozyClient = /*#__PURE__*/function () {
1461
1471
  while (1) {
1462
1472
  switch (_context10.prev = _context10.next) {
1463
1473
  case 0:
1464
- _ref5 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {};
1465
- update = _ref5.update, updateQueries = _ref5.updateQueries, options = (0, _objectWithoutProperties2.default)(_ref5, ["update", "updateQueries"]);
1474
+ _ref6 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {};
1475
+ update = _ref6.update, updateQueries = _ref6.updateQueries, options = (0, _objectWithoutProperties2.default)(_ref6, ["update", "updateQueries"]);
1466
1476
  this.ensureStore();
1467
1477
  mutationId = options.as || this.queryIdGenerator.generateId(mutationDefinition);
1468
1478
  this.dispatch((0, _store.initMutation)(mutationId, mutationDefinition));
@@ -1931,6 +1941,8 @@ var CozyClient = /*#__PURE__*/function () {
1931
1941
  * Has a behavior close to <Query /> or useQuery
1932
1942
  *
1933
1943
  * @param {object} query - Query with definition and options
1944
+ * @param {QueryDefinition} query.definition - Query Definition
1945
+ * @param {QueryOptions} query.options - Query Options
1934
1946
  * @returns {Promise<QueryState>} Query state
1935
1947
  */
1936
1948
 
@@ -2053,12 +2065,12 @@ var CozyClient = /*#__PURE__*/function () {
2053
2065
  key: "authorize",
2054
2066
  value: function () {
2055
2067
  var _authorize = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16() {
2056
- var _ref6,
2057
- _ref6$openURLCallback,
2068
+ var _ref7,
2069
+ _ref7$openURLCallback,
2058
2070
  openURLCallback,
2059
- _ref6$sessionCode,
2071
+ _ref7$sessionCode,
2060
2072
  sessionCode,
2061
- _ref6$pkceCodes,
2073
+ _ref7$pkceCodes,
2062
2074
  pkceCodes,
2063
2075
  codeVerifier,
2064
2076
  codeChallenge,
@@ -2075,7 +2087,7 @@ var CozyClient = /*#__PURE__*/function () {
2075
2087
  while (1) {
2076
2088
  switch (_context16.prev = _context16.next) {
2077
2089
  case 0:
2078
- _ref6 = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {}, _ref6$openURLCallback = _ref6.openURLCallback, openURLCallback = _ref6$openURLCallback === void 0 ? _mobile.authFunction : _ref6$openURLCallback, _ref6$sessionCode = _ref6.sessionCode, sessionCode = _ref6$sessionCode === void 0 ? undefined : _ref6$sessionCode, _ref6$pkceCodes = _ref6.pkceCodes, pkceCodes = _ref6$pkceCodes === void 0 ? {} : _ref6$pkceCodes;
2090
+ _ref7 = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {}, _ref7$openURLCallback = _ref7.openURLCallback, openURLCallback = _ref7$openURLCallback === void 0 ? _mobile.authFunction : _ref7$openURLCallback, _ref7$sessionCode = _ref7.sessionCode, sessionCode = _ref7$sessionCode === void 0 ? undefined : _ref7$sessionCode, _ref7$pkceCodes = _ref7.pkceCodes, pkceCodes = _ref7$pkceCodes === void 0 ? {} : _ref7$pkceCodes;
2079
2091
  _context16.prev = 1;
2080
2092
  codeVerifier = pkceCodes.codeVerifier, codeChallenge = pkceCodes.codeChallenge;
2081
2093
  stackClient = this.getStackClient();
@@ -2172,9 +2184,9 @@ var CozyClient = /*#__PURE__*/function () {
2172
2184
  }, {
2173
2185
  key: "setStore",
2174
2186
  value: function setStore(store) {
2175
- var _ref7 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2176
- _ref7$force = _ref7.force,
2177
- force = _ref7$force === void 0 ? false : _ref7$force;
2187
+ var _ref8 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2188
+ _ref8$force = _ref8.force,
2189
+ force = _ref8$force === void 0 ? false : _ref8$force;
2178
2190
 
2179
2191
  if (store === undefined) {
2180
2192
  throw new Error('Store is undefined');
@@ -2368,10 +2380,10 @@ var CozyClient = /*#__PURE__*/function () {
2368
2380
  var _this10 = this;
2369
2381
 
2370
2382
  this.ensureStore();
2371
- Object.entries(data).forEach(function (_ref8) {
2372
- var _ref9 = (0, _slicedToArray2.default)(_ref8, 2),
2373
- doctype = _ref9[0],
2374
- data = _ref9[1];
2383
+ Object.entries(data).forEach(function (_ref9) {
2384
+ var _ref10 = (0, _slicedToArray2.default)(_ref9, 2),
2385
+ doctype = _ref10[0],
2386
+ data = _ref10[1];
2375
2387
 
2376
2388
  _this10.dispatch((0, _store.receiveQueryResult)(null, {
2377
2389
  data: data
@@ -2553,7 +2565,7 @@ var CozyClient = /*#__PURE__*/function () {
2553
2565
  CozyClient.hooks = CozyClient.hooks || {};
2554
2566
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2555
2567
 
2556
- CozyClient.version = "32.3.2";
2568
+ CozyClient.version = "32.3.3";
2557
2569
 
2558
2570
  _microee.default.mixin(CozyClient);
2559
2571
 
@@ -17,6 +17,8 @@ var _logger = _interopRequireDefault(require("../logger"));
17
17
 
18
18
  var _storeAttestation = require("./store-attestation");
19
19
 
20
+ var _typedefs = require("./typedefs");
21
+
20
22
  /**
21
23
  * Request a challenge from the Stack that can be used to request the app attestation from the app store
22
24
  *
@@ -13,7 +13,9 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
13
13
 
14
14
  var _reactNativeGoogleSafetynet = _interopRequireDefault(require("react-native-google-safetynet"));
15
15
 
16
- //@ts-ignore
16
+ var _typedefs = require("./typedefs");
17
+
18
+ //@ts-ignore next-line
17
19
 
18
20
  /**
19
21
  * Retrieve the app's attestation from the Google Play store
@@ -13,7 +13,9 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
13
13
 
14
14
  var _reactNativeIos11Devicecheck = _interopRequireDefault(require("react-native-ios11-devicecheck"));
15
15
 
16
- //@ts-ignore
16
+ var _typedefs = require("./typedefs");
17
+
18
+ //@ts-ignore next-line
17
19
 
18
20
  /**
19
21
  * Retrieve the app's attestation from the Apple AppStore
@@ -11,6 +11,8 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
11
11
 
12
12
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
13
 
14
+ var _typedefs = require("./typedefs");
15
+
14
16
  /**
15
17
  * Retrieve the app's attestation from the app's store
16
18
  * /!\ This is a mock implementation that should never be called
@@ -1,3 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
1
8
  /**
2
9
  * @typedef {string} jws - A JSON Web Signature
3
10
  */
@@ -17,4 +24,5 @@
17
24
  * @typedef {object} CertificationConfig - Configuration to access the stores certification API
18
25
  * @property {string} androidSafetyNetApiKey
19
26
  */
20
- "use strict";
27
+ var _default = {};
28
+ exports.default = _default;
package/dist/types.js CHANGED
@@ -158,6 +158,7 @@ var _dsl = require("./queries/dsl");
158
158
  * @property {boolean} [_deleted] - When the document has been deleted
159
159
  * @property {ReferencedByRelationship} [relationships] - Relationships of the document
160
160
  * @property {Reference[]} [referenced_by] - referenced by of another document
161
+ * @property {object} [cozyMetadata] - Cozy Metadata
161
162
  */
162
163
 
163
164
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "32.3.2",
3
+ "version": "32.3.3",
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": "^32.3.2",
21
+ "cozy-stack-client": "^32.3.3",
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": "5517f3f84a4d9d3e129f7bb74ea7d44dd66fa1a0"
76
+ "gitHead": "e8d0916a43759433221c24dc62c48ca1627b5f96"
77
77
  }
@@ -343,9 +343,15 @@ declare class CozyClient {
343
343
  update?: Function;
344
344
  updateQueries?: Function;
345
345
  }): Promise<void>;
346
- ensureCozyMetadata(document: any, options?: {
347
- event: string;
348
- }): any;
346
+ /**
347
+ * @param {CozyClientDocument} document - Document that will be saved
348
+ * @param {object} [options={event: DOC_CREATION}] - Event
349
+ * @param {string} [options.event] - Mutation type
350
+ * @returns {CozyClientDocument}
351
+ */
352
+ ensureCozyMetadata(document: CozyClientDocument, options?: {
353
+ event?: string;
354
+ }): CozyClientDocument;
349
355
  /**
350
356
  * Dehydrates and adds metadata before saving a document
351
357
  *
@@ -367,14 +373,14 @@ declare class CozyClient {
367
373
  * ```
368
374
  *
369
375
  *
370
- * @param {object} document - Document to create
376
+ * @param {CozyClientDocument} document - Document to create
371
377
  * @param {ReferenceMap} [referencesByName] - References to the created document. The
372
378
  * relationship class associated to each reference list should support references, otherwise this
373
379
  * method will throw.
374
380
  *
375
381
  * @returns {Mutation[]|Mutation} One or more mutation to execute
376
382
  */
377
- getDocumentSavePlan(document: object, referencesByName?: ReferenceMap): Mutation[] | Mutation;
383
+ getDocumentSavePlan(document: CozyClientDocument, referencesByName?: ReferenceMap): Mutation[] | Mutation;
378
384
  triggerHook(name: any, document: any): void;
379
385
  /**
380
386
  * Destroys a document. {before,after}:destroy hooks will be fired.
@@ -549,9 +555,14 @@ declare class CozyClient {
549
555
  * Has a behavior close to <Query /> or useQuery
550
556
  *
551
557
  * @param {object} query - Query with definition and options
558
+ * @param {QueryDefinition} query.definition - Query Definition
559
+ * @param {QueryOptions} query.options - Query Options
552
560
  * @returns {Promise<QueryState>} Query state
553
561
  */
554
- fetchQueryAndGetFromState: (query: object) => Promise<QueryState>;
562
+ fetchQueryAndGetFromState: ({ definition, options }: {
563
+ definition: QueryDefinition;
564
+ options: QueryOptions;
565
+ }) => Promise<QueryState>;
555
566
  /**
556
567
  * Performs a complete OAuth flow using a Cordova webview
557
568
  * or React Native WebView for auth.
@@ -1,2 +1,3 @@
1
1
  export function certifyFlagship(certificationConfig: CertificationConfig, client: CozyClient): Promise<void>;
2
+ import { CertificationConfig } from "./typedefs";
2
3
  import CozyClient from "../CozyClient";
@@ -1 +1,3 @@
1
1
  export function getAppAttestationFromStore(nonce: string, certificationConfig: CertificationConfig): Promise<AttestationResult>;
2
+ import { CertificationConfig } from "./typedefs";
3
+ import { AttestationResult } from "./typedefs";
@@ -7,3 +7,5 @@
7
7
  * @returns {Promise<AttestationResult>} the app's attestation
8
8
  */
9
9
  export function getAppAttestationFromStore(nonce: string, certificationConfig: CertificationConfig): Promise<AttestationResult>;
10
+ import { CertificationConfig } from "./typedefs";
11
+ import { AttestationResult } from "./typedefs";
@@ -1 +1,3 @@
1
1
  export function getAppAttestationFromStore(nonce: string, certificationConfig: CertificationConfig): Promise<AttestationResult>;
2
+ import { CertificationConfig } from "./typedefs";
3
+ import { AttestationResult } from "./typedefs";
@@ -1,15 +1,17 @@
1
+ declare var _default: {};
2
+ export default _default;
1
3
  /**
2
4
  * - A JSON Web Signature
3
5
  */
4
- type jws = string;
6
+ export type jws = string;
5
7
  /**
6
8
  * - A JSON Web Signature
7
9
  */
8
- type base64string = string;
10
+ export type base64string = string;
9
11
  /**
10
12
  * - An app attestation from the app store
11
13
  */
12
- type AttestationResult = {
14
+ export type AttestationResult = {
13
15
  platform: string;
14
16
  attestation: jws | base64string;
15
17
  keyId?: string;
@@ -17,6 +19,6 @@ type AttestationResult = {
17
19
  /**
18
20
  * - Configuration to access the stores certification API
19
21
  */
20
- type CertificationConfig = {
22
+ export type CertificationConfig = {
21
23
  androidSafetyNetApiKey: string;
22
24
  };
package/types/types.d.ts CHANGED
@@ -164,6 +164,10 @@ export type CozyClientDocument = {
164
164
  * - referenced by of another document
165
165
  */
166
166
  referenced_by?: Reference[];
167
+ /**
168
+ * - Cozy Metadata
169
+ */
170
+ cozyMetadata?: object;
167
171
  };
168
172
  /**
169
173
  * - An io.cozy.files document