@shipeasy/sdk 5.4.0 → 6.0.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.
@@ -499,7 +499,7 @@ function parseOverrides(rawUrl) {
499
499
  }
500
500
  return { gates, configs, experiments };
501
501
  }
502
- var FlagsClient = class _FlagsClient {
502
+ var Engine = class _Engine {
503
503
  apiKey;
504
504
  baseUrl;
505
505
  env;
@@ -514,7 +514,7 @@ var FlagsClient = class _FlagsClient {
514
514
  pollInterval = 30;
515
515
  timer = null;
516
516
  initialized = false;
517
- // Test mode: built by `FlagsClient.forTesting()`. When set, init()/initOnce()
517
+ // Test mode: built by `Engine.forTesting()`. When set, init()/initOnce()
518
518
  // never fetch, track() is a no-op, and telemetry is off — the client is a
519
519
  // fully self-contained, network-free seam for unit tests.
520
520
  testMode;
@@ -555,13 +555,13 @@ var FlagsClient = class _FlagsClient {
555
555
  * with overrideFlag/overrideConfig/overrideExperiment. No SDK key required.
556
556
  *
557
557
  * ```ts
558
- * const client = FlagsClient.forTesting();
558
+ * const client = Engine.forTesting();
559
559
  * client.overrideFlag("new_checkout", true);
560
560
  * client.getFlag("new_checkout", { user_id: "u1" }); // true
561
561
  * ```
562
562
  */
563
563
  static forTesting(opts) {
564
- return new _FlagsClient({ apiKey: "", ...opts, testMode: true });
564
+ return new _Engine({ apiKey: "", ...opts, testMode: true });
565
565
  }
566
566
  /**
567
567
  * Build a fully OFFLINE client from a pre-captured snapshot — no network ever.
@@ -574,7 +574,7 @@ var FlagsClient = class _FlagsClient {
574
574
  * `{ flags: <GET /sdk/flags body>, experiments: <GET /sdk/experiments body> }`.
575
575
  */
576
576
  static fromSnapshot(snapshot) {
577
- const client = new _FlagsClient({ apiKey: "", testMode: true });
577
+ const client = new _Engine({ apiKey: "", testMode: true });
578
578
  client.flagsBlob = snapshot.flags;
579
579
  client.expsBlob = snapshot.experiments;
580
580
  client.initialized = true;
@@ -584,13 +584,13 @@ var FlagsClient = class _FlagsClient {
584
584
  * Build a fully OFFLINE client from a snapshot JSON file on disk (Node only —
585
585
  * not available in the browser entrypoint). The file must contain
586
586
  * `{ "flags": <GET /sdk/flags body>, "experiments": <GET /sdk/experiments body> }`.
587
- * See {@link FlagsClient.fromSnapshot}.
587
+ * See {@link Engine.fromSnapshot}.
588
588
  */
589
589
  static fromFile(path) {
590
590
  const fs = __require("fs");
591
591
  const raw = fs.readFileSync(path, "utf8");
592
592
  const snapshot = JSON.parse(raw);
593
- return _FlagsClient.fromSnapshot(snapshot);
593
+ return _Engine.fromSnapshot(snapshot);
594
594
  }
595
595
  async init() {
596
596
  if (this.testMode) {
@@ -1050,7 +1050,7 @@ async function fetchLabelsForSSR(opts) {
1050
1050
  var _server = null;
1051
1051
  function configureShipeasyServer(opts) {
1052
1052
  if (_server) return _server;
1053
- _server = new FlagsClient(opts);
1053
+ _server = new Engine(opts);
1054
1054
  return _server;
1055
1055
  }
1056
1056
  function getShipeasyServerClient() {
@@ -1225,7 +1225,7 @@ var flags = {
1225
1225
  _server?.track(userId, eventName, props);
1226
1226
  },
1227
1227
  /** Emit an exposure for an enrolled experiment at the decision point. See
1228
- * {@link FlagsClient.logExposure}. No-op before configure(). */
1228
+ * {@link Engine.logExposure}. No-op before configure(). */
1229
1229
  logExposure(user, name) {
1230
1230
  _server?.logExposure(user, name);
1231
1231
  },
@@ -1243,6 +1243,50 @@ var flags = {
1243
1243
  };
1244
1244
  }
1245
1245
  };
1246
+ var _identityAttributes = (user) => user && typeof user === "object" ? user : {};
1247
+ var _attributes = _identityAttributes;
1248
+ function configure(opts) {
1249
+ const { attributes, ...engineOpts } = opts;
1250
+ _attributes = attributes ?? _identityAttributes;
1251
+ const engine = configureShipeasyServer(engineOpts);
1252
+ void engine.initOnce().catch(() => {
1253
+ });
1254
+ return engine;
1255
+ }
1256
+ function _resetConfigureForTests() {
1257
+ _attributes = _identityAttributes;
1258
+ }
1259
+ var Client = class {
1260
+ engine;
1261
+ /** The resolved attribute bag this handle evaluates against. */
1262
+ attributes;
1263
+ constructor(user) {
1264
+ const engine = getShipeasyServerClient();
1265
+ if (!engine) {
1266
+ throw new Error(
1267
+ "[shipeasy] new Client(user) called before configure({ apiKey }). Call configure() once at app boot from @shipeasy/sdk/server."
1268
+ );
1269
+ }
1270
+ this.engine = engine;
1271
+ this.attributes = _attributes(user);
1272
+ }
1273
+ getFlag(name, defaultValue = false) {
1274
+ return this.engine.getFlag(name, this.attributes, defaultValue);
1275
+ }
1276
+ getFlagDetail(name) {
1277
+ return this.engine.getFlagDetail(name, this.attributes);
1278
+ }
1279
+ getConfig(name, decodeOrOpts) {
1280
+ return this.engine.getConfig(name, decodeOrOpts);
1281
+ }
1282
+ getExperiment(name, defaultParams, decode) {
1283
+ return this.engine.getExperiment(name, this.attributes, defaultParams, decode);
1284
+ }
1285
+ /** Read a killswitch (not user-bound; mirrors {@link Engine.getKillswitch}). */
1286
+ getKillswitch(name, switchKey) {
1287
+ return this.engine.getKillswitch(name, switchKey);
1288
+ }
1289
+ };
1246
1290
  function dispatchSee(problem, consequence, extras, kind) {
1247
1291
  if (!_server) {
1248
1292
  console.warn("[shipeasy] see() called before shipeasy({ serverKey }) \u2014 error dropped");
@@ -1259,10 +1303,13 @@ var see = Object.assign(
1259
1303
  );
1260
1304
  export {
1261
1305
  ANON_ID_COOKIE,
1306
+ Client,
1307
+ Engine,
1262
1308
  FLAG_REASONS,
1263
- FlagsClient,
1264
1309
  _murmur3ForTests,
1310
+ _resetConfigureForTests,
1265
1311
  _resetShipeasyServerForTests,
1312
+ configure,
1266
1313
  configureShipeasyServer,
1267
1314
  createInMemoryStickyStore,
1268
1315
  fetchLabelsForSSR,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipeasy/sdk",
3
- "version": "5.4.0",
3
+ "version": "6.0.0",
4
4
  "description": "Shipeasy SDK — feature gates, runtime configs, experiments, and metrics for the Shipeasy hosted service.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://shipeasy.ai",