Observed since 20 Oct, 18:35 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
1password-config
1Password configuration utilities
A secure Node.js toolkit for retrieving configurations from 1Password.
# Install
npm install 1password-config
# Create a configuration item in 1Password, then:
import { getConfig } from '1password-config';
// Example: Alibaba Cloud OSS Configuration
const ossConfig = await getConfig('your-1password-item-uuid-or-name', {
region: 'OSS region configuration',
access_key_id: {
key: 'username',
description: 'OSS Access Key ID'
},
access_key_secret: {
key: 'credential',
description: 'OSS Access Key Secret'
},
bucket: {
description: 'Storage bucket name'
},
host: {
description: 'OSS service host'
}
});
// Use directly - it's that simple!
console.log('Region:', ossConfig.region);
console.log('Access Key:', ossConfig.access_key_id);
// Simple format (default)
function getConfig<T extends ConfigMap>(
idOrName: string,
keyOptions: T,
options?: { detailedResult?: false }
): Promise<{ [K in keyof T]: string | undefined }>
// Detailed format
function getConfig<T extends ConfigMap>(
idOrName: string,
keyOptions: T,
options: { detailedResult: true }
): Promise<{ [K in keyof T]: ConfigResult }>
idOrName: stringThe name or UUID of the 1Password item.
keyOptions: ConfigMapConfiguration field mapping object. Supports two formats:
1. String value format:
{
username: 'User name description'
}
2. Object value format:
{
access_key: {
key: 'username', // Field name in 1Password (optional, defaults to key name)
default: 'default_value', // Default value (optional)
description: 'Access key' // Description (optional)
}
}
options?: GetConfigOptionsConfiguration options object:
detailedResult?: boolean - Whether to return detailed format, default falseReturns an object with configuration values:
{
region: "oss-cn-shanghai",
access_key_id: "DSAI5aOitshaSH6PsagdLtms",
bucket: "my-bucket"
}
Returns an object with complete information for each field:
{
region: {
value: "oss-cn-shanghai",
matched: true,
description: "OSS region configuration"
},
access_key_id: {
value: "DSAI5aOitshaSH6PsagdLtms",
matched: true,
description: "OSS Access Key ID"
},
backup_key: {
value: "default-backup-key",
matched: false,
description: "Backup key"
}
}
type ConfigResult = {
value: string | undefined; // Field value
matched: boolean; // Whether found in 1Password
description?: string; // Description
}
Most common usage - directly get configuration values:
const config = await getConfig('my-oss-config', {
region: 'OSS region',
access_key_id: {
key: 'username',
default: 'dev-key'
},
bucket: { default: 'dev-bucket' }
});
// Use directly
const ossClient = new OSS({
region: config.region,
accessKeyId: config.access_key_id,
bucket: config.bucket
});
When 1Password field names differ from your desired names:
const config = await getConfig('oss-credentials', {
accessKey: {
key: 'username', // Maps to 'username' field in 1Password
description: 'Access key'
},
secretKey: {
key: 'credential', // Maps to 'credential' field in 1Password
default: 'dev-secret' // Development environment default
}
});
When you need to know if configuration was actually retrieved from 1Password:
const config = await getConfig('my-config', {
database_url: 'Database connection string',
api_key: { default: 'dev-key' }
}, { detailedResult: true }); // Enable detailed mode
// Check configuration status
console.log('Database URL:', config.database_url.value);
console.log('From 1Password:', config.database_url.matched ? 'Yes' : 'No');
if (!config.api_key.matched) {
console.warn('⚠️ API key using default value, please configure in 1Password');
}
username - Your access key IDcredential - Your access key secretregion - OSS region (e.g., oss-cn-shanghai)bucket - Bucket namehost - OSS endpoint URLcdn_host - CDN URLThen in your code:
const config = await getConfig('My OSS Config', {
region: 'OSS region',
access_key_id: {
key: 'username',
description: 'OSS Access Key ID'
},
access_key_secret: {
key: 'credential',
description: 'OSS Access Key Secret'
},
bucket: 'Storage bucket',
host: 'OSS endpoint',
cdn_host: 'CDN endpoint'
});
// Use different configurations for different environments
const itemName = process.env.NODE_ENV === 'production'
? 'Production OSS Config'
: 'Development OSS Config';
const config = await getConfig(itemName, {
region: 'OSS region',
access_key_id: { key: 'username' },
access_key_secret: { key: 'credential' },
bucket: { default: 'dev-bucket' }
});
if (process.env.NODE_ENV === 'production') {
const config = await getConfig('Production Config', {
database_url: 'Database URL',
jwt_secret: 'JWT Secret',
oss_key: 'OSS Access Key'
}, { detailedResult: true });
// Ensure critical configurations are set
const missing = Object.entries(config)
.filter(([, cfg]) => !cfg.matched)
.map(([key]) => key);
if (missing.length > 0) {
throw new Error(`Missing production configurations: ${missing.join(', ')}`);
}
}
Q: Item not found error?
op item list to viewQ: Field not retrieving?
Q: Need to re-login?
op signin to re-authenticatenpm run exampleMIT
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
@1password/op-jsEnvironment{
"local_name": "@1password/op-js",
"alias": false,
"peer_metadata": null
} | 0.1.13 | runtime |
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | ^20.0.0 | development |
tsxEnvironment{
"local_name": "tsx",
"alias": false,
"peer_metadata": null
} | ^4.0.0 | development |
typescriptEnvironment{
"local_name": "typescript",
"alias": false,
"peer_metadata": null
} | ^5.0.0 | development |
Source distribution
{
"integrity": "sha512-lasdUese4CMms7P0LG8XNdp53JQyHM8XFHH+CgtbpubmJraH+TvLhk9/99j1zc3PwNB7xGnK7mLGaQUw7a935g==",
"shasum": "69fbba8ec0c801c6b76a1310af52385f61557869",
"tarball": "https://registry.npmjs.org/1password-config/-/1password-config-1.0.0.tgz",
"fileCount": 7,
"unpackedSize": 16693,
"signatures": [
{
"keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U",
"sig": "MEYCIQDWTN06gDq/TfwbkvHKL+brEkBKyeU6lMhZLGLkGdCU8gIhAMdXyktEhZAbmBZDPC+cuYUtD6A6j1X3UNFrFGyrxGQW"
}
]
}Shared repository data · GitHub
Observed since 20 Oct, 18:35 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:6e29a495f3c2435f636901d7173a19651f81a6bb7c19eec0bf9c8f209b06b1ab