@things-factory/integration-fulfillment 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/operato-logo.jpeg'
6
7
 
@@ -99,12 +100,70 @@ class FulfillmentCenterOperato extends PageView {
99
100
  static get properties() {
100
101
  return {
101
102
  id: String,
102
- fulfillmentCenter: Object,
103
103
  code: String,
104
104
  centerId: String
105
105
  }
106
106
  }
107
107
 
108
+ /* The center the address names (ADR-0190). */
109
+ read = new QueryController(
110
+ this,
111
+ gql`
112
+ query fulfillmentCenter($id: String!) {
113
+ fulfillmentCenter(id: $id) {
114
+ name
115
+ platform
116
+ centerId
117
+ countryCode
118
+ accessInfo
119
+ status
120
+ }
121
+ }
122
+ `,
123
+ { variables: () => (this.id ? { id: this.id } : undefined) }
124
+ )
125
+
126
+ get fulfillmentCenter() {
127
+ return this.read.data?.fulfillmentCenter
128
+ }
129
+
130
+ connecting = new MutationController(
131
+ this,
132
+ gql`
133
+ mutation generateOperatoAccessToken($id: String!, $code: String!) {
134
+ generateOperatoAccessToken(id: $id, code: $code) {
135
+ name
136
+ status
137
+ }
138
+ }
139
+ `,
140
+ { refetch: () => [this.read] }
141
+ )
142
+
143
+ deactivating = new MutationController(
144
+ this,
145
+ gql`
146
+ mutation deactivateOperatoCenter($name: String!) {
147
+ deactivateOperatoCenter(name: $name) {
148
+ status
149
+ }
150
+ }
151
+ `,
152
+ { refetch: () => [this.read] }
153
+ )
154
+
155
+ refreshing = new MutationController(
156
+ this,
157
+ gql`
158
+ mutation refreshOperatoAccessToken($id: String!) {
159
+ refreshOperatoAccessToken(id: $id) {
160
+ name
161
+ }
162
+ }
163
+ `,
164
+ { refetch: () => [this.read] }
165
+ )
166
+
108
167
  get context() {
109
168
  return {
110
169
  title: 'center operato'
@@ -163,26 +222,6 @@ class FulfillmentCenterOperato extends PageView {
163
222
  return
164
223
  }
165
224
 
166
- const response = await client.query({
167
- query: gql`
168
- query fulfillmentCenter($id: String!) {
169
- fulfillmentCenter(id: $id) {
170
- name
171
- platform
172
- centerId
173
- countryCode
174
- accessInfo
175
- status
176
- }
177
- }
178
- `,
179
- variables: {
180
- id: this.id
181
- }
182
- })
183
-
184
- this.fulfillmentCenter = response.data.fulfillmentCenter
185
-
186
225
  if (location.pathname.endsWith('connect-callback')) {
187
226
  let { code } = changes.params
188
227
  this.code = code
@@ -208,28 +247,9 @@ class FulfillmentCenterOperato extends PageView {
208
247
  }
209
248
 
210
249
  async handleConnectCallback() {
211
- const response = await client.mutate({
212
- mutation: gql`
213
- mutation generateOperatoAccessToken($id: String!, $code: String!) {
214
- generateOperatoAccessToken(id: $id, code: $code) {
215
- name
216
- platform
217
- centerId
218
- countryCode
219
- accessInfo
220
- status
221
- }
222
- }
223
- `,
224
- variables: {
225
- id: this.id,
226
- code: this.code
227
- }
228
- })
229
-
230
- this.fulfillmentCenter = response.data.generateOperatoAccessToken
231
- console.log('fulfillment center', this.fulfillmentCenter)
232
- var { status, name } = this.fulfillmentCenter
250
+ const connected = await this.connecting.run({ id: this.id, code: this.code })
251
+ if (!connected) return
252
+ const { status, name } = connected.generateOperatoAccessToken
233
253
 
234
254
  document.dispatchEvent(
235
255
  new CustomEvent('notify', {
@@ -246,28 +266,11 @@ class FulfillmentCenterOperato extends PageView {
246
266
  }
247
267
 
248
268
  async deactivate() {
249
- var { name } = this.fulfillmentCenter
250
-
251
- var response = await client.mutate({
252
- mutation: gql`
253
- mutation deactivateOperatoCenter($name: String!) {
254
- deactivateOperatoCenter(name: $name) {
255
- name
256
- platform
257
- centerId
258
- countryCode
259
- accessInfo
260
- status
261
- }
262
- }
263
- `,
264
- variables: {
265
- name
266
- }
267
- })
269
+ const { name } = this.fulfillmentCenter
268
270
 
269
- this.fulfillmentCenter = response.data.deactivateOperatoCenter
270
- var { status } = this.fulfillmentCenter
271
+ const deactivated = await this.deactivating.run({ name })
272
+ if (!deactivated) return
273
+ const { status } = deactivated.deactivateOperatoCenter
271
274
  this.code = ''
272
275
 
273
276
  document.dispatchEvent(
@@ -283,33 +286,14 @@ class FulfillmentCenterOperato extends PageView {
283
286
  async refreshToken() {
284
287
  const { name } = this.fulfillmentCenter
285
288
 
286
- var response = await client.mutate({
287
- mutation: gql`
288
- mutation refreshOperatoAccessToken($id: String!) {
289
- refreshOperatoAccessToken(id: $id) {
290
- name
291
- platform
292
- centerId
293
- countryCode
294
- accessInfo
295
- status
296
- }
297
- }
298
- `,
299
- variables: {
300
- id: this.id
301
- }
302
- })
303
-
304
- if (!response.errors) {
305
- this.fulfillmentCenter = response.data.refreshOperatoAccessToken
306
- }
289
+ /* A failure is reported by the client. */
290
+ if (!(await this.refreshing.run({ id: this.id }))) return
307
291
 
308
292
  document.dispatchEvent(
309
293
  new CustomEvent('notify', {
310
294
  detail: {
311
295
  level: 'info',
312
- message: `${response.errors ? 'fail' : 'success'} to refresh : ${name}`
296
+ message: `success to refresh : ${name}`
313
297
  }
314
298
  })
315
299
  )