@loadstrike/loadstrike-sdk 1.0.10801 → 1.0.15201

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/cjs/local.js CHANGED
@@ -178,9 +178,10 @@ class LoadStrikeLocalClient {
178
178
  const timer = setTimeout(() => controller.abort(), this.licenseValidationTimeoutMs);
179
179
  try {
180
180
  const { response, json } = await this.postLicensingRequest("/api/v1/licenses/validate", payload, controller.signal);
181
- if (!response.ok || json.IsValid !== true) {
182
- const denialCode = stringOrDefault(json.DenialCode, "unknown_denial");
183
- const details = stringOrDefault(json.Message, "No additional details provided.");
181
+ const isValid = pickValue(json, "IsValid", "isValid");
182
+ if (!response.ok || isValid !== true) {
183
+ const denialCode = stringOrDefault(pickValue(json, "DenialCode", "denialCode"), "unknown_denial");
184
+ const details = stringOrDefault(pickValue(json, "Message", "message"), "No additional details provided.");
184
185
  throw new Error(`Runner key validation denied for '${runnerKey}'. Reason: ${denialCode}. ${details}`);
185
186
  }
186
187
  const runToken = stringOrDefault(pickValue(json, "RunToken", "SignedRunToken", "Token", "runToken"), "").trim();
@@ -272,12 +273,12 @@ class LoadStrikeLocalClient {
272
273
  if (!response.ok) {
273
274
  throw new Error(`Failed to resolve licensing signing key. status=${response.status}`);
274
275
  }
275
- const resolvedAlgorithm = stringOrDefault(pickValue(json, "Algorithm", "alg"), normalizedAlgorithm).toUpperCase();
276
- const publicKeyPem = stringOrDefault(pickValue(json, "PublicKeyPem", "PublicKey", "Pem"), "");
276
+ const resolvedAlgorithm = stringOrDefault(pickValue(json, "Algorithm", "algorithm", "alg"), normalizedAlgorithm).toUpperCase();
277
+ const publicKeyPem = normalizePemText(pickValue(json, "PublicKeyPem", "publicKeyPem", "PublicKey", "publicKey", "Pem", "pem"));
277
278
  if (!publicKeyPem.trim()) {
278
279
  throw new Error("Runner key validation failed: signing key response is empty.");
279
280
  }
280
- const resolvedKeyId = stringOrDefault(pickValue(json, "KeyId", "Kid", "kid"), normalizedKeyId).trim() || normalizedKeyId;
281
+ const resolvedKeyId = stringOrDefault(pickValue(json, "KeyId", "keyId", "Kid", "kid"), normalizedKeyId).trim() || normalizedKeyId;
281
282
  if (resolvedKeyId !== normalizedKeyId) {
282
283
  throw new Error("Runner key validation failed: signing key response key id does not match requested key id.");
283
284
  }
@@ -404,7 +405,7 @@ function normalizeLicensingApiBaseUrl(value) {
404
405
  return normalized || DEFAULT_LICENSING_API_BASE_URL;
405
406
  }
406
407
  function resolveLicensingApiBaseUrl() {
407
- return normalizeLicensingApiBaseUrl(developmentLicensingApiBaseUrlOverride);
408
+ return normalizeLicensingApiBaseUrl(process.env.LOADSTRIKE_LICENSING_API_BASE_URL ?? developmentLicensingApiBaseUrlOverride);
408
409
  }
409
410
  function setDevelopmentLicensingApiBaseUrlOverride(value) {
410
411
  developmentLicensingApiBaseUrlOverride = value;
@@ -1609,6 +1610,20 @@ function stringOrDefault(value, fallback) {
1609
1610
  }
1610
1611
  return String(value);
1611
1612
  }
1613
+ function normalizePemText(value) {
1614
+ let text = stringOrDefault(value, "").trim();
1615
+ if (!text) {
1616
+ return "";
1617
+ }
1618
+ if (text.length >= 2 && text.startsWith("\"") && text.endsWith("\"")) {
1619
+ text = text.slice(1, -1).trim();
1620
+ }
1621
+ text = text.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n").replace(/\\r/g, "\r").trim();
1622
+ if (text.length >= 2 && text.startsWith("\"") && text.endsWith("\"")) {
1623
+ text = text.slice(1, -1).trim();
1624
+ }
1625
+ return text;
1626
+ }
1612
1627
  function asInt(value) {
1613
1628
  if (typeof value === "number" && Number.isFinite(value)) {
1614
1629
  return Math.trunc(value);
package/dist/esm/local.js CHANGED
@@ -139,9 +139,10 @@ export class LoadStrikeLocalClient {
139
139
  const timer = setTimeout(() => controller.abort(), this.licenseValidationTimeoutMs);
140
140
  try {
141
141
  const { response, json } = await this.postLicensingRequest("/api/v1/licenses/validate", payload, controller.signal);
142
- if (!response.ok || json.IsValid !== true) {
143
- const denialCode = stringOrDefault(json.DenialCode, "unknown_denial");
144
- const details = stringOrDefault(json.Message, "No additional details provided.");
142
+ const isValid = pickValue(json, "IsValid", "isValid");
143
+ if (!response.ok || isValid !== true) {
144
+ const denialCode = stringOrDefault(pickValue(json, "DenialCode", "denialCode"), "unknown_denial");
145
+ const details = stringOrDefault(pickValue(json, "Message", "message"), "No additional details provided.");
145
146
  throw new Error(`Runner key validation denied for '${runnerKey}'. Reason: ${denialCode}. ${details}`);
146
147
  }
147
148
  const runToken = stringOrDefault(pickValue(json, "RunToken", "SignedRunToken", "Token", "runToken"), "").trim();
@@ -233,12 +234,12 @@ export class LoadStrikeLocalClient {
233
234
  if (!response.ok) {
234
235
  throw new Error(`Failed to resolve licensing signing key. status=${response.status}`);
235
236
  }
236
- const resolvedAlgorithm = stringOrDefault(pickValue(json, "Algorithm", "alg"), normalizedAlgorithm).toUpperCase();
237
- const publicKeyPem = stringOrDefault(pickValue(json, "PublicKeyPem", "PublicKey", "Pem"), "");
237
+ const resolvedAlgorithm = stringOrDefault(pickValue(json, "Algorithm", "algorithm", "alg"), normalizedAlgorithm).toUpperCase();
238
+ const publicKeyPem = normalizePemText(pickValue(json, "PublicKeyPem", "publicKeyPem", "PublicKey", "publicKey", "Pem", "pem"));
238
239
  if (!publicKeyPem.trim()) {
239
240
  throw new Error("Runner key validation failed: signing key response is empty.");
240
241
  }
241
- const resolvedKeyId = stringOrDefault(pickValue(json, "KeyId", "Kid", "kid"), normalizedKeyId).trim() || normalizedKeyId;
242
+ const resolvedKeyId = stringOrDefault(pickValue(json, "KeyId", "keyId", "Kid", "kid"), normalizedKeyId).trim() || normalizedKeyId;
242
243
  if (resolvedKeyId !== normalizedKeyId) {
243
244
  throw new Error("Runner key validation failed: signing key response key id does not match requested key id.");
244
245
  }
@@ -364,7 +365,7 @@ function normalizeLicensingApiBaseUrl(value) {
364
365
  return normalized || DEFAULT_LICENSING_API_BASE_URL;
365
366
  }
366
367
  function resolveLicensingApiBaseUrl() {
367
- return normalizeLicensingApiBaseUrl(developmentLicensingApiBaseUrlOverride);
368
+ return normalizeLicensingApiBaseUrl(process.env.LOADSTRIKE_LICENSING_API_BASE_URL ?? developmentLicensingApiBaseUrlOverride);
368
369
  }
369
370
  function setDevelopmentLicensingApiBaseUrlOverride(value) {
370
371
  developmentLicensingApiBaseUrlOverride = value;
@@ -1569,6 +1570,20 @@ function stringOrDefault(value, fallback) {
1569
1570
  }
1570
1571
  return String(value);
1571
1572
  }
1573
+ function normalizePemText(value) {
1574
+ let text = stringOrDefault(value, "").trim();
1575
+ if (!text) {
1576
+ return "";
1577
+ }
1578
+ if (text.length >= 2 && text.startsWith("\"") && text.endsWith("\"")) {
1579
+ text = text.slice(1, -1).trim();
1580
+ }
1581
+ text = text.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n").replace(/\\r/g, "\r").trim();
1582
+ if (text.length >= 2 && text.startsWith("\"") && text.endsWith("\"")) {
1583
+ text = text.slice(1, -1).trim();
1584
+ }
1585
+ return text;
1586
+ }
1572
1587
  function asInt(value) {
1573
1588
  if (typeof value === "number" && Number.isFinite(value)) {
1574
1589
  return Math.trunc(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadstrike/loadstrike-sdk",
3
- "version": "1.0.10801",
3
+ "version": "1.0.15201",
4
4
  "description": "TypeScript and JavaScript SDK for in-process load execution, traffic correlation, and reporting.",
5
5
  "keywords": [
6
6
  "load-testing",
@@ -68,7 +68,7 @@
68
68
  "audit": "npm audit --audit-level=moderate",
69
69
  "audit:fix": "npm audit fix --package-lock-only",
70
70
  "pretest": "npm run build",
71
- "test": "npm run test:coverage",
71
+ "test": "node ./tests/end-end/published-package-sdk.dispatcher.mjs",
72
72
  "test:clean": "npm run clean && npm test",
73
73
  "test:coverage": "c8 --check-coverage --lines 89.5 --branches 81.6 --functions 95.5 node ./scripts/run-tests.mjs",
74
74
  "test:unit": "node ./scripts/run-tests.mjs",