mirror of
https://github.com/NVIDIA/OpenShell.git
synced 2026-10-26 06:52:57 +08:00
Per RFC 0005, ship openshell-sdk-node as a napi-rs wrapper over the openshell-sdk crate, exposing the same surface to TypeScript/Node consumers as @openshell/sdk. - New crate openshell-sdk-node binds OpenShellClient, OidcRefresher, the edge-tunnel dialer, and the sandbox/exec API through napi-rs. - Generated index.d.ts and index.js are committed; the per-platform .node binary is gitignored and rebuilt with `napi build` per host. - lib.mjs provides a small ESM facade with named exports plus the errorCode() helper for typed error discrimination. Tests: 5-case smoke suite that exercises exports, typed connect errors, and OidcRefresher single-flight semantics.
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// ESM facade over the auto-generated CommonJS index.
|
|
//
|
|
// Re-exports the napi-generated classes and adds the `errorCode` helper,
|
|
// which parses the `[code] message` prefix the binding uses to surface the
|
|
// SDK's discriminable error kind. The auto-generated `index.js`/`index.d.ts`
|
|
// pair from napi-rs is left untouched so the build matrix stays cookie-cutter.
|
|
|
|
import nativeBinding from './index.js'
|
|
|
|
const { OpenShellClient, OidcRefresher } = nativeBinding
|
|
|
|
export { OpenShellClient, OidcRefresher }
|
|
|
|
/**
|
|
* Extract the SDK error code from a thrown error.
|
|
*
|
|
* The native binding prefixes every error message with `[code] ` where
|
|
* `code` is one of: `invalid_config`, `tls`, `connect`, `auth`, `io`,
|
|
* `not_found`, `already_exists`, `rpc`. Returns `null` when the prefix is
|
|
* missing (the error wasn't thrown by this binding).
|
|
*
|
|
* @param {unknown} err
|
|
* @returns {string | null}
|
|
*/
|
|
export function errorCode(err) {
|
|
if (!err || typeof err.message !== 'string') return null
|
|
const match = err.message.match(/^\[([^\]]+)\]/)
|
|
return match ? match[1] : null
|
|
}
|