From 721432025589720f51c56ad4bd75fe32134f0079 Mon Sep 17 00:00:00 2001 From: Benjamin von Polheim Date: Thu, 24 Oct 2024 22:22:39 +0200 Subject: [PATCH] v0.2.0 --- .prettierrc.json | 6 ++++++ CHANGELOG.md | 8 ++++++++ dist/app.js | 36 ++++++++++++++++++++---------------- dist/cache.js | 9 +++++---- package.json | 1 + pnpm-lock.yaml | 28 +++++++++++++++++++++++----- src/app.ts | 7 +++++-- 7 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 .prettierrc.json create mode 100644 CHANGELOG.md diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..2706279 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "singleQuote": true, + "trailingComma": "all", + "printWidth": 100, + "arrowParens": "avoid" +} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..128dfe6 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Changelog + +## 0.2.0 (2024-10-24) + +### Enhancements + * Support passing flags to op-cli via `flags` configuration key. + * Add an argument to specify an account when fetching a secret. + * Allow setting up a default account in config. diff --git a/dist/app.js b/dist/app.js index 5cde941..166165e 100644 --- a/dist/app.js +++ b/dist/app.js @@ -32,8 +32,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); - return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); @@ -67,28 +67,29 @@ var op_js_1 = require("@1password/op-js"); var cache = __importStar(require("./cache")); var path_1 = __importDefault(require("path")); var fs_1 = __importDefault(require("fs")); -var OP_PLUGIN_CONFIG_KEY = '__op_plugin'; +var OP_PLUGIN_CONFIG_KEY = "__op_plugin"; var fetchSecretTemplateTag = { - name: 'op', - displayName: '1Password => Fetch Secret', + name: "op", + displayName: "1Password => Fetch Secret", liveDisplayName: function (args) { var _a, _b, _c; - return "1Password => ".concat((_b = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '--', " {").concat(((_c = args[1]) === null || _c === void 0 ? void 0 : _c.value) ? (args[1].value) : '', "}"); + console.log(args); + return "1Password => ".concat((_b = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "--").concat(((_c = args[1]) === null || _c === void 0 ? void 0 : _c.value) ? " (".concat(args[1].value, ")") : ""); }, - description: 'Fetch a secret from your 1Password vault', + description: "Fetch a secret from your 1Password vault", args: [ { - displayName: 'Reference', - description: '1Password item reference (op://...)', - type: 'string', - defaultValue: '', + displayName: "Reference", + description: "1Password item reference (op://...)", + type: "string", + defaultValue: "", placeholder: "e.g. 'op://vault-name/item-name/section/field'", }, { - displayName: 'Account', - description: '1Password account name', - type: 'string', - defaultValue: '', + displayName: "Account", + description: "1Password account name", + type: "string", + defaultValue: "", placeholder: "e.g. 'team-name.1password.com'", }, ], @@ -99,6 +100,7 @@ var fetchSecretTemplateTag = { switch (_a.label) { case 0: config = context.context[OP_PLUGIN_CONFIG_KEY]; + console.log(context, reference, account); if (config === null || config === void 0 ? void 0 : config.flags) { (0, op_js_1.setGlobalFlags)(config.flags); } @@ -134,7 +136,9 @@ function checkCli(cliPath) { pathToAdd = path_1.default.dirname(cliPath); } } - process.env.PATH = pathToAdd ? "".concat(pathToAdd, ":").concat(process.env.PATH) : process.env.PATH; + process.env.PATH = pathToAdd + ? "".concat(pathToAdd, ":").concat(process.env.PATH) + : process.env.PATH; return [4, (0, op_js_1.validateCli)()]; case 2: _a.sent(); diff --git a/dist/cache.js b/dist/cache.js index 9e5de0e..627705d 100644 --- a/dist/cache.js +++ b/dist/cache.js @@ -3,21 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.writeEntry = writeEntry; -exports.getEntry = getEntry; -exports.opCliInstalled = opCliInstalled; -exports.writeOpCliInstalled = writeOpCliInstalled; +exports.writeOpCliInstalled = exports.opCliInstalled = exports.getEntry = exports.writeEntry = void 0; var node_cache_1 = __importDefault(require("node-cache")); var cache = new node_cache_1.default({ stdTTL: 60 * 60 }); function writeEntry(ref, value) { return cache.set(ref, value); } +exports.writeEntry = writeEntry; function getEntry(ref) { return cache.get(ref); } +exports.getEntry = getEntry; function opCliInstalled() { return cache.get('opCliInstalled'); } +exports.opCliInstalled = opCliInstalled; function writeOpCliInstalled(installed) { return cache.set('opCliInstalled', installed); } +exports.writeOpCliInstalled = writeOpCliInstalled; diff --git a/package.json b/package.json index 7d393f7..18582d9 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", + "eslint-plugin-react-hooks": "^5.0.0", "prettier": "^3.2.4", "typescript": "^5.3.3" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0b7461f..1ee89ad 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,7 +20,7 @@ importers: version: 20.11.5 '@typescript-eslint/eslint-plugin': specifier: ^6.19.1 - version: 6.19.1(@typescript-eslint/parser@6.19.1)(eslint@8.56.0)(typescript@5.3.3) + version: 6.19.1(@typescript-eslint/parser@6.19.1(eslint@8.56.0)(typescript@5.3.3))(eslint@8.56.0)(typescript@5.3.3) '@typescript-eslint/parser': specifier: ^6.19.1 version: 6.19.1(eslint@8.56.0)(typescript@5.3.3) @@ -32,7 +32,10 @@ importers: version: 9.1.0(eslint@8.56.0) eslint-plugin-prettier: specifier: ^5.1.3 - version: 5.1.3(eslint-config-prettier@9.1.0)(eslint@8.56.0)(prettier@3.2.4) + version: 5.1.3(eslint-config-prettier@9.1.0(eslint@8.56.0))(eslint@8.56.0)(prettier@3.2.4) + eslint-plugin-react-hooks: + specifier: ^5.0.0 + version: 5.0.0(eslint@8.56.0) prettier: specifier: ^3.2.4 version: 3.2.4 @@ -275,6 +278,12 @@ packages: eslint-config-prettier: optional: true + eslint-plugin-react-hooks@5.0.0: + resolution: {integrity: sha512-hIOwI+5hYGpJEc4uPRmz2ulCjAGD/N13Lukkh8cLV0i2IRk/bdZDYjgLVHj+U9Z704kLIdIO6iueGvxNur0sgw==} + engines: {node: '>=10'} + peerDependencies: + eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0 + eslint-scope@7.2.2: resolution: {integrity: sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -696,7 +705,7 @@ snapshots: '@types/semver@7.5.6': {} - '@typescript-eslint/eslint-plugin@6.19.1(@typescript-eslint/parser@6.19.1)(eslint@8.56.0)(typescript@5.3.3)': + '@typescript-eslint/eslint-plugin@6.19.1(@typescript-eslint/parser@6.19.1(eslint@8.56.0)(typescript@5.3.3))(eslint@8.56.0)(typescript@5.3.3)': dependencies: '@eslint-community/regexpp': 4.10.0 '@typescript-eslint/parser': 6.19.1(eslint@8.56.0)(typescript@5.3.3) @@ -711,6 +720,7 @@ snapshots: natural-compare: 1.4.0 semver: 7.5.4 ts-api-utils: 1.0.3(typescript@5.3.3) + optionalDependencies: typescript: 5.3.3 transitivePeerDependencies: - supports-color @@ -723,6 +733,7 @@ snapshots: '@typescript-eslint/visitor-keys': 6.19.1 debug: 4.3.4 eslint: 8.56.0 + optionalDependencies: typescript: 5.3.3 transitivePeerDependencies: - supports-color @@ -739,6 +750,7 @@ snapshots: debug: 4.3.4 eslint: 8.56.0 ts-api-utils: 1.0.3(typescript@5.3.3) + optionalDependencies: typescript: 5.3.3 transitivePeerDependencies: - supports-color @@ -755,6 +767,7 @@ snapshots: minimatch: 9.0.3 semver: 7.5.4 ts-api-utils: 1.0.3(typescript@5.3.3) + optionalDependencies: typescript: 5.3.3 transitivePeerDependencies: - supports-color @@ -861,13 +874,18 @@ snapshots: dependencies: eslint: 8.56.0 - eslint-plugin-prettier@5.1.3(eslint-config-prettier@9.1.0)(eslint@8.56.0)(prettier@3.2.4): + eslint-plugin-prettier@5.1.3(eslint-config-prettier@9.1.0(eslint@8.56.0))(eslint@8.56.0)(prettier@3.2.4): dependencies: eslint: 8.56.0 - eslint-config-prettier: 9.1.0(eslint@8.56.0) prettier: 3.2.4 prettier-linter-helpers: 1.0.0 synckit: 0.8.8 + optionalDependencies: + eslint-config-prettier: 9.1.0(eslint@8.56.0) + + eslint-plugin-react-hooks@5.0.0(eslint@8.56.0): + dependencies: + eslint: 8.56.0 eslint-scope@7.2.2: dependencies: diff --git a/src/app.ts b/src/app.ts index bf96072..cf850c4 100644 --- a/src/app.ts +++ b/src/app.ts @@ -15,7 +15,8 @@ const fetchSecretTemplateTag = { name: 'op', displayName: '1Password => Fetch Secret', liveDisplayName: (args: any[]) => { - return `1Password => ${args[0]?.value ?? '--'} {${args[1]?.value ? (args[1].value) : ''}}`; + console.log(args); + return `1Password => ${args[0]?.value ?? '--'}${args[1]?.value ? ` (${args[1].value})` : ''}`; }, description: 'Fetch a secret from your 1Password vault', args: [ @@ -37,6 +38,8 @@ const fetchSecretTemplateTag = { async run(context: any, reference: string, account: string) { const config = context.context[OP_PLUGIN_CONFIG_KEY] as PluginConfig | undefined; + console.log(context, reference, account); + if (config?.flags) { setGlobalFlags(config.flags); } @@ -90,7 +93,7 @@ async function fetchEntry(ref: string, account: string) { const args: Partial = {}; - if ( account ) { + if (account) { args.account = account; }