@absolutejs/voice 0.0.22-beta.414 → 0.0.22-beta.415

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.ts CHANGED
@@ -206,6 +206,6 @@ export type { PlivoInboundMessage, PlivoMediaStreamBridge, PlivoMediaStreamBridg
206
206
  export type { VoiceTelephonyCarrierMatrix, VoiceTelephonyCarrierMatrixEntry, VoiceTelephonyCarrierMatrixInput, VoiceTelephonyCarrierMatrixOptions, VoiceTelephonyCarrierMatrixRoutesOptions, VoiceTelephonyCarrierMatrixStatus } from './telephony/matrix';
207
207
  export { shapeTelephonyAssistantText } from './telephony/response';
208
208
  export type { TelephonyResponseShapeMode, TelephonyResponseShapeOptions } from './telephony/response';
209
- export { buildVoiceProofPack, buildVoiceProofPackFromObservabilityExport, createVoiceProofPackArtifacts, createVoiceProofPackOperationsRecordSection, createVoiceProofPackProductionReadinessSection, createVoiceProofPackProviderSloSection, createVoiceProofPackRoutes, createVoiceProofPackSupportBundleSection, renderVoiceProofPackMarkdown, writeVoiceProofPack } from './proofPack';
210
- export type { VoiceProofPack, VoiceProofPackEvidence, VoiceProofPackInput, VoiceProofPackRoutesOptions, VoiceProofPackSection, VoiceProofPackStatus, VoiceProofPackWriteResult } from './proofPack';
209
+ export { buildVoiceProofPack, buildVoiceProofPackFromObservabilityExport, createVoiceProofPackStaleWhileRefreshSource, createVoiceProofPackArtifacts, createVoiceProofPackOperationsRecordSection, createVoiceProofPackProductionReadinessSection, createVoiceProofPackProviderSloSection, createVoiceProofPackRoutes, createVoiceProofPackSupportBundleSection, renderVoiceProofPackMarkdown, writeVoiceProofPack } from './proofPack';
210
+ export type { VoiceProofPack, VoiceProofPackEvidence, VoiceProofPackInput, VoiceProofPackRoutesOptions, VoiceProofPackSection, VoiceProofPackSourceValue, VoiceProofPackStatus, VoiceProofPackStaleWhileRefreshSourceOptions, VoiceProofPackWriteResult } from './proofPack';
211
211
  export * from './types';
package/dist/index.js CHANGED
@@ -39952,6 +39952,11 @@ import { Elysia as Elysia66 } from "elysia";
39952
39952
  import { mkdir as mkdir5 } from "fs/promises";
39953
39953
  import { dirname as dirname3, join as join4 } from "path";
39954
39954
  var toGeneratedAt = (value) => value === undefined ? new Date().toISOString() : typeof value === "number" ? new Date(value).toISOString() : value;
39955
+ var getProofPackGeneratedAtMs = (proofPack) => {
39956
+ const generatedAt = buildVoiceProofPack(proofPack).generatedAt;
39957
+ const generatedAtMs = Date.parse(generatedAt);
39958
+ return Number.isFinite(generatedAtMs) ? generatedAtMs : 0;
39959
+ };
39955
39960
  var summarizeProofPackSections = (sections) => {
39956
39961
  let pass = 0;
39957
39962
  let warn = 0;
@@ -40163,6 +40168,34 @@ var buildVoiceProofPack = (input) => {
40163
40168
  summary
40164
40169
  };
40165
40170
  };
40171
+ var createVoiceProofPackStaleWhileRefreshSource = (options) => {
40172
+ const maxAgeMs = options.maxAgeMs ?? 5 * 60000;
40173
+ const now = options.now ?? Date.now;
40174
+ let refreshPromise;
40175
+ const refresh = async () => {
40176
+ const refreshed = await options.refresh();
40177
+ return refreshed ?? options.read();
40178
+ };
40179
+ const startRefresh = () => {
40180
+ refreshPromise ??= refresh().finally(() => {
40181
+ refreshPromise = undefined;
40182
+ });
40183
+ return refreshPromise;
40184
+ };
40185
+ return async () => {
40186
+ let current;
40187
+ try {
40188
+ current = await options.read();
40189
+ } catch {
40190
+ return startRefresh();
40191
+ }
40192
+ if (now() - getProofPackGeneratedAtMs(current) <= maxAgeMs) {
40193
+ return current;
40194
+ }
40195
+ startRefresh().catch((error) => options.onRefreshError?.(error));
40196
+ return current;
40197
+ };
40198
+ };
40166
40199
  var buildVoiceProofPackFromObservabilityExport = (report, input = {}) => buildVoiceProofPack({
40167
40200
  ...input,
40168
40201
  artifacts: report.artifacts,
@@ -40725,6 +40758,7 @@ export {
40725
40758
  createVoiceProofTrendRecommendationRoutes,
40726
40759
  createVoiceProofTraceStore,
40727
40760
  createVoiceProofPackSupportBundleSection,
40761
+ createVoiceProofPackStaleWhileRefreshSource,
40728
40762
  createVoiceProofPackRoutes,
40729
40763
  createVoiceProofPackProviderSloSection,
40730
40764
  createVoiceProofPackProductionReadinessSection,
@@ -53,12 +53,20 @@ export type VoiceProofPackWriteResult = {
53
53
  markdownPath: string;
54
54
  proofPack: VoiceProofPack;
55
55
  };
56
+ export type VoiceProofPackSourceValue = VoiceProofPack | VoiceProofPackInput;
57
+ export type VoiceProofPackStaleWhileRefreshSourceOptions = {
58
+ maxAgeMs?: number;
59
+ now?: () => number;
60
+ onRefreshError?: (error: unknown) => void;
61
+ read: () => VoiceProofPackSourceValue | Promise<VoiceProofPackSourceValue>;
62
+ refresh: () => VoiceProofPackSourceValue | void | Promise<VoiceProofPackSourceValue | void>;
63
+ };
56
64
  export type VoiceProofPackRoutesOptions = {
57
65
  headers?: HeadersInit;
58
66
  jsonPath?: false | string;
59
67
  markdownPath?: false | string;
60
68
  name?: string;
61
- source: VoiceProofPack | VoiceProofPackInput | (() => VoiceProofPack | VoiceProofPackInput | Promise<VoiceProofPack | VoiceProofPackInput>);
69
+ source: VoiceProofPackSourceValue | (() => VoiceProofPackSourceValue | Promise<VoiceProofPackSourceValue>);
62
70
  };
63
71
  export declare const createVoiceProofPackProviderSloSection: (report: VoiceProviderSloReport, options?: {
64
72
  href?: string;
@@ -77,6 +85,7 @@ export declare const createVoiceProofPackSupportBundleSection: (input: {
77
85
  title?: string;
78
86
  }) => VoiceProofPackSection;
79
87
  export declare const buildVoiceProofPack: (input: VoiceProofPackInput | VoiceProofPack) => VoiceProofPack;
88
+ export declare const createVoiceProofPackStaleWhileRefreshSource: (options: VoiceProofPackStaleWhileRefreshSourceOptions) => () => Promise<VoiceProofPackSourceValue>;
80
89
  export declare const buildVoiceProofPackFromObservabilityExport: (report: VoiceObservabilityExportReport, input?: Omit<VoiceProofPackInput, "artifacts" | "sections">) => VoiceProofPack;
81
90
  export declare const renderVoiceProofPackMarkdown: (proofPack: VoiceProofPack) => string;
82
91
  export declare const writeVoiceProofPack: (input: VoiceProofPackInput | VoiceProofPack, options?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.414",
3
+ "version": "0.0.22-beta.415",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",