@centia-io/sdk 0.1.3 → 0.2.0
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/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 +0 -107
- package/dist/centia-io-sdk.d.cts +1 -34
- package/dist/centia-io-sdk.d.cts.map +1 -1
- package/dist/centia-io-sdk.d.ts +1 -34
- package/dist/centia-io-sdk.d.ts.map +1 -1
- package/dist/centia-io-sdk.js +1 -107
- package/dist/centia-io-sdk.js.map +1 -1
- package/dist/centia-io-sdk.umd.js +0 -107
- package/node.d.ts +1 -0
- package/package.json +7 -2
|
@@ -2686,112 +2686,6 @@
|
|
|
2686
2686
|
return Math.floor(Date.now() / 1e3) + skewSeconds >= exp;
|
|
2687
2687
|
}
|
|
2688
2688
|
|
|
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
2689
|
//#endregion
|
|
2796
2690
|
//#region src/index.ts
|
|
2797
2691
|
/**
|
|
@@ -2822,7 +2716,6 @@ exports.Ws = Ws;
|
|
|
2822
2716
|
exports.createApi = createApi;
|
|
2823
2717
|
exports.createCentiaAdminClient = createCentiaAdminClient;
|
|
2824
2718
|
exports.createCentiaClient = createCentiaClient;
|
|
2825
|
-
exports.createConfigstoreTokenStore = createConfigstoreTokenStore;
|
|
2826
2719
|
exports.createSqlBuilder = createSqlBuilder;
|
|
2827
2720
|
exports.createTokenProvider = createTokenProvider;
|
|
2828
2721
|
exports.isCentiaApiError = isCentiaApiError;
|
package/node.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/centia-io-sdk-node'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@centia-io/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Centia-io TypeScript SDK",
|
|
5
5
|
"author": "Martin Høgh",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,10 +13,15 @@
|
|
|
13
13
|
"require": "./dist/centia-io-sdk.cjs",
|
|
14
14
|
"import": "./dist/centia-io-sdk.js"
|
|
15
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
|
+
},
|
|
16
20
|
"./package.json": "./package.json"
|
|
17
21
|
},
|
|
18
22
|
"files": [
|
|
19
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"node.d.ts"
|
|
20
25
|
],
|
|
21
26
|
"scripts": {
|
|
22
27
|
"build": "tsdown",
|