@activepieces/piece-sftp 0.1.2 → 0.1.4
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/package.json +5 -4
- package/src/index.js +38 -12
- package/src/index.js.map +1 -1
- package/src/lib/actions/create-file.js +9 -3
- package/src/lib/actions/create-file.js.map +1 -1
- package/src/lib/actions/read-file.d.ts +9 -0
- package/src/lib/actions/read-file.js +56 -0
- package/src/lib/actions/read-file.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@activepieces/piece-sftp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@sinclair/typebox": "^0.26.3",
|
|
6
6
|
"axios": "1.4.0",
|
|
7
7
|
"dayjs": "^1.11.8",
|
|
8
|
+
"is-base64": "^1.1.0",
|
|
8
9
|
"nanoid": "^3.3.4",
|
|
9
10
|
"semver": "7.5.3",
|
|
10
11
|
"ssh2-sftp-client": "^9.1.0",
|
|
11
|
-
"@activepieces/pieces-common": "0.2.
|
|
12
|
-
"@activepieces/pieces-framework": "0.6.
|
|
13
|
-
"@activepieces/shared": "0.
|
|
12
|
+
"@activepieces/pieces-common": "0.2.2",
|
|
13
|
+
"@activepieces/pieces-framework": "0.6.10",
|
|
14
|
+
"@activepieces/shared": "0.6.4",
|
|
14
15
|
"tslib": "1.14.1"
|
|
15
16
|
},
|
|
16
17
|
"main": "./src/index.js",
|
package/src/index.js
CHANGED
|
@@ -1,44 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sftp = exports.sftpAuth = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
6
|
const create_file_1 = require("./lib/actions/create-file");
|
|
6
7
|
const new_modified_file_1 = require("./lib/triggers/new-modified-file");
|
|
8
|
+
const ssh2_sftp_client_1 = tslib_1.__importDefault(require("ssh2-sftp-client"));
|
|
9
|
+
const read_file_1 = require("./lib/actions/read-file");
|
|
7
10
|
exports.sftpAuth = pieces_framework_1.PieceAuth.CustomAuth({
|
|
8
|
-
displayName: 'Authentication',
|
|
9
11
|
description: 'Enter the authentication details',
|
|
10
12
|
props: {
|
|
11
13
|
host: pieces_framework_1.Property.ShortText({
|
|
12
14
|
displayName: 'Host',
|
|
13
15
|
description: 'The host of the SFTP server',
|
|
14
|
-
required: true
|
|
16
|
+
required: true
|
|
15
17
|
}),
|
|
16
18
|
port: pieces_framework_1.Property.Number({
|
|
17
19
|
displayName: 'Port',
|
|
18
20
|
description: 'The port of the SFTP server',
|
|
19
21
|
required: true,
|
|
20
|
-
defaultValue: 22
|
|
22
|
+
defaultValue: 22
|
|
21
23
|
}),
|
|
22
24
|
username: pieces_framework_1.Property.ShortText({
|
|
23
25
|
displayName: 'Username',
|
|
24
26
|
description: 'The username of the SFTP server',
|
|
25
|
-
required: true
|
|
27
|
+
required: true
|
|
26
28
|
}),
|
|
27
29
|
password: pieces_framework_1.PieceAuth.SecretText({
|
|
28
30
|
displayName: 'Password',
|
|
29
31
|
description: 'The password of the SFTP server',
|
|
30
|
-
required: true
|
|
31
|
-
})
|
|
32
|
+
required: true
|
|
33
|
+
})
|
|
32
34
|
},
|
|
35
|
+
validate: ({ auth }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const { host, port, username, password } = auth;
|
|
37
|
+
const sftp = new ssh2_sftp_client_1.default();
|
|
38
|
+
try {
|
|
39
|
+
yield sftp.connect({
|
|
40
|
+
host,
|
|
41
|
+
port,
|
|
42
|
+
username,
|
|
43
|
+
password
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
valid: true
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
return {
|
|
51
|
+
valid: false,
|
|
52
|
+
error: 'Connection failed. Please check your credentials and try again.'
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
yield sftp.end();
|
|
57
|
+
}
|
|
58
|
+
}),
|
|
33
59
|
required: true
|
|
34
60
|
});
|
|
35
61
|
exports.sftp = (0, pieces_framework_1.createPiece)({
|
|
36
|
-
displayName:
|
|
37
|
-
minimumSupportedRelease: '0.
|
|
38
|
-
logoUrl:
|
|
39
|
-
authors: [
|
|
62
|
+
displayName: 'SFTP',
|
|
63
|
+
minimumSupportedRelease: '0.7.1',
|
|
64
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/sftp.svg',
|
|
65
|
+
authors: ['Abdallah-Alwarawreh', 'abuaboud'],
|
|
40
66
|
auth: exports.sftpAuth,
|
|
41
|
-
actions: [create_file_1.createFile],
|
|
42
|
-
triggers: [new_modified_file_1.newOrModifiedFile]
|
|
67
|
+
actions: [create_file_1.createFile, read_file_1.readFileContent],
|
|
68
|
+
triggers: [new_modified_file_1.newOrModifiedFile]
|
|
43
69
|
});
|
|
44
70
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/pieces/sftp/src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/pieces/sftp/src/index.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,2DAAuD;AACvD,wEAAqE;AACrE,gFAAsC;AACtC,uDAA0D;AAC7C,QAAA,QAAQ,GAAG,4BAAS,CAAC,UAAU,CAAC;IAC3C,WAAW,EAAE,kCAAkC;IAC/C,KAAK,EAAE;QACL,IAAI,EAAE,2BAAQ,CAAC,SAAS,CAAC;YACvB,WAAW,EAAE,MAAM;YACnB,WAAW,EAAE,6BAA6B;YAC1C,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,IAAI,EAA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,CAAC;IACtC,QAAQ,EAAE,CAAC,qCAAiB,CAAC;CAC9B,CAAC,CAAC"}
|
|
@@ -8,17 +8,15 @@ const __1 = require("../..");
|
|
|
8
8
|
exports.createFile = (0, pieces_framework_1.createAction)({
|
|
9
9
|
auth: __1.sftpAuth,
|
|
10
10
|
name: 'create_file',
|
|
11
|
-
displayName: 'Create
|
|
11
|
+
displayName: 'Create File from Text',
|
|
12
12
|
description: 'Create a new file in the given path',
|
|
13
13
|
props: {
|
|
14
14
|
fileName: pieces_framework_1.Property.ShortText({
|
|
15
15
|
displayName: 'File Path',
|
|
16
|
-
description: 'The name of the file to create',
|
|
17
16
|
required: true,
|
|
18
17
|
}),
|
|
19
18
|
fileContent: pieces_framework_1.Property.LongText({
|
|
20
19
|
displayName: 'File content',
|
|
21
|
-
description: 'The content of the file to create',
|
|
22
20
|
required: true,
|
|
23
21
|
})
|
|
24
22
|
},
|
|
@@ -38,6 +36,14 @@ exports.createFile = (0, pieces_framework_1.createAction)({
|
|
|
38
36
|
username,
|
|
39
37
|
password
|
|
40
38
|
});
|
|
39
|
+
const remotePathExists = yield sftp.exists(fileName);
|
|
40
|
+
if (!remotePathExists) {
|
|
41
|
+
// Extract the directory path from the fileName
|
|
42
|
+
const remoteDirectory = fileName.substring(0, fileName.lastIndexOf('/'));
|
|
43
|
+
// Create the directory if it doesn't exist
|
|
44
|
+
yield sftp.mkdir(remoteDirectory, true); // The second argument 'true' makes the function create all intermediate directories
|
|
45
|
+
// You can also check if the directory was successfully created and handle any potential errors here
|
|
46
|
+
}
|
|
41
47
|
yield sftp.put(Buffer.from(fileContent), fileName);
|
|
42
48
|
yield sftp.end();
|
|
43
49
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-file.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/sftp/src/lib/actions/create-file.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,gFAAqC;AACrC,6BAAiC;AAEpB,QAAA,UAAU,GA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AI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBACrD,IAAI,CAAC,gBAAgB,EAAE;oBACnB,+CAA+C;oBAC/C,MAAM,eAAe,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;oBAEzE,2CAA2C;oBAC3C,MAAM,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC,oFAAoF;oBAE7H,oGAAoG;iBACvG;gBAED,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,CAAC;gBACnD,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;gBAEjB,OAAO;oBACH,MAAM,EAAE,SAAS;iBACpB,CAAA;aACJ;YAAC,OAAO,GAAG,EAAE;gBACV,OAAO;oBACH,MAAM,EAAE,OAAO;oBACf,KAAK,EAAE,GAAG;iBACb,CAAA;aACJ;QACL,CAAC;KAAA;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const readFileContent: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<true, {
|
|
2
|
+
host: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
port: import("@activepieces/pieces-framework").NumberProperty<true>;
|
|
4
|
+
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
5
|
+
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
6
|
+
}>, {
|
|
7
|
+
filePath: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
outputFormat: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readFileContent = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const index_1 = require("../../index");
|
|
6
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
7
|
+
const ssh2_sftp_client_1 = tslib_1.__importDefault(require("ssh2-sftp-client"));
|
|
8
|
+
exports.readFileContent = (0, pieces_framework_1.createAction)({
|
|
9
|
+
auth: index_1.sftpAuth,
|
|
10
|
+
name: 'read_file_content',
|
|
11
|
+
displayName: 'Read File Content',
|
|
12
|
+
description: 'Read the content of a file',
|
|
13
|
+
props: {
|
|
14
|
+
filePath: pieces_framework_1.Property.ShortText({
|
|
15
|
+
displayName: 'File Path',
|
|
16
|
+
required: true
|
|
17
|
+
}),
|
|
18
|
+
outputFormat: pieces_framework_1.Property.StaticDropdown({
|
|
19
|
+
displayName: 'Output Format',
|
|
20
|
+
required: true,
|
|
21
|
+
defaultValue: 'base64',
|
|
22
|
+
options: {
|
|
23
|
+
options: [
|
|
24
|
+
{
|
|
25
|
+
value: 'Text',
|
|
26
|
+
label: 'utf8'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
value: 'base64',
|
|
30
|
+
label: 'Base64'
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
},
|
|
36
|
+
run(context) {
|
|
37
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const { host, port, username, password } = context.auth;
|
|
39
|
+
const filePath = context.propsValue['filePath'];
|
|
40
|
+
const sftp = new ssh2_sftp_client_1.default();
|
|
41
|
+
yield sftp.connect({
|
|
42
|
+
host,
|
|
43
|
+
port,
|
|
44
|
+
username,
|
|
45
|
+
password,
|
|
46
|
+
readyTimeout: 15000
|
|
47
|
+
});
|
|
48
|
+
const fileContent = yield sftp.get(filePath);
|
|
49
|
+
yield sftp.end();
|
|
50
|
+
return {
|
|
51
|
+
base64: fileContent.toString(context.propsValue.outputFormat === 'base64' ? 'base64' : 'utf8')
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=read-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/sftp/src/lib/actions/read-file.ts"],"names":[],"mappings":";;;;AAAA,uCAAuC;AACvC,qEAAwE;AACxE,gFAAsC;AAEzB,QAAA,eAAe,GAAG,IAAA,+BAAY,EAAC;IAC1C,IAAI,EAAE,gBAAQ;IACd,IAAI,EAAE,mBAAmB;IACzB,WAAW,EAAE,mBAAmB;IAChC,WAAW,EAAE,4BAA4B;IACzC,KAAK,EAAE;QACL,QAAQ,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC3B,WAAW,EAAE,WAAW;YACxB,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,YAAY,EAAE,2BAAQ,CAAC,cAAc,CAAC;YACpC,WAAW,EAAE,eAAe;YAC5B,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,QAAQ;YACtB,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP;wBACE,KAAK,EAAE,MAAM;wBACb,KAAK,EAAE,MAAM;qBACd;oBACD;wBACE,KAAK,EAAE,QAAQ;wBACf,KAAK,EAAE,QAAQ;qBAChB;iBACF;aACF;SACF,CAAC;KACH;IACK,GAAG,CAAC,OAAO;;YACf,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;YACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YAChD,MAAM,IAAI,GAAG,IAAI,0BAAM,EAAE,CAAC;YAE1B,MAAM,IAAI,CAAC,OAAO,CAAC;gBACjB,IAAI;gBACJ,IAAI;gBACJ,QAAQ;gBACR,QAAQ;gBACR,YAAY,EAAE,KAAK;aACpB,CAAC,CAAC;YAEH,MAAM,WAAW,GAAG,MAAM,IAAI,C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