@1password/sdk 0.4.0 → 0.5.0-beta.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 CHANGED
@@ -135,9 +135,16 @@ Field types:
135
135
  ### Authentication
136
136
 
137
137
  - [x] [1Password Service Accounts](https://developer.1password.com/docs/service-accounts/get-started/)
138
+ - [x] [Workload identity](#workload-identity-beta) (beta)
138
139
  - [ ] User authentication
139
140
  - [ ] 1Password Connect. For now, use [1Password/connect-sdk-js](https://github.com/1Password/connect-sdk-js).
140
141
 
142
+ ### Workload identity (beta)
143
+
144
+ > **Private beta.** Currently available for GitHub Actions via 1Password Credential Broker.
145
+
146
+ Instead of a service account token, you can authenticate a workload by providing an OIDC token fetcher and your workload details. The SDK calls your `oidcFetcher` to obtain a token when it needs one.
147
+
141
148
  ## 📖 Learn more
142
149
 
143
150
  - [Load secrets with 1Password SDKs](https://developer.1password.com/docs/sdks/load-secrets)
package/dist/client.d.ts CHANGED
@@ -2,11 +2,13 @@ import { InnerClient } from "./core.js";
2
2
  import { SecretsApi } from "./secrets.js";
3
3
  import { ItemsApi } from "./items.js";
4
4
  import { VaultsApi } from "./vaults.js";
5
+ import { EnvironmentsApi } from "./environments.js";
5
6
  import { GroupsApi } from "./groups.js";
6
7
  export declare class Client {
7
8
  secrets: SecretsApi;
8
9
  items: ItemsApi;
9
10
  vaults: VaultsApi;
11
+ environments: EnvironmentsApi;
10
12
  groups: GroupsApi;
11
13
  constructor(innerClient: InnerClient);
12
14
  }
package/dist/client.js CHANGED
@@ -5,12 +5,14 @@ exports.Client = void 0;
5
5
  const secrets_js_1 = require("./secrets.js");
6
6
  const items_js_1 = require("./items.js");
7
7
  const vaults_js_1 = require("./vaults.js");
8
+ const environments_js_1 = require("./environments.js");
8
9
  const groups_js_1 = require("./groups.js");
9
10
  class Client {
10
11
  constructor(innerClient) {
11
12
  this.secrets = new secrets_js_1.Secrets(innerClient);
12
13
  this.items = new items_js_1.Items(innerClient);
13
14
  this.vaults = new vaults_js_1.Vaults(innerClient);
15
+ this.environments = new environments_js_1.Environments(innerClient);
14
16
  this.groups = new groups_js_1.Groups(innerClient);
15
17
  }
16
18
  }
@@ -22,11 +22,19 @@ const finalizationRegistry = new FinalizationRegistry((heldClient) => {
22
22
  * @returns The authenticated 1Password SDK client.
23
23
  */
24
24
  const createClientWithCore = (config, core) => __awaiter(void 0, void 0, void 0, function* () {
25
+ if (!config.auth && !config.oidcFetcher) {
26
+ throw new Error("createClient requires either `auth` (service account token) or `oidcFetcher` (workload identity).");
27
+ }
28
+ if (config.oidcFetcher && !config.workloadDetails) {
29
+ throw new Error("`oidcFetcher` (workload identity) requires `workloadDetails` to be set.");
30
+ }
25
31
  const authConfig = (0, configuration_js_1.clientAuthConfig)(config);
26
32
  if (authConfig.accountName) {
27
33
  core.setInner(new shared_lib_core_js_1.SharedLibCore(authConfig.accountName));
28
34
  }
29
- const clientId = yield core.initClient(authConfig);
35
+ const clientId = config.oidcFetcher
36
+ ? yield core.initClientOidc(authConfig, config.oidcFetcher)
37
+ : yield core.initClient(authConfig);
30
38
  const inner = new core_js_1.InnerClient(parseInt(clientId, 10), core, authConfig);
31
39
  const client = new client_js_1.Client(inner);
32
40
  // Cleans up associated memory from core when client instance goes out of scope.
@@ -1,10 +1,12 @@
1
- import { ClientAuthConfig } from "./core.js";
1
+ import { ClientAuthConfig, WorkloadDetails } from "./core.js";
2
2
  export declare const LANGUAGE = "JS";
3
- export declare const VERSION = "0040003";
3
+ export declare const VERSION = "0050001";
4
4
  export interface ClientConfiguration {
5
- auth: Auth;
5
+ auth?: Auth;
6
6
  integrationName: string;
7
7
  integrationVersion: string;
8
+ oidcFetcher?: (audience: string) => Promise<string>;
9
+ workloadDetails?: WorkloadDetails;
8
10
  }
9
11
  type Auth = string | DesktopAuth;
10
12
  /**
@@ -44,6 +44,7 @@ const clientAuthConfig = (userConfig) => {
44
44
  os: (0, exports.getOsName)(),
45
45
  osVersion: defaultOsVersion,
46
46
  architecture: os_1.default.arch(),
47
+ workloadDetails: userConfig.workloadDetails,
47
48
  };
48
49
  };
49
50
  exports.clientAuthConfig = clientAuthConfig;
package/dist/core.d.ts CHANGED
@@ -6,6 +6,10 @@ export interface Core {
6
6
  * Allocates a new authenticated client and returns its id.
7
7
  */
8
8
  initClient(config: string): Promise<string>;
9
+ /**
10
+ * Allocates a new authenticated client using an OIDC token fetcher and returns its id.
11
+ */
12
+ initClientOidc(config: string, fetcher: (audience: string) => Promise<string>): Promise<string>;
9
13
  /**
10
14
  * Calls async business logic from a given client and returns the result.
11
15
  */
@@ -30,6 +34,14 @@ export interface ClientAuthConfig {
30
34
  architecture: string;
31
35
  serviceAccountToken?: string;
32
36
  accountName?: string;
37
+ workloadDetails?: WorkloadDetails;
38
+ }
39
+ /**
40
+ * Contains workload authentication details for OIDC-based workload identity.
41
+ */
42
+ export interface WorkloadDetails {
43
+ customerManagedSecret: string;
44
+ workloadUuid: string;
33
45
  }
34
46
  /**
35
47
  * Contains the information sent to the SDK core when you call (invoke) a function.
@@ -64,6 +76,7 @@ export interface Parameters {
64
76
  }
65
77
  export declare class WasmCore implements Core {
66
78
  initClient(config: string): Promise<string>;
79
+ initClientOidc(config: string, fetcher: (audience: string) => Promise<string>): Promise<string>;
67
80
  invoke(config: string): Promise<string>;
68
81
  releaseClient(clientId: string): void;
69
82
  }
@@ -75,6 +88,7 @@ export declare class SharedCore {
75
88
  constructor();
76
89
  setInner(core: Core): void;
77
90
  initClient(config: ClientAuthConfig): Promise<string>;
91
+ initClientOidc(config: ClientAuthConfig, fetcher: (audience: string) => Promise<string>): Promise<string>;
78
92
  invoke(config: InvokeConfig): Promise<string>;
79
93
  invoke_sync(config: InvokeConfig): string;
80
94
  releaseClient(clientId: number): void;
package/dist/core.js CHANGED
@@ -28,6 +28,16 @@ class WasmCore {
28
28
  }
29
29
  });
30
30
  }
31
+ initClientOidc(config, fetcher) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ try {
34
+ return yield (0, sdk_core_1.init_client_oidc)(config, fetcher);
35
+ }
36
+ catch (e) {
37
+ (0, errors_1.throwError)(e);
38
+ }
39
+ });
40
+ }
31
41
  invoke(config) {
32
42
  return __awaiter(this, void 0, void 0, function* () {
33
43
  try {
@@ -64,6 +74,12 @@ class SharedCore {
64
74
  return this.inner.initClient(serializedConfig);
65
75
  });
66
76
  }
77
+ initClientOidc(config, fetcher) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const serializedConfig = JSON.stringify(config);
80
+ return this.inner.initClientOidc(serializedConfig, fetcher);
81
+ });
82
+ }
67
83
  invoke(config) {
68
84
  return __awaiter(this, void 0, void 0, function* () {
69
85
  const serializedConfig = JSON.stringify(config, types_1.ReplacerFunc);
@@ -0,0 +1,19 @@
1
+ import { InnerClient } from "./core.js";
2
+ import { GetVariablesResponse } from "./types.js";
3
+ /**
4
+ * The Environments API holds all the operations the SDK client can perform on 1Password Environments.
5
+ */
6
+ export interface EnvironmentsApi {
7
+ /**
8
+ * Get environment variables belonging to an Environment.
9
+ */
10
+ getVariables(environmentId: string): Promise<GetVariablesResponse>;
11
+ }
12
+ export declare class Environments implements EnvironmentsApi {
13
+ #private;
14
+ constructor(inner: InnerClient);
15
+ /**
16
+ * Get environment variables belonging to an Environment.
17
+ */
18
+ getVariables(environmentId: string): Promise<GetVariablesResponse>;
19
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ // Code generated by op-codegen - DO NOT EDIT MANUALLY
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
13
+ if (kind === "m") throw new TypeError("Private method is not writable");
14
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
15
+ 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");
16
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
17
+ };
18
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
19
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
20
+ 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");
21
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
22
+ };
23
+ var _Environments_inner;
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.Environments = void 0;
26
+ const types_js_1 = require("./types.js");
27
+ class Environments {
28
+ constructor(inner) {
29
+ _Environments_inner.set(this, void 0);
30
+ __classPrivateFieldSet(this, _Environments_inner, inner, "f");
31
+ }
32
+ /**
33
+ * Get environment variables belonging to an Environment.
34
+ */
35
+ getVariables(environmentId) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const invocationConfig = {
38
+ invocation: {
39
+ clientId: __classPrivateFieldGet(this, _Environments_inner, "f").id,
40
+ parameters: {
41
+ name: "EnvironmentsGetVariables",
42
+ parameters: {
43
+ environment_id: environmentId,
44
+ },
45
+ },
46
+ },
47
+ };
48
+ return JSON.parse(yield __classPrivateFieldGet(this, _Environments_inner, "f").invoke(invocationConfig), types_js_1.ReviverFunc);
49
+ });
50
+ }
51
+ }
52
+ exports.Environments = Environments;
53
+ _Environments_inner = new WeakMap();
@@ -11,6 +11,7 @@ export declare class SharedLibCore implements Core {
11
11
  */
12
12
  private callSharedLibrary;
13
13
  initClient(config: string): Promise<string>;
14
+ initClientOidc(config: string, _fetcher: (audience: string) => Promise<string>): Promise<string>;
14
15
  invoke(invokeConfigBytes: string): Promise<string>;
15
16
  releaseClient(clientId: string): void;
16
17
  }
@@ -163,6 +163,12 @@ class SharedLibCore {
163
163
  return this.callSharedLibrary(config, "init_client");
164
164
  });
165
165
  }
166
+ // eslint-disable-next-line @typescript-eslint/require-await
167
+ initClientOidc(config, _fetcher) {
168
+ return __awaiter(this, void 0, void 0, function* () {
169
+ throw new Error("OIDC authentication is not supported with desktop auth");
170
+ });
171
+ }
166
172
  invoke(invokeConfigBytes) {
167
173
  return __awaiter(this, void 0, void 0, function* () {
168
174
  return this.callSharedLibrary(invokeConfigBytes, "invoke");
package/dist/types.d.ts CHANGED
@@ -18,6 +18,15 @@ export interface DocumentCreateParams {
18
18
  /** The content of the file */
19
19
  content: Uint8Array;
20
20
  }
21
+ /** Represents an environment variable (name:value pair) and its masked state */
22
+ export interface EnvironmentVariable {
23
+ /** An environment variable's name */
24
+ name: string;
25
+ /** An environment variable's value */
26
+ value: string;
27
+ /** An environment variable's masked state */
28
+ masked: boolean;
29
+ }
21
30
  export interface FileAttributes {
22
31
  /** The name of the file */
23
32
  name: string;
@@ -44,6 +53,11 @@ export interface GeneratePasswordResponse {
44
53
  /** The generated password. */
45
54
  password: string;
46
55
  }
56
+ /** Response containing the full set of environment variables from an Environment. */
57
+ export interface GetVariablesResponse {
58
+ /** List of environment variables. */
59
+ variables: EnvironmentVariable[];
60
+ }
47
61
  export declare enum GroupType {
48
62
  /**
49
63
  * The owners group, which gives the following permissions:
@@ -93,7 +107,8 @@ export declare enum GroupState {
93
107
  }
94
108
  export declare enum VaultAccessorType {
95
109
  User = "user",
96
- Group = "group"
110
+ Group = "group",
111
+ Broker = "broker"
97
112
  }
98
113
  /** Represents the vault access information. */
99
114
  export interface VaultAccess {
@@ -605,7 +620,7 @@ export interface Vault {
605
620
  activeItemCount: number;
606
621
  /** The content version number of the vault. It gets incremented whenever the state of the vault's contents changes (e.g. items from within the vault get created or updated). */
607
622
  contentVersion: number;
608
- /** The attribute version number of the vault. It gets incremented whenever vault presentation information changes, such as its title or icon. */
623
+ /** The attribute version number of the vault. It gets incremented whenever vault presentation information changes, such as its name or icon. */
609
624
  attributeVersion: number;
610
625
  /** The access information associated with the vault. */
611
626
  access?: VaultAccess[];
@@ -637,7 +652,7 @@ export interface VaultOverview {
637
652
  activeItemCount: number;
638
653
  /** The content version number of the vault. It gets incremented whenever the state of the vault's contents changes (e.g. items from within the vault get created or updated). */
639
654
  contentVersion: number;
640
- /** The attribute version number of the vault. It gets incremented whenever vault presentation information changes, such as its title or icon. */
655
+ /** The attribute version number of the vault. It gets incremented whenever vault presentation information changes, such as its name or icon. */
641
656
  attributeVersion: number;
642
657
  /** The time the vault was created at */
643
658
  createdAt: Date;
package/dist/types.js CHANGED
@@ -57,6 +57,7 @@ var VaultAccessorType;
57
57
  (function (VaultAccessorType) {
58
58
  VaultAccessorType["User"] = "user";
59
59
  VaultAccessorType["Group"] = "group";
60
+ VaultAccessorType["Broker"] = "broker";
60
61
  })(VaultAccessorType || (exports.VaultAccessorType = VaultAccessorType = {}));
61
62
  var ItemCategory;
62
63
  (function (ItemCategory) {
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION = "0.4.0";
2
- export declare const SDK_BUILD_NUMBER = "0040003";
1
+ export declare const SDK_VERSION = "0.5.0-beta.1";
2
+ export declare const SDK_BUILD_NUMBER = "0050001";
package/dist/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_BUILD_NUMBER = exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.4.0";
5
- exports.SDK_BUILD_NUMBER = "0040003";
6
- const SDK_CORE_VERSION = "0.4.0";
4
+ exports.SDK_VERSION = "0.5.0-beta.1";
5
+ exports.SDK_BUILD_NUMBER = "0050001";
6
+ const SDK_CORE_VERSION = "0.5.0-beta.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1password/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0-beta.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",
@@ -26,7 +26,7 @@
26
26
  "main": "./dist/sdk.js",
27
27
  "types": "./dist/sdk.d.ts",
28
28
  "dependencies": {
29
- "@1password/sdk-core": "0.4.0"
29
+ "@1password/sdk-core": "0.5.0-beta.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@1password/eslint-config": "^4.0.0",