n8n-nodes-amis-v1 0.1.0 → 0.1.1
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.
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MisaAmisApp = void 0;
|
|
4
|
+
class MisaAmisApp {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = 'misaAmisApp';
|
|
7
|
+
this.displayName = 'MISA AMIS App Config';
|
|
8
|
+
this.documentationUrl = 'https://amisapp.misa.vn/';
|
|
9
|
+
this.properties = [
|
|
10
|
+
{
|
|
11
|
+
displayName: 'Storage Path',
|
|
12
|
+
name: 'storagePath',
|
|
13
|
+
type: 'string',
|
|
14
|
+
default: 'C:/Users/Admin/.n8n/misa_sessions',
|
|
15
|
+
description: 'Local directory to store user sessions (cookies). Ensure n8n has write access.',
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
displayName: 'API URL (Optional)',
|
|
20
|
+
name: 'apiUrl',
|
|
21
|
+
type: 'string',
|
|
22
|
+
default: '',
|
|
23
|
+
description: 'Placeholder for future server sync. Leave empty for local mode.',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
displayName: 'API Key (Optional)',
|
|
27
|
+
name: 'apiKey',
|
|
28
|
+
type: 'string',
|
|
29
|
+
typeOptions: {
|
|
30
|
+
password: true,
|
|
31
|
+
},
|
|
32
|
+
default: '',
|
|
33
|
+
description: 'Placeholder for future server authentication.',
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.MisaAmisApp = MisaAmisApp;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MisaAmisUser = void 0;
|
|
4
|
+
class MisaAmisUser {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = 'misaAmisUser';
|
|
7
|
+
this.displayName = 'MISA AMIS User Identity';
|
|
8
|
+
this.documentationUrl = 'https://amisapp.misa.vn/';
|
|
9
|
+
this.properties = [
|
|
10
|
+
{
|
|
11
|
+
displayName: 'User Identity (Email/ID)',
|
|
12
|
+
name: 'userIdentity',
|
|
13
|
+
type: 'string',
|
|
14
|
+
default: '',
|
|
15
|
+
description: 'The unique ID used when logging in (e.g. hiennv). Used to find the saved session file.',
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.MisaAmisUser = MisaAmisUser;
|
|
@@ -44,7 +44,6 @@ const tough_cookie_1 = require("tough-cookie");
|
|
|
44
44
|
const qrcode_1 = __importDefault(require("qrcode"));
|
|
45
45
|
const fs = __importStar(require("fs"));
|
|
46
46
|
const path = __importStar(require("path"));
|
|
47
|
-
const os = __importStar(require("os"));
|
|
48
47
|
class MisaAmisLogin {
|
|
49
48
|
constructor() {
|
|
50
49
|
this.description = {
|
|
@@ -53,7 +52,7 @@ class MisaAmisLogin {
|
|
|
53
52
|
icon: 'fa:users',
|
|
54
53
|
group: ['transform'],
|
|
55
54
|
version: 1,
|
|
56
|
-
description: 'Login to MISA AMIS via QR Code
|
|
55
|
+
description: 'Login to MISA AMIS via QR Code',
|
|
57
56
|
defaults: {
|
|
58
57
|
name: 'MISA AMIS Login',
|
|
59
58
|
},
|
|
@@ -61,26 +60,28 @@ class MisaAmisLogin {
|
|
|
61
60
|
outputs: ['main'],
|
|
62
61
|
credentials: [
|
|
63
62
|
{
|
|
64
|
-
name: '
|
|
63
|
+
name: 'misaAmisApp',
|
|
65
64
|
required: true,
|
|
66
65
|
},
|
|
67
66
|
],
|
|
68
67
|
properties: [
|
|
69
68
|
{
|
|
70
|
-
displayName: '
|
|
71
|
-
name: '
|
|
69
|
+
displayName: 'User Identity (Email/ID)',
|
|
70
|
+
name: 'userIdentity',
|
|
72
71
|
type: 'string',
|
|
73
72
|
default: '',
|
|
74
|
-
placeholder: '
|
|
75
|
-
description: '
|
|
73
|
+
placeholder: 'hiennv',
|
|
74
|
+
description: 'Unique identifier for the user logging in. This will be used to name the session file.',
|
|
76
75
|
required: true,
|
|
77
76
|
},
|
|
78
77
|
{
|
|
79
|
-
displayName: '
|
|
80
|
-
name: '
|
|
78
|
+
displayName: 'QR Code Path',
|
|
79
|
+
name: 'qrPath',
|
|
81
80
|
type: 'string',
|
|
82
81
|
default: '',
|
|
83
|
-
|
|
82
|
+
placeholder: 'C:/tmp/misa_qr.png',
|
|
83
|
+
description: 'Path to save the generated QR code image',
|
|
84
|
+
required: true,
|
|
84
85
|
},
|
|
85
86
|
],
|
|
86
87
|
};
|
|
@@ -89,20 +90,18 @@ class MisaAmisLogin {
|
|
|
89
90
|
const items = this.getInputData();
|
|
90
91
|
const returnData = [];
|
|
91
92
|
const qrPath = this.getNodeParameter('qrPath', 0);
|
|
92
|
-
|
|
93
|
-
const credentials = await this.getCredentials('
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
const userIdentity = this.getNodeParameter('userIdentity', 0);
|
|
94
|
+
const credentials = await this.getCredentials('misaAmisApp');
|
|
95
|
+
const storagePath = credentials.storagePath || 'C:/Users/Admin/.n8n/misa_sessions'; // Fallback
|
|
96
|
+
// Ensure Session Dir
|
|
97
|
+
if (!fs.existsSync(storagePath)) {
|
|
98
|
+
fs.mkdirSync(storagePath, { recursive: true });
|
|
97
99
|
}
|
|
98
|
-
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
fs.mkdirSync(sessionDir, { recursive: true });
|
|
104
|
-
}
|
|
105
|
-
const sessionFilePath = path.join(sessionDir, `${identityId}.json`);
|
|
100
|
+
const sessionFilePath = path.join(storagePath, `${userIdentity}.json`);
|
|
101
|
+
// Client ID (Device) - Fixed or Derived from Identity to keep session stable
|
|
102
|
+
// We can hash the userIdentity to get a stable UUID if needed,
|
|
103
|
+
// but for now reusing the static one or random is fine.
|
|
104
|
+
const clientId = '6bcbc4d1-5426-42f7-bc61-69cac2e229f4';
|
|
106
105
|
// Initialize Cookie Jar
|
|
107
106
|
const jar = new tough_cookie_1.CookieJar();
|
|
108
107
|
const client = (0, axios_cookiejar_support_1.wrapper)(axios_1.default.create({ jar }));
|
|
@@ -115,7 +114,6 @@ class MisaAmisLogin {
|
|
|
115
114
|
};
|
|
116
115
|
try {
|
|
117
116
|
// Step 1: Gen QR Code
|
|
118
|
-
// ... (Same logic as before) ...
|
|
119
117
|
const genQrPayload = {
|
|
120
118
|
clientId: clientId,
|
|
121
119
|
deviceId: clientId,
|
|
@@ -151,20 +149,7 @@ class MisaAmisLogin {
|
|
|
151
149
|
const pollUrl = `https://id.misa.vn/api/login-cross-device/v2/polling?cdRequestId=${cdRequestId}&clientId=${clientId}&deviceId=${clientId}`;
|
|
152
150
|
const pollRes = await client.get(pollUrl, { headers });
|
|
153
151
|
lastPollData = pollRes.data;
|
|
154
|
-
if (
|
|
155
|
-
// Assuming success if status changes or token present
|
|
156
|
-
if (pollRes.data.Token || pollRes.data.Success === true) {
|
|
157
|
-
pollingSuccess = true;
|
|
158
|
-
}
|
|
159
|
-
// If the API returns a Token/Code that needs a follow-up "Login" call, do it here.
|
|
160
|
-
// Based on user cURL, after polling success, there might be 'qrlogin' or 'startup'.
|
|
161
|
-
// Since we are using cookies (cookie jar), the polling response might already set some cookies?
|
|
162
|
-
// Or we might need to manually set the Token from pollRes into the jar?
|
|
163
|
-
// However, usually detailed auth flow requires more steps.
|
|
164
|
-
// For this version: We Save the JAR state.
|
|
165
|
-
}
|
|
166
|
-
// Workaround: Break if we see "Success"
|
|
167
|
-
if (JSON.stringify(pollRes.data).includes("Success") && JSON.stringify(pollRes.data).includes("true")) {
|
|
152
|
+
if (JSON.stringify(pollRes.data).includes("Success") || JSON.stringify(pollRes.data).includes("Token")) {
|
|
168
153
|
pollingSuccess = true;
|
|
169
154
|
}
|
|
170
155
|
}
|
|
@@ -173,14 +158,13 @@ class MisaAmisLogin {
|
|
|
173
158
|
}
|
|
174
159
|
}
|
|
175
160
|
if (pollingSuccess) {
|
|
176
|
-
// Save Cookies to File
|
|
177
161
|
const serializedJar = await jar.serialize();
|
|
178
162
|
fs.writeFileSync(sessionFilePath, JSON.stringify(serializedJar, null, 2));
|
|
179
163
|
}
|
|
180
164
|
returnData.push({
|
|
181
165
|
json: {
|
|
182
|
-
message: pollingSuccess ? "Login Successful
|
|
183
|
-
|
|
166
|
+
message: pollingSuccess ? "Login Successful" : "Timed out",
|
|
167
|
+
userIdentity: userIdentity,
|
|
184
168
|
sessionFile: sessionFilePath,
|
|
185
169
|
lastPollResult: lastPollData,
|
|
186
170
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-amis-v1",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "n8n node for AMIS v1",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"n8n-community-node-package"
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"dist/nodes/MisaAmisLogin/MisaAmisLogin.node.js"
|
|
13
13
|
],
|
|
14
14
|
"credentials": [
|
|
15
|
-
"dist/credentials/
|
|
15
|
+
"dist/credentials/MisaAmisApp.credentials.js",
|
|
16
|
+
"dist/credentials/MisaAmisUser.credentials.js"
|
|
16
17
|
]
|
|
17
18
|
},
|
|
18
19
|
"scripts": {
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
39
|
"axios": "^1.6.0",
|
|
39
|
-
"axios-cookiejar-support": "^
|
|
40
|
+
"axios-cookiejar-support": "^5.0.0",
|
|
40
41
|
"qrcode": "^1.5.3",
|
|
41
42
|
"tough-cookie": "^4.1.3"
|
|
42
43
|
},
|