@1password/sdk 0.1.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/dist/client.d.ts +12 -0
- package/dist/client.js +90 -0
- package/dist/configuration.d.ts +12 -0
- package/dist/configuration.js +2 -0
- package/dist/core.d.ts +31 -0
- package/dist/core.js +33 -0
- package/dist/secrets.d.ts +9 -0
- package/dist/secrets.js +34 -0
- package/package.json +45 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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>;
|
|
8
|
+
export declare class Client {
|
|
9
|
+
secrets: SecretsAPI;
|
|
10
|
+
constructor(innerClient: InnerClient);
|
|
11
|
+
}
|
|
12
|
+
export declare function createClientAuthConfig(userConfig: ClientConfiguration): ClientAuthConfig;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
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;
|
|
36
|
+
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.
|
|
69
|
+
class Client {
|
|
70
|
+
constructor(innerClient) {
|
|
71
|
+
this.secrets = new secrets_js_1.SecretsSource(innerClient);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
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;
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface Core {
|
|
2
|
+
initClient(config: ClientAuthConfig): Promise<string>;
|
|
3
|
+
invoke(config: InvokeConfig): Promise<string>;
|
|
4
|
+
releaseClient(clientId: number): void;
|
|
5
|
+
}
|
|
6
|
+
export interface ClientAuthConfig {
|
|
7
|
+
serviceAccountToken: string;
|
|
8
|
+
programmingLanguage: string;
|
|
9
|
+
sdkVersion: string;
|
|
10
|
+
integrationName: string;
|
|
11
|
+
integrationVersion: string;
|
|
12
|
+
requestLibraryName: string;
|
|
13
|
+
requestLibraryVersion: string;
|
|
14
|
+
os: string;
|
|
15
|
+
osVersion: string;
|
|
16
|
+
architecture: string;
|
|
17
|
+
}
|
|
18
|
+
export interface InvokeConfig {
|
|
19
|
+
clientId: number;
|
|
20
|
+
invocation: Invocation;
|
|
21
|
+
}
|
|
22
|
+
interface Invocation {
|
|
23
|
+
name: string;
|
|
24
|
+
parameters: string;
|
|
25
|
+
}
|
|
26
|
+
export declare class SharedCore implements Core {
|
|
27
|
+
initClient(config: ClientAuthConfig): Promise<string>;
|
|
28
|
+
invoke(config: InvokeConfig): Promise<string>;
|
|
29
|
+
releaseClient(clientId: number): void;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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.SharedCore = void 0;
|
|
13
|
+
const sdk_core_1 = require("@1password/sdk-core");
|
|
14
|
+
// An implementation of the `Core` interface that shares resources across all clients.
|
|
15
|
+
class SharedCore {
|
|
16
|
+
initClient(config) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const serializedConfig = JSON.stringify(config);
|
|
19
|
+
return (0, sdk_core_1.init_client)(serializedConfig);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
invoke(config) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const serializedConfig = JSON.stringify(config);
|
|
25
|
+
return (0, sdk_core_1.invoke)(serializedConfig);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
releaseClient(clientId) {
|
|
29
|
+
const serializedId = JSON.stringify(clientId);
|
|
30
|
+
(0, sdk_core_1.release_client)(serializedId);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.SharedCore = SharedCore;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InnerClient } from "./configuration.js";
|
|
2
|
+
export interface SecretsAPI {
|
|
3
|
+
resolve(secretReference: string): Promise<string>;
|
|
4
|
+
}
|
|
5
|
+
export declare class SecretsSource implements SecretsAPI {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(inner: InnerClient);
|
|
8
|
+
resolve(secretReference: string): Promise<string>;
|
|
9
|
+
}
|
package/dist/secrets.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _SecretsSource_inner;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SecretsSource = void 0;
|
|
16
|
+
// An implementation of the `SecretsAPI` that wraps a `Core`.
|
|
17
|
+
class SecretsSource {
|
|
18
|
+
constructor(inner) {
|
|
19
|
+
_SecretsSource_inner.set(this, void 0);
|
|
20
|
+
__classPrivateFieldSet(this, _SecretsSource_inner, inner, "f");
|
|
21
|
+
}
|
|
22
|
+
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
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.SecretsSource = SecretsSource;
|
|
34
|
+
_SecretsSource_inner = new WeakMap();
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@1password/sdk",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
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
|
+
"scripts": {
|
|
6
|
+
"build": "npm run clean && tsc",
|
|
7
|
+
"clean": "rimraf dist",
|
|
8
|
+
"test": "npm run build && jest",
|
|
9
|
+
"prettier": "prettier --check 'src/*.ts'",
|
|
10
|
+
"prepare": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"author": "1Password",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"files": [
|
|
15
|
+
"./dist"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/client.d.ts",
|
|
20
|
+
"default": "./dist/client.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/client.js",
|
|
24
|
+
"types": "./dist/client.d.ts",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@1password/sdk-core": "0.1.0-beta.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@1password/eslint-config": "^4.0.0",
|
|
30
|
+
"@1password/prettier-config": "^1.1.3",
|
|
31
|
+
"@jest/globals": "^29.7.0",
|
|
32
|
+
"@types/jest": "^29.5.11",
|
|
33
|
+
"jest": "^29.7.0",
|
|
34
|
+
"eslint": "^8.54.0",
|
|
35
|
+
"prettier-plugin-organize-imports": "^3.2.3",
|
|
36
|
+
"jest-environment-jsdom": "^29.6.2",
|
|
37
|
+
"prettier": "3.1.1",
|
|
38
|
+
"ts-jest": "^29.1.1",
|
|
39
|
+
"rimraf": "^5.0.0",
|
|
40
|
+
"typescript": "^5.3.3",
|
|
41
|
+
"@types/node": "^20.11.0",
|
|
42
|
+
"@babel/preset-env": "^7.23.8",
|
|
43
|
+
"babel-jest": "^29.7.0"
|
|
44
|
+
}
|
|
45
|
+
}
|