{"id":13683675,"url":"https://github.com/1Password/op-js","last_synced_at":"2025-04-30T13:31:44.086Z","repository":{"id":37085862,"uuid":"481601189","full_name":"1Password/op-js","owner":"1Password","description":"A JS library powered by the 1Password CLI","archived":false,"fork":false,"pushed_at":"2024-09-12T02:12:20.000Z","size":1350,"stargazers_count":94,"open_issues_count":9,"forks_count":8,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-11-06T08:03:37.194Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://developer.1password.com/docs/cli","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/1Password.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-14T12:45:44.000Z","updated_at":"2024-10-22T15:57:47.000Z","dependencies_parsed_at":"2023-10-17T04:46:51.987Z","dependency_job_id":"4e1e44ce-6762-4411-8283-80ad6a90dd02","html_url":"https://github.com/1Password/op-js","commit_stats":{"total_commits":107,"total_committers":5,"mean_commits":21.4,"dds":"0.39252336448598135","last_synced_commit":"ddd224b4a5ea0987cdb00cc30e46317b027b57fa"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1Password%2Fop-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1Password%2Fop-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1Password%2Fop-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1Password%2Fop-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1Password","download_url":"https://codeload.github.com/1Password/op-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224212363,"owners_count":17274391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T13:02:22.246Z","updated_at":"2024-11-12T03:31:33.693Z","avatar_url":"https://github.com/1Password.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# op-js\n\nThis package is a simple JavaScript wrapper for the [1Password CLI](https://developer.1password.com/docs/cli). It provides methods for most of the CLI's [commands](https://developer.1password.com/docs/cli/reference), and in many cases extends the CLI's ability to authenticate using [biometrics](https://developer.1password.com/docs/cli/about-biometric-unlock) to whatever Node-based application you're building. It also includes TypeScript declarations.\n\n## Installation\n\nInstall using Yarn:\n\n```shell\nyarn add @1password/op-js\n```\n\nOr using NPM:\n\n```shell\nnpm install @1password/op-js\n```\n\n## Usage\n\nAfter installation you can start using command methods:\n\n```js\nimport { version, item, connect } from \"@1password/op-js\";\n\n// Some command functions may be directly imported\nversion();\n\n// But most exist on their parent command's object\nitem.get(\"x1oszeq62e2ys32v9a3l2sgcwly\");\n\n// And sub-commands are nested even further\nconnect.group.revoke({\n\tgroup: \"MyGroup\",\n\tallServers: true,\n});\n```\n\nThe CLI takes flags as `kebab-case`, however to align better with JS object convention all flags should be provided as `camelCase`.\n\n### Flags\n\nAll command methods support support [global command flags](https://developer.1password.com/docs/cli/reference#global-flags), as well as their own flags, but this package also provides a helper to set global command flags do you don't need to each time. For example:\n\n```js\nimport { setGlobalFlags } from \"@1password/op-js\";\n\nsetGlobalFlags({\n\taccount: \"example.1password.com\",\n});\n```\n\nNote that you should not try to set the `--format` flag as this is set under the hood to `json` for all commands that can return JSON format; it is otherwise a string response.\n\n### Validating the CLI\n\nSince this package depends on the 1Password CLI it's up to the user to install it, and the types may depend on a specific version. There is a function that your application can call to validate that the user has the CLI installed at a specific version:\n\n```js\nimport { validateCli } from \"@1password/op-js\";\n\nvalidateCli().catch((error) =\u003e {\n\tconsole.log(\"CLI is not valid:\", error.message);\n});\n\n// defaults to the recommended version, but you can supply a semver:\nvalidateCli(\"\u003e=2.3.1\").catch((error) =\u003e {\n\tconsole.log(\"CLI is not valid:\", error.message);\n});\n```\n\n### Authentication\n\nBy default `op-js` uses system authentication (e.g. biometrics), but it also supports automated authentication via [Connect Server](https://developer.1password.com/docs/connect) or [Service Account](https://developer.1password.com/docs/service-accounts).\n\n**Connect**\n\nIf you've got a Connect Server set up you can supply your host and token:\n\n```\nimport { setConnect } from \"@1password/op-js\";\n\nsetConnect(\"https://connect.myserver.com\", \"1kjhd9872hd981865s\");\n```\n\nAlternatively you can use environment variables when executing the code that uses `op-js`:\n\n```\nOP_CONNECT_HOST=https://connect.myserver.com\nOP_CONNECT_TOKEN=1kjhd9872hd981865s\n```\n\n**Service Account**\n\nIf you're using service accounts you can supply your token:\n\n```\nimport { setServiceAccount } from \"@1password/op-js\";\n\nsetServiceAccount(\"1kjhd9872hd981865s\");\n```\n\nAlternatively you can use environment variables when executing the code that uses `op-js`:\n\n```\nOP_SERVICE_ACCOUNT_TOKEN=1kjhd9872hd981865s\n```\n\n### Available commands and functions\n\nThere are roughly 70 commands available for use, so you're encouraged to check out the main [`index.ts`](./src/index.ts) file to get a better sense of what's available. Generally, though, here are the top-level commands/namespaces you can import:\n\n- `version` - Retrieve the current version of the CLI\n- `inject` - Inject secrets into a config file\n- `read` - Read a secret by secret references\n- `account` - Manage accounts\n- `document` - Manage documents in a vault\n- `eventsApi` - Create an Events API integration token\n- `connect` - Manage Connect groups, services, tokens, and vaults\n- `item` - Manage vault items and templates\n- `vault` - Manage account vaults\n- `user` - Manage account users\n- `group` - Manage groups and their users\n- `whoami` - Get details about the authenticated account\n\n## Contributing and feedback\n\n🐛 If you find an issue you'd like to report, or otherwise have feedback, please [file a new Issue](https://github.com/1Password/op-js/issues/new).\n\n🧑‍💻 If you'd like to contribute to the project please start by filing or commenting on an [Issue](https://github.com/1Password/op-js/issues) so we can track the work. Refer to the [Contributing doc](https://github.com/1Password/op-js/blob/main/CONTRIBUTING.md) for development setup instructions.\n\n💬 Share your feedback and connect with the Developer Products team in the [1Password Developers Slack](https://developer.1password.com/joinslack) workspace.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1Password%2Fop-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1Password%2Fop-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1Password%2Fop-js/lists"}