hiloop-sdk 0.9.0 → 0.9.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 +9 -0
- package/dist/client.js +13 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ export interface HiloopClientOptions {
|
|
|
19
19
|
apiKey: string;
|
|
20
20
|
/** Agent name or UUID. Sent as X-Hiloop header to identify the agent. */
|
|
21
21
|
agentName: string;
|
|
22
|
+
/**
|
|
23
|
+
* Space name. If provided, the SDK auto-creates the space on first use
|
|
24
|
+
* (idempotent — returns existing if slug matches). Requires a key with
|
|
25
|
+
* "owner" permission. The slug is derived from the name (lowercased,
|
|
26
|
+
* non-alphanumeric replaced with hyphens).
|
|
27
|
+
*/
|
|
28
|
+
spaceName?: string;
|
|
22
29
|
baseUrl?: string;
|
|
23
30
|
/** Agent's X25519 secret key (base64). Required for E2E encryption. */
|
|
24
31
|
secretKey?: string;
|
|
@@ -42,6 +49,8 @@ export declare class HiloopClient {
|
|
|
42
49
|
private initialized;
|
|
43
50
|
private initPromise;
|
|
44
51
|
private options;
|
|
52
|
+
/** Cached spaceId after auto-creation resolves spaceName. */
|
|
53
|
+
private resolvedSpaceId;
|
|
45
54
|
constructor(options: HiloopClientOptions);
|
|
46
55
|
/**
|
|
47
56
|
* Initialize encryption: derive keypair from API key, register public key,
|
package/dist/client.js
CHANGED
|
@@ -14,6 +14,8 @@ export class HiloopClient {
|
|
|
14
14
|
this.publicKeyB64 = "";
|
|
15
15
|
this.initialized = false;
|
|
16
16
|
this.initPromise = null;
|
|
17
|
+
/** Cached spaceId after auto-creation resolves spaceName. */
|
|
18
|
+
this.resolvedSpaceId = null;
|
|
17
19
|
this.apiKey = options.apiKey;
|
|
18
20
|
this.baseUrl = (options.baseUrl ?? "https://api.hi-loop.com").replace(/\/$/, "");
|
|
19
21
|
this.timeout = options.timeout ?? 30000;
|
|
@@ -43,6 +45,17 @@ export class HiloopClient {
|
|
|
43
45
|
await this.initPromise;
|
|
44
46
|
}
|
|
45
47
|
async doInit() {
|
|
48
|
+
// 0. Auto-create space if spaceName is provided (idempotent)
|
|
49
|
+
if (this.options.spaceName && !this.resolvedSpaceId) {
|
|
50
|
+
const slug = this.options.spaceName.toLowerCase().replace(/[^a-z0-9]/g, "-").slice(0, 100);
|
|
51
|
+
try {
|
|
52
|
+
const space = await this.rawRequest("POST", "/org/spaces", { body: { name: this.options.spaceName, slug } });
|
|
53
|
+
this.resolvedSpaceId = space.id;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// Space creation failed — may not have owner permission, continue without
|
|
57
|
+
}
|
|
58
|
+
}
|
|
46
59
|
// 1. Derive keypair from API key (or use provided keys)
|
|
47
60
|
let secretKey = this.options.secretKey;
|
|
48
61
|
let publicKey = this.options.publicKey;
|