@things-factory/integration-accounting 10.1.256 → 10.1.257

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.
@@ -1,6 +1,7 @@
1
1
  import gql from 'graphql-tag'
2
2
  import { css, html } from 'lit'
3
3
  import { client, PageView, store } from '@things-factory/shell'
4
+ import { MutationController, QueryController } from '@operato/graphql'
4
5
 
5
6
  import LOGO from '../../assets/images/xero-logo.png'
6
7
 
@@ -121,11 +122,65 @@ class AccountXero extends PageView {
121
122
  static get properties() {
122
123
  return {
123
124
  id: String,
124
- account: Object,
125
125
  code: String,
126
- accountId: String,
127
- accessInfo: Object,
128
- connectionInfo: Object
126
+ accountId: String
127
+ }
128
+ }
129
+
130
+ /* The account the address names (ADR-0190). */
131
+ read = new QueryController(
132
+ this,
133
+ gql`
134
+ query account($id: String!) {
135
+ account(id: $id) ${ACCOUNT_RESULT}
136
+ }
137
+ `,
138
+ { variables: () => (this.id ? { id: this.id } : undefined) }
139
+ )
140
+
141
+ get account() {
142
+ return this.read.data?.account
143
+ }
144
+
145
+ deactivating = new MutationController(
146
+ this,
147
+ gql`
148
+ mutation deactivateXeroAccount($id: String!) {
149
+ deactivateXeroAccount(id: $id) {
150
+ status
151
+ }
152
+ }
153
+ `,
154
+ { refetch: () => [this.read] }
155
+ )
156
+
157
+ refreshing = new MutationController(
158
+ this,
159
+ gql`
160
+ mutation refreshXeroAccessToken($id: String!) {
161
+ refreshXeroAccessToken(id: $id) {
162
+ id
163
+ }
164
+ }
165
+ `,
166
+ { refetch: () => [this.read] }
167
+ )
168
+
169
+ get accessInfo() {
170
+ return this.parsed('accessInfo')
171
+ }
172
+
173
+ get connectionInfo() {
174
+ return this.parsed('accountInfo')
175
+ }
176
+
177
+ parsed(field) {
178
+ if (this.account?.status != 'active') return {}
179
+ try {
180
+ return JSON.parse(this.account[field])
181
+ } catch (e) {
182
+ console.error(e)
183
+ return {}
129
184
  }
130
185
  }
131
186
 
@@ -185,44 +240,10 @@ class AccountXero extends PageView {
185
240
  `
186
241
  }
187
242
 
188
- updated(changed) {
189
- if (changed.has('account')) {
190
- var active = this.account && this.account.status == 'active'
191
-
192
- try {
193
- this.accessInfo = active ? JSON.parse(this.account.accessInfo) : {}
194
- } catch (e) {
195
- console.error(e)
196
- this.accessInfo = {}
197
- }
198
-
199
- try {
200
- this.connectionInfo = active ? JSON.parse(this.account.accountInfo) : {}
201
- } catch (e) {
202
- console.error(e)
203
- this.connectionInfo = {}
204
- }
205
- }
206
- }
207
-
208
243
  async pageUpdated(changes, after, before) {
209
- /* refresh always page revisited */
210
244
  if (this.lifecycle.resourceId) {
211
245
  this.id = this.lifecycle.resourceId
212
246
 
213
- const response = await client.query({
214
- query: gql`
215
- query account($id: String!) {
216
- account(id: $id) ${ACCOUNT_RESULT}
217
- }
218
- `,
219
- variables: {
220
- id: this.id
221
- }
222
- })
223
-
224
- this.account = response.data.account
225
-
226
247
  if (location.pathname.endsWith('connect-callback')) {
227
248
  let { status, message } = changes.params
228
249
 
@@ -264,19 +285,9 @@ class AccountXero extends PageView {
264
285
  async deactivate() {
265
286
  const { id, name } = this.account
266
287
 
267
- var response = await client.mutate({
268
- mutation: gql`
269
- mutation deactivateXeroAccount($id: String!) {
270
- deactivateXeroAccount(id: $id) ${ACCOUNT_RESULT}
271
- }
272
- `,
273
- variables: {
274
- id
275
- }
276
- })
277
-
278
- this.account = response.data.deactivateXeroAccount
279
- var { status } = this.account
288
+ const deactivated = await this.deactivating.run({ id })
289
+ if (!deactivated) return
290
+ const { status } = deactivated.deactivateXeroAccount
280
291
 
281
292
  document.dispatchEvent(
282
293
  new CustomEvent('notify', {
@@ -291,26 +302,14 @@ class AccountXero extends PageView {
291
302
  async refreshToken() {
292
303
  const { id, name } = this.account
293
304
 
294
- var response = await client.mutate({
295
- mutation: gql`
296
- mutation refreshXeroAccessToken($id: String!) {
297
- refreshXeroAccessToken(id: $id) ${ACCOUNT_RESULT}
298
- }
299
- `,
300
- variables: {
301
- id
302
- }
303
- })
304
-
305
- if (!response.errors) {
306
- this.account = response.data.refreshXeroAccessToken
307
- }
305
+ /* A failure is reported by the client. */
306
+ if (!(await this.refreshing.run({ id }))) return
308
307
 
309
308
  document.dispatchEvent(
310
309
  new CustomEvent('notify', {
311
310
  detail: {
312
311
  level: 'info',
313
- message: `${response.errors ? 'fail' : 'success'} to refresh : ${name}`
312
+ message: `success to refresh : ${name}`
314
313
  }
315
314
  })
316
315
  )
@@ -94,8 +94,8 @@ class CreateAccountPopup extends localize(i18next)(LitElement) {
94
94
 
95
95
  async _createAccount() {
96
96
  try {
97
- const response = await client.query({
98
- query: gql`
97
+ const response = await client.mutate({
98
+ mutation: gql`
99
99
  mutation {
100
100
  createAccount(${gqlBuilder.buildArgs({
101
101
  account: this._getAccountInfo()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-accounting",
3
- "version": "10.1.256",
3
+ "version": "10.1.257",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.ts",
6
6
  "things-factory": true,
@@ -25,18 +25,19 @@
25
25
  "test": "DEBUG=things-factory:* NODE_ENV=development npx mocha -r ts-node/register ./test/**/*spec.ts"
26
26
  },
27
27
  "dependencies": {
28
- "@operato/data-grist": "^10.0.0",
29
- "@things-factory/apptool-ui": "^10.1.256",
30
- "@things-factory/auth-ui": "^10.1.256",
31
- "@things-factory/biz-base": "^10.1.256",
32
- "@things-factory/code-ui": "^10.1.256",
28
+ "@operato/data-grist": "^10.29.69",
29
+ "@operato/graphql": "^10.29.69",
30
+ "@things-factory/apptool-ui": "^10.1.257",
31
+ "@things-factory/auth-ui": "^10.1.257",
32
+ "@things-factory/biz-base": "^10.1.257",
33
+ "@things-factory/code-ui": "^10.1.257",
33
34
  "@things-factory/context-ui": "^10.1.254",
34
- "@things-factory/i18n-base": "^10.1.256",
35
- "@things-factory/integration-ui": "^10.1.256",
35
+ "@things-factory/i18n-base": "^10.1.257",
36
+ "@things-factory/integration-ui": "^10.1.257",
36
37
  "@things-factory/more-ui": "^10.1.254",
37
- "@things-factory/product-base": "^10.1.256",
38
- "@things-factory/resource-ui": "^10.1.256",
39
- "@things-factory/setting-ui": "^10.1.256",
38
+ "@things-factory/product-base": "^10.1.257",
39
+ "@things-factory/resource-ui": "^10.1.257",
40
+ "@things-factory/setting-ui": "^10.1.257",
40
41
  "debug": "^4.1.1",
41
42
  "node-fetch": "^2.6.0"
42
43
  },
@@ -50,5 +51,5 @@
50
51
  "nock": "^13.0.2",
51
52
  "should": "^13.2.3"
52
53
  },
53
- "gitHead": "2fd641697190ce6e87bcf454a60b2321553e8110"
54
+ "gitHead": "885b594299601ca4936f4f39701d6713273bbf1e"
54
55
  }