@rolloutctrl/js-sdk 0.0.1 → 0.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/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +22 -8
- package/dist/index.mjs +22 -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,8 @@ 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 normalizeConfiguration;
|
|
101
|
+
private fetchChanges;
|
|
99
102
|
private request;
|
|
100
103
|
}
|
|
101
104
|
|
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,8 @@ 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 normalizeConfiguration;
|
|
101
|
+
private fetchChanges;
|
|
99
102
|
private request;
|
|
100
103
|
}
|
|
101
104
|
|
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,23 @@ var HttpConfigurationRepository = class {
|
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
async fetchBootstrap() {
|
|
169
|
-
|
|
170
|
+
const raw = await this.request(`${this.apiUrl}/sdk/config?environment=${encodeURIComponent(this.environment)}`);
|
|
171
|
+
return this.normalizeConfiguration(raw);
|
|
172
|
+
}
|
|
173
|
+
normalizeConfiguration(raw) {
|
|
174
|
+
const flags = Array.isArray(raw.flags) ? raw.flags : Object.entries(raw.flags ?? {}).map(([key, value]) => ({ key, ...value }));
|
|
175
|
+
const actions = Array.isArray(raw.actions) ? raw.actions : Object.values(raw.actions ?? {});
|
|
176
|
+
return {
|
|
177
|
+
projectId: raw.project?.id ?? raw.projectId ?? "",
|
|
178
|
+
environmentId: raw.environmentId ?? "",
|
|
179
|
+
version: raw.version,
|
|
180
|
+
flags,
|
|
181
|
+
actions
|
|
182
|
+
};
|
|
170
183
|
}
|
|
171
|
-
async
|
|
172
|
-
|
|
184
|
+
async fetchChanges() {
|
|
185
|
+
const url = `${this.apiUrl}/config/changes?environment=${encodeURIComponent(this.environment)}&since=${this.version}`;
|
|
186
|
+
return this.request(url);
|
|
173
187
|
}
|
|
174
188
|
async request(url) {
|
|
175
189
|
const controller = new AbortController();
|
|
@@ -177,7 +191,7 @@ var HttpConfigurationRepository = class {
|
|
|
177
191
|
try {
|
|
178
192
|
const response = await fetch(url, {
|
|
179
193
|
headers: {
|
|
180
|
-
|
|
194
|
+
"x-api-key": this.sdkKey,
|
|
181
195
|
"Content-Type": "application/json"
|
|
182
196
|
},
|
|
183
197
|
signal: controller.signal
|
|
@@ -249,7 +263,7 @@ var RolloutCtrlClient = class {
|
|
|
249
263
|
const apiUrl = options.apiUrl ?? DEFAULT_API_URL;
|
|
250
264
|
const refreshInterval = options.refreshInterval ?? DEFAULT_REFRESH_INTERVAL;
|
|
251
265
|
const requestTimeout = options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT;
|
|
252
|
-
this.repository = new HttpConfigurationRepository(apiUrl, options.sdkKey, requestTimeout);
|
|
266
|
+
this.repository = new HttpConfigurationRepository(apiUrl, options.sdkKey, options.environment, requestTimeout);
|
|
253
267
|
this.evaluatorManager = new EvaluatorManager();
|
|
254
268
|
this.updateProvider = new PollingUpdateProvider(refreshInterval);
|
|
255
269
|
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,23 @@ var HttpConfigurationRepository = class {
|
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
async fetchBootstrap() {
|
|
141
|
-
|
|
142
|
+
const raw = await this.request(`${this.apiUrl}/sdk/config?environment=${encodeURIComponent(this.environment)}`);
|
|
143
|
+
return this.normalizeConfiguration(raw);
|
|
144
|
+
}
|
|
145
|
+
normalizeConfiguration(raw) {
|
|
146
|
+
const flags = Array.isArray(raw.flags) ? raw.flags : Object.entries(raw.flags ?? {}).map(([key, value]) => ({ key, ...value }));
|
|
147
|
+
const actions = Array.isArray(raw.actions) ? raw.actions : Object.values(raw.actions ?? {});
|
|
148
|
+
return {
|
|
149
|
+
projectId: raw.project?.id ?? raw.projectId ?? "",
|
|
150
|
+
environmentId: raw.environmentId ?? "",
|
|
151
|
+
version: raw.version,
|
|
152
|
+
flags,
|
|
153
|
+
actions
|
|
154
|
+
};
|
|
142
155
|
}
|
|
143
|
-
async
|
|
144
|
-
|
|
156
|
+
async fetchChanges() {
|
|
157
|
+
const url = `${this.apiUrl}/config/changes?environment=${encodeURIComponent(this.environment)}&since=${this.version}`;
|
|
158
|
+
return this.request(url);
|
|
145
159
|
}
|
|
146
160
|
async request(url) {
|
|
147
161
|
const controller = new AbortController();
|
|
@@ -149,7 +163,7 @@ var HttpConfigurationRepository = class {
|
|
|
149
163
|
try {
|
|
150
164
|
const response = await fetch(url, {
|
|
151
165
|
headers: {
|
|
152
|
-
|
|
166
|
+
"x-api-key": this.sdkKey,
|
|
153
167
|
"Content-Type": "application/json"
|
|
154
168
|
},
|
|
155
169
|
signal: controller.signal
|
|
@@ -221,7 +235,7 @@ var RolloutCtrlClient = class {
|
|
|
221
235
|
const apiUrl = options.apiUrl ?? DEFAULT_API_URL;
|
|
222
236
|
const refreshInterval = options.refreshInterval ?? DEFAULT_REFRESH_INTERVAL;
|
|
223
237
|
const requestTimeout = options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT;
|
|
224
|
-
this.repository = new HttpConfigurationRepository(apiUrl, options.sdkKey, requestTimeout);
|
|
238
|
+
this.repository = new HttpConfigurationRepository(apiUrl, options.sdkKey, options.environment, requestTimeout);
|
|
225
239
|
this.evaluatorManager = new EvaluatorManager();
|
|
226
240
|
this.updateProvider = new PollingUpdateProvider(refreshInterval);
|
|
227
241
|
this.repository.subscribe((configuration) => {
|