n8n-nodes-amis-v1 0.1.6 → 0.1.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.
|
@@ -132,8 +132,9 @@ class MisaAmis {
|
|
|
132
132
|
// 1. Load Session
|
|
133
133
|
const credentials = await this.getCredentials('misaAmisUser');
|
|
134
134
|
const userIdentity = credentials.userIdentity;
|
|
135
|
+
const safeIdentity = userIdentity.replace(/[^a-z0-9]/gi, '_').toLowerCase();
|
|
135
136
|
const n8nDir = process.env.N8N_USER_FOLDER || path.join(os.homedir(), '.n8n');
|
|
136
|
-
const sessionFilePath = path.join(n8nDir, 'misa_sessions', `${
|
|
137
|
+
const sessionFilePath = path.join(n8nDir, 'misa_sessions', `${safeIdentity}.json`);
|
|
137
138
|
if (!fs.existsSync(sessionFilePath)) {
|
|
138
139
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Session file not found for user: ${userIdentity}. Please run Login Node first.`);
|
|
139
140
|
}
|
|
@@ -108,14 +108,20 @@ class MisaAmisLogin {
|
|
|
108
108
|
const returnData = [];
|
|
109
109
|
const operation = this.getNodeParameter('operation', 0);
|
|
110
110
|
const userIdentity = this.getNodeParameter('userIdentity', 0);
|
|
111
|
+
const safeIdentity = userIdentity.replace(/[^a-z0-9]/gi, '_').toLowerCase();
|
|
111
112
|
const n8nDir = process.env.N8N_USER_FOLDER || path.join(os.homedir(), '.n8n');
|
|
112
113
|
const storagePath = path.join(n8nDir, 'misa_sessions');
|
|
113
|
-
|
|
114
|
-
fs.
|
|
114
|
+
try {
|
|
115
|
+
if (!fs.existsSync(storagePath)) {
|
|
116
|
+
fs.mkdirSync(storagePath, { recursive: true });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to create storage directory '${storagePath}': ${error.message}. Please check permissions.`);
|
|
115
121
|
}
|
|
116
122
|
// File paths
|
|
117
|
-
const sessionFilePath = path.join(storagePath, `${
|
|
118
|
-
const pendingFilePath = path.join(storagePath, `${
|
|
123
|
+
const sessionFilePath = path.join(storagePath, `${safeIdentity}.json`);
|
|
124
|
+
const pendingFilePath = path.join(storagePath, `${safeIdentity}.pending.json`);
|
|
119
125
|
const clientId = '6bcbc4d1-5426-42f7-bc61-69cac2e229f4';
|
|
120
126
|
const headers = {
|
|
121
127
|
'Content-Type': 'application/json',
|
|
@@ -174,7 +180,9 @@ class MisaAmisLogin {
|
|
|
174
180
|
// --- Operation: Check Login ---
|
|
175
181
|
// READ PENDING STATE
|
|
176
182
|
if (!fs.existsSync(pendingFilePath)) {
|
|
177
|
-
|
|
183
|
+
const allFiles = fs.readdirSync(storagePath);
|
|
184
|
+
const pendingFiles = allFiles.filter(f => f.endsWith('.pending.json'));
|
|
185
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `No pending login found for user '${userIdentity}'. Path: ${pendingFilePath}. Available pending sessions: ${pendingFiles.join(', ')}`);
|
|
178
186
|
}
|
|
179
187
|
const pendingState = JSON.parse(fs.readFileSync(pendingFilePath, 'utf8'));
|
|
180
188
|
const cdRequestId = pendingState.requestId;
|
|
@@ -188,6 +196,7 @@ class MisaAmisLogin {
|
|
|
188
196
|
}
|
|
189
197
|
let pollingSuccess = false;
|
|
190
198
|
let attempts = 0;
|
|
199
|
+
let lastResponseData = null;
|
|
191
200
|
const maxAttempts = 60; // 2 minutes
|
|
192
201
|
while (!pollingSuccess && attempts < maxAttempts) {
|
|
193
202
|
attempts++;
|
|
@@ -196,6 +205,7 @@ class MisaAmisLogin {
|
|
|
196
205
|
const pollUrl = `https://id.misa.vn/api/login-cross-device/v2/polling?cdRequestId=${cdRequestId}&clientId=${clientId}&deviceId=${clientId}`;
|
|
197
206
|
console.log(`[MISA Debug] Polling Attempt ${attempts}: ${pollUrl}`);
|
|
198
207
|
const pollRes = await client.get(pollUrl, { headers });
|
|
208
|
+
lastResponseData = pollRes.data;
|
|
199
209
|
if (JSON.stringify(pollRes.data).includes("Success") || JSON.stringify(pollRes.data).includes("v1/auth/token")) {
|
|
200
210
|
pollingSuccess = true;
|
|
201
211
|
}
|
|
@@ -224,7 +234,8 @@ class MisaAmisLogin {
|
|
|
224
234
|
});
|
|
225
235
|
}
|
|
226
236
|
else {
|
|
227
|
-
|
|
237
|
+
// Timeout
|
|
238
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Login timeout. Last Polling Status: ${lastResponseData ? JSON.stringify(lastResponseData) : 'No response'}. Please scan QR Code again.`);
|
|
228
239
|
}
|
|
229
240
|
}
|
|
230
241
|
}
|