@lifesi/genesis-cli 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ /** Saved `genesis login`: kept in the OS keychain (macOS Keychain, Windows Credential Manager, libsecret). */
2
+ export interface SavedLogin {
3
+ access_token: string;
4
+ refresh_token?: string;
5
+ user?: {
6
+ id: string;
7
+ email?: string;
8
+ first_name?: string | null;
9
+ last_name?: string | null;
10
+ };
11
+ organization_id?: string;
12
+ /** epoch seconds, from the access token's exp claim */
13
+ expires_at?: number;
14
+ client_id: string;
15
+ }
16
+ export interface CredentialStore {
17
+ get(): Promise<SavedLogin | undefined>;
18
+ set(v: SavedLogin): Promise<void>;
19
+ clear(): Promise<boolean>;
20
+ readonly kind: string;
21
+ }
22
+ export declare function keychainStore(): Promise<CredentialStore>;
23
+ export declare function memoryStore(initial?: SavedLogin): CredentialStore;
package/dist/store.js ADDED
@@ -0,0 +1,33 @@
1
+ const SERVICE = 'one.life.genesis';
2
+ const ACCOUNT = 'default';
3
+ export async function keychainStore() {
4
+ let Entry;
5
+ try {
6
+ ({ Entry } = await import('@napi-rs/keyring'));
7
+ }
8
+ catch {
9
+ throw new Error('OS keychain is unavailable (@napi-rs/keyring not installed). Use GENESIS_API_KEY instead.');
10
+ }
11
+ const entry = new Entry(SERVICE, ACCOUNT);
12
+ return {
13
+ kind: 'os-keychain',
14
+ async get() { try {
15
+ const s = entry.getPassword();
16
+ return s ? JSON.parse(s) : undefined;
17
+ }
18
+ catch {
19
+ return undefined;
20
+ } },
21
+ async set(v) { entry.setPassword(JSON.stringify(v)); },
22
+ async clear() { try {
23
+ return entry.deletePassword();
24
+ }
25
+ catch {
26
+ return false;
27
+ } },
28
+ };
29
+ }
30
+ export function memoryStore(initial) {
31
+ let v = initial;
32
+ return { kind: 'memory', async get() { return v; }, async set(x) { v = x; }, async clear() { const had = !!v; v = undefined; return had; } };
33
+ }
@@ -0,0 +1,2 @@
1
+ /** Read only the explicitly requested regular file, with a bounded allocation. */
2
+ export declare function readWasmFile(path: string): Promise<Blob>;
@@ -0,0 +1,31 @@
1
+ import { open } from 'node:fs/promises';
2
+ import { MAX_WASM_BYTES } from '@lifesi/genesis';
3
+ /** Read only the explicitly requested regular file, with a bounded allocation. */
4
+ export async function readWasmFile(path) {
5
+ let file;
6
+ try {
7
+ file = await open(path, 'r');
8
+ }
9
+ catch {
10
+ throw new Error('Could not open the WASM file. Check its path and permissions.');
11
+ }
12
+ try {
13
+ const stat = await file.stat();
14
+ if (!stat.isFile() || stat.size < 4 || stat.size > MAX_WASM_BYTES)
15
+ throw new Error('Choose a regular WASM file of 4 bytes to 10 MiB.');
16
+ const bytes = new Uint8Array(MAX_WASM_BYTES + 1);
17
+ let size = 0;
18
+ for (;;) {
19
+ const { bytesRead } = await file.read(bytes, size, bytes.length - size, null);
20
+ if (!bytesRead)
21
+ break;
22
+ size += bytesRead;
23
+ if (size > MAX_WASM_BYTES)
24
+ throw new Error('WASM file exceeds 10 MiB.');
25
+ }
26
+ return new Blob([bytes.slice(0, size)], { type: 'application/wasm' });
27
+ }
28
+ finally {
29
+ await file.close();
30
+ }
31
+ }
package/package.json CHANGED
@@ -1,6 +1,24 @@
1
1
  {
2
2
  "name": "@lifesi/genesis-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "genesis: one CLI for every Genesis service",
5
+ "type": "module",
6
+ "bin": {
7
+ "genesis": "bin/genesis.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "dist"
12
+ ],
13
+ "dependencies": {
14
+ "commander": "^14.0.0",
15
+ "undici": "6.29.0",
16
+ "@lifesi/genesis": "0.1.1"
17
+ },
18
+ "optionalDependencies": {
19
+ "@napi-rs/keyring": "^1.2.0"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.json"
23
+ }
6
24
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.