@timeback/core 0.2.2 → 0.2.3-beta.20260326001827
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/{chunk-2mkbbgd8.js → chunk-z964w2xh.js} +61 -11
- package/dist/index.js +1 -1
- package/dist/utils.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseTransport,
|
|
3
3
|
DEFAULT_PROVIDER_REGISTRY,
|
|
4
|
+
createInputValidationError,
|
|
4
5
|
createScopedLogger,
|
|
5
6
|
parseBodyPaginationRaw,
|
|
6
7
|
resolveToProvider,
|
|
@@ -22,6 +23,56 @@ function normalizeUser(user) {
|
|
|
22
23
|
enabledUser: normalizeBoolean(user.enabledUser)
|
|
23
24
|
};
|
|
24
25
|
}
|
|
26
|
+
function getTimezoneOffsetMs(at, timezone) {
|
|
27
|
+
const fmt = new Intl.DateTimeFormat("en-US", {
|
|
28
|
+
timeZone: timezone,
|
|
29
|
+
hourCycle: "h23",
|
|
30
|
+
year: "numeric",
|
|
31
|
+
month: "2-digit",
|
|
32
|
+
day: "2-digit",
|
|
33
|
+
hour: "2-digit",
|
|
34
|
+
minute: "2-digit",
|
|
35
|
+
second: "2-digit"
|
|
36
|
+
});
|
|
37
|
+
const parts = fmt.formatToParts(at);
|
|
38
|
+
const n = (type) => Number(parts.find((p) => p.type === type)?.value ?? 0);
|
|
39
|
+
const localMs = Date.UTC(n("year"), n("month") - 1, n("day"), n("hour"), n("minute"), n("second"));
|
|
40
|
+
return at.getTime() - at.getTime() % 1000 - localMs;
|
|
41
|
+
}
|
|
42
|
+
function bareDateToUTC(bareDate, time, timezone) {
|
|
43
|
+
try {
|
|
44
|
+
const [year, month, day] = bareDate.split("-").map(Number);
|
|
45
|
+
const [h, m, secMs] = time.split(":");
|
|
46
|
+
const [s, msStr] = secMs.split(".");
|
|
47
|
+
const ms = Number(msStr ?? 0);
|
|
48
|
+
const localAsUtcMs = Date.UTC(year, month - 1, day, +h, +m, +s, ms);
|
|
49
|
+
const offset1 = getTimezoneOffsetMs(new Date(localAsUtcMs), timezone);
|
|
50
|
+
const result1 = localAsUtcMs + offset1;
|
|
51
|
+
const offset2 = getTimezoneOffsetMs(new Date(result1), timezone);
|
|
52
|
+
return new Date(localAsUtcMs + offset2).toISOString();
|
|
53
|
+
} catch (err) {
|
|
54
|
+
if (err instanceof RangeError) {
|
|
55
|
+
throw createInputValidationError("Invalid timezone", [
|
|
56
|
+
{ path: "timezone", message: `Must be a valid IANA timezone, got "${timezone}"` }
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function normalizeStartDate(date, timezone) {
|
|
63
|
+
if (date.includes("T"))
|
|
64
|
+
return date;
|
|
65
|
+
if (!timezone)
|
|
66
|
+
return `${date}T00:00:00.000Z`;
|
|
67
|
+
return bareDateToUTC(date, "00:00:00.000", timezone);
|
|
68
|
+
}
|
|
69
|
+
function normalizeEndDate(date, timezone) {
|
|
70
|
+
if (date.includes("T"))
|
|
71
|
+
return date;
|
|
72
|
+
if (!timezone)
|
|
73
|
+
return `${date}T23:59:59.999Z`;
|
|
74
|
+
return bareDateToUTC(date, "23:59:59.999", timezone);
|
|
75
|
+
}
|
|
25
76
|
function aggregateActivityMetrics(data) {
|
|
26
77
|
const result = {
|
|
27
78
|
totalXp: 0,
|
|
@@ -774,7 +825,6 @@ var TimebackConfig = z6.object({
|
|
|
774
825
|
// ../../types/src/zod/edubridge.ts
|
|
775
826
|
import { z as z7 } from "zod/v4";
|
|
776
827
|
var EdubridgeDateString = z7.union([IsoDateTimeString, IsoDateString]);
|
|
777
|
-
var EdubridgeDateStringInput = EdubridgeDateString.transform((date) => date.includes("T") ? date : `${date}T00:00:00.000Z`);
|
|
778
828
|
var EduBridgeEnrollment = z7.object({
|
|
779
829
|
id: z7.string(),
|
|
780
830
|
role: z7.string(),
|
|
@@ -865,18 +915,18 @@ var EdubridgeUsersListParams = z7.object({
|
|
|
865
915
|
orgSourcedIds: z7.array(NonEmptyString).optional()
|
|
866
916
|
});
|
|
867
917
|
var EdubridgeActivityParams = EmailOrStudentId.extend({
|
|
868
|
-
startDate:
|
|
869
|
-
endDate:
|
|
918
|
+
startDate: EdubridgeDateString,
|
|
919
|
+
endDate: EdubridgeDateString,
|
|
870
920
|
timezone: z7.string().optional()
|
|
871
921
|
});
|
|
872
922
|
var EdubridgeWeeklyFactsParams = EmailOrStudentId.extend({
|
|
873
|
-
weekDate:
|
|
923
|
+
weekDate: EdubridgeDateString,
|
|
874
924
|
timezone: z7.string().optional()
|
|
875
925
|
});
|
|
876
926
|
var EdubridgeEnrollmentFactsParams = z7.object({
|
|
877
927
|
enrollmentId: NonEmptyString,
|
|
878
|
-
startDate:
|
|
879
|
-
endDate:
|
|
928
|
+
startDate: EdubridgeDateString.optional(),
|
|
929
|
+
endDate: EdubridgeDateString.optional(),
|
|
880
930
|
timezone: z7.string().optional()
|
|
881
931
|
});
|
|
882
932
|
// ../../types/src/zod/masterytrack.ts
|
|
@@ -1898,8 +1948,8 @@ class AnalyticsResource {
|
|
|
1898
1948
|
params: {
|
|
1899
1949
|
email: validated.email,
|
|
1900
1950
|
studentId: validated.studentId,
|
|
1901
|
-
startDate: validated.startDate,
|
|
1902
|
-
endDate: validated.endDate,
|
|
1951
|
+
startDate: normalizeStartDate(validated.startDate, validated.timezone),
|
|
1952
|
+
endDate: normalizeEndDate(validated.endDate, validated.timezone),
|
|
1903
1953
|
timezone: validated.timezone
|
|
1904
1954
|
}
|
|
1905
1955
|
});
|
|
@@ -1911,7 +1961,7 @@ class AnalyticsResource {
|
|
|
1911
1961
|
params: {
|
|
1912
1962
|
email: validated.email,
|
|
1913
1963
|
studentId: validated.studentId,
|
|
1914
|
-
weekDate: validated.weekDate,
|
|
1964
|
+
weekDate: normalizeStartDate(validated.weekDate, validated.timezone),
|
|
1915
1965
|
timezone: validated.timezone
|
|
1916
1966
|
}
|
|
1917
1967
|
});
|
|
@@ -1921,8 +1971,8 @@ class AnalyticsResource {
|
|
|
1921
1971
|
const validated = validateWithSchema(EdubridgeEnrollmentFactsParams, params, "enrollment facts params");
|
|
1922
1972
|
const response = await this.transport.request(`${this.transport.paths.base}/analytics/enrollment/${encodeURIComponent(validated.enrollmentId)}`, {
|
|
1923
1973
|
params: {
|
|
1924
|
-
startDate: validated.startDate,
|
|
1925
|
-
endDate: validated.endDate,
|
|
1974
|
+
startDate: validated.startDate ? normalizeStartDate(validated.startDate, validated.timezone) : undefined,
|
|
1975
|
+
endDate: validated.endDate ? normalizeEndDate(validated.endDate, validated.timezone) : undefined,
|
|
1926
1976
|
timezone: validated.timezone
|
|
1927
1977
|
}
|
|
1928
1978
|
});
|
package/dist/index.js
CHANGED
package/dist/utils.js
CHANGED