@1password/sdk 0.1.0-beta.9 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +2 -0
- package/dist/configuration.d.ts +2 -0
- package/dist/configuration.js +11 -30
- package/dist/items.d.ts +30 -6
- package/dist/items.js +37 -7
- package/dist/iterator.d.ts +6 -0
- package/dist/iterator.js +32 -0
- package/dist/secrets.d.ts +10 -0
- package/dist/secrets.js +4 -1
- package/dist/types.d.ts +71 -51
- package/dist/types.js +5 -1
- package/dist/vaults.d.ts +20 -0
- package/dist/vaults.js +48 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +6 -0
- package/package.json +13 -11
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://1password.com">
|
|
3
|
+
<h1 align="center">1Password JavaScript SDK</h1>
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<h4 align="center">Build integrations that programmatically access your secrets in 1Password.</h4>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://developer.1password.com/docs/sdks/">Documentation</a> | <a href="https://github.com/1Password/onepassword-sdk-js/tree/main/examples">Examples</a>
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 🚀 Get started
|
|
18
|
+
|
|
19
|
+
To use the 1Password JavaScript SDK in your project:
|
|
20
|
+
|
|
21
|
+
1. [Create a service account](https://my.1password.com/developer-tools/infrastructure-secrets/serviceaccount/) and give it the appropriate permissions in the vaults where the items you want to use with the SDK are saved.
|
|
22
|
+
2. Provision your service account token. We recommend provisioning your token from the environment. For example, to export your token to the `OP_SERVICE_ACCOUNT_TOKEN` environment variable:
|
|
23
|
+
|
|
24
|
+
**macOS or Linux**
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
export OP_SERVICE_ACCOUNT_TOKEN=<your-service-account-token>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Windows**
|
|
31
|
+
|
|
32
|
+
```powershell
|
|
33
|
+
$Env:OP_SERVICE_ACCOUNT_TOKEN = "<your-service-account-token>"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
3. Install the 1Password JavaScript SDK in your project:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
## NPM
|
|
40
|
+
npm install @1password/sdk
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
## PNPM
|
|
45
|
+
pnpm add @1password/sdk
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
## Yarn
|
|
50
|
+
yarn add @1password/sdk
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
4. Use the JavaScript SDK in your project:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import { createClient } from "@1password/sdk";
|
|
57
|
+
|
|
58
|
+
// Creates an authenticated client.
|
|
59
|
+
const client = await createClient({
|
|
60
|
+
auth: process.env.OP_SERVICE_ACCOUNT_TOKEN,
|
|
61
|
+
// Set the following to your own integration name and version.
|
|
62
|
+
integrationName: "My 1Password Integration",
|
|
63
|
+
integrationVersion: "v1.0.0",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Fetches a secret.
|
|
67
|
+
const secret = await client.secrets.resolve("op://vault/item/field");
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Make sure to use [secret reference URIs](https://developer.1password.com/docs/cli/secrets-reference-syntax/) with the syntax `op://vault/item/field` to securely load secrets from 1Password into your code.
|
|
71
|
+
|
|
72
|
+
Inside `createClient()`, set `integrationName` to the name of your application and `integrationVersion` to the version of your application.
|
|
73
|
+
|
|
74
|
+
## Supported functionality
|
|
75
|
+
|
|
76
|
+
1Password SDKs are in active development. We're keen to hear what you'd like to see next. Let us know by [upvoting](https://github.com/1Password/onepassword-sdk-js/issues) or [filing](https://github.com/1Password/onepassword-sdk-js/issues/new/choose) an issue.
|
|
77
|
+
|
|
78
|
+
### Item management
|
|
79
|
+
|
|
80
|
+
Operations:
|
|
81
|
+
|
|
82
|
+
- [x] [Retrieve secrets](https://developer.1password.com/docs/sdks/load-secrets)
|
|
83
|
+
- [x] [Retrieve items](https://developer.1password.com/docs/sdks/manage-items#get-an-item)
|
|
84
|
+
- [x] [Create items](https://developer.1password.com/docs/sdks/manage-items#create-an-item)
|
|
85
|
+
- [x] [Update items](https://developer.1password.com/docs/sdks/manage-items#edit-an-item)
|
|
86
|
+
- [x] [Delete items](https://developer.1password.com/docs/sdks/manage-items#delete-an-item)
|
|
87
|
+
- [x] [List items](https://developer.1password.com/docs/sdks/list-vaults-items/)
|
|
88
|
+
- [ ] Add & update tags on items
|
|
89
|
+
|
|
90
|
+
Field types:
|
|
91
|
+
- [x] API Keys
|
|
92
|
+
- [x] Passwords
|
|
93
|
+
- [x] Concealed fields
|
|
94
|
+
- [x] Text fields
|
|
95
|
+
- [x] Notes
|
|
96
|
+
- [x] SSH private keys (partially supported: supported in resolving secret references, not yet supported in item create/get/update)
|
|
97
|
+
- [ ] SSH public keys, fingerprint and key type
|
|
98
|
+
- [x] One-time passwords
|
|
99
|
+
- [x] URLs
|
|
100
|
+
- [x] Phone numbers
|
|
101
|
+
- [x] Credit card types
|
|
102
|
+
- [ ] File attachments and Document items
|
|
103
|
+
|
|
104
|
+
### Vault management
|
|
105
|
+
- [ ] Retrieve vaults
|
|
106
|
+
- [ ] Create vaults ([#50](https://github.com/1Password/onepassword-sdk-js/issues/50))
|
|
107
|
+
- [ ] Update vaults
|
|
108
|
+
- [ ] Delete vaults
|
|
109
|
+
- [x] [List vaults](https://developer.1password.com/docs/sdks/list-vaults-items/)
|
|
110
|
+
|
|
111
|
+
### User & access management
|
|
112
|
+
- [ ] Provision users
|
|
113
|
+
- [ ] Retrieve users
|
|
114
|
+
- [ ] List users
|
|
115
|
+
- [ ] Suspend users
|
|
116
|
+
- [ ] Create groups
|
|
117
|
+
- [ ] Update group membership
|
|
118
|
+
- [ ] Update vault access & permissions
|
|
119
|
+
|
|
120
|
+
### Compliance & reporting
|
|
121
|
+
- [ ] Watchtower insights
|
|
122
|
+
- [ ] Travel mode
|
|
123
|
+
- [ ] Events. For now, use [1Password Events Reporting API](https://developer.1password.com/docs/events-api/) directly.
|
|
124
|
+
|
|
125
|
+
### Authentication
|
|
126
|
+
|
|
127
|
+
- [x] [1Password Service Accounts](https://developer.1password.com/docs/service-accounts/get-started/)
|
|
128
|
+
- [ ] User authentication
|
|
129
|
+
- [ ] 1Password Connect. For now, use [1Password/connect-sdk-go](https://github.com/1Password/connect-sdk-go).
|
|
130
|
+
|
|
131
|
+
## 📖 Learn more
|
|
132
|
+
|
|
133
|
+
- [Load secrets with 1Password SDKs](https://developer.1password.com/docs/sdks/load-secrets)
|
|
134
|
+
- [Manage items with 1Password SDKs](https://developer.1password.com/docs/sdks/manage-items)
|
|
135
|
+
- [List vaults and items with 1Password SDKs](https://developer.1password.com/docs/sdks/list-vaults-items)
|
|
136
|
+
- [1Password SDK concepts](https://developer.1password.com/docs/sdks/concepts)
|
package/dist/client.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { InnerClient } from "./core.js";
|
|
2
2
|
import { SecretsApi } from "./secrets.js";
|
|
3
3
|
import { ItemsApi } from "./items.js";
|
|
4
|
+
import { VaultsApi } from "./vaults.js";
|
|
4
5
|
export declare class Client {
|
|
5
6
|
secrets: SecretsApi;
|
|
6
7
|
items: ItemsApi;
|
|
8
|
+
vaults: VaultsApi;
|
|
7
9
|
constructor(innerClient: InnerClient);
|
|
8
10
|
}
|
package/dist/client.js
CHANGED
|
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Client = void 0;
|
|
4
4
|
const secrets_js_1 = require("./secrets.js");
|
|
5
5
|
const items_js_1 = require("./items.js");
|
|
6
|
+
const vaults_js_1 = require("./vaults.js");
|
|
6
7
|
class Client {
|
|
7
8
|
constructor(innerClient) {
|
|
8
9
|
this.secrets = new secrets_js_1.SecretsSource(innerClient);
|
|
9
10
|
this.items = new items_js_1.ItemsSource(innerClient);
|
|
11
|
+
this.vaults = new vaults_js_1.VaultsSource(innerClient);
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
exports.Client = Client;
|
package/dist/configuration.d.ts
CHANGED
package/dist/configuration.js
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getOsName = exports.clientAuthConfig = void 0;
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
6
|
+
exports.getOsName = exports.clientAuthConfig = exports.VERSION = exports.LANGUAGE = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const version_js_1 = require("./version.js");
|
|
9
|
+
exports.LANGUAGE = "JS";
|
|
10
|
+
exports.VERSION = version_js_1.SDK_BUILD_NUMBER;
|
|
30
11
|
/**
|
|
31
12
|
* Creates a default client configuration.
|
|
32
13
|
* @returns The client configuration to instantiate the client with.
|
|
@@ -36,21 +17,21 @@ const clientAuthConfig = (userConfig) => {
|
|
|
36
17
|
const defaultOsVersion = "0.0.0";
|
|
37
18
|
return {
|
|
38
19
|
serviceAccountToken: userConfig.auth,
|
|
39
|
-
programmingLanguage: LANGUAGE,
|
|
40
|
-
sdkVersion: VERSION,
|
|
20
|
+
programmingLanguage: exports.LANGUAGE,
|
|
21
|
+
sdkVersion: exports.VERSION,
|
|
41
22
|
integrationName: userConfig.integrationName,
|
|
42
23
|
integrationVersion: userConfig.integrationVersion,
|
|
43
24
|
requestLibraryName: "Fetch API",
|
|
44
25
|
requestLibraryVersion: "Fetch API",
|
|
45
26
|
os: (0, exports.getOsName)(),
|
|
46
27
|
osVersion: defaultOsVersion,
|
|
47
|
-
architecture:
|
|
28
|
+
architecture: os_1.default.arch(),
|
|
48
29
|
};
|
|
49
30
|
};
|
|
50
31
|
exports.clientAuthConfig = clientAuthConfig;
|
|
51
32
|
const getOsName = () => {
|
|
52
33
|
// Only supported on Node.js
|
|
53
|
-
const os_name =
|
|
34
|
+
const os_name = os_1.default.type().toLowerCase();
|
|
54
35
|
if (os_name === "windows_nt") {
|
|
55
36
|
return "windows";
|
|
56
37
|
}
|
package/dist/items.d.ts
CHANGED
|
@@ -1,28 +1,52 @@
|
|
|
1
1
|
import { InnerClient } from "./core.js";
|
|
2
2
|
import * as types from "./types.js";
|
|
3
|
+
import { SdkIterable } from "./iterator.js";
|
|
4
|
+
/**
|
|
5
|
+
* The Items API holds all operations the SDK client can perform on 1Password items.
|
|
6
|
+
*/
|
|
3
7
|
export interface ItemsApi {
|
|
4
8
|
/**
|
|
5
9
|
* Create a new item
|
|
6
10
|
*/
|
|
7
|
-
create(
|
|
11
|
+
create(params: types.ItemCreateParams): Promise<types.Item>;
|
|
8
12
|
/**
|
|
9
13
|
* Get an item by vault and item ID
|
|
10
14
|
*/
|
|
11
15
|
get(vaultId: string, itemId: string): Promise<types.Item>;
|
|
12
16
|
/**
|
|
13
|
-
* Update an existing item.
|
|
17
|
+
* Update an existing item.
|
|
14
18
|
*/
|
|
15
|
-
|
|
19
|
+
put(item: types.Item): Promise<types.Item>;
|
|
16
20
|
/**
|
|
17
|
-
* Delete an item.
|
|
21
|
+
* Delete an item.
|
|
18
22
|
*/
|
|
19
23
|
delete(vaultId: string, itemId: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* List all items
|
|
26
|
+
*/
|
|
27
|
+
listAll(vaultId: string): Promise<SdkIterable<types.ItemOverview>>;
|
|
20
28
|
}
|
|
21
29
|
export declare class ItemsSource implements ItemsApi {
|
|
22
30
|
#private;
|
|
23
31
|
constructor(inner: InnerClient);
|
|
24
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Create a new item
|
|
34
|
+
*/
|
|
35
|
+
create(params: types.ItemCreateParams): Promise<types.Item>;
|
|
36
|
+
/**
|
|
37
|
+
* Get an item by vault and item ID
|
|
38
|
+
*/
|
|
25
39
|
get(vaultId: string, itemId: string): Promise<types.Item>;
|
|
26
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Update an existing item.
|
|
42
|
+
*/
|
|
43
|
+
put(item: types.Item): Promise<types.Item>;
|
|
44
|
+
/**
|
|
45
|
+
* Delete an item.
|
|
46
|
+
*/
|
|
27
47
|
delete(vaultId: string, itemId: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* List all items
|
|
50
|
+
*/
|
|
51
|
+
listAll(vaultId: string): Promise<SdkIterable<types.ItemOverview>>;
|
|
28
52
|
}
|
package/dist/items.js
CHANGED
|
@@ -22,31 +22,38 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
22
22
|
var _ItemsSource_inner;
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.ItemsSource = void 0;
|
|
25
|
+
const iterator_js_1 = require("./iterator.js");
|
|
25
26
|
class ItemsSource {
|
|
26
27
|
constructor(inner) {
|
|
27
28
|
_ItemsSource_inner.set(this, void 0);
|
|
28
29
|
__classPrivateFieldSet(this, _ItemsSource_inner, inner, "f");
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Create a new item
|
|
33
|
+
*/
|
|
34
|
+
create(params) {
|
|
31
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
36
|
const invocationConfig = {
|
|
33
37
|
clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
|
|
34
38
|
invocation: {
|
|
35
|
-
name: "
|
|
39
|
+
name: "ItemsCreate",
|
|
36
40
|
parameters: {
|
|
37
|
-
|
|
41
|
+
params,
|
|
38
42
|
},
|
|
39
43
|
},
|
|
40
44
|
};
|
|
41
45
|
return JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig));
|
|
42
46
|
});
|
|
43
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Get an item by vault and item ID
|
|
50
|
+
*/
|
|
44
51
|
get(vaultId, itemId) {
|
|
45
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
53
|
const invocationConfig = {
|
|
47
54
|
clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
|
|
48
55
|
invocation: {
|
|
49
|
-
name: "
|
|
56
|
+
name: "ItemsGet",
|
|
50
57
|
parameters: {
|
|
51
58
|
vault_id: vaultId,
|
|
52
59
|
item_id: itemId,
|
|
@@ -56,12 +63,15 @@ class ItemsSource {
|
|
|
56
63
|
return JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig));
|
|
57
64
|
});
|
|
58
65
|
}
|
|
59
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Update an existing item.
|
|
68
|
+
*/
|
|
69
|
+
put(item) {
|
|
60
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
71
|
const invocationConfig = {
|
|
62
72
|
clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
|
|
63
73
|
invocation: {
|
|
64
|
-
name: "
|
|
74
|
+
name: "ItemsPut",
|
|
65
75
|
parameters: {
|
|
66
76
|
item,
|
|
67
77
|
},
|
|
@@ -70,12 +80,15 @@ class ItemsSource {
|
|
|
70
80
|
return JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig));
|
|
71
81
|
});
|
|
72
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Delete an item.
|
|
85
|
+
*/
|
|
73
86
|
delete(vaultId, itemId) {
|
|
74
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
88
|
const invocationConfig = {
|
|
76
89
|
clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
|
|
77
90
|
invocation: {
|
|
78
|
-
name: "
|
|
91
|
+
name: "ItemsDelete",
|
|
79
92
|
parameters: {
|
|
80
93
|
vault_id: vaultId,
|
|
81
94
|
item_id: itemId,
|
|
@@ -85,6 +98,23 @@ class ItemsSource {
|
|
|
85
98
|
yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig);
|
|
86
99
|
});
|
|
87
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* List all items
|
|
103
|
+
*/
|
|
104
|
+
listAll(vaultId) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const invocationConfig = {
|
|
107
|
+
clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
|
|
108
|
+
invocation: {
|
|
109
|
+
name: "ItemsListAll",
|
|
110
|
+
parameters: {
|
|
111
|
+
vault_id: vaultId,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
return new iterator_js_1.SdkIterable(JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig)));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
88
118
|
}
|
|
89
119
|
exports.ItemsSource = ItemsSource;
|
|
90
120
|
_ItemsSource_inner = new WeakMap();
|
package/dist/iterator.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
3
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
4
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
5
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
6
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
7
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
8
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
9
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
10
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
11
|
+
function fulfill(value) { resume("next", value); }
|
|
12
|
+
function reject(value) { resume("throw", value); }
|
|
13
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.SdkIterable = void 0;
|
|
17
|
+
class SdkIterable {
|
|
18
|
+
constructor(elements) {
|
|
19
|
+
this.elements = elements;
|
|
20
|
+
}
|
|
21
|
+
[Symbol.asyncIterator]() {
|
|
22
|
+
return this.asyncIterator();
|
|
23
|
+
}
|
|
24
|
+
asyncIterator() {
|
|
25
|
+
return __asyncGenerator(this, arguments, function* asyncIterator_1() {
|
|
26
|
+
for (const element of this.elements) {
|
|
27
|
+
yield yield __await(yield __await(Promise.resolve(element)));
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.SdkIterable = SdkIterable;
|
package/dist/secrets.d.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { InnerClient } from "./core.js";
|
|
2
|
+
/**
|
|
3
|
+
* The Secrets API includes all operations the SDK client can perform on secrets.
|
|
4
|
+
* Use secret reference URIs to securely load secrets from 1Password: op://<vault-name>/<item-name>[/<section-name>]/<field-name>
|
|
5
|
+
*/
|
|
2
6
|
export interface SecretsApi {
|
|
7
|
+
/**
|
|
8
|
+
* Resolve returns the secret the provided secret reference points to.
|
|
9
|
+
*/
|
|
3
10
|
resolve(secretReference: string): Promise<string>;
|
|
4
11
|
}
|
|
5
12
|
export declare class SecretsSource implements SecretsApi {
|
|
6
13
|
#private;
|
|
7
14
|
constructor(inner: InnerClient);
|
|
15
|
+
/**
|
|
16
|
+
* Resolve returns the secret the provided secret reference points to.
|
|
17
|
+
*/
|
|
8
18
|
resolve(secretReference: string): Promise<string>;
|
|
9
19
|
}
|
package/dist/secrets.js
CHANGED
|
@@ -27,12 +27,15 @@ class SecretsSource {
|
|
|
27
27
|
_SecretsSource_inner.set(this, void 0);
|
|
28
28
|
__classPrivateFieldSet(this, _SecretsSource_inner, inner, "f");
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolve returns the secret the provided secret reference points to.
|
|
32
|
+
*/
|
|
30
33
|
resolve(secretReference) {
|
|
31
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
35
|
const invocationConfig = {
|
|
33
36
|
clientId: __classPrivateFieldGet(this, _SecretsSource_inner, "f").id,
|
|
34
37
|
invocation: {
|
|
35
|
-
name: "
|
|
38
|
+
name: "SecretsResolve",
|
|
36
39
|
parameters: {
|
|
37
40
|
secret_reference: secretReference,
|
|
38
41
|
},
|
package/dist/types.d.ts
CHANGED
|
@@ -27,72 +27,92 @@ export declare enum ItemCategory {
|
|
|
27
27
|
export declare enum ItemFieldType {
|
|
28
28
|
Text = "Text",
|
|
29
29
|
Concealed = "Concealed",
|
|
30
|
+
CreditCardType = "CreditCardType",
|
|
31
|
+
Phone = "Phone",
|
|
32
|
+
Url = "Url",
|
|
33
|
+
Totp = "Totp",
|
|
30
34
|
Unsupported = "Unsupported"
|
|
31
35
|
}
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
*/
|
|
36
|
+
/** Field type-specific attributes. */
|
|
37
|
+
export type ItemFieldDetails =
|
|
38
|
+
/** The computed OTP code and other details */
|
|
39
|
+
{
|
|
40
|
+
type: "Otp";
|
|
41
|
+
content: OtpFieldDetails;
|
|
42
|
+
};
|
|
43
|
+
/** Represents a field within an item. */
|
|
35
44
|
export interface ItemField {
|
|
36
|
-
/**
|
|
37
|
-
* The field's ID
|
|
38
|
-
*/
|
|
45
|
+
/** The field's ID */
|
|
39
46
|
id: string;
|
|
40
|
-
/**
|
|
41
|
-
* The field's title
|
|
42
|
-
*/
|
|
47
|
+
/** The field's title */
|
|
43
48
|
title: string;
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* The type of value stored in the field
|
|
50
|
-
*/
|
|
51
|
-
field_type: ItemFieldType;
|
|
52
|
-
/**
|
|
53
|
-
* The string representation of the field's value
|
|
54
|
-
*/
|
|
49
|
+
/** The ID of the section containing the field. Built-in fields such as usernames and passwords don't require a section. */
|
|
50
|
+
sectionId?: string;
|
|
51
|
+
/** The field's type */
|
|
52
|
+
fieldType: ItemFieldType;
|
|
53
|
+
/** The string representation of the field's value */
|
|
55
54
|
value: string;
|
|
55
|
+
/** Field type-specific attributes. */
|
|
56
|
+
details?: ItemFieldDetails;
|
|
56
57
|
}
|
|
57
|
-
/**
|
|
58
|
-
* A section groups together multiple fields in an item.
|
|
59
|
-
*/
|
|
58
|
+
/** A section groups together multiple fields in an item. */
|
|
60
59
|
export interface ItemSection {
|
|
61
|
-
/**
|
|
62
|
-
* The ID of the section
|
|
63
|
-
*/
|
|
60
|
+
/** The section's unique ID */
|
|
64
61
|
id: string;
|
|
65
|
-
/**
|
|
66
|
-
* The title of the section
|
|
67
|
-
*/
|
|
62
|
+
/** The section's title */
|
|
68
63
|
title: string;
|
|
69
64
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Represents a 1Password item.
|
|
72
|
-
*/
|
|
65
|
+
/** Represents a 1Password item. */
|
|
73
66
|
export interface Item {
|
|
74
|
-
/**
|
|
75
|
-
* The item's unique ID
|
|
76
|
-
*/
|
|
67
|
+
/** The item's ID */
|
|
77
68
|
id: string;
|
|
78
|
-
/**
|
|
79
|
-
* The item's title
|
|
80
|
-
*/
|
|
69
|
+
/** The item's title */
|
|
81
70
|
title: string;
|
|
82
|
-
/**
|
|
83
|
-
* The item's category
|
|
84
|
-
*/
|
|
71
|
+
/** The item's category */
|
|
85
72
|
category: ItemCategory;
|
|
86
|
-
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
vault_id: string;
|
|
90
|
-
/**
|
|
91
|
-
* The item's fields
|
|
92
|
-
*/
|
|
73
|
+
/** The ID of the vault where the item is saved */
|
|
74
|
+
vaultId: string;
|
|
75
|
+
/** The item's fields */
|
|
93
76
|
fields: ItemField[];
|
|
94
|
-
/**
|
|
95
|
-
* The item's sections
|
|
96
|
-
*/
|
|
77
|
+
/** The item's sections */
|
|
97
78
|
sections: ItemSection[];
|
|
79
|
+
/** The item's version */
|
|
80
|
+
version: number;
|
|
81
|
+
}
|
|
82
|
+
export interface ItemCreateParams {
|
|
83
|
+
/** The item's category */
|
|
84
|
+
category: ItemCategory;
|
|
85
|
+
/** The ID of the vault where the item is saved */
|
|
86
|
+
vaultId: string;
|
|
87
|
+
/** The item's title */
|
|
88
|
+
title: string;
|
|
89
|
+
/** The item's fields */
|
|
90
|
+
fields: ItemField[];
|
|
91
|
+
/** The item's sections */
|
|
92
|
+
sections: ItemSection[];
|
|
93
|
+
}
|
|
94
|
+
/** Represents a decrypted 1Password item. */
|
|
95
|
+
export interface ItemOverview {
|
|
96
|
+
/** The item's ID */
|
|
97
|
+
id: string;
|
|
98
|
+
/** The item's title */
|
|
99
|
+
title: string;
|
|
100
|
+
/** The item's category */
|
|
101
|
+
category: ItemCategory;
|
|
102
|
+
/** The ID of the vault where the item is saved */
|
|
103
|
+
vaultId: string;
|
|
104
|
+
}
|
|
105
|
+
/** Additional attributes for OTP fields. */
|
|
106
|
+
export interface OtpFieldDetails {
|
|
107
|
+
/** The OTP code, if successfully computed */
|
|
108
|
+
code?: string;
|
|
109
|
+
/** The error message, if the OTP code could not be computed */
|
|
110
|
+
errorMessage?: string;
|
|
111
|
+
}
|
|
112
|
+
/** Represents a decrypted 1Password vault. */
|
|
113
|
+
export interface VaultOverview {
|
|
114
|
+
/** The vault's ID */
|
|
115
|
+
id: string;
|
|
116
|
+
/** The vault's title */
|
|
117
|
+
title: string;
|
|
98
118
|
}
|
package/dist/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Generated by typeshare 1.
|
|
3
|
+
Generated by typeshare 1.10.0-beta.7
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ItemFieldType = exports.ItemCategory = void 0;
|
|
@@ -35,5 +35,9 @@ var ItemFieldType;
|
|
|
35
35
|
(function (ItemFieldType) {
|
|
36
36
|
ItemFieldType["Text"] = "Text";
|
|
37
37
|
ItemFieldType["Concealed"] = "Concealed";
|
|
38
|
+
ItemFieldType["CreditCardType"] = "CreditCardType";
|
|
39
|
+
ItemFieldType["Phone"] = "Phone";
|
|
40
|
+
ItemFieldType["Url"] = "Url";
|
|
41
|
+
ItemFieldType["Totp"] = "Totp";
|
|
38
42
|
ItemFieldType["Unsupported"] = "Unsupported";
|
|
39
43
|
})(ItemFieldType || (exports.ItemFieldType = ItemFieldType = {}));
|
package/dist/vaults.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { InnerClient } from "./core.js";
|
|
2
|
+
import * as types from "./types.js";
|
|
3
|
+
import { SdkIterable } from "./iterator.js";
|
|
4
|
+
/**
|
|
5
|
+
* The Vaults API holds all the operations the SDK client can perform on 1Password vaults.
|
|
6
|
+
*/
|
|
7
|
+
export interface VaultsApi {
|
|
8
|
+
/**
|
|
9
|
+
* List all vaults
|
|
10
|
+
*/
|
|
11
|
+
listAll(): Promise<SdkIterable<types.VaultOverview>>;
|
|
12
|
+
}
|
|
13
|
+
export declare class VaultsSource implements VaultsApi {
|
|
14
|
+
#private;
|
|
15
|
+
constructor(inner: InnerClient);
|
|
16
|
+
/**
|
|
17
|
+
* List all vaults
|
|
18
|
+
*/
|
|
19
|
+
listAll(): Promise<SdkIterable<types.VaultOverview>>;
|
|
20
|
+
}
|
package/dist/vaults.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var _VaultsSource_inner;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.VaultsSource = void 0;
|
|
25
|
+
const iterator_js_1 = require("./iterator.js");
|
|
26
|
+
class VaultsSource {
|
|
27
|
+
constructor(inner) {
|
|
28
|
+
_VaultsSource_inner.set(this, void 0);
|
|
29
|
+
__classPrivateFieldSet(this, _VaultsSource_inner, inner, "f");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* List all vaults
|
|
33
|
+
*/
|
|
34
|
+
listAll() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const invocationConfig = {
|
|
37
|
+
clientId: __classPrivateFieldGet(this, _VaultsSource_inner, "f").id,
|
|
38
|
+
invocation: {
|
|
39
|
+
name: "VaultsListAll",
|
|
40
|
+
parameters: {},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
return new iterator_js_1.SdkIterable(JSON.parse(yield __classPrivateFieldGet(this, _VaultsSource_inner, "f").core.invoke(invocationConfig)));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.VaultsSource = VaultsSource;
|
|
48
|
+
_VaultsSource_inner = new WeakMap();
|
package/dist/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1password/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"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`",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc",
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
"prettier-fix": "prettier --write 'src/*.ts'",
|
|
10
10
|
"eslint": "eslint -c .eslintrc.json 'src/*.ts'",
|
|
11
11
|
"prepare": "rm -rf ./dist && npm run build",
|
|
12
|
-
"publish-test": "cp ../README.md . && npm publish --
|
|
13
|
-
"publish-
|
|
12
|
+
"publish-test": "cp ../README.md . && npm publish --dry-run && rm ./README.md",
|
|
13
|
+
"publish-prod": "cp ../README.md . && npm publish && rm ./README.md"
|
|
14
14
|
},
|
|
15
15
|
"author": "1Password",
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"files": [
|
|
17
|
+
"files": [
|
|
18
|
+
"./dist"
|
|
19
|
+
],
|
|
18
20
|
"exports": {
|
|
19
21
|
".": {
|
|
20
22
|
"types": "./dist/sdk.d.ts",
|
|
@@ -24,22 +26,22 @@
|
|
|
24
26
|
"main": "./dist/sdk.js",
|
|
25
27
|
"types": "./dist/sdk.d.ts",
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"@1password/sdk-core": "0.1.0-beta.
|
|
29
|
+
"@1password/sdk-core": "0.1.0-beta.15"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
32
|
"@1password/eslint-config": "^4.0.0",
|
|
31
33
|
"@1password/prettier-config": "^1.1.3",
|
|
34
|
+
"@babel/preset-env": "^7.23.8",
|
|
32
35
|
"@jest/globals": "^29.7.0",
|
|
33
36
|
"@types/jest": "^29.5.11",
|
|
34
|
-
"
|
|
37
|
+
"@types/node": "^20.11.0",
|
|
38
|
+
"babel-jest": "^29.7.0",
|
|
35
39
|
"eslint": "^8.54.0",
|
|
36
|
-
"
|
|
40
|
+
"jest": "^29.7.0",
|
|
37
41
|
"jest-environment-jsdom": "^29.6.2",
|
|
38
42
|
"prettier": "3.1.1",
|
|
43
|
+
"prettier-plugin-organize-imports": "^3.2.3",
|
|
39
44
|
"ts-jest": "^29.1.1",
|
|
40
|
-
"typescript": "^5.3.3"
|
|
41
|
-
"@types/node": "^20.11.0",
|
|
42
|
-
"@babel/preset-env": "^7.23.8",
|
|
43
|
-
"babel-jest": "^29.7.0"
|
|
45
|
+
"typescript": "^5.3.3"
|
|
44
46
|
}
|
|
45
47
|
}
|