@centia-io/sdk 0.1.3 → 0.2.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/LICENSE +21 -21
- package/README.md +570 -570
- package/dist/centia-io-sdk-node.cjs +174 -0
- package/dist/centia-io-sdk-node.d.cts +50 -0
- package/dist/centia-io-sdk-node.d.cts.map +1 -0
- package/dist/centia-io-sdk-node.d.ts +50 -0
- package/dist/centia-io-sdk-node.d.ts.map +1 -0
- package/dist/centia-io-sdk-node.js +174 -0
- package/dist/centia-io-sdk-node.js.map +1 -0
- package/dist/centia-io-sdk.cjs +93 -107
- package/dist/centia-io-sdk.d.cts +122 -34
- package/dist/centia-io-sdk.d.cts.map +1 -1
- package/dist/centia-io-sdk.d.ts +122 -34
- package/dist/centia-io-sdk.d.ts.map +1 -1
- package/dist/centia-io-sdk.js +94 -107
- package/dist/centia-io-sdk.js.map +1 -1
- package/dist/centia-io-sdk.umd.js +93 -107
- package/node.d.ts +1 -0
- package/package.json +48 -43
|
@@ -2431,6 +2431,98 @@
|
|
|
2431
2431
|
}
|
|
2432
2432
|
};
|
|
2433
2433
|
|
|
2434
|
+
//#endregion
|
|
2435
|
+
//#region src/provisioning/Functions.ts
|
|
2436
|
+
/**
|
|
2437
|
+
* Lambda-like functions: manage (CRUD), invoke (sync/async/dry-run) and read
|
|
2438
|
+
* the generated TypeScript interface.
|
|
2439
|
+
*/
|
|
2440
|
+
var Functions = class {
|
|
2441
|
+
constructor(client) {
|
|
2442
|
+
this.client = client;
|
|
2443
|
+
}
|
|
2444
|
+
async getFunctions(name) {
|
|
2445
|
+
var _this = this;
|
|
2446
|
+
const path = name ? `api/v4/functions/${encodeURIComponent(name)}` : "api/v4/functions";
|
|
2447
|
+
return _this.client.request({
|
|
2448
|
+
path,
|
|
2449
|
+
method: "GET"
|
|
2450
|
+
});
|
|
2451
|
+
}
|
|
2452
|
+
/** Create one or more functions. Returns the Location of the created resource. */
|
|
2453
|
+
async postFunction(body) {
|
|
2454
|
+
var _this2 = this;
|
|
2455
|
+
var _res$getHeader;
|
|
2456
|
+
return { location: (_res$getHeader = (await _this2.client.requestFull({
|
|
2457
|
+
path: "api/v4/functions",
|
|
2458
|
+
method: "POST",
|
|
2459
|
+
body,
|
|
2460
|
+
expectedStatus: 201
|
|
2461
|
+
})).getHeader("Location")) !== null && _res$getHeader !== void 0 ? _res$getHeader : "" };
|
|
2462
|
+
}
|
|
2463
|
+
/** Update a function. Changing the code bumps its version. */
|
|
2464
|
+
async patchFunction(name, body) {
|
|
2465
|
+
var _this3 = this;
|
|
2466
|
+
var _res$getHeader2;
|
|
2467
|
+
return { location: (_res$getHeader2 = (await _this3.client.requestFull({
|
|
2468
|
+
path: `api/v4/functions/${encodeURIComponent(name)}`,
|
|
2469
|
+
method: "PATCH",
|
|
2470
|
+
body,
|
|
2471
|
+
expectedStatus: 303
|
|
2472
|
+
})).getHeader("Location")) !== null && _res$getHeader2 !== void 0 ? _res$getHeader2 : "" };
|
|
2473
|
+
}
|
|
2474
|
+
/** Delete a function. */
|
|
2475
|
+
async deleteFunction(name) {
|
|
2476
|
+
await this.client.request({
|
|
2477
|
+
path: `api/v4/functions/${encodeURIComponent(name)}`,
|
|
2478
|
+
method: "DELETE",
|
|
2479
|
+
expectedStatus: 204
|
|
2480
|
+
});
|
|
2481
|
+
}
|
|
2482
|
+
/** Invoke a function synchronously and return its result. */
|
|
2483
|
+
async invoke(name, event = {}) {
|
|
2484
|
+
return this.client.request({
|
|
2485
|
+
path: `api/v4/functions/${encodeURIComponent(name)}/invocations`,
|
|
2486
|
+
method: "POST",
|
|
2487
|
+
body: event
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
/** Queue a function invocation; returns immediately with 202 and an id to poll. */
|
|
2491
|
+
async invokeAsync(name, event = {}) {
|
|
2492
|
+
return this.client.request({
|
|
2493
|
+
path: `api/v4/functions/${encodeURIComponent(name)}/invocations`,
|
|
2494
|
+
method: "POST",
|
|
2495
|
+
body: event,
|
|
2496
|
+
query: { async: "true" },
|
|
2497
|
+
expectedStatus: 202
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2500
|
+
/** Run once to infer and store input/output type schemas (for TypeScript generation). */
|
|
2501
|
+
async dryRun(name, event = {}) {
|
|
2502
|
+
return this.client.request({
|
|
2503
|
+
path: `api/v4/functions/${encodeURIComponent(name)}/invocations`,
|
|
2504
|
+
method: "POST",
|
|
2505
|
+
body: event,
|
|
2506
|
+
query: { dry: "true" }
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
/** Get a stored invocation record (e.g. to poll an async invocation). */
|
|
2510
|
+
async getInvocation(name, id) {
|
|
2511
|
+
return this.client.request({
|
|
2512
|
+
path: `api/v4/functions/${encodeURIComponent(name)}/invocations/${encodeURIComponent(id)}`,
|
|
2513
|
+
method: "GET"
|
|
2514
|
+
});
|
|
2515
|
+
}
|
|
2516
|
+
/** Get the generated TypeScript `Functions` interface (from dry-run schemas). */
|
|
2517
|
+
async getInterfaces() {
|
|
2518
|
+
return this.client.request({
|
|
2519
|
+
path: "api/v4/function-interfaces",
|
|
2520
|
+
method: "GET",
|
|
2521
|
+
accept: "text/plain"
|
|
2522
|
+
});
|
|
2523
|
+
}
|
|
2524
|
+
};
|
|
2525
|
+
|
|
2434
2526
|
//#endregion
|
|
2435
2527
|
//#region src/provisioning/MetadataWrite.ts
|
|
2436
2528
|
var MetadataWrite = class {
|
|
@@ -2566,6 +2658,7 @@
|
|
|
2566
2658
|
rules: new Rules(http),
|
|
2567
2659
|
privileges: new Privileges(http),
|
|
2568
2660
|
rpcMethods: new RpcMethods(http),
|
|
2661
|
+
functions: new Functions(http),
|
|
2569
2662
|
metadata: new MetadataWrite(http),
|
|
2570
2663
|
typeScript: new TypeScriptInterfaces(http),
|
|
2571
2664
|
fileImport: new FileImport(http),
|
|
@@ -2686,112 +2779,6 @@
|
|
|
2686
2779
|
return Math.floor(Date.now() / 1e3) + skewSeconds >= exp;
|
|
2687
2780
|
}
|
|
2688
2781
|
|
|
2689
|
-
//#endregion
|
|
2690
|
-
//#region src/auth/configstoreTokenStore.ts
|
|
2691
|
-
const LOCK_RETRIES = 5;
|
|
2692
|
-
const LOCK_RETRY_MIN_MS = 100;
|
|
2693
|
-
const LOCK_RETRY_MAX_MS = 500;
|
|
2694
|
-
const LOCK_STALE_MS = 1e4;
|
|
2695
|
-
/**
|
|
2696
|
-
* Build a Node-only file-backed {@link TokenStore} that persists OAuth
|
|
2697
|
-
* credentials at `~/.config/configstore/<name>.json` (or
|
|
2698
|
-
* `$XDG_CONFIG_HOME/configstore/<name>.json` if set), with both in-process
|
|
2699
|
-
* and cross-process write safety.
|
|
2700
|
-
*
|
|
2701
|
-
* **Shared-state intent.** The `name` is the file name on disk. Two processes
|
|
2702
|
-
* (e.g. `gc2-cli` and a local MCP server) that pass the same name share the
|
|
2703
|
-
* same on-disk credentials and therefore the same login session. The default
|
|
2704
|
-
* `'gc2-env'` matches the name `gc2-cli` already uses, so a one-time
|
|
2705
|
-
* `gc2 login` is observable to every process that calls
|
|
2706
|
-
* `createConfigstoreTokenStore()` with no argument. Pass a different name
|
|
2707
|
-
* to isolate.
|
|
2708
|
-
*
|
|
2709
|
-
* **In-process correctness.** A serial promise chain on `set()` ensures
|
|
2710
|
-
* concurrent same-process calls do not race on the shared configstore cache.
|
|
2711
|
-
*
|
|
2712
|
-
* **Cross-process correctness.** `proper-lockfile` serializes the
|
|
2713
|
-
* read-merge-write critical section across processes so two simultaneous
|
|
2714
|
-
* `set()` calls from different processes cannot corrupt the file.
|
|
2715
|
-
*
|
|
2716
|
-
* **Node-only.** The dynamic imports keep `configstore` and `proper-lockfile`
|
|
2717
|
-
* out of browser bundles even when this module is imported through the SDK
|
|
2718
|
-
* barrel. Calling this function in a browser environment will fail at
|
|
2719
|
-
* runtime when the deferred `await import('configstore')` cannot resolve.
|
|
2720
|
-
*
|
|
2721
|
-
* @param name - configstore file name (without `.json`). Default `'gc2-env'`
|
|
2722
|
-
* matches `gc2-cli`'s configstore so credentials are shared.
|
|
2723
|
-
* @returns A {@link TokenStore} suitable for passing to {@link createTokenProvider}.
|
|
2724
|
-
*/
|
|
2725
|
-
function createConfigstoreTokenStore(name = "gc2-env") {
|
|
2726
|
-
let configstoreInstance = null;
|
|
2727
|
-
let setChain = Promise.resolve();
|
|
2728
|
-
async function getConfigstore() {
|
|
2729
|
-
var _default;
|
|
2730
|
-
if (configstoreInstance) return configstoreInstance;
|
|
2731
|
-
const mod = await import("configstore");
|
|
2732
|
-
const Configstore = (_default = mod.default) !== null && _default !== void 0 ? _default : mod;
|
|
2733
|
-
const { homedir } = await import("node:os");
|
|
2734
|
-
const { join } = await import("node:path");
|
|
2735
|
-
configstoreInstance = new Configstore(name, void 0, { configPath: join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "configstore", `${name}.json`) });
|
|
2736
|
-
return configstoreInstance;
|
|
2737
|
-
}
|
|
2738
|
-
async function getLockfile() {
|
|
2739
|
-
var _default2;
|
|
2740
|
-
const mod = await import("proper-lockfile");
|
|
2741
|
-
return (_default2 = mod.default) !== null && _default2 !== void 0 ? _default2 : mod;
|
|
2742
|
-
}
|
|
2743
|
-
function readAll(cs) {
|
|
2744
|
-
const result = {};
|
|
2745
|
-
const token = cs.get("token");
|
|
2746
|
-
const refresh_token = cs.get("refresh_token");
|
|
2747
|
-
const host = cs.get("host");
|
|
2748
|
-
if (token !== void 0) result.token = token;
|
|
2749
|
-
if (refresh_token !== void 0) result.refresh_token = refresh_token;
|
|
2750
|
-
if (host !== void 0) result.host = host;
|
|
2751
|
-
return result;
|
|
2752
|
-
}
|
|
2753
|
-
async function doLockedSet(patch) {
|
|
2754
|
-
const cs = await getConfigstore();
|
|
2755
|
-
const lockfile = await getLockfile();
|
|
2756
|
-
const filePath = cs.path;
|
|
2757
|
-
const { mkdirSync, writeFileSync } = await import("node:fs");
|
|
2758
|
-
const { dirname } = await import("node:path");
|
|
2759
|
-
try {
|
|
2760
|
-
mkdirSync(dirname(filePath), { recursive: true });
|
|
2761
|
-
writeFileSync(filePath, "{}", { flag: "wx" });
|
|
2762
|
-
} catch (e) {
|
|
2763
|
-
if ((e === null || e === void 0 ? void 0 : e.code) !== "EEXIST") throw e;
|
|
2764
|
-
}
|
|
2765
|
-
const release = await lockfile.lock(filePath, {
|
|
2766
|
-
retries: {
|
|
2767
|
-
retries: LOCK_RETRIES,
|
|
2768
|
-
minTimeout: LOCK_RETRY_MIN_MS,
|
|
2769
|
-
maxTimeout: LOCK_RETRY_MAX_MS,
|
|
2770
|
-
factor: 2
|
|
2771
|
-
},
|
|
2772
|
-
stale: LOCK_STALE_MS,
|
|
2773
|
-
realpath: false
|
|
2774
|
-
});
|
|
2775
|
-
try {
|
|
2776
|
-
configstoreInstance = null;
|
|
2777
|
-
const fresh = await getConfigstore();
|
|
2778
|
-
fresh.all = _objectSpread2(_objectSpread2({}, readAll(fresh)), patch);
|
|
2779
|
-
} finally {
|
|
2780
|
-
await release();
|
|
2781
|
-
}
|
|
2782
|
-
}
|
|
2783
|
-
return {
|
|
2784
|
-
async get() {
|
|
2785
|
-
return readAll(await getConfigstore());
|
|
2786
|
-
},
|
|
2787
|
-
async set(patch) {
|
|
2788
|
-
const next = setChain.then(() => doLockedSet(patch));
|
|
2789
|
-
setChain = next.catch(() => {});
|
|
2790
|
-
return next;
|
|
2791
|
-
}
|
|
2792
|
-
};
|
|
2793
|
-
}
|
|
2794
|
-
|
|
2795
2782
|
//#endregion
|
|
2796
2783
|
//#region src/index.ts
|
|
2797
2784
|
/**
|
|
@@ -2822,7 +2809,6 @@ exports.Ws = Ws;
|
|
|
2822
2809
|
exports.createApi = createApi;
|
|
2823
2810
|
exports.createCentiaAdminClient = createCentiaAdminClient;
|
|
2824
2811
|
exports.createCentiaClient = createCentiaClient;
|
|
2825
|
-
exports.createConfigstoreTokenStore = createConfigstoreTokenStore;
|
|
2826
2812
|
exports.createSqlBuilder = createSqlBuilder;
|
|
2827
2813
|
exports.createTokenProvider = createTokenProvider;
|
|
2828
2814
|
exports.isCentiaApiError = isCentiaApiError;
|
package/node.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/centia-io-sdk-node'
|
package/package.json
CHANGED
|
@@ -1,43 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@centia-io/sdk",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "Centia-io TypeScript SDK",
|
|
5
|
-
"author": "Martin Høgh",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"main": "./dist/centia-io-sdk.cjs",
|
|
9
|
-
"module": "./dist/centia-io-sdk.js",
|
|
10
|
-
"types": "./dist/centia-io-sdk.d.cts",
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"require": "./dist/centia-io-sdk.cjs",
|
|
14
|
-
"import": "./dist/centia-io-sdk.js"
|
|
15
|
-
},
|
|
16
|
-
"./
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@centia-io/sdk",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Centia-io TypeScript SDK",
|
|
5
|
+
"author": "Martin Høgh",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/centia-io-sdk.cjs",
|
|
9
|
+
"module": "./dist/centia-io-sdk.js",
|
|
10
|
+
"types": "./dist/centia-io-sdk.d.cts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"require": "./dist/centia-io-sdk.cjs",
|
|
14
|
+
"import": "./dist/centia-io-sdk.js"
|
|
15
|
+
},
|
|
16
|
+
"./node": {
|
|
17
|
+
"import": { "types": "./dist/centia-io-sdk-node.d.ts", "default": "./dist/centia-io-sdk-node.js" },
|
|
18
|
+
"require": { "types": "./dist/centia-io-sdk-node.d.cts", "default": "./dist/centia-io-sdk-node.cjs" }
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"node.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsdown",
|
|
28
|
+
"build-watch": "tsdown --watch",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test:watch": "vitest"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"configstore": "^7.0.0",
|
|
34
|
+
"proper-lockfile": "^4.1.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/configstore": "^6.0.2",
|
|
38
|
+
"@types/proper-lockfile": "^4.1.4",
|
|
39
|
+
"tsdown": "^0.17.3",
|
|
40
|
+
"tsx": "^4.19.0",
|
|
41
|
+
"typescript": "^5.6.3",
|
|
42
|
+
"vitest": "^4.0.18"
|
|
43
|
+
},
|
|
44
|
+
"private": false,
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18"
|
|
47
|
+
}
|
|
48
|
+
}
|