@jimmiewang/message-broker 0.0.3 → 0.0.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/bin/mb.js +25 -14
- package/package.json +1 -1
package/bin/mb.js
CHANGED
|
@@ -204,20 +204,31 @@ function cmdPoll() {
|
|
|
204
204
|
// poll cycles are never skipped.
|
|
205
205
|
for (const version of unseen) {
|
|
206
206
|
const spec = `${cfg.packageName}@${version}`;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
207
|
+
try {
|
|
208
|
+
withTempPack(spec, (tgz) => {
|
|
209
|
+
const envelope = extractFile(tgz, 'message.dat');
|
|
210
|
+
const { text, sentAt } = decrypt(key, envelope);
|
|
211
|
+
const record = {
|
|
212
|
+
version,
|
|
213
|
+
sentAt,
|
|
214
|
+
receivedAt: new Date().toISOString(),
|
|
215
|
+
text,
|
|
216
|
+
};
|
|
217
|
+
fs.appendFileSync(inboxPath(), JSON.stringify(record) + '\n', { mode: 0o600 });
|
|
218
|
+
writeState({ lastVersion: version });
|
|
219
|
+
console.log(`New message ${spec} (sent ${sentAt || 'unknown'}):`);
|
|
220
|
+
console.log(text);
|
|
221
|
+
});
|
|
222
|
+
} catch (err) {
|
|
223
|
+
// Registry metadata can expose a version before its tarball finishes
|
|
224
|
+
// propagating (ETARGET/E404 on npm pack). Keep the cursor at the last
|
|
225
|
+
// successfully processed version; the next poll cycle retries.
|
|
226
|
+
if (/ETARGET|E404|notarget|Not found/i.test(err.message)) {
|
|
227
|
+
console.warn(`Tarball for ${spec} not available yet, will retry next poll.`);
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
throw err;
|
|
231
|
+
}
|
|
221
232
|
}
|
|
222
233
|
}
|
|
223
234
|
|