@goodtiming/baton-sdk 1.2.0 → 1.2.1
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.cjs +38 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -1
- package/dist/index.d.ts +44 -1
- package/dist/index.js +38 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -53,7 +53,7 @@ __export(index_exports, {
|
|
|
53
53
|
module.exports = __toCommonJS(index_exports);
|
|
54
54
|
|
|
55
55
|
// src/version.ts
|
|
56
|
-
var SDK_VERSION = "ts-1.2.
|
|
56
|
+
var SDK_VERSION = "ts-1.2.1";
|
|
57
57
|
|
|
58
58
|
// src/events.ts
|
|
59
59
|
var import_zod = require("zod");
|
|
@@ -187,7 +187,8 @@ var CaptureObservedSchema = import_zod.z.object({
|
|
|
187
187
|
settings_version: import_zod.z.number().int().min(1).optional(),
|
|
188
188
|
audience: import_zod.z.string().optional(),
|
|
189
189
|
overlay: import_zod.z.string().optional(),
|
|
190
|
-
candidate: import_zod.z.string().optional()
|
|
190
|
+
candidate: import_zod.z.string().optional(),
|
|
191
|
+
task: import_zod.z.string().optional()
|
|
191
192
|
}).strict();
|
|
192
193
|
var PrincipalWireSchema = import_zod.z.object({
|
|
193
194
|
id: import_zod.z.string(),
|
|
@@ -2387,18 +2388,36 @@ var CANDIDATES_HELD = 32;
|
|
|
2387
2388
|
var CANDIDATE_READS_AT_ONCE = 4;
|
|
2388
2389
|
var CANDIDATE_START_TIMEOUT_MS = 5e3;
|
|
2389
2390
|
var CANDIDATE_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
2390
|
-
|
|
2391
|
+
var TASK_ENV = "BATON_TASK";
|
|
2392
|
+
var TASK_HEADER = "baton-task";
|
|
2393
|
+
var TASK_ID = /^[A-Za-z0-9_.:-]{1,128}$/;
|
|
2394
|
+
function matchingId(pattern, value) {
|
|
2391
2395
|
if (typeof value !== "string") return null;
|
|
2392
2396
|
const id = stripWhiteSpace(value);
|
|
2393
|
-
return
|
|
2397
|
+
return pattern.test(id) ? id : null;
|
|
2394
2398
|
}
|
|
2395
|
-
function
|
|
2399
|
+
function headerId(headers, name, parse) {
|
|
2396
2400
|
try {
|
|
2397
|
-
return
|
|
2401
|
+
return parse(headers?.get(name));
|
|
2398
2402
|
} catch {
|
|
2399
2403
|
return null;
|
|
2400
2404
|
}
|
|
2401
2405
|
}
|
|
2406
|
+
function candidateId(value) {
|
|
2407
|
+
return matchingId(CANDIDATE_ID, value);
|
|
2408
|
+
}
|
|
2409
|
+
function headerCandidate(headers) {
|
|
2410
|
+
return headerId(headers, CANDIDATE_HEADER, candidateId);
|
|
2411
|
+
}
|
|
2412
|
+
function taskId(value) {
|
|
2413
|
+
return matchingId(TASK_ID, value);
|
|
2414
|
+
}
|
|
2415
|
+
function headerTask(headers) {
|
|
2416
|
+
return headerId(headers, TASK_HEADER, taskId);
|
|
2417
|
+
}
|
|
2418
|
+
function envTask() {
|
|
2419
|
+
return taskId(typeof process !== "undefined" ? process.env?.[TASK_ENV] : void 0);
|
|
2420
|
+
}
|
|
2402
2421
|
function envCandidate() {
|
|
2403
2422
|
const value = typeof process !== "undefined" ? process.env?.[CANDIDATE_ENV] : void 0;
|
|
2404
2423
|
if (!value) return null;
|
|
@@ -2622,15 +2641,17 @@ var SettingsFetcher = class {
|
|
|
2622
2641
|
};
|
|
2623
2642
|
var PENDING = /* @__PURE__ */ Symbol("pending");
|
|
2624
2643
|
var CaptureSettings = class {
|
|
2625
|
-
constructor(vendorId2, source, candidate = null, startTimeoutMs = CANDIDATE_START_TIMEOUT_MS) {
|
|
2644
|
+
constructor(vendorId2, source, candidate = null, task = null, startTimeoutMs = CANDIDATE_START_TIMEOUT_MS) {
|
|
2626
2645
|
this.vendorId = vendorId2;
|
|
2627
2646
|
this.source = source;
|
|
2628
2647
|
this.candidate = candidate;
|
|
2648
|
+
this.task = task;
|
|
2629
2649
|
this.startTimeoutMs = startTimeoutMs;
|
|
2630
2650
|
}
|
|
2631
2651
|
vendorId;
|
|
2632
2652
|
source;
|
|
2633
2653
|
candidate;
|
|
2654
|
+
task;
|
|
2634
2655
|
startTimeoutMs;
|
|
2635
2656
|
processDocument = null;
|
|
2636
2657
|
/** `BATON_CANDIDATE`'s read; requests wait for it. */
|
|
@@ -2676,7 +2697,10 @@ var CaptureSettings = class {
|
|
|
2676
2697
|
/** `undefined` while no document is held, and the config's values apply. */
|
|
2677
2698
|
forCaller(caller) {
|
|
2678
2699
|
const document = caller.candidate == null ? this.document : this.headerDocument(caller.candidate) ?? this.source.document;
|
|
2679
|
-
|
|
2700
|
+
const settings = document?.settingsFor(caller, this.vendorId);
|
|
2701
|
+
const task = caller.candidate == null ? this.task : caller.task;
|
|
2702
|
+
if (settings === void 0 || task == null || settings.capture.candidate === void 0) return settings;
|
|
2703
|
+
return { ...settings, capture: { ...settings.capture, task } };
|
|
2680
2704
|
}
|
|
2681
2705
|
/** Whether `test` holds for some document a request could be served under now. */
|
|
2682
2706
|
someDocument(test) {
|
|
@@ -2817,11 +2841,14 @@ async function resolveCaller(hook, call, settings, client = null) {
|
|
|
2817
2841
|
const caller = await resolveIdentity(hook, call);
|
|
2818
2842
|
if (settings === void 0) return caller;
|
|
2819
2843
|
try {
|
|
2844
|
+
const headers = extraHeaders(call.extra);
|
|
2845
|
+
const candidate = headerCandidate(headers);
|
|
2820
2846
|
const callSettings = settings.forCaller({
|
|
2821
2847
|
labels: caller.labels,
|
|
2822
2848
|
clientName: client?.info?.name ?? null,
|
|
2823
2849
|
shareKey: caller.principal?.id ?? null,
|
|
2824
|
-
candidate
|
|
2850
|
+
candidate,
|
|
2851
|
+
task: candidate === null ? null : headerTask(headers)
|
|
2825
2852
|
});
|
|
2826
2853
|
return callSettings === void 0 ? caller : { ...caller, settings: callSettings };
|
|
2827
2854
|
} catch {
|
|
@@ -3557,7 +3584,8 @@ function resolveBatonConfig(supplied) {
|
|
|
3557
3584
|
vendorId: dsn.vendorId,
|
|
3558
3585
|
refreshMs: identity.settingsRefreshMs ?? DEFAULT_SETTINGS_REFRESH_MS
|
|
3559
3586
|
}),
|
|
3560
|
-
envCandidate()
|
|
3587
|
+
envCandidate(),
|
|
3588
|
+
envTask()
|
|
3561
3589
|
)
|
|
3562
3590
|
} : {}
|
|
3563
3591
|
};
|