@1password/sdk 0.0.0-credential-broker-dev-preview
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 +220 -0
- package/dist/client.d.ts +23 -0
- package/dist/client.js +32 -0
- package/dist/client_builder.d.ts +18 -0
- package/dist/client_builder.js +64 -0
- package/dist/configuration.d.ts +33 -0
- package/dist/configuration.js +58 -0
- package/dist/core.d.ts +115 -0
- package/dist/core.js +154 -0
- package/dist/credential_broker.d.ts +28 -0
- package/dist/credential_broker.js +31 -0
- package/dist/credential_broker_access_requests.d.ts +43 -0
- package/dist/credential_broker_access_requests.js +78 -0
- package/dist/credential_broker_environment_variables.d.ts +33 -0
- package/dist/credential_broker_environment_variables.js +58 -0
- package/dist/credential_broker_logins.d.ts +38 -0
- package/dist/credential_broker_logins.js +77 -0
- package/dist/environments.d.ts +82 -0
- package/dist/environments.js +132 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +45 -0
- package/dist/groups.d.ts +19 -0
- package/dist/groups.js +54 -0
- package/dist/items.d.ts +89 -0
- package/dist/items.js +216 -0
- package/dist/items_files.d.ts +40 -0
- package/dist/items_files.js +116 -0
- package/dist/items_shares.d.ts +32 -0
- package/dist/items_shares.js +95 -0
- package/dist/sdk.d.ts +24 -0
- package/dist/sdk.js +57 -0
- package/dist/secrets.d.ts +36 -0
- package/dist/secrets.js +107 -0
- package/dist/shared_lib_core.d.ts +17 -0
- package/dist/shared_lib_core.js +183 -0
- package/dist/types.d.ts +972 -0
- package/dist/types.js +279 -0
- package/dist/vaults.d.ts +83 -0
- package/dist/vaults.js +209 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +6 -0
- package/dist/web.d.ts +11 -0
- package/dist/web.js +55 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
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 interact with 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
|
+
You can choose between two [authentication methods](https://developer.1password.com/docs/sdks/concepts#authentication) for the 1Password JavaScript SDK: local authorization prompts from the [1Password desktop app](#option-1-1password-desktop-app) or automated authentication with a [1Password Service Account](#option-2-1password-service-account).
|
|
20
|
+
|
|
21
|
+
### Option 1: 1Password desktop app
|
|
22
|
+
|
|
23
|
+
[1Password desktop app authentication](https://developer.1password.com/docs/sdks/concepts#1password-desktop-app) is best for local integrations that require minimal setup from end users and sensitive workflows that require human-in-the-loop approval.
|
|
24
|
+
|
|
25
|
+
1. Install the [1Password desktop app](https://1password.com/downloads/) and sign in to your account in the app.
|
|
26
|
+
2. Select your account or collection at the top of the sidebar, then navigate to **Settings** > **Developer**.
|
|
27
|
+
3. Under Integrate with the 1Password SDKs, select **Integrate with other apps**.
|
|
28
|
+
4. If you want to authenticate with biometrics, navigate to **Settings** > **Security**, then turn on the option to unlock using [Touch ID](https://support.1password.com/touch-id-mac/), [Windows Hello](https://support.1password.com/windows-hello/), or [system authentication](https://support.1password.com/system-authentication-linux/).
|
|
29
|
+
5. Install the 1Password JavaScript SDK in your project:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
## NPM
|
|
33
|
+
npm install @1password/sdk
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
## PNPM
|
|
38
|
+
pnpm add @1password/sdk
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
## Yarn
|
|
43
|
+
yarn add @1password/sdk
|
|
44
|
+
|
|
45
|
+
6. To use the Javascript SDK in your project, replace `your-account-name` in the code below with the name of your 1Password account as it appears at the top left sidebar of the 1Password desktop app.
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
const sdk = require("@1password/sdk");
|
|
49
|
+
|
|
50
|
+
async function main() {
|
|
51
|
+
// Creates an authenticated client.
|
|
52
|
+
const client = await sdk.createClient({
|
|
53
|
+
auth: new sdk.DesktopAuth("your-account-name"),
|
|
54
|
+
// Set the following to your own integration name and version.
|
|
55
|
+
integrationName: "My 1Password Integration",
|
|
56
|
+
integrationVersion: "v1.0.0",
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Fetches a secret.
|
|
60
|
+
const secret = await client.secrets.resolve("op://vault/item/field");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
main()
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Inside `createClient()`, set `integrationName` to the name of your application and `integrationVersion` to the version of your application.
|
|
67
|
+
|
|
68
|
+
Make sure to use [secret reference URIs](https://developer.1password.com/docs/cli/secret-reference-syntax/) with the syntax `op://vault/item/field` to securely load secrets from 1Password into your code.
|
|
69
|
+
|
|
70
|
+
### Option 2: 1Password Service Account
|
|
71
|
+
|
|
72
|
+
[Service account authentication](https://developer.1password.com/docs/sdks/concepts/#1password-service-account) is best for automated access and limiting your integration to least privilege access.
|
|
73
|
+
|
|
74
|
+
1. [Create a service account](https://my.1password.com/developer-tools/infrastructure-secrets/serviceaccount/?source=github-sdk) and give it the appropriate permissions in the vaults where the items you want to use with the SDK are saved.
|
|
75
|
+
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:
|
|
76
|
+
|
|
77
|
+
**macOS or Linux**
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
export OP_SERVICE_ACCOUNT_TOKEN=<your-service-account-token>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Windows**
|
|
84
|
+
|
|
85
|
+
```powershell
|
|
86
|
+
$Env:OP_SERVICE_ACCOUNT_TOKEN = "<your-service-account-token>"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
3. Install the 1Password JavaScript SDK in your project:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
## NPM
|
|
93
|
+
npm install @1password/sdk
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
## PNPM
|
|
98
|
+
pnpm add @1password/sdk
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
## Yarn
|
|
103
|
+
yarn add @1password/sdk
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
4. Use the JavaScript SDK in your project:
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
const sdk = require("@1password/sdk");
|
|
110
|
+
|
|
111
|
+
async function main() {
|
|
112
|
+
// Creates an authenticated client.
|
|
113
|
+
const client = await sdk.createClient({
|
|
114
|
+
auth: process.env.OP_SERVICE_ACCOUNT_TOKEN,
|
|
115
|
+
// Set the following to your own integration name and version.
|
|
116
|
+
integrationName: "My 1Password Integration",
|
|
117
|
+
integrationVersion: "v1.0.0",
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Fetches a secret.
|
|
121
|
+
const secret = await client.secrets.resolve("op://vault/item/field");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
main()
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Make sure to use [secret reference URIs](https://developer.1password.com/docs/cli/secret-reference-syntax/) with the syntax `op://vault/item/field` to securely load secrets from 1Password into your code.
|
|
128
|
+
|
|
129
|
+
Inside `createClient()`, set `integrationName` to the name of your application and `integrationVersion` to the version of your application.
|
|
130
|
+
|
|
131
|
+
## Supported functionality
|
|
132
|
+
|
|
133
|
+
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.
|
|
134
|
+
|
|
135
|
+
### Item management
|
|
136
|
+
|
|
137
|
+
**Operations:**
|
|
138
|
+
|
|
139
|
+
- [x] [Retrieve secrets](https://developer.1password.com/docs/sdks/load-secrets)
|
|
140
|
+
- [Read 1Password Environments (beta)](https://developer.1password.com/docs/sdks/environments)
|
|
141
|
+
- [x] [Retrieve items](https://developer.1password.com/docs/sdks/manage-items#get-an-item)
|
|
142
|
+
- [x] [Create items](https://developer.1password.com/docs/sdks/manage-items#create-an-item)
|
|
143
|
+
- [x] [Update items](https://developer.1password.com/docs/sdks/manage-items#update-an-item)
|
|
144
|
+
- [x] [Delete items](https://developer.1password.com/docs/sdks/manage-items#delete-an-item)
|
|
145
|
+
- [x] [Archive items](https://developer.1password.com/docs/sdks/manage-items/#archive-an-item)
|
|
146
|
+
- [x] [List items](https://developer.1password.com/docs/sdks/list-vaults-items/)
|
|
147
|
+
- [x] [Share items](https://developer.1password.com/docs/sdks/share-items)
|
|
148
|
+
- [x] [Generate PIN, random and memorable passwords](https://developer.1password.com/docs/sdks/manage-items#generate-a-password)
|
|
149
|
+
|
|
150
|
+
**Field types:**
|
|
151
|
+
|
|
152
|
+
- [x] API Keys
|
|
153
|
+
- [x] Passwords
|
|
154
|
+
- [x] Concealed fields
|
|
155
|
+
- [x] Text fields
|
|
156
|
+
- [x] Notes
|
|
157
|
+
- [x] SSH private keys, public keys, fingerprint and key type
|
|
158
|
+
- [x] One-time passwords
|
|
159
|
+
- [x] URLs
|
|
160
|
+
- [x] Websites (used to suggest and autofill logins)
|
|
161
|
+
- [x] Phone numbers
|
|
162
|
+
- [x] Credit card types
|
|
163
|
+
- [x] Credit card numbers
|
|
164
|
+
- [x] Emails
|
|
165
|
+
- [x] References to other items
|
|
166
|
+
- [x] Address
|
|
167
|
+
- [x] Date
|
|
168
|
+
- [x] MM/YY
|
|
169
|
+
- [x] File attachments and Document items
|
|
170
|
+
- [x] Menu
|
|
171
|
+
- [ ] Passkeys
|
|
172
|
+
|
|
173
|
+
### Vault management
|
|
174
|
+
|
|
175
|
+
- [x] [Retrieve vaults](https://developer.1password.com/docs/sdks/vaults#get-a-vault-overview)
|
|
176
|
+
- [x] [Create vaults](https://developer.1password.com/docs/sdks/vaults#create-a-vault)
|
|
177
|
+
- [x] [Update vaults](https://developer.1password.com/docs/sdks/vaults#update-a-vault)
|
|
178
|
+
- [x] [Delete vaults](https://developer.1password.com/docs/sdks/vaults#delete-a-vault)
|
|
179
|
+
- [x] [List vaults](https://developer.1password.com/docs/sdks/list-vaults-items#list-vaults)
|
|
180
|
+
- [x] [Manage group vault permissions](https://developer.1password.com/docs/sdks/vault-permissions)
|
|
181
|
+
- [ ] Manage user vault permissions
|
|
182
|
+
|
|
183
|
+
### User & access management
|
|
184
|
+
|
|
185
|
+
- [ ] Provision users
|
|
186
|
+
- [ ] Retrieve users
|
|
187
|
+
- [ ] List users
|
|
188
|
+
- [ ] Suspend users
|
|
189
|
+
- [x] [Retrieve groups](https://developer.1password.com/docs/sdks/groups/)
|
|
190
|
+
- [ ] List groups
|
|
191
|
+
- [ ] Create groups
|
|
192
|
+
- [ ] Update group membership
|
|
193
|
+
|
|
194
|
+
## Environments management
|
|
195
|
+
|
|
196
|
+
- [x] [Read 1Password Environments](/docs/sdks/environments) (beta)
|
|
197
|
+
|
|
198
|
+
### Compliance & reporting
|
|
199
|
+
|
|
200
|
+
- [ ] Watchtower insights
|
|
201
|
+
- [ ] Travel mode
|
|
202
|
+
- [ ] Events. For now, use [1Password Events Reporting API](https://developer.1password.com/docs/events-api/) directly.
|
|
203
|
+
|
|
204
|
+
### Authentication
|
|
205
|
+
|
|
206
|
+
- [x] [1Password Service Accounts](https://developer.1password.com/docs/sdks/concepts#1password-service-account)
|
|
207
|
+
- [x] [User authentication](https://developer.1password.com/docs/sdks/concepts#1password-desktop-app)
|
|
208
|
+
- [ ] 1Password Connect. For now, use [1Password/connect-sdk-js](https://github.com/1Password/connect-sdk-js).
|
|
209
|
+
|
|
210
|
+
## 📖 Learn more
|
|
211
|
+
|
|
212
|
+
- [Load secrets](https://developer.1password.com/docs/sdks/load-secrets)
|
|
213
|
+
- [Manage items](https://developer.1password.com/docs/sdks/manage-items)
|
|
214
|
+
- [Manage files](https://developer.1password.com/docs/sdks/files)
|
|
215
|
+
- [Share items](https://developer.1password.com/docs/sdks/share-items)
|
|
216
|
+
- [List vaults and items](https://developer.1password.com/docs/sdks/list-vaults-items)
|
|
217
|
+
- [Manage vaults](https://developer.1password.com/docs/sdks/vaults)
|
|
218
|
+
- [Manage vault permissions](https://developer.1password.com/docs/sdks/vault-permissions)
|
|
219
|
+
- [Manage groups](https://developer.1password.com/docs/sdks/groups)
|
|
220
|
+
- [1Password SDK concepts](https://developer.1password.com/docs/sdks/concepts)
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { InnerClient } from "./core.js";
|
|
2
|
+
import { SecretsApi } from "./secrets.js";
|
|
3
|
+
import { ItemsApi } from "./items.js";
|
|
4
|
+
import { VaultsApi } from "./vaults.js";
|
|
5
|
+
import { EnvironmentsApi } from "./environments.js";
|
|
6
|
+
import { GroupsApi } from "./groups.js";
|
|
7
|
+
import { CredentialBrokerApi, OAuthCredentialBrokerApi } from "./credential_broker.js";
|
|
8
|
+
export declare class Client {
|
|
9
|
+
secrets: SecretsApi;
|
|
10
|
+
items: ItemsApi;
|
|
11
|
+
vaults: VaultsApi;
|
|
12
|
+
environments: EnvironmentsApi;
|
|
13
|
+
groups: GroupsApi;
|
|
14
|
+
constructor(innerClient: InnerClient);
|
|
15
|
+
}
|
|
16
|
+
export declare class OidcClient {
|
|
17
|
+
credentialBroker: CredentialBrokerApi;
|
|
18
|
+
constructor(innerClient: InnerClient);
|
|
19
|
+
}
|
|
20
|
+
export declare class OAuthClient {
|
|
21
|
+
credentialBroker: OAuthCredentialBrokerApi;
|
|
22
|
+
constructor(innerClient: InnerClient);
|
|
23
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Code generated by op-codegen - DO NOT EDIT MANUALLY
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.OAuthClient = exports.OidcClient = exports.Client = void 0;
|
|
5
|
+
const secrets_js_1 = require("./secrets.js");
|
|
6
|
+
const items_js_1 = require("./items.js");
|
|
7
|
+
const vaults_js_1 = require("./vaults.js");
|
|
8
|
+
const environments_js_1 = require("./environments.js");
|
|
9
|
+
const groups_js_1 = require("./groups.js");
|
|
10
|
+
const credential_broker_js_1 = require("./credential_broker.js");
|
|
11
|
+
class Client {
|
|
12
|
+
constructor(innerClient) {
|
|
13
|
+
this.secrets = new secrets_js_1.Secrets(innerClient);
|
|
14
|
+
this.items = new items_js_1.Items(innerClient);
|
|
15
|
+
this.vaults = new vaults_js_1.Vaults(innerClient);
|
|
16
|
+
this.environments = new environments_js_1.Environments(innerClient);
|
|
17
|
+
this.groups = new groups_js_1.Groups(innerClient);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Client = Client;
|
|
21
|
+
class OidcClient {
|
|
22
|
+
constructor(innerClient) {
|
|
23
|
+
this.credentialBroker = new credential_broker_js_1.CredentialBroker(innerClient);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.OidcClient = OidcClient;
|
|
27
|
+
class OAuthClient {
|
|
28
|
+
constructor(innerClient) {
|
|
29
|
+
this.credentialBroker = new credential_broker_js_1.OAuthCredentialBroker(innerClient);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.OAuthClient = OAuthClient;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SharedCore } from "./core.js";
|
|
2
|
+
import { ClientConfiguration, OidcClientConfiguration, OAuthClientConfiguration } from "./configuration.js";
|
|
3
|
+
import { Client, OAuthClient, OidcClient } from "./client.js";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a 1Password SDK client with a given core implementation.
|
|
6
|
+
* @returns The authenticated 1Password SDK client.
|
|
7
|
+
*/
|
|
8
|
+
export declare const createClientWithCore: (config: ClientConfiguration, core: SharedCore) => Promise<Client>;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a 1Password OIDC client with a given core implementation.
|
|
11
|
+
* @returns The authenticated 1Password OIDC client.
|
|
12
|
+
*/
|
|
13
|
+
export declare const createOidcClientWithCore: (config: OidcClientConfiguration, core: SharedCore) => Promise<OidcClient>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a 1Password OAuth client with a given core implementation.
|
|
16
|
+
* @returns The authenticated 1Password OAuth client.
|
|
17
|
+
*/
|
|
18
|
+
export declare const createOAuthClientWithCore: (config: OAuthClientConfiguration, core: SharedCore) => Promise<OAuthClient>;
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createOAuthClientWithCore = exports.createOidcClientWithCore = exports.createClientWithCore = void 0;
|
|
13
|
+
const core_js_1 = require("./core.js");
|
|
14
|
+
const configuration_js_1 = require("./configuration.js");
|
|
15
|
+
const client_js_1 = require("./client.js");
|
|
16
|
+
const shared_lib_core_js_1 = require("./shared_lib_core.js");
|
|
17
|
+
const finalizationRegistry = new FinalizationRegistry((heldClient) => {
|
|
18
|
+
heldClient.core.releaseClient(heldClient.id);
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Creates a 1Password SDK client with a given core implementation.
|
|
22
|
+
* @returns The authenticated 1Password SDK client.
|
|
23
|
+
*/
|
|
24
|
+
const createClientWithCore = (config, core) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const authConfig = (0, configuration_js_1.clientAuthConfig)(config);
|
|
26
|
+
if (authConfig.accountName) {
|
|
27
|
+
core.setInner(new shared_lib_core_js_1.SharedLibCore(authConfig.accountName));
|
|
28
|
+
}
|
|
29
|
+
const clientId = yield core.initClient(authConfig);
|
|
30
|
+
const inner = new core_js_1.StandardClient(parseInt(clientId, 10), core, authConfig);
|
|
31
|
+
const client = new client_js_1.Client(inner);
|
|
32
|
+
// Cleans up associated memory from core when client instance goes out of scope.
|
|
33
|
+
finalizationRegistry.register(client, inner);
|
|
34
|
+
return client;
|
|
35
|
+
});
|
|
36
|
+
exports.createClientWithCore = createClientWithCore;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a 1Password OIDC client with a given core implementation.
|
|
39
|
+
* @returns The authenticated 1Password OIDC client.
|
|
40
|
+
*/
|
|
41
|
+
const createOidcClientWithCore = (config, core) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const clientId = yield core.initClientOidc(config, config.oidcFetcher);
|
|
43
|
+
const inner = new core_js_1.InnerClient(parseInt(clientId, 10), core);
|
|
44
|
+
const client = new client_js_1.OidcClient(inner);
|
|
45
|
+
// Cleans up associated memory from core when client instance goes out of scope.
|
|
46
|
+
finalizationRegistry.register(client, inner);
|
|
47
|
+
return client;
|
|
48
|
+
});
|
|
49
|
+
exports.createOidcClientWithCore = createOidcClientWithCore;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a 1Password OAuth client with a given core implementation.
|
|
52
|
+
* @returns The authenticated 1Password OAuth client.
|
|
53
|
+
*/
|
|
54
|
+
const createOAuthClientWithCore = (config, core) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
// ClientConfig is untagged in the Rust core. Passing only integrationKey and
|
|
56
|
+
// accessToken to init_client selects its ClientConfig::Oauth variant.
|
|
57
|
+
const clientId = yield core.initClient(config);
|
|
58
|
+
const inner = new core_js_1.InnerClient(parseInt(clientId, 10), core);
|
|
59
|
+
const client = new client_js_1.OAuthClient(inner);
|
|
60
|
+
// Cleans up associated memory from core when client instance goes out of scope.
|
|
61
|
+
finalizationRegistry.register(client, inner);
|
|
62
|
+
return client;
|
|
63
|
+
});
|
|
64
|
+
exports.createOAuthClientWithCore = createOAuthClientWithCore;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ClientAuthConfig, WorkloadDetails } from "./core.js";
|
|
2
|
+
export declare const LANGUAGE = "JS";
|
|
3
|
+
export declare const VERSION = "0000000";
|
|
4
|
+
interface BaseClientConfiguration {
|
|
5
|
+
integrationName: string;
|
|
6
|
+
integrationVersion: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ClientConfiguration extends BaseClientConfiguration {
|
|
9
|
+
auth: Auth;
|
|
10
|
+
}
|
|
11
|
+
export interface OidcClientConfiguration extends BaseClientConfiguration {
|
|
12
|
+
oidcFetcher: (audience: string) => Promise<string>;
|
|
13
|
+
workloadDetails: WorkloadDetails;
|
|
14
|
+
}
|
|
15
|
+
export interface OAuthClientConfiguration {
|
|
16
|
+
accessToken: string;
|
|
17
|
+
integrationKey: string;
|
|
18
|
+
}
|
|
19
|
+
type Auth = string | DesktopAuth;
|
|
20
|
+
/**
|
|
21
|
+
* Setting that specifies a client should use the desktop app to authenticate. Set accountName to your 1Password account name as shown at the top left sidebar of the app, or your account UUID.
|
|
22
|
+
*/
|
|
23
|
+
export declare class DesktopAuth {
|
|
24
|
+
accountName: string;
|
|
25
|
+
constructor(accountName: string);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a default client configuration.
|
|
29
|
+
* @returns The client configuration to instantiate the client with.
|
|
30
|
+
*/
|
|
31
|
+
export declare const clientAuthConfig: (userConfig: ClientConfiguration) => ClientAuthConfig;
|
|
32
|
+
export declare const getOsName: () => string;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getOsName = exports.clientAuthConfig = exports.DesktopAuth = 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;
|
|
11
|
+
/**
|
|
12
|
+
* Setting that specifies a client should use the desktop app to authenticate. Set accountName to your 1Password account name as shown at the top left sidebar of the app, or your account UUID.
|
|
13
|
+
*/
|
|
14
|
+
class DesktopAuth {
|
|
15
|
+
constructor(accountName) {
|
|
16
|
+
this.accountName = accountName;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DesktopAuth = DesktopAuth;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a default client configuration.
|
|
22
|
+
* @returns The client configuration to instantiate the client with.
|
|
23
|
+
*/
|
|
24
|
+
const clientAuthConfig = (userConfig) => {
|
|
25
|
+
// TODO: Add logic for computing the correct sanitized version value for each platform
|
|
26
|
+
const defaultOsVersion = "0.0.0";
|
|
27
|
+
let serviceAccountToken;
|
|
28
|
+
let accountName;
|
|
29
|
+
if (typeof userConfig.auth === "string") {
|
|
30
|
+
serviceAccountToken = userConfig.auth;
|
|
31
|
+
}
|
|
32
|
+
else if (userConfig.auth instanceof DesktopAuth) {
|
|
33
|
+
accountName = userConfig.auth.accountName;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
serviceAccountToken: serviceAccountToken !== null && serviceAccountToken !== void 0 ? serviceAccountToken : "",
|
|
37
|
+
accountName,
|
|
38
|
+
programmingLanguage: exports.LANGUAGE,
|
|
39
|
+
sdkVersion: exports.VERSION,
|
|
40
|
+
integrationName: userConfig.integrationName,
|
|
41
|
+
integrationVersion: userConfig.integrationVersion,
|
|
42
|
+
requestLibraryName: "Fetch API",
|
|
43
|
+
requestLibraryVersion: "Fetch API",
|
|
44
|
+
os: (0, exports.getOsName)(),
|
|
45
|
+
osVersion: defaultOsVersion,
|
|
46
|
+
architecture: os_1.default.arch(),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
exports.clientAuthConfig = clientAuthConfig;
|
|
50
|
+
const getOsName = () => {
|
|
51
|
+
// Only supported on Node.js
|
|
52
|
+
const os_name = os_1.default.type().toLowerCase();
|
|
53
|
+
if (os_name === "windows_nt") {
|
|
54
|
+
return "windows";
|
|
55
|
+
}
|
|
56
|
+
return os_name;
|
|
57
|
+
};
|
|
58
|
+
exports.getOsName = getOsName;
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { OidcClientConfiguration, OAuthClientConfiguration } from "./configuration.js";
|
|
2
|
+
/**
|
|
3
|
+
* Exposes the SDK core to the host JS SDK.
|
|
4
|
+
*/
|
|
5
|
+
export interface Core {
|
|
6
|
+
/**
|
|
7
|
+
* Allocates a new authenticated client and returns its id.
|
|
8
|
+
*/
|
|
9
|
+
initClient(config: string): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Allocates a new authenticated client using an OIDC token fetcher and returns its id.
|
|
12
|
+
*/
|
|
13
|
+
initClientOidc(config: string, fetcher: (audience: string) => Promise<string>): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Calls async business logic from a given client and returns the result.
|
|
16
|
+
*/
|
|
17
|
+
invoke(config: string): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Deallocates memory held by the given client in the SDK core when it goes out of scope.
|
|
20
|
+
*/
|
|
21
|
+
releaseClient(clientId: string): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Wraps configuration information needed to allocate and authenticate a client instance and sends it to the SDK core.
|
|
25
|
+
*/
|
|
26
|
+
export interface ClientAuthConfig {
|
|
27
|
+
programmingLanguage: string;
|
|
28
|
+
sdkVersion: string;
|
|
29
|
+
integrationName: string;
|
|
30
|
+
integrationVersion: string;
|
|
31
|
+
requestLibraryName: string;
|
|
32
|
+
requestLibraryVersion: string;
|
|
33
|
+
os: string;
|
|
34
|
+
osVersion: string;
|
|
35
|
+
architecture: string;
|
|
36
|
+
serviceAccountToken?: string;
|
|
37
|
+
accountName?: string;
|
|
38
|
+
workloadDetails?: WorkloadDetails;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Contains workload authentication details for OIDC-based workload identity.
|
|
42
|
+
*/
|
|
43
|
+
export interface WorkloadDetails {
|
|
44
|
+
customerManagedSecret: string;
|
|
45
|
+
workloadUuid: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Contains the information sent to the SDK core when you call (invoke) a function.
|
|
49
|
+
*/
|
|
50
|
+
export interface InvokeConfig {
|
|
51
|
+
/**
|
|
52
|
+
* Identifies the client instance for which you called the function.
|
|
53
|
+
*/
|
|
54
|
+
invocation: Invocation;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Calls certain logic from the SDK core, with the given parameters.
|
|
58
|
+
*/
|
|
59
|
+
interface Invocation {
|
|
60
|
+
/**
|
|
61
|
+
* Identifies the client instance for which you called the function.
|
|
62
|
+
*/
|
|
63
|
+
clientId?: number;
|
|
64
|
+
parameters: Parameters;
|
|
65
|
+
}
|
|
66
|
+
export interface Parameters {
|
|
67
|
+
/**
|
|
68
|
+
* Functionality name
|
|
69
|
+
*/
|
|
70
|
+
name: string;
|
|
71
|
+
/**
|
|
72
|
+
* Parameters
|
|
73
|
+
*/
|
|
74
|
+
parameters: {
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export declare class WasmCore implements Core {
|
|
79
|
+
initClient(config: string): Promise<string>;
|
|
80
|
+
initClientOidc(config: string, fetcher: (audience: string) => Promise<string>): Promise<string>;
|
|
81
|
+
invoke(config: string): Promise<string>;
|
|
82
|
+
releaseClient(clientId: string): void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* An implementation of the `Core` interface that shares resources across all clients.
|
|
86
|
+
*/
|
|
87
|
+
export declare class SharedCore {
|
|
88
|
+
private inner;
|
|
89
|
+
constructor();
|
|
90
|
+
setInner(core: Core): void;
|
|
91
|
+
initClient(config: ClientAuthConfig | OAuthClientConfiguration): Promise<string>;
|
|
92
|
+
initClientOidc(config: OidcClientConfiguration, fetcher: (audience: string) => Promise<string>): Promise<string>;
|
|
93
|
+
invoke(config: InvokeConfig): Promise<string>;
|
|
94
|
+
invoke_sync(config: InvokeConfig): string;
|
|
95
|
+
releaseClient(clientId: number): void;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Represents the client instance on which a call is made.
|
|
99
|
+
*/
|
|
100
|
+
export declare class InnerClient {
|
|
101
|
+
id: number;
|
|
102
|
+
readonly core: SharedCore;
|
|
103
|
+
constructor(id: number, core: SharedCore);
|
|
104
|
+
invoke(config: InvokeConfig): Promise<string>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A token- or desktop-authenticated client. It retains the auth config so it can
|
|
108
|
+
* transparently re-initialize after a desktop session expires.
|
|
109
|
+
*/
|
|
110
|
+
export declare class StandardClient extends InnerClient {
|
|
111
|
+
config: ClientAuthConfig;
|
|
112
|
+
constructor(id: number, core: SharedCore, config: ClientAuthConfig);
|
|
113
|
+
invoke(config: InvokeConfig): Promise<string>;
|
|
114
|
+
}
|
|
115
|
+
export {};
|