@things-factory/integration-sftp 3.8.8
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 +8 -0
- package/LICENSE.md +21 -0
- package/client/bootstrap.js +1 -0
- package/client/index.js +0 -0
- package/client/pages/main.js +25 -0
- package/client/route.js +10 -0
- package/client/themes/app-theme.css +59 -0
- package/config/config.development.js +1 -0
- package/config/config.production.js +1 -0
- package/dist-server/controllers/herbalife/apis/echo.js +19 -0
- package/dist-server/controllers/herbalife/apis/echo.js.map +1 -0
- package/dist-server/controllers/herbalife/apis/get-outbound-order.js +73 -0
- package/dist-server/controllers/herbalife/apis/get-outbound-order.js.map +1 -0
- package/dist-server/controllers/herbalife/apis/index.js +15 -0
- package/dist-server/controllers/herbalife/apis/index.js.map +1 -0
- package/dist-server/controllers/herbalife/herbalife.js +20 -0
- package/dist-server/controllers/herbalife/herbalife.js.map +1 -0
- package/dist-server/controllers/herbalife/index.js +30 -0
- package/dist-server/controllers/herbalife/index.js.map +1 -0
- package/dist-server/controllers/herbalife/platform-action.js +30 -0
- package/dist-server/controllers/herbalife/platform-action.js.map +1 -0
- package/dist-server/controllers/index.js +15 -0
- package/dist-server/controllers/index.js.map +1 -0
- package/dist-server/controllers/sftp-api/decorators.js +30 -0
- package/dist-server/controllers/sftp-api/decorators.js.map +1 -0
- package/dist-server/controllers/sftp-api/index.js +50 -0
- package/dist-server/controllers/sftp-api/index.js.map +1 -0
- package/dist-server/controllers/sftp-api/types.js +1 -0
- package/dist-server/controllers/sftp-api/types.js.map +1 -0
- package/dist-server/index.js +18 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/middlewares/index.js +8 -0
- package/dist-server/middlewares/index.js.map +1 -0
- package/dist-server/routes.js +25 -0
- package/dist-server/routes.js.map +1 -0
- package/dist-server/service/index.js +28 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/service/sftp/index.js +9 -0
- package/dist-server/service/sftp/index.js.map +1 -0
- package/dist-server/service/sftp/sftp-mutation.js +191 -0
- package/dist-server/service/sftp/sftp-mutation.js.map +1 -0
- package/dist-server/service/sftp/sftp-query.js +87 -0
- package/dist-server/service/sftp/sftp-query.js.map +1 -0
- package/dist-server/service/sftp/sftp-type.js +113 -0
- package/dist-server/service/sftp/sftp-type.js.map +1 -0
- package/dist-server/service/sftp/sftp.js +131 -0
- package/dist-server/service/sftp/sftp.js.map +1 -0
- package/dist-server/sftp-const.js +9 -0
- package/dist-server/sftp-const.js.map +1 -0
- package/dist-server/sftp-s3.js +53 -0
- package/dist-server/sftp-s3.js.map +1 -0
- package/dist-server/util/get-permitted-directories.js +16 -0
- package/dist-server/util/get-permitted-directories.js.map +1 -0
- package/dist-server/util/index.js +14 -0
- package/dist-server/util/index.js.map +1 -0
- package/package.json +36 -0
- package/server/controllers/herbalife/apis/echo.ts +14 -0
- package/server/controllers/herbalife/apis/get-outbound-order.ts +76 -0
- package/server/controllers/herbalife/apis/index.ts +2 -0
- package/server/controllers/herbalife/herbalife.ts +22 -0
- package/server/controllers/herbalife/index.ts +7 -0
- package/server/controllers/herbalife/platform-action.ts +34 -0
- package/server/controllers/index.ts +3 -0
- package/server/controllers/sftp-api/decorators.ts +43 -0
- package/server/controllers/sftp-api/index.ts +33 -0
- package/server/controllers/sftp-api/types.ts +0 -0
- package/server/index.ts +6 -0
- package/server/middlewares/index.ts +3 -0
- package/server/routes.ts +28 -0
- package/server/service/index.ts +18 -0
- package/server/service/sftp/index.ts +6 -0
- package/server/service/sftp/sftp-mutation.ts +185 -0
- package/server/service/sftp/sftp-query.ts +45 -0
- package/server/service/sftp/sftp-type.ts +72 -0
- package/server/service/sftp/sftp.ts +106 -0
- package/server/sftp-const.ts +6 -0
- package/server/sftp-s3.ts +64 -0
- package/server/util/get-permitted-directories.ts +15 -0
- package/server/util/index.ts +1 -0
- package/things-factory.config.js +13 -0
- package/translations/en.json +1 -0
- package/translations/ko.json +1 -0
- package/translations/ms.json +1 -0
- package/translations/zh.json +1 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./get-permitted-directories"), exports);
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8DAA2C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@things-factory/integration-sftp",
|
|
3
|
+
"version": "3.8.8",
|
|
4
|
+
"main": "dist-server/index.js",
|
|
5
|
+
"browser": "client/index.js",
|
|
6
|
+
"things-factory": true,
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "heartyoh",
|
|
9
|
+
"description": "Integration With SFTP",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"@things-factory:registry": "https://registry.npmjs.org"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/hatiolab/things-factory.git",
|
|
17
|
+
"directory": "packages/integration-sftp"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc --p tsconfig.json",
|
|
21
|
+
"build:server": "npm run clean:server && tsc",
|
|
22
|
+
"clean:server": "rm -rf dist-server",
|
|
23
|
+
"clean": "npm run clean:server",
|
|
24
|
+
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@things-factory/auth-base": "^3.8.0",
|
|
28
|
+
"@things-factory/biz-base": "^3.8.0",
|
|
29
|
+
"@things-factory/env": "^3.7.5",
|
|
30
|
+
"@things-factory/integration-fulfillment": "^3.8.0",
|
|
31
|
+
"@things-factory/shell": "^3.8.0",
|
|
32
|
+
"aws-sdk": "^2.960.0",
|
|
33
|
+
"xml-js": "^1.6.11"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "3f0cf4cd9eba27f4b4a7688c462cc3183dd9df00"
|
|
36
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export function getOutboundOrder() {
|
|
2
|
+
return {
|
|
3
|
+
method: 'get',
|
|
4
|
+
path: '{folderPath}/{folderType}/submit_outbound/data/{fileKey}',
|
|
5
|
+
denormalize(req) {
|
|
6
|
+
const { folderPath, folderType, fileKey } = req
|
|
7
|
+
return {
|
|
8
|
+
resource: { folderPath, folderType, fileKey }
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
normalize(res) {
|
|
12
|
+
const { Order } = res
|
|
13
|
+
|
|
14
|
+
let orderHeader: any = Order.OrderHeader
|
|
15
|
+
let generalInfo: any = orderHeader.General
|
|
16
|
+
let distributorDetails: any = orderHeader.DistributorDetails
|
|
17
|
+
let ntsDateParts = generalInfo.NTS_Date._text.split('/')
|
|
18
|
+
let releaseDate: string = ntsDateParts[2] + '-' + ntsDateParts[1] + '-' + ntsDateParts[0]
|
|
19
|
+
let orderInfo: any = {
|
|
20
|
+
refNo: generalInfo.OrderNumber._text,
|
|
21
|
+
type: 'b2c',
|
|
22
|
+
releaseDate,
|
|
23
|
+
collectionOrderNo: generalInfo.OrderNumber._text,
|
|
24
|
+
ownTransport: true,
|
|
25
|
+
exportOption: false,
|
|
26
|
+
packingOption: true,
|
|
27
|
+
billTo: {
|
|
28
|
+
billingAddress: distributorDetails.BillTo.BillToAddress._text
|
|
29
|
+
},
|
|
30
|
+
deliverTo: {
|
|
31
|
+
deliveryAddress1: distributorDetails.ShipTo.Address1._text,
|
|
32
|
+
deliveryAddress2: distributorDetails.ShipTo.Address2._text,
|
|
33
|
+
deliveryAddress3: distributorDetails.ShipTo.Address3._text,
|
|
34
|
+
deliveryAddress4: '-',
|
|
35
|
+
deliveryAddress5: '-',
|
|
36
|
+
attentionTo: distributorDetails.ShipTo.Name._text,
|
|
37
|
+
city: distributorDetails.ShipTo.City._text,
|
|
38
|
+
state: distributorDetails.ShipTo.ShipToState._text,
|
|
39
|
+
postalCode: distributorDetails.ShipTo.Zipcode._text,
|
|
40
|
+
country: distributorDetails.ShipTo.Country._text,
|
|
41
|
+
phone1: distributorDetails.ShipTo.Phone._text,
|
|
42
|
+
phone2: '-',
|
|
43
|
+
email: '-'
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let OrderLine = Order.OrderLine
|
|
48
|
+
let totalItems: number = parseFloat(Order.OrderLine.NumberOfOrderLines._text)
|
|
49
|
+
let orderItems: any[] =
|
|
50
|
+
totalItems == 1
|
|
51
|
+
? [
|
|
52
|
+
{
|
|
53
|
+
product: {
|
|
54
|
+
sku: OrderLine.Item.StockingSKU._text
|
|
55
|
+
},
|
|
56
|
+
releaseQty: parseFloat(OrderLine.Item.QtyOrdered._text)
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
: OrderLine.Item.map(line => {
|
|
60
|
+
return {
|
|
61
|
+
product: {
|
|
62
|
+
sku: line.StockingSKU._text
|
|
63
|
+
},
|
|
64
|
+
releaseQty: parseFloat(line.QtyOrdered._text)
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
let result: any = {
|
|
69
|
+
...orderInfo,
|
|
70
|
+
orderInventories: orderItems
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return result
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import '../../sftp-s3'
|
|
2
|
+
|
|
3
|
+
import { xml2js } from 'xml-js'
|
|
4
|
+
|
|
5
|
+
import { SFTPFILESTORAGE } from '../../sftp-const'
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')('things-factory:integration-sftp:herbalife')
|
|
8
|
+
|
|
9
|
+
export type HerbalifeConfig = {}
|
|
10
|
+
|
|
11
|
+
export class Herbalife {
|
|
12
|
+
constructor() {}
|
|
13
|
+
|
|
14
|
+
async get(path: string, data: any = {}) {
|
|
15
|
+
const fileResult: any = await SFTPFILESTORAGE.readFile(path, 'utf-8')
|
|
16
|
+
const item: any = xml2js(fileResult, {
|
|
17
|
+
compact: true
|
|
18
|
+
})
|
|
19
|
+
const result: any = { ...item }
|
|
20
|
+
return result
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Herbalife } from './herbalife'
|
|
2
|
+
|
|
3
|
+
function substitute(path, obj) {
|
|
4
|
+
var props = []
|
|
5
|
+
var re = /{([^}]+)}/g
|
|
6
|
+
var text
|
|
7
|
+
|
|
8
|
+
while ((text = re.exec(path))) {
|
|
9
|
+
props.push(text[1])
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var result = path
|
|
13
|
+
props.forEach(prop => {
|
|
14
|
+
let value = obj[prop.trim()]
|
|
15
|
+
result = result.replace(`{${prop}}`, value === undefined ? '' : value)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
return result
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const action = async ({ method = 'get', path, request }) => {
|
|
22
|
+
const client = new Herbalife()
|
|
23
|
+
|
|
24
|
+
const { resource = {}, payload = {} } = request
|
|
25
|
+
|
|
26
|
+
path = substitute(path, resource)
|
|
27
|
+
|
|
28
|
+
var response = await client[method](path, payload)
|
|
29
|
+
if (response.errors) {
|
|
30
|
+
throw response
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return response
|
|
34
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Debug from 'debug'
|
|
2
|
+
|
|
3
|
+
import { Sftp } from '../../service'
|
|
4
|
+
|
|
5
|
+
const debug = Debug('things-factory:integration-sftp:sftp-api-decorator')
|
|
6
|
+
|
|
7
|
+
const NOOP = v => v
|
|
8
|
+
|
|
9
|
+
export const api = (target: Object, property: string, descriptor: TypedPropertyDescriptor<any>): any => {
|
|
10
|
+
const method = descriptor.value
|
|
11
|
+
|
|
12
|
+
descriptor.value = async function (sftp: Sftp, request) {
|
|
13
|
+
const SftpAPI = this
|
|
14
|
+
|
|
15
|
+
var { platform } = sftp
|
|
16
|
+
|
|
17
|
+
var { action: platformAction, apis } = SftpAPI.getPlatform(platform)
|
|
18
|
+
|
|
19
|
+
var m = apis[method.name]
|
|
20
|
+
if (!m) {
|
|
21
|
+
throw Error(`SFTP doesn't have API ${method.name}`)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var {
|
|
25
|
+
path,
|
|
26
|
+
method: httpMethod = 'post',
|
|
27
|
+
denormalize = NOOP,
|
|
28
|
+
normalize = NOOP,
|
|
29
|
+
action = platformAction
|
|
30
|
+
} = m.apply(this, [request])
|
|
31
|
+
|
|
32
|
+
var denormalized = await denormalize(request || {}, { sftp })
|
|
33
|
+
debug('request', denormalized)
|
|
34
|
+
|
|
35
|
+
var response = await action.apply(this, [{ sftp, method: httpMethod, path, request: denormalized, platformAction }])
|
|
36
|
+
|
|
37
|
+
debug('response', response)
|
|
38
|
+
|
|
39
|
+
return await normalize(response, { sftp })
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return descriptor
|
|
43
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getRepository } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { Sftp } from '../../service'
|
|
4
|
+
import { api } from './decorators'
|
|
5
|
+
|
|
6
|
+
export class SftpAPI {
|
|
7
|
+
static platforms = {}
|
|
8
|
+
|
|
9
|
+
static registerPlatform(name, action, apis) {
|
|
10
|
+
SftpAPI.platforms[name] = {
|
|
11
|
+
action,
|
|
12
|
+
apis
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static getPlatform(name) {
|
|
17
|
+
return SftpAPI.platforms[name]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static async getSftp(id) {
|
|
21
|
+
const repository = getRepository(Sftp)
|
|
22
|
+
return await repository.findOne({
|
|
23
|
+
where: { id },
|
|
24
|
+
relations: ['domain']
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@api
|
|
29
|
+
static echo(sftp, req): any {}
|
|
30
|
+
|
|
31
|
+
@api
|
|
32
|
+
static getOutboundOrder(sftp, req): any {}
|
|
33
|
+
}
|
|
File without changes
|
package/server/index.ts
ADDED
package/server/routes.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const debug = require('debug')('things-factory:integration-sftp:routes')
|
|
2
|
+
|
|
3
|
+
process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
|
|
4
|
+
/*
|
|
5
|
+
* can add global public routes to application (auth not required, tenancy not required)
|
|
6
|
+
*
|
|
7
|
+
* ex) routes.get('/path', async(context, next) => {})
|
|
8
|
+
* ex) routes.post('/path', async(context, next) => {})
|
|
9
|
+
*/
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
|
|
13
|
+
/*
|
|
14
|
+
* can add global private routes to application (auth required, tenancy not required)
|
|
15
|
+
*/
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
|
|
19
|
+
/*
|
|
20
|
+
* can add domain public routes to application (auth not required, tenancy required)
|
|
21
|
+
*/
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
|
|
25
|
+
/*
|
|
26
|
+
* can add domain private routes to application (auth required, tenancy required)
|
|
27
|
+
*/
|
|
28
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* EXPORT ENTITY TYPES */
|
|
2
|
+
export * from './sftp/sftp'
|
|
3
|
+
|
|
4
|
+
/* IMPORT ENTITIES AND RESOLVERS */
|
|
5
|
+
import { entities as SftpEntities, resolvers as SftpResolvers } from './sftp'
|
|
6
|
+
|
|
7
|
+
export const entities = [
|
|
8
|
+
/* ENTITIES */
|
|
9
|
+
...SftpEntities,
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export const schema = {
|
|
14
|
+
resolverClasses: [
|
|
15
|
+
/* RESOLVER CLASSES */
|
|
16
|
+
...SftpResolvers,
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import '../../sftp-s3'
|
|
2
|
+
|
|
3
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
4
|
+
import { In } from 'typeorm'
|
|
5
|
+
|
|
6
|
+
import { Bizplace } from '@things-factory/biz-base'
|
|
7
|
+
import { FulfillmentAPI, FulFillmentCenter } from '@things-factory/integration-fulfillment'
|
|
8
|
+
import { Domain } from '@things-factory/shell'
|
|
9
|
+
|
|
10
|
+
import { SftpAPI } from '../../controllers'
|
|
11
|
+
import { FAILEDDATAPATH, SFTPFILESTORAGE, SUBMITDATAPATH, SUCCESSDATAPATH } from '../../sftp-const'
|
|
12
|
+
import { getPermittedDirectories } from '../../util'
|
|
13
|
+
import { Sftp } from './sftp'
|
|
14
|
+
import { NewSftp, SftpPatch } from './sftp-type'
|
|
15
|
+
|
|
16
|
+
@Resolver(Sftp)
|
|
17
|
+
export class SftpMutation {
|
|
18
|
+
@Directive('@transaction')
|
|
19
|
+
@Mutation(returns => Sftp, { description: 'To create new Sftp' })
|
|
20
|
+
async createSftp(@Arg('sftp') sftp: NewSftp, @Ctx() context: any): Promise<Sftp> {
|
|
21
|
+
const { domain, user, tx } = context.state
|
|
22
|
+
|
|
23
|
+
return await tx.getRepository(Sftp).save({
|
|
24
|
+
...sftp,
|
|
25
|
+
domain,
|
|
26
|
+
creator: user,
|
|
27
|
+
updater: user
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Directive('@transaction')
|
|
32
|
+
@Mutation(returns => Sftp, { description: 'To modify Sftp information' })
|
|
33
|
+
async updateSftp(@Arg('id') id: string, @Arg('patch') patch: SftpPatch, @Ctx() context: any): Promise<Sftp> {
|
|
34
|
+
const { domain, user, tx } = context.state
|
|
35
|
+
|
|
36
|
+
const repository = tx.getRepository(Sftp)
|
|
37
|
+
const sftp = await repository.findOne({
|
|
38
|
+
where: { domain, id }
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return await repository.save({
|
|
42
|
+
...sftp,
|
|
43
|
+
...patch,
|
|
44
|
+
updater: user
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Directive('@transaction')
|
|
49
|
+
@Mutation(returns => [Sftp], { description: "To modify multiple Sftps' information" })
|
|
50
|
+
async updateMultipleSftp(
|
|
51
|
+
@Arg('patches', type => [SftpPatch]) patches: SftpPatch[],
|
|
52
|
+
@Ctx() context: any
|
|
53
|
+
): Promise<Sftp[]> {
|
|
54
|
+
const { domain, user, tx } = context.state
|
|
55
|
+
|
|
56
|
+
let results = []
|
|
57
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
58
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
59
|
+
const sftpRepo = tx.getRepository(Sftp)
|
|
60
|
+
|
|
61
|
+
if (_createRecords.length > 0) {
|
|
62
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
63
|
+
const newRecord = _createRecords[i]
|
|
64
|
+
|
|
65
|
+
const result = await sftpRepo.save({
|
|
66
|
+
...newRecord,
|
|
67
|
+
domain,
|
|
68
|
+
creator: user,
|
|
69
|
+
updater: user
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
results.push({ ...result, cuFlag: '+' })
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (_updateRecords.length > 0) {
|
|
77
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
78
|
+
const newRecord = _updateRecords[i]
|
|
79
|
+
const sftp = await sftpRepo.findOne(newRecord.id)
|
|
80
|
+
|
|
81
|
+
const result = await sftpRepo.save({
|
|
82
|
+
...sftp,
|
|
83
|
+
...newRecord,
|
|
84
|
+
updater: user
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return results
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@Directive('@transaction')
|
|
95
|
+
@Mutation(returns => Boolean, { description: 'To delete Sftp' })
|
|
96
|
+
async deleteSftp(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
|
|
97
|
+
const { domain, tx } = context.state
|
|
98
|
+
|
|
99
|
+
await tx.getRepository(Sftp).delete({ domain, id })
|
|
100
|
+
return true
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@Directive('@transaction')
|
|
104
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple sftps' })
|
|
105
|
+
async deleteSftps(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
|
|
106
|
+
const { domain, tx } = context.state
|
|
107
|
+
|
|
108
|
+
await tx.getRepository(Sftp).delete({
|
|
109
|
+
domain,
|
|
110
|
+
id: In(ids)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
return true
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@Directive('@transaction')
|
|
117
|
+
@Mutation(returns => Boolean, { description: 'To sync all orders from sftp' })
|
|
118
|
+
async syncSftpOrders(
|
|
119
|
+
@Arg('customerDomainId', type => String) customerDomainId: string,
|
|
120
|
+
@Ctx() context: any
|
|
121
|
+
): Promise<boolean> {
|
|
122
|
+
const { tx } = context.state
|
|
123
|
+
|
|
124
|
+
const customerDomain: Domain = await tx.getRepository(Domain).findOne(customerDomainId)
|
|
125
|
+
|
|
126
|
+
const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
|
|
127
|
+
where: { domain: customerDomain }
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
const customerBizplaceId: string = customerBizplace.id
|
|
131
|
+
|
|
132
|
+
const sftpUsers: Sftp[] = await tx.getRepository(Sftp).find({
|
|
133
|
+
where: { domain: customerDomain },
|
|
134
|
+
relations: ['fulfillmentCenter']
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
for (var i = 0; i < sftpUsers.length; i++) {
|
|
138
|
+
const sftpUser: Sftp = sftpUsers[i]
|
|
139
|
+
|
|
140
|
+
const fulfilmentCenter: FulFillmentCenter = sftpUser.fulfillmentCenter
|
|
141
|
+
const isDevelopment: boolean = sftpUser.isDevelopment
|
|
142
|
+
const folderPath: string = sftpUser.folderPath
|
|
143
|
+
const folderType: string = isDevelopment ? 'development' : 'production'
|
|
144
|
+
let dataPath: string = `${sftpUser.folderPath}/${folderType}${SUBMITDATAPATH}/`
|
|
145
|
+
let successPath: string = `${sftpUser.folderPath}/${folderType}${SUCCESSDATAPATH}/`
|
|
146
|
+
let failedPath: string = `${sftpUser.folderPath}/${folderType}${FAILEDDATAPATH}/`
|
|
147
|
+
const results: any[] = await getPermittedDirectories({ path: dataPath }, context)
|
|
148
|
+
const filesDirectories: any[] = results.filter(result => result.Size > 0)
|
|
149
|
+
|
|
150
|
+
for (var j = 0; j < filesDirectories.length; j++) {
|
|
151
|
+
const fileDirectory: any = filesDirectories[j]
|
|
152
|
+
const fileKey: string = fileDirectory.Key
|
|
153
|
+
const lastSlashIdx = fileKey.lastIndexOf('/')
|
|
154
|
+
const fileString: string = fileKey.substring(lastSlashIdx + 1, fileKey.length)
|
|
155
|
+
try {
|
|
156
|
+
const sftp: any = { platform: sftpUser.platform }
|
|
157
|
+
const result: any = await SftpAPI.getOutboundOrder(sftp, { folderPath, folderType, fileKey: fileString })
|
|
158
|
+
|
|
159
|
+
if (result) {
|
|
160
|
+
var releaseOrder: any = await FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
|
|
161
|
+
customerBizplaceId,
|
|
162
|
+
releaseOrder: result
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
if (releaseOrder) {
|
|
166
|
+
let movePaths = {
|
|
167
|
+
source: dataPath += fileString,
|
|
168
|
+
destination: successPath += fileString
|
|
169
|
+
}
|
|
170
|
+
await SFTPFILESTORAGE.moveFile(movePaths)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} catch (e) {
|
|
174
|
+
let movePaths = {
|
|
175
|
+
source: dataPath += fileString,
|
|
176
|
+
destination: failedPath += fileString
|
|
177
|
+
}
|
|
178
|
+
await SFTPFILESTORAGE.moveFile(movePaths)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return true
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
+
import { getRepository } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { User } from '@things-factory/auth-base'
|
|
5
|
+
import { convertListParams, Domain, ListParam } from '@things-factory/shell'
|
|
6
|
+
|
|
7
|
+
import { Sftp } from './sftp'
|
|
8
|
+
import { SftpList } from './sftp-type'
|
|
9
|
+
|
|
10
|
+
@Resolver(Sftp)
|
|
11
|
+
export class SftpQuery {
|
|
12
|
+
@Query(returns => Sftp, { description: 'To fetch a Sftp' })
|
|
13
|
+
async sftp(@Arg('id') id: string, @Ctx() context: any): Promise<Sftp> {
|
|
14
|
+
const { domain } = context.state
|
|
15
|
+
|
|
16
|
+
return await getRepository(Sftp).findOne({
|
|
17
|
+
where: { domain, id }
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Query(returns => SftpList, { description: 'To fetch multiple Sftps' })
|
|
22
|
+
async sftps(@Args() params: ListParam, @Ctx() context: any): Promise<SftpList> {
|
|
23
|
+
const { domain } = context.state
|
|
24
|
+
|
|
25
|
+
const convertedParams = convertListParams(params, domain.id)
|
|
26
|
+
const [items, total] = await getRepository(Sftp).findAndCount(convertedParams)
|
|
27
|
+
|
|
28
|
+
return { items, total }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@FieldResolver(type => Domain)
|
|
32
|
+
async domain(@Root() sftp: Sftp): Promise<Domain> {
|
|
33
|
+
return await getRepository(Domain).findOne(sftp.domainId)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@FieldResolver(type => User)
|
|
37
|
+
async updater(@Root() sftp: Sftp): Promise<User> {
|
|
38
|
+
return await getRepository(User).findOne(sftp.updaterId)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@FieldResolver(type => User)
|
|
42
|
+
async creator(@Root() sftp: Sftp): Promise<User> {
|
|
43
|
+
return await getRepository(User).findOne(sftp.creatorId)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { Sftp } from './sftp'
|
|
4
|
+
|
|
5
|
+
@InputType()
|
|
6
|
+
export class NewSftp {
|
|
7
|
+
@Field()
|
|
8
|
+
name: string
|
|
9
|
+
|
|
10
|
+
@Field({ nullable: true })
|
|
11
|
+
description?: string
|
|
12
|
+
|
|
13
|
+
@Field({ nullable: true })
|
|
14
|
+
username?: string
|
|
15
|
+
|
|
16
|
+
@Field({ nullable: true })
|
|
17
|
+
publicKey?: string
|
|
18
|
+
|
|
19
|
+
@Field({ nullable: true })
|
|
20
|
+
privateKey?: string
|
|
21
|
+
|
|
22
|
+
@Field({ nullable: true })
|
|
23
|
+
folderPath?: string
|
|
24
|
+
|
|
25
|
+
@Field({ nullable: true })
|
|
26
|
+
isDevelopment?: boolean
|
|
27
|
+
|
|
28
|
+
@Field({ nullable: true })
|
|
29
|
+
platform?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@InputType()
|
|
33
|
+
export class SftpPatch {
|
|
34
|
+
@Field(type => ID, { nullable: true })
|
|
35
|
+
id?: string
|
|
36
|
+
|
|
37
|
+
@Field({ nullable: true })
|
|
38
|
+
name?: string
|
|
39
|
+
|
|
40
|
+
@Field({ nullable: true })
|
|
41
|
+
description?: string
|
|
42
|
+
|
|
43
|
+
@Field({ nullable: true })
|
|
44
|
+
username?: string
|
|
45
|
+
|
|
46
|
+
@Field({ nullable: true })
|
|
47
|
+
publicKey?: string
|
|
48
|
+
|
|
49
|
+
@Field({ nullable: true })
|
|
50
|
+
privateKey?: string
|
|
51
|
+
|
|
52
|
+
@Field({ nullable: true })
|
|
53
|
+
folderPath?: string
|
|
54
|
+
|
|
55
|
+
@Field({ nullable: true })
|
|
56
|
+
isDevelopment?: boolean
|
|
57
|
+
|
|
58
|
+
@Field({ nullable: true })
|
|
59
|
+
platform?: string
|
|
60
|
+
|
|
61
|
+
@Field()
|
|
62
|
+
cuFlag: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@ObjectType()
|
|
66
|
+
export class SftpList {
|
|
67
|
+
@Field(type => [Sftp])
|
|
68
|
+
items: Sftp[]
|
|
69
|
+
|
|
70
|
+
@Field(type => Int)
|
|
71
|
+
total: number
|
|
72
|
+
}
|