@tehw0lf/yaft 0.0.4 → 0.0.5

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/jest.config.js CHANGED
@@ -7,6 +7,9 @@ module.exports = {
7
7
  globals: {},
8
8
  coverageDirectory: 'coverage/yaft',
9
9
  testEnvironment: "node",
10
+ testMatch: [
11
+ '<rootDir>/src/**/*.spec.ts'
12
+ ],
10
13
  transform: {
11
14
  "^.+\.tsx?$": ["ts-jest",{}],
12
15
  },
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@tehw0lf/yaft",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "YaFT - Feature Toggles using Go&PostgreSQL or any source!",
5
5
  "type": "commonjs",
6
6
  "scripts": {
7
7
  "build": "tsc && npm pkg delete devDependencies && cp package.json README.md logo.svg dist/",
8
- "test": "jest"
8
+ "test": "npx jest"
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
@@ -9,6 +9,7 @@ export type Feature = {
9
9
  value: string;
10
10
  activeAt: string;
11
11
  disabledAt: string;
12
+ tags?: string[];
12
13
  };
13
14
 
14
15
  export interface FeatureProvider<T> {
@@ -17,7 +17,7 @@ export class ApiServiceBooleanProvider implements FeatureProvider<boolean> {
17
17
  async getCollectionHash(configPathOrUrl: string): Promise<void> {
18
18
  try {
19
19
  const response = await axios.get(configPathOrUrl);
20
- const newHash = response.data.value;
20
+ const newHash = response.data.collectionHash || response.data.value;
21
21
  if (this.collectionHash !== newHash) {
22
22
  this.collectionHash = newHash;
23
23
  await this.getConfig(`${this.apiUrl}/features/${this.baseUUID}`);
@@ -30,7 +30,23 @@ export class ApiServiceBooleanProvider implements FeatureProvider<boolean> {
30
30
  async getConfig(configPathOrUrl: string): Promise<void> {
31
31
  try {
32
32
  const response = await axios.get(configPathOrUrl);
33
- this.data = response.data.value;
33
+ // Handle Go backend response format
34
+ const featuresArray = response.data.toggles || response.data.value || [];
35
+
36
+ // Convert array to keyed boolean object and handle capitalized field names
37
+ this.data = {};
38
+ if (Array.isArray(featuresArray)) {
39
+ featuresArray.forEach((feature: any) => {
40
+ const key = feature.key || feature.Key;
41
+ const value = feature.value || feature.Value;
42
+ if (key) {
43
+ this.data[key] = value === 'true' || value === true;
44
+ }
45
+ });
46
+ } else {
47
+ // Fallback for object format
48
+ this.data = featuresArray;
49
+ }
34
50
  } catch (error) {
35
51
  console.error("Failed to fetch feature toggle from API:", error);
36
52
  }
@@ -17,7 +17,7 @@ export class ApiServiceFeatureProvider implements FeatureProvider<Feature> {
17
17
  async getCollectionHash(configPathOrUrl: string): Promise<void> {
18
18
  try {
19
19
  const response = await axios.get(configPathOrUrl);
20
- const newHash = response.data.value;
20
+ const newHash = response.data.collectionHash || response.data.value;
21
21
  if (this.collectionHash !== newHash) {
22
22
  this.collectionHash = newHash;
23
23
  await this.getConfig(`${this.apiUrl}/features/${this.baseUUID}`);
@@ -30,7 +30,28 @@ export class ApiServiceFeatureProvider implements FeatureProvider<Feature> {
30
30
  async getConfig(configPathOrUrl: string): Promise<void> {
31
31
  try {
32
32
  const response = await axios.get(configPathOrUrl);
33
- this.data = response.data.value;
33
+ // Handle Go backend response format
34
+ const featuresArray = response.data.toggles || response.data.value || [];
35
+
36
+ // Convert array to keyed object and handle capitalized field names
37
+ this.data = {};
38
+ if (Array.isArray(featuresArray)) {
39
+ featuresArray.forEach((feature: any) => {
40
+ const normalizedFeature = {
41
+ key: feature.key || feature.Key,
42
+ value: feature.value || feature.Value,
43
+ activeAt: feature.activeAt || feature.ActiveAt,
44
+ disabledAt: feature.disabledAt || feature.DisabledAt,
45
+ tags: feature.tags || feature.Tags || [],
46
+ };
47
+ if (normalizedFeature.key) {
48
+ this.data[normalizedFeature.key] = normalizedFeature;
49
+ }
50
+ });
51
+ } else {
52
+ // Fallback for object format
53
+ this.data = featuresArray;
54
+ }
34
55
  } catch (error) {
35
56
  console.error("Failed to fetch feature toggle from API:", error);
36
57
  }
@@ -6,6 +6,7 @@ import axios from 'axios';
6
6
  // Mock axios for API provider tests
7
7
  jest.mock('axios');
8
8
  const mockedAxios = axios as jest.Mocked<typeof axios>;
9
+ mockedAxios.get = jest.fn();
9
10
 
10
11
  describe('Error Handling and Edge Cases', () => {
11
12
  let mockProvider: FeatureProvider<boolean>;
@@ -18,6 +19,8 @@ describe('Error Handling and Edge Cases', () => {
18
19
  };
19
20
  FeatureToggleBase.featureProvider = mockProvider;
20
21
  jest.clearAllMocks();
22
+ // Reset axios mock
23
+ (mockedAxios.get as jest.Mock).mockReset();
21
24
  });
22
25
 
23
26
  describe('Provider Initialization Errors', () => {
package/tsconfig.json CHANGED
@@ -6,5 +6,6 @@
6
6
  "declaration": true,
7
7
  "outDir": "./dist"
8
8
  },
9
- "include": ["**/**/*.ts"]
9
+ "include": ["src/**/*.ts"],
10
+ "exclude": ["**/*.spec.ts", "**/*.test.ts", "**/test/**/*"]
10
11
  }