cozy-harvest-lib 9.22.3 → 9.23.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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [9.23.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.22.3...cozy-harvest-lib@9.23.0) (2022-07-26)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add BI aggregator releationship to BI accounts ([cb7a79c](https://github.com/cozy/cozy-libs/commit/cb7a79c6cd72a9f8e95ae71307f27f04b68f0e94))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [9.22.3](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.22.2...cozy-harvest-lib@9.22.3) (2022-07-26)
7
18
 
8
19
  **Note:** Version bump only for package cozy-harvest-lib
@@ -33,6 +33,7 @@ import { waitForRealtimeEvent } from './jobUtils';
33
33
  import '../types';
34
34
  import { LOGIN_SUCCESS_EVENT } from '../models/flowEvents';
35
35
  var TEMP_TOKEN_TIMOUT_S = 60;
36
+ export var ACCOUNTS_DOCTYPE = 'io.cozy.accounts';
36
37
  export var isBiWebViewConnector = function isBiWebViewConnector(konnector) {
37
38
  return flag('harvest.bi.webview') && isBudgetInsightConnector(konnector);
38
39
  };
@@ -201,7 +202,7 @@ export var handleOAuthAccount = /*#__PURE__*/function () {
201
202
  logger.info("Found a BI webview connection id: ".concat(connectionId));
202
203
  flow.konnector = konnector;
203
204
  _context3.next = 12;
204
- return flow.saveAccount(setBIConnectionId(biWebviewAccount, connectionId));
205
+ return flow.saveAccount(_objectSpread(_objectSpread({}, setBIConnectionId(biWebviewAccount, connectionId)), getBiAggregatorParentRelationship(konnector)));
205
206
 
206
207
  case 12:
207
208
  biWebviewAccount = _context3.sent;
@@ -228,6 +229,34 @@ export var handleOAuthAccount = /*#__PURE__*/function () {
228
229
  return _ref6.apply(this, arguments);
229
230
  };
230
231
  }();
232
+ /**
233
+ * Return the bi aggregator parent relationship configuration for a given konnector
234
+ *
235
+ * @param {io.cozy.konnectors} konnector connector manifest content
236
+ *
237
+ * @return {Object}
238
+ */
239
+
240
+ var getBiAggregatorParentRelationship = function getBiAggregatorParentRelationship(konnector) {
241
+ var _konnector$aggregator;
242
+
243
+ var biAggregatorId = konnector === null || konnector === void 0 ? void 0 : (_konnector$aggregator = konnector.aggregator) === null || _konnector$aggregator === void 0 ? void 0 : _konnector$aggregator.accountId;
244
+
245
+ if (!biAggregatorId) {
246
+ return {};
247
+ }
248
+
249
+ return {
250
+ relationships: {
251
+ parent: {
252
+ data: {
253
+ _id: biAggregatorId,
254
+ _type: ACCOUNTS_DOCTYPE
255
+ }
256
+ }
257
+ }
258
+ };
259
+ };
231
260
  /**
232
261
  * Gets BI webview connection id which is returned in the account by the stack
233
262
  * via oauth callback url
@@ -237,6 +266,7 @@ export var handleOAuthAccount = /*#__PURE__*/function () {
237
266
  * @return {Integer} Connection Id
238
267
  */
239
268
 
269
+
240
270
  var getWebviewBIConnectionId = function getWebviewBIConnectionId(account) {
241
271
  var _account$oauth, _account$oauth$query, _account$oauth$query$;
242
272
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-harvest-lib",
3
- "version": "9.22.3",
3
+ "version": "9.23.0",
4
4
  "description": "Provides logic, modules and components for Cozy's harvest applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -29,7 +29,7 @@
29
29
  "@cozy/minilog": "^1.0.0",
30
30
  "@sentry/browser": "^6.0.1",
31
31
  "cozy-bi-auth": "0.0.25",
32
- "cozy-doctypes": "^1.84.0",
32
+ "cozy-doctypes": "^1.85.0",
33
33
  "cozy-logger": "^1.9.0",
34
34
  "date-fns": "^1.30.1",
35
35
  "final-form": "^4.18.5",
@@ -90,5 +90,5 @@
90
90
  "react-router-dom": "^5.0.1"
91
91
  },
92
92
  "sideEffects": false,
93
- "gitHead": "6bfb68f221c204c40e54baab55cc25655e71a548"
93
+ "gitHead": "8d4f7daa10df35a9d4f019e2426731f79557aa80"
94
94
  }
@@ -23,6 +23,7 @@ import '../types'
23
23
  import { LOGIN_SUCCESS_EVENT } from '../models/flowEvents'
24
24
 
25
25
  const TEMP_TOKEN_TIMOUT_S = 60
26
+ export const ACCOUNTS_DOCTYPE = 'io.cozy.accounts'
26
27
 
27
28
  export const isBiWebViewConnector = konnector =>
28
29
  flag('harvest.bi.webview') && isBudgetInsightConnector(konnector)
@@ -130,9 +131,11 @@ export const handleOAuthAccount = async ({
130
131
  if (connectionId) {
131
132
  logger.info(`Found a BI webview connection id: ${connectionId}`)
132
133
  flow.konnector = konnector
133
- biWebviewAccount = await flow.saveAccount(
134
- setBIConnectionId(biWebviewAccount, connectionId)
135
- )
134
+
135
+ biWebviewAccount = await flow.saveAccount({
136
+ ...setBIConnectionId(biWebviewAccount, connectionId),
137
+ ...getBiAggregatorParentRelationship(konnector)
138
+ })
136
139
 
137
140
  await flow.handleFormSubmit({
138
141
  client,
@@ -145,6 +148,30 @@ export const handleOAuthAccount = async ({
145
148
  return connectionId
146
149
  }
147
150
 
151
+ /**
152
+ * Return the bi aggregator parent relationship configuration for a given konnector
153
+ *
154
+ * @param {io.cozy.konnectors} konnector connector manifest content
155
+ *
156
+ * @return {Object}
157
+ */
158
+ const getBiAggregatorParentRelationship = konnector => {
159
+ const biAggregatorId = konnector?.aggregator?.accountId
160
+ if (!biAggregatorId) {
161
+ return {}
162
+ }
163
+ return {
164
+ relationships: {
165
+ parent: {
166
+ data: {
167
+ _id: biAggregatorId,
168
+ _type: ACCOUNTS_DOCTYPE
169
+ }
170
+ }
171
+ }
172
+ }
173
+ }
174
+
148
175
  /**
149
176
  * Gets BI webview connection id which is returned in the account by the stack
150
177
  * via oauth callback url