@setgo/sdk 1.0.1
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 +184 -0
- package/dist/core/client.d.ts +81 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +319 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +14 -0
- package/dist/core/metrics-reporter.d.ts +40 -0
- package/dist/core/metrics-reporter.d.ts.map +1 -0
- package/dist/core/metrics-reporter.js +152 -0
- package/dist/core/repository.d.ts +37 -0
- package/dist/core/repository.d.ts.map +1 -0
- package/dist/core/repository.js +58 -0
- package/dist/core/strategy-evaluator.d.ts +43 -0
- package/dist/core/strategy-evaluator.d.ts.map +1 -0
- package/dist/core/strategy-evaluator.js +209 -0
- package/dist/errors/index.d.ts +22 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +52 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/nestjs/index.d.ts +7 -0
- package/dist/nestjs/index.d.ts.map +1 -0
- package/dist/nestjs/index.js +13 -0
- package/dist/nestjs/setgo.constants.d.ts +6 -0
- package/dist/nestjs/setgo.constants.d.ts.map +1 -0
- package/dist/nestjs/setgo.constants.js +8 -0
- package/dist/nestjs/setgo.module.d.ts +20 -0
- package/dist/nestjs/setgo.module.d.ts.map +1 -0
- package/dist/nestjs/setgo.module.js +64 -0
- package/dist/nestjs/setgo.service.d.ts +34 -0
- package/dist/nestjs/setgo.service.d.ts.map +1 -0
- package/dist/nestjs/setgo.service.js +84 -0
- package/dist/types/config.d.ts +41 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +5 -0
- package/dist/types/events.d.ts +21 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +5 -0
- package/dist/types/features.d.ts +41 -0
- package/dist/types/features.d.ts.map +1 -0
- package/dist/types/features.js +5 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/metrics.d.ts +16 -0
- package/dist/types/metrics.d.ts.map +1 -0
- package/dist/types/metrics.js +5 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +12 -0
- package/dist/utils/ip-matcher.d.ts +14 -0
- package/dist/utils/ip-matcher.d.ts.map +1 -0
- package/dist/utils/ip-matcher.js +165 -0
- package/dist/utils/murmurhash.d.ts +10 -0
- package/dist/utils/murmurhash.d.ts.map +1 -0
- package/dist/utils/murmurhash.js +59 -0
- package/package.json +72 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setgo.constants.d.ts","sourceRoot":"","sources":["../../src/nestjs/setgo.constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,YAAY,eAAyB,CAAC;AACnD,eAAO,MAAM,YAAY,eAAyB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SetGo NestJS Module Constants
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SETGO_CLIENT = exports.SETGO_CONFIG = void 0;
|
|
7
|
+
exports.SETGO_CONFIG = Symbol('SETGO_CONFIG');
|
|
8
|
+
exports.SETGO_CLIENT = Symbol('SETGO_CLIENT');
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SetGo NestJS Module
|
|
3
|
+
*/
|
|
4
|
+
import type { DynamicModule } from '@nestjs/common';
|
|
5
|
+
import type { SetGoConfig, SetGoModuleAsyncOptions } from '../types/index.js';
|
|
6
|
+
export declare class SetGoModule {
|
|
7
|
+
/**
|
|
8
|
+
* Register the module with static configuration
|
|
9
|
+
*/
|
|
10
|
+
static forRoot(config: SetGoConfig): DynamicModule;
|
|
11
|
+
/**
|
|
12
|
+
* Register the module with async configuration
|
|
13
|
+
*/
|
|
14
|
+
static forRootAsync(options: SetGoModuleAsyncOptions): DynamicModule;
|
|
15
|
+
/**
|
|
16
|
+
* Create async providers
|
|
17
|
+
*/
|
|
18
|
+
private static createAsyncProviders;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=setgo.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setgo.module.d.ts","sourceRoot":"","sources":["../../src/nestjs/setgo.module.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,gBAAgB,CAAC;AAGpE,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAI9E,qBACa,WAAW;IACtB;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,aAAa;IAelD;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,uBAAuB,GAAG,aAAa;IAYpE;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;CASpC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SetGo NestJS Module
|
|
4
|
+
*/
|
|
5
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
6
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var SetGoModule_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.SetGoModule = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const setgo_constants_js_1 = require("./setgo.constants.js");
|
|
16
|
+
const setgo_service_js_1 = require("./setgo.service.js");
|
|
17
|
+
let SetGoModule = SetGoModule_1 = class SetGoModule {
|
|
18
|
+
/**
|
|
19
|
+
* Register the module with static configuration
|
|
20
|
+
*/
|
|
21
|
+
static forRoot(config) {
|
|
22
|
+
return {
|
|
23
|
+
module: SetGoModule_1,
|
|
24
|
+
global: true,
|
|
25
|
+
providers: [
|
|
26
|
+
{
|
|
27
|
+
provide: setgo_constants_js_1.SETGO_CONFIG,
|
|
28
|
+
useValue: config,
|
|
29
|
+
},
|
|
30
|
+
setgo_service_js_1.SetGoService,
|
|
31
|
+
],
|
|
32
|
+
exports: [setgo_service_js_1.SetGoService],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Register the module with async configuration
|
|
37
|
+
*/
|
|
38
|
+
static forRootAsync(options) {
|
|
39
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
40
|
+
return {
|
|
41
|
+
module: SetGoModule_1,
|
|
42
|
+
global: true,
|
|
43
|
+
imports: options.imports,
|
|
44
|
+
providers: [...asyncProviders, setgo_service_js_1.SetGoService],
|
|
45
|
+
exports: [setgo_service_js_1.SetGoService],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create async providers
|
|
50
|
+
*/
|
|
51
|
+
static createAsyncProviders(options) {
|
|
52
|
+
return [
|
|
53
|
+
{
|
|
54
|
+
provide: setgo_constants_js_1.SETGO_CONFIG,
|
|
55
|
+
useFactory: options.useFactory,
|
|
56
|
+
inject: options.inject,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.SetGoModule = SetGoModule;
|
|
62
|
+
exports.SetGoModule = SetGoModule = SetGoModule_1 = __decorate([
|
|
63
|
+
(0, common_1.Module)({})
|
|
64
|
+
], SetGoModule);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SetGo NestJS Service
|
|
3
|
+
*/
|
|
4
|
+
import type { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
|
5
|
+
import { SetGoClient } from '../core/index.js';
|
|
6
|
+
import type { Feature, FeatureContext, SetGoConfig } from '../types/index.js';
|
|
7
|
+
export declare class SetGoService implements OnModuleInit, OnModuleDestroy {
|
|
8
|
+
private readonly client;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
constructor(config: SetGoConfig);
|
|
11
|
+
onModuleInit(): Promise<void>;
|
|
12
|
+
onModuleDestroy(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Check if a feature is enabled
|
|
15
|
+
*/
|
|
16
|
+
isEnabled(featureName: string, context?: FeatureContext): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Get a feature by name
|
|
19
|
+
*/
|
|
20
|
+
getFeature(featureName: string): Feature | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Get all features
|
|
23
|
+
*/
|
|
24
|
+
getAllFeatures(): Feature[];
|
|
25
|
+
/**
|
|
26
|
+
* Check if the client is ready
|
|
27
|
+
*/
|
|
28
|
+
isReady(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Get the underlying client (for advanced usage)
|
|
31
|
+
*/
|
|
32
|
+
getClient(): SetGoClient;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=setgo.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setgo.service.d.ts","sourceRoot":"","sources":["../../src/nestjs/setgo.service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGpE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG9E,qBACa,YAAa,YAAW,YAAY,EAAE,eAAe;IAChE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiC;gBAEtB,MAAM,EAAE,WAAW;IAI/C,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAU7B,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAStC;;OAEG;IACH,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO;IAIjE;;OAEG;IACH,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAIpD;;OAEG;IACH,cAAc,IAAI,OAAO,EAAE;IAI3B;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,SAAS,IAAI,WAAW;CAGzB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SetGo NestJS Service
|
|
4
|
+
*/
|
|
5
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
6
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
13
|
+
};
|
|
14
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
15
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
16
|
+
};
|
|
17
|
+
var SetGoService_1;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.SetGoService = void 0;
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const index_js_1 = require("../core/index.js");
|
|
22
|
+
const setgo_constants_js_1 = require("./setgo.constants.js");
|
|
23
|
+
let SetGoService = SetGoService_1 = class SetGoService {
|
|
24
|
+
client;
|
|
25
|
+
logger = new common_1.Logger(SetGoService_1.name);
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.client = new index_js_1.SetGoClient(config);
|
|
28
|
+
}
|
|
29
|
+
async onModuleInit() {
|
|
30
|
+
try {
|
|
31
|
+
await this.client.start();
|
|
32
|
+
this.logger.log('SetGo client started successfully');
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
this.logger.error('Failed to start SetGo client', error);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async onModuleDestroy() {
|
|
40
|
+
try {
|
|
41
|
+
await this.client.stop();
|
|
42
|
+
this.logger.log('SetGo client stopped');
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
this.logger.error('Error stopping SetGo client', error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check if a feature is enabled
|
|
50
|
+
*/
|
|
51
|
+
isEnabled(featureName, context) {
|
|
52
|
+
return this.client.isEnabled(featureName, context);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get a feature by name
|
|
56
|
+
*/
|
|
57
|
+
getFeature(featureName) {
|
|
58
|
+
return this.client.getFeature(featureName);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get all features
|
|
62
|
+
*/
|
|
63
|
+
getAllFeatures() {
|
|
64
|
+
return this.client.getAllFeatures();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if the client is ready
|
|
68
|
+
*/
|
|
69
|
+
isReady() {
|
|
70
|
+
return this.client.isReady();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the underlying client (for advanced usage)
|
|
74
|
+
*/
|
|
75
|
+
getClient() {
|
|
76
|
+
return this.client;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.SetGoService = SetGoService;
|
|
80
|
+
exports.SetGoService = SetGoService = SetGoService_1 = __decorate([
|
|
81
|
+
(0, common_1.Injectable)(),
|
|
82
|
+
__param(0, (0, common_1.Inject)(setgo_constants_js_1.SETGO_CONFIG)),
|
|
83
|
+
__metadata("design:paramtypes", [Object])
|
|
84
|
+
], SetGoService);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SetGo SDK Configuration Types
|
|
3
|
+
*/
|
|
4
|
+
export interface SetGoConfig {
|
|
5
|
+
/** Base URL of the SetGo API */
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
/** Client API token */
|
|
8
|
+
token: string;
|
|
9
|
+
/** Application name for identification */
|
|
10
|
+
appName: string;
|
|
11
|
+
/** Environment name (optional, usually set in token) */
|
|
12
|
+
environment?: string;
|
|
13
|
+
/** Unique instance identifier (auto-generated if not provided) */
|
|
14
|
+
instanceId?: string;
|
|
15
|
+
/** Interval in ms between feature fetches (default: 15000) */
|
|
16
|
+
refreshInterval?: number;
|
|
17
|
+
/** Interval in ms between metrics submissions (default: 60000) */
|
|
18
|
+
metricsInterval?: number;
|
|
19
|
+
/** Request timeout in ms (default: 10000) */
|
|
20
|
+
timeout?: number;
|
|
21
|
+
/** Disable metrics collection and submission */
|
|
22
|
+
disableMetrics?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface ResolvedSetGoConfig {
|
|
25
|
+
baseUrl: string;
|
|
26
|
+
token: string;
|
|
27
|
+
appName: string;
|
|
28
|
+
environment?: string;
|
|
29
|
+
instanceId: string;
|
|
30
|
+
refreshInterval: number;
|
|
31
|
+
metricsInterval: number;
|
|
32
|
+
timeout: number;
|
|
33
|
+
disableMetrics: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** NestJS async module options */
|
|
36
|
+
export interface SetGoModuleAsyncOptions {
|
|
37
|
+
imports?: unknown[];
|
|
38
|
+
inject?: unknown[];
|
|
39
|
+
useFactory: (...args: unknown[]) => SetGoConfig | Promise<SetGoConfig>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,WAAW;IAC1B,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,kCAAkC;AAClC,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACxE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SetGo SDK Event Types
|
|
3
|
+
*/
|
|
4
|
+
import type { Feature } from './features.js';
|
|
5
|
+
export type SetGoEventType = 'ready' | 'update' | 'error';
|
|
6
|
+
export interface SetGoReadyEvent {
|
|
7
|
+
type: 'ready';
|
|
8
|
+
features: Feature[];
|
|
9
|
+
}
|
|
10
|
+
export interface SetGoUpdateEvent {
|
|
11
|
+
type: 'update';
|
|
12
|
+
features: Feature[];
|
|
13
|
+
version: number;
|
|
14
|
+
}
|
|
15
|
+
export interface SetGoErrorEvent {
|
|
16
|
+
type: 'error';
|
|
17
|
+
error: Error;
|
|
18
|
+
}
|
|
19
|
+
export type SetGoEvent = SetGoReadyEvent | SetGoUpdateEvent | SetGoErrorEvent;
|
|
20
|
+
export type SetGoEventHandler<T extends SetGoEventType = SetGoEventType> = (data: T extends 'ready' ? SetGoReadyEvent : T extends 'update' ? SetGoUpdateEvent : T extends 'error' ? SetGoErrorEvent : never) => void;
|
|
21
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;CACd;AAED,MAAM,MAAM,UAAU,GAAG,eAAe,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAE9E,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,IAAI,CACzE,IAAI,EAAE,CAAC,SAAS,OAAO,GACnB,eAAe,GACf,CAAC,SAAS,QAAQ,GAChB,gBAAgB,GAChB,CAAC,SAAS,OAAO,GACf,eAAe,GACf,KAAK,KACV,IAAI,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SetGo SDK Feature Types
|
|
3
|
+
*/
|
|
4
|
+
export interface FeatureContext {
|
|
5
|
+
/** User identifier for targeting */
|
|
6
|
+
userId?: string;
|
|
7
|
+
/** Session identifier for targeting */
|
|
8
|
+
sessionId?: string;
|
|
9
|
+
/** Remote IP address for REMOTE_ADDRESS strategy */
|
|
10
|
+
remoteAddress?: string;
|
|
11
|
+
/** Additional properties for flexible rollout */
|
|
12
|
+
properties?: Record<string, string | number | boolean>;
|
|
13
|
+
}
|
|
14
|
+
export type StrategyType = 'DEFAULT' | 'GRADUAL_ROLLOUT' | 'USER_WITH_ID' | 'FLEXIBLE_ROLLOUT' | 'REMOTE_ADDRESS';
|
|
15
|
+
export interface Strategy {
|
|
16
|
+
name: string;
|
|
17
|
+
type: StrategyType;
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
parameters?: Record<string, unknown>;
|
|
20
|
+
constraints?: Record<string, unknown>[];
|
|
21
|
+
sortOrder: number;
|
|
22
|
+
}
|
|
23
|
+
export interface Feature {
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
enabled: boolean;
|
|
27
|
+
description?: string;
|
|
28
|
+
strategies?: Strategy[];
|
|
29
|
+
}
|
|
30
|
+
export interface FeaturesResponse {
|
|
31
|
+
version: number;
|
|
32
|
+
features: Feature[];
|
|
33
|
+
}
|
|
34
|
+
export interface RegisterPayload {
|
|
35
|
+
appName: string;
|
|
36
|
+
instanceId?: string;
|
|
37
|
+
sdkVersion?: string;
|
|
38
|
+
platformInfo?: Record<string, unknown>;
|
|
39
|
+
interval?: number;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=features.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../../src/types/features.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,cAAc;IAC7B,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CACxD;AAED,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,iBAAiB,GACjB,cAAc,GACd,kBAAkB,GAClB,gBAAgB,CAAC;AAErB,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACxC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SetGo SDK Types - Re-exports
|
|
3
|
+
*/
|
|
4
|
+
export type { SetGoConfig, ResolvedSetGoConfig, SetGoModuleAsyncOptions } from './config.js';
|
|
5
|
+
export type { FeatureContext, StrategyType, Strategy, Feature, FeaturesResponse, RegisterPayload, } from './features.js';
|
|
6
|
+
export type { SetGoEventType, SetGoReadyEvent, SetGoUpdateEvent, SetGoErrorEvent, SetGoEvent, SetGoEventHandler, } from './events.js';
|
|
7
|
+
export type { FeatureMetric, MetricsPayload } from './metrics.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE7F,YAAY,EACV,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,gBAAgB,EAChB,eAAe,GAChB,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SetGo SDK Metrics Types
|
|
3
|
+
*/
|
|
4
|
+
export interface FeatureMetric {
|
|
5
|
+
featureName: string;
|
|
6
|
+
yes: number;
|
|
7
|
+
no: number;
|
|
8
|
+
variants?: Record<string, number>;
|
|
9
|
+
}
|
|
10
|
+
export interface MetricsPayload {
|
|
11
|
+
appName: string;
|
|
12
|
+
instanceId?: string;
|
|
13
|
+
bucket: string;
|
|
14
|
+
toggles: FeatureMetric[];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/types/metrics.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.matchIPList = exports.matchIP = exports.normalizedHash = exports.murmurhash3 = void 0;
|
|
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; } });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IP Address Matcher Utility
|
|
3
|
+
* Supports exact IPs, CIDR notation, and wildcards
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Check if an IP address matches a pattern
|
|
7
|
+
* Supports: exact match, CIDR notation, wildcards (*)
|
|
8
|
+
*/
|
|
9
|
+
export declare function matchIP(ip: string, pattern: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Check if an IP matches any pattern in the list
|
|
12
|
+
*/
|
|
13
|
+
export declare function matchIPList(ip: string, patterns: string[]): boolean;
|
|
14
|
+
//# sourceMappingURL=ip-matcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ip-matcher.d.ts","sourceRoot":"","sources":["../../src/utils/ip-matcher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2JH;;;GAGG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CA2B5D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAEnE"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* IP Address Matcher Utility
|
|
4
|
+
* Supports exact IPs, CIDR notation, and wildcards
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.matchIP = matchIP;
|
|
8
|
+
exports.matchIPList = matchIPList;
|
|
9
|
+
function parseIPv4(ip) {
|
|
10
|
+
const parts = ip.split('.');
|
|
11
|
+
if (parts.length !== 4)
|
|
12
|
+
return null;
|
|
13
|
+
const octets = [];
|
|
14
|
+
for (const part of parts) {
|
|
15
|
+
const num = parseInt(part, 10);
|
|
16
|
+
if (isNaN(num) || num < 0 || num > 255)
|
|
17
|
+
return null;
|
|
18
|
+
octets.push(num);
|
|
19
|
+
}
|
|
20
|
+
return { type: 'ipv4', octets };
|
|
21
|
+
}
|
|
22
|
+
function parseIPv6(ip) {
|
|
23
|
+
// Handle IPv4-mapped IPv6 addresses
|
|
24
|
+
if (ip.includes('.')) {
|
|
25
|
+
const lastColon = ip.lastIndexOf(':');
|
|
26
|
+
if (lastColon === -1)
|
|
27
|
+
return null;
|
|
28
|
+
const ipv4Part = ip.slice(lastColon + 1);
|
|
29
|
+
const ipv4 = parseIPv4(ipv4Part);
|
|
30
|
+
if (!ipv4)
|
|
31
|
+
return null;
|
|
32
|
+
const ipv6Part = ip.slice(0, lastColon);
|
|
33
|
+
const parsed = parseIPv6(ipv6Part + ':0:0');
|
|
34
|
+
if (!parsed)
|
|
35
|
+
return null;
|
|
36
|
+
// Replace last two segments with IPv4 octets
|
|
37
|
+
parsed.segments[6] = (ipv4.octets[0] << 8) | ipv4.octets[1];
|
|
38
|
+
parsed.segments[7] = (ipv4.octets[2] << 8) | ipv4.octets[3];
|
|
39
|
+
return parsed;
|
|
40
|
+
}
|
|
41
|
+
let segments = [];
|
|
42
|
+
const parts = ip.split('::');
|
|
43
|
+
if (parts.length > 2)
|
|
44
|
+
return null;
|
|
45
|
+
if (parts.length === 2) {
|
|
46
|
+
const left = parts[0] ? parts[0].split(':').map((s) => parseInt(s, 16)) : [];
|
|
47
|
+
const right = parts[1] ? parts[1].split(':').map((s) => parseInt(s, 16)) : [];
|
|
48
|
+
if (left.some(isNaN) || right.some(isNaN))
|
|
49
|
+
return null;
|
|
50
|
+
const zeros = 8 - left.length - right.length;
|
|
51
|
+
if (zeros < 0)
|
|
52
|
+
return null;
|
|
53
|
+
segments = [...left, ...Array(zeros).fill(0), ...right];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
segments = ip.split(':').map((s) => parseInt(s, 16));
|
|
57
|
+
if (segments.length !== 8 || segments.some(isNaN))
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
if (segments.some((s) => s < 0 || s > 0xffff))
|
|
61
|
+
return null;
|
|
62
|
+
return { type: 'ipv6', segments };
|
|
63
|
+
}
|
|
64
|
+
function parseIP(ip) {
|
|
65
|
+
const trimmed = ip.trim().toLowerCase();
|
|
66
|
+
// Try IPv4 first
|
|
67
|
+
if (trimmed.includes('.') && !trimmed.includes(':')) {
|
|
68
|
+
return parseIPv4(trimmed);
|
|
69
|
+
}
|
|
70
|
+
// Try IPv6
|
|
71
|
+
if (trimmed.includes(':')) {
|
|
72
|
+
return parseIPv6(trimmed);
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
function matchIPv4CIDR(ip, cidr) {
|
|
77
|
+
const [network, prefixStr] = cidr.split('/');
|
|
78
|
+
if (!network || !prefixStr)
|
|
79
|
+
return false;
|
|
80
|
+
const networkIP = parseIPv4(network);
|
|
81
|
+
if (!networkIP)
|
|
82
|
+
return false;
|
|
83
|
+
const prefix = parseInt(prefixStr, 10);
|
|
84
|
+
if (isNaN(prefix) || prefix < 0 || prefix > 32)
|
|
85
|
+
return false;
|
|
86
|
+
const mask = prefix === 0 ? 0 : (~0 << (32 - prefix)) >>> 0;
|
|
87
|
+
const ipNum = ((ip.octets[0] << 24) | (ip.octets[1] << 16) | (ip.octets[2] << 8) | ip.octets[3]) >>> 0;
|
|
88
|
+
const networkNum = ((networkIP.octets[0] << 24) |
|
|
89
|
+
(networkIP.octets[1] << 16) |
|
|
90
|
+
(networkIP.octets[2] << 8) |
|
|
91
|
+
networkIP.octets[3]) >>>
|
|
92
|
+
0;
|
|
93
|
+
return (ipNum & mask) === (networkNum & mask);
|
|
94
|
+
}
|
|
95
|
+
function matchIPv6CIDR(ip, cidr) {
|
|
96
|
+
const [network, prefixStr] = cidr.split('/');
|
|
97
|
+
if (!network || !prefixStr)
|
|
98
|
+
return false;
|
|
99
|
+
const networkIP = parseIPv6(network);
|
|
100
|
+
if (!networkIP)
|
|
101
|
+
return false;
|
|
102
|
+
const prefix = parseInt(prefixStr, 10);
|
|
103
|
+
if (isNaN(prefix) || prefix < 0 || prefix > 128)
|
|
104
|
+
return false;
|
|
105
|
+
let bitsToCheck = prefix;
|
|
106
|
+
for (let i = 0; i < 8 && bitsToCheck > 0; i++) {
|
|
107
|
+
const segmentBits = Math.min(16, bitsToCheck);
|
|
108
|
+
const mask = segmentBits === 16 ? 0xffff : (0xffff << (16 - segmentBits)) & 0xffff;
|
|
109
|
+
if ((ip.segments[i] & mask) !== (networkIP.segments[i] & mask)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
bitsToCheck -= 16;
|
|
113
|
+
}
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
function matchExact(ip, pattern) {
|
|
117
|
+
if (!ip)
|
|
118
|
+
return false;
|
|
119
|
+
const patternIP = parseIP(pattern);
|
|
120
|
+
if (!patternIP || ip.type !== patternIP.type)
|
|
121
|
+
return false;
|
|
122
|
+
if (ip.type === 'ipv4' && patternIP.type === 'ipv4') {
|
|
123
|
+
return ip.octets.every((o, i) => o === patternIP.octets[i]);
|
|
124
|
+
}
|
|
125
|
+
if (ip.type === 'ipv6' && patternIP.type === 'ipv6') {
|
|
126
|
+
return ip.segments.every((s, i) => s === patternIP.segments[i]);
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check if an IP address matches a pattern
|
|
132
|
+
* Supports: exact match, CIDR notation, wildcards (*)
|
|
133
|
+
*/
|
|
134
|
+
function matchIP(ip, pattern) {
|
|
135
|
+
const parsedIP = parseIP(ip);
|
|
136
|
+
if (!parsedIP)
|
|
137
|
+
return false;
|
|
138
|
+
const trimmedPattern = pattern.trim();
|
|
139
|
+
// CIDR notation
|
|
140
|
+
if (trimmedPattern.includes('/')) {
|
|
141
|
+
if (parsedIP.type === 'ipv4') {
|
|
142
|
+
return matchIPv4CIDR(parsedIP, trimmedPattern);
|
|
143
|
+
}
|
|
144
|
+
return matchIPv6CIDR(parsedIP, trimmedPattern);
|
|
145
|
+
}
|
|
146
|
+
// Wildcard pattern (e.g., 192.168.*.*)
|
|
147
|
+
if (trimmedPattern.includes('*')) {
|
|
148
|
+
const patternParts = trimmedPattern.split('.');
|
|
149
|
+
if (parsedIP.type !== 'ipv4' || patternParts.length !== 4)
|
|
150
|
+
return false;
|
|
151
|
+
return patternParts.every((part, i) => {
|
|
152
|
+
if (part === '*')
|
|
153
|
+
return true;
|
|
154
|
+
return parseInt(part, 10) === parsedIP.octets[i];
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
// Exact match
|
|
158
|
+
return matchExact(parsedIP, trimmedPattern);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Check if an IP matches any pattern in the list
|
|
162
|
+
*/
|
|
163
|
+
function matchIPList(ip, patterns) {
|
|
164
|
+
return patterns.some((pattern) => matchIP(ip, pattern));
|
|
165
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MurmurHash3 implementation for consistent hashing
|
|
3
|
+
* Used for gradual rollout percentages
|
|
4
|
+
*/
|
|
5
|
+
export declare function murmurhash3(key: string, seed?: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Normalize hash to a percentage (0-100)
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizedHash(groupId: string, identifier: string, normalizer?: number): number;
|
|
10
|
+
//# sourceMappingURL=murmurhash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"murmurhash.d.ts","sourceRoot":"","sources":["../../src/utils/murmurhash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,MAAU,GAAG,MAAM,CAmDjE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,UAAU,GAAE,MAAY,GACvB,MAAM,CAIR"}
|