@superpanel-sdk/runtime 0.2.3 → 0.5.0
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/README.md +28 -8
- package/dist/builder/codegen/emit.d.ts +29 -11
- package/dist/builder/codegen/emit.js +328 -61
- package/dist/builder/codegen/generate.d.ts +21 -0
- package/dist/builder/codegen/generate.js +152 -20
- package/dist/builder/company-import-graph.d.ts +2 -0
- package/dist/builder/company-import-graph.js +40 -8
- package/dist/builder/company-imports.d.ts +24 -0
- package/dist/builder/company-imports.js +114 -0
- package/dist/builder/compile/compile-sequence.d.ts +59 -8
- package/dist/builder/compile/compile-sequence.js +279 -77
- package/dist/builder/compile/function-code.d.ts +12 -2
- package/dist/builder/compile/function-code.js +87 -39
- package/dist/builder/compile/registry.d.ts +7 -3
- package/dist/builder/compile/registry.js +24 -23
- package/dist/builder/load.d.ts +70 -10
- package/dist/builder/load.js +250 -61
- package/dist/builder/paths.d.ts +3 -0
- package/dist/builder/paths.js +16 -0
- package/dist/builder/schedules.d.ts +23 -0
- package/dist/builder/schedules.js +102 -0
- package/dist/builder/slot-schema-validation.d.ts +4 -0
- package/dist/builder/slot-schema-validation.js +10 -0
- package/dist/builder/typecheck.d.ts +8 -0
- package/dist/builder/typecheck.js +105 -0
- package/dist/builder/types.d.ts +91 -19
- package/dist/builder/types.js +2 -1
- package/dist/cli/auth/auth.d.ts +37 -0
- package/dist/cli/auth/auth.js +211 -0
- package/dist/cli/auth/backend-url.d.ts +5 -0
- package/dist/cli/auth/backend-url.js +25 -0
- package/dist/cli/auth/clipboard.d.ts +9 -0
- package/dist/cli/auth/clipboard.js +38 -0
- package/dist/cli/auth/http.d.ts +20 -0
- package/dist/cli/auth/http.js +27 -0
- package/dist/cli/auth/index.d.ts +10 -0
- package/dist/cli/auth/index.js +27 -0
- package/dist/cli/auth/progress.d.ts +12 -0
- package/dist/cli/auth/progress.js +15 -0
- package/dist/cli/auth/serve-login.d.ts +8 -0
- package/dist/cli/auth/serve-login.js +24 -0
- package/dist/cli/compile/index.js +3 -0
- package/dist/cli/config.d.ts +10 -0
- package/dist/cli/config.js +52 -0
- package/dist/cli/index.js +28 -8
- package/dist/cli/serve/index.d.ts +73 -3
- package/dist/cli/serve/index.js +365 -116
- package/dist/cli/type-gen/index.js +9 -8
- package/dist/compiler.d.ts +7 -0
- package/dist/compiler.js +7 -0
- package/dist/compute-host/compute-host.d.ts +15 -23
- package/dist/compute-host/compute-host.js +25 -28
- package/dist/compute-host/index.d.ts +2 -4
- package/dist/compute-host/index.js +1 -2
- package/dist/compute-host/source-compute-host.d.ts +11 -9
- package/dist/compute-host/source-compute-host.js +46 -32
- package/dist/core/case-orchestrator/contact-hours.d.ts +50 -0
- package/dist/core/case-orchestrator/contact-hours.js +108 -0
- package/dist/core/case-orchestrator/follow-ups.d.ts +31 -0
- package/dist/core/case-orchestrator/follow-ups.js +103 -0
- package/dist/core/case-orchestrator/index.d.ts +6 -0
- package/dist/core/case-orchestrator/index.js +6 -0
- package/dist/core/case-orchestrator/render.d.ts +75 -0
- package/dist/core/case-orchestrator/render.js +239 -0
- package/dist/core/case-orchestrator/time.d.ts +11 -0
- package/dist/core/case-orchestrator/time.js +29 -0
- package/dist/core/case-orchestrator/tools.d.ts +29 -0
- package/dist/core/case-orchestrator/tools.js +31 -0
- package/dist/core/case-orchestrator/types.d.ts +753 -0
- package/dist/core/case-orchestrator/types.js +46 -0
- package/dist/core/case-orchestrator/validate.d.ts +11 -0
- package/dist/core/case-orchestrator/validate.js +63 -0
- package/dist/core/context/call.d.ts +291 -0
- package/dist/core/context/call.js +94 -0
- package/dist/core/context/channels.d.ts +60 -0
- package/dist/core/context/channels.js +35 -0
- package/dist/core/context/contact.d.ts +96 -6
- package/dist/core/context/contact.js +48 -2
- package/dist/core/context/email-message.d.ts +159 -0
- package/dist/core/context/email-message.js +59 -0
- package/dist/core/context/email.d.ts +97 -0
- package/dist/core/context/email.js +91 -0
- package/dist/core/context/exchanges.d.ts +142 -0
- package/dist/core/context/exchanges.js +63 -0
- package/dist/core/context/instances.d.ts +278 -0
- package/dist/core/context/instances.js +123 -0
- package/dist/core/context/kv.d.ts +113 -0
- package/dist/core/context/kv.js +60 -0
- package/dist/core/context/platform-registry.d.ts +509 -4
- package/dist/core/context/platform-registry.js +14 -2
- package/dist/core/context/platform.d.ts +2 -1
- package/dist/core/context/sms.d.ts +147 -0
- package/dist/core/context/sms.js +57 -0
- package/dist/core/context/types.d.ts +51 -48
- package/dist/core/context/types.js +1 -7
- package/dist/core/conversation/index.d.ts +31 -0
- package/dist/core/conversation/index.js +14 -0
- package/dist/core/functions/define/bind.d.ts +25 -0
- package/dist/core/functions/define/bind.js +14 -0
- package/dist/core/functions/define/case.d.ts +9 -0
- package/dist/core/functions/define/case.js +13 -0
- package/dist/core/functions/define/events.d.ts +20 -0
- package/dist/core/functions/define/events.js +21 -0
- package/dist/core/functions/define/no-case.d.ts +4 -0
- package/dist/core/functions/define/no-case.js +9 -0
- package/dist/core/functions/events.d.ts +247 -0
- package/dist/core/functions/events.js +32 -0
- package/dist/core/functions/func-ref.d.ts +11 -2
- package/dist/core/functions/schedules.d.ts +51 -0
- package/dist/core/functions/schedules.js +20 -0
- package/dist/core/functions/types.d.ts +62 -51
- package/dist/core/functions/types.js +6 -1
- package/dist/core/office-hours/index.d.ts +39 -0
- package/dist/core/office-hours/index.js +187 -0
- package/dist/core/page/define.d.ts +834 -0
- package/dist/core/page/define.js +477 -0
- package/dist/core/page/ops.d.ts +58 -0
- package/dist/core/page/ops.js +220 -0
- package/dist/core/page/render.d.ts +253 -0
- package/dist/core/page/render.js +840 -0
- package/dist/core/page/time-format.d.ts +19 -0
- package/dist/core/page/time-format.js +41 -0
- package/dist/core/page/timeline.d.ts +40 -0
- package/dist/core/page/timeline.js +2 -0
- package/dist/core/page/typed.d.ts +642 -0
- package/dist/core/page/typed.js +2 -0
- package/dist/core/page/workspace.d.ts +33 -0
- package/dist/core/page/workspace.js +231 -0
- package/dist/core/party/index.d.ts +3 -0
- package/dist/core/party/index.js +3 -0
- package/dist/core/party/schema.d.ts +137 -0
- package/dist/core/party/schema.js +80 -0
- package/dist/core/party/types.d.ts +40 -0
- package/dist/core/party/types.js +15 -0
- package/dist/core/sequence/define.d.ts +57 -0
- package/dist/core/sequence/define.js +10 -0
- package/dist/core/sequence/index.d.ts +63 -0
- package/dist/core/sequence/index.js +231 -0
- package/dist/core/slot/binding.d.ts +40 -0
- package/dist/core/slot/binding.js +2 -0
- package/dist/core/slot/company-metadata.d.ts +113 -0
- package/dist/core/slot/company-metadata.js +563 -0
- package/dist/core/slot/compile-schema.d.ts +19 -13
- package/dist/core/slot/compile-schema.js +51 -248
- package/dist/core/slot/contact-timezone.d.ts +110 -0
- package/dist/core/slot/contact-timezone.js +186 -0
- package/dist/core/slot/field.d.ts +2 -24
- package/dist/core/slot/field.js +0 -69
- package/dist/core/slot/id-ref.d.ts +17 -2
- package/dist/core/slot/id-ref.js +16 -8
- package/dist/core/slot/index.d.ts +12 -13
- package/dist/core/slot/index.js +11 -12
- package/dist/core/slot/naming.d.ts +15 -0
- package/dist/core/slot/naming.js +96 -0
- package/dist/core/slot/platform-fields.d.ts +119 -0
- package/dist/core/slot/platform-fields.js +121 -0
- package/dist/core/slot/ref.d.ts +16 -0
- package/dist/core/slot/ref.js +14 -0
- package/dist/core/slot/row.d.ts +2 -9
- package/dist/core/slot/row.js +13 -23
- package/dist/core/slot/schema-compat.d.ts +16 -0
- package/dist/core/slot/schema-compat.js +112 -0
- package/dist/core/slot/schema.d.ts +409 -76
- package/dist/core/slot/schema.js +178 -10
- package/dist/core/slot/types.d.ts +27 -94
- package/dist/core/slot/value.d.ts +26 -3
- package/dist/core/slot/value.js +89 -57
- package/dist/dev-overlay/protocol.d.ts +41 -8
- package/dist/fn-context/build-context.d.ts +3 -1
- package/dist/fn-context/build-context.js +20 -10
- package/dist/fn-context/fake/empty-api.js +9 -28
- package/dist/fn-context/fake/index.d.ts +11 -4
- package/dist/fn-context/fake/index.js +27 -2
- package/dist/fn-context/fn-params.d.ts +6 -0
- package/dist/fn-context/fn-params.js +13 -0
- package/dist/fn-context/index.d.ts +5 -5
- package/dist/fn-context/index.js +4 -4
- package/dist/fn-context/log.js +2 -2
- package/dist/fn-context/make-ctx.d.ts +11 -0
- package/dist/fn-context/make-ctx.js +18 -8
- package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +24 -0
- package/dist/fn-context/rpc/case-orchestrator-tools.js +13 -0
- package/dist/fn-context/rpc/index.d.ts +3 -1
- package/dist/fn-context/rpc/index.js +3 -1
- package/dist/fn-context/rpc/integration/index.d.ts +4 -4
- package/dist/fn-context/rpc/integration/index.js +1 -1
- package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
- package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
- package/dist/fn-context/rpc/platform.d.ts +2 -2
- package/dist/fn-context/rpc/platform.js +1 -1
- package/dist/fn-context/rpc/records.d.ts +78 -0
- package/dist/fn-context/rpc/records.js +26 -0
- package/dist/fn-context/rpc/trpc-client.d.ts +2 -2
- package/dist/fn-context/rpc/trpc-client.js +88 -7
- package/dist/fn-context/rpc/trpc-init.d.ts +2 -2
- package/dist/fn-context/rpc/trpc-router-factory.d.ts +49 -3
- package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
- package/dist/fn-context/run-scope.d.ts +4 -0
- package/dist/fn-context/run-scope.js +9 -0
- package/dist/fn-context/types.d.ts +36 -3
- package/dist/index.d.ts +37 -46
- package/dist/index.js +33 -33
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +41 -0
- package/dist/platform.d.ts +76 -0
- package/dist/platform.js +56 -0
- package/dist/voice-service/actions.d.ts +71 -4
- package/dist/voice-service/types.d.ts +42 -5
- package/dist/worker.d.ts +10 -0
- package/dist/worker.js +10 -0
- package/package.json +38 -19
- package/dist/builder/compile/compile-agenda.d.ts +0 -15
- package/dist/builder/compile/compile-agenda.js +0 -64
- package/dist/builder/merge.d.ts +0 -4
- package/dist/builder/merge.js +0 -19
- package/dist/compute-host/read-only-cache.d.ts +0 -20
- package/dist/compute-host/read-only-cache.js +0 -61
- package/dist/core/context/db.d.ts +0 -69
- package/dist/core/context/db.js +0 -44
- package/dist/core/context/docusign.d.ts +0 -134
- package/dist/core/context/docusign.js +0 -108
- package/dist/core/context/filevine.d.ts +0 -323
- package/dist/core/context/filevine.js +0 -254
- package/dist/core/context/http.d.ts +0 -9
- package/dist/core/context/http.js +0 -4
- package/dist/core/context/hubspot.d.ts +0 -250
- package/dist/core/context/hubspot.js +0 -191
- package/dist/core/context/twilio.d.ts +0 -50
- package/dist/core/context/twilio.js +0 -42
- package/dist/core/functions/define/case-context.d.ts +0 -14
- package/dist/core/functions/define/case-context.js +0 -15
- package/dist/core/functions/define/compute.d.ts +0 -7
- package/dist/core/functions/define/compute.js +0 -17
- package/dist/core/functions/define/custom.d.ts +0 -4
- package/dist/core/functions/define/custom.js +0 -8
- package/dist/core/functions/define/system.d.ts +0 -7
- package/dist/core/functions/define/system.js +0 -12
- package/dist/core/slot/deps.d.ts +0 -15
- package/dist/core/slot/deps.js +0 -88
- package/dist/core/slot/derived.d.ts +0 -32
- package/dist/core/slot/derived.js +0 -115
- package/dist/core/slot/platform-session-fields.d.ts +0 -38
- package/dist/core/slot/platform-session-fields.js +0 -48
- package/dist/core/slot/sf-schema.d.ts +0 -23
- package/dist/core/slot/sf-schema.js +0 -125
- package/dist/core/slot/sf-validate.d.ts +0 -14
- package/dist/core/slot/sf-validate.js +0 -132
- package/dist/core/slot/snapshot.d.ts +0 -18
- package/dist/core/slot/snapshot.js +0 -138
- package/dist/core/slot/write.d.ts +0 -48
- package/dist/core/slot/write.js +0 -426
- package/dist/core/stage/builders.d.ts +0 -54
- package/dist/core/stage/builders.js +0 -31
- package/dist/core/stage/condition.d.ts +0 -17
- package/dist/core/stage/condition.js +0 -198
- package/dist/core/stage/drive.d.ts +0 -43
- package/dist/core/stage/drive.js +0 -78
- package/dist/core/stage/finish-when.d.ts +0 -20
- package/dist/core/stage/finish-when.js +0 -82
- package/dist/core/stage/flatten.d.ts +0 -27
- package/dist/core/stage/flatten.js +0 -466
- package/dist/core/stage/index.d.ts +0 -15
- package/dist/core/stage/index.js +0 -13
- package/dist/core/stage/interrupts.d.ts +0 -28
- package/dist/core/stage/interrupts.js +0 -120
- package/dist/core/stage/ivr-fields.d.ts +0 -9
- package/dist/core/stage/ivr-fields.js +0 -75
- package/dist/core/stage/simulate.d.ts +0 -24
- package/dist/core/stage/simulate.js +0 -33
- package/dist/core/stage/transfer-fields.d.ts +0 -19
- package/dist/core/stage/transfer-fields.js +0 -129
- package/dist/core/stage/transfer-spec.d.ts +0 -48
- package/dist/core/stage/transfer-spec.js +0 -113
- package/dist/core/stage/types.d.ts +0 -208
- package/dist/core/stage/types.js +0 -2
- package/dist/core/stage/validate.d.ts +0 -11
- package/dist/core/stage/validate.js +0 -330
- package/dist/core/stage/walk.d.ts +0 -39
- package/dist/core/stage/walk.js +0 -119
- package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
- package/dist/fn-context/system-args.d.ts +0 -6
- package/dist/fn-context/system-args.js +0 -14
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const WEEKDAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
|
3
|
+
const windowSchema = z.object({ start: z.string(), end: z.string() }).strict();
|
|
4
|
+
const hoursSchema = z.array(windowSchema);
|
|
5
|
+
const officeHoursSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
timezone: z.string(),
|
|
8
|
+
week: z
|
|
9
|
+
.object({
|
|
10
|
+
mon: hoursSchema,
|
|
11
|
+
tue: hoursSchema,
|
|
12
|
+
wed: hoursSchema,
|
|
13
|
+
thu: hoursSchema,
|
|
14
|
+
fri: hoursSchema,
|
|
15
|
+
sat: hoursSchema,
|
|
16
|
+
sun: hoursSchema,
|
|
17
|
+
})
|
|
18
|
+
.strict(),
|
|
19
|
+
holidays: z.array(z.object({ date: z.string(), hours: hoursSchema }).strict()),
|
|
20
|
+
overrides: z.array(z.object({ date: z.string(), hours: hoursSchema }).strict()),
|
|
21
|
+
})
|
|
22
|
+
.strict();
|
|
23
|
+
const TIME_RE = /^(?:[01]\d|2[0-3]):[0-5]\d$/;
|
|
24
|
+
const MONTH_DAY_RE = /^(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
25
|
+
const YEAR_DATE_RE = /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
26
|
+
const DAYS_IN_MONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
27
|
+
const WEEKDAY_FROM_SHORT = {
|
|
28
|
+
Mon: 'mon',
|
|
29
|
+
Tue: 'tue',
|
|
30
|
+
Wed: 'wed',
|
|
31
|
+
Thu: 'thu',
|
|
32
|
+
Fri: 'fri',
|
|
33
|
+
Sat: 'sat',
|
|
34
|
+
Sun: 'sun',
|
|
35
|
+
};
|
|
36
|
+
function parseClockMinutes(time) {
|
|
37
|
+
if (time === '24:00')
|
|
38
|
+
return 24 * 60;
|
|
39
|
+
if (!TIME_RE.test(time))
|
|
40
|
+
return null;
|
|
41
|
+
return Number(time.slice(0, 2)) * 60 + Number(time.slice(3, 5));
|
|
42
|
+
}
|
|
43
|
+
function isIanaTimezone(name) {
|
|
44
|
+
try {
|
|
45
|
+
Intl.DateTimeFormat('en-US', { timeZone: name });
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function isMonthDay(date) {
|
|
53
|
+
const match = MONTH_DAY_RE.exec(date);
|
|
54
|
+
if (!match)
|
|
55
|
+
return false;
|
|
56
|
+
return Number(match[2]) <= DAYS_IN_MONTH[Number(match[1]) - 1];
|
|
57
|
+
}
|
|
58
|
+
function isRealDate(date) {
|
|
59
|
+
const match = YEAR_DATE_RE.exec(date);
|
|
60
|
+
if (!match)
|
|
61
|
+
return false;
|
|
62
|
+
const year = Number(match[1]);
|
|
63
|
+
const month = Number(match[2]);
|
|
64
|
+
const day = Number(match[3]);
|
|
65
|
+
const utc = new Date(Date.UTC(year, month - 1, day));
|
|
66
|
+
return utc.getUTCFullYear() === year && utc.getUTCMonth() === month - 1 && utc.getUTCDate() === day;
|
|
67
|
+
}
|
|
68
|
+
function validateWindows(hours, path, issues) {
|
|
69
|
+
const ranges = [];
|
|
70
|
+
for (const [index, window] of hours.entries()) {
|
|
71
|
+
const start = parseClockMinutes(window.start);
|
|
72
|
+
const end = parseClockMinutes(window.end);
|
|
73
|
+
if (window.start === '24:00' || start == null) {
|
|
74
|
+
issues.push(`${path}[${index}].start must be HH:mm (00:00–23:59)`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (end == null) {
|
|
78
|
+
issues.push(`${path}[${index}].end must be HH:mm or 24:00`);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (start >= end) {
|
|
82
|
+
issues.push(`${path}[${index}].start must be earlier than end`);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
ranges.push({ start, end });
|
|
86
|
+
}
|
|
87
|
+
ranges.sort((a, b) => a.start - b.start);
|
|
88
|
+
for (let i = 1; i < ranges.length; i += 1) {
|
|
89
|
+
if (ranges[i].start < ranges[i - 1].end) {
|
|
90
|
+
issues.push(`${path} windows must not overlap`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function validateOfficeHoursRules(config) {
|
|
96
|
+
const issues = [];
|
|
97
|
+
if (!isIanaTimezone(config.timezone))
|
|
98
|
+
issues.push(`timezone must be an IANA time zone name`);
|
|
99
|
+
for (const day of WEEKDAYS)
|
|
100
|
+
validateWindows(config.week[day], `week.${day}`, issues);
|
|
101
|
+
const holidayDates = new Set();
|
|
102
|
+
for (const [index, holiday] of config.holidays.entries()) {
|
|
103
|
+
if (!isMonthDay(holiday.date))
|
|
104
|
+
issues.push(`holidays[${index}].date must be MM-DD`);
|
|
105
|
+
else if (holidayDates.has(holiday.date))
|
|
106
|
+
issues.push(`holidays date ${holiday.date} is repeated`);
|
|
107
|
+
else
|
|
108
|
+
holidayDates.add(holiday.date);
|
|
109
|
+
validateWindows(holiday.hours, `holidays[${index}].hours`, issues);
|
|
110
|
+
}
|
|
111
|
+
const overrideDates = new Set();
|
|
112
|
+
for (const [index, override] of config.overrides.entries()) {
|
|
113
|
+
if (!isRealDate(override.date))
|
|
114
|
+
issues.push(`overrides[${index}].date must be a real YYYY-MM-DD`);
|
|
115
|
+
else if (overrideDates.has(override.date))
|
|
116
|
+
issues.push(`overrides date ${override.date} is repeated`);
|
|
117
|
+
else
|
|
118
|
+
overrideDates.add(override.date);
|
|
119
|
+
validateWindows(override.hours, `overrides[${index}].hours`, issues);
|
|
120
|
+
}
|
|
121
|
+
return issues;
|
|
122
|
+
}
|
|
123
|
+
export function parseOfficeHours(value) {
|
|
124
|
+
const shape = officeHoursSchema.safeParse(value);
|
|
125
|
+
if (!shape.success) {
|
|
126
|
+
return {
|
|
127
|
+
ok: false,
|
|
128
|
+
issues: shape.error.issues.map((issue) => {
|
|
129
|
+
const path = issue.path.join('.');
|
|
130
|
+
return path ? `${path}: ${issue.message}` : issue.message;
|
|
131
|
+
}),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const issues = validateOfficeHoursRules(shape.data);
|
|
135
|
+
if (issues.length > 0)
|
|
136
|
+
return { ok: false, issues };
|
|
137
|
+
return { ok: true, value: shape.data };
|
|
138
|
+
}
|
|
139
|
+
function localClock(now, timezone) {
|
|
140
|
+
const parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', {
|
|
141
|
+
timeZone: timezone,
|
|
142
|
+
weekday: 'short',
|
|
143
|
+
year: 'numeric',
|
|
144
|
+
month: '2-digit',
|
|
145
|
+
day: '2-digit',
|
|
146
|
+
hour: '2-digit',
|
|
147
|
+
minute: '2-digit',
|
|
148
|
+
hourCycle: 'h23',
|
|
149
|
+
})
|
|
150
|
+
.formatToParts(new Date(now))
|
|
151
|
+
.map((part) => [part.type, part.value]));
|
|
152
|
+
const weekday = WEEKDAY_FROM_SHORT[parts.weekday ?? ''];
|
|
153
|
+
if (!weekday)
|
|
154
|
+
throw new Error(`could not read weekday in ${timezone}`);
|
|
155
|
+
return {
|
|
156
|
+
date: `${parts.year}-${parts.month}-${parts.day}`,
|
|
157
|
+
monthDay: `${parts.month}-${parts.day}`,
|
|
158
|
+
weekday,
|
|
159
|
+
minutes: Number(parts.hour) * 60 + Number(parts.minute),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function hoursForDate(config, now) {
|
|
163
|
+
const clock = localClock(now, config.timezone);
|
|
164
|
+
const override = config.overrides.find((entry) => entry.date === clock.date);
|
|
165
|
+
if (override)
|
|
166
|
+
return override.hours;
|
|
167
|
+
const holiday = config.holidays.find((entry) => entry.date === clock.monthDay);
|
|
168
|
+
if (holiday)
|
|
169
|
+
return holiday.hours;
|
|
170
|
+
return config.week[clock.weekday];
|
|
171
|
+
}
|
|
172
|
+
export function resolveOfficeHours(config, now) {
|
|
173
|
+
if (!config)
|
|
174
|
+
return null;
|
|
175
|
+
const today = hoursForDate(config, now);
|
|
176
|
+
const clock = localClock(now, config.timezone);
|
|
177
|
+
return {
|
|
178
|
+
...structuredClone(config),
|
|
179
|
+
open: today.some((window) => {
|
|
180
|
+
const start = parseClockMinutes(window.start);
|
|
181
|
+
const end = parseClockMinutes(window.end);
|
|
182
|
+
return start != null && end != null && clock.minutes >= start && clock.minutes < end;
|
|
183
|
+
}),
|
|
184
|
+
today: structuredClone(today),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=index.js.map
|