Skip to content

Commit 5f4cd0a

Browse files
MOmarMiraj1PasswordSDKBotlibutcher
authored
JS SDK Release V0.3.0 (#143)
* Update core to version e1f91a18 * update example * Release v0.3.0 * update release notes * update release notes * update wording of breaking changes * Apply suggestions from code review Co-authored-by: Lucy Butcher <89952129+libutcher@users.noreply.github.com> * update release notes * Remove some unnecessary text * remove unnecessary log * add error check for misisng op-vault-id env and remove unnecessary await keyword * update release notes * remove unnecessary await * Update package.json's --------- Co-authored-by: 1PasswordSDKBot <it-github-sdk-bot@agilebits.com> Co-authored-by: Lucy Butcher <89952129+libutcher@users.noreply.github.com>
1 parent 325d924 commit 5f4cd0a

16 files changed

+170
-100
lines changed

client/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@1password/sdk",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "The 1Password JavaScript SDK offers programmatic read access to your secrets in 1Password in an interface native to JavaScript. The SDK currently supports `Node.JS`",
55
"scripts": {
66
"build": "tsc",
@@ -26,7 +26,7 @@
2626
"main": "./dist/sdk.js",
2727
"types": "./dist/sdk.d.ts",
2828
"dependencies": {
29-
"@1password/sdk-core": "0.2.1"
29+
"@1password/sdk-core": "0.3.0"
3030
},
3131
"devDependencies": {
3232
"@1password/eslint-config": "^4.0.0",

client/release/RELEASE-NOTES

+61-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,68 @@
1-
# 1Password JavaScript SDK v0.2.1
1+
# 1Password JavaScript SDK v0.3.0
22

33
## NEW
44

5-
- **`CreatedAt` and `UpdatedAt` item metadata:** Items and item overviews now expose attributes with their creation and last edit times.
6-
- **Resolving secrets in bulk**: With the `client.secrets.resolveAll` function, the SDK is now able to resolve multiple secrets at once, improving the performance of the operation.
5+
- **Support for item states**: You can now fetch an item's state using the SDK. `ItemOverview` exposes one of two states: `Active` or `Archived`.
6+
- `Active`: An item located inside a vault. (Default)
7+
- `Archived`: An item that has been moved to the Archive. 1Password doesn't include archived items in search results or suggest them when you fill in apps and browsers. You can keep archived items as long as you'd like.
8+
- **Filtering listed items by state**: You can now filter the results of the item list function by item state.
79

8-
## IMPROVED
10+
## FIXED
911

10-
- **Support for new field types:** Items with `Address` and `Date` fields can now be created, retrieved, and edited using the 1Password SDK.
11-
- **Item sharing for attachments and documents**: Items with files attached now can also be shared using the `client.items.shares` functions.
12-
- **Adding custom fields in sections automatically**: The SDK now automatically adds custom fields without a section to an empty section within the item, creating it if necessary.
13-
- **`Tags` in item overviews**: The return type of `items.listAll` now also contains the item tags.
14-
- **Broader item editing capabilities**: You are now able to use the `items.put` function on more items, including those with fields that are not directly editable through the SDK (such as legacy fields, passkeys etc.)
12+
- **Deleting Archived Items:** The SDK now supports deleting items from the archive.
1513

16-
## FIXED
14+
### ⚠️ BREAKING CHANGES ⚠️
15+
This release contains breaking changes for two functions in the JS SDK.
16+
17+
**Vault listing**
18+
19+
* The function name has changed from `listAll` to `list`. To use this in your code, replace:
20+
```js
21+
const vaults = await client.vaults.listAll();
22+
```
23+
with:
24+
```js
25+
const vaults = await client.vaults.list();
26+
```
27+
28+
* The return type of the vault listing functions has changed from `SdkIterable<VaultOverview>` to `VaultOverview[]`. To use this in your code, replace:
29+
```js
30+
for await (const vault of vaults) {
31+
console.log(vault.id + " " + vault.title);
32+
}
33+
```
34+
with:
35+
```js
36+
for (const vault of vaults) {
37+
console.log(vault.id + " " + vault.title);
38+
}
39+
```
40+
41+
**Item listing**
42+
43+
* The function name has changed from `listAll` to `list`. To use this in your code, replace:
44+
```js
45+
const overviews = await client.items.listAll(vault.id);
46+
```
47+
with:
48+
```js
49+
const overviews = await client.items.list(vault.id, {
50+
type: "ByState",
51+
content: { active: true, archived: true },
52+
})
53+
```
54+
55+
* The return type of the item listing functions has changed from `SdkIterable<ItemOverview>` to `ItemOverview[]`. To use this in your code, replace:
56+
```js
57+
for await (const overview of overviews) {
58+
console.log(overview.id + " " + overview.title);
59+
}
60+
```
61+
with:
62+
```js
63+
for (const overview of overviews) {
64+
console.log(overview.id + " " + overview.title);
65+
}
66+
```
1767

18-
- **Improvements to resolving secret references:**
19-
- Archived items are no longer used for secret references.
20-
- When multiple sections match a section query in resolving secret references, the SDK look through the fields in all sections, instead of erroring.
68+
This does not affect any code that's already deployed, and will not take effect in your codebase until you choose to update to version 0.3.0 or later of the 1Password JS SDK.

client/src/items.ts

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// Code generated by op-codegen - DO NOT EDIT MANUALLY
22

33
import { InvokeConfig, InnerClient, SharedCore } from "./core.js";
4-
import { SdkIterable } from "./iterator.js";
5-
import { Item, ItemCreateParams, ItemOverview, ReviverFunc } from "./types.js";
4+
import {
5+
Item,
6+
ItemCreateParams,
7+
ItemListFilter,
8+
ItemOverview,
9+
ReviverFunc,
10+
} from "./types.js";
611
import { ItemsSharesApi, ItemsShares } from "./items_shares.js";
712
import { ItemsFilesApi, ItemsFiles } from "./items_files.js";
813

@@ -38,9 +43,9 @@ export interface ItemsApi {
3843
archive(vaultId: string, itemId: string);
3944

4045
/**
41-
* List all items
46+
* List items based on filters.
4247
*/
43-
listAll(vaultId: string): Promise<SdkIterable<ItemOverview>>;
48+
list(vaultId: string, ...filters: ItemListFilter[]): Promise<ItemOverview[]>;
4449
}
4550

4651
export class Items implements ItemsApi {
@@ -72,7 +77,7 @@ export class Items implements ItemsApi {
7277
return JSON.parse(
7378
await this.#inner.core.invoke(invocationConfig),
7479
ReviverFunc,
75-
) as Promise<Item>;
80+
) as Item;
7681
}
7782

7883
/**
@@ -94,7 +99,7 @@ export class Items implements ItemsApi {
9499
return JSON.parse(
95100
await this.#inner.core.invoke(invocationConfig),
96101
ReviverFunc,
97-
) as Promise<Item>;
102+
) as Item;
98103
}
99104

100105
/**
@@ -115,7 +120,7 @@ export class Items implements ItemsApi {
115120
return JSON.parse(
116121
await this.#inner.core.invoke(invocationConfig),
117122
ReviverFunc,
118-
) as Promise<Item>;
123+
) as Item;
119124
}
120125

121126
/**
@@ -157,25 +162,27 @@ export class Items implements ItemsApi {
157162
}
158163

159164
/**
160-
* List all items
165+
* List items based on filters.
161166
*/
162-
public async listAll(vaultId: string): Promise<SdkIterable<ItemOverview>> {
167+
public async list(
168+
vaultId: string,
169+
...filters: ItemListFilter[]
170+
): Promise<ItemOverview[]> {
163171
const invocationConfig: InvokeConfig = {
164172
invocation: {
165173
clientId: this.#inner.id,
166174
parameters: {
167-
name: "ItemsListAll",
175+
name: "ItemsList",
168176
parameters: {
169177
vault_id: vaultId,
178+
filters,
170179
},
171180
},
172181
},
173182
};
174-
return new SdkIterable<ItemOverview>(
175-
JSON.parse(
176-
await this.#inner.core.invoke(invocationConfig),
177-
ReviverFunc,
178-
) as ItemOverview[],
179-
);
183+
return JSON.parse(
184+
await this.#inner.core.invoke(invocationConfig),
185+
ReviverFunc,
186+
) as ItemOverview[];
180187
}
181188
}

client/src/items_files.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Code generated by op-codegen - DO NOT EDIT MANUALLY
22

33
import { InvokeConfig, InnerClient, SharedCore } from "./core.js";
4-
import { SdkIterable } from "./iterator.js";
54
import {
65
DocumentCreateParams,
76
FileAttributes,
@@ -62,7 +61,7 @@ export class ItemsFiles implements ItemsFilesApi {
6261
return JSON.parse(
6362
await this.#inner.core.invoke(invocationConfig),
6463
ReviverFunc,
65-
) as Promise<Item>;
64+
) as Item;
6665
}
6766

6867
/**
@@ -89,7 +88,7 @@ export class ItemsFiles implements ItemsFilesApi {
8988
return JSON.parse(
9089
await this.#inner.core.invoke(invocationConfig),
9190
ReviverFunc,
92-
) as Promise<Uint8Array>;
91+
) as Uint8Array;
9392
}
9493

9594
/**
@@ -116,7 +115,7 @@ export class ItemsFiles implements ItemsFilesApi {
116115
return JSON.parse(
117116
await this.#inner.core.invoke(invocationConfig),
118117
ReviverFunc,
119-
) as Promise<Item>;
118+
) as Item;
120119
}
121120

122121
/**
@@ -141,6 +140,6 @@ export class ItemsFiles implements ItemsFilesApi {
141140
return JSON.parse(
142141
await this.#inner.core.invoke(invocationConfig),
143142
ReviverFunc,
144-
) as Promise<Item>;
143+
) as Item;
145144
}
146145
}

client/src/items_shares.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Code generated by op-codegen - DO NOT EDIT MANUALLY
22

33
import { InvokeConfig, InnerClient, SharedCore } from "./core.js";
4-
import { SdkIterable } from "./iterator.js";
54
import {
65
Item,
76
ItemShareAccountPolicy,
@@ -66,7 +65,7 @@ export class ItemsShares implements ItemsSharesApi {
6665
return JSON.parse(
6766
await this.#inner.core.invoke(invocationConfig),
6867
ReviverFunc,
69-
) as Promise<ItemShareAccountPolicy>;
68+
) as ItemShareAccountPolicy;
7069
}
7170

7271
/**
@@ -91,7 +90,7 @@ export class ItemsShares implements ItemsSharesApi {
9190
return JSON.parse(
9291
await this.#inner.core.invoke(invocationConfig),
9392
ReviverFunc,
94-
) as Promise<ValidRecipient[]>;
93+
) as ValidRecipient[];
9594
}
9695

9796
/**
@@ -118,6 +117,6 @@ export class ItemsShares implements ItemsSharesApi {
118117
return JSON.parse(
119118
await this.#inner.core.invoke(invocationConfig),
120119
ReviverFunc,
121-
) as Promise<string>;
120+
) as string;
122121
}
123122
}

client/src/iterator.ts

-15
This file was deleted.

client/src/secrets.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Code generated by op-codegen - DO NOT EDIT MANUALLY
22

33
import { InvokeConfig, InnerClient, SharedCore } from "./core.js";
4-
import { SdkIterable } from "./iterator.js";
54
import {
65
GeneratePasswordResponse,
76
PasswordRecipe,
@@ -50,7 +49,7 @@ export class Secrets implements SecretsApi {
5049
return JSON.parse(
5150
await this.#inner.core.invoke(invocationConfig),
5251
ReviverFunc,
53-
) as Promise<string>;
52+
) as string;
5453
}
5554

5655
/**
@@ -73,7 +72,7 @@ export class Secrets implements SecretsApi {
7372
return JSON.parse(
7473
await this.#inner.core.invoke(invocationConfig),
7574
ReviverFunc,
76-
) as Promise<ResolveAllResponse>;
75+
) as ResolveAllResponse;
7776
}
7877

7978
/**

client/src/types.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export interface ItemFile {
169169
fieldId: string;
170170
}
171171

172-
/** Represents a 1Password item. */
172+
/** Represents an active 1Password item. */
173173
export interface Item {
174174
/** The item's ID */
175175
id: string;
@@ -224,6 +224,14 @@ export interface ItemCreateParams {
224224
document?: DocumentCreateParams;
225225
}
226226

227+
/** Represents the state of an item in the SDK. */
228+
export enum ItemState {
229+
/** The item is active */
230+
Active = "active",
231+
/** The item is archived meaning it's hidden from regular view and stored in the archive. */
232+
Archived = "archived",
233+
}
234+
227235
/** Represents a decrypted 1Password item overview. */
228236
export interface ItemOverview {
229237
/** The item's ID */
@@ -242,6 +250,8 @@ export interface ItemOverview {
242250
createdAt: Date;
243251
/** The time the item was updated at */
244252
updatedAt: Date;
253+
/** Indicates the state of the item */
254+
state: ItemState;
245255
}
246256

247257
/** The valid duration options for sharing an item */
@@ -418,6 +428,14 @@ export interface VaultOverview {
418428
title: string;
419429
}
420430

431+
export type ItemListFilter = {
432+
type: "ByState";
433+
content: {
434+
active: boolean;
435+
archived: boolean;
436+
};
437+
};
438+
421439
export type PasswordRecipe =
422440
| {
423441
type: "Memorable";

0 commit comments

Comments
 (0)