diff --git a/dist/app.js b/dist/app.js index 298e2cf..415beb9 100644 --- a/dist/app.js +++ b/dist/app.js @@ -22,23 +22,58 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +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; + 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."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -const op_js_1 = require("@1password/op-js"); -const cache = __importStar(require("./cache")); -const path_1 = __importDefault(require("path")); -const fs_1 = __importDefault(require("fs")); -const lodash_1 = require("lodash"); -const OP_PLUGIN_CONFIG_KEY = '__op_plugin'; -const debouncedFetchEntry = (0, lodash_1.debounce)(fetchEntry, 500); -const fetchSecretTemplateTag = { +exports.templateTags = void 0; +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 fetchSecretTemplateTag = { name: 'op', displayName: '1Password => Fetch Secret', - liveDisplayName: (args) => { + liveDisplayName: function (args) { var _a, _b; - return `1Password => ${(_b = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '--'}`; + return "1Password => ".concat((_b = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '--'); }, description: 'Fetch a secret from your 1Password vault', args: [ @@ -50,44 +85,73 @@ const fetchSecretTemplateTag = { placeholder: "e.g. 'op://team-name.1password.com/vault-name/item-name'", }, ], - async run(context, reference) { - const config = context.context[OP_PLUGIN_CONFIG_KEY]; - await checkCli(config === null || config === void 0 ? void 0 : config.cliPath); - const entry = await debouncedFetchEntry(reference); - return entry; + run: function (context, reference) { + return __awaiter(this, void 0, void 0, function () { + var config, entry; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + config = context.context[OP_PLUGIN_CONFIG_KEY]; + return [4, checkCli(config === null || config === void 0 ? void 0 : config.cliPath)]; + case 1: + _a.sent(); + return [4, fetchEntry(reference)]; + case 2: + entry = _a.sent(); + return [2, entry]; + } + }); + }); }, }; -async function checkCli(cliPath) { - if (cache.opCliInstalled() !== true) { - try { - if (cliPath && !fs_1.default.existsSync(cliPath)) { - throw new Error(`The file at path ${cliPath} does not exist.`); +function checkCli(cliPath) { + return __awaiter(this, void 0, void 0, function () { + var pathToAdd, stats, e_1, error; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(cache.opCliInstalled() !== true)) return [3, 4]; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + if (cliPath && !fs_1.default.existsSync(cliPath)) { + throw new Error("The file at path ".concat(cliPath, " does not exist.")); + } + pathToAdd = cliPath; + if (cliPath) { + stats = fs_1.default.statSync(cliPath); + if (stats.isFile()) { + pathToAdd = path_1.default.dirname(cliPath); + } + } + process.env.PATH = pathToAdd ? "".concat(pathToAdd, ":").concat(process.env.PATH) : process.env.PATH; + return [4, (0, op_js_1.validateCli)()]; + case 2: + _a.sent(); + cache.writeOpCliInstalled(true); + return [3, 4]; + case 3: + e_1 = _a.sent(); + error = new Error("There was an issue with the 1Password CLI. If you have the op CLI installed using e.g. Homebrew, please set the '__op_plugin.cliPath' environment variable to the directory containing the 'op' binary. (e.g. /opt/homebrew/bin/op). Error details: ".concat(e_1.message)); + error.stack = e_1.stack; + throw error; + case 4: return [2]; } - let pathToAdd = cliPath; - if (cliPath) { - const stats = fs_1.default.statSync(cliPath); - if (stats.isFile()) { - pathToAdd = path_1.default.dirname(cliPath); - } - } - process.env.PATH = pathToAdd ? `${pathToAdd}:${process.env.PATH}` : process.env.PATH; - await (0, op_js_1.validateCli)(); - cache.writeOpCliInstalled(true); - } - catch (e) { - const error = new Error(`There was an issue with the 1Password CLI. If you have the op CLI installed using e.g. Homebrew, please set the '__op_plugin.cliPath' environment variable to the directory containing the 'op' binary. (e.g. /opt/homebrew/bin/op). Error details: ${e.message}`); - error.stack = e.stack; - throw error; - } - } + }); + }); } -async function fetchEntry(ref) { - const existing = cache.getEntry(ref); - if (existing) { - return existing; - } - const entry = op_js_1.read.parse(ref); - cache.writeEntry(ref, entry); - return entry; +function fetchEntry(ref) { + return __awaiter(this, void 0, void 0, function () { + var existing, entry; + return __generator(this, function (_a) { + existing = cache.getEntry(ref); + if (existing) { + return [2, existing]; + } + entry = op_js_1.read.parse(ref); + cache.writeEntry(ref, entry); + return [2, entry]; + }); + }); } -module.exports.templateTags = [fetchSecretTemplateTag]; +exports.templateTags = [fetchSecretTemplateTag]; diff --git a/dist/cache.js b/dist/cache.js index 52ff705..627705d 100644 --- a/dist/cache.js +++ b/dist/cache.js @@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeOpCliInstalled = exports.opCliInstalled = exports.getEntry = exports.writeEntry = void 0; -const node_cache_1 = __importDefault(require("node-cache")); -const cache = new node_cache_1.default({ stdTTL: 60 * 60 }); +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); } diff --git a/package.json b/package.json index 70bf88e..e2f9eec 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,19 @@ { "name": "insomnia-plugin-op", - "version": "0.1.1", + "version": "0.1.2", "description": "Insomnia Plugin to integrate with 1Password CLI (op)", "main": "./dist/app.js", + "type": "commonjs", "scripts": { "build": "tsc", "dev": "tsc -w", "test": "echo \"Error: no test specified\" && exit 1" }, - "keywords": ["insomnia", "insomnia plugin", "1password"], + "keywords": [ + "insomnia", + "insomnia plugin", + "1password" + ], "author": { "name": "Benjamin von Polheim", "email": "hi@benvp.co", @@ -19,7 +24,7 @@ "url": "https://github.com/benvp/insomnia-plugin-op/issues" }, "license": "MIT", - "homepage": "https://github.com/benvp/insomnia-plugin-op", + "homepage": "https://github.com/benvp/insomnia-pluggpin-op", "repository": { "type": "git", "url": "https://github.com/benvp/insomnia-plugin-op" @@ -39,7 +44,6 @@ "unlisted": false }, "devDependencies": { - "@types/lodash": "^4.14.202", "@types/node": "^20.11.5", "@typescript-eslint/eslint-plugin": "^6.19.1", "@typescript-eslint/parser": "^6.19.1", @@ -51,7 +55,6 @@ }, "dependencies": { "@1password/op-js": "^0.1.11", - "lodash": "^4.17.21", "node-cache": "^5.1.2" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9375734..ee0efd5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,17 +8,11 @@ dependencies: '@1password/op-js': specifier: ^0.1.11 version: 0.1.11 - lodash: - specifier: ^4.17.21 - version: 4.17.21 node-cache: specifier: ^5.1.2 version: 5.1.2 devDependencies: - '@types/lodash': - specifier: ^4.14.202 - version: 4.14.202 '@types/node': specifier: ^20.11.5 version: 20.11.5 @@ -145,10 +139,6 @@ packages: resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} dev: true - /@types/lodash@4.14.202: - resolution: {integrity: sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==} - dev: true - /@types/node@20.11.5: resolution: {integrity: sha512-g557vgQjUUfN76MZAN/dt1z3dzcUsimuysco0KeluHgrPdJXkP/XdAURgyO2W9fZWHRtRBiVKzKn8vyOAwlG+w==} dependencies: @@ -787,10 +777,6 @@ packages: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} dev: true - /lodash@4.17.21: - resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} - dev: false - /lookpath@1.2.2: resolution: {integrity: sha512-k2Gmn8iV6qdME3ztZC2spubmQISimFOPLuQKiPaLcVdRz0IpdxrNClVepMlyTJlhodm/zG/VfbkWERm3kUIh+Q==} engines: {npm: '>=6.13.4'} diff --git a/src/app.ts b/src/app.ts index abb54aa..3e4bec9 100644 --- a/src/app.ts +++ b/src/app.ts @@ -2,7 +2,6 @@ import { validateCli, read } from '@1password/op-js'; import * as cache from './cache'; import path from 'path'; import fs from 'fs'; -import { debounce } from 'lodash'; type PluginConfig = { cliPath?: string; @@ -10,8 +9,6 @@ type PluginConfig = { const OP_PLUGIN_CONFIG_KEY = '__op_plugin'; -const debouncedFetchEntry = debounce(fetchEntry, 500); - const fetchSecretTemplateTag = { name: 'op', displayName: '1Password => Fetch Secret', @@ -32,7 +29,7 @@ const fetchSecretTemplateTag = { const config = context.context[OP_PLUGIN_CONFIG_KEY] as PluginConfig | undefined; await checkCli(config?.cliPath); - const entry = await debouncedFetchEntry(reference); + const entry = await fetchEntry(reference); return entry; }, @@ -84,4 +81,4 @@ async function fetchEntry(ref: string) { return entry; } -module.exports.templateTags = [fetchSecretTemplateTag]; +export const templateTags = [fetchSecretTemplateTag]; diff --git a/tsconfig.json b/tsconfig.json index a782097..ca57502 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,6 @@ "compilerOptions": { "baseUrl": ".", "outDir": "dist", - "target": "ES2017", "lib": ["esnext"], "strict": true, "forceConsistentCasingInFileNames": true, @@ -12,7 +11,7 @@ "moduleResolution": "node", "isolatedModules": true, "noUnusedLocals": false, - "removeComments": true + "removeComments": true, }, "exclude": ["node_modules"], "include": ["src/**/*"]