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