Repository: electron/electron-packager (js)

Issue:
validateAuthorizationArgs doesn't work when using `keychain` and `keychainProfile`
The `validateAuthorizationArgs` check is now really the `validateLegacyAuthorizationArgs` check from the `electron-notarize` package.
https://github.com/electron/electron-packager/blob/bde6031985cc83d25ffd78532e1ce3baa88dd79d/src/mac.js#L419-L425

This means that using the keychain-profile method of authentication causes an error:

```
Packaging ApplicationWARNING: Failed validation, notarization will not run: No authentication properties provided (e.g. appleId, appleApiKey)
```

Forge -> Packager -> Notarizer config:

```
"osxNotarize": {
  "keychain": "~/Library/Keychains/login.keychain-db",
  "keychainProfile": "AC_PASSWORD"
},
```

Pull request description:
fix(mac): compatibility with electron-notarize@^1.1.0
* [x] I have read the [contribution documentation](https://github.com/electron/electron-packager/blob/main/CONTRIBUTING.md) for this project.
* [x] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project follows, as appropriate.
* [x] The changes have sufficient test coverage (if applicable).
* [x] The testsuite passes successfully on my local machine (if applicable).

**Summarize your changes:**

electron-notarize 1.1.0 added a new mode (using the new `notarytool` binary) which caused `validateAuthorizationArgs` to break.

Update notarization support so that the `tool: notarytool` option works with TypeScript.

Since the module handles its own validation, I'm removing it from this module.

Fixes #1277.

Patch:
diff --git a/.eslintrc.typescript.js b/.eslintrc.typescript.js
index c2025b9..f1b61df 100644
--- a/.eslintrc.typescript.js
+++ b/.eslintrc.typescript.js
@@ -5,7 +5,8 @@ eslintConfig.parser = '@typescript-eslint/parser'
 eslintConfig.parserOptions.sourceType = 'module'
 eslintConfig.extends.push(
   'plugin:@typescript-eslint/eslint-recommended',
-  'plugin:@typescript-eslint/recommended'
+  'plugin:@typescript-eslint/recommended',
+  'plugin:import/typescript'
 )
 
 eslintConfig.rules['comma-dangle'] = ['error', 'only-multiline']
diff --git a/package.json b/package.json
index 8559c8a..63af7a1 100644
--- a/package.json
+++ b/package.json
@@ -30,7 +30,7 @@
     "asar": "^3.0.0",
     "cross-spawn-windows-exe": "^1.2.0",
     "debug": "^4.0.1",
-    "electron-notarize": "^1.0.0",
+    "electron-notarize": "^1.1.1",
     "electron-osx-sign": "^0.5.0",
     "extract-zip": "^2.0.0",
     "filenamify": "^4.1.0",
diff --git a/src/index.d.ts b/src/index.d.ts
index 9a1c078..8d2f77f 100644
--- a/src/index.d.ts
+++ b/src/index.d.ts
@@ -10,9 +10,15 @@
 
 import { CreateOptions as AsarOptions } from 'asar';
 import { ElectronDownloadRequestOptions as ElectronDownloadOptions } from '@electron/get';
-import { NotarizeCredentials, TransporterOptions as NotarizeTransporterOptions } from 'electron-notarize';
+import {
+  LegacyNotarizeCredentials,
+  NotaryToolCredentials,
+  TransporterOptions
+} from 'electron-notarize/lib/types';
 import { SignOptions } from 'electron-osx-sign';
 
+type NotarizeLegacyOptions = LegacyNotarizeCredentials & TransporterOptions;
+
 /**
  * Bundles Electron-based application source code with a renamed/customized Electron executable and
  * its supporting files into folders ready for distribution.
@@ -118,7 +124,9 @@ declare namespace electronPackager {
    * See the documentation for [`electron-notarize`](https://npm.im/electron-notarize#method-notarizeopts-promisevoid)
    * for details.
    */
-  type OsxNotarizeOptions = NotarizeCredentials & NotarizeTransporterOptions;
+  type OsxNotarizeOptions =
+    | ({ tool?: 'legacy' } & NotarizeLegacyOptions)
+    | ({ tool: 'notarytool' } & NotaryToolCredentials);
 
   /**
    * Defines URL protocol schemes to be used on macOS.
diff --git a/src/mac.js b/src/mac.js
index ebc2510..d0baa03 100644
--- a/src/mac.js
+++ b/src/mac.js
@@ -6,7 +6,7 @@ const debug = require('debug')('electron-packager')
 const fs = require('fs-extra')
 const path = require('path')
 const plist = require('plist')
-const { notarize, validateAuthorizationArgs } = require('electron-notarize')
+const { notarize } = require('electron-notarize')
 const { signAsync } = require('electron-osx-sign')
 
 class MacApp extends App {
@@ -417,17 +417,12 @@ function createSignOpts (properties, platform, app, version, notarize, quiet) {
 }
 
 function createNotarizeOpts (properties, appBundleId, appPath, quiet) {
-  try {
-    validateAuthorizationArgs(properties)
-  } catch (e) {
-    common.warning(`Failed validation, notarization will not run: ${e.message}`)
-    return
-  }
-
   // osxNotarize options are handed off to the electron-notarize module, but with a few
   // additions from the main options. The user may think they can pass bundle ID or appPath,
   // but they will be ignored.
-  common.subOptionWarning(properties, 'osxNotarize', 'appBundleId', appBundleId, quiet)
+  if (properties.tool !== 'notarytool') {
+    common.subOptionWarning(properties, 'osxNotarize', 'appBundleId', appBundleId, quiet)
+  }
   common.subOptionWarning(properties, 'osxNotarize', 'appPath', appPath, quiet)
   return properties
 }


Test patch:
diff --git a/test/darwin.js b/test/darwin.js
index 0099301..c069293 100644
--- a/test/darwin.js
+++ b/test/darwin.js
@@ -298,11 +298,10 @@ if (!(process.env.CI && process.platform === 'win32')) {
     t.deepEqual(obj.CFBundleURLTypes, expected, 'CFBundleURLTypes did not contain specified protocol schemes and names')
   }))
 
-  test('osxNotarize: missing appleIdPassword', t => {
-    util.setupConsoleWarnSpy()
-    const notarizeOpts = mac.createNotarizeOpts({ appleId: '' })
-    t.falsy(notarizeOpts, 'does not generate options')
-    util.assertWarning(t, 'WARNING: Failed validation, notarization will not run: The appleId property is required when using notarization with appleIdPassword')
+  test('osxNotarize: appBundleId can be overwritten if tool = notarytool', t => {
+    const args = { appleId: '1', appleIdPassword: '2', appBundleId: 'overwritten', tool: 'notarytool' }
+    const notarizeOpts = mac.createNotarizeOpts(args, 'original', 'appPath', true)
+    t.is(notarizeOpts.appBundleId, 'overwritten', 'appBundleId is taken from user-supplied options')
   })
 
   test('osxNotarize: appBundleId not overwritten', t => {