flagsmith-nodejs 2.2.2-beta.2 → 2.3.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.
- package/build/index.js +10 -8
- package/build/sdk/index.d.ts +5 -17
- package/build/sdk/index.js +2 -0
- package/build/sdk/types.d.ts +19 -1
- package/build/sdk/utils.d.ts +2 -2
- package/{es6-example → examples/api-proxy}/.babelrc +0 -0
- package/{es6-example → examples/api-proxy}/.eslintrc +0 -0
- package/examples/api-proxy/.idea/api-proxy.iml +12 -0
- package/examples/api-proxy/.idea/codeStyles/Project.xml +60 -0
- package/examples/api-proxy/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/examples/api-proxy/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/examples/api-proxy/.idea/modules.xml +8 -0
- package/examples/api-proxy/.idea/vcs.xml +6 -0
- package/examples/api-proxy/README.md +12 -0
- package/examples/api-proxy/package-lock.json +10895 -0
- package/examples/api-proxy/package.json +57 -0
- package/examples/api-proxy/src/api/index.js +42 -0
- package/{es6-example → examples/api-proxy}/src/index.js +0 -0
- package/examples/basic/.babelrc +3 -0
- package/examples/basic/.eslintrc +8 -0
- package/examples/basic/README.md +10 -0
- package/{es6-example → examples/basic}/package-lock.json +235 -38
- package/{es6-example → examples/basic}/package.json +1 -0
- package/examples/basic/src/api/index.js +33 -0
- package/{example/server → examples/basic/src}/index.js +4 -4
- package/examples/caching/.babelrc +3 -0
- package/examples/caching/.eslintrc +8 -0
- package/examples/caching/README.md +9 -0
- package/examples/caching/package-lock.json +10782 -0
- package/examples/caching/package.json +56 -0
- package/{example/server → examples/caching/src}/api/index.js +7 -11
- package/examples/caching/src/index.js +29 -0
- package/examples/custom-fetch-agent/.babelrc +3 -0
- package/examples/custom-fetch-agent/.eslintrc +8 -0
- package/examples/custom-fetch-agent/README.md +12 -0
- package/examples/custom-fetch-agent/package-lock.json +10782 -0
- package/examples/custom-fetch-agent/package.json +56 -0
- package/examples/custom-fetch-agent/src/api/index.js +34 -0
- package/examples/custom-fetch-agent/src/index.js +29 -0
- package/examples/local-evaluation/.babelrc +3 -0
- package/examples/local-evaluation/.eslintrc +8 -0
- package/examples/local-evaluation/README.md +18 -0
- package/examples/local-evaluation/package-lock.json +10782 -0
- package/examples/local-evaluation/package.json +56 -0
- package/{es6-example → examples/local-evaluation}/src/api/index.js +2 -13
- package/examples/local-evaluation/src/index.js +29 -0
- package/index.ts +4 -0
- package/package.json +1 -1
- package/sdk/index.ts +8 -15
- package/sdk/types.ts +19 -2
- package/sdk/utils.ts +2 -2
- package/tests/sdk/flagsmith.test.ts +25 -10
- package/es6-example/README.md +0 -62
- package/example/LICENSE +0 -0
- package/example/Procfile +0 -1
- package/example/README.md +0 -15
- package/example/package-lock.json +0 -2387
- package/example/package.json +0 -27
package/build/index.js
CHANGED
|
@@ -4,14 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.OrganisationModel = exports.SegmentModel = exports.TraitModel = exports.IdentityModel = exports.FeatureStateModel = exports.IntegrationModel = exports.EnvironmentModel = exports.default = exports.Flags = exports.DefaultFlag = exports.EnvironmentDataPollingManager = exports.FlagsmithClientError = exports.FlagsmithAPIError = exports.AnalyticsProcessor = void 0;
|
|
7
|
-
var sdk_1 = require("./sdk");
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "
|
|
10
|
-
Object.defineProperty(exports, "
|
|
11
|
-
Object.defineProperty(exports, "
|
|
12
|
-
Object.defineProperty(exports, "
|
|
13
|
-
Object.defineProperty(exports, "
|
|
14
|
-
Object.defineProperty(exports, "
|
|
7
|
+
var sdk_1 = __importDefault(require("./sdk"));
|
|
8
|
+
var sdk_2 = require("./sdk");
|
|
9
|
+
Object.defineProperty(exports, "AnalyticsProcessor", { enumerable: true, get: function () { return sdk_2.AnalyticsProcessor; } });
|
|
10
|
+
Object.defineProperty(exports, "FlagsmithAPIError", { enumerable: true, get: function () { return sdk_2.FlagsmithAPIError; } });
|
|
11
|
+
Object.defineProperty(exports, "FlagsmithClientError", { enumerable: true, get: function () { return sdk_2.FlagsmithClientError; } });
|
|
12
|
+
Object.defineProperty(exports, "EnvironmentDataPollingManager", { enumerable: true, get: function () { return sdk_2.EnvironmentDataPollingManager; } });
|
|
13
|
+
Object.defineProperty(exports, "DefaultFlag", { enumerable: true, get: function () { return sdk_2.DefaultFlag; } });
|
|
14
|
+
Object.defineProperty(exports, "Flags", { enumerable: true, get: function () { return sdk_2.Flags; } });
|
|
15
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(sdk_2).default; } });
|
|
15
16
|
var flagsmith_engine_1 = require("./flagsmith-engine");
|
|
16
17
|
Object.defineProperty(exports, "EnvironmentModel", { enumerable: true, get: function () { return flagsmith_engine_1.EnvironmentModel; } });
|
|
17
18
|
Object.defineProperty(exports, "IntegrationModel", { enumerable: true, get: function () { return flagsmith_engine_1.IntegrationModel; } });
|
|
@@ -20,3 +21,4 @@ Object.defineProperty(exports, "IdentityModel", { enumerable: true, get: functio
|
|
|
20
21
|
Object.defineProperty(exports, "TraitModel", { enumerable: true, get: function () { return flagsmith_engine_1.TraitModel; } });
|
|
21
22
|
Object.defineProperty(exports, "SegmentModel", { enumerable: true, get: function () { return flagsmith_engine_1.SegmentModel; } });
|
|
22
23
|
Object.defineProperty(exports, "OrganisationModel", { enumerable: true, get: function () { return flagsmith_engine_1.OrganisationModel; } });
|
|
24
|
+
module.exports = sdk_1.default;
|
package/build/sdk/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { RequestInit } from "node-fetch";
|
|
1
2
|
import { EnvironmentModel } from '../flagsmith-engine/environments/models';
|
|
2
3
|
import { DefaultFlag, Flags } from './models';
|
|
3
4
|
import { EnvironmentDataPollingManager } from './polling_manager';
|
|
4
5
|
import { SegmentModel } from '../flagsmith-engine/segments/models';
|
|
5
|
-
import {
|
|
6
|
+
import { FlagsmithConfig } from './types';
|
|
6
7
|
export { AnalyticsProcessor } from './analytics';
|
|
7
8
|
export { FlagsmithAPIError, FlagsmithClientError } from './errors';
|
|
8
9
|
export { DefaultFlag, Flags } from './models';
|
|
9
10
|
export { EnvironmentDataPollingManager } from './polling_manager';
|
|
10
|
-
export { FlagsmithCache } from './types';
|
|
11
|
+
export { FlagsmithCache, FlagsmithConfig } from './types';
|
|
11
12
|
export declare class Flagsmith {
|
|
12
13
|
environmentKey?: string;
|
|
13
14
|
apiUrl: string;
|
|
@@ -15,6 +16,7 @@ export declare class Flagsmith {
|
|
|
15
16
|
[key: string]: any;
|
|
16
17
|
};
|
|
17
18
|
requestTimeoutSeconds?: number;
|
|
19
|
+
agent: RequestInit['agent'];
|
|
18
20
|
requestTimeoutMs?: number;
|
|
19
21
|
enableLocalEvaluation?: boolean;
|
|
20
22
|
environmentRefreshIntervalSeconds: number;
|
|
@@ -59,21 +61,7 @@ export declare class Flagsmith {
|
|
|
59
61
|
flags cannot be retrieved from the API or a non existent feature is
|
|
60
62
|
requested
|
|
61
63
|
*/
|
|
62
|
-
constructor(data:
|
|
63
|
-
environmentKey: string;
|
|
64
|
-
apiUrl?: string;
|
|
65
|
-
customHeaders?: {
|
|
66
|
-
[key: string]: any;
|
|
67
|
-
};
|
|
68
|
-
requestTimeoutSeconds?: number;
|
|
69
|
-
enableLocalEvaluation?: boolean;
|
|
70
|
-
environmentRefreshIntervalSeconds?: number;
|
|
71
|
-
retries?: number;
|
|
72
|
-
enableAnalytics?: boolean;
|
|
73
|
-
defaultFlagHandler?: (featureName: string) => DefaultFlag;
|
|
74
|
-
cache?: FlagsmithCache;
|
|
75
|
-
onEnvironmentChange?: (error: Error | null, result: EnvironmentModel) => void;
|
|
76
|
-
});
|
|
64
|
+
constructor(data: FlagsmithConfig);
|
|
77
65
|
/**
|
|
78
66
|
* Get all the default for flags for the current environment.
|
|
79
67
|
*
|
package/build/sdk/index.js
CHANGED
|
@@ -121,6 +121,7 @@ var Flagsmith = /** @class */ (function () {
|
|
|
121
121
|
this.enableLocalEvaluation = false;
|
|
122
122
|
this.environmentRefreshIntervalSeconds = 60;
|
|
123
123
|
this.enableAnalytics = false;
|
|
124
|
+
this.agent = data.agent;
|
|
124
125
|
this.environmentKey = data.environmentKey;
|
|
125
126
|
this.apiUrl = data.apiUrl || this.apiUrl;
|
|
126
127
|
this.customHeaders = data.customHeaders;
|
|
@@ -348,6 +349,7 @@ var Flagsmith = /** @class */ (function () {
|
|
|
348
349
|
}
|
|
349
350
|
}
|
|
350
351
|
return [4 /*yield*/, (0, utils_1.retryFetch)(url, {
|
|
352
|
+
agent: this.agent,
|
|
351
353
|
method: method,
|
|
352
354
|
timeout: this.requestTimeoutMs || undefined,
|
|
353
355
|
body: JSON.stringify(body),
|
package/build/sdk/types.d.ts
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import { Flags } from "./models";
|
|
1
|
+
import { DefaultFlag, Flags } from "./models";
|
|
2
|
+
import { EnvironmentModel } from "../flagsmith-engine";
|
|
3
|
+
import { RequestInit } from "node-fetch";
|
|
2
4
|
export interface FlagsmithCache {
|
|
3
5
|
get(key: string): Promise<Flags | undefined> | undefined;
|
|
4
6
|
set(key: string, value: Flags, ttl: string | number): boolean | Promise<boolean>;
|
|
5
7
|
has(key: string): boolean | Promise<boolean>;
|
|
6
8
|
[key: string]: any;
|
|
7
9
|
}
|
|
10
|
+
export interface FlagsmithConfig {
|
|
11
|
+
environmentKey: string;
|
|
12
|
+
apiUrl?: string;
|
|
13
|
+
agent?: RequestInit['agent'];
|
|
14
|
+
customHeaders?: {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
requestTimeoutSeconds?: number;
|
|
18
|
+
enableLocalEvaluation?: boolean;
|
|
19
|
+
environmentRefreshIntervalSeconds?: number;
|
|
20
|
+
retries?: number;
|
|
21
|
+
enableAnalytics?: boolean;
|
|
22
|
+
defaultFlagHandler?: (featureName: string) => DefaultFlag;
|
|
23
|
+
cache?: FlagsmithCache;
|
|
24
|
+
onEnvironmentChange?: (error: Error | null, result: EnvironmentModel) => void;
|
|
25
|
+
}
|
package/build/sdk/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Response } from 'node-fetch';
|
|
1
|
+
import { RequestInit, Response } from 'node-fetch';
|
|
2
2
|
export declare function generateIdentitiesData(identifier: string, traits: {
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
}): {
|
|
@@ -9,4 +9,4 @@ export declare function generateIdentitiesData(identifier: string, traits: {
|
|
|
9
9
|
}[];
|
|
10
10
|
};
|
|
11
11
|
export declare const delay: (ms: number) => Promise<unknown>;
|
|
12
|
-
export declare const retryFetch: (url: string, fetchOptions:
|
|
12
|
+
export declare const retryFetch: (url: string, fetchOptions: RequestInit, retries?: number, timeout?: number | undefined) => Promise<Response>;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
7
|
+
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
+
</content>
|
|
9
|
+
<orderEntry type="inheritedJdk" />
|
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
+
</component>
|
|
12
|
+
</module>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
+
<code_scheme name="Project" version="173">
|
|
3
|
+
<HTMLCodeStyleSettings>
|
|
4
|
+
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
|
5
|
+
<option name="HTML_KEEP_WHITESPACES_INSIDE" value="pre,textarea" />
|
|
6
|
+
<option name="HTML_ENFORCE_QUOTES" value="true" />
|
|
7
|
+
<option name="HTML_NEWLINE_AFTER_LAST_ATTRIBUTE" value="When multiline" />
|
|
8
|
+
</HTMLCodeStyleSettings>
|
|
9
|
+
<JSCodeStyleSettings version="0">
|
|
10
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
11
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
12
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
13
|
+
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
14
|
+
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
15
|
+
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
16
|
+
</JSCodeStyleSettings>
|
|
17
|
+
<TypeScriptCodeStyleSettings version="0">
|
|
18
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
19
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
20
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
21
|
+
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
22
|
+
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
23
|
+
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
24
|
+
</TypeScriptCodeStyleSettings>
|
|
25
|
+
<VueCodeStyleSettings>
|
|
26
|
+
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
|
|
27
|
+
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
|
28
|
+
</VueCodeStyleSettings>
|
|
29
|
+
<codeStyleSettings language="HTML">
|
|
30
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
31
|
+
<indentOptions>
|
|
32
|
+
<option name="INDENT_SIZE" value="2" />
|
|
33
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
34
|
+
<option name="TAB_SIZE" value="2" />
|
|
35
|
+
</indentOptions>
|
|
36
|
+
</codeStyleSettings>
|
|
37
|
+
<codeStyleSettings language="JavaScript">
|
|
38
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
39
|
+
<indentOptions>
|
|
40
|
+
<option name="INDENT_SIZE" value="2" />
|
|
41
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
42
|
+
<option name="TAB_SIZE" value="2" />
|
|
43
|
+
</indentOptions>
|
|
44
|
+
</codeStyleSettings>
|
|
45
|
+
<codeStyleSettings language="TypeScript">
|
|
46
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
47
|
+
<indentOptions>
|
|
48
|
+
<option name="INDENT_SIZE" value="2" />
|
|
49
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
50
|
+
<option name="TAB_SIZE" value="2" />
|
|
51
|
+
</indentOptions>
|
|
52
|
+
</codeStyleSettings>
|
|
53
|
+
<codeStyleSettings language="Vue">
|
|
54
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
55
|
+
<indentOptions>
|
|
56
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
57
|
+
</indentOptions>
|
|
58
|
+
</codeStyleSettings>
|
|
59
|
+
</code_scheme>
|
|
60
|
+
</component>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/api-proxy.iml" filepath="$PROJECT_DIR$/.idea/api-proxy.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<img width="100%" src="https://github.com/Flagsmith/flagsmith/raw/main/static-files/hero.png"/>
|
|
2
|
+
|
|
3
|
+
# Flagsmith Node.js example with custom fetch agent
|
|
4
|
+
|
|
5
|
+
This is a simple Flagsmith Node.js example in local evaluation modes with a custom fetch agent. Using a custom fetch agent lets allows you to specify networking related options such as keep alive and socket timeout, read more on this [here](https://github.com/node-fetch/node-fetch#custom-agent).
|
|
6
|
+
|
|
7
|
+
## Running the example
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
npm i
|
|
11
|
+
npm run dev
|
|
12
|
+
```
|