zotero-plugin 5.0.19 → 5.0.20

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/release.js CHANGED
@@ -8382,7 +8382,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
8382
8382
  "package.json"(exports, module) {
8383
8383
  module.exports = {
8384
8384
  name: "zotero-plugin",
8385
- version: "5.0.19",
8385
+ version: "5.0.20",
8386
8386
  description: "Zotero plugin builder",
8387
8387
  homepage: "https://github.com/retorquere/zotero-plugin/wiki",
8388
8388
  bin: {
@@ -11984,9 +11984,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
11984
11984
  const link = `[${build}](https://github.com/${owner}/${repo}/releases/download/${release.data.tag_name}/${pkg.name}-${version_default}.xpi)`;
11985
11985
  if (!options.tag) {
11986
11986
  reason = ` (${JSON.stringify(ContinuousIntegration.commit_message)})`;
11987
- reason += `
11988
-
11989
- Please test this build and send a new log. Install in Zotero by downloading ${link}, opening the Zotero "Tools" menu, selecting "Add-ons", open the gear menu in the top right, and select "Install Add-on From File...".`;
11987
+ reason += [
11988
+ "",
11989
+ `Install in Zotero by downloading ${link}, opening the Zotero "Tools" menu, selecting "Add-ons", open the gear menu in the top right, and select "Install Add-on From File...".`,
11990
+ "Please test this build and report back whether it fixes the issue, and if not, what the remaining problem is. In the latter case, please also send a new log."
11991
+ ].join("\n\n");
11990
11992
  }
11991
11993
  const body = `:robot: this is your friendly neighborhood build bot announcing ${link}${reason}`;
11992
11994
  report(body);
package/debug-log.d.ts CHANGED
@@ -9,7 +9,7 @@ declare class DebugLogSender {
9
9
  private get zotero();
10
10
  convertLegacy(): void;
11
11
  private element;
12
- register(plugin: string, preferences?: string[]): void;
12
+ register(plugin: string, preferences?: string[], pem?: string): void;
13
13
  unregister(plugin: string): void;
14
14
  private alert;
15
15
  send(target: EventTarget): void;
@@ -17,6 +17,10 @@ declare class DebugLogSender {
17
17
  private preferences;
18
18
  private info;
19
19
  private rdf;
20
+ private publicKey;
21
+ private encrypt;
22
+ private arrayBufferToBase64;
23
+ private base64ToArrayBuffer;
20
24
  }
21
25
  export declare const DebugLog: DebugLogSender;
22
26
  export {};
package/debug-log.js CHANGED
@@ -55,7 +55,7 @@ class DebugLogSender {
55
55
  }
56
56
  return elt;
57
57
  }
58
- register(plugin, preferences = []) {
58
+ register(plugin, preferences = [], pem = '') {
59
59
  var _a, _b;
60
60
  this.convertLegacy();
61
61
  const label = 'Send debug log to bashupload.com';
@@ -75,6 +75,7 @@ class DebugLogSender {
75
75
  label: plugin,
76
76
  class: this.id.menuitem,
77
77
  'data-preferences': JSON.stringify(preferences || []),
78
+ 'data-pem': pem,
78
79
  }));
79
80
  menuitem.addEventListener('command', event => this.send(event.currentTarget));
80
81
  }
@@ -103,22 +104,30 @@ class DebugLogSender {
103
104
  const elt = target;
104
105
  const plugin = elt.getAttribute('label');
105
106
  const preferences = JSON.parse(elt.getAttribute('data-preferences'));
106
- this.sendAsync(plugin, preferences).catch((err) => {
107
+ const pem = elt.getAttribute('data-pem');
108
+ this.sendAsync(plugin, preferences, pem).catch((err) => {
107
109
  this.alert('Debug log submission error', `${err}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions
108
110
  });
109
111
  }
110
- async sendAsync(plugin, preferences) {
112
+ async sendAsync(plugin, preferences, pem) {
111
113
  await this.zotero.Schema.schemaUpdatePromise;
112
114
  const files = {};
113
115
  const enc = new TextEncoder();
114
116
  const key = this.zotero.Utilities.generateObjectKey();
115
- const log = [
117
+ let publicKey = pem ? await this.publicKey(pem) : null;
118
+ if (pem)
119
+ files[`${key}/pem.txt`] = enc.encode(pem);
120
+ let log = [
116
121
  await this.info(preferences),
117
122
  this.zotero.getErrors(true).join('\n\n'),
118
123
  this.zotero.Debug.getConsoleViewerOutput().slice(-250000).join('\n'), // eslint-disable-line no-magic-numbers
119
124
  ].filter((txt) => txt).join('\n\n').trim();
125
+ if (publicKey)
126
+ log = await this.encrypt(publicKey, log);
120
127
  files[`${key}/debug.txt`] = enc.encode(log);
121
- const rdf = await this.rdf();
128
+ let rdf = await this.rdf();
129
+ if (publicKey)
130
+ rdf = await this.encrypt(publicKey, rdf);
122
131
  if (rdf)
123
132
  files[`${key}/items.rdf`] = enc.encode(rdf);
124
133
  // do this runtime because Zotero is not defined at start for bootstrapped zoter6 plugins
@@ -210,5 +219,37 @@ class DebugLogSender {
210
219
  translation.translate(); // eslint-disable-line @typescript-eslint/no-unsafe-call
211
220
  });
212
221
  }
222
+ async publicKey(pem) {
223
+ const base64Key = pem
224
+ .replace('-----BEGIN PUBLIC KEY-----', '')
225
+ .replace('-----END PUBLIC KEY-----', '')
226
+ .replace(/\n/g, '');
227
+ const keyBuffer = this.base64ToArrayBuffer(base64Key);
228
+ return await crypto.subtle.importKey('spki', keyBuffer, { name: 'RSA-OAEP', hash: 'SHA-256' }, true, ['encrypt']);
229
+ }
230
+ async encrypt(publicKey, plaintext) {
231
+ const textEncoder = new TextEncoder();
232
+ const data = textEncoder.encode(plaintext);
233
+ const encrypted = await crypto.subtle.encrypt({ name: 'RSA-OAEP' }, publicKey, data);
234
+ return this.arrayBufferToBase64(encrypted);
235
+ }
236
+ arrayBufferToBase64(buffer) {
237
+ let binary = '';
238
+ const bytes = new Uint8Array(buffer);
239
+ const len = bytes.byteLength;
240
+ for (let i = 0; i < len; i++) {
241
+ binary += String.fromCharCode(bytes[i]);
242
+ }
243
+ return btoa(binary);
244
+ }
245
+ base64ToArrayBuffer(base64) {
246
+ const binaryString = atob(base64);
247
+ const len = binaryString.length;
248
+ const bytes = new Uint8Array(len);
249
+ for (let i = 0; i < len; i++) {
250
+ bytes[i] = binaryString.charCodeAt(i);
251
+ }
252
+ return bytes.buffer;
253
+ }
213
254
  }
214
255
  exports.DebugLog = new DebugLogSender();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zotero-plugin",
3
- "version": "5.0.19",
3
+ "version": "5.0.20",
4
4
  "description": "Zotero plugin builder",
5
5
  "homepage": "https://github.com/retorquere/zotero-plugin/wiki",
6
6
  "bin": {