@things-factory/integration-fulfillment 4.0.23 → 4.0.27
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/client/pages/fulfillment-center-operato.js +46 -7
- package/dist-server/controllers/operato/operato.js +33 -1
- package/dist-server/controllers/operato/operato.js.map +1 -1
- package/dist-server/controllers/operato/platform-action.js +17 -6
- package/dist-server/controllers/operato/platform-action.js.map +1 -1
- package/dist-server/graphql/resolvers/fulfillment-center/operato/index.js +3 -2
- package/dist-server/graphql/resolvers/fulfillment-center/operato/index.js.map +1 -1
- package/dist-server/graphql/resolvers/fulfillment-center/operato/refresh-operato-access-token.js +48 -0
- package/dist-server/graphql/resolvers/fulfillment-center/operato/refresh-operato-access-token.js.map +1 -0
- package/dist-server/graphql/types/fulfillment-center/index.js +6 -2
- package/dist-server/graphql/types/fulfillment-center/index.js.map +1 -1
- package/package.json +13 -13
- package/server/controllers/operato/operato.ts +49 -1
- package/server/controllers/operato/platform-action.ts +14 -6
- package/server/graphql/resolvers/fulfillment-center/operato/index.ts +4 -3
- package/server/graphql/resolvers/fulfillment-center/operato/refresh-operato-access-token.ts +62 -0
- package/server/graphql/types/fulfillment-center/index.ts +6 -2
- package/translations/en.json +1 -1
- package/translations/ms.json +1 -1
- package/translations/zh.json +1 -1
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { html, css } from 'lit-element'
|
|
2
1
|
import gql from 'graphql-tag'
|
|
2
|
+
import { css, html } from 'lit-element'
|
|
3
3
|
import { connect } from 'pwa-helpers/connect-mixin.js'
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
import { client, PageView, store } from '@things-factory/shell'
|
|
6
|
+
|
|
5
7
|
import LOGO from '../../assets/images/operato-logo.jpeg'
|
|
8
|
+
|
|
6
9
|
class FulfillmentCenterOperato extends connect(store)(PageView) {
|
|
7
10
|
static get styles() {
|
|
8
11
|
return css`
|
|
@@ -140,11 +143,12 @@ class FulfillmentCenterOperato extends connect(store)(PageView) {
|
|
|
140
143
|
<div>
|
|
141
144
|
${status == 'active'
|
|
142
145
|
? html`<mwc-button
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
@click=${e => this.deactivate(name)}
|
|
147
|
+
raised
|
|
148
|
+
danger
|
|
149
|
+
label="disconnect this center"
|
|
150
|
+
></mwc-button>
|
|
151
|
+
<mwc-button @click=${e => this.refreshToken()} raised label="refresh token"></mwc-button>`
|
|
148
152
|
: html`<mwc-button @click=${e => this.activate(name)} raised label="connect this center"></mwc-button>`}
|
|
149
153
|
</div>
|
|
150
154
|
`
|
|
@@ -277,6 +281,41 @@ class FulfillmentCenterOperato extends connect(store)(PageView) {
|
|
|
277
281
|
})
|
|
278
282
|
)
|
|
279
283
|
}
|
|
284
|
+
|
|
285
|
+
async refreshToken() {
|
|
286
|
+
const { name } = this.fulfillmentCenter
|
|
287
|
+
|
|
288
|
+
var response = await client.mutate({
|
|
289
|
+
mutation: gql`
|
|
290
|
+
mutation refreshOperatoAccessToken($id: String!) {
|
|
291
|
+
refreshOperatoAccessToken(id: $id) {
|
|
292
|
+
name
|
|
293
|
+
platform
|
|
294
|
+
centerId
|
|
295
|
+
countryCode
|
|
296
|
+
accessInfo
|
|
297
|
+
status
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
`,
|
|
301
|
+
variables: {
|
|
302
|
+
id: this.id
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
if (!response.errors) {
|
|
307
|
+
this.fulfillmentCenter = response.data.refreshOperatoAccessToken
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
document.dispatchEvent(
|
|
311
|
+
new CustomEvent('notify', {
|
|
312
|
+
detail: {
|
|
313
|
+
level: 'info',
|
|
314
|
+
message: `${response.errors ? 'fail' : 'success'} to refresh : ${name}`
|
|
315
|
+
}
|
|
316
|
+
})
|
|
317
|
+
)
|
|
318
|
+
}
|
|
280
319
|
}
|
|
281
320
|
|
|
282
321
|
customElements.define('fulfillment-center-operato', FulfillmentCenterOperato)
|
|
@@ -7,6 +7,9 @@ exports.Operato = void 0;
|
|
|
7
7
|
const debug_1 = __importDefault(require("debug"));
|
|
8
8
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
9
9
|
const env_1 = require("@things-factory/env");
|
|
10
|
+
const utils_1 = require("@things-factory/utils");
|
|
11
|
+
const typeorm_1 = require("typeorm");
|
|
12
|
+
const entities_1 = require("../../entities");
|
|
10
13
|
const { protocol = 'https', host, callback } = env_1.config.get('fulfillmentIntegrationOperato', {});
|
|
11
14
|
const debug = (0, debug_1.default)('things-factory:integration-fulfillment:operato');
|
|
12
15
|
class Operato {
|
|
@@ -55,9 +58,38 @@ class Operato {
|
|
|
55
58
|
else {
|
|
56
59
|
const text = await response.text();
|
|
57
60
|
debug('response result', text);
|
|
58
|
-
throw
|
|
61
|
+
throw response;
|
|
59
62
|
}
|
|
60
63
|
}
|
|
64
|
+
static async refreshAccessToken(fulfillmentCenter) {
|
|
65
|
+
const requestBody = {
|
|
66
|
+
refreshToken: fulfillmentCenter.refreshToken
|
|
67
|
+
};
|
|
68
|
+
const refreshResponse = await (0, node_fetch_1.default)(`${protocol}://${host}/oauth/refresh-token`, {
|
|
69
|
+
method: 'post',
|
|
70
|
+
headers: {
|
|
71
|
+
'Content-Type': 'application/json'
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify(requestBody)
|
|
74
|
+
});
|
|
75
|
+
if (!refreshResponse.ok) {
|
|
76
|
+
throw new Error(`get operato information failed: ${await refreshResponse.text()}`);
|
|
77
|
+
}
|
|
78
|
+
const body = await refreshResponse.json();
|
|
79
|
+
const { accessToken /* token used to call the API */, id_token /* token containing user identity details (only returned if OpenID Connect scopes are requested) */, expires_in /* amount of seconds until the access token expires */, token_type: tokenType /* must be Bearer */, refreshToken
|
|
80
|
+
/* token used to refresh the access token once it has expired (only returned if the offline_access scope is requested).
|
|
81
|
+
*/
|
|
82
|
+
} = body;
|
|
83
|
+
const { exp } = (0, utils_1.parseJwt)(accessToken);
|
|
84
|
+
var patch = {
|
|
85
|
+
accessToken,
|
|
86
|
+
refreshToken,
|
|
87
|
+
tokenType,
|
|
88
|
+
expiresIn: new Date(exp * 1000)
|
|
89
|
+
};
|
|
90
|
+
const repository = (0, typeorm_1.getRepository)(entities_1.FulfillmentCenter);
|
|
91
|
+
return await repository.save(Object.assign(Object.assign({}, fulfillmentCenter), patch));
|
|
92
|
+
}
|
|
61
93
|
}
|
|
62
94
|
exports.Operato = Operato;
|
|
63
95
|
//# sourceMappingURL=operato.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operato.js","sourceRoot":"","sources":["../../../server/controllers/operato/operato.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,4DAA8B;AAE9B,6CAA4C;
|
|
1
|
+
{"version":3,"file":"operato.js","sourceRoot":"","sources":["../../../server/controllers/operato/operato.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,4DAA8B;AAE9B,6CAA4C;AAC5C,iDAAgD;AAChD,qCAAuC;AACvC,6CAAkD;AAElD,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,YAAM,CAAC,GAAG,CAAC,+BAA+B,EAAE,EAAE,CAAC,CAAA;AAE9F,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,gDAAgD,CAAC,CAAA;AAUrE,MAAa,OAAO;IAGlB,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,qBACN,MAAM,CACV,CAAA;IACH,CAAC;IAED,YAAY,CAAC,KAAK;QAChB,4BAA4B;QAC5B,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;QAC3C,sJAAsJ;QACtJ,OAAO,GAAG,QAAQ,MAAM,IAAI,iDAAiD,MAAM,iCAAiC,WAAW,UAAU,KAAK,EAAE,CAAA;I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AI,KAAK,GAAG;YACV,WAAW;YACX,YAAY;YACZ,SAAS;YACT,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;SAChC,CAAA;QAED,MAAM,UAAU,GAAG,IAAA,uBAAa,EAAC,4BAAiB,CAAC,CAAA;QAEnD,OAAO,MAAM,UAAU,CAAC,IAAI,iCACvB,iBAAiB,GACjB,KAAK,EACR,CAAA;IACJ,CAAC;CACF;AA5GD,0BA4GC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.action = void 0;
|
|
3
|
+
exports.action = exports._action = void 0;
|
|
4
4
|
const operato_1 = require("./operato");
|
|
5
5
|
const env_1 = require("@things-factory/env");
|
|
6
6
|
const operatoConfig = env_1.config.get('fulfillmentIntegrationOperato', {});
|
|
@@ -19,7 +19,7 @@ function substitute(path, obj) {
|
|
|
19
19
|
});
|
|
20
20
|
return result;
|
|
21
21
|
}
|
|
22
|
-
const
|
|
22
|
+
const _action = async ({ center, method = 'get', path, request }) => {
|
|
23
23
|
const client = new operato_1.Operato({
|
|
24
24
|
center: center.centerId,
|
|
25
25
|
appKey,
|
|
@@ -28,11 +28,22 @@ const action = async ({ center, method = 'get', path, request }) => {
|
|
|
28
28
|
});
|
|
29
29
|
const { resource = {}, payload = {} } = request;
|
|
30
30
|
path = substitute(path, resource);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
return await client[method](center, path, payload);
|
|
32
|
+
};
|
|
33
|
+
exports._action = _action;
|
|
34
|
+
const action = async ({ center, method = 'get', path, request }) => {
|
|
35
|
+
try {
|
|
36
|
+
return await (0, exports._action)({ center, method, path, request });
|
|
37
|
+
}
|
|
38
|
+
catch (ex) {
|
|
39
|
+
if (ex.status === 401) {
|
|
40
|
+
var refreshed = await operato_1.Operato.refreshAccessToken(center);
|
|
41
|
+
return await (0, exports._action)({ center: refreshed, method, path, request });
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw ex;
|
|
45
|
+
}
|
|
34
46
|
}
|
|
35
|
-
return response;
|
|
36
47
|
};
|
|
37
48
|
exports.action = action;
|
|
38
49
|
//# sourceMappingURL=platform-action.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-action.js","sourceRoot":"","sources":["../../../server/controllers/operato/platform-action.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AAEnC,6CAA4C;AAC5C,MAAM,aAAa,GAAG,YAAM,CAAC,GAAG,CAAC,+BAA+B,EAAE,EAAE,CAAC,CAAA;AACrE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,aAAa,CAAA;AAE3C,SAAS,UAAU,CAAC,IAAI,EAAE,GAAG;IAC3B,IAAI,KAAK,GAAG,EAAE,CAAA;IACd,IAAI,EAAE,GAAG,YAAY,CAAA;IACrB,IAAI,IAAI,CAAA;IAER,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE;QAC7B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;KACpB;IAED,IAAI,MAAM,GAAG,IAAI,CAAA;IACjB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACnB,IAAI,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAC5B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,GAAG,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;IACxE,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC;AAEM,MAAM,
|
|
1
|
+
{"version":3,"file":"platform-action.js","sourceRoot":"","sources":["../../../server/controllers/operato/platform-action.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AAEnC,6CAA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,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;AACpD,CAAC,CAAA;AAbY,QAAA,OAAO,WAanB;AAEM,MAAM,MAAM,GAAG,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;IACxE,IAAI;QACF,OAAO,MAAM,IAAA,eAAO,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;KACxD;IAAC,OAAO,EAAE,EAAE;QACX,IAAI,EAAE,CAAC,MAAM,KAAK,GAAG,EAAE;YACrB,IAAI,SAAS,GAAG,MAAM,iBAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;YACxD,OAAO,MAAM,IAAA,eAAO,EAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;SACnE;aAAM;YACL,MAAM,EAAE,CAAA;SACT;KACF;AACH,CAAC,CAAA;AAXY,QAAA,MAAM,UAWlB"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Mutation = exports.Query = void 0;
|
|
4
|
-
const get_operato_auth_url_1 = require("./get-operato-auth-url");
|
|
5
4
|
const deactivate_operato_center_1 = require("./deactivate-operato-center");
|
|
6
5
|
const generate_operato_access_token_1 = require("./generate-operato-access-token");
|
|
6
|
+
const get_operato_auth_url_1 = require("./get-operato-auth-url");
|
|
7
|
+
const refresh_operato_access_token_1 = require("./refresh-operato-access-token");
|
|
7
8
|
exports.Query = Object.assign({}, get_operato_auth_url_1.getOperatoAuthURL);
|
|
8
|
-
exports.Mutation = Object.assign(Object.assign({}, generate_operato_access_token_1.generateOperatoAccessToken), deactivate_operato_center_1.deactivateOperatoCenter);
|
|
9
|
+
exports.Mutation = Object.assign(Object.assign(Object.assign({}, generate_operato_access_token_1.generateOperatoAccessToken), deactivate_operato_center_1.deactivateOperatoCenter), refresh_operato_access_token_1.refreshOperatoAccessToken);
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../server/graphql/resolvers/fulfillment-center/operato/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../server/graphql/resolvers/fulfillment-center/operato/index.ts"],"names":[],"mappings":";;;AAAA,2EAAqE;AACrE,mFAA4E;AAC5E,iEAA0D;AAC1D,iFAA0E;AAE7D,QAAA,KAAK,qBACb,wCAAiB,EACrB;AAEY,QAAA,QAAQ,iDAChB,0DAA0B,GAC1B,mDAAuB,GACvB,wDAAyB,EAC7B"}
|
package/dist-server/graphql/resolvers/fulfillment-center/operato/refresh-operato-access-token.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.refreshOperatoAccessToken = void 0;
|
|
7
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
|
+
const typeorm_1 = require("typeorm");
|
|
9
|
+
const env_1 = require("@things-factory/env");
|
|
10
|
+
const utils_1 = require("@things-factory/utils");
|
|
11
|
+
const entities_1 = require("../../../../entities");
|
|
12
|
+
const { protocol = 'https', host, appKey, appSecret } = env_1.config.get('fulfillmentIntegrationOperato', {});
|
|
13
|
+
const debug = require('debug')('things-factory:integration-fulfillment:refresh-operato-access-token');
|
|
14
|
+
exports.refreshOperatoAccessToken = {
|
|
15
|
+
async refreshOperatoAccessToken(_, { id }, context) {
|
|
16
|
+
const repository = (0, typeorm_1.getRepository)(entities_1.FulfillmentCenter);
|
|
17
|
+
const fulfillmentCenter = await repository.findOne({
|
|
18
|
+
where: { domain: context.state.domain, id }
|
|
19
|
+
});
|
|
20
|
+
const requestBody = {
|
|
21
|
+
refreshToken: fulfillmentCenter.refreshToken
|
|
22
|
+
};
|
|
23
|
+
const refreshResponse = await (0, node_fetch_1.default)(`${protocol}://${host}/oauth/refresh-token`, {
|
|
24
|
+
method: 'post',
|
|
25
|
+
headers: {
|
|
26
|
+
'Content-Type': 'application/json'
|
|
27
|
+
},
|
|
28
|
+
body: JSON.stringify(requestBody)
|
|
29
|
+
});
|
|
30
|
+
if (!refreshResponse.ok) {
|
|
31
|
+
throw new Error(`get operato information failed: ${await refreshResponse.text()}`);
|
|
32
|
+
}
|
|
33
|
+
const body = await refreshResponse.json();
|
|
34
|
+
const { accessToken /* token used to call the API */, id_token /* token containing user identity details (only returned if OpenID Connect scopes are requested) */, expires_in /* amount of seconds until the access token expires */, token_type: tokenType /* must be Bearer */, refreshToken
|
|
35
|
+
/* token used to refresh the access token once it has expired (only returned if the offline_access scope is requested).
|
|
36
|
+
*/
|
|
37
|
+
} = body;
|
|
38
|
+
const { exp } = (0, utils_1.parseJwt)(accessToken);
|
|
39
|
+
var patch = {
|
|
40
|
+
accessToken,
|
|
41
|
+
refreshToken,
|
|
42
|
+
tokenType,
|
|
43
|
+
expiresIn: new Date(exp * 1000)
|
|
44
|
+
};
|
|
45
|
+
return await repository.save(Object.assign(Object.assign(Object.assign({}, fulfillmentCenter), patch), { updater: context.state.user }));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=refresh-operato-access-token.js.map
|
package/dist-server/graphql/resolvers/fulfillment-center/operato/refresh-operato-access-token.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-operato-access-token.js","sourceRoot":"","sources":["../../../../../server/graphql/resolvers/fulfillment-center/operato/refresh-operato-access-token.ts"],"names":[],"mappings":";;;;;;A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AAE,SAAS,CAAC,oBAAoB,EAC1C,YAAY;QACZ;WACG;UACJ,GAAG,IAAI,CAAA;QAER,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,gBAAQ,EAAC,WAAW,CAAC,CAAA;QAErC,IAAI,KAAK,GAAG;YACV,WAAW;YACX,YAAY;YACZ,SAAS;YACT,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;SAChC,CAAA;QAED,OAAO,MAAM,UAAU,CAAC,IAAI,+CACvB,iBAAiB,GACjB,KAAK,KACR,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,IAC3B,CAAA;IACJ,CAAC;CACF,CAAA"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Types = exports.Query = exports.Mutation = void 0;
|
|
4
4
|
const fulfillment_center_1 = require("./fulfillment-center");
|
|
5
|
-
const new_fulfillment_center_1 = require("./new-fulfillment-center");
|
|
6
|
-
const fulfillment_center_patch_1 = require("./fulfillment-center-patch");
|
|
7
5
|
const fulfillment_center_list_1 = require("./fulfillment-center-list");
|
|
6
|
+
const fulfillment_center_patch_1 = require("./fulfillment-center-patch");
|
|
7
|
+
const new_fulfillment_center_1 = require("./new-fulfillment-center");
|
|
8
8
|
exports.Mutation = `
|
|
9
9
|
createFulfillmentCenter (
|
|
10
10
|
fulfillmentCenter: NewFulfillmentCenter!
|
|
@@ -35,6 +35,10 @@ exports.Mutation = `
|
|
|
35
35
|
deactivateOperatoCenter (
|
|
36
36
|
name: String!
|
|
37
37
|
): FulfillmentCenter @transaction
|
|
38
|
+
|
|
39
|
+
refreshOperatoAccessToken (
|
|
40
|
+
id: String!
|
|
41
|
+
): FulfillmentCenter
|
|
38
42
|
`;
|
|
39
43
|
exports.Query = `
|
|
40
44
|
fulfillmentCenters(filters: [Filter], pagination: Pagination, sortings: [Sorting]): FulfillmentCenterList
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/types/fulfillment-center/index.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/types/fulfillment-center/index.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AACxD,uEAAiE;AACjE,yEAAmE;AACnE,qEAA+D;AAElD,QAAA,QAAQ,GAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCrC,CAAA;AAEY,QAAA,KAAK,GAAiB;;;;;;;;CAQlC,CAAA;AAEY,QAAA,KAAK,GAAG,CAAC,sCAAiB,EAAE,6CAAoB,EAAE,iDAAsB,EAAE,+CAAqB,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/integration-fulfillment",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.27",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -25,17 +25,17 @@
|
|
|
25
25
|
"test": "DEBUG=things-factory:* NODE_ENV=development npx mocha -r ts-node/register ./test/**/*spec.ts"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@things-factory/apptool-ui": "^4.0.
|
|
29
|
-
"@things-factory/auth-ui": "^4.0.
|
|
30
|
-
"@things-factory/biz-base": "^4.0.
|
|
31
|
-
"@things-factory/context-ui": "^4.0.
|
|
32
|
-
"@things-factory/grist-ui": "^4.0.
|
|
33
|
-
"@things-factory/i18n-ui": "^4.0.
|
|
34
|
-
"@things-factory/integration-ui": "^4.0.
|
|
35
|
-
"@things-factory/more-ui": "^4.0.
|
|
36
|
-
"@things-factory/resource-ui": "^4.0.
|
|
37
|
-
"@things-factory/setting-ui": "^4.0.
|
|
38
|
-
"@things-factory/system-ui": "^4.0.
|
|
28
|
+
"@things-factory/apptool-ui": "^4.0.27",
|
|
29
|
+
"@things-factory/auth-ui": "^4.0.27",
|
|
30
|
+
"@things-factory/biz-base": "^4.0.27",
|
|
31
|
+
"@things-factory/context-ui": "^4.0.27",
|
|
32
|
+
"@things-factory/grist-ui": "^4.0.27",
|
|
33
|
+
"@things-factory/i18n-ui": "^4.0.27",
|
|
34
|
+
"@things-factory/integration-ui": "^4.0.27",
|
|
35
|
+
"@things-factory/more-ui": "^4.0.27",
|
|
36
|
+
"@things-factory/resource-ui": "^4.0.27",
|
|
37
|
+
"@things-factory/setting-ui": "^4.0.27",
|
|
38
|
+
"@things-factory/system-ui": "^4.0.27",
|
|
39
39
|
"debug": "^4.1.1",
|
|
40
40
|
"node-fetch": "^2.6.0"
|
|
41
41
|
},
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"nock": "^13.0.2",
|
|
51
51
|
"should": "^13.2.3"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "276eaface2890c8f229ce6c9f64cde9c6b1e0083"
|
|
54
54
|
}
|
|
@@ -2,6 +2,9 @@ import Debug from 'debug'
|
|
|
2
2
|
import fetch from 'node-fetch'
|
|
3
3
|
|
|
4
4
|
import { config } from '@things-factory/env'
|
|
5
|
+
import { parseJwt } from '@things-factory/utils'
|
|
6
|
+
import { getRepository } from 'typeorm'
|
|
7
|
+
import { FulfillmentCenter } from '../../entities'
|
|
5
8
|
|
|
6
9
|
const { protocol = 'https', host, callback } = config.get('fulfillmentIntegrationOperato', {})
|
|
7
10
|
|
|
@@ -75,7 +78,52 @@ export class Operato {
|
|
|
75
78
|
} else {
|
|
76
79
|
const text = await response.text()
|
|
77
80
|
debug('response result', text)
|
|
78
|
-
throw
|
|
81
|
+
throw response
|
|
79
82
|
}
|
|
80
83
|
}
|
|
84
|
+
|
|
85
|
+
public static async refreshAccessToken(fulfillmentCenter) {
|
|
86
|
+
const requestBody = {
|
|
87
|
+
refreshToken: fulfillmentCenter.refreshToken
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const refreshResponse = await fetch(`${protocol}://${host}/oauth/refresh-token`, {
|
|
91
|
+
method: 'post',
|
|
92
|
+
headers: {
|
|
93
|
+
'Content-Type': 'application/json'
|
|
94
|
+
},
|
|
95
|
+
body: JSON.stringify(requestBody)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
if (!refreshResponse.ok) {
|
|
99
|
+
throw new Error(`get operato information failed: ${await refreshResponse.text()}`)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const body = await refreshResponse.json()
|
|
103
|
+
const {
|
|
104
|
+
accessToken /* token used to call the API */,
|
|
105
|
+
id_token /* token containing user identity details (only returned if OpenID Connect scopes are requested) */,
|
|
106
|
+
expires_in /* amount of seconds until the access token expires */,
|
|
107
|
+
token_type: tokenType /* must be Bearer */,
|
|
108
|
+
refreshToken
|
|
109
|
+
/* token used to refresh the access token once it has expired (only returned if the offline_access scope is requested).
|
|
110
|
+
*/
|
|
111
|
+
} = body
|
|
112
|
+
|
|
113
|
+
const { exp } = parseJwt(accessToken)
|
|
114
|
+
|
|
115
|
+
var patch = {
|
|
116
|
+
accessToken,
|
|
117
|
+
refreshToken,
|
|
118
|
+
tokenType,
|
|
119
|
+
expiresIn: new Date(exp * 1000)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const repository = getRepository(FulfillmentCenter)
|
|
123
|
+
|
|
124
|
+
return await repository.save({
|
|
125
|
+
...fulfillmentCenter,
|
|
126
|
+
...patch
|
|
127
|
+
})
|
|
128
|
+
}
|
|
81
129
|
}
|
|
@@ -22,7 +22,7 @@ function substitute(path, obj) {
|
|
|
22
22
|
return result
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const
|
|
25
|
+
export const _action = async ({ center, method = 'get', path, request }) => {
|
|
26
26
|
const client = new Operato({
|
|
27
27
|
center: center.centerId,
|
|
28
28
|
appKey,
|
|
@@ -34,10 +34,18 @@ export const action = async ({ center, method = 'get', path, request }) => {
|
|
|
34
34
|
|
|
35
35
|
path = substitute(path, resource)
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
throw response
|
|
40
|
-
}
|
|
37
|
+
return await client[method](center, path, payload)
|
|
38
|
+
}
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
export const action = async ({ center, method = 'get', path, request }) => {
|
|
41
|
+
try {
|
|
42
|
+
return await _action({ center, method, path, request })
|
|
43
|
+
} catch (ex) {
|
|
44
|
+
if (ex.status === 401) {
|
|
45
|
+
var refreshed = await Operato.refreshAccessToken(center)
|
|
46
|
+
return await _action({ center: refreshed, method, path, request })
|
|
47
|
+
} else {
|
|
48
|
+
throw ex
|
|
49
|
+
}
|
|
50
|
+
}
|
|
43
51
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getOperatoAuthURL } from './get-operato-auth-url'
|
|
2
|
-
|
|
3
1
|
import { deactivateOperatoCenter } from './deactivate-operato-center'
|
|
4
2
|
import { generateOperatoAccessToken } from './generate-operato-access-token'
|
|
3
|
+
import { getOperatoAuthURL } from './get-operato-auth-url'
|
|
4
|
+
import { refreshOperatoAccessToken } from './refresh-operato-access-token'
|
|
5
5
|
|
|
6
6
|
export const Query = {
|
|
7
7
|
...getOperatoAuthURL
|
|
@@ -9,5 +9,6 @@ export const Query = {
|
|
|
9
9
|
|
|
10
10
|
export const Mutation = {
|
|
11
11
|
...generateOperatoAccessToken,
|
|
12
|
-
...deactivateOperatoCenter
|
|
12
|
+
...deactivateOperatoCenter,
|
|
13
|
+
...refreshOperatoAccessToken
|
|
13
14
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import fetch from 'node-fetch'
|
|
2
|
+
import { getRepository } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { config } from '@things-factory/env'
|
|
5
|
+
import { parseJwt } from '@things-factory/utils'
|
|
6
|
+
|
|
7
|
+
import { FulfillmentCenter } from '../../../../entities'
|
|
8
|
+
|
|
9
|
+
const { protocol = 'https', host, appKey, appSecret } = config.get('fulfillmentIntegrationOperato', {})
|
|
10
|
+
|
|
11
|
+
const debug = require('debug')('things-factory:integration-fulfillment:refresh-operato-access-token')
|
|
12
|
+
|
|
13
|
+
export const refreshOperatoAccessToken = {
|
|
14
|
+
async refreshOperatoAccessToken(_: any, { id }, context: any) {
|
|
15
|
+
const repository = getRepository(FulfillmentCenter)
|
|
16
|
+
const fulfillmentCenter: any = await repository.findOne({
|
|
17
|
+
where: { domain: context.state.domain, id }
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const requestBody = {
|
|
21
|
+
refreshToken: fulfillmentCenter.refreshToken
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const refreshResponse = await fetch(`${protocol}://${host}/oauth/refresh-token`, {
|
|
25
|
+
method: 'post',
|
|
26
|
+
headers: {
|
|
27
|
+
'Content-Type': 'application/json'
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify(requestBody)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
if (!refreshResponse.ok) {
|
|
33
|
+
throw new Error(`get operato information failed: ${await refreshResponse.text()}`)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const body = await refreshResponse.json()
|
|
37
|
+
const {
|
|
38
|
+
accessToken /* token used to call the API */,
|
|
39
|
+
id_token /* token containing user identity details (only returned if OpenID Connect scopes are requested) */,
|
|
40
|
+
expires_in /* amount of seconds until the access token expires */,
|
|
41
|
+
token_type: tokenType /* must be Bearer */,
|
|
42
|
+
refreshToken
|
|
43
|
+
/* token used to refresh the access token once it has expired (only returned if the offline_access scope is requested).
|
|
44
|
+
*/
|
|
45
|
+
} = body
|
|
46
|
+
|
|
47
|
+
const { exp } = parseJwt(accessToken)
|
|
48
|
+
|
|
49
|
+
var patch = {
|
|
50
|
+
accessToken,
|
|
51
|
+
refreshToken,
|
|
52
|
+
tokenType,
|
|
53
|
+
expiresIn: new Date(exp * 1000)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return await repository.save({
|
|
57
|
+
...fulfillmentCenter,
|
|
58
|
+
...patch,
|
|
59
|
+
updater: context.state.user
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FulfillmentCenter } from './fulfillment-center'
|
|
2
|
-
import { NewFulfillmentCenter } from './new-fulfillment-center'
|
|
3
|
-
import { FulfillmentCenterPatch } from './fulfillment-center-patch'
|
|
4
2
|
import { FulfillmentCenterList } from './fulfillment-center-list'
|
|
3
|
+
import { FulfillmentCenterPatch } from './fulfillment-center-patch'
|
|
4
|
+
import { NewFulfillmentCenter } from './new-fulfillment-center'
|
|
5
5
|
|
|
6
6
|
export const Mutation = /* GraphQL */ `
|
|
7
7
|
createFulfillmentCenter (
|
|
@@ -33,6 +33,10 @@ export const Mutation = /* GraphQL */ `
|
|
|
33
33
|
deactivateOperatoCenter (
|
|
34
34
|
name: String!
|
|
35
35
|
): FulfillmentCenter @transaction
|
|
36
|
+
|
|
37
|
+
refreshOperatoAccessToken (
|
|
38
|
+
id: String!
|
|
39
|
+
): FulfillmentCenter
|
|
36
40
|
`
|
|
37
41
|
|
|
38
42
|
export const Query = /* GraphQL */ `
|
package/translations/en.json
CHANGED
package/translations/ms.json
CHANGED