Skip to content

Commit 1e0f864

Browse files
committed
chore: clean up types and old decide type signature
1 parent fa52982 commit 1e0f864

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed
Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { LogEvent } from '@optimizely/optimizely-sdk';
1+
import type { LogEvent } from '@optimizely/optimizely-sdk';
22

33
/**
44
* Web standards friendly event dispatcher for Optimizely
5-
* uses `after` to avoid blocking the visitor's page load
5+
* uses `waitUntil()` to avoid blocking the visitor's page load
6+
*
7+
* This does not send back the status code to the dispatcher as it runs in `waitUntil()`
68
*/
79
export async function dispatchEvent(event: LogEvent) {
810
// Non-POST requests not supported
@@ -21,21 +23,9 @@ export async function dispatchEvent(event: LogEvent) {
2123
headers: {
2224
'Content-Type': 'application/json',
2325
},
24-
})
25-
.then((response) => {
26-
if (response.ok) {
27-
return { statusCode: response.status };
28-
}
29-
})
30-
.catch((error) => {
31-
console.error('Error dispatching event:', error);
32-
});
26+
});
3327

34-
try {
35-
import('@vercel/functions').then(({ waitUntil }) => {
36-
waitUntil(dispatch);
37-
});
38-
} catch (error) {
39-
console.error('Error dispatching event:', error);
40-
}
28+
import('@vercel/functions').then(({ waitUntil }) => {
29+
waitUntil(dispatch);
30+
});
4131
}

packages/adapter-optimizely/src/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
UserAttributes,
77
} from '@optimizely/optimizely-sdk';
88

9-
import type { Adapter } from 'flags';
9+
import type { Adapter, JsonValue } from 'flags';
1010
import { dispatchEvent } from './edge-runtime-hooks';
1111
import {
1212
createForwardingEventProcessor,
@@ -32,11 +32,6 @@ export type UserContext = {
3232
type AdapterResponse = {
3333
decide: <T>(
3434
getValue: (decision: OptimizelyDecision) => T,
35-
{
36-
attributes,
37-
}: {
38-
attributes?: UserAttributes;
39-
},
4035
) => Adapter<T, UserContext>;
4136
initialize: () => Promise<Client>;
4237
};
@@ -50,7 +45,7 @@ const requestHandler: RequestHandler = {
5045
const abortController = new AbortController();
5146

5247
const responsePromise = fetch(requestUrl, {
53-
headers: headers as any,
48+
headers: headers as Record<string, string>,
5449
method,
5550
body: data,
5651
signal: abortController.signal,
@@ -88,7 +83,9 @@ export function createOptimizelyAdapter({
8883
let projectConfigManager: OpaqueConfigManager | undefined;
8984
if (edgeConfig) {
9085
const edgeConfigClient = createClient(edgeConfig.connectionString);
91-
const datafile = await edgeConfigClient.get<string>(edgeConfig.itemKey);
86+
const datafile = await edgeConfigClient.get<JsonValue>(
87+
edgeConfig.itemKey,
88+
);
9289

9390
if (!datafile) {
9491
throw new Error(

0 commit comments

Comments
 (0)