@hexclave/shared 1.0.53 → 1.0.55
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/{admin-interface-D9wMduWc.d.ts → admin-interface-DIt0PvhC.d.ts} +4 -4
- package/dist/{admin-interface-D9wMduWc.d.ts.map → admin-interface-DIt0PvhC.d.ts.map} +1 -1
- package/dist/ai/unified-prompts/reminders.js +1 -1
- package/dist/ai/unified-prompts/reminders.js.map +1 -1
- package/dist/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js +4 -4
- package/dist/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js.map +1 -1
- package/dist/config/schema-fuzzer.test.js +1 -1
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/schema.js +1 -1
- package/dist/config-authoring.d.ts +1 -1
- package/dist/config-rendering.d.ts +9 -1
- package/dist/config-rendering.d.ts.map +1 -1
- package/dist/config-rendering.js +2 -2
- package/dist/config-rendering.js.map +1 -1
- package/dist/dates-BRAvSk6L.d.ts.map +1 -1
- package/dist/{email-outbox-B1wmVPRG.d.ts → email-outbox-CqzwInBL.d.ts} +91 -91
- package/dist/{email-outbox-B1wmVPRG.d.ts.map → email-outbox-CqzwInBL.d.ts.map} +1 -1
- package/dist/esm/ai/unified-prompts/reminders.js +1 -1
- package/dist/esm/ai/unified-prompts/reminders.js.map +1 -1
- package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js +4 -4
- package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js.map +1 -1
- package/dist/esm/config/schema-fuzzer.test.js +1 -1
- package/dist/esm/config/schema.d.ts +28 -28
- package/dist/esm/config/schema.js +1 -1
- package/dist/esm/config-rendering.d.ts +9 -1
- package/dist/esm/config-rendering.d.ts.map +1 -1
- package/dist/esm/config-rendering.js +2 -3
- package/dist/esm/config-rendering.js.map +1 -1
- package/dist/esm/interface/admin-interface.js +1 -1
- package/dist/esm/interface/client-interface.js +2 -2
- package/dist/esm/interface/crud/email-outbox.d.ts +90 -90
- package/dist/esm/interface/plan-usage.d.ts +1 -1
- package/dist/esm/interface/server-interface.js +1 -1
- package/dist/esm/package.json +18 -0
- package/dist/esm/utils/dates.d.ts.map +1 -1
- package/dist/esm/utils/dates.js +2 -1
- package/dist/esm/utils/dates.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/interface/admin-interface.d.ts +2 -2
- package/dist/interface/admin-interface.js +1 -1
- package/dist/interface/client-interface.js +2 -2
- package/dist/interface/crud/email-outbox.d.ts +1 -1
- package/dist/interface/plan-usage.d.ts +1 -1
- package/dist/interface/server-interface.js +1 -1
- package/dist/{plan-usage-BaDxcLZ1.d.ts → plan-usage-BO2GsKlN.d.ts} +2 -2
- package/dist/{plan-usage-BaDxcLZ1.d.ts.map → plan-usage-BO2GsKlN.d.ts.map} +1 -1
- package/dist/{schema-DV0SQUbY.d.ts → schema-CLmaZetm.d.ts} +29 -29
- package/dist/{schema-DV0SQUbY.d.ts.map → schema-CLmaZetm.d.ts.map} +1 -1
- package/dist/utils/dates.js +2 -1
- package/dist/utils/dates.js.map +1 -1
- package/package.json +1 -1
- package/src/ai/unified-prompts/reminders.ts +1 -1
- package/src/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.ts +4 -4
- package/src/config-rendering.ts +5 -6
- package/src/utils/dates.tsx +22 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dates.js","names":[],"sources":["../../../src/utils/dates.tsx"],"sourcesContent":["import { intervalSchema } from \"../schema-fields\";\nimport { HexclaveAssertionError } from \"./errors\";\nimport { remainder } from \"./math\";\n\nexport function isWeekend(date: Date): boolean {\n return date.getDay() === 0 || date.getDay() === 6;\n}\n\nimport.meta.vitest?.test(\"isWeekend\", ({ expect }) => {\n // Sunday (day 0)\n expect(isWeekend(new Date(2023, 0, 1))).toBe(true);\n // Saturday (day 6)\n expect(isWeekend(new Date(2023, 0, 7))).toBe(true);\n // Monday (day 1)\n expect(isWeekend(new Date(2023, 0, 2))).toBe(false);\n // Friday (day 5)\n expect(isWeekend(new Date(2023, 0, 6))).toBe(false);\n});\n\nconst agoUnits = [\n [60, 'second'],\n [60, 'minute'],\n [24, 'hour'],\n [7, 'day'],\n [5, 'week'],\n] as const;\n\nexport function fromNow(date: Date): string {\n return fromNowDetailed(date).result;\n}\n\nimport.meta.vitest?.test(\"fromNow\", ({ expect }) => {\n // Set a fixed date for testing\n const fixedDate = new Date(\"2023-01-15T12:00:00.000Z\");\n\n // Use Vitest's fake timers\n import.meta.vitest?.vi.useFakeTimers();\n import.meta.vitest?.vi.setSystemTime(fixedDate);\n\n // Test past times\n expect(fromNow(new Date(\"2023-01-15T11:59:50.000Z\"))).toBe(\"just now\");\n expect(fromNow(new Date(\"2023-01-15T11:59:00.000Z\"))).toBe(\"1 minute ago\");\n expect(fromNow(new Date(\"2023-01-15T11:00:00.000Z\"))).toBe(\"1 hour ago\");\n expect(fromNow(new Date(\"2023-01-14T12:00:00.000Z\"))).toBe(\"1 day ago\");\n expect(fromNow(new Date(\"2023-01-08T12:00:00.000Z\"))).toBe(\"1 week ago\");\n\n // Test future times\n expect(fromNow(new Date(\"2023-01-15T12:00:10.000Z\"))).toBe(\"just now\");\n expect(fromNow(new Date(\"2023-01-15T12:01:00.000Z\"))).toBe(\"in 1 minute\");\n expect(fromNow(new Date(\"2023-01-15T13:00:00.000Z\"))).toBe(\"in 1 hour\");\n expect(fromNow(new Date(\"2023-01-16T12:00:00.000Z\"))).toBe(\"in 1 day\");\n expect(fromNow(new Date(\"2023-01-22T12:00:00.000Z\"))).toBe(\"in 1 week\");\n\n // Test very old dates (should use date format)\n expect(fromNow(new Date(\"2022-01-15T12:00:00.000Z\"))).toMatch(/Jan 15, 2022/);\n\n // Restore real timers\n import.meta.vitest?.vi.useRealTimers();\n});\n\nexport function fromNowDetailed(date: Date): {\n result: string,\n /**\n * May be Infinity if the result will never change.\n */\n secondsUntilChange: number,\n} {\n if (!(date instanceof Date)) {\n throw new Error(`fromNow only accepts Date objects (received: ${date})`);\n }\n\n const now = new Date();\n const elapsed = now.getTime() - date.getTime();\n\n let remainingInUnit = Math.abs(elapsed) / 1000;\n if (remainingInUnit < 15) {\n return {\n result: 'just now',\n secondsUntilChange: 15 - remainingInUnit,\n };\n }\n let unitInSeconds = 1;\n for (const [nextUnitSize, unitName] of agoUnits) {\n const rounded = Math.round(remainingInUnit);\n if (rounded < nextUnitSize) {\n if (elapsed < 0) {\n return {\n result: `in ${rounded} ${unitName}${rounded === 1 ? '' : 's'}`,\n secondsUntilChange: remainder((remainingInUnit - rounded + 0.5) * unitInSeconds, unitInSeconds),\n };\n } else {\n return {\n result: `${rounded} ${unitName}${rounded === 1 ? '' : 's'} ago`,\n secondsUntilChange: remainder((rounded - remainingInUnit - 0.5) * unitInSeconds, unitInSeconds),\n };\n }\n }\n unitInSeconds *= nextUnitSize;\n remainingInUnit /= nextUnitSize;\n }\n\n return {\n result: date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' }),\n secondsUntilChange: Infinity,\n };\n}\n\n/**\n * Returns a string representation of the given date in the format expected by the `datetime-local` input type.\n */\nexport function getInputDatetimeLocalString(date: Date): string {\n date = new Date(date);\n date.setMinutes(date.getMinutes() - date.getTimezoneOffset());\n return date.toISOString().slice(0, 19);\n}\n\nimport.meta.vitest?.test(\"getInputDatetimeLocalString\", ({ expect }) => {\n // Use Vitest's fake timers to ensure consistent timezone behavior\n import.meta.vitest?.vi.useFakeTimers();\n\n // Test with a specific date\n const mockDate = new Date(\"2023-01-15T12:30:45.000Z\");\n const result = getInputDatetimeLocalString(mockDate);\n\n // The result should be in the format YYYY-MM-DDTHH:MM:SS\n expect(result).toMatch(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$/);\n\n // Test with different dates\n const dates = [\n new Date(\"2023-01-01T00:00:00.000Z\"),\n new Date(\"2023-06-15T23:59:59.000Z\"),\n new Date(\"2023-12-31T12:34:56.000Z\"),\n ];\n\n for (const date of dates) {\n const result = getInputDatetimeLocalString(date);\n expect(result).toMatch(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$/);\n }\n\n // Restore real timers\n import.meta.vitest?.vi.useRealTimers();\n});\n\n\nexport type Interval = [number, 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'];\nexport type DayInterval = [number, 'day' | 'week' | 'month' | 'year'];\n\nfunction applyInterval(date: Date, times: number, interval: Interval): Date {\n if (!intervalSchema.isValidSync(interval)) {\n throw new HexclaveAssertionError(`Invalid interval`, { interval });\n }\n const [amount, unit] = interval;\n switch (unit) {\n case 'millisecond': {\n date.setMilliseconds(date.getMilliseconds() + amount * times);\n break;\n }\n case 'second': {\n date.setSeconds(date.getSeconds() + amount * times);\n break;\n }\n case 'minute': {\n date.setMinutes(date.getMinutes() + amount * times);\n break;\n }\n case 'hour': {\n date.setHours(date.getHours() + amount * times);\n break;\n }\n case 'day': {\n date.setDate(date.getDate() + amount * times);\n break;\n }\n case 'week': {\n date.setDate(date.getDate() + amount * times * 7);\n break;\n }\n case 'month': {\n date.setMonth(date.getMonth() + amount * times);\n break;\n }\n case 'year': {\n date.setFullYear(date.getFullYear() + amount * times);\n break;\n }\n default: {\n throw new HexclaveAssertionError(`Invalid interval despite schema validation`, { interval });\n }\n }\n return date;\n}\n\nexport function subtractInterval(date: Date, interval: Interval): Date {\n return applyInterval(date, -1, interval);\n}\n\n// One-shot local-time interval arithmetic that OVERFLOWS (Jan 31 + 1 month -> Mar 3, via\n// Date#setMonth) rather than clamping. Use this for single-step period math where JS/Stripe overflow\n// semantics are what we want (e.g. computing a subscription's currentPeriodEnd). For recurring\n// grant/reset BOUNDARIES, use `nthDayIntervalMillis` / `getIntervalsElapsed` instead — they clamp to\n// month-end and compute in UTC from a fixed anchor, and mixing the two would drift.\nexport function addInterval(date: Date, interval: Interval): Date {\n return applyInterval(date, 1, interval);\n}\n\nexport const FAR_FUTURE_DATE = new Date(8640000000000000); // 13 Sep 275760 00:00:00 UTC\n\nfunction getMsPerDayIntervalUnit(unit: 'day' | 'week'): number {\n if (unit === 'day') {\n return 24 * 60 * 60 * 1000;\n }\n return 7 * 24 * 60 * 60 * 1000;\n}\n\n\n// The number of full `repeat` intervals elapsed from `anchor` up to (and including) `to`, i.e. the\n// largest n >= 0 with the n-th boundary <= to. Boundaries are the SAME ones `nthDayIntervalMillis`\n// computes (anchor-relative, UTC, month-end clamped), so counting and boundary-computation never\n// disagree — a Jan 31 monthly anchor has elapsed one interval by Feb 28, matching the reset the\n// bulldozer item-repeat fold actually emits. (This is why it must NOT be built on `addInterval`,\n// which is local-time and overflows instead of clamping.)\nexport function getIntervalsElapsed(anchor: Date, to: Date, repeat: DayInterval): number {\n const [amount, unit] = repeat;\n const toMillis = to.getTime();\n if (toMillis <= anchor.getTime()) return 0;\n if (unit === 'day' || unit === 'week') {\n const msPerUnit = getMsPerDayIntervalUnit(unit);\n const diffMs = toMillis - anchor.getTime();\n return Math.floor(diffMs / (msPerUnit * amount));\n }\n // month/year: walk anchor-relative boundaries. The count is small in practice (bounded by the\n // number of billing periods since the anchor), so a linear walk is fine.\n let count = 0;\n while (nthDayIntervalMillis(anchor.getTime(), repeat, count + 1) <= toMillis) count += 1;\n return count;\n}\n\nimport.meta.vitest?.test(\"getIntervalsElapsed\", ({ expect }) => {\n const anchor = new Date('2025-01-01T00:00:00.000Z');\n const to = new Date('2025-01-15T00:00:00.000Z');\n expect(getIntervalsElapsed(anchor, to, [1, 'week'])).toBe(2);\n expect(getIntervalsElapsed(anchor, to, [3, 'day'])).toBe(4);\n\n // Jan 31 monthly anchor: the first boundary is clamped to Feb 28, which is <= Mar 1, so one\n // interval has elapsed (anchor-relative clamped math, consistent with nthDayIntervalMillis).\n const mAnchor = new Date('2023-01-31T00:00:00.000Z');\n const mTo = new Date('2023-03-01T00:00:00.000Z');\n expect(getIntervalsElapsed(mAnchor, mTo, [1, 'month'])).toBe(1);\n\n const yAnchor = new Date('2020-01-01T00:00:00.000Z');\n const yTo = new Date('2022-06-01T00:00:00.000Z');\n expect(getIntervalsElapsed(yAnchor, yTo, [1, 'year'])).toBe(2);\n});\n\n/**\n * The UTC millis of the `occurrence`-th (1-based) repeat of `interval` after `anchorMillis`.\n *\n * Each boundary is computed from the *original* anchor (never by stepping off the previous, possibly\n * clamped, boundary) so the anchor's day-of-month is preserved across resets: a Jan 31 anchor yields\n * Feb 28, Mar 31, Apr 30, ... (matching Stripe's billing-cycle behavior) rather than drifting to\n * Feb 28, Mar 28, ... . Month/year overflow (e.g. Jan 31 -> Feb) is clamped to the target month's\n * last day. Day/week are exact multiples (no calendar involved, so no drift possible).\n *\n * Everything is done in UTC (unlike `addInterval`, which uses local-time Date accessors) so the\n * result is deterministic regardless of the server's timezone — this is relied upon by bulldozer\n * folds, which must be reproducible across machines.\n *\n * `occurrence` 0 returns the anchor itself; `getIntervalsElapsed` counts these same boundaries, so\n * the two are always consistent for a given DayInterval.\n */\nexport function nthDayIntervalMillis(anchorMillis: number, interval: DayInterval, occurrence: number): number {\n const [count, unit] = interval;\n const totalUnits = count * occurrence;\n if (unit === 'day' || unit === 'week') {\n return anchorMillis + totalUnits * getMsPerDayIntervalUnit(unit);\n }\n const anchor = new Date(anchorMillis);\n const monthsToAdd = unit === 'year' ? totalUnits * 12 : totalUnits;\n const absoluteMonth = anchor.getUTCFullYear() * 12 + anchor.getUTCMonth() + monthsToAdd;\n const targetYear = Math.floor(absoluteMonth / 12);\n const targetMonth = absoluteMonth - targetYear * 12;\n // Day 0 of the following month is the last day of the target month, so this gives its length.\n const daysInTargetMonth = new Date(Date.UTC(targetYear, targetMonth + 1, 0)).getUTCDate();\n const clampedDay = Math.min(anchor.getUTCDate(), daysInTargetMonth);\n return Date.UTC(\n targetYear,\n targetMonth,\n clampedDay,\n anchor.getUTCHours(),\n anchor.getUTCMinutes(),\n anchor.getUTCSeconds(),\n anchor.getUTCMilliseconds(),\n );\n}\n\nimport.meta.vitest?.test(\"nthDayIntervalMillis\", ({ expect }) => {\n const at = (iso: string) => new Date(iso).getTime();\n const iso = (millis: number) => new Date(millis).toISOString();\n\n // day / week are exact multiples (no drift), and honor the count.\n const dayAnchor = at('2025-01-01T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [1, 'day'], 1))).toBe('2025-01-02T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [3, 'day'], 4))).toBe('2025-01-13T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [2, 'week'], 3))).toBe('2025-02-12T08:30:00.000Z'); // 6 weeks = 42 days after Jan 1\n\n // Jan 31 monthly: clamp in short months, restore to the anchor day in long ones.\n const jan31 = at('2025-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 1))).toBe('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 2))).toBe('2025-03-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 3))).toBe('2025-04-30T00:00:00.000Z');\n\n // Anchor-day preservation: a Feb 28 anchor stays on day 28 (never jumps to Mar 31), unlike the\n // Jan 31 anchor above which restores to Mar 31. This is the evidence we compute from the anchor.\n const feb28 = at('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb28, [1, 'month'], 1))).toBe('2025-03-28T00:00:00.000Z');\n\n // Leap-year Feb: Feb 29 anchor clamps to Feb 28 in a non-leap year and restores in the next leap year.\n const feb29 = at('2024-02-29T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb29, [1, 'year'], 1))).toBe('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb29, [1, 'year'], 4))).toBe('2028-02-29T00:00:00.000Z');\n // Jan 31 monthly landing in a leap February clamps to Feb 29, not Feb 28.\n const jan31Leap = at('2024-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31Leap, [1, 'month'], 1))).toBe('2024-02-29T00:00:00.000Z');\n\n // End-of-December rollover: absolute-month math carries the year.\n const dec31 = at('2025-12-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 1))).toBe('2026-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 2))).toBe('2026-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 3))).toBe('2026-03-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'year'], 1))).toBe('2026-12-31T00:00:00.000Z');\n\n // Time-of-day is preserved through month clamping.\n const withTime = at('2025-01-31T13:45:59.123Z');\n expect(iso(nthDayIntervalMillis(withTime, [1, 'month'], 1))).toBe('2025-02-28T13:45:59.123Z');\n});\n"],"mappings":";;;;AAIA,SAAgB,UAAU,MAAqB;CAC7C,OAAO,KAAK,OAAO,MAAM,KAAK,KAAK,OAAO,MAAM;AAClD;AAaA,MAAM,WAAW;CACf,CAAC,IAAI,QAAQ;CACb,CAAC,IAAI,QAAQ;CACb,CAAC,IAAI,MAAM;CACX,CAAC,GAAG,KAAK;CACT,CAAC,GAAG,MAAM;AACZ;AAEA,SAAgB,QAAQ,MAAoB;CAC1C,OAAO,gBAAgB,IAAI,CAAC,CAAC;AAC/B;AA+BA,SAAgB,gBAAgB,MAM9B;CACA,IAAI,EAAE,gBAAgB,OACpB,MAAM,IAAI,MAAM,gDAAgD,KAAK,EAAE;CAIzE,MAAM,2BAAU,IADA,KACE,EAAA,CAAE,QAAQ,IAAI,KAAK,QAAQ;CAE7C,IAAI,kBAAkB,KAAK,IAAI,OAAO,IAAI;CAC1C,IAAI,kBAAkB,IACpB,OAAO;EACL,QAAQ;EACR,oBAAoB,KAAK;CAC3B;CAEF,IAAI,gBAAgB;CACpB,KAAK,MAAM,CAAC,cAAc,aAAa,UAAU;EAC/C,MAAM,UAAU,KAAK,MAAM,eAAe;EAC1C,IAAI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AY,IAAI;CAC5E,MAAM,aAAa,KAAK,MAAM,gBAAgB,EAAE;CAChD,MAAM,cAAc,gBAAgB,aAAa;CAEjD,MAAM,oBAAoB,IAAI,KAAK,KAAK,IAAI,YAAY,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW;CACxF,MAAM,aAAa,KAAK,IAAI,OAAO,WAAW,GAAG,iBAAiB;CAClE,OAAO,KAAK,IACV,YACA,aACA,YACA,OAAO,YAAY,GACnB,OAAO,cAAc,GACrB,OAAO,cAAc,GACrB,OAAO,mBAAmB,CAC5B;AACF"}
|
|
1
|
+
{"version":3,"file":"dates.js","names":[],"sources":["../../../src/utils/dates.tsx"],"sourcesContent":["import { intervalSchema } from \"../schema-fields\";\nimport { HexclaveAssertionError } from \"./errors\";\nimport { remainder } from \"./math\";\n\nexport function isWeekend(date: Date): boolean {\n return date.getDay() === 0 || date.getDay() === 6;\n}\n\nimport.meta.vitest?.test(\"isWeekend\", ({ expect }) => {\n // Sunday (day 0)\n expect(isWeekend(new Date(2023, 0, 1))).toBe(true);\n // Saturday (day 6)\n expect(isWeekend(new Date(2023, 0, 7))).toBe(true);\n // Monday (day 1)\n expect(isWeekend(new Date(2023, 0, 2))).toBe(false);\n // Friday (day 5)\n expect(isWeekend(new Date(2023, 0, 6))).toBe(false);\n});\n\nconst agoUnits = [\n [60, 'second'],\n [60, 'minute'],\n [24, 'hour'],\n [7, 'day'],\n [5, 'week'],\n] as const;\n\nexport function fromNow(date: Date): string {\n return fromNowDetailed(date).result;\n}\n\nimport.meta.vitest?.test(\"fromNow\", ({ expect }) => {\n // Set a fixed date for testing\n const fixedDate = new Date(\"2023-01-15T12:00:00.000Z\");\n\n // Use Vitest's fake timers\n import.meta.vitest?.vi.useFakeTimers();\n import.meta.vitest?.vi.setSystemTime(fixedDate);\n\n // Test past times\n expect(fromNow(new Date(\"2023-01-15T11:59:50.000Z\"))).toBe(\"just now\");\n expect(fromNow(new Date(\"2023-01-15T11:59:00.000Z\"))).toBe(\"1 minute ago\");\n expect(fromNow(new Date(\"2023-01-15T11:00:00.000Z\"))).toBe(\"1 hour ago\");\n expect(fromNow(new Date(\"2023-01-14T12:00:00.000Z\"))).toBe(\"1 day ago\");\n expect(fromNow(new Date(\"2023-01-08T12:00:00.000Z\"))).toBe(\"1 week ago\");\n\n // Test future times\n expect(fromNow(new Date(\"2023-01-15T12:00:10.000Z\"))).toBe(\"just now\");\n expect(fromNow(new Date(\"2023-01-15T12:01:00.000Z\"))).toBe(\"in 1 minute\");\n expect(fromNow(new Date(\"2023-01-15T13:00:00.000Z\"))).toBe(\"in 1 hour\");\n expect(fromNow(new Date(\"2023-01-16T12:00:00.000Z\"))).toBe(\"in 1 day\");\n expect(fromNow(new Date(\"2023-01-22T12:00:00.000Z\"))).toBe(\"in 1 week\");\n\n // Test very old dates (should use date format)\n expect(fromNow(new Date(\"2022-01-15T12:00:00.000Z\"))).toMatch(/Jan 15, 2022/);\n\n // Restore real timers\n import.meta.vitest?.vi.useRealTimers();\n});\n\nexport function fromNowDetailed(date: Date): {\n result: string,\n /**\n * May be Infinity if the result will never change.\n */\n secondsUntilChange: number,\n} {\n if (!(date instanceof Date)) {\n throw new Error(`fromNow only accepts Date objects (received: ${date})`);\n }\n\n const now = new Date();\n const elapsed = now.getTime() - date.getTime();\n\n let remainingInUnit = Math.abs(elapsed) / 1000;\n if (remainingInUnit < 15) {\n return {\n result: 'just now',\n secondsUntilChange: 15 - remainingInUnit,\n };\n }\n let unitInSeconds = 1;\n for (const [nextUnitSize, unitName] of agoUnits) {\n const rounded = Math.round(remainingInUnit);\n if (rounded < nextUnitSize) {\n if (elapsed < 0) {\n return {\n result: `in ${rounded} ${unitName}${rounded === 1 ? '' : 's'}`,\n secondsUntilChange: remainder((remainingInUnit - rounded + 0.5) * unitInSeconds, unitInSeconds),\n };\n } else {\n return {\n result: `${rounded} ${unitName}${rounded === 1 ? '' : 's'} ago`,\n secondsUntilChange: remainder((rounded - remainingInUnit - 0.5) * unitInSeconds, unitInSeconds),\n };\n }\n }\n unitInSeconds *= nextUnitSize;\n remainingInUnit /= nextUnitSize;\n }\n\n return {\n result: date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' }),\n secondsUntilChange: Infinity,\n };\n}\n\n/**\n * Returns a string representation of the given date in the format expected by the `datetime-local` input type.\n */\nexport function getInputDatetimeLocalString(date: Date): string {\n date = new Date(date);\n date.setMinutes(date.getMinutes() - date.getTimezoneOffset());\n return date.toISOString().slice(0, 19);\n}\n\nimport.meta.vitest?.test(\"getInputDatetimeLocalString\", ({ expect }) => {\n // Use Vitest's fake timers to ensure consistent timezone behavior\n import.meta.vitest?.vi.useFakeTimers();\n\n // Test with a specific date\n const mockDate = new Date(\"2023-01-15T12:30:45.000Z\");\n const result = getInputDatetimeLocalString(mockDate);\n\n // The result should be in the format YYYY-MM-DDTHH:MM:SS\n expect(result).toMatch(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$/);\n\n // Test with different dates\n const dates = [\n new Date(\"2023-01-01T00:00:00.000Z\"),\n new Date(\"2023-06-15T23:59:59.000Z\"),\n new Date(\"2023-12-31T12:34:56.000Z\"),\n ];\n\n for (const date of dates) {\n const result = getInputDatetimeLocalString(date);\n expect(result).toMatch(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$/);\n }\n\n // Restore real timers\n import.meta.vitest?.vi.useRealTimers();\n});\n\n\nexport type Interval = [number, 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'];\nexport type DayInterval = [number, 'day' | 'week' | 'month' | 'year'];\n\nfunction applyInterval(inputDate: Date, times: number, interval: Interval): Date {\n if (!intervalSchema.isValidSync(interval)) {\n throw new HexclaveAssertionError(`Invalid interval`, { interval });\n }\n // Operate on a copy: the Date setters below mutate in place, and callers routinely pass a date they\n // also keep a reference to (e.g. `{ currentPeriodStart: now, currentPeriodEnd: addInterval(now, ...) }`).\n // Mutating the input would alias both fields to the same advanced date, silently collapsing the period.\n const date = new Date(inputDate);\n const [amount, unit] = interval;\n switch (unit) {\n case 'millisecond': {\n date.setMilliseconds(date.getMilliseconds() + amount * times);\n break;\n }\n case 'second': {\n date.setSeconds(date.getSeconds() + amount * times);\n break;\n }\n case 'minute': {\n date.setMinutes(date.getMinutes() + amount * times);\n break;\n }\n case 'hour': {\n date.setHours(date.getHours() + amount * times);\n break;\n }\n case 'day': {\n date.setDate(date.getDate() + amount * times);\n break;\n }\n case 'week': {\n date.setDate(date.getDate() + amount * times * 7);\n break;\n }\n case 'month': {\n date.setMonth(date.getMonth() + amount * times);\n break;\n }\n case 'year': {\n date.setFullYear(date.getFullYear() + amount * times);\n break;\n }\n default: {\n throw new HexclaveAssertionError(`Invalid interval despite schema validation`, { interval });\n }\n }\n return date;\n}\n\nexport function subtractInterval(date: Date, interval: Interval): Date {\n return applyInterval(date, -1, interval);\n}\n\n// One-shot local-time interval arithmetic that OVERFLOWS (Jan 31 + 1 month -> Mar 3, via\n// Date#setMonth) rather than clamping. Use this for single-step period math where JS/Stripe overflow\n// semantics are what we want (e.g. computing a subscription's currentPeriodEnd). For recurring\n// grant/reset BOUNDARIES, use `nthDayIntervalMillis` / `getIntervalsElapsed` instead — they clamp to\n// month-end and compute in UTC from a fixed anchor, and mixing the two would drift.\nexport function addInterval(date: Date, interval: Interval): Date {\n return applyInterval(date, 1, interval);\n}\n\nimport.meta.vitest?.test(\"addInterval/subtractInterval do not mutate their input\", ({ expect }) => {\n const original = new Date('2026-07-20T00:00:00.000Z');\n const originalMillis = original.getTime();\n\n const later = addInterval(original, [1, 'month']);\n const earlier = subtractInterval(original, [1, 'month']);\n\n // The input must be untouched, and the result must be a distinct object. This guards the aliasing\n // footgun in `{ currentPeriodStart: now, currentPeriodEnd: addInterval(now, ...) }`, where mutating\n // `now` would collapse both fields to the same advanced instant (a zero-width period).\n expect(original.getTime()).toBe(originalMillis);\n expect(later).not.toBe(original);\n expect(earlier).not.toBe(original);\n expect(later).toEqual(new Date('2026-08-20T00:00:00.000Z'));\n expect(earlier).toEqual(new Date('2026-06-20T00:00:00.000Z'));\n});\n\nexport const FAR_FUTURE_DATE = new Date(8640000000000000); // 13 Sep 275760 00:00:00 UTC\n\nfunction getMsPerDayIntervalUnit(unit: 'day' | 'week'): number {\n if (unit === 'day') {\n return 24 * 60 * 60 * 1000;\n }\n return 7 * 24 * 60 * 60 * 1000;\n}\n\n\n// The number of full `repeat` intervals elapsed from `anchor` up to (and including) `to`, i.e. the\n// largest n >= 0 with the n-th boundary <= to. Boundaries are the SAME ones `nthDayIntervalMillis`\n// computes (anchor-relative, UTC, month-end clamped), so counting and boundary-computation never\n// disagree — a Jan 31 monthly anchor has elapsed one interval by Feb 28, matching the reset the\n// bulldozer item-repeat fold actually emits. (This is why it must NOT be built on `addInterval`,\n// which is local-time and overflows instead of clamping.)\nexport function getIntervalsElapsed(anchor: Date, to: Date, repeat: DayInterval): number {\n const [amount, unit] = repeat;\n const toMillis = to.getTime();\n if (toMillis <= anchor.getTime()) return 0;\n if (unit === 'day' || unit === 'week') {\n const msPerUnit = getMsPerDayIntervalUnit(unit);\n const diffMs = toMillis - anchor.getTime();\n return Math.floor(diffMs / (msPerUnit * amount));\n }\n // month/year: walk anchor-relative boundaries. The count is small in practice (bounded by the\n // number of billing periods since the anchor), so a linear walk is fine.\n let count = 0;\n while (nthDayIntervalMillis(anchor.getTime(), repeat, count + 1) <= toMillis) count += 1;\n return count;\n}\n\nimport.meta.vitest?.test(\"getIntervalsElapsed\", ({ expect }) => {\n const anchor = new Date('2025-01-01T00:00:00.000Z');\n const to = new Date('2025-01-15T00:00:00.000Z');\n expect(getIntervalsElapsed(anchor, to, [1, 'week'])).toBe(2);\n expect(getIntervalsElapsed(anchor, to, [3, 'day'])).toBe(4);\n\n // Jan 31 monthly anchor: the first boundary is clamped to Feb 28, which is <= Mar 1, so one\n // interval has elapsed (anchor-relative clamped math, consistent with nthDayIntervalMillis).\n const mAnchor = new Date('2023-01-31T00:00:00.000Z');\n const mTo = new Date('2023-03-01T00:00:00.000Z');\n expect(getIntervalsElapsed(mAnchor, mTo, [1, 'month'])).toBe(1);\n\n const yAnchor = new Date('2020-01-01T00:00:00.000Z');\n const yTo = new Date('2022-06-01T00:00:00.000Z');\n expect(getIntervalsElapsed(yAnchor, yTo, [1, 'year'])).toBe(2);\n});\n\n/**\n * The UTC millis of the `occurrence`-th (1-based) repeat of `interval` after `anchorMillis`.\n *\n * Each boundary is computed from the *original* anchor (never by stepping off the previous, possibly\n * clamped, boundary) so the anchor's day-of-month is preserved across resets: a Jan 31 anchor yields\n * Feb 28, Mar 31, Apr 30, ... (matching Stripe's billing-cycle behavior) rather than drifting to\n * Feb 28, Mar 28, ... . Month/year overflow (e.g. Jan 31 -> Feb) is clamped to the target month's\n * last day. Day/week are exact multiples (no calendar involved, so no drift possible).\n *\n * Everything is done in UTC (unlike `addInterval`, which uses local-time Date accessors) so the\n * result is deterministic regardless of the server's timezone — this is relied upon by bulldozer\n * folds, which must be reproducible across machines.\n *\n * `occurrence` 0 returns the anchor itself; `getIntervalsElapsed` counts these same boundaries, so\n * the two are always consistent for a given DayInterval.\n */\nexport function nthDayIntervalMillis(anchorMillis: number, interval: DayInterval, occurrence: number): number {\n const [count, unit] = interval;\n const totalUnits = count * occurrence;\n if (unit === 'day' || unit === 'week') {\n return anchorMillis + totalUnits * getMsPerDayIntervalUnit(unit);\n }\n const anchor = new Date(anchorMillis);\n const monthsToAdd = unit === 'year' ? totalUnits * 12 : totalUnits;\n const absoluteMonth = anchor.getUTCFullYear() * 12 + anchor.getUTCMonth() + monthsToAdd;\n const targetYear = Math.floor(absoluteMonth / 12);\n const targetMonth = absoluteMonth - targetYear * 12;\n // Day 0 of the following month is the last day of the target month, so this gives its length.\n const daysInTargetMonth = new Date(Date.UTC(targetYear, targetMonth + 1, 0)).getUTCDate();\n const clampedDay = Math.min(anchor.getUTCDate(), daysInTargetMonth);\n return Date.UTC(\n targetYear,\n targetMonth,\n clampedDay,\n anchor.getUTCHours(),\n anchor.getUTCMinutes(),\n anchor.getUTCSeconds(),\n anchor.getUTCMilliseconds(),\n );\n}\n\nimport.meta.vitest?.test(\"nthDayIntervalMillis\", ({ expect }) => {\n const at = (iso: string) => new Date(iso).getTime();\n const iso = (millis: number) => new Date(millis).toISOString();\n\n // day / week are exact multiples (no drift), and honor the count.\n const dayAnchor = at('2025-01-01T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [1, 'day'], 1))).toBe('2025-01-02T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [3, 'day'], 4))).toBe('2025-01-13T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [2, 'week'], 3))).toBe('2025-02-12T08:30:00.000Z'); // 6 weeks = 42 days after Jan 1\n\n // Jan 31 monthly: clamp in short months, restore to the anchor day in long ones.\n const jan31 = at('2025-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 1))).toBe('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 2))).toBe('2025-03-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 3))).toBe('2025-04-30T00:00:00.000Z');\n\n // Anchor-day preservation: a Feb 28 anchor stays on day 28 (never jumps to Mar 31), unlike the\n // Jan 31 anchor above which restores to Mar 31. This is the evidence we compute from the anchor.\n const feb28 = at('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb28, [1, 'month'], 1))).toBe('2025-03-28T00:00:00.000Z');\n\n // Leap-year Feb: Feb 29 anchor clamps to Feb 28 in a non-leap year and restores in the next leap year.\n const feb29 = at('2024-02-29T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb29, [1, 'year'], 1))).toBe('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb29, [1, 'year'], 4))).toBe('2028-02-29T00:00:00.000Z');\n // Jan 31 monthly landing in a leap February clamps to Feb 29, not Feb 28.\n const jan31Leap = at('2024-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31Leap, [1, 'month'], 1))).toBe('2024-02-29T00:00:00.000Z');\n\n // End-of-December rollover: absolute-month math carries the year.\n const dec31 = at('2025-12-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 1))).toBe('2026-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 2))).toBe('2026-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 3))).toBe('2026-03-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'year'], 1))).toBe('2026-12-31T00:00:00.000Z');\n\n // Time-of-day is preserved through month clamping.\n const withTime = at('2025-01-31T13:45:59.123Z');\n expect(iso(nthDayIntervalMillis(withTime, [1, 'month'], 1))).toBe('2025-02-28T13:45:59.123Z');\n});\n"],"mappings":";;;;AAIA,SAAgB,UAAU,MAAqB;CAC7C,OAAO,KAAK,OAAO,MAAM,KAAK,KAAK,OAAO,MAAM;AAClD;AAaA,MAAM,WAAW;CACf,CAAC,IAAI,QAAQ;CACb,CAAC,IAAI,QAAQ;CACb,CAAC,IAAI,MAAM;CACX,CAAC,GAAG,KAAK;CACT,CAAC,GAAG,MAAM;AACZ;AAEA,SAAgB,QAAQ,MAAoB;CAC1C,OAAO,gBAAgB,IAAI,CAAC,CAAC;AAC/B;AA+BA,SAAgB,gBAAgB,MAM9B;CACA,IAAI,EAAE,gBAAgB,OACpB,MAAM,IAAI,MAAM,gDAAgD,KAAK,EAAE;CAIzE,MAAM,2BAAU,IADA,KACE,EAAA,CAAE,QAAQ,IAAI,KAAK,QAAQ;CAE7C,IAAI,kBAAkB,KAAK,IAAI,OAAO,IAAI;CAC1C,IAAI,kBAAkB,IACpB,OAAO;EACL,QAAQ;EACR,oBAAoB,KAAK;CAC3B;CAEF,IAAI,gBAAgB;CACpB,KAAK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,SAAS,IAAI,KAAK,YAAY;CACpC,MAAM,cAAc,SAAS,SAAS,aAAa,KAAK;CACxD,MAAM,gBAAgB,OAAO,eAAe,IAAI,KAAK,OAAO,YAAY,IAAI;CAC5E,MAAM,aAAa,KAAK,MAAM,gBAAgB,EAAE;CAChD,MAAM,cAAc,gBAAgB,aAAa;CAEjD,MAAM,oBAAoB,IAAI,KAAK,KAAK,IAAI,YAAY,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW;CACxF,MAAM,aAAa,KAAK,IAAI,OAAO,WAAW,GAAG,iBAAiB;CAClE,OAAO,KAAK,IACV,YACA,aACA,YACA,OAAO,YAAY,GACnB,OAAO,cAAc,GACrB,OAAO,cAAc,GACrB,OAAO,mBAAmB,CAC5B;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as KnownErrors, n as KnownError } from "./known-errors-Bm4a61wL.js";
|
|
2
2
|
import { n as HexclaveClientInterface } from "./client-interface-BQz4jNAC.js";
|
|
3
3
|
import { t as HexclaveServerInterface } from "./server-interface-BjY-eS4Q.js";
|
|
4
|
-
import { r as HexclaveAdminInterface } from "./admin-interface-
|
|
4
|
+
import { r as HexclaveAdminInterface } from "./admin-interface-DIt0PvhC.js";
|
|
5
5
|
export { HexclaveAdminInterface, HexclaveClientInterface, HexclaveServerInterface, KnownError, KnownErrors };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as PlanUsageResponse } from "../plan-usage-
|
|
2
|
-
import { a as InternalApiKeyCreateCrudResponse, i as InternalApiKeyCreateCrudRequest, n as ChatContent, r as HexclaveAdminInterface, t as AdminAuthApplicationOptions } from "../admin-interface-
|
|
1
|
+
import { n as PlanUsageResponse } from "../plan-usage-BO2GsKlN.js";
|
|
2
|
+
import { a as InternalApiKeyCreateCrudResponse, i as InternalApiKeyCreateCrudRequest, n as ChatContent, r as HexclaveAdminInterface, t as AdminAuthApplicationOptions } from "../admin-interface-DIt0PvhC.js";
|
|
3
3
|
export { AdminAuthApplicationOptions, ChatContent, HexclaveAdminInterface, InternalApiKeyCreateCrudRequest, InternalApiKeyCreateCrudResponse, type PlanUsageResponse };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
let ___utils_results_js = require("../utils/results.js");
|
|
3
2
|
let ___utils_urls_js = require("../utils/urls.js");
|
|
3
|
+
let ___utils_results_js = require("../utils/results.js");
|
|
4
4
|
let ___known_errors_js = require("../known-errors.js");
|
|
5
5
|
let __server_interface_js = require("./server-interface.js");
|
|
6
6
|
//#region src/interface/admin-interface.ts
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let ___utils_strings_js = require("../utils/strings.js");
|
|
2
3
|
let ___utils_errors_js = require("../utils/errors.js");
|
|
4
|
+
let ___utils_urls_js = require("../utils/urls.js");
|
|
3
5
|
let ___utils_objects_js = require("../utils/objects.js");
|
|
4
|
-
let ___utils_strings_js = require("../utils/strings.js");
|
|
5
6
|
let ___utils_oauth_js = require("../utils/oauth.js");
|
|
6
7
|
let ___utils_results_js = require("../utils/results.js");
|
|
7
|
-
let ___utils_urls_js = require("../utils/urls.js");
|
|
8
8
|
let ___known_errors_js = require("../known-errors.js");
|
|
9
9
|
let ___sessions_js = require("../sessions.js");
|
|
10
10
|
let ___utils_crypto_js = require("../utils/crypto.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as emailOutboxUpdateSchema, n as emailOutboxCrud, r as emailOutboxReadSchema, t as EmailOutboxCrud } from "../../email-outbox-
|
|
1
|
+
import { i as emailOutboxUpdateSchema, n as emailOutboxCrud, r as emailOutboxReadSchema, t as EmailOutboxCrud } from "../../email-outbox-CqzwInBL.js";
|
|
2
2
|
export { EmailOutboxCrud, emailOutboxCrud, emailOutboxReadSchema, emailOutboxUpdateSchema };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as planUsageResponseSchema, i as planUsageKindSchema, n as PlanUsageResponse, o as planUsageRowSchema, r as PlanUsageRow, t as PlanUsageKind } from "../plan-usage-
|
|
1
|
+
import { a as planUsageResponseSchema, i as planUsageKindSchema, n as PlanUsageResponse, o as planUsageRowSchema, r as PlanUsageRow, t as PlanUsageKind } from "../plan-usage-BO2GsKlN.js";
|
|
2
2
|
export { PlanUsageKind, PlanUsageResponse, PlanUsageRow, planUsageKindSchema, planUsageResponseSchema, planUsageRowSchema };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let ___utils_errors_js = require("../utils/errors.js");
|
|
3
|
+
let ___utils_urls_js = require("../utils/urls.js");
|
|
3
4
|
let ___utils_objects_js = require("../utils/objects.js");
|
|
4
5
|
let ___utils_results_js = require("../utils/results.js");
|
|
5
|
-
let ___utils_urls_js = require("../utils/urls.js");
|
|
6
6
|
let ___known_errors_js = require("../known-errors.js");
|
|
7
7
|
let ___sessions_js = require("../sessions.js");
|
|
8
8
|
let __client_interface_js = require("./client-interface.js");
|
|
@@ -24,7 +24,7 @@ declare const planUsageRowSchema: yup$1.ObjectSchema<{
|
|
|
24
24
|
declare const planUsageResponseSchema: yup$1.ObjectSchema<{
|
|
25
25
|
owner_team_id: string;
|
|
26
26
|
owner_team_display_name: string;
|
|
27
|
-
plan_id: "
|
|
27
|
+
plan_id: "free" | "team" | "growth";
|
|
28
28
|
plan_display_name: string;
|
|
29
29
|
period_start_millis: number;
|
|
30
30
|
period_end_millis: number;
|
|
@@ -56,4 +56,4 @@ type PlanUsageRow = yup$1.InferType<typeof planUsageRowSchema>;
|
|
|
56
56
|
type PlanUsageResponse = yup$1.InferType<typeof planUsageResponseSchema>;
|
|
57
57
|
//#endregion
|
|
58
58
|
export { planUsageResponseSchema as a, planUsageKindSchema as i, PlanUsageResponse as n, planUsageRowSchema as o, PlanUsageRow as r, PlanUsageKind as t };
|
|
59
|
-
//# sourceMappingURL=plan-usage-
|
|
59
|
+
//# sourceMappingURL=plan-usage-BO2GsKlN.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-usage-
|
|
1
|
+
{"version":3,"file":"plan-usage-BO2GsKlN.d.ts","names":[],"sources":["../src/interface/plan-usage.ts"],"mappings":";;;cAOa,mBAAA,EAAmB,KAAA,CAAA,YAAA,uCAAA,KAAA,CAAA,SAAA;AAAA,cAEnB,kBAAA,EAAkB,KAAA,CAAA,YAAA;;;;;;;;;GASnB,KAAA,CAAA,SAAA;;;;;;;;;;cAEC,uBAAA,EAAuB,KAAA,CAAA,YAAA;;;;;;;;;;;;;;;;;;;GAUxB,KAAA,CAAA,SAAA;;;;;;;;;;;KAEA,aAAA,GAAgB,KAAA,CAAI,SAAS,QAAQ,mBAAA;AAAA,KACrC,YAAA,GAAe,KAAA,CAAI,SAAS,QAAQ,kBAAA;AAAA,KACpC,iBAAA,GAAoB,KAAA,CAAI,SAAS,QAAQ,uBAAA"}
|
|
@@ -84,7 +84,7 @@ declare const branchConfigSchema: yup$1.Schema<Omit<Omit<{
|
|
|
84
84
|
sourceOfTruth: {
|
|
85
85
|
type: "hosted";
|
|
86
86
|
};
|
|
87
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
87
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
88
88
|
payments?: {
|
|
89
89
|
blockNewPurchases?: boolean | undefined;
|
|
90
90
|
autoPay?: {
|
|
@@ -187,9 +187,6 @@ declare const branchConfigSchema: yup$1.Schema<Omit<Omit<{
|
|
|
187
187
|
tsxSource: string;
|
|
188
188
|
}>;
|
|
189
189
|
};
|
|
190
|
-
users: {
|
|
191
|
-
allowClientUserDeletion?: boolean | undefined;
|
|
192
|
-
};
|
|
193
190
|
apiKeys: {
|
|
194
191
|
enabled: {
|
|
195
192
|
team?: boolean | undefined;
|
|
@@ -202,6 +199,9 @@ declare const branchConfigSchema: yup$1.Schema<Omit<Omit<{
|
|
|
202
199
|
}>;
|
|
203
200
|
};
|
|
204
201
|
domains: {};
|
|
202
|
+
users: {
|
|
203
|
+
allowClientUserDeletion?: boolean | undefined;
|
|
204
|
+
};
|
|
205
205
|
dataVault: {
|
|
206
206
|
stores: Record<string, {
|
|
207
207
|
displayName?: string | undefined;
|
|
@@ -212,7 +212,7 @@ declare const branchConfigSchema: yup$1.Schema<Omit<Omit<{
|
|
|
212
212
|
project: {
|
|
213
213
|
requirePublishableClientKey: undefined;
|
|
214
214
|
};
|
|
215
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
215
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
216
216
|
rbac: {
|
|
217
217
|
permissions: undefined;
|
|
218
218
|
defaultPermissions: {
|
|
@@ -284,7 +284,7 @@ declare const environmentConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<Omit<{
|
|
|
284
284
|
sourceOfTruth: {
|
|
285
285
|
type: "hosted";
|
|
286
286
|
};
|
|
287
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
287
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
288
288
|
payments?: {
|
|
289
289
|
blockNewPurchases?: boolean | undefined;
|
|
290
290
|
autoPay?: {
|
|
@@ -387,9 +387,6 @@ declare const environmentConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<Omit<{
|
|
|
387
387
|
tsxSource: string;
|
|
388
388
|
}>;
|
|
389
389
|
};
|
|
390
|
-
users: {
|
|
391
|
-
allowClientUserDeletion?: boolean | undefined;
|
|
392
|
-
};
|
|
393
390
|
apiKeys: {
|
|
394
391
|
enabled: {
|
|
395
392
|
team?: boolean | undefined;
|
|
@@ -402,6 +399,9 @@ declare const environmentConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<Omit<{
|
|
|
402
399
|
}>;
|
|
403
400
|
};
|
|
404
401
|
domains: {};
|
|
402
|
+
users: {
|
|
403
|
+
allowClientUserDeletion?: boolean | undefined;
|
|
404
|
+
};
|
|
405
405
|
dataVault: {
|
|
406
406
|
stores: Record<string, {
|
|
407
407
|
displayName?: string | undefined;
|
|
@@ -566,7 +566,7 @@ declare const environmentConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<Omit<{
|
|
|
566
566
|
project: {
|
|
567
567
|
requirePublishableClientKey: undefined;
|
|
568
568
|
};
|
|
569
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
569
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
570
570
|
rbac: {
|
|
571
571
|
permissions: undefined;
|
|
572
572
|
defaultPermissions: {
|
|
@@ -636,7 +636,7 @@ declare const environmentConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<Omit<{
|
|
|
636
636
|
project: {
|
|
637
637
|
requirePublishableClientKey: undefined;
|
|
638
638
|
};
|
|
639
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
639
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
640
640
|
rbac: {
|
|
641
641
|
permissions: undefined;
|
|
642
642
|
defaultPermissions: {
|
|
@@ -706,7 +706,7 @@ declare const environmentConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<Omit<{
|
|
|
706
706
|
project: {
|
|
707
707
|
requirePublishableClientKey: undefined;
|
|
708
708
|
};
|
|
709
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
709
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
710
710
|
rbac: {
|
|
711
711
|
permissions: undefined;
|
|
712
712
|
defaultPermissions: {
|
|
@@ -779,7 +779,7 @@ declare const environmentConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<Omit<{
|
|
|
779
779
|
project: {
|
|
780
780
|
requirePublishableClientKey: undefined;
|
|
781
781
|
};
|
|
782
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
782
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
783
783
|
rbac: {
|
|
784
784
|
permissions: undefined;
|
|
785
785
|
defaultPermissions: {
|
|
@@ -862,7 +862,7 @@ declare const environmentConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<Omit<{
|
|
|
862
862
|
project: {
|
|
863
863
|
requirePublishableClientKey: undefined;
|
|
864
864
|
};
|
|
865
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
865
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
866
866
|
rbac: {
|
|
867
867
|
permissions: undefined;
|
|
868
868
|
defaultPermissions: {
|
|
@@ -935,7 +935,7 @@ declare const environmentConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<Omit<{
|
|
|
935
935
|
project: {
|
|
936
936
|
requirePublishableClientKey: undefined;
|
|
937
937
|
};
|
|
938
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
938
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
939
939
|
rbac: {
|
|
940
940
|
permissions: undefined;
|
|
941
941
|
defaultPermissions: {
|
|
@@ -1017,7 +1017,7 @@ declare const organizationConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<NonNu
|
|
|
1017
1017
|
sourceOfTruth: {
|
|
1018
1018
|
type: "hosted";
|
|
1019
1019
|
};
|
|
1020
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
1020
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
1021
1021
|
payments?: {
|
|
1022
1022
|
blockNewPurchases?: boolean | undefined;
|
|
1023
1023
|
autoPay?: {
|
|
@@ -1120,9 +1120,6 @@ declare const organizationConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<NonNu
|
|
|
1120
1120
|
tsxSource: string;
|
|
1121
1121
|
}>;
|
|
1122
1122
|
};
|
|
1123
|
-
users: {
|
|
1124
|
-
allowClientUserDeletion?: boolean | undefined;
|
|
1125
|
-
};
|
|
1126
1123
|
apiKeys: {
|
|
1127
1124
|
enabled: {
|
|
1128
1125
|
team?: boolean | undefined;
|
|
@@ -1135,6 +1132,9 @@ declare const organizationConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<NonNu
|
|
|
1135
1132
|
}>;
|
|
1136
1133
|
};
|
|
1137
1134
|
domains: {};
|
|
1135
|
+
users: {
|
|
1136
|
+
allowClientUserDeletion?: boolean | undefined;
|
|
1137
|
+
};
|
|
1138
1138
|
dataVault: {
|
|
1139
1139
|
stores: Record<string, {
|
|
1140
1140
|
displayName?: string | undefined;
|
|
@@ -1299,7 +1299,7 @@ declare const organizationConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<NonNu
|
|
|
1299
1299
|
project: {
|
|
1300
1300
|
requirePublishableClientKey: undefined;
|
|
1301
1301
|
};
|
|
1302
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
1302
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
1303
1303
|
rbac: {
|
|
1304
1304
|
permissions: undefined;
|
|
1305
1305
|
defaultPermissions: {
|
|
@@ -1369,7 +1369,7 @@ declare const organizationConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<NonNu
|
|
|
1369
1369
|
project: {
|
|
1370
1370
|
requirePublishableClientKey: undefined;
|
|
1371
1371
|
};
|
|
1372
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
1372
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
1373
1373
|
rbac: {
|
|
1374
1374
|
permissions: undefined;
|
|
1375
1375
|
defaultPermissions: {
|
|
@@ -1439,7 +1439,7 @@ declare const organizationConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<NonNu
|
|
|
1439
1439
|
project: {
|
|
1440
1440
|
requirePublishableClientKey: undefined;
|
|
1441
1441
|
};
|
|
1442
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
1442
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
1443
1443
|
rbac: {
|
|
1444
1444
|
permissions: undefined;
|
|
1445
1445
|
defaultPermissions: {
|
|
@@ -1512,7 +1512,7 @@ declare const organizationConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<NonNu
|
|
|
1512
1512
|
project: {
|
|
1513
1513
|
requirePublishableClientKey: undefined;
|
|
1514
1514
|
};
|
|
1515
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
1515
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
1516
1516
|
rbac: {
|
|
1517
1517
|
permissions: undefined;
|
|
1518
1518
|
defaultPermissions: {
|
|
@@ -1595,7 +1595,7 @@ declare const organizationConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<NonNu
|
|
|
1595
1595
|
project: {
|
|
1596
1596
|
requirePublishableClientKey: undefined;
|
|
1597
1597
|
};
|
|
1598
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
1598
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
1599
1599
|
rbac: {
|
|
1600
1600
|
permissions: undefined;
|
|
1601
1601
|
defaultPermissions: {
|
|
@@ -1668,7 +1668,7 @@ declare const organizationConfigSchema: yup$1.Schema<Omit<NonNullable<Omit<NonNu
|
|
|
1668
1668
|
project: {
|
|
1669
1669
|
requirePublishableClientKey: undefined;
|
|
1670
1670
|
};
|
|
1671
|
-
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "
|
|
1671
|
+
}, string>, "auth" | "onboarding" | "teams" | "rbac" | "payments" | "emails" | "apiKeys" | "apps" | "domains" | "users" | "dataVault"> & {
|
|
1672
1672
|
rbac: {
|
|
1673
1673
|
permissions: undefined;
|
|
1674
1674
|
defaultPermissions: {
|
|
@@ -2188,9 +2188,6 @@ declare function sanitizeOrganizationConfig(config: OrganizationRenderedConfigBe
|
|
|
2188
2188
|
};
|
|
2189
2189
|
};
|
|
2190
2190
|
};
|
|
2191
|
-
users: {
|
|
2192
|
-
allowClientUserDeletion: boolean;
|
|
2193
|
-
};
|
|
2194
2191
|
apiKeys: {
|
|
2195
2192
|
enabled: {
|
|
2196
2193
|
team: boolean;
|
|
@@ -2206,6 +2203,9 @@ declare function sanitizeOrganizationConfig(config: OrganizationRenderedConfigBe
|
|
|
2206
2203
|
};
|
|
2207
2204
|
};
|
|
2208
2205
|
};
|
|
2206
|
+
users: {
|
|
2207
|
+
allowClientUserDeletion: boolean;
|
|
2208
|
+
};
|
|
2209
2209
|
dataVault: {
|
|
2210
2210
|
stores: {
|
|
2211
2211
|
[x: string]: {
|
|
@@ -2286,4 +2286,4 @@ type OrganizationRenderedConfig = Expand<Awaited<ReturnType<typeof sanitizeOrgan
|
|
|
2286
2286
|
type CompleteConfig = OrganizationRenderedConfig;
|
|
2287
2287
|
//#endregion
|
|
2288
2288
|
export { branchConfigSchema as A, sanitizeEnvironmentConfig as B, ValidatedToHaveNoConfigOverrideErrors as C, applyOrganizationDefaults as D, applyEnvironmentDefaults as E, getIncompleteConfigWarnings as F, sanitizeProjectConfig as H, migrateConfigOverride as I, organizationConfigSchema as L, configLevels as M, environmentConfigSchema as N, applyProjectDefaults as O, getConfigOverrideErrors as P, projectConfigSchema as R, ProjectRenderedConfig as S, applyBranchDefaults as T, sanitizeOrganizationConfig as V, OrganizationRenderedConfig as _, BranchRenderedConfig as a, ProjectConfigOverrideOverride as b, EnvironmentConfigNormalizedOverride as c, EnvironmentIncompleteConfig as d, EnvironmentRenderedConfig as f, OrganizationIncompleteConfig as g, OrganizationConfigOverrideOverride as h, BranchIncompleteConfig as i, branchPaymentsSchema as j, assertNoConfigOverrideErrors as k, EnvironmentConfigOverride as l, OrganizationConfigOverride as m, BranchConfigOverride as n, CompleteConfig as o, OrganizationConfigNormalizedOverride as p, BranchConfigOverrideOverride as r, ConfigLevel as s, BranchConfigNormalizedOverride as t, EnvironmentConfigOverrideOverride as u, ProjectConfigNormalizedOverride as v, ValidatedToHaveNoIncompleteConfigWarnings as w, ProjectIncompleteConfig as x, ProjectConfigOverride as y, sanitizeBranchConfig as z };
|
|
2289
|
-
//# sourceMappingURL=schema-
|
|
2289
|
+
//# sourceMappingURL=schema-CLmaZetm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-
|
|
1
|
+
{"version":3,"file":"schema-CLmaZetm.d.ts","names":[],"sources":["../src/config/schema.ts"],"mappings":";;;;;;;;cAqBa,YAAA;AAA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BAAA,SACA,mCAAA,SACA,oCAAA;AAAA,KAEL,kCAAA,GAAqC,IAAA,CAAK,sBAAA,QACrC,mCAAA,SACA,oCAAA;AAAA,KAEL,uCAAA,GAA0C,IAAA,CAAK,2BAAA,QAC1C,oCAAA;AAAA,KAEL,wCAAA,GAA2C,4BAA4B;AAAA,KAIvE,uCAAA,GAA0C,MAAA,CAAO,OAAA,CAAQ,UAAA,QAAkB,oBAAA,CAAqB,mCAAA;AAAA,KAChG,sCAAA,GAAyC,MAAA,CAAO,OAAA,CAAQ,UAAA,QAAkB,mBAAA,CAAoB,kCAAA;AAAA,KAC9F,2CAAA,GAA8C,MAAA,CAAO,OAAA,CAAQ,UAAA,QAAkB,wBAAA,CAAyB,uCAAA;AAAA,KACxG,4CAAA,GAA+C,MAAA,CAAO,OAAA,CAAQ,UAAA,QAAkB,yBAAA;AAAA,KAGzE,qBAAA,GAAwB,MAAA,CAAO,OAAA,CAAQ,UAAA,QAAkB,qBAAA,CAAsB,uCAAA;AAAA,KAC/E,oBAAA,GAAuB,MAAA,CAAO,OAAA,CAAQ,UAAA,QAAkB,oBAAA,CAAqB,sCAAA;AAAA,KAC7E,yBAAA,GAA4B,MAAA,CAAO,OAAA,CAAQ,UAAA,QAAkB,yBAAA,CAA0B,2CAAA;AAAA,KACvF,0BAAA,GAA6B,MAAA,CAAO,OAAA,CAAQ,UAAA,QAAkB,0BAAA;AAAA,KAG9D,cAAA,GAAiB,0BAA0B"}
|
package/dist/utils/dates.js
CHANGED
|
@@ -55,8 +55,9 @@ function getInputDatetimeLocalString(date) {
|
|
|
55
55
|
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
|
|
56
56
|
return date.toISOString().slice(0, 19);
|
|
57
57
|
}
|
|
58
|
-
function applyInterval(
|
|
58
|
+
function applyInterval(inputDate, times, interval) {
|
|
59
59
|
if (!___schema_fields_js.intervalSchema.isValidSync(interval)) throw new __errors_js.HexclaveAssertionError(`Invalid interval`, { interval });
|
|
60
|
+
const date = new Date(inputDate);
|
|
60
61
|
const [amount, unit] = interval;
|
|
61
62
|
switch (unit) {
|
|
62
63
|
case "millisecond":
|
package/dist/utils/dates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dates.js","names":["intervalSchema","HexclaveAssertionError"],"sources":["../../src/utils/dates.tsx"],"sourcesContent":["import { intervalSchema } from \"../schema-fields\";\nimport { HexclaveAssertionError } from \"./errors\";\nimport { remainder } from \"./math\";\n\nexport function isWeekend(date: Date): boolean {\n return date.getDay() === 0 || date.getDay() === 6;\n}\n\nimport.meta.vitest?.test(\"isWeekend\", ({ expect }) => {\n // Sunday (day 0)\n expect(isWeekend(new Date(2023, 0, 1))).toBe(true);\n // Saturday (day 6)\n expect(isWeekend(new Date(2023, 0, 7))).toBe(true);\n // Monday (day 1)\n expect(isWeekend(new Date(2023, 0, 2))).toBe(false);\n // Friday (day 5)\n expect(isWeekend(new Date(2023, 0, 6))).toBe(false);\n});\n\nconst agoUnits = [\n [60, 'second'],\n [60, 'minute'],\n [24, 'hour'],\n [7, 'day'],\n [5, 'week'],\n] as const;\n\nexport function fromNow(date: Date): string {\n return fromNowDetailed(date).result;\n}\n\nimport.meta.vitest?.test(\"fromNow\", ({ expect }) => {\n // Set a fixed date for testing\n const fixedDate = new Date(\"2023-01-15T12:00:00.000Z\");\n\n // Use Vitest's fake timers\n import.meta.vitest?.vi.useFakeTimers();\n import.meta.vitest?.vi.setSystemTime(fixedDate);\n\n // Test past times\n expect(fromNow(new Date(\"2023-01-15T11:59:50.000Z\"))).toBe(\"just now\");\n expect(fromNow(new Date(\"2023-01-15T11:59:00.000Z\"))).toBe(\"1 minute ago\");\n expect(fromNow(new Date(\"2023-01-15T11:00:00.000Z\"))).toBe(\"1 hour ago\");\n expect(fromNow(new Date(\"2023-01-14T12:00:00.000Z\"))).toBe(\"1 day ago\");\n expect(fromNow(new Date(\"2023-01-08T12:00:00.000Z\"))).toBe(\"1 week ago\");\n\n // Test future times\n expect(fromNow(new Date(\"2023-01-15T12:00:10.000Z\"))).toBe(\"just now\");\n expect(fromNow(new Date(\"2023-01-15T12:01:00.000Z\"))).toBe(\"in 1 minute\");\n expect(fromNow(new Date(\"2023-01-15T13:00:00.000Z\"))).toBe(\"in 1 hour\");\n expect(fromNow(new Date(\"2023-01-16T12:00:00.000Z\"))).toBe(\"in 1 day\");\n expect(fromNow(new Date(\"2023-01-22T12:00:00.000Z\"))).toBe(\"in 1 week\");\n\n // Test very old dates (should use date format)\n expect(fromNow(new Date(\"2022-01-15T12:00:00.000Z\"))).toMatch(/Jan 15, 2022/);\n\n // Restore real timers\n import.meta.vitest?.vi.useRealTimers();\n});\n\nexport function fromNowDetailed(date: Date): {\n result: string,\n /**\n * May be Infinity if the result will never change.\n */\n secondsUntilChange: number,\n} {\n if (!(date instanceof Date)) {\n throw new Error(`fromNow only accepts Date objects (received: ${date})`);\n }\n\n const now = new Date();\n const elapsed = now.getTime() - date.getTime();\n\n let remainingInUnit = Math.abs(elapsed) / 1000;\n if (remainingInUnit < 15) {\n return {\n result: 'just now',\n secondsUntilChange: 15 - remainingInUnit,\n };\n }\n let unitInSeconds = 1;\n for (const [nextUnitSize, unitName] of agoUnits) {\n const rounded = Math.round(remainingInUnit);\n if (rounded < nextUnitSize) {\n if (elapsed < 0) {\n return {\n result: `in ${rounded} ${unitName}${rounded === 1 ? '' : 's'}`,\n secondsUntilChange: remainder((remainingInUnit - rounded + 0.5) * unitInSeconds, unitInSeconds),\n };\n } else {\n return {\n result: `${rounded} ${unitName}${rounded === 1 ? '' : 's'} ago`,\n secondsUntilChange: remainder((rounded - remainingInUnit - 0.5) * unitInSeconds, unitInSeconds),\n };\n }\n }\n unitInSeconds *= nextUnitSize;\n remainingInUnit /= nextUnitSize;\n }\n\n return {\n result: date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' }),\n secondsUntilChange: Infinity,\n };\n}\n\n/**\n * Returns a string representation of the given date in the format expected by the `datetime-local` input type.\n */\nexport function getInputDatetimeLocalString(date: Date): string {\n date = new Date(date);\n date.setMinutes(date.getMinutes() - date.getTimezoneOffset());\n return date.toISOString().slice(0, 19);\n}\n\nimport.meta.vitest?.test(\"getInputDatetimeLocalString\", ({ expect }) => {\n // Use Vitest's fake timers to ensure consistent timezone behavior\n import.meta.vitest?.vi.useFakeTimers();\n\n // Test with a specific date\n const mockDate = new Date(\"2023-01-15T12:30:45.000Z\");\n const result = getInputDatetimeLocalString(mockDate);\n\n // The result should be in the format YYYY-MM-DDTHH:MM:SS\n expect(result).toMatch(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$/);\n\n // Test with different dates\n const dates = [\n new Date(\"2023-01-01T00:00:00.000Z\"),\n new Date(\"2023-06-15T23:59:59.000Z\"),\n new Date(\"2023-12-31T12:34:56.000Z\"),\n ];\n\n for (const date of dates) {\n const result = getInputDatetimeLocalString(date);\n expect(result).toMatch(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$/);\n }\n\n // Restore real timers\n import.meta.vitest?.vi.useRealTimers();\n});\n\n\nexport type Interval = [number, 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'];\nexport type DayInterval = [number, 'day' | 'week' | 'month' | 'year'];\n\nfunction applyInterval(date: Date, times: number, interval: Interval): Date {\n if (!intervalSchema.isValidSync(interval)) {\n throw new HexclaveAssertionError(`Invalid interval`, { interval });\n }\n const [amount, unit] = interval;\n switch (unit) {\n case 'millisecond': {\n date.setMilliseconds(date.getMilliseconds() + amount * times);\n break;\n }\n case 'second': {\n date.setSeconds(date.getSeconds() + amount * times);\n break;\n }\n case 'minute': {\n date.setMinutes(date.getMinutes() + amount * times);\n break;\n }\n case 'hour': {\n date.setHours(date.getHours() + amount * times);\n break;\n }\n case 'day': {\n date.setDate(date.getDate() + amount * times);\n break;\n }\n case 'week': {\n date.setDate(date.getDate() + amount * times * 7);\n break;\n }\n case 'month': {\n date.setMonth(date.getMonth() + amount * times);\n break;\n }\n case 'year': {\n date.setFullYear(date.getFullYear() + amount * times);\n break;\n }\n default: {\n throw new HexclaveAssertionError(`Invalid interval despite schema validation`, { interval });\n }\n }\n return date;\n}\n\nexport function subtractInterval(date: Date, interval: Interval): Date {\n return applyInterval(date, -1, interval);\n}\n\n// One-shot local-time interval arithmetic that OVERFLOWS (Jan 31 + 1 month -> Mar 3, via\n// Date#setMonth) rather than clamping. Use this for single-step period math where JS/Stripe overflow\n// semantics are what we want (e.g. computing a subscription's currentPeriodEnd). For recurring\n// grant/reset BOUNDARIES, use `nthDayIntervalMillis` / `getIntervalsElapsed` instead — they clamp to\n// month-end and compute in UTC from a fixed anchor, and mixing the two would drift.\nexport function addInterval(date: Date, interval: Interval): Date {\n return applyInterval(date, 1, interval);\n}\n\nexport const FAR_FUTURE_DATE = new Date(8640000000000000); // 13 Sep 275760 00:00:00 UTC\n\nfunction getMsPerDayIntervalUnit(unit: 'day' | 'week'): number {\n if (unit === 'day') {\n return 24 * 60 * 60 * 1000;\n }\n return 7 * 24 * 60 * 60 * 1000;\n}\n\n\n// The number of full `repeat` intervals elapsed from `anchor` up to (and including) `to`, i.e. the\n// largest n >= 0 with the n-th boundary <= to. Boundaries are the SAME ones `nthDayIntervalMillis`\n// computes (anchor-relative, UTC, month-end clamped), so counting and boundary-computation never\n// disagree — a Jan 31 monthly anchor has elapsed one interval by Feb 28, matching the reset the\n// bulldozer item-repeat fold actually emits. (This is why it must NOT be built on `addInterval`,\n// which is local-time and overflows instead of clamping.)\nexport function getIntervalsElapsed(anchor: Date, to: Date, repeat: DayInterval): number {\n const [amount, unit] = repeat;\n const toMillis = to.getTime();\n if (toMillis <= anchor.getTime()) return 0;\n if (unit === 'day' || unit === 'week') {\n const msPerUnit = getMsPerDayIntervalUnit(unit);\n const diffMs = toMillis - anchor.getTime();\n return Math.floor(diffMs / (msPerUnit * amount));\n }\n // month/year: walk anchor-relative boundaries. The count is small in practice (bounded by the\n // number of billing periods since the anchor), so a linear walk is fine.\n let count = 0;\n while (nthDayIntervalMillis(anchor.getTime(), repeat, count + 1) <= toMillis) count += 1;\n return count;\n}\n\nimport.meta.vitest?.test(\"getIntervalsElapsed\", ({ expect }) => {\n const anchor = new Date('2025-01-01T00:00:00.000Z');\n const to = new Date('2025-01-15T00:00:00.000Z');\n expect(getIntervalsElapsed(anchor, to, [1, 'week'])).toBe(2);\n expect(getIntervalsElapsed(anchor, to, [3, 'day'])).toBe(4);\n\n // Jan 31 monthly anchor: the first boundary is clamped to Feb 28, which is <= Mar 1, so one\n // interval has elapsed (anchor-relative clamped math, consistent with nthDayIntervalMillis).\n const mAnchor = new Date('2023-01-31T00:00:00.000Z');\n const mTo = new Date('2023-03-01T00:00:00.000Z');\n expect(getIntervalsElapsed(mAnchor, mTo, [1, 'month'])).toBe(1);\n\n const yAnchor = new Date('2020-01-01T00:00:00.000Z');\n const yTo = new Date('2022-06-01T00:00:00.000Z');\n expect(getIntervalsElapsed(yAnchor, yTo, [1, 'year'])).toBe(2);\n});\n\n/**\n * The UTC millis of the `occurrence`-th (1-based) repeat of `interval` after `anchorMillis`.\n *\n * Each boundary is computed from the *original* anchor (never by stepping off the previous, possibly\n * clamped, boundary) so the anchor's day-of-month is preserved across resets: a Jan 31 anchor yields\n * Feb 28, Mar 31, Apr 30, ... (matching Stripe's billing-cycle behavior) rather than drifting to\n * Feb 28, Mar 28, ... . Month/year overflow (e.g. Jan 31 -> Feb) is clamped to the target month's\n * last day. Day/week are exact multiples (no calendar involved, so no drift possible).\n *\n * Everything is done in UTC (unlike `addInterval`, which uses local-time Date accessors) so the\n * result is deterministic regardless of the server's timezone — this is relied upon by bulldozer\n * folds, which must be reproducible across machines.\n *\n * `occurrence` 0 returns the anchor itself; `getIntervalsElapsed` counts these same boundaries, so\n * the two are always consistent for a given DayInterval.\n */\nexport function nthDayIntervalMillis(anchorMillis: number, interval: DayInterval, occurrence: number): number {\n const [count, unit] = interval;\n const totalUnits = count * occurrence;\n if (unit === 'day' || unit === 'week') {\n return anchorMillis + totalUnits * getMsPerDayIntervalUnit(unit);\n }\n const anchor = new Date(anchorMillis);\n const monthsToAdd = unit === 'year' ? totalUnits * 12 : totalUnits;\n const absoluteMonth = anchor.getUTCFullYear() * 12 + anchor.getUTCMonth() + monthsToAdd;\n const targetYear = Math.floor(absoluteMonth / 12);\n const targetMonth = absoluteMonth - targetYear * 12;\n // Day 0 of the following month is the last day of the target month, so this gives its length.\n const daysInTargetMonth = new Date(Date.UTC(targetYear, targetMonth + 1, 0)).getUTCDate();\n const clampedDay = Math.min(anchor.getUTCDate(), daysInTargetMonth);\n return Date.UTC(\n targetYear,\n targetMonth,\n clampedDay,\n anchor.getUTCHours(),\n anchor.getUTCMinutes(),\n anchor.getUTCSeconds(),\n anchor.getUTCMilliseconds(),\n );\n}\n\nimport.meta.vitest?.test(\"nthDayIntervalMillis\", ({ expect }) => {\n const at = (iso: string) => new Date(iso).getTime();\n const iso = (millis: number) => new Date(millis).toISOString();\n\n // day / week are exact multiples (no drift), and honor the count.\n const dayAnchor = at('2025-01-01T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [1, 'day'], 1))).toBe('2025-01-02T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [3, 'day'], 4))).toBe('2025-01-13T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [2, 'week'], 3))).toBe('2025-02-12T08:30:00.000Z'); // 6 weeks = 42 days after Jan 1\n\n // Jan 31 monthly: clamp in short months, restore to the anchor day in long ones.\n const jan31 = at('2025-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 1))).toBe('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 2))).toBe('2025-03-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 3))).toBe('2025-04-30T00:00:00.000Z');\n\n // Anchor-day preservation: a Feb 28 anchor stays on day 28 (never jumps to Mar 31), unlike the\n // Jan 31 anchor above which restores to Mar 31. This is the evidence we compute from the anchor.\n const feb28 = at('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb28, [1, 'month'], 1))).toBe('2025-03-28T00:00:00.000Z');\n\n // Leap-year Feb: Feb 29 anchor clamps to Feb 28 in a non-leap year and restores in the next leap year.\n const feb29 = at('2024-02-29T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb29, [1, 'year'], 1))).toBe('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb29, [1, 'year'], 4))).toBe('2028-02-29T00:00:00.000Z');\n // Jan 31 monthly landing in a leap February clamps to Feb 29, not Feb 28.\n const jan31Leap = at('2024-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31Leap, [1, 'month'], 1))).toBe('2024-02-29T00:00:00.000Z');\n\n // End-of-December rollover: absolute-month math carries the year.\n const dec31 = at('2025-12-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 1))).toBe('2026-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 2))).toBe('2026-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 3))).toBe('2026-03-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'year'], 1))).toBe('2026-12-31T00:00:00.000Z');\n\n // Time-of-day is preserved through month clamping.\n const withTime = at('2025-01-31T13:45:59.123Z');\n expect(iso(nthDayIntervalMillis(withTime, [1, 'month'], 1))).toBe('2025-02-28T13:45:59.123Z');\n});\n"],"mappings":";;;;;AAIA,SAAgB,UAAU,MAAqB;CAC7C,OAAO,KAAK,OAAO,MAAM,KAAK,KAAK,OAAO,MAAM;AAClD;AAaA,MAAM,WAAW;CACf,CAAC,IAAI,QAAQ;CACb,CAAC,IAAI,QAAQ;CACb,CAAC,IAAI,MAAM;CACX,CAAC,GAAG,KAAK;CACT,CA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rC,MAAM,YAAY,wBAAwB,IAAI;EAC9C,MAAM,SAAS,WAAW,OAAO,QAAQ;EACzC,OAAO,KAAK,MAAM,UAAU,YAAY,OAAO;CACjD;CAGA,IAAI,QAAQ;CACZ,OAAO,qBAAqB,OAAO,QAAQ,GAAG,QAAQ,QAAQ,CAAC,KAAK,UAAU,SAAS;CACvF,OAAO;AACT;;;;;;;;;;;;;;;;;AAmCA,SAAgB,qBAAqB,cAAsB,UAAuB,YAA4B;CAC5G,MAAM,CAAC,OAAO,QAAQ;CACtB,MAAM,aAAa,QAAQ;CAC3B,IAAI,SAAS,SAAS,SAAS,QAC7B,OAAO,eAAe,aAAa,wBAAwB,IAAI;CAEjE,MAAM,SAAS,IAAI,KAAK,YAAY;CACpC,MAAM,cAAc,SAAS,SAAS,aAAa,KAAK;CACxD,MAAM,gBAAgB,OAAO,eAAe,IAAI,KAAK,OAAO,YAAY,IAAI;CAC5E,MAAM,aAAa,KAAK,MAAM,gBAAgB,EAAE;CAChD,MAAM,cAAc,gBAAgB,aAAa;CAEjD,MAAM,oBAAoB,IAAI,KAAK,KAAK,IAAI,YAAY,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW;CACxF,MAAM,aAAa,KAAK,IAAI,OAAO,WAAW,GAAG,iBAAiB;CAClE,OAAO,KAAK,IACV,YACA,aACA,YACA,OAAO,YAAY,GACnB,OAAO,cAAc,GACrB,OAAO,cAAc,GACrB,OAAO,mBAAmB,CAC5B;AACF"}
|
|
1
|
+
{"version":3,"file":"dates.js","names":["intervalSchema","HexclaveAssertionError"],"sources":["../../src/utils/dates.tsx"],"sourcesContent":["import { intervalSchema } from \"../schema-fields\";\nimport { HexclaveAssertionError } from \"./errors\";\nimport { remainder } from \"./math\";\n\nexport function isWeekend(date: Date): boolean {\n return date.getDay() === 0 || date.getDay() === 6;\n}\n\nimport.meta.vitest?.test(\"isWeekend\", ({ expect }) => {\n // Sunday (day 0)\n expect(isWeekend(new Date(2023, 0, 1))).toBe(true);\n // Saturday (day 6)\n expect(isWeekend(new Date(2023, 0, 7))).toBe(true);\n // Monday (day 1)\n expect(isWeekend(new Date(2023, 0, 2))).toBe(false);\n // Friday (day 5)\n expect(isWeekend(new Date(2023, 0, 6))).toBe(false);\n});\n\nconst agoUnits = [\n [60, 'second'],\n [60, 'minute'],\n [24, 'hour'],\n [7, 'day'],\n [5, 'week'],\n] as const;\n\nexport function fromNow(date: Date): string {\n return fromNowDetailed(date).result;\n}\n\nimport.meta.vitest?.test(\"fromNow\", ({ expect }) => {\n // Set a fixed date for testing\n const fixedDate = new Date(\"2023-01-15T12:00:00.000Z\");\n\n // Use Vitest's fake timers\n import.meta.vitest?.vi.useFakeTimers();\n import.meta.vitest?.vi.setSystemTime(fixedDate);\n\n // Test past times\n expect(fromNow(new Date(\"2023-01-15T11:59:50.000Z\"))).toBe(\"just now\");\n expect(fromNow(new Date(\"2023-01-15T11:59:00.000Z\"))).toBe(\"1 minute ago\");\n expect(fromNow(new Date(\"2023-01-15T11:00:00.000Z\"))).toBe(\"1 hour ago\");\n expect(fromNow(new Date(\"2023-01-14T12:00:00.000Z\"))).toBe(\"1 day ago\");\n expect(fromNow(new Date(\"2023-01-08T12:00:00.000Z\"))).toBe(\"1 week ago\");\n\n // Test future times\n expect(fromNow(new Date(\"2023-01-15T12:00:10.000Z\"))).toBe(\"just now\");\n expect(fromNow(new Date(\"2023-01-15T12:01:00.000Z\"))).toBe(\"in 1 minute\");\n expect(fromNow(new Date(\"2023-01-15T13:00:00.000Z\"))).toBe(\"in 1 hour\");\n expect(fromNow(new Date(\"2023-01-16T12:00:00.000Z\"))).toBe(\"in 1 day\");\n expect(fromNow(new Date(\"2023-01-22T12:00:00.000Z\"))).toBe(\"in 1 week\");\n\n // Test very old dates (should use date format)\n expect(fromNow(new Date(\"2022-01-15T12:00:00.000Z\"))).toMatch(/Jan 15, 2022/);\n\n // Restore real timers\n import.meta.vitest?.vi.useRealTimers();\n});\n\nexport function fromNowDetailed(date: Date): {\n result: string,\n /**\n * May be Infinity if the result will never change.\n */\n secondsUntilChange: number,\n} {\n if (!(date instanceof Date)) {\n throw new Error(`fromNow only accepts Date objects (received: ${date})`);\n }\n\n const now = new Date();\n const elapsed = now.getTime() - date.getTime();\n\n let remainingInUnit = Math.abs(elapsed) / 1000;\n if (remainingInUnit < 15) {\n return {\n result: 'just now',\n secondsUntilChange: 15 - remainingInUnit,\n };\n }\n let unitInSeconds = 1;\n for (const [nextUnitSize, unitName] of agoUnits) {\n const rounded = Math.round(remainingInUnit);\n if (rounded < nextUnitSize) {\n if (elapsed < 0) {\n return {\n result: `in ${rounded} ${unitName}${rounded === 1 ? '' : 's'}`,\n secondsUntilChange: remainder((remainingInUnit - rounded + 0.5) * unitInSeconds, unitInSeconds),\n };\n } else {\n return {\n result: `${rounded} ${unitName}${rounded === 1 ? '' : 's'} ago`,\n secondsUntilChange: remainder((rounded - remainingInUnit - 0.5) * unitInSeconds, unitInSeconds),\n };\n }\n }\n unitInSeconds *= nextUnitSize;\n remainingInUnit /= nextUnitSize;\n }\n\n return {\n result: date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' }),\n secondsUntilChange: Infinity,\n };\n}\n\n/**\n * Returns a string representation of the given date in the format expected by the `datetime-local` input type.\n */\nexport function getInputDatetimeLocalString(date: Date): string {\n date = new Date(date);\n date.setMinutes(date.getMinutes() - date.getTimezoneOffset());\n return date.toISOString().slice(0, 19);\n}\n\nimport.meta.vitest?.test(\"getInputDatetimeLocalString\", ({ expect }) => {\n // Use Vitest's fake timers to ensure consistent timezone behavior\n import.meta.vitest?.vi.useFakeTimers();\n\n // Test with a specific date\n const mockDate = new Date(\"2023-01-15T12:30:45.000Z\");\n const result = getInputDatetimeLocalString(mockDate);\n\n // The result should be in the format YYYY-MM-DDTHH:MM:SS\n expect(result).toMatch(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$/);\n\n // Test with different dates\n const dates = [\n new Date(\"2023-01-01T00:00:00.000Z\"),\n new Date(\"2023-06-15T23:59:59.000Z\"),\n new Date(\"2023-12-31T12:34:56.000Z\"),\n ];\n\n for (const date of dates) {\n const result = getInputDatetimeLocalString(date);\n expect(result).toMatch(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$/);\n }\n\n // Restore real timers\n import.meta.vitest?.vi.useRealTimers();\n});\n\n\nexport type Interval = [number, 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'];\nexport type DayInterval = [number, 'day' | 'week' | 'month' | 'year'];\n\nfunction applyInterval(inputDate: Date, times: number, interval: Interval): Date {\n if (!intervalSchema.isValidSync(interval)) {\n throw new HexclaveAssertionError(`Invalid interval`, { interval });\n }\n // Operate on a copy: the Date setters below mutate in place, and callers routinely pass a date they\n // also keep a reference to (e.g. `{ currentPeriodStart: now, currentPeriodEnd: addInterval(now, ...) }`).\n // Mutating the input would alias both fields to the same advanced date, silently collapsing the period.\n const date = new Date(inputDate);\n const [amount, unit] = interval;\n switch (unit) {\n case 'millisecond': {\n date.setMilliseconds(date.getMilliseconds() + amount * times);\n break;\n }\n case 'second': {\n date.setSeconds(date.getSeconds() + amount * times);\n break;\n }\n case 'minute': {\n date.setMinutes(date.getMinutes() + amount * times);\n break;\n }\n case 'hour': {\n date.setHours(date.getHours() + amount * times);\n break;\n }\n case 'day': {\n date.setDate(date.getDate() + amount * times);\n break;\n }\n case 'week': {\n date.setDate(date.getDate() + amount * times * 7);\n break;\n }\n case 'month': {\n date.setMonth(date.getMonth() + amount * times);\n break;\n }\n case 'year': {\n date.setFullYear(date.getFullYear() + amount * times);\n break;\n }\n default: {\n throw new HexclaveAssertionError(`Invalid interval despite schema validation`, { interval });\n }\n }\n return date;\n}\n\nexport function subtractInterval(date: Date, interval: Interval): Date {\n return applyInterval(date, -1, interval);\n}\n\n// One-shot local-time interval arithmetic that OVERFLOWS (Jan 31 + 1 month -> Mar 3, via\n// Date#setMonth) rather than clamping. Use this for single-step period math where JS/Stripe overflow\n// semantics are what we want (e.g. computing a subscription's currentPeriodEnd). For recurring\n// grant/reset BOUNDARIES, use `nthDayIntervalMillis` / `getIntervalsElapsed` instead — they clamp to\n// month-end and compute in UTC from a fixed anchor, and mixing the two would drift.\nexport function addInterval(date: Date, interval: Interval): Date {\n return applyInterval(date, 1, interval);\n}\n\nimport.meta.vitest?.test(\"addInterval/subtractInterval do not mutate their input\", ({ expect }) => {\n const original = new Date('2026-07-20T00:00:00.000Z');\n const originalMillis = original.getTime();\n\n const later = addInterval(original, [1, 'month']);\n const earlier = subtractInterval(original, [1, 'month']);\n\n // The input must be untouched, and the result must be a distinct object. This guards the aliasing\n // footgun in `{ currentPeriodStart: now, currentPeriodEnd: addInterval(now, ...) }`, where mutating\n // `now` would collapse both fields to the same advanced instant (a zero-width period).\n expect(original.getTime()).toBe(originalMillis);\n expect(later).not.toBe(original);\n expect(earlier).not.toBe(original);\n expect(later).toEqual(new Date('2026-08-20T00:00:00.000Z'));\n expect(earlier).toEqual(new Date('2026-06-20T00:00:00.000Z'));\n});\n\nexport const FAR_FUTURE_DATE = new Date(8640000000000000); // 13 Sep 275760 00:00:00 UTC\n\nfunction getMsPerDayIntervalUnit(unit: 'day' | 'week'): number {\n if (unit === 'day') {\n return 24 * 60 * 60 * 1000;\n }\n return 7 * 24 * 60 * 60 * 1000;\n}\n\n\n// The number of full `repeat` intervals elapsed from `anchor` up to (and including) `to`, i.e. the\n// largest n >= 0 with the n-th boundary <= to. Boundaries are the SAME ones `nthDayIntervalMillis`\n// computes (anchor-relative, UTC, month-end clamped), so counting and boundary-computation never\n// disagree — a Jan 31 monthly anchor has elapsed one interval by Feb 28, matching the reset the\n// bulldozer item-repeat fold actually emits. (This is why it must NOT be built on `addInterval`,\n// which is local-time and overflows instead of clamping.)\nexport function getIntervalsElapsed(anchor: Date, to: Date, repeat: DayInterval): number {\n const [amount, unit] = repeat;\n const toMillis = to.getTime();\n if (toMillis <= anchor.getTime()) return 0;\n if (unit === 'day' || unit === 'week') {\n const msPerUnit = getMsPerDayIntervalUnit(unit);\n const diffMs = toMillis - anchor.getTime();\n return Math.floor(diffMs / (msPerUnit * amount));\n }\n // month/year: walk anchor-relative boundaries. The count is small in practice (bounded by the\n // number of billing periods since the anchor), so a linear walk is fine.\n let count = 0;\n while (nthDayIntervalMillis(anchor.getTime(), repeat, count + 1) <= toMillis) count += 1;\n return count;\n}\n\nimport.meta.vitest?.test(\"getIntervalsElapsed\", ({ expect }) => {\n const anchor = new Date('2025-01-01T00:00:00.000Z');\n const to = new Date('2025-01-15T00:00:00.000Z');\n expect(getIntervalsElapsed(anchor, to, [1, 'week'])).toBe(2);\n expect(getIntervalsElapsed(anchor, to, [3, 'day'])).toBe(4);\n\n // Jan 31 monthly anchor: the first boundary is clamped to Feb 28, which is <= Mar 1, so one\n // interval has elapsed (anchor-relative clamped math, consistent with nthDayIntervalMillis).\n const mAnchor = new Date('2023-01-31T00:00:00.000Z');\n const mTo = new Date('2023-03-01T00:00:00.000Z');\n expect(getIntervalsElapsed(mAnchor, mTo, [1, 'month'])).toBe(1);\n\n const yAnchor = new Date('2020-01-01T00:00:00.000Z');\n const yTo = new Date('2022-06-01T00:00:00.000Z');\n expect(getIntervalsElapsed(yAnchor, yTo, [1, 'year'])).toBe(2);\n});\n\n/**\n * The UTC millis of the `occurrence`-th (1-based) repeat of `interval` after `anchorMillis`.\n *\n * Each boundary is computed from the *original* anchor (never by stepping off the previous, possibly\n * clamped, boundary) so the anchor's day-of-month is preserved across resets: a Jan 31 anchor yields\n * Feb 28, Mar 31, Apr 30, ... (matching Stripe's billing-cycle behavior) rather than drifting to\n * Feb 28, Mar 28, ... . Month/year overflow (e.g. Jan 31 -> Feb) is clamped to the target month's\n * last day. Day/week are exact multiples (no calendar involved, so no drift possible).\n *\n * Everything is done in UTC (unlike `addInterval`, which uses local-time Date accessors) so the\n * result is deterministic regardless of the server's timezone — this is relied upon by bulldozer\n * folds, which must be reproducible across machines.\n *\n * `occurrence` 0 returns the anchor itself; `getIntervalsElapsed` counts these same boundaries, so\n * the two are always consistent for a given DayInterval.\n */\nexport function nthDayIntervalMillis(anchorMillis: number, interval: DayInterval, occurrence: number): number {\n const [count, unit] = interval;\n const totalUnits = count * occurrence;\n if (unit === 'day' || unit === 'week') {\n return anchorMillis + totalUnits * getMsPerDayIntervalUnit(unit);\n }\n const anchor = new Date(anchorMillis);\n const monthsToAdd = unit === 'year' ? totalUnits * 12 : totalUnits;\n const absoluteMonth = anchor.getUTCFullYear() * 12 + anchor.getUTCMonth() + monthsToAdd;\n const targetYear = Math.floor(absoluteMonth / 12);\n const targetMonth = absoluteMonth - targetYear * 12;\n // Day 0 of the following month is the last day of the target month, so this gives its length.\n const daysInTargetMonth = new Date(Date.UTC(targetYear, targetMonth + 1, 0)).getUTCDate();\n const clampedDay = Math.min(anchor.getUTCDate(), daysInTargetMonth);\n return Date.UTC(\n targetYear,\n targetMonth,\n clampedDay,\n anchor.getUTCHours(),\n anchor.getUTCMinutes(),\n anchor.getUTCSeconds(),\n anchor.getUTCMilliseconds(),\n );\n}\n\nimport.meta.vitest?.test(\"nthDayIntervalMillis\", ({ expect }) => {\n const at = (iso: string) => new Date(iso).getTime();\n const iso = (millis: number) => new Date(millis).toISOString();\n\n // day / week are exact multiples (no drift), and honor the count.\n const dayAnchor = at('2025-01-01T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [1, 'day'], 1))).toBe('2025-01-02T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [3, 'day'], 4))).toBe('2025-01-13T08:30:00.000Z');\n expect(iso(nthDayIntervalMillis(dayAnchor, [2, 'week'], 3))).toBe('2025-02-12T08:30:00.000Z'); // 6 weeks = 42 days after Jan 1\n\n // Jan 31 monthly: clamp in short months, restore to the anchor day in long ones.\n const jan31 = at('2025-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 1))).toBe('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 2))).toBe('2025-03-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31, [1, 'month'], 3))).toBe('2025-04-30T00:00:00.000Z');\n\n // Anchor-day preservation: a Feb 28 anchor stays on day 28 (never jumps to Mar 31), unlike the\n // Jan 31 anchor above which restores to Mar 31. This is the evidence we compute from the anchor.\n const feb28 = at('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb28, [1, 'month'], 1))).toBe('2025-03-28T00:00:00.000Z');\n\n // Leap-year Feb: Feb 29 anchor clamps to Feb 28 in a non-leap year and restores in the next leap year.\n const feb29 = at('2024-02-29T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb29, [1, 'year'], 1))).toBe('2025-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(feb29, [1, 'year'], 4))).toBe('2028-02-29T00:00:00.000Z');\n // Jan 31 monthly landing in a leap February clamps to Feb 29, not Feb 28.\n const jan31Leap = at('2024-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(jan31Leap, [1, 'month'], 1))).toBe('2024-02-29T00:00:00.000Z');\n\n // End-of-December rollover: absolute-month math carries the year.\n const dec31 = at('2025-12-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 1))).toBe('2026-01-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 2))).toBe('2026-02-28T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'month'], 3))).toBe('2026-03-31T00:00:00.000Z');\n expect(iso(nthDayIntervalMillis(dec31, [1, 'year'], 1))).toBe('2026-12-31T00:00:00.000Z');\n\n // Time-of-day is preserved through month clamping.\n const withTime = at('2025-01-31T13:45:59.123Z');\n expect(iso(nthDayIntervalMillis(withTime, [1, 'month'], 1))).toBe('2025-02-28T13:45:59.123Z');\n});\n"],"mappings":";;;;;AAIA,SAAgB,UAAU,MAAqB;CAC7C,OAAO,KAA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c,KAAK;AAC5B;AASA,SAAgB,oBAAoB,QAAc,IAAU,QAA6B;CACvF,MAAM,CAAC,QAAQ,QAAQ;CACvB,MAAM,WAAW,GAAG,QAAQ;CAC5B,IAAI,YAAY,OAAO,QAAQ,GAAG,OAAO;CACzC,IAAI,SAAS,SAAS,SAAS,QAAQ;EACrC,MAAM,YAAY,wBAAwB,IAAI;EAC9C,MAAM,SAAS,WAAW,OAAO,QAAQ;EACzC,OAAO,KAAK,MAAM,UAAU,YAAY,OAAO;CACjD;CAGA,IAAI,QAAQ;CACZ,OAAO,qBAAqB,OAAO,QAAQ,GAAG,QAAQ,QAAQ,CAAC,KAAK,UAAU,SAAS;CACvF,OAAO;AACT;;;;;;;;;;;;;;;;;AAmCA,SAAgB,qBAAqB,cAAsB,UAAuB,YAA4B;CAC5G,MAAM,CAAC,OAAO,QAAQ;CACtB,MAAM,aAAa,QAAQ;CAC3B,IAAI,SAAS,SAAS,SAAS,QAC7B,OAAO,eAAe,aAAa,wBAAwB,IAAI;CAEjE,MAAM,SAAS,IAAI,KAAK,YAAY;CACpC,MAAM,cAAc,SAAS,SAAS,aAAa,KAAK;CACxD,MAAM,gBAAgB,OAAO,eAAe,IAAI,KAAK,OAAO,YAAY,IAAI;CAC5E,MAAM,aAAa,KAAK,MAAM,gBAAgB,EAAE;CAChD,MAAM,cAAc,gBAAgB,aAAa;CAEjD,MAAM,oBAAoB,IAAI,KAAK,KAAK,IAAI,YAAY,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW;CACxF,MAAM,aAAa,KAAK,IAAI,OAAO,WAAW,GAAG,iBAAiB;CAClE,OAAO,KAAK,IACV,YACA,aACA,YACA,OAAO,YAAY,GACnB,OAAO,cAAc,GACrB,OAAO,cAAc,GACrB,OAAO,mBAAmB,CAC5B;AACF"}
|
package/package.json
CHANGED
|
@@ -32,5 +32,5 @@ export const remindersPrompt = deindent`
|
|
|
32
32
|
- You can use the \`npx @hexclave/cli exec <javascript>\` command to run JavaScript with a pre-configured HexclaveServerApp available as \`hexclaveServerApp\`. This allows you to read and write from and to the Hexclave project as you would on the dashboard, but from the CLI. To read and write project configuration, see the note on the config file above.
|
|
33
33
|
- For advanced read queries, you can use \`hexclaveServerApp.queryAnalytics("<clickhouse-sql>")\`. Use \`SHOW TABLES\` and \`DESCRIBE TABLE\` to understand the schema of the available tables (columns have comments that may be useful as a description).
|
|
34
34
|
- Hexclave was formerly known as Stack Auth. You may still see references to it as Stack Auth in some places.
|
|
35
|
-
- When a human is talking about Users, more often than not, they are referring to non-anonymous users. Make sure to decide whether to filter anonymous users out in SQL queries based on suspected intent.
|
|
35
|
+
- When a human is talking about Users, more often than not, they are referring to non-anonymous users. Make sure to decide whether to filter anonymous users out in SQL queries based on suspected intent. For example, when reporting number of users, or recent sign-ups, almost certainly they're just asking about non-anonymous users.
|
|
36
36
|
`;
|
|
@@ -411,12 +411,12 @@ function getRestBackendSetupPrompt(kind: "python" | "rest-api") {
|
|
|
411
411
|
If this project already has a \`hexclave.config.ts\` file for another frontend or backend, reuse that same file so the whole project shares one Hexclave config. Otherwise, create a new \`hexclave.config.ts\` file in your workspace:
|
|
412
412
|
|
|
413
413
|
\`\`\`ts hexclave.config.ts
|
|
414
|
-
import type { HexclaveConfig } from "@hexclave/js
|
|
414
|
+
import type { HexclaveConfig } from "@hexclave/js";
|
|
415
415
|
|
|
416
416
|
export const config: HexclaveConfig = "show-onboarding";
|
|
417
417
|
\`\`\`
|
|
418
418
|
|
|
419
|
-
|
|
419
|
+
If you later switch to a config object and want type-checking, wrap it with \`defineHexclaveConfig\`, imported from the same \`@hexclave/js\` package.
|
|
420
420
|
|
|
421
421
|
Run your backend through the Hexclave CLI so it starts the local dashboard and injects the Hexclave environment variables:
|
|
422
422
|
|
|
@@ -975,13 +975,13 @@ export function getSdkSetupPrompt(mainType: "ai-prompt" | "nextjs" | "react" | "
|
|
|
975
975
|
First, create a \`hexclave.config.ts\` configuration file in the root directory of the workspace (or anywhere else):
|
|
976
976
|
|
|
977
977
|
\`\`\`ts hexclave.config.ts
|
|
978
|
-
import type { HexclaveConfig } from "${packageName}
|
|
978
|
+
import type { HexclaveConfig } from "${packageName}";
|
|
979
979
|
|
|
980
980
|
// default: show-onboarding, which shows the onboarding flow for this project when Hexclave starts
|
|
981
981
|
export const config: HexclaveConfig = "show-onboarding";
|
|
982
982
|
\`\`\`
|
|
983
983
|
|
|
984
|
-
|
|
984
|
+
If you later switch to a config object and want type-checking, wrap it with \`defineHexclaveConfig\`, imported from the same \`${packageName}\` package.
|
|
985
985
|
|
|
986
986
|
${isAiPrompt ? deindent`
|
|
987
987
|
If you already know which apps you want to enable and how to configure them, you can also set the \`config\` object to the desired configuration directly. Refer to the per-app setup instructions for more information. However, in most cases, you would probably want to let the user onboard manually through the show-onboarding flow.
|