@1password/sdk 0.1.0-beta.1 → 0.1.0-beta.10

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 ADDED
@@ -0,0 +1,92 @@
1
+ <p align="center">
2
+ <a href="https://1password.com">
3
+ <h1 align="center">1Password JavaScript SDK (beta)</h1>
4
+ </a>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <h4 align="center"> ❗ The 1Password SDK project is in beta. Future iterations may bring backwards-incompatible changes.</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
+ The 1Password JavaScript SDK offers programmatic access to your secrets in 1Password with JavaScript. The SDK currently supports `Node.js`. During the beta, you can create, retrieve, update, and delete items and resolve secret references.
18
+
19
+ ## 🔑 Authentication
20
+
21
+ 1Password SDKs support authentication with [1Password Service Accounts](https://developer.1password.com/docs/service-accounts/get-started/).
22
+
23
+ Before you get started, [create a service account](https://developer.1password.com/docs/service-accounts/get-started/#create-a-service-account) and give it the appropriate permissions in the vaults where the items you want to use with the SDK are saved.
24
+
25
+ ## ❗ Limitations
26
+
27
+ 1Password SDKs don't yet support using secret references with query parameters, so you can't retrieve file attachments or SSH keys, or get more information about field metadata.
28
+
29
+ 1Password SDKs currently only support operations on text and concealed fields. As a result, you can't edit items that include information saved in other types of fields.
30
+
31
+ When managing items with 1Password SDKs, you must use [unique identifiers (IDs)](https://developer.1password.com/docs/sdks/concepts#unique-identifiers) in place of vault, item, and field names.
32
+
33
+ ## 🚀 Get started
34
+
35
+ To use the 1Password JavaScript SDK in your project:
36
+
37
+ 1. Provision your [service account](#authentication) token. We recommend provisioning your token from the environment. For example, to export your token to the `OP_SERVICE_ACCOUNT_TOKEN` environment variable:
38
+
39
+ **macOS or Linux**
40
+
41
+ ```bash
42
+ export OP_SERVICE_ACCOUNT_TOKEN=<your-service-account-token>
43
+ ```
44
+
45
+ **Windows**
46
+
47
+ ```powershell
48
+ $Env:OP_SERVICE_ACCOUNT_TOKEN = "<your-service-account-token>"
49
+ ```
50
+
51
+ 2. Install the 1Password JavaScript SDK in your project:
52
+
53
+ ```bash
54
+ ## NPM
55
+ npm install @1password/sdk@beta
56
+ ```
57
+
58
+ ```bash
59
+ ## PNPM
60
+ pnpm add @1password/sdk@beta
61
+ ```
62
+
63
+ ```bash
64
+ ## Yarn
65
+ yarn add @1password/sdk@beta
66
+ ```
67
+
68
+ 3. Use the JavaScript SDK in your project:
69
+
70
+ ```js
71
+ import { createClient } from "@1password/sdk";
72
+
73
+ // Creates an authenticated client.
74
+ const client = await createClient({
75
+ auth: process.env.OP_SERVICE_ACCOUNT_TOKEN,
76
+ integrationName: "My 1Password Integration",
77
+ integrationVersion: "v1.0.0",
78
+ });
79
+
80
+ // Fetches a secret.
81
+ const secret = await client.secrets.resolve("op://vault/item/field");
82
+ ```
83
+
84
+ 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.
85
+
86
+ Inside `createClient()`, set `integrationName` to the name of your application and `integrationVersion` to the version of your application.
87
+
88
+ ## 📖 Learn more
89
+
90
+ - [Load secrets with 1Password SDKs](https://developer.1password.com/docs/sdks/load-secrets)
91
+ - [Manage items with 1Password SDKs](https://developer.1password.com/docs/sdks/manage-items)
92
+ - [1Password SDK concepts](https://developer.1password.com/docs/sdks/concepts)
package/dist/client.d.ts CHANGED
@@ -1,12 +1,8 @@
1
- import { SecretsAPI } from "./secrets.js";
2
- import { ClientAuthConfig, Core } from "./core.js";
3
- import { ClientConfiguration, InnerClient } from "./configuration.js";
4
- export declare const DEFAULT_INTEGRATION_NAME = "Unknown";
5
- export declare const DEFAULT_INTEGRATION_VERSION = "Unknown";
6
- export declare function createClient(config: ClientConfiguration): Promise<Client>;
7
- export declare function createClientWithCore(config: ClientConfiguration, core: Core): Promise<Client>;
1
+ import { InnerClient } from "./core.js";
2
+ import { SecretsApi } from "./secrets.js";
3
+ import { ItemsApi } from "./items.js";
8
4
  export declare class Client {
9
- secrets: SecretsAPI;
5
+ secrets: SecretsApi;
6
+ items: ItemsApi;
10
7
  constructor(innerClient: InnerClient);
11
8
  }
12
- export declare function createClientAuthConfig(userConfig: ClientConfiguration): ClientAuthConfig;
package/dist/client.js CHANGED
@@ -1,90 +1,12 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
2
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.createClientAuthConfig = exports.Client = exports.createClientWithCore = exports.createClient = exports.DEFAULT_INTEGRATION_VERSION = exports.DEFAULT_INTEGRATION_NAME = void 0;
3
+ exports.Client = void 0;
36
4
  const secrets_js_1 = require("./secrets.js");
37
- const core_js_1 = require("./core.js");
38
- const os = __importStar(require("os"));
39
- exports.DEFAULT_INTEGRATION_NAME = "Unknown";
40
- exports.DEFAULT_INTEGRATION_VERSION = "Unknown";
41
- const LANGUAGE = "JS";
42
- const VERSION = "0010001"; // v0.1.0
43
- const finalizationRegistry = new FinalizationRegistry((heldClientId) => {
44
- const sharedCore = new core_js_1.SharedCore();
45
- sharedCore.releaseClient(heldClientId);
46
- });
47
- function createClient(config) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- return createClientWithCore(config, new core_js_1.SharedCore());
50
- });
51
- }
52
- exports.createClient = createClient;
53
- function createClientWithCore(config, core) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- const authConfig = createClientAuthConfig(config);
56
- const clientID = yield core.initClient(authConfig);
57
- const inner = {
58
- id: parseInt(clientID),
59
- core: core,
60
- };
61
- const client = new Client(inner);
62
- // Cleans up associated memory from core when client instance goes out of scope.
63
- finalizationRegistry.register(client, inner.id);
64
- return client;
65
- });
66
- }
67
- exports.createClientWithCore = createClientWithCore;
68
- // Client represents a client instance of the SDK.
5
+ const items_js_1 = require("./items.js");
69
6
  class Client {
70
7
  constructor(innerClient) {
71
8
  this.secrets = new secrets_js_1.SecretsSource(innerClient);
9
+ this.items = new items_js_1.ItemsSource(innerClient);
72
10
  }
73
11
  }
74
12
  exports.Client = Client;
75
- function createClientAuthConfig(userConfig) {
76
- return {
77
- serviceAccountToken: userConfig.auth,
78
- programmingLanguage: LANGUAGE,
79
- sdkVersion: VERSION,
80
- integrationName: userConfig.integrationName,
81
- integrationVersion: userConfig.integrationVersion,
82
- requestLibraryName: "Fetch API",
83
- requestLibraryVersion: "Fetch API",
84
- // Only supported on Node.js
85
- os: os.type(),
86
- osVersion: os.version(),
87
- architecture: os.arch(),
88
- };
89
- }
90
- exports.createClientAuthConfig = createClientAuthConfig;
@@ -0,0 +1,8 @@
1
+ import { Core } from "./core.js";
2
+ import { ClientConfiguration } from "./configuration.js";
3
+ import { Client } 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: Core) => Promise<Client>;
@@ -0,0 +1,34 @@
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.createClientWithCore = void 0;
13
+ const configuration_js_1 = require("./configuration.js");
14
+ const client_js_1 = require("./client.js");
15
+ const finalizationRegistry = new FinalizationRegistry((heldClient) => {
16
+ heldClient.core.releaseClient(heldClient.id);
17
+ });
18
+ /**
19
+ * Creates a 1Password SDK client with a given core implementation.
20
+ * @returns The authenticated 1Password SDK client.
21
+ */
22
+ const createClientWithCore = (config, core) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const authConfig = (0, configuration_js_1.clientAuthConfig)(config);
24
+ const clientId = yield core.initClient(authConfig);
25
+ const inner = {
26
+ id: parseInt(clientId, 10),
27
+ core,
28
+ };
29
+ const client = new client_js_1.Client(inner);
30
+ // Cleans up associated memory from core when client instance goes out of scope.
31
+ finalizationRegistry.register(client, inner);
32
+ return client;
33
+ });
34
+ exports.createClientWithCore = createClientWithCore;
@@ -1,12 +1,14 @@
1
- import { Core } from "./core.js";
2
- export interface InnerClient {
3
- id: number;
4
- core: Core;
5
- }
1
+ import { ClientAuthConfig } from "./core.js";
6
2
  export interface ClientConfiguration {
7
3
  auth: Auth;
8
4
  integrationName: string;
9
5
  integrationVersion: string;
10
6
  }
11
7
  type Auth = string;
8
+ /**
9
+ * Creates a default client configuration.
10
+ * @returns The client configuration to instantiate the client with.
11
+ */
12
+ export declare const clientAuthConfig: (userConfig: ClientConfiguration) => ClientAuthConfig;
13
+ export declare const getOsName: () => string;
12
14
  export {};
@@ -1,2 +1,59 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
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;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getOsName = exports.clientAuthConfig = void 0;
27
+ const os = __importStar(require("os"));
28
+ const LANGUAGE = "JS";
29
+ const VERSION = "0010009"; // v0.1.0-beta.9
30
+ /**
31
+ * Creates a default client configuration.
32
+ * @returns The client configuration to instantiate the client with.
33
+ */
34
+ const clientAuthConfig = (userConfig) => {
35
+ // TODO: Add logic for computing the correct sanitized version value for each platform
36
+ const defaultOsVersion = "0.0.0";
37
+ return {
38
+ serviceAccountToken: userConfig.auth,
39
+ programmingLanguage: LANGUAGE,
40
+ sdkVersion: VERSION,
41
+ integrationName: userConfig.integrationName,
42
+ integrationVersion: userConfig.integrationVersion,
43
+ requestLibraryName: "Fetch API",
44
+ requestLibraryVersion: "Fetch API",
45
+ os: (0, exports.getOsName)(),
46
+ osVersion: defaultOsVersion,
47
+ architecture: os.arch(),
48
+ };
49
+ };
50
+ exports.clientAuthConfig = clientAuthConfig;
51
+ const getOsName = () => {
52
+ // Only supported on Node.js
53
+ const os_name = os.type().toLowerCase();
54
+ if (os_name === "windows_nt") {
55
+ return "windows";
56
+ }
57
+ return os_name;
58
+ };
59
+ exports.getOsName = getOsName;
package/dist/core.d.ts CHANGED
@@ -1,8 +1,23 @@
1
+ /**
2
+ * Exposes the SDK core to the host JS SDK.
3
+ */
1
4
  export interface Core {
5
+ /**
6
+ * Allocates a new authenticated client and returns its id.
7
+ */
2
8
  initClient(config: ClientAuthConfig): Promise<string>;
9
+ /**
10
+ * Calls business logic from a given client and returns the result.
11
+ */
3
12
  invoke(config: InvokeConfig): Promise<string>;
13
+ /**
14
+ * Deallocates memory held by the given client in the SDK core when it goes out of scope.
15
+ */
4
16
  releaseClient(clientId: number): void;
5
17
  }
18
+ /**
19
+ * Wraps configuration information needed to allocate and authenticate a client instance and sends it to the SDK core.
20
+ */
6
21
  export interface ClientAuthConfig {
7
22
  serviceAccountToken: string;
8
23
  programmingLanguage: string;
@@ -15,17 +30,44 @@ export interface ClientAuthConfig {
15
30
  osVersion: string;
16
31
  architecture: string;
17
32
  }
33
+ /**
34
+ * Contains the information sent to the SDK core when you call (invoke) a function.
35
+ */
18
36
  export interface InvokeConfig {
37
+ /**
38
+ * Identifies the client instance for which you called the function.
39
+ */
19
40
  clientId: number;
20
41
  invocation: Invocation;
21
42
  }
43
+ /**
44
+ * Calls certain logic from the SDK core, with the given parameters.
45
+ */
22
46
  interface Invocation {
47
+ /**
48
+ * Functionality name
49
+ */
23
50
  name: string;
24
- parameters: string;
51
+ /**
52
+ * Parameters
53
+ */
54
+ parameters: {
55
+ [key: string]: unknown;
56
+ };
25
57
  }
58
+ /**
59
+ * An implementation of the `Core` interface that shares resources across all clients.
60
+ */
26
61
  export declare class SharedCore implements Core {
27
62
  initClient(config: ClientAuthConfig): Promise<string>;
28
63
  invoke(config: InvokeConfig): Promise<string>;
29
64
  releaseClient(clientId: number): void;
30
65
  }
66
+ /**
67
+ * Represents the client instance on which a call is made.
68
+ */
69
+ export interface InnerClient {
70
+ id: number;
71
+ core: Core;
72
+ }
31
73
  export {};
package/dist/core.js CHANGED
@@ -11,7 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SharedCore = void 0;
13
13
  const sdk_core_1 = require("@1password/sdk-core");
14
- // An implementation of the `Core` interface that shares resources across all clients.
14
+ /**
15
+ * An implementation of the `Core` interface that shares resources across all clients.
16
+ */
15
17
  class SharedCore {
16
18
  initClient(config) {
17
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -0,0 +1,28 @@
1
+ import { InnerClient } from "./core.js";
2
+ import * as types from "./types.js";
3
+ export interface ItemsApi {
4
+ /**
5
+ * Create a new item
6
+ */
7
+ create(item: types.Item): Promise<types.Item>;
8
+ /**
9
+ * Get an item by vault and item ID
10
+ */
11
+ get(vaultId: string, itemId: string): Promise<types.Item>;
12
+ /**
13
+ * Update an existing item. Warning: Only text and concealed fields are currently supported. Other fields will be permanently lost when you update an item.
14
+ */
15
+ update(item: types.Item): Promise<types.Item>;
16
+ /**
17
+ * Delete an item. Warning: Information saved in fields other than text and concealed fields will be permanently lost.
18
+ */
19
+ delete(vaultId: string, itemId: string): Promise<void>;
20
+ }
21
+ export declare class ItemsSource implements ItemsApi {
22
+ #private;
23
+ constructor(inner: InnerClient);
24
+ create(item: types.Item): Promise<types.Item>;
25
+ get(vaultId: string, itemId: string): Promise<types.Item>;
26
+ update(item: types.Item): Promise<types.Item>;
27
+ delete(vaultId: string, itemId: string): Promise<void>;
28
+ }
package/dist/items.js ADDED
@@ -0,0 +1,90 @@
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 _ItemsSource_inner;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.ItemsSource = void 0;
25
+ class ItemsSource {
26
+ constructor(inner) {
27
+ _ItemsSource_inner.set(this, void 0);
28
+ __classPrivateFieldSet(this, _ItemsSource_inner, inner, "f");
29
+ }
30
+ create(item) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const invocationConfig = {
33
+ clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
34
+ invocation: {
35
+ name: "Create",
36
+ parameters: {
37
+ item,
38
+ },
39
+ },
40
+ };
41
+ return JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig));
42
+ });
43
+ }
44
+ get(vaultId, itemId) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const invocationConfig = {
47
+ clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
48
+ invocation: {
49
+ name: "Get",
50
+ parameters: {
51
+ vault_id: vaultId,
52
+ item_id: itemId,
53
+ },
54
+ },
55
+ };
56
+ return JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig));
57
+ });
58
+ }
59
+ update(item) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const invocationConfig = {
62
+ clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
63
+ invocation: {
64
+ name: "Update",
65
+ parameters: {
66
+ item,
67
+ },
68
+ },
69
+ };
70
+ return JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig));
71
+ });
72
+ }
73
+ delete(vaultId, itemId) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const invocationConfig = {
76
+ clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
77
+ invocation: {
78
+ name: "Delete",
79
+ parameters: {
80
+ vault_id: vaultId,
81
+ item_id: itemId,
82
+ },
83
+ },
84
+ };
85
+ yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig);
86
+ });
87
+ }
88
+ }
89
+ exports.ItemsSource = ItemsSource;
90
+ _ItemsSource_inner = new WeakMap();
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { ClientConfiguration } from "./configuration.js";
2
+ import { Client } from "./client.js";
3
+ export declare const DEFAULT_INTEGRATION_NAME = "Unknown";
4
+ export declare const DEFAULT_INTEGRATION_VERSION = "Unknown";
5
+ export * from "./client.js";
6
+ export * from "./types.js";
7
+ /**
8
+ * Creates a default 1Password SDK client.
9
+ * @returns The authenticated 1Password SDK client.
10
+ */
11
+ export declare const createClient: (config: ClientConfiguration) => Promise<Client>;
package/dist/sdk.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.createClient = exports.DEFAULT_INTEGRATION_VERSION = exports.DEFAULT_INTEGRATION_NAME = void 0;
27
+ const core_js_1 = require("./core.js");
28
+ const client_builder_js_1 = require("./client_builder.js");
29
+ exports.DEFAULT_INTEGRATION_NAME = "Unknown";
30
+ exports.DEFAULT_INTEGRATION_VERSION = "Unknown";
31
+ __exportStar(require("./client.js"), exports);
32
+ __exportStar(require("./types.js"), exports);
33
+ /**
34
+ * Creates a default 1Password SDK client.
35
+ * @returns The authenticated 1Password SDK client.
36
+ */
37
+ const createClient = (config) => __awaiter(void 0, void 0, void 0, function* () { return (0, client_builder_js_1.createClientWithCore)(config, new core_js_1.SharedCore()); });
38
+ exports.createClient = createClient;
package/dist/secrets.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { InnerClient } from "./configuration.js";
2
- export interface SecretsAPI {
1
+ import { InnerClient } from "./core.js";
2
+ export interface SecretsApi {
3
3
  resolve(secretReference: string): Promise<string>;
4
4
  }
5
- export declare class SecretsSource implements SecretsAPI {
5
+ export declare class SecretsSource implements SecretsApi {
6
6
  #private;
7
7
  constructor(inner: InnerClient);
8
8
  resolve(secretReference: string): Promise<string>;
package/dist/secrets.js CHANGED
@@ -1,4 +1,13 @@
1
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
+ };
2
11
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
12
  if (kind === "m") throw new TypeError("Private method is not writable");
4
13
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -13,21 +22,24 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
22
  var _SecretsSource_inner;
14
23
  Object.defineProperty(exports, "__esModule", { value: true });
15
24
  exports.SecretsSource = void 0;
16
- // An implementation of the `SecretsAPI` that wraps a `Core`.
17
25
  class SecretsSource {
18
26
  constructor(inner) {
19
27
  _SecretsSource_inner.set(this, void 0);
20
28
  __classPrivateFieldSet(this, _SecretsSource_inner, inner, "f");
21
29
  }
22
30
  resolve(secretReference) {
23
- const invocationConfig = {
24
- clientId: __classPrivateFieldGet(this, _SecretsSource_inner, "f").id,
25
- invocation: {
26
- name: "Resolve",
27
- parameters: secretReference,
28
- },
29
- };
30
- return __classPrivateFieldGet(this, _SecretsSource_inner, "f").core.invoke(invocationConfig);
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const invocationConfig = {
33
+ clientId: __classPrivateFieldGet(this, _SecretsSource_inner, "f").id,
34
+ invocation: {
35
+ name: "Resolve",
36
+ parameters: {
37
+ secret_reference: secretReference,
38
+ },
39
+ },
40
+ };
41
+ return JSON.parse(yield __classPrivateFieldGet(this, _SecretsSource_inner, "f").core.invoke(invocationConfig));
42
+ });
31
43
  }
32
44
  }
33
45
  exports.SecretsSource = SecretsSource;
@@ -0,0 +1,98 @@
1
+ export declare enum ItemCategory {
2
+ Login = "Login",
3
+ SecureNote = "SecureNote",
4
+ CreditCard = "CreditCard",
5
+ CryptoWallet = "CryptoWallet",
6
+ Identity = "Identity",
7
+ Password = "Password",
8
+ Document = "Document",
9
+ ApiCredentials = "ApiCredentials",
10
+ BankAccount = "BankAccount",
11
+ Database = "Database",
12
+ DriverLicense = "DriverLicense",
13
+ Email = "Email",
14
+ MedicalRecord = "MedicalRecord",
15
+ Membership = "Membership",
16
+ OutdoorLicense = "OutdoorLicense",
17
+ Passport = "Passport",
18
+ Rewards = "Rewards",
19
+ Router = "Router",
20
+ Server = "Server",
21
+ SshKey = "SshKey",
22
+ SocialSecurityNumber = "SocialSecurityNumber",
23
+ SoftwareLicense = "SoftwareLicense",
24
+ Person = "Person",
25
+ Unsupported = "Unsupported"
26
+ }
27
+ export declare enum ItemFieldType {
28
+ Text = "Text",
29
+ Concealed = "Concealed",
30
+ Unsupported = "Unsupported"
31
+ }
32
+ /**
33
+ * Stores a field's title and value.
34
+ */
35
+ export interface ItemField {
36
+ /**
37
+ * The field's ID
38
+ */
39
+ id: string;
40
+ /**
41
+ * The field's title
42
+ */
43
+ title: string;
44
+ /**
45
+ * The ID of the section containing the field
46
+ */
47
+ section_id?: string;
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
+ */
55
+ value: string;
56
+ }
57
+ /**
58
+ * A section groups together multiple fields in an item.
59
+ */
60
+ export interface ItemSection {
61
+ /**
62
+ * The ID of the section
63
+ */
64
+ id: string;
65
+ /**
66
+ * The title of the section
67
+ */
68
+ title: string;
69
+ }
70
+ /**
71
+ * Represents a 1Password item.
72
+ */
73
+ export interface Item {
74
+ /**
75
+ * The item's unique ID
76
+ */
77
+ id: string;
78
+ /**
79
+ * The item's title
80
+ */
81
+ title: string;
82
+ /**
83
+ * The item's category
84
+ */
85
+ category: ItemCategory;
86
+ /**
87
+ * The ID of the vault where the item is saved
88
+ */
89
+ vault_id: string;
90
+ /**
91
+ * The item's fields
92
+ */
93
+ fields: ItemField[];
94
+ /**
95
+ * The item's sections
96
+ */
97
+ sections: ItemSection[];
98
+ }
package/dist/types.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /*
3
+ Generated by typeshare 1.9.2
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ItemFieldType = exports.ItemCategory = void 0;
7
+ var ItemCategory;
8
+ (function (ItemCategory) {
9
+ ItemCategory["Login"] = "Login";
10
+ ItemCategory["SecureNote"] = "SecureNote";
11
+ ItemCategory["CreditCard"] = "CreditCard";
12
+ ItemCategory["CryptoWallet"] = "CryptoWallet";
13
+ ItemCategory["Identity"] = "Identity";
14
+ ItemCategory["Password"] = "Password";
15
+ ItemCategory["Document"] = "Document";
16
+ ItemCategory["ApiCredentials"] = "ApiCredentials";
17
+ ItemCategory["BankAccount"] = "BankAccount";
18
+ ItemCategory["Database"] = "Database";
19
+ ItemCategory["DriverLicense"] = "DriverLicense";
20
+ ItemCategory["Email"] = "Email";
21
+ ItemCategory["MedicalRecord"] = "MedicalRecord";
22
+ ItemCategory["Membership"] = "Membership";
23
+ ItemCategory["OutdoorLicense"] = "OutdoorLicense";
24
+ ItemCategory["Passport"] = "Passport";
25
+ ItemCategory["Rewards"] = "Rewards";
26
+ ItemCategory["Router"] = "Router";
27
+ ItemCategory["Server"] = "Server";
28
+ ItemCategory["SshKey"] = "SshKey";
29
+ ItemCategory["SocialSecurityNumber"] = "SocialSecurityNumber";
30
+ ItemCategory["SoftwareLicense"] = "SoftwareLicense";
31
+ ItemCategory["Person"] = "Person";
32
+ ItemCategory["Unsupported"] = "Unsupported";
33
+ })(ItemCategory || (exports.ItemCategory = ItemCategory = {}));
34
+ var ItemFieldType;
35
+ (function (ItemFieldType) {
36
+ ItemFieldType["Text"] = "Text";
37
+ ItemFieldType["Concealed"] = "Concealed";
38
+ ItemFieldType["Unsupported"] = "Unsupported";
39
+ })(ItemFieldType || (exports.ItemFieldType = ItemFieldType = {}));
package/package.json CHANGED
@@ -1,29 +1,30 @@
1
1
  {
2
2
  "name": "@1password/sdk",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.10",
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
- "build": "npm run clean && tsc",
7
- "clean": "rimraf dist",
6
+ "build": "tsc",
8
7
  "test": "npm run build && jest",
9
8
  "prettier": "prettier --check 'src/*.ts'",
10
- "prepare": "npm run build"
9
+ "prettier-fix": "prettier --write 'src/*.ts'",
10
+ "eslint": "eslint -c .eslintrc.json 'src/*.ts'",
11
+ "prepare": "rm -rf ./dist && npm run build",
12
+ "publish-test": "cp ../README.md . && npm publish --tag beta --dry-run && rm ./README.md",
13
+ "publish-beta": "cp ../README.md . && npm publish --tag beta && rm ./README.md"
11
14
  },
12
15
  "author": "1Password",
13
16
  "license": "MIT",
14
- "files": [
15
- "./dist"
16
- ],
17
+ "files": ["./dist"],
17
18
  "exports": {
18
19
  ".": {
19
- "types": "./dist/client.d.ts",
20
- "default": "./dist/client.js"
20
+ "types": "./dist/sdk.d.ts",
21
+ "default": "./dist/sdk.js"
21
22
  }
22
23
  },
23
- "main": "./dist/client.js",
24
- "types": "./dist/client.d.ts",
24
+ "main": "./dist/sdk.js",
25
+ "types": "./dist/sdk.d.ts",
25
26
  "dependencies": {
26
- "@1password/sdk-core": "0.1.0-beta.1"
27
+ "@1password/sdk-core": "0.1.0-beta.9"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@1password/eslint-config": "^4.0.0",
@@ -36,7 +37,6 @@
36
37
  "jest-environment-jsdom": "^29.6.2",
37
38
  "prettier": "3.1.1",
38
39
  "ts-jest": "^29.1.1",
39
- "rimraf": "^5.0.0",
40
40
  "typescript": "^5.3.3",
41
41
  "@types/node": "^20.11.0",
42
42
  "@babel/preset-env": "^7.23.8",