@setgo/sdk 1.0.2 → 1.0.3
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/core/client.js +18 -22
- package/dist/core/index.js +4 -11
- package/dist/core/metrics-reporter.js +6 -10
- package/dist/core/repository.js +1 -5
- package/dist/core/strategy-evaluator.js +6 -10
- package/dist/errors/index.js +5 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -15
- package/dist/nestjs/index.js +3 -10
- package/dist/nestjs/setgo.constants.js +2 -5
- package/dist/nestjs/setgo.module.js +12 -15
- package/dist/nestjs/setgo.service.js +9 -12
- package/dist/types/config.js +1 -2
- package/dist/types/events.js +1 -2
- package/dist/types/features.js +1 -2
- package/dist/types/index.js +1 -2
- package/dist/types/metrics.js +1 -2
- package/dist/utils/index.js +2 -9
- package/dist/utils/ip-matcher.js +2 -6
- package/dist/utils/murmurhash.js +2 -6
- package/package.json +4 -1
package/dist/core/client.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* SetGo Client - main SDK entry point
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const strategy_evaluator_js_1 = require("./strategy-evaluator.js");
|
|
10
|
-
const index_js_1 = require("../errors/index.js");
|
|
4
|
+
import { FeatureRepository } from './repository.js';
|
|
5
|
+
import { MetricsReporter } from './metrics-reporter.js';
|
|
6
|
+
import { StrategyEvaluator } from './strategy-evaluator.js';
|
|
7
|
+
import { ConfigurationError, NetworkError, AuthenticationError, TimeoutError, } from '../errors/index.js';
|
|
11
8
|
const SDK_VERSION = '1.0.0';
|
|
12
|
-
class SetGoClient {
|
|
9
|
+
export class SetGoClient {
|
|
13
10
|
config;
|
|
14
11
|
repository;
|
|
15
12
|
metricsReporter;
|
|
@@ -32,9 +29,9 @@ class SetGoClient {
|
|
|
32
29
|
timeout: config.timeout ?? 10000,
|
|
33
30
|
disableMetrics: config.disableMetrics ?? false,
|
|
34
31
|
};
|
|
35
|
-
this.repository = new
|
|
36
|
-
this.metricsReporter = new
|
|
37
|
-
this.evaluator = new
|
|
32
|
+
this.repository = new FeatureRepository();
|
|
33
|
+
this.metricsReporter = new MetricsReporter(this.config);
|
|
34
|
+
this.evaluator = new StrategyEvaluator();
|
|
38
35
|
// Initialize event maps
|
|
39
36
|
this.events.set('ready', new Set());
|
|
40
37
|
this.events.set('update', new Set());
|
|
@@ -45,13 +42,13 @@ class SetGoClient {
|
|
|
45
42
|
*/
|
|
46
43
|
validateConfig(config) {
|
|
47
44
|
if (!config.baseUrl) {
|
|
48
|
-
throw new
|
|
45
|
+
throw new ConfigurationError('baseUrl is required');
|
|
49
46
|
}
|
|
50
47
|
if (!config.token) {
|
|
51
|
-
throw new
|
|
48
|
+
throw new ConfigurationError('token is required');
|
|
52
49
|
}
|
|
53
50
|
if (!config.appName) {
|
|
54
|
-
throw new
|
|
51
|
+
throw new ConfigurationError('appName is required');
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
/**
|
|
@@ -206,23 +203,23 @@ class SetGoClient {
|
|
|
206
203
|
return response;
|
|
207
204
|
}
|
|
208
205
|
if (response.status === 401 || response.status === 403) {
|
|
209
|
-
throw new
|
|
206
|
+
throw new AuthenticationError();
|
|
210
207
|
}
|
|
211
208
|
if (!response.ok) {
|
|
212
|
-
throw new
|
|
209
|
+
throw new NetworkError(`Request failed: ${response.statusText}`, response.status);
|
|
213
210
|
}
|
|
214
211
|
return response;
|
|
215
212
|
}
|
|
216
213
|
catch (error) {
|
|
217
214
|
if (error instanceof Error && error.name === 'AbortError') {
|
|
218
|
-
throw new
|
|
215
|
+
throw new TimeoutError();
|
|
219
216
|
}
|
|
220
|
-
if (error instanceof
|
|
221
|
-
error instanceof
|
|
222
|
-
error instanceof
|
|
217
|
+
if (error instanceof NetworkError ||
|
|
218
|
+
error instanceof AuthenticationError ||
|
|
219
|
+
error instanceof TimeoutError) {
|
|
223
220
|
throw error;
|
|
224
221
|
}
|
|
225
|
-
throw new
|
|
222
|
+
throw new NetworkError(`Request failed: ${error instanceof Error ? error.message : 'Unknown error'}`, undefined, error instanceof Error ? error : undefined);
|
|
226
223
|
}
|
|
227
224
|
finally {
|
|
228
225
|
clearTimeout(timeoutId);
|
|
@@ -316,4 +313,3 @@ class SetGoClient {
|
|
|
316
313
|
}
|
|
317
314
|
}
|
|
318
315
|
}
|
|
319
|
-
exports.SetGoClient = SetGoClient;
|
package/dist/core/index.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* SetGo SDK Core - Re-exports
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var repository_js_1 = require("./repository.js");
|
|
10
|
-
Object.defineProperty(exports, "FeatureRepository", { enumerable: true, get: function () { return repository_js_1.FeatureRepository; } });
|
|
11
|
-
var strategy_evaluator_js_1 = require("./strategy-evaluator.js");
|
|
12
|
-
Object.defineProperty(exports, "StrategyEvaluator", { enumerable: true, get: function () { return strategy_evaluator_js_1.StrategyEvaluator; } });
|
|
13
|
-
var metrics_reporter_js_1 = require("./metrics-reporter.js");
|
|
14
|
-
Object.defineProperty(exports, "MetricsReporter", { enumerable: true, get: function () { return metrics_reporter_js_1.MetricsReporter; } });
|
|
4
|
+
export { SetGoClient } from './client.js';
|
|
5
|
+
export { FeatureRepository } from './repository.js';
|
|
6
|
+
export { StrategyEvaluator } from './strategy-evaluator.js';
|
|
7
|
+
export { MetricsReporter } from './metrics-reporter.js';
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Metrics Reporter - collects and sends usage metrics
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const index_js_1 = require("../errors/index.js");
|
|
8
|
-
class MetricsReporter {
|
|
4
|
+
import { NetworkError, TimeoutError } from '../errors/index.js';
|
|
5
|
+
export class MetricsReporter {
|
|
9
6
|
metrics = new Map();
|
|
10
7
|
bucketStart;
|
|
11
8
|
sendInterval;
|
|
@@ -126,17 +123,17 @@ class MetricsReporter {
|
|
|
126
123
|
signal: controller.signal,
|
|
127
124
|
});
|
|
128
125
|
if (!response.ok) {
|
|
129
|
-
throw new
|
|
126
|
+
throw new NetworkError(`Failed to send metrics: ${response.statusText}`, response.status);
|
|
130
127
|
}
|
|
131
128
|
}
|
|
132
129
|
catch (error) {
|
|
133
130
|
if (error instanceof Error && error.name === 'AbortError') {
|
|
134
|
-
throw new
|
|
131
|
+
throw new TimeoutError('Metrics request timed out');
|
|
135
132
|
}
|
|
136
|
-
if (error instanceof
|
|
133
|
+
if (error instanceof NetworkError) {
|
|
137
134
|
throw error;
|
|
138
135
|
}
|
|
139
|
-
throw new
|
|
136
|
+
throw new NetworkError(`Failed to send metrics: ${error instanceof Error ? error.message : 'Unknown error'}`, undefined, error instanceof Error ? error : undefined);
|
|
140
137
|
}
|
|
141
138
|
finally {
|
|
142
139
|
clearTimeout(timeoutId);
|
|
@@ -149,4 +146,3 @@ class MetricsReporter {
|
|
|
149
146
|
return this.metrics.size;
|
|
150
147
|
}
|
|
151
148
|
}
|
|
152
|
-
exports.MetricsReporter = MetricsReporter;
|
package/dist/core/repository.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* In-memory feature repository
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
exports.FeatureRepository = void 0;
|
|
7
|
-
class FeatureRepository {
|
|
4
|
+
export class FeatureRepository {
|
|
8
5
|
features = new Map();
|
|
9
6
|
version = 0;
|
|
10
7
|
/**
|
|
@@ -55,4 +52,3 @@ class FeatureRepository {
|
|
|
55
52
|
this.version = 0;
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
|
-
exports.FeatureRepository = FeatureRepository;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Strategy Evaluator - evaluates feature flag strategies locally
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const ip_matcher_js_1 = require("../utils/ip-matcher.js");
|
|
9
|
-
class StrategyEvaluator {
|
|
4
|
+
import { normalizedHash } from '../utils/murmurhash.js';
|
|
5
|
+
import { matchIPList } from '../utils/ip-matcher.js';
|
|
6
|
+
export class StrategyEvaluator {
|
|
10
7
|
/**
|
|
11
8
|
* Evaluate a single strategy
|
|
12
9
|
*/
|
|
@@ -69,7 +66,7 @@ class StrategyEvaluator {
|
|
|
69
66
|
// If no identifier available, use random for this evaluation
|
|
70
67
|
identifier = Math.random().toString();
|
|
71
68
|
}
|
|
72
|
-
const hash =
|
|
69
|
+
const hash = normalizedHash(groupId, identifier, 100);
|
|
73
70
|
return hash <= percentage;
|
|
74
71
|
}
|
|
75
72
|
/**
|
|
@@ -113,7 +110,7 @@ class StrategyEvaluator {
|
|
|
113
110
|
if (!identifier) {
|
|
114
111
|
identifier = Math.random().toString();
|
|
115
112
|
}
|
|
116
|
-
const hash =
|
|
113
|
+
const hash = normalizedHash(groupId, identifier, 100);
|
|
117
114
|
return hash <= rollout;
|
|
118
115
|
}
|
|
119
116
|
/**
|
|
@@ -126,7 +123,7 @@ class StrategyEvaluator {
|
|
|
126
123
|
const ips = params?.ips ?? [];
|
|
127
124
|
if (ips.length === 0)
|
|
128
125
|
return false;
|
|
129
|
-
return
|
|
126
|
+
return matchIPList(context.remoteAddress, ips);
|
|
130
127
|
}
|
|
131
128
|
/**
|
|
132
129
|
* Check if context satisfies all constraints
|
|
@@ -206,4 +203,3 @@ class StrategyEvaluator {
|
|
|
206
203
|
}
|
|
207
204
|
}
|
|
208
205
|
}
|
|
209
|
-
exports.StrategyEvaluator = StrategyEvaluator;
|
package/dist/errors/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* SetGo SDK Error Classes
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
exports.TimeoutError = exports.AuthenticationError = exports.ConfigurationError = exports.NetworkError = exports.SetGoError = void 0;
|
|
7
|
-
class SetGoError extends Error {
|
|
4
|
+
export class SetGoError extends Error {
|
|
8
5
|
code;
|
|
9
6
|
constructor(message, code) {
|
|
10
7
|
super(message);
|
|
@@ -13,8 +10,7 @@ class SetGoError extends Error {
|
|
|
13
10
|
Object.setPrototypeOf(this, SetGoError.prototype);
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
class NetworkError extends SetGoError {
|
|
13
|
+
export class NetworkError extends SetGoError {
|
|
18
14
|
statusCode;
|
|
19
15
|
cause;
|
|
20
16
|
constructor(message, statusCode, cause) {
|
|
@@ -25,28 +21,24 @@ class NetworkError extends SetGoError {
|
|
|
25
21
|
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
class ConfigurationError extends SetGoError {
|
|
24
|
+
export class ConfigurationError extends SetGoError {
|
|
30
25
|
constructor(message) {
|
|
31
26
|
super(message, 'CONFIGURATION_ERROR');
|
|
32
27
|
this.name = 'ConfigurationError';
|
|
33
28
|
Object.setPrototypeOf(this, ConfigurationError.prototype);
|
|
34
29
|
}
|
|
35
30
|
}
|
|
36
|
-
|
|
37
|
-
class AuthenticationError extends SetGoError {
|
|
31
|
+
export class AuthenticationError extends SetGoError {
|
|
38
32
|
constructor(message = 'Invalid or expired API token') {
|
|
39
33
|
super(message, 'AUTHENTICATION_ERROR');
|
|
40
34
|
this.name = 'AuthenticationError';
|
|
41
35
|
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
42
36
|
}
|
|
43
37
|
}
|
|
44
|
-
|
|
45
|
-
class TimeoutError extends SetGoError {
|
|
38
|
+
export class TimeoutError extends SetGoError {
|
|
46
39
|
constructor(message = 'Request timed out') {
|
|
47
40
|
super(message, 'TIMEOUT_ERROR');
|
|
48
41
|
this.name = 'TimeoutError';
|
|
49
42
|
Object.setPrototypeOf(this, TimeoutError.prototype);
|
|
50
43
|
}
|
|
51
44
|
}
|
|
52
|
-
exports.TimeoutError = TimeoutError;
|
package/dist/index.d.ts
CHANGED
|
@@ -22,4 +22,5 @@ export { SetGoClient } from './core/index.js';
|
|
|
22
22
|
export type { SetGoConfig, ResolvedSetGoConfig, FeatureContext, Feature, Strategy, StrategyType, FeaturesResponse, SetGoEventType, SetGoEventHandler, SetGoReadyEvent, SetGoUpdateEvent, SetGoErrorEvent, SetGoEvent, FeatureMetric, MetricsPayload, RegisterPayload, SetGoModuleAsyncOptions, } from './types/index.js';
|
|
23
23
|
export { SetGoError, NetworkError, ConfigurationError, AuthenticationError, TimeoutError, } from './errors/index.js';
|
|
24
24
|
export { FeatureRepository, StrategyEvaluator, MetricsReporter } from './core/index.js';
|
|
25
|
+
export { SetGoModule, SetGoService, SETGO_CONFIG, SETGO_CLIENT } from './nestjs/index.js';
|
|
25
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,aAAa,EACb,cAAc,EACd,eAAe,EACf,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,GACb,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,aAAa,EACb,cAAc,EACd,eAAe,EACf,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,GACb,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGxF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* SetGo SDK - Feature Flag Management
|
|
4
3
|
*
|
|
@@ -19,20 +18,11 @@
|
|
|
19
18
|
* }
|
|
20
19
|
* ```
|
|
21
20
|
*/
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.MetricsReporter = exports.StrategyEvaluator = exports.FeatureRepository = exports.TimeoutError = exports.AuthenticationError = exports.ConfigurationError = exports.NetworkError = exports.SetGoError = exports.SetGoClient = void 0;
|
|
24
21
|
// Main client
|
|
25
|
-
|
|
26
|
-
Object.defineProperty(exports, "SetGoClient", { enumerable: true, get: function () { return index_js_1.SetGoClient; } });
|
|
22
|
+
export { SetGoClient } from './core/index.js';
|
|
27
23
|
// Errors
|
|
28
|
-
|
|
29
|
-
Object.defineProperty(exports, "SetGoError", { enumerable: true, get: function () { return index_js_2.SetGoError; } });
|
|
30
|
-
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return index_js_2.NetworkError; } });
|
|
31
|
-
Object.defineProperty(exports, "ConfigurationError", { enumerable: true, get: function () { return index_js_2.ConfigurationError; } });
|
|
32
|
-
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return index_js_2.AuthenticationError; } });
|
|
33
|
-
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return index_js_2.TimeoutError; } });
|
|
24
|
+
export { SetGoError, NetworkError, ConfigurationError, AuthenticationError, TimeoutError, } from './errors/index.js';
|
|
34
25
|
// Internal (for advanced usage)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Object.defineProperty(exports, "MetricsReporter", { enumerable: true, get: function () { return index_js_3.MetricsReporter; } });
|
|
26
|
+
export { FeatureRepository, StrategyEvaluator, MetricsReporter } from './core/index.js';
|
|
27
|
+
// NestJS Module (optional - only available when @nestjs/common is installed)
|
|
28
|
+
export { SetGoModule, SetGoService, SETGO_CONFIG, SETGO_CLIENT } from './nestjs/index.js';
|
package/dist/nestjs/index.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* SetGo NestJS Module Exports
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, "SetGoModule", { enumerable: true, get: function () { return setgo_module_js_1.SetGoModule; } });
|
|
9
|
-
var setgo_service_js_1 = require("./setgo.service.js");
|
|
10
|
-
Object.defineProperty(exports, "SetGoService", { enumerable: true, get: function () { return setgo_service_js_1.SetGoService; } });
|
|
11
|
-
var setgo_constants_js_1 = require("./setgo.constants.js");
|
|
12
|
-
Object.defineProperty(exports, "SETGO_CONFIG", { enumerable: true, get: function () { return setgo_constants_js_1.SETGO_CONFIG; } });
|
|
13
|
-
Object.defineProperty(exports, "SETGO_CLIENT", { enumerable: true, get: function () { return setgo_constants_js_1.SETGO_CLIENT; } });
|
|
4
|
+
export { SetGoModule } from './setgo.module.js';
|
|
5
|
+
export { SetGoService } from './setgo.service.js';
|
|
6
|
+
export { SETGO_CONFIG, SETGO_CLIENT } from './setgo.constants.js';
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* SetGo NestJS Module Constants
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.SETGO_CONFIG = Symbol('SETGO_CONFIG');
|
|
8
|
-
exports.SETGO_CLIENT = Symbol('SETGO_CLIENT');
|
|
4
|
+
export const SETGO_CONFIG = Symbol('SETGO_CONFIG');
|
|
5
|
+
export const SETGO_CLIENT = Symbol('SETGO_CLIENT');
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* SetGo NestJS Module
|
|
4
3
|
*/
|
|
@@ -9,11 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
9
8
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
9
|
};
|
|
11
10
|
var SetGoModule_1;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const setgo_constants_js_1 = require("./setgo.constants.js");
|
|
16
|
-
const setgo_service_js_1 = require("./setgo.service.js");
|
|
11
|
+
import { Module } from '@nestjs/common';
|
|
12
|
+
import { SETGO_CONFIG } from './setgo.constants.js';
|
|
13
|
+
import { SetGoService } from './setgo.service.js';
|
|
17
14
|
let SetGoModule = SetGoModule_1 = class SetGoModule {
|
|
18
15
|
/**
|
|
19
16
|
* Register the module with static configuration
|
|
@@ -24,12 +21,12 @@ let SetGoModule = SetGoModule_1 = class SetGoModule {
|
|
|
24
21
|
global: true,
|
|
25
22
|
providers: [
|
|
26
23
|
{
|
|
27
|
-
provide:
|
|
24
|
+
provide: SETGO_CONFIG,
|
|
28
25
|
useValue: config,
|
|
29
26
|
},
|
|
30
|
-
|
|
27
|
+
SetGoService,
|
|
31
28
|
],
|
|
32
|
-
exports: [
|
|
29
|
+
exports: [SetGoService],
|
|
33
30
|
};
|
|
34
31
|
}
|
|
35
32
|
/**
|
|
@@ -41,8 +38,8 @@ let SetGoModule = SetGoModule_1 = class SetGoModule {
|
|
|
41
38
|
module: SetGoModule_1,
|
|
42
39
|
global: true,
|
|
43
40
|
imports: options.imports,
|
|
44
|
-
providers: [...asyncProviders,
|
|
45
|
-
exports: [
|
|
41
|
+
providers: [...asyncProviders, SetGoService],
|
|
42
|
+
exports: [SetGoService],
|
|
46
43
|
};
|
|
47
44
|
}
|
|
48
45
|
/**
|
|
@@ -51,14 +48,14 @@ let SetGoModule = SetGoModule_1 = class SetGoModule {
|
|
|
51
48
|
static createAsyncProviders(options) {
|
|
52
49
|
return [
|
|
53
50
|
{
|
|
54
|
-
provide:
|
|
51
|
+
provide: SETGO_CONFIG,
|
|
55
52
|
useFactory: options.useFactory,
|
|
56
53
|
inject: options.inject,
|
|
57
54
|
},
|
|
58
55
|
];
|
|
59
56
|
}
|
|
60
57
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
(0, common_1.Module)({})
|
|
58
|
+
SetGoModule = SetGoModule_1 = __decorate([
|
|
59
|
+
Module({})
|
|
64
60
|
], SetGoModule);
|
|
61
|
+
export { SetGoModule };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* SetGo NestJS Service
|
|
4
3
|
*/
|
|
@@ -15,16 +14,14 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
15
14
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
16
15
|
};
|
|
17
16
|
var SetGoService_1;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const index_js_1 = require("../core/index.js");
|
|
22
|
-
const setgo_constants_js_1 = require("./setgo.constants.js");
|
|
17
|
+
import { Inject, Injectable, Logger } from '@nestjs/common';
|
|
18
|
+
import { SetGoClient } from '../core/index.js';
|
|
19
|
+
import { SETGO_CONFIG } from './setgo.constants.js';
|
|
23
20
|
let SetGoService = SetGoService_1 = class SetGoService {
|
|
24
21
|
client;
|
|
25
|
-
logger = new
|
|
22
|
+
logger = new Logger(SetGoService_1.name);
|
|
26
23
|
constructor(config) {
|
|
27
|
-
this.client = new
|
|
24
|
+
this.client = new SetGoClient(config);
|
|
28
25
|
}
|
|
29
26
|
async onModuleInit() {
|
|
30
27
|
try {
|
|
@@ -76,9 +73,9 @@ let SetGoService = SetGoService_1 = class SetGoService {
|
|
|
76
73
|
return this.client;
|
|
77
74
|
}
|
|
78
75
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
(0,
|
|
82
|
-
__param(0, (0, common_1.Inject)(setgo_constants_js_1.SETGO_CONFIG)),
|
|
76
|
+
SetGoService = SetGoService_1 = __decorate([
|
|
77
|
+
Injectable(),
|
|
78
|
+
__param(0, Inject(SETGO_CONFIG)),
|
|
83
79
|
__metadata("design:paramtypes", [Object])
|
|
84
80
|
], SetGoService);
|
|
81
|
+
export { SetGoService };
|
package/dist/types/config.js
CHANGED
package/dist/types/events.js
CHANGED
package/dist/types/features.js
CHANGED
package/dist/types/index.js
CHANGED
package/dist/types/metrics.js
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Utility functions
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var murmurhash_js_1 = require("./murmurhash.js");
|
|
8
|
-
Object.defineProperty(exports, "murmurhash3", { enumerable: true, get: function () { return murmurhash_js_1.murmurhash3; } });
|
|
9
|
-
Object.defineProperty(exports, "normalizedHash", { enumerable: true, get: function () { return murmurhash_js_1.normalizedHash; } });
|
|
10
|
-
var ip_matcher_js_1 = require("./ip-matcher.js");
|
|
11
|
-
Object.defineProperty(exports, "matchIP", { enumerable: true, get: function () { return ip_matcher_js_1.matchIP; } });
|
|
12
|
-
Object.defineProperty(exports, "matchIPList", { enumerable: true, get: function () { return ip_matcher_js_1.matchIPList; } });
|
|
4
|
+
export { murmurhash3, normalizedHash } from './murmurhash.js';
|
|
5
|
+
export { matchIP, matchIPList } from './ip-matcher.js';
|
package/dist/utils/ip-matcher.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* IP Address Matcher Utility
|
|
4
3
|
* Supports exact IPs, CIDR notation, and wildcards
|
|
5
4
|
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.matchIP = matchIP;
|
|
8
|
-
exports.matchIPList = matchIPList;
|
|
9
5
|
function parseIPv4(ip) {
|
|
10
6
|
const parts = ip.split('.');
|
|
11
7
|
if (parts.length !== 4)
|
|
@@ -131,7 +127,7 @@ function matchExact(ip, pattern) {
|
|
|
131
127
|
* Check if an IP address matches a pattern
|
|
132
128
|
* Supports: exact match, CIDR notation, wildcards (*)
|
|
133
129
|
*/
|
|
134
|
-
function matchIP(ip, pattern) {
|
|
130
|
+
export function matchIP(ip, pattern) {
|
|
135
131
|
const parsedIP = parseIP(ip);
|
|
136
132
|
if (!parsedIP)
|
|
137
133
|
return false;
|
|
@@ -160,6 +156,6 @@ function matchIP(ip, pattern) {
|
|
|
160
156
|
/**
|
|
161
157
|
* Check if an IP matches any pattern in the list
|
|
162
158
|
*/
|
|
163
|
-
function matchIPList(ip, patterns) {
|
|
159
|
+
export function matchIPList(ip, patterns) {
|
|
164
160
|
return patterns.some((pattern) => matchIP(ip, pattern));
|
|
165
161
|
}
|
package/dist/utils/murmurhash.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* MurmurHash3 implementation for consistent hashing
|
|
4
3
|
* Used for gradual rollout percentages
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
exports.murmurhash3 = murmurhash3;
|
|
8
|
-
exports.normalizedHash = normalizedHash;
|
|
9
|
-
function murmurhash3(key, seed = 0) {
|
|
5
|
+
export function murmurhash3(key, seed = 0) {
|
|
10
6
|
const remainder = key.length & 3;
|
|
11
7
|
const bytes = key.length - remainder;
|
|
12
8
|
let h1 = seed;
|
|
@@ -52,7 +48,7 @@ function murmurhash3(key, seed = 0) {
|
|
|
52
48
|
/**
|
|
53
49
|
* Normalize hash to a percentage (0-100)
|
|
54
50
|
*/
|
|
55
|
-
function normalizedHash(groupId, identifier, normalizer = 100) {
|
|
51
|
+
export function normalizedHash(groupId, identifier, normalizer = 100) {
|
|
56
52
|
const key = `${groupId}:${identifier}`;
|
|
57
53
|
const hash = murmurhash3(key);
|
|
58
54
|
return (hash % normalizer) + 1;
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@setgo/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "SDK oficial do SetGo Feature Flags",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Scoder Tech",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
10
|
"url": "git+https://github.com/Scoder-Tech/SetGo-SDK.git"
|
|
@@ -30,10 +31,12 @@
|
|
|
30
31
|
"exports": {
|
|
31
32
|
".": {
|
|
32
33
|
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
33
35
|
"default": "./dist/index.js"
|
|
34
36
|
},
|
|
35
37
|
"./nestjs": {
|
|
36
38
|
"types": "./dist/nestjs/index.d.ts",
|
|
39
|
+
"import": "./dist/nestjs/index.js",
|
|
37
40
|
"default": "./dist/nestjs/index.js"
|
|
38
41
|
}
|
|
39
42
|
},
|