@flipt-io/flipt-client-js 0.0.5 → 0.1.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.
@@ -583,6 +583,25 @@ exports.ErrorStrategy = void 0;
583
583
  /** The client will maintain the last known good state and use that state for evaluation in case of an error. */
584
584
  ErrorStrategy["Fallback"] = "fallback";
585
585
  })(exports.ErrorStrategy || (exports.ErrorStrategy = {}));
586
+ /**
587
+ * Factory class for creating default client options.
588
+ */
589
+ class ClientOptionsFactory {
590
+ /**
591
+ * Creates a default client options object.
592
+ * @returns {ClientOptions} A default client options object.
593
+ */
594
+ static default() {
595
+ return {
596
+ environment: 'default',
597
+ namespace: 'default',
598
+ url: 'http://localhost:8080',
599
+ reference: '',
600
+ updateInterval: 120,
601
+ errorStrategy: exports.ErrorStrategy.Fail
602
+ };
603
+ }
604
+ }
586
605
 
587
606
  function snakeToCamel(str) {
588
607
  return str.replace(/([-_][a-z])/g, (group) => group.toUpperCase().replace('-', '').replace('_', ''));
@@ -780,16 +799,11 @@ class FliptClient extends BaseFliptClient {
780
799
  * @param wasmOptions - options for loading WASM
781
800
  * @returns {Promise<FliptClient>}
782
801
  */
783
- static async init(options = {
784
- namespace: 'default',
785
- url: 'http://localhost:8080',
786
- reference: '',
787
- updateInterval: 120,
788
- errorStrategy: exports.ErrorStrategy.Fail
789
- }, wasmOptions) {
802
+ static async init(options = ClientOptionsFactory.default(), wasmOptions) {
790
803
  if (!wasmOptions || !wasmOptions.wasm) {
791
804
  throw new Error('WASM module must be provided in slim mode. Use the standard client or provide a wasm module.');
792
805
  }
806
+ const environment = options.environment ?? 'default';
793
807
  const namespace = options.namespace ?? 'default';
794
808
  let url = options.url ?? 'http://localhost:8080';
795
809
  url = url.replace(/\/$/, '');
@@ -799,7 +813,8 @@ class FliptClient extends BaseFliptClient {
799
813
  }
800
814
  const headers = {
801
815
  Accept: 'application/json',
802
- 'x-flipt-accept-server-version': '1.47.0'
816
+ 'x-flipt-accept-server-version': '1.47.0',
817
+ 'x-flipt-environment': environment
803
818
  };
804
819
  if (options.authentication) {
805
820
  if ('clientToken' in options.authentication) {
@@ -848,4 +863,5 @@ class FliptClient extends BaseFliptClient {
848
863
  }
849
864
 
850
865
  exports.BaseFliptClient = BaseFliptClient;
866
+ exports.ClientOptionsFactory = ClientOptionsFactory;
851
867
  exports.FliptClient = FliptClient;
@@ -580,6 +580,25 @@ var ErrorStrategy;
580
580
  /** The client will maintain the last known good state and use that state for evaluation in case of an error. */
581
581
  ErrorStrategy["Fallback"] = "fallback";
582
582
  })(ErrorStrategy || (ErrorStrategy = {}));
583
+ /**
584
+ * Factory class for creating default client options.
585
+ */
586
+ class ClientOptionsFactory {
587
+ /**
588
+ * Creates a default client options object.
589
+ * @returns {ClientOptions} A default client options object.
590
+ */
591
+ static default() {
592
+ return {
593
+ environment: 'default',
594
+ namespace: 'default',
595
+ url: 'http://localhost:8080',
596
+ reference: '',
597
+ updateInterval: 120,
598
+ errorStrategy: ErrorStrategy.Fail
599
+ };
600
+ }
601
+ }
583
602
 
584
603
  function snakeToCamel(str) {
585
604
  return str.replace(/([-_][a-z])/g, (group) => group.toUpperCase().replace('-', '').replace('_', ''));
@@ -777,16 +796,11 @@ class FliptClient extends BaseFliptClient {
777
796
  * @param wasmOptions - options for loading WASM
778
797
  * @returns {Promise<FliptClient>}
779
798
  */
780
- static async init(options = {
781
- namespace: 'default',
782
- url: 'http://localhost:8080',
783
- reference: '',
784
- updateInterval: 120,
785
- errorStrategy: ErrorStrategy.Fail
786
- }, wasmOptions) {
799
+ static async init(options = ClientOptionsFactory.default(), wasmOptions) {
787
800
  if (!wasmOptions || !wasmOptions.wasm) {
788
801
  throw new Error('WASM module must be provided in slim mode. Use the standard client or provide a wasm module.');
789
802
  }
803
+ const environment = options.environment ?? 'default';
790
804
  const namespace = options.namespace ?? 'default';
791
805
  let url = options.url ?? 'http://localhost:8080';
792
806
  url = url.replace(/\/$/, '');
@@ -796,7 +810,8 @@ class FliptClient extends BaseFliptClient {
796
810
  }
797
811
  const headers = {
798
812
  Accept: 'application/json',
799
- 'x-flipt-accept-server-version': '1.47.0'
813
+ 'x-flipt-accept-server-version': '1.47.0',
814
+ 'x-flipt-environment': environment
800
815
  };
801
816
  if (options.authentication) {
802
817
  if ('clientToken' in options.authentication) {
@@ -844,4 +859,4 @@ class FliptClient extends BaseFliptClient {
844
859
  }
845
860
  }
846
861
 
847
- export { BaseFliptClient, ErrorStrategy, FliptClient };
862
+ export { BaseFliptClient, ClientOptionsFactory, ErrorStrategy, FliptClient };
@@ -5,7 +5,6 @@ export * from '../core/base';
5
5
  export declare class FliptClient extends BaseFliptClient {
6
6
  /**
7
7
  * Initialize the client
8
- * @param namespace - optional namespace to evaluate flags
9
8
  * @param options - optional client options
10
9
  * @returns {Promise<FliptClient>}
11
10
  */
@@ -83,6 +83,12 @@ export interface JWTAuthentication extends AuthenticationStrategy {
83
83
  jwtToken: string;
84
84
  }
85
85
  export interface ClientOptions {
86
+ /**
87
+ * The environment to use when evaluating flags (Flipt v2)
88
+ *
89
+ * @defaultValue `default`
90
+ */
91
+ environment?: string;
86
92
  /**
87
93
  * The namespace to use when evaluating flags.
88
94
  *
@@ -250,3 +256,13 @@ export declare enum ErrorStrategy {
250
256
  /** The client will maintain the last known good state and use that state for evaluation in case of an error. */
251
257
  Fallback = "fallback"
252
258
  }
259
+ /**
260
+ * Factory class for creating default client options.
261
+ */
262
+ export declare class ClientOptionsFactory {
263
+ /**
264
+ * Creates a default client options object.
265
+ * @returns {ClientOptions} A default client options object.
266
+ */
267
+ static default(): ClientOptions;
268
+ }
package/engine.wasm.js CHANGED
@@ -1,2 +1,2 @@
1
- import wasmUrl from './dist/flipt_engine_wasm_js_bg.wasm';
1
+ import wasmUrl from './dist/flipt_engine_wasm_js_bg.wasm?url';
2
2
  export default wasmUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipt-io/flipt-client-js",
3
- "version": "0.0.5",
3
+ "version": "0.1.0",
4
4
  "description": "Flipt Client Evaluation SDK for Web and Node.js",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.cjs",
@@ -78,14 +78,17 @@
78
78
  "node-fetch": "^3.3.0"
79
79
  },
80
80
  "devDependencies": {
81
+ "@eslint/eslintrc": "^3.3.1",
82
+ "@eslint/js": "^9.28.0",
81
83
  "@rollup/plugin-typescript": "^12.1.0",
82
84
  "@rollup/plugin-wasm": "^6.2.2",
83
85
  "@types/jest": "^29.5.12",
84
86
  "@types/node": "^22.13.14",
85
87
  "@types/node-fetch": "^2.6.11",
86
- "@typescript-eslint/eslint-plugin": "^5.47.0",
87
- "@typescript-eslint/parser": "^5.47.0",
88
- "eslint": "^8.30.0",
88
+ "@typescript-eslint/eslint-plugin": "^8.33.1",
89
+ "@typescript-eslint/parser": "^8.33.1",
90
+ "eslint": "^9.28.0",
91
+ "globals": "^16.2.0",
89
92
  "jest": "^29.7.0",
90
93
  "node-fetch": "^3.3.0",
91
94
  "prettier": "^3.1.0",