@rolloutctrl/js-sdk 0.0.1 → 0.0.2
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/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +10 -8
- package/dist/index.mjs +10 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -24,6 +24,7 @@ interface StorageAdapter {
|
|
|
24
24
|
}
|
|
25
25
|
interface RolloutCtrlOptions {
|
|
26
26
|
sdkKey: string;
|
|
27
|
+
environment: string;
|
|
27
28
|
apiUrl?: string;
|
|
28
29
|
refreshInterval?: number;
|
|
29
30
|
requestTimeout?: number;
|
|
@@ -82,11 +83,12 @@ interface ConfigurationRepository {
|
|
|
82
83
|
declare class HttpConfigurationRepository implements ConfigurationRepository {
|
|
83
84
|
private readonly apiUrl;
|
|
84
85
|
private readonly sdkKey;
|
|
86
|
+
private readonly environment;
|
|
85
87
|
private readonly requestTimeout;
|
|
86
88
|
private configuration;
|
|
87
89
|
private version;
|
|
88
90
|
private readonly listeners;
|
|
89
|
-
constructor(apiUrl: string, sdkKey: string, requestTimeout: number);
|
|
91
|
+
constructor(apiUrl: string, sdkKey: string, environment: string, requestTimeout: number);
|
|
90
92
|
initialize(): Promise<void>;
|
|
91
93
|
initializeWith(configuration: Configuration): void;
|
|
92
94
|
refresh(): Promise<boolean>;
|
|
@@ -95,7 +97,7 @@ declare class HttpConfigurationRepository implements ConfigurationRepository {
|
|
|
95
97
|
subscribe(listener: (configuration: Configuration) => void): () => void;
|
|
96
98
|
private notify;
|
|
97
99
|
private fetchBootstrap;
|
|
98
|
-
private
|
|
100
|
+
private fetchChanges;
|
|
99
101
|
private request;
|
|
100
102
|
}
|
|
101
103
|
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ interface StorageAdapter {
|
|
|
24
24
|
}
|
|
25
25
|
interface RolloutCtrlOptions {
|
|
26
26
|
sdkKey: string;
|
|
27
|
+
environment: string;
|
|
27
28
|
apiUrl?: string;
|
|
28
29
|
refreshInterval?: number;
|
|
29
30
|
requestTimeout?: number;
|
|
@@ -82,11 +83,12 @@ interface ConfigurationRepository {
|
|
|
82
83
|
declare class HttpConfigurationRepository implements ConfigurationRepository {
|
|
83
84
|
private readonly apiUrl;
|
|
84
85
|
private readonly sdkKey;
|
|
86
|
+
private readonly environment;
|
|
85
87
|
private readonly requestTimeout;
|
|
86
88
|
private configuration;
|
|
87
89
|
private version;
|
|
88
90
|
private readonly listeners;
|
|
89
|
-
constructor(apiUrl: string, sdkKey: string, requestTimeout: number);
|
|
91
|
+
constructor(apiUrl: string, sdkKey: string, environment: string, requestTimeout: number);
|
|
90
92
|
initialize(): Promise<void>;
|
|
91
93
|
initializeWith(configuration: Configuration): void;
|
|
92
94
|
refresh(): Promise<boolean>;
|
|
@@ -95,7 +97,7 @@ declare class HttpConfigurationRepository implements ConfigurationRepository {
|
|
|
95
97
|
subscribe(listener: (configuration: Configuration) => void): () => void;
|
|
96
98
|
private notify;
|
|
97
99
|
private fetchBootstrap;
|
|
98
|
-
private
|
|
100
|
+
private fetchChanges;
|
|
99
101
|
private request;
|
|
100
102
|
}
|
|
101
103
|
|
package/dist/index.js
CHANGED
|
@@ -111,9 +111,10 @@ var EvaluatorManager = class {
|
|
|
111
111
|
|
|
112
112
|
// src/repository.ts
|
|
113
113
|
var HttpConfigurationRepository = class {
|
|
114
|
-
constructor(apiUrl, sdkKey, requestTimeout) {
|
|
114
|
+
constructor(apiUrl, sdkKey, environment, requestTimeout) {
|
|
115
115
|
this.apiUrl = apiUrl;
|
|
116
116
|
this.sdkKey = sdkKey;
|
|
117
|
+
this.environment = environment;
|
|
117
118
|
this.requestTimeout = requestTimeout;
|
|
118
119
|
this.configuration = null;
|
|
119
120
|
this.version = 0;
|
|
@@ -132,8 +133,8 @@ var HttpConfigurationRepository = class {
|
|
|
132
133
|
}
|
|
133
134
|
async refresh() {
|
|
134
135
|
try {
|
|
135
|
-
const
|
|
136
|
-
if (
|
|
136
|
+
const changesResponse = await this.fetchChanges();
|
|
137
|
+
if (!changesResponse.hasChanges) {
|
|
137
138
|
return false;
|
|
138
139
|
}
|
|
139
140
|
const config = await this.fetchBootstrap();
|
|
@@ -166,10 +167,11 @@ var HttpConfigurationRepository = class {
|
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
async fetchBootstrap() {
|
|
169
|
-
return this.request(`${this.apiUrl}/sdk/
|
|
170
|
+
return this.request(`${this.apiUrl}/sdk/config?environment=${encodeURIComponent(this.environment)}`);
|
|
170
171
|
}
|
|
171
|
-
async
|
|
172
|
-
|
|
172
|
+
async fetchChanges() {
|
|
173
|
+
const url = `${this.apiUrl}/config/changes?environment=${encodeURIComponent(this.environment)}&since=${this.version}`;
|
|
174
|
+
return this.request(url);
|
|
173
175
|
}
|
|
174
176
|
async request(url) {
|
|
175
177
|
const controller = new AbortController();
|
|
@@ -177,7 +179,7 @@ var HttpConfigurationRepository = class {
|
|
|
177
179
|
try {
|
|
178
180
|
const response = await fetch(url, {
|
|
179
181
|
headers: {
|
|
180
|
-
|
|
182
|
+
"x-api-key": this.sdkKey,
|
|
181
183
|
"Content-Type": "application/json"
|
|
182
184
|
},
|
|
183
185
|
signal: controller.signal
|
|
@@ -249,7 +251,7 @@ var RolloutCtrlClient = class {
|
|
|
249
251
|
const apiUrl = options.apiUrl ?? DEFAULT_API_URL;
|
|
250
252
|
const refreshInterval = options.refreshInterval ?? DEFAULT_REFRESH_INTERVAL;
|
|
251
253
|
const requestTimeout = options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT;
|
|
252
|
-
this.repository = new HttpConfigurationRepository(apiUrl, options.sdkKey, requestTimeout);
|
|
254
|
+
this.repository = new HttpConfigurationRepository(apiUrl, options.sdkKey, options.environment, requestTimeout);
|
|
253
255
|
this.evaluatorManager = new EvaluatorManager();
|
|
254
256
|
this.updateProvider = new PollingUpdateProvider(refreshInterval);
|
|
255
257
|
this.repository.subscribe((configuration) => {
|
package/dist/index.mjs
CHANGED
|
@@ -83,9 +83,10 @@ var EvaluatorManager = class {
|
|
|
83
83
|
|
|
84
84
|
// src/repository.ts
|
|
85
85
|
var HttpConfigurationRepository = class {
|
|
86
|
-
constructor(apiUrl, sdkKey, requestTimeout) {
|
|
86
|
+
constructor(apiUrl, sdkKey, environment, requestTimeout) {
|
|
87
87
|
this.apiUrl = apiUrl;
|
|
88
88
|
this.sdkKey = sdkKey;
|
|
89
|
+
this.environment = environment;
|
|
89
90
|
this.requestTimeout = requestTimeout;
|
|
90
91
|
this.configuration = null;
|
|
91
92
|
this.version = 0;
|
|
@@ -104,8 +105,8 @@ var HttpConfigurationRepository = class {
|
|
|
104
105
|
}
|
|
105
106
|
async refresh() {
|
|
106
107
|
try {
|
|
107
|
-
const
|
|
108
|
-
if (
|
|
108
|
+
const changesResponse = await this.fetchChanges();
|
|
109
|
+
if (!changesResponse.hasChanges) {
|
|
109
110
|
return false;
|
|
110
111
|
}
|
|
111
112
|
const config = await this.fetchBootstrap();
|
|
@@ -138,10 +139,11 @@ var HttpConfigurationRepository = class {
|
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
async fetchBootstrap() {
|
|
141
|
-
return this.request(`${this.apiUrl}/sdk/
|
|
142
|
+
return this.request(`${this.apiUrl}/sdk/config?environment=${encodeURIComponent(this.environment)}`);
|
|
142
143
|
}
|
|
143
|
-
async
|
|
144
|
-
|
|
144
|
+
async fetchChanges() {
|
|
145
|
+
const url = `${this.apiUrl}/config/changes?environment=${encodeURIComponent(this.environment)}&since=${this.version}`;
|
|
146
|
+
return this.request(url);
|
|
145
147
|
}
|
|
146
148
|
async request(url) {
|
|
147
149
|
const controller = new AbortController();
|
|
@@ -149,7 +151,7 @@ var HttpConfigurationRepository = class {
|
|
|
149
151
|
try {
|
|
150
152
|
const response = await fetch(url, {
|
|
151
153
|
headers: {
|
|
152
|
-
|
|
154
|
+
"x-api-key": this.sdkKey,
|
|
153
155
|
"Content-Type": "application/json"
|
|
154
156
|
},
|
|
155
157
|
signal: controller.signal
|
|
@@ -221,7 +223,7 @@ var RolloutCtrlClient = class {
|
|
|
221
223
|
const apiUrl = options.apiUrl ?? DEFAULT_API_URL;
|
|
222
224
|
const refreshInterval = options.refreshInterval ?? DEFAULT_REFRESH_INTERVAL;
|
|
223
225
|
const requestTimeout = options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT;
|
|
224
|
-
this.repository = new HttpConfigurationRepository(apiUrl, options.sdkKey, requestTimeout);
|
|
226
|
+
this.repository = new HttpConfigurationRepository(apiUrl, options.sdkKey, options.environment, requestTimeout);
|
|
225
227
|
this.evaluatorManager = new EvaluatorManager();
|
|
226
228
|
this.updateProvider = new PollingUpdateProvider(refreshInterval);
|
|
227
229
|
this.repository.subscribe((configuration) => {
|