Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize example code comments #103

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function fetchSecret() {
// Creates an authenticated client.
const client = await sdk.createClient({
auth: process.env.OP_SERVICE_ACCOUNT_TOKEN,
// Set the following to your own integration name and version.
// TODO: Set the following to your own integration name and version.
integrationName: "My 1Password Integration",
integrationVersion: "v1.0.0",
});
Expand All @@ -32,7 +32,7 @@ async function manageItems() {
}
}

// Create an item
// Creates an item with a username, password, one-time password, autofill website, and tags.
let item = await client.items.create({
title: "My Item",
category: sdk.ItemCategory.Login,
Expand Down Expand Up @@ -75,7 +75,7 @@ async function manageItems() {
],
});

// Get a one-time password code.
// Gets a one-time password code from an item.
let element = item.fields.find((element) => {
return element.fieldType == sdk.ItemFieldType.Totp;
});
Expand All @@ -96,7 +96,7 @@ async function manageItems() {
default:
}

// Edit an item (change the password)
// Updates an item by changing its password.
let newItem = {
...item,
fields: item.fields.map((f) => {
Expand All @@ -110,7 +110,7 @@ async function manageItems() {
let updatedItem = await client.items.put(newItem);
console.log(updatedItem.fields);

// Delete an item
// Deletes an item.
await client.items.delete(item.vaultId, item.id);
}

Expand Down
17 changes: 10 additions & 7 deletions examples/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,36 @@ import sdk from "@1password/sdk";
// Creates an authenticated client.
const client = await sdk.createClient({
auth: process.env.OP_SERVICE_ACCOUNT_TOKEN,
// Set the following to your own integration name and version.
// TODO: Set the following to your own integration name and version.
integrationName: "My 1Password Integration",
integrationVersion: "v1.0.0",
});
// [developer-docs.sdk.js.client-initialization]-end

// [developer-docs.sdk.js.list-vaults]-start
// Lists all vaults in an account.
const vaults = await client.vaults.listAll();
for await (const vault of vaults) {
console.log(vault.id + " " + vault.title);
}
// [developer-docs.sdk.js.list-vaults]-end

// [developer-docs.sdk.js.list-items]-start
// Lists all items in a vault.
const items = await client.items.listAll("7turaasywpymt3jecxoxk5roli");
for await (const item of items) {
console.log(item.id + " " + item.title);
}
// [developer-docs.sdk.js.list-items]-end

// [developer-docs.sdk.js.resolve-secret]-start
// Fetches a secret.
// Fetches the value of a field in 1Password using a secret reference.
const secret = await client.secrets.resolve("op://vault/item/field");
console.log(secret);
// [developer-docs.sdk.js.resolve-secret]-end

// [developer-docs.sdk.js.create-item]-start
// Creates an item
// Creates an item with a username, password, one-time password, autofill website, and tags.
let item = await client.items.create({
title: "My Item",
category: sdk.ItemCategory.Login,
Expand Down Expand Up @@ -78,15 +80,15 @@ let item = await client.items.create({
// [developer-docs.sdk.js.create-item]-end

// [developer-docs.sdk.js.resolve-totp-code]-start
// Fetches a TOTP code.
// Gets a one-time password code using a secret reference with the totp query parameter.
const code = await client.secrets.resolve(
`op://${item.vaultId}/${item.id}/TOTP_onetimepassword?attribute=totp`,
);
console.log(code);
// [developer-docs.sdk.js.resolve-totp-code]-end

// [developer-docs.sdk.js.get-totp-item-crud]-start
// Get a one-time password code.
// Gets a one-time password code from an item.
libutcher marked this conversation as resolved.
Show resolved Hide resolved
let element = item.fields.find((element) => {
return element.fieldType == sdk.ItemFieldType.Totp;
});
Expand All @@ -108,11 +110,12 @@ if (!element) {
// [developer-docs.sdk.js.get-totp-item-crud]-end

// [developer-docs.sdk.js.get-item]-start
// Retrieves an item.
libutcher marked this conversation as resolved.
Show resolved Hide resolved
let retrievedItem = await client.items.get(item.vaultId, item.id);
// [developer-docs.sdk.js.get-item]-end

// [developer-docs.sdk.js.update-item]-start
// Edit an item (change the password)
// Updates the item by changing its password.
libutcher marked this conversation as resolved.
Show resolved Hide resolved
let newItem = {
...retrievedItem,
fields: retrievedItem.fields.map((f) => {
Expand All @@ -129,6 +132,6 @@ let updatedItem = await client.items.put(newItem);
console.log(updatedItem.fields);

// [developer-docs.sdk.js.delete-item]-start
// Deletes an item
// Deletes an item.
await client.items.delete(item.vaultId, item.id);
// [developer-docs.sdk.js.delete-item]-end
Loading