perspectapi-ts-sdk 7.2.6 → 7.2.8
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.js +7 -3
- package/dist/index.mjs +7 -3
- package/package.json +1 -1
- package/src/ab/ab-client.ts +8 -4
package/dist/index.js
CHANGED
|
@@ -4478,7 +4478,7 @@ function buildAbClient(apiKey, siteName, baseUrl, ctx, config, visitorId, isBot)
|
|
|
4478
4478
|
return { variant: flag.defaultVariant, enrolled: false, config: null };
|
|
4479
4479
|
}
|
|
4480
4480
|
const variantCfg = flag.variants.find((v) => v.key === assigned)?.config ?? null;
|
|
4481
|
-
emit(apiKey, baseUrl, ctx, {
|
|
4481
|
+
await emit(apiKey, baseUrl, ctx, {
|
|
4482
4482
|
site: siteName,
|
|
4483
4483
|
kind: "exposure",
|
|
4484
4484
|
flag: flagKey,
|
|
@@ -4499,7 +4499,7 @@ function buildAbClient(apiKey, siteName, baseUrl, ctx, config, visitorId, isBot)
|
|
|
4499
4499
|
const bucket = bucketFor(visitorId, flagKey, flag.currentVersion);
|
|
4500
4500
|
const assigned = variantForBucket(bucket, flag.variants, flag.trafficAllocationBp);
|
|
4501
4501
|
if (assigned === null) continue;
|
|
4502
|
-
emit(apiKey, baseUrl, ctx, {
|
|
4502
|
+
await emit(apiKey, baseUrl, ctx, {
|
|
4503
4503
|
site: siteName,
|
|
4504
4504
|
kind: "conversion",
|
|
4505
4505
|
flag: flagKey,
|
|
@@ -4543,7 +4543,11 @@ function emit(apiKey, baseUrl, ctx, body) {
|
|
|
4543
4543
|
headers: { "content-type": "application/json", "x-api-key": apiKey },
|
|
4544
4544
|
body: JSON.stringify(body)
|
|
4545
4545
|
}).then(() => void 0).catch(() => void 0);
|
|
4546
|
-
if (ctx)
|
|
4546
|
+
if (ctx) {
|
|
4547
|
+
ctx.waitUntil(task);
|
|
4548
|
+
return Promise.resolve();
|
|
4549
|
+
}
|
|
4550
|
+
return task;
|
|
4547
4551
|
}
|
|
4548
4552
|
function classifyBotFromCfRequest(request) {
|
|
4549
4553
|
const cf = request.cf;
|
package/dist/index.mjs
CHANGED
|
@@ -2889,7 +2889,7 @@ function buildAbClient(apiKey, siteName, baseUrl, ctx, config, visitorId, isBot)
|
|
|
2889
2889
|
return { variant: flag.defaultVariant, enrolled: false, config: null };
|
|
2890
2890
|
}
|
|
2891
2891
|
const variantCfg = flag.variants.find((v) => v.key === assigned)?.config ?? null;
|
|
2892
|
-
emit(apiKey, baseUrl, ctx, {
|
|
2892
|
+
await emit(apiKey, baseUrl, ctx, {
|
|
2893
2893
|
site: siteName,
|
|
2894
2894
|
kind: "exposure",
|
|
2895
2895
|
flag: flagKey,
|
|
@@ -2910,7 +2910,7 @@ function buildAbClient(apiKey, siteName, baseUrl, ctx, config, visitorId, isBot)
|
|
|
2910
2910
|
const bucket = bucketFor(visitorId, flagKey, flag.currentVersion);
|
|
2911
2911
|
const assigned = variantForBucket(bucket, flag.variants, flag.trafficAllocationBp);
|
|
2912
2912
|
if (assigned === null) continue;
|
|
2913
|
-
emit(apiKey, baseUrl, ctx, {
|
|
2913
|
+
await emit(apiKey, baseUrl, ctx, {
|
|
2914
2914
|
site: siteName,
|
|
2915
2915
|
kind: "conversion",
|
|
2916
2916
|
flag: flagKey,
|
|
@@ -2954,7 +2954,11 @@ function emit(apiKey, baseUrl, ctx, body) {
|
|
|
2954
2954
|
headers: { "content-type": "application/json", "x-api-key": apiKey },
|
|
2955
2955
|
body: JSON.stringify(body)
|
|
2956
2956
|
}).then(() => void 0).catch(() => void 0);
|
|
2957
|
-
if (ctx)
|
|
2957
|
+
if (ctx) {
|
|
2958
|
+
ctx.waitUntil(task);
|
|
2959
|
+
return Promise.resolve();
|
|
2960
|
+
}
|
|
2961
|
+
return task;
|
|
2958
2962
|
}
|
|
2959
2963
|
function classifyBotFromCfRequest(request) {
|
|
2960
2964
|
const cf = request.cf;
|
package/package.json
CHANGED
package/src/ab/ab-client.ts
CHANGED
|
@@ -124,7 +124,7 @@ function buildAbClient(
|
|
|
124
124
|
return { variant: flag.defaultVariant, enrolled: false, config: null };
|
|
125
125
|
}
|
|
126
126
|
const variantCfg = flag.variants.find((v) => v.key === assigned)?.config ?? null;
|
|
127
|
-
emit(apiKey, baseUrl, ctx, {
|
|
127
|
+
await emit(apiKey, baseUrl, ctx, {
|
|
128
128
|
site: siteName,
|
|
129
129
|
kind: 'exposure',
|
|
130
130
|
flag: flagKey,
|
|
@@ -146,7 +146,7 @@ function buildAbClient(
|
|
|
146
146
|
const bucket = bucketFor(visitorId, flagKey, flag.currentVersion);
|
|
147
147
|
const assigned = variantForBucket(bucket, flag.variants, flag.trafficAllocationBp);
|
|
148
148
|
if (assigned === null) continue;
|
|
149
|
-
emit(apiKey, baseUrl, ctx, {
|
|
149
|
+
await emit(apiKey, baseUrl, ctx, {
|
|
150
150
|
site: siteName,
|
|
151
151
|
kind: 'conversion',
|
|
152
152
|
flag: flagKey,
|
|
@@ -225,7 +225,7 @@ function emit(
|
|
|
225
225
|
baseUrl: string,
|
|
226
226
|
ctx: { waitUntil(p: Promise<unknown>): void } | undefined,
|
|
227
227
|
body: EventBody,
|
|
228
|
-
): void {
|
|
228
|
+
): Promise<void> {
|
|
229
229
|
const task = fetch(`${baseUrl}/_ab/event`, {
|
|
230
230
|
method: 'POST',
|
|
231
231
|
headers: { 'content-type': 'application/json', 'x-api-key': apiKey },
|
|
@@ -233,7 +233,11 @@ function emit(
|
|
|
233
233
|
})
|
|
234
234
|
.then(() => undefined)
|
|
235
235
|
.catch(() => undefined);
|
|
236
|
-
if (ctx)
|
|
236
|
+
if (ctx) {
|
|
237
|
+
ctx.waitUntil(task);
|
|
238
|
+
return Promise.resolve();
|
|
239
|
+
}
|
|
240
|
+
return task;
|
|
237
241
|
}
|
|
238
242
|
|
|
239
243
|
// ---------------------------------------------------------------------------
|