@things-factory/integration-accounting 10.1.255 → 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
|
-
|
|
128
|
-
|
|
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
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
295
|
-
|
|
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:
|
|
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.
|
|
98
|
-
|
|
97
|
+
const response = await client.mutate({
|
|
98
|
+
mutation: gql`
|
|
99
99
|
mutation {
|
|
100
100
|
createAccount(${gqlBuilder.buildArgs({
|
|
101
101
|
account: this._getAccountInfo()
|