@plyaz/core 1.0.3 → 1.0.4
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/README.md +33 -21
- package/dist/base/cache/index.d.ts.map +1 -1
- package/dist/base/cache/strategies/redis.d.ts.map +1 -1
- package/dist/domain/featureFlags/provider.d.ts.map +1 -1
- package/dist/index.cjs +10 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +11 -21
- package/dist/index.mjs.map +1 -1
- package/dist/utils/common/hash.d.ts.map +1 -1
- package/dist/utils/common/values.d.ts.map +1 -1
- package/dist/utils/featureFlags/context.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CACHE_MAX_SIZE_DEFAULT, CACHE_CLEANUP_INTERVAL_DEFAULT, FILE_CHECK_INTERVAL_DEFAULT, FEATURE_FLAG_FILE_PATHS, FEATURE_FLAG_CACHE_TTL_DEFAULT, FEATURES } from '@plyaz/config';
|
|
1
|
+
import { CACHE_MAX_SIZE_DEFAULT, CACHE_CLEANUP_INTERVAL_DEFAULT, TIME_CONSTANTS, FORMAT_CONSTANTS, FILE_CHECK_INTERVAL_DEFAULT, FEATURE_FLAG_FILE_PATHS, FEATURE_FLAG_CACHE_TTL_DEFAULT, MATH_CONSTANTS, ISO_STANDARDS, FEATURES } from '@plyaz/config';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import { promisify } from 'util';
|
|
@@ -23,8 +23,6 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
23
23
|
};
|
|
24
24
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
25
25
|
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
26
|
-
|
|
27
|
-
// src/utils/common/hash.ts
|
|
28
26
|
function hashString(str) {
|
|
29
27
|
const HASH_SHIFT = 5;
|
|
30
28
|
let hash = 0;
|
|
@@ -37,10 +35,10 @@ function hashString(str) {
|
|
|
37
35
|
}
|
|
38
36
|
__name(hashString, "hashString");
|
|
39
37
|
function isInRollout(identifier, percentage) {
|
|
40
|
-
if (percentage >=
|
|
38
|
+
if (percentage >= MATH_CONSTANTS.PERCENTAGE_MAX) return true;
|
|
41
39
|
if (percentage <= 0) return false;
|
|
42
40
|
const hash = hashString(identifier);
|
|
43
|
-
return hash %
|
|
41
|
+
return hash % MATH_CONSTANTS.PERCENTAGE_MAX < percentage;
|
|
44
42
|
}
|
|
45
43
|
__name(isInRollout, "isInRollout");
|
|
46
44
|
function createRolloutIdentifier(featureKey, userId) {
|
|
@@ -69,7 +67,7 @@ var HashUtils = {
|
|
|
69
67
|
* @param totalBuckets - Total number of buckets (default: 100)
|
|
70
68
|
* @returns true if identifier is in the bucket range
|
|
71
69
|
*/
|
|
72
|
-
isInBucketRange: /* @__PURE__ */ __name((identifier, startBucket, endBucket, totalBuckets =
|
|
70
|
+
isInBucketRange: /* @__PURE__ */ __name((identifier, startBucket, endBucket, totalBuckets = MATH_CONSTANTS.PERCENTAGE_MAX) => {
|
|
73
71
|
const bucket = hashString(identifier) % totalBuckets;
|
|
74
72
|
return bucket >= startBucket && bucket <= endBucket;
|
|
75
73
|
}, "isInBucketRange"),
|
|
@@ -84,8 +82,6 @@ var HashUtils = {
|
|
|
84
82
|
return hashString(str) % SAFE_INT;
|
|
85
83
|
}, "createSeed")
|
|
86
84
|
};
|
|
87
|
-
|
|
88
|
-
// src/utils/common/values.ts
|
|
89
85
|
function isStringFalsy(value) {
|
|
90
86
|
if (value === "") return true;
|
|
91
87
|
const lower = value.toLowerCase().trim();
|
|
@@ -151,7 +147,7 @@ var ValueUtils = {
|
|
|
151
147
|
*/
|
|
152
148
|
isValidPercentage: /* @__PURE__ */ __name((value) => {
|
|
153
149
|
if (typeof value !== "number") return false;
|
|
154
|
-
return !isNaN(value) && isFinite(value) && value >= 0 && value <=
|
|
150
|
+
return !isNaN(value) && isFinite(value) && value >= 0 && value <= MATH_CONSTANTS.PERCENTAGE_MAX;
|
|
155
151
|
}, "isValidPercentage"),
|
|
156
152
|
/**
|
|
157
153
|
* Clamps a number to a specific range.
|
|
@@ -197,8 +193,6 @@ var ValueUtils = {
|
|
|
197
193
|
return current;
|
|
198
194
|
}, "getNestedProperty")
|
|
199
195
|
};
|
|
200
|
-
|
|
201
|
-
// src/utils/featureFlags/context.ts
|
|
202
196
|
var FeatureFlagContextBuilder = class _FeatureFlagContextBuilder {
|
|
203
197
|
static {
|
|
204
198
|
__name(this, "FeatureFlagContextBuilder");
|
|
@@ -394,7 +388,7 @@ var ContextUtils = {
|
|
|
394
388
|
if (context.platform && !["web", "mobile", "desktop"].includes(context.platform)) {
|
|
395
389
|
errors.push("Platform must be web, mobile, or desktop");
|
|
396
390
|
}
|
|
397
|
-
if (context.country && context.country.length !==
|
|
391
|
+
if (context.country && context.country.length !== ISO_STANDARDS.ISO_COUNTRY_CODE_LENGTH) {
|
|
398
392
|
errors.push("Country must be a 2-letter ISO country code");
|
|
399
393
|
}
|
|
400
394
|
return {
|
|
@@ -1161,8 +1155,6 @@ var MemoryCacheStrategy = class {
|
|
|
1161
1155
|
}
|
|
1162
1156
|
}
|
|
1163
1157
|
};
|
|
1164
|
-
|
|
1165
|
-
// src/base/cache/strategies/redis.ts
|
|
1166
1158
|
var RedisCacheStrategy = class {
|
|
1167
1159
|
/**
|
|
1168
1160
|
* Creates a new Redis cache strategy.
|
|
@@ -1200,7 +1192,7 @@ var RedisCacheStrategy = class {
|
|
|
1200
1192
|
const redisKey = this.buildRedisKey(key);
|
|
1201
1193
|
const serializedEntry = JSON.stringify(entry);
|
|
1202
1194
|
const ttlMs = entry.expiresAt - Date.now();
|
|
1203
|
-
const ttlSeconds = Math.max(1, Math.ceil(ttlMs /
|
|
1195
|
+
const ttlSeconds = Math.max(1, Math.ceil(ttlMs / TIME_CONSTANTS.MILLISECONDS_PER_SECOND));
|
|
1204
1196
|
await this.client.set(redisKey, serializedEntry, "EX", ttlSeconds);
|
|
1205
1197
|
this.stats.setCount++;
|
|
1206
1198
|
}
|
|
@@ -1371,7 +1363,7 @@ var CacheManager = class {
|
|
|
1371
1363
|
const finalTtl = ttl ?? this.config.ttl;
|
|
1372
1364
|
const entry = {
|
|
1373
1365
|
data: value,
|
|
1374
|
-
expiresAt: Date.now() + finalTtl *
|
|
1366
|
+
expiresAt: Date.now() + finalTtl * TIME_CONSTANTS.MILLISECONDS_PER_SECOND,
|
|
1375
1367
|
createdAt: Date.now()
|
|
1376
1368
|
};
|
|
1377
1369
|
await this.strategy.set(key, entry);
|
|
@@ -1464,8 +1456,6 @@ var CacheManager = class {
|
|
|
1464
1456
|
await this.strategy.dispose?.();
|
|
1465
1457
|
}
|
|
1466
1458
|
};
|
|
1467
|
-
|
|
1468
|
-
// src/domain/featureFlags/provider.ts
|
|
1469
1459
|
var FeatureFlagProvider = class {
|
|
1470
1460
|
/**
|
|
1471
1461
|
* Creates a new feature flag provider.
|
|
@@ -1700,7 +1690,7 @@ var FeatureFlagProvider = class {
|
|
|
1700
1690
|
void this.refresh().catch((error) => {
|
|
1701
1691
|
this.log("Auto-refresh failed:", error);
|
|
1702
1692
|
});
|
|
1703
|
-
}, this.config.refreshInterval *
|
|
1693
|
+
}, this.config.refreshInterval * TIME_CONSTANTS.MILLISECONDS_PER_SECOND);
|
|
1704
1694
|
}
|
|
1705
1695
|
}
|
|
1706
1696
|
/**
|
|
@@ -2344,7 +2334,7 @@ var FileFeatureFlagProvider = class extends FeatureFlagProvider {
|
|
|
2344
2334
|
};
|
|
2345
2335
|
let content;
|
|
2346
2336
|
if (format === "json") {
|
|
2347
|
-
content = JSON.stringify(defaultData, null,
|
|
2337
|
+
content = JSON.stringify(defaultData, null, FORMAT_CONSTANTS.JSON_INDENT_SPACES);
|
|
2348
2338
|
} else {
|
|
2349
2339
|
content = yaml.stringify(defaultData);
|
|
2350
2340
|
}
|
|
@@ -2452,7 +2442,7 @@ var FileFeatureFlagProvider = class extends FeatureFlagProvider {
|
|
|
2452
2442
|
try {
|
|
2453
2443
|
let content;
|
|
2454
2444
|
if (format === "json") {
|
|
2455
|
-
content = JSON.stringify(fileData, null,
|
|
2445
|
+
content = JSON.stringify(fileData, null, FORMAT_CONSTANTS.JSON_INDENT_SPACES);
|
|
2456
2446
|
} else {
|
|
2457
2447
|
content = yaml.stringify(fileData);
|
|
2458
2448
|
}
|