superposition-provider 0.98.0 → 0.99.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/index.esm.js +51 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +51 -5
- package/dist/index.js.map +1 -1
- package/dist/native-lib/libsuperposition_core-aarch64-apple-darwin.dylib +0 -0
- package/dist/native-lib/libsuperposition_core-x86_64-apple-darwin.dylib +0 -0
- package/dist/native-lib/libsuperposition_core-x86_64-pc-windows-msvc.dll +0 -0
- package/dist/native-lib/libsuperposition_core-x86_64-unknown-linux-gnu.so +0 -0
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -3180,7 +3180,7 @@ var runtimeConfig = {};
|
|
|
3180
3180
|
|
|
3181
3181
|
var name = "superposition-sdk";
|
|
3182
3182
|
var description = "superposition-sdk client";
|
|
3183
|
-
var version = "0.
|
|
3183
|
+
var version = "0.99.1";
|
|
3184
3184
|
var repository = {
|
|
3185
3185
|
type: "git",
|
|
3186
3186
|
url: "git+https://github.com/juspay/superposition.git"
|
|
@@ -17039,6 +17039,7 @@ function convertToObject(value, defaultValue) {
|
|
|
17039
17039
|
return defaultValue;
|
|
17040
17040
|
}
|
|
17041
17041
|
|
|
17042
|
+
const ERROR_BUFFER_SIZE = 2048;
|
|
17042
17043
|
class NativeResolver {
|
|
17043
17044
|
constructor(libPath) {
|
|
17044
17045
|
this.isAvailable = false;
|
|
@@ -17050,6 +17051,7 @@ class NativeResolver {
|
|
|
17050
17051
|
this.lib.core_free_string = this.lib.func("void core_free_string(char*)");
|
|
17051
17052
|
this.lib.core_get_applicable_variants = this.lib.func("char* core_get_applicable_variants(const char*, const char*, const char*, const char*, const char*)");
|
|
17052
17053
|
this.lib.core_test_connection = this.lib.func("int core_test_connection()");
|
|
17054
|
+
this.lib.core_parse_toml_config = this.lib.func("char* core_parse_toml_config(const char*, char*)");
|
|
17053
17055
|
this.isAvailable = true;
|
|
17054
17056
|
}
|
|
17055
17057
|
catch (error) {
|
|
@@ -17127,7 +17129,7 @@ class NativeResolver {
|
|
|
17127
17129
|
queryDataJson === "undefined") {
|
|
17128
17130
|
throw new Error("queryData serialization failed");
|
|
17129
17131
|
}
|
|
17130
|
-
const ebuf = Buffer$1.alloc(
|
|
17132
|
+
const ebuf = Buffer$1.alloc(ERROR_BUFFER_SIZE);
|
|
17131
17133
|
const result = this.lib.core_get_resolved_config(defaultConfigsJson, contextsJson, overridesJson, dimensionsJson, queryDataJson, mergeStrategy, filterPrefixesJson, experimentationJson, ebuf);
|
|
17132
17134
|
console.log("🔧 FFI call completed, result:", result);
|
|
17133
17135
|
const err = ebuf.toString('utf8').split('\0')[0];
|
|
@@ -17159,7 +17161,7 @@ class NativeResolver {
|
|
|
17159
17161
|
const experimentationJson = experimentation
|
|
17160
17162
|
? JSON.stringify(experimentation)
|
|
17161
17163
|
: null;
|
|
17162
|
-
const ebuf = Buffer$1.alloc(
|
|
17164
|
+
const ebuf = Buffer$1.alloc(ERROR_BUFFER_SIZE);
|
|
17163
17165
|
const result = this.lib.core_get_resolved_config_with_reasoning(JSON.stringify(defaultConfigs || {}), JSON.stringify(contexts), JSON.stringify(overrides), JSON.stringify(dimensions), JSON.stringify(queryData), mergeStrategy, filterPrefixesJson, experimentationJson, ebuf);
|
|
17164
17166
|
const err = ebuf.toString('utf8').split('\0')[0];
|
|
17165
17167
|
if (err.length !== 0) {
|
|
@@ -17201,7 +17203,7 @@ class NativeResolver {
|
|
|
17201
17203
|
console.log(" userContext:", userContext);
|
|
17202
17204
|
console.log(" identifier:", identifier);
|
|
17203
17205
|
console.log(" filterPrefixes:", filterPrefixes);
|
|
17204
|
-
const ebuf = Buffer$1.alloc(
|
|
17206
|
+
const ebuf = Buffer$1.alloc(ERROR_BUFFER_SIZE);
|
|
17205
17207
|
const result = this.lib.core_get_applicable_variants(experimentsJson, experimentGroupsJson, dimensionsJson, userContextJson, identifier, filterPrefixesJson);
|
|
17206
17208
|
console.log("FFI getApplicableVariants call completed, result:", result);
|
|
17207
17209
|
const err = ebuf.toString('utf8').split('\0')[0];
|
|
@@ -17223,6 +17225,50 @@ class NativeResolver {
|
|
|
17223
17225
|
throw new Error(`Failed to parse variants evaluation result: ${parseError}`);
|
|
17224
17226
|
}
|
|
17225
17227
|
}
|
|
17228
|
+
/**
|
|
17229
|
+
* Parse TOML configuration into structured format matching the Config type
|
|
17230
|
+
*
|
|
17231
|
+
* @param tomlContent - TOML configuration string
|
|
17232
|
+
* @returns Parsed Config object with contexts, overrides, default_configs, dimensions
|
|
17233
|
+
* @throws Error if parsing fails
|
|
17234
|
+
*/
|
|
17235
|
+
parseTomlConfig(tomlContent) {
|
|
17236
|
+
if (!this.isAvailable) {
|
|
17237
|
+
throw new Error("Native resolver is not available. Please ensure the native library is built and accessible.");
|
|
17238
|
+
}
|
|
17239
|
+
if (typeof tomlContent !== 'string') {
|
|
17240
|
+
throw new TypeError('tomlContent must be a string');
|
|
17241
|
+
}
|
|
17242
|
+
// Allocate error buffer (matching the Rust implementation)
|
|
17243
|
+
const errorBuffer = Buffer$1.alloc(ERROR_BUFFER_SIZE);
|
|
17244
|
+
// Call the C function
|
|
17245
|
+
const resultJson = this.lib.core_parse_toml_config(tomlContent, errorBuffer);
|
|
17246
|
+
// Check for errors
|
|
17247
|
+
if (!resultJson) {
|
|
17248
|
+
// Read error message from buffer
|
|
17249
|
+
const nullTermIndex = errorBuffer.indexOf(0);
|
|
17250
|
+
const errorMsg = errorBuffer.toString('utf8', 0, nullTermIndex > 0 ? nullTermIndex : errorBuffer.length);
|
|
17251
|
+
throw new Error(`TOML parsing failed: ${errorMsg}`);
|
|
17252
|
+
}
|
|
17253
|
+
// Decode the result to a JS string if it's not already a string
|
|
17254
|
+
const configStr = typeof resultJson === "string"
|
|
17255
|
+
? resultJson
|
|
17256
|
+
: this.lib.decode(resultJson, "string");
|
|
17257
|
+
// Free the native string if it wasn't already a string
|
|
17258
|
+
if (typeof resultJson !== "string") {
|
|
17259
|
+
this.lib.core_free_string(resultJson);
|
|
17260
|
+
}
|
|
17261
|
+
// Parse the JSON result
|
|
17262
|
+
try {
|
|
17263
|
+
const result = JSON.parse(configStr);
|
|
17264
|
+
return result;
|
|
17265
|
+
}
|
|
17266
|
+
catch (parseError) {
|
|
17267
|
+
console.error("Failed to parse TOML result:", parseError);
|
|
17268
|
+
console.error("Raw result string:", configStr);
|
|
17269
|
+
throw new Error(`Failed to parse TOML result: ${parseError}`);
|
|
17270
|
+
}
|
|
17271
|
+
}
|
|
17226
17272
|
/**
|
|
17227
17273
|
* Get the path to the native library.
|
|
17228
17274
|
* Uses the same approach as Java and Python - looks for GitHub artifacts first,
|
|
@@ -17277,7 +17323,7 @@ class NativeResolver {
|
|
|
17277
17323
|
console.log(`Using local build: ${localBuildPath}`);
|
|
17278
17324
|
return localBuildPath;
|
|
17279
17325
|
}
|
|
17280
|
-
//
|
|
17326
|
+
// 5. Final fallback - assume it's in the system path
|
|
17281
17327
|
console.warn(`Native library not found in expected locations, trying: ${filename}`);
|
|
17282
17328
|
return filename;
|
|
17283
17329
|
}
|