@davidwoods/skylight-mcp 1.18.1 → 1.20.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 +70 -9
- package/dist/api/client.d.ts +7 -1
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +20 -8
- package/dist/api/client.js.map +1 -1
- package/dist/api/endpoints/calendar.d.ts +13 -0
- package/dist/api/endpoints/calendar.d.ts.map +1 -1
- package/dist/api/endpoints/calendar.js +26 -0
- package/dist/api/endpoints/calendar.js.map +1 -1
- package/dist/api/oauth.d.ts +4 -1
- package/dist/api/oauth.d.ts.map +1 -1
- package/dist/api/oauth.js +10 -8
- package/dist/api/oauth.js.map +1 -1
- package/dist/lib.d.ts +151 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +268 -0
- package/dist/lib.js.map +1 -0
- package/dist/setup.d.ts +51 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +164 -0
- package/dist/setup.js.map +1 -0
- package/dist/tools/calendar.d.ts.map +1 -1
- package/dist/tools/calendar.js +23 -4
- package/dist/tools/calendar.js.map +1 -1
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +12 -1
- package/dist/tools/registry.js.map +1 -1
- package/dist/utils/errors.d.ts +9 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +13 -0
- package/dist/utils/errors.js.map +1 -1
- package/package.json +14 -2
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library entry point (experimental). The only module an importer may load:
|
|
3
|
+
* package.json `exports` lists this file and nothing else.
|
|
4
|
+
*
|
|
5
|
+
* import { createSkylight } from "@davidwoods/skylight-mcp";
|
|
6
|
+
*
|
|
7
|
+
* Guarantees, each covered by tests/library-*.test.ts from the importer's side:
|
|
8
|
+
* - The API host is pinned in code. There is no host, base URL or fetch option; an
|
|
9
|
+
* unknown option is refused, not ignored.
|
|
10
|
+
* - Returned objects are plain JSON-safe DTOs. They never carry emails, event uids,
|
|
11
|
+
* calendar or account ids, or a subscription feed address.
|
|
12
|
+
* - No function takes a URL or a feed address (so the feed-address helper is not exported either).
|
|
13
|
+
* - Importing this module starts nothing and reads nothing from process.argv.
|
|
14
|
+
*
|
|
15
|
+
* Phase 1 is read-only. Writes, deletes, messages, source-calendar management and
|
|
16
|
+
* login are deliberately not exported.
|
|
17
|
+
*
|
|
18
|
+
* Honest limit: an importer holds a live bearer token and can do whatever the token
|
|
19
|
+
* allows. These guards stop accidents and token leakage, not a malicious importer.
|
|
20
|
+
*/
|
|
21
|
+
import type { CredentialStore } from "./api/credential-types.js";
|
|
22
|
+
export type { CredentialStore };
|
|
23
|
+
/** Where the sign-in comes from: a store that refreshes it, or a fixed token that does not. */
|
|
24
|
+
export type SkylightCredential = CredentialStore | {
|
|
25
|
+
token: string;
|
|
26
|
+
};
|
|
27
|
+
export interface CreateSkylightOptions {
|
|
28
|
+
/** Household id: digits, from the Skylight web app's URLs. */
|
|
29
|
+
frameId: string;
|
|
30
|
+
/** IANA zone, for example "America/Los_Angeles". */
|
|
31
|
+
timezone: string;
|
|
32
|
+
credential: SkylightCredential;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* An event. `id` is opaque: a repeating event's occurrence ids embed the start time and
|
|
36
|
+
* CHANGE after a time edit, so never store or compare ids across edits. `seriesId` is the
|
|
37
|
+
* series number for occurrences of a repeating event, else null.
|
|
38
|
+
*/
|
|
39
|
+
export interface EventDto {
|
|
40
|
+
id: string;
|
|
41
|
+
title: string;
|
|
42
|
+
/** ISO 8601 with offset, or a local-midnight stamp for all-day events. */
|
|
43
|
+
start: string | null;
|
|
44
|
+
end: string | null;
|
|
45
|
+
allDay: boolean;
|
|
46
|
+
location: string | null;
|
|
47
|
+
profiles: string[];
|
|
48
|
+
labels: string[];
|
|
49
|
+
recurring: boolean;
|
|
50
|
+
seriesId: string | null;
|
|
51
|
+
editable: boolean;
|
|
52
|
+
source: "skylight" | "google" | "feed" | "other";
|
|
53
|
+
}
|
|
54
|
+
export interface SourceDto {
|
|
55
|
+
id: string;
|
|
56
|
+
/** An email-shaped label is replaced, so no address leaves the library. */
|
|
57
|
+
label: string;
|
|
58
|
+
kind: "google" | "feed" | "other";
|
|
59
|
+
role: string | null;
|
|
60
|
+
editable: boolean;
|
|
61
|
+
/** Scheme and host of a subscription feed only; null otherwise. */
|
|
62
|
+
host: string | null;
|
|
63
|
+
}
|
|
64
|
+
export interface ProfileDto {
|
|
65
|
+
id: string;
|
|
66
|
+
label: string;
|
|
67
|
+
color: string | null;
|
|
68
|
+
}
|
|
69
|
+
export interface ChoreDto {
|
|
70
|
+
id: string;
|
|
71
|
+
title: string;
|
|
72
|
+
date: string | null;
|
|
73
|
+
time: string | null;
|
|
74
|
+
status: string;
|
|
75
|
+
done: boolean;
|
|
76
|
+
profile: string | null;
|
|
77
|
+
upForGrabs: boolean;
|
|
78
|
+
routine: boolean;
|
|
79
|
+
recurring: boolean;
|
|
80
|
+
points: number | null;
|
|
81
|
+
}
|
|
82
|
+
export interface MealSittingDto {
|
|
83
|
+
id: string;
|
|
84
|
+
dates: string[];
|
|
85
|
+
title: string | null;
|
|
86
|
+
category: string | null;
|
|
87
|
+
recipeId: string | null;
|
|
88
|
+
recurring: boolean;
|
|
89
|
+
}
|
|
90
|
+
export interface RecipeDto {
|
|
91
|
+
id: string;
|
|
92
|
+
title: string | null;
|
|
93
|
+
}
|
|
94
|
+
export interface MealCategoryDto {
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
}
|
|
98
|
+
export interface ListDto {
|
|
99
|
+
id: string;
|
|
100
|
+
label: string;
|
|
101
|
+
kind: string;
|
|
102
|
+
color: string | null;
|
|
103
|
+
}
|
|
104
|
+
export interface ListItemDto {
|
|
105
|
+
id: string;
|
|
106
|
+
label: string;
|
|
107
|
+
done: boolean;
|
|
108
|
+
section: string | null;
|
|
109
|
+
}
|
|
110
|
+
export interface Skylight {
|
|
111
|
+
calendar: {
|
|
112
|
+
/** Events from `from` to `to`, both YYYY-MM-DD, both days included. */
|
|
113
|
+
events(range: {
|
|
114
|
+
from: string;
|
|
115
|
+
to: string;
|
|
116
|
+
}): Promise<EventDto[]>;
|
|
117
|
+
sources(): Promise<SourceDto[]>;
|
|
118
|
+
};
|
|
119
|
+
profiles: {
|
|
120
|
+
list(): Promise<ProfileDto[]>;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Chores for one day (`date`) or a range (`from` and `to`, both included, at most 31 days).
|
|
124
|
+
* Pass one or the other, not both. A repeating chore appears once per day it falls on; `date`
|
|
125
|
+
* on each item is that day.
|
|
126
|
+
*/
|
|
127
|
+
chores: {
|
|
128
|
+
list(options: {
|
|
129
|
+
date: string;
|
|
130
|
+
profile?: string;
|
|
131
|
+
} | {
|
|
132
|
+
from: string;
|
|
133
|
+
to: string;
|
|
134
|
+
profile?: string;
|
|
135
|
+
}): Promise<ChoreDto[]>;
|
|
136
|
+
};
|
|
137
|
+
meals: {
|
|
138
|
+
sittings(range: {
|
|
139
|
+
from: string;
|
|
140
|
+
to: string;
|
|
141
|
+
}): Promise<MealSittingDto[]>;
|
|
142
|
+
recipes(): Promise<RecipeDto[]>;
|
|
143
|
+
categories(): Promise<MealCategoryDto[]>;
|
|
144
|
+
};
|
|
145
|
+
lists: {
|
|
146
|
+
list(): Promise<ListDto[]>;
|
|
147
|
+
items(listId: string): Promise<ListItemDto[]>;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
export declare function createSkylight(options: CreateSkylightOptions): Skylight;
|
|
151
|
+
//# sourceMappingURL=lib.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,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,MAAM,CAAC,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjE,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;KACjC,CAAC;IACF,QAAQ,EAAE;QAAE,IAAI,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;KAAE,CAAC;IAC5C;;;;OAIG;IACH,MAAM,EAAE;QAAE,IAAI,CAAC,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,CAAC,EAAE,MAAM,CAAA;SAAE,GAAG;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,CAAC;YAAC,OAAO,CAAC,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;KAAE,CAAC;IACpI,KAAK,EAAE;QACL,QAAQ,CAAC,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;QACzE,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;QAChC,UAAU,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;KAC1C,CAAC;IACF,KAAK,EAAE;QACL,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3B,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;KAC/C,CAAC;CACH;AA0ID,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,QAAQ,CA4GvE"}
|
package/dist/lib.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library entry point (experimental). The only module an importer may load:
|
|
3
|
+
* package.json `exports` lists this file and nothing else.
|
|
4
|
+
*
|
|
5
|
+
* import { createSkylight } from "@davidwoods/skylight-mcp";
|
|
6
|
+
*
|
|
7
|
+
* Guarantees, each covered by tests/library-*.test.ts from the importer's side:
|
|
8
|
+
* - The API host is pinned in code. There is no host, base URL or fetch option; an
|
|
9
|
+
* unknown option is refused, not ignored.
|
|
10
|
+
* - Returned objects are plain JSON-safe DTOs. They never carry emails, event uids,
|
|
11
|
+
* calendar or account ids, or a subscription feed address.
|
|
12
|
+
* - No function takes a URL or a feed address (so the feed-address helper is not exported either).
|
|
13
|
+
* - Importing this module starts nothing and reads nothing from process.argv.
|
|
14
|
+
*
|
|
15
|
+
* Phase 1 is read-only. Writes, deletes, messages, source-calendar management and
|
|
16
|
+
* login are deliberately not exported.
|
|
17
|
+
*
|
|
18
|
+
* Honest limit: an importer holds a live bearer token and can do whatever the token
|
|
19
|
+
* allows. These guards stop accidents and token leakage, not a malicious importer.
|
|
20
|
+
*/
|
|
21
|
+
import { SkylightClient } from "./api/client.js";
|
|
22
|
+
import { runWithContext } from "./context.js";
|
|
23
|
+
import { getCalendarEvents, getSourceCalendars } from "./api/endpoints/calendar.js";
|
|
24
|
+
import { getCategories } from "./api/endpoints/categories.js";
|
|
25
|
+
import { getChores } from "./api/endpoints/chores.js";
|
|
26
|
+
import { getListWithItems, getLists } from "./api/endpoints/lists.js";
|
|
27
|
+
import { getMealCategories, getMealSittings, getRecipes, mealCategoryName } from "./api/endpoints/meals.js";
|
|
28
|
+
import { isChoreDone, parseOccurrenceId } from "./api/endpoints/chores.js";
|
|
29
|
+
import { addDays } from "./utils/schedule.js";
|
|
30
|
+
import { redactFeedUrl } from "./utils/redact.js";
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// Validation: refuse, never ignore.
|
|
33
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
34
|
+
const EMAIL = /[^\s@<>()"',;:]+@[^\s@<>()"',;:]+\.[^\s@<>()"',;:]+/;
|
|
35
|
+
const OPTION_KEYS = new Set(["frameId", "timezone", "credential"]);
|
|
36
|
+
function assertDate(value, name) {
|
|
37
|
+
if (typeof value !== "string" || !DATE.test(value) || Number.isNaN(Date.parse(`${value}T00:00:00Z`))) {
|
|
38
|
+
throw new Error(`${name} must be a date, YYYY-MM-DD.`);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
function assertRange(range) {
|
|
43
|
+
const from = assertDate(range?.from, "from");
|
|
44
|
+
const to = assertDate(range?.to, "to");
|
|
45
|
+
if (to < from)
|
|
46
|
+
throw new Error("to is before from.");
|
|
47
|
+
return { from, to };
|
|
48
|
+
}
|
|
49
|
+
function daysBetween(from, to) {
|
|
50
|
+
return Math.round((Date.parse(`${to}T00:00:00Z`) - Date.parse(`${from}T00:00:00Z`)) / 86_400_000);
|
|
51
|
+
}
|
|
52
|
+
function isStore(value) {
|
|
53
|
+
const v = value;
|
|
54
|
+
return !!v && typeof v === "object" && typeof v.read === "function" && typeof v.write === "function" && typeof v.delete === "function";
|
|
55
|
+
}
|
|
56
|
+
function validateOptions(options) {
|
|
57
|
+
if (!options || typeof options !== "object")
|
|
58
|
+
throw new Error("createSkylight needs an options object.");
|
|
59
|
+
for (const key of Object.keys(options)) {
|
|
60
|
+
if (!OPTION_KEYS.has(key))
|
|
61
|
+
throw new Error(`Unknown option "${key}". The API host is fixed and cannot be configured.`);
|
|
62
|
+
}
|
|
63
|
+
const { frameId, timezone, credential } = options;
|
|
64
|
+
if (typeof frameId !== "string" || !/^\d+$/.test(frameId))
|
|
65
|
+
throw new Error("frameId must be the household's numeric id.");
|
|
66
|
+
if (typeof timezone !== "string")
|
|
67
|
+
throw new Error("timezone must be an IANA zone name.");
|
|
68
|
+
try {
|
|
69
|
+
new Intl.DateTimeFormat("en-US", { timeZone: timezone });
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
throw new Error("timezone must be an IANA zone name.");
|
|
73
|
+
}
|
|
74
|
+
if (isStore(credential)) {
|
|
75
|
+
return { config: { frameId, timezone, authType: "bearer" }, store: credential };
|
|
76
|
+
}
|
|
77
|
+
const keys = credential && typeof credential === "object" ? Object.keys(credential) : [];
|
|
78
|
+
if (keys.length === 1 && keys[0] === "token" && typeof credential.token === "string" && credential.token) {
|
|
79
|
+
return { config: { frameId, timezone, authType: "bearer", token: credential.token }, store: null };
|
|
80
|
+
}
|
|
81
|
+
throw new Error("credential must be a credential store or { token }.");
|
|
82
|
+
}
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// Projection: raw JSON:API in, DTOs out. Every field is named here; nothing is spread.
|
|
85
|
+
function categoryIds(event) {
|
|
86
|
+
const ids = new Set();
|
|
87
|
+
for (const ref of event.relationships?.categories?.data ?? [])
|
|
88
|
+
if (ref?.id)
|
|
89
|
+
ids.add(String(ref.id));
|
|
90
|
+
const single = event.relationships?.category?.data?.id;
|
|
91
|
+
if (single)
|
|
92
|
+
ids.add(String(single));
|
|
93
|
+
const fromAttrs = event.attributes.category_ids;
|
|
94
|
+
if (Array.isArray(fromAttrs))
|
|
95
|
+
for (const id of fromAttrs)
|
|
96
|
+
ids.add(String(id));
|
|
97
|
+
return [...ids];
|
|
98
|
+
}
|
|
99
|
+
const str = (v) => (typeof v === "string" && v !== "" ? v : null);
|
|
100
|
+
function toEvent(event, categories) {
|
|
101
|
+
const a = event.attributes;
|
|
102
|
+
const profiles = [];
|
|
103
|
+
const labels = [];
|
|
104
|
+
for (const id of categoryIds(event)) {
|
|
105
|
+
const c = categories.get(id);
|
|
106
|
+
const label = str(c?.attributes.label);
|
|
107
|
+
if (!c || !label)
|
|
108
|
+
continue;
|
|
109
|
+
(c.attributes.linked_to_profile === true ? profiles : labels).push(label);
|
|
110
|
+
}
|
|
111
|
+
const id = String(event.id);
|
|
112
|
+
const composite = /^(\d+)-\d+$/.exec(id);
|
|
113
|
+
const source = a.source === "skylight" ? "skylight" : a.source === "google" ? "google" : a.source === "ics_link" ? "feed" : "other";
|
|
114
|
+
return {
|
|
115
|
+
id,
|
|
116
|
+
title: str(a.summary) ?? "",
|
|
117
|
+
start: str(a.starts_at),
|
|
118
|
+
end: str(a.ends_at),
|
|
119
|
+
allDay: a.all_day === true,
|
|
120
|
+
location: str(a.location),
|
|
121
|
+
profiles,
|
|
122
|
+
labels,
|
|
123
|
+
recurring: a.recurring === true || a.recurring_config === true,
|
|
124
|
+
seriesId: composite ? composite[1] : null,
|
|
125
|
+
editable: a.editable !== false,
|
|
126
|
+
source,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function toSource(cal) {
|
|
130
|
+
const a = cal.attributes;
|
|
131
|
+
const kind = a.kind === "gmail" ? "google" : a.kind === "webcal" ? "feed" : "other";
|
|
132
|
+
let label = str(a.label) ?? "";
|
|
133
|
+
if (EMAIL.test(label))
|
|
134
|
+
label = kind === "google" ? "Google calendar" : "Calendar";
|
|
135
|
+
const sourceId = str(a.source_id);
|
|
136
|
+
const hostMatch = kind === "feed" && sourceId ? /^([a-z]+:\/\/[^/]+)/i.exec(redactFeedUrl(sourceId)) : null;
|
|
137
|
+
return {
|
|
138
|
+
id: String(cal.id),
|
|
139
|
+
label,
|
|
140
|
+
kind,
|
|
141
|
+
role: str(a.role),
|
|
142
|
+
editable: a.editable === true,
|
|
143
|
+
host: hostMatch ? hostMatch[1] : null,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function toChore(chore, names) {
|
|
147
|
+
const a = chore.attributes;
|
|
148
|
+
const cid = chore.relationships?.category?.data?.id;
|
|
149
|
+
return {
|
|
150
|
+
id: String(chore.id),
|
|
151
|
+
title: str(a.summary) ?? "",
|
|
152
|
+
// An occurrence of a repeating chore carries its own day in its id ({series}-{YYYY-MM-DD}-{HHMM},
|
|
153
|
+
// verified live for completions); `start` may be the series' first day.
|
|
154
|
+
date: parseOccurrenceId(String(chore.id))?.instanceDate ?? str(a.start),
|
|
155
|
+
time: str(a.start_time),
|
|
156
|
+
status: str(a.status) ?? "",
|
|
157
|
+
done: isChoreDone(a.status),
|
|
158
|
+
profile: cid ? (names.get(String(cid)) ?? null) : null,
|
|
159
|
+
upForGrabs: a.up_for_grabs === true,
|
|
160
|
+
routine: a.routine === true,
|
|
161
|
+
recurring: a.recurring === true,
|
|
162
|
+
points: typeof a.reward_points === "number" ? a.reward_points : null,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
export function createSkylight(options) {
|
|
167
|
+
const { config, store } = validateOptions(options);
|
|
168
|
+
// Quiet: no per-request trace lines in the importer's logs. Errors and warnings still print.
|
|
169
|
+
const client = new SkylightClient(config, store, { quiet: true });
|
|
170
|
+
const run = (fn) => runWithContext({ client, config }, fn);
|
|
171
|
+
return {
|
|
172
|
+
calendar: {
|
|
173
|
+
events: (range) => run(async () => {
|
|
174
|
+
const { from, to } = assertRange(range);
|
|
175
|
+
const [events, categories] = await Promise.all([
|
|
176
|
+
getCalendarEvents({ dateMin: from, dateMax: to, timezone: config.timezone }),
|
|
177
|
+
getCategories(),
|
|
178
|
+
]);
|
|
179
|
+
const byId = new Map(categories.map((c) => [String(c.id), c]));
|
|
180
|
+
return events.map((e) => toEvent(e, byId));
|
|
181
|
+
}),
|
|
182
|
+
sources: () => run(async () => (await getSourceCalendars()).map(toSource)),
|
|
183
|
+
},
|
|
184
|
+
profiles: {
|
|
185
|
+
list: () => run(async () => (await getCategories())
|
|
186
|
+
.filter((c) => c.attributes.linked_to_profile === true && str(c.attributes.label))
|
|
187
|
+
.map((c) => ({ id: String(c.id), label: c.attributes.label, color: str(c.attributes.color) }))),
|
|
188
|
+
},
|
|
189
|
+
chores: {
|
|
190
|
+
list: (opts) => run(async () => {
|
|
191
|
+
const o = (opts ?? {});
|
|
192
|
+
for (const key of Object.keys(o)) {
|
|
193
|
+
if (!["date", "from", "to", "profile"].includes(key))
|
|
194
|
+
throw new Error(`Unknown option "${key}".`);
|
|
195
|
+
}
|
|
196
|
+
let from;
|
|
197
|
+
let to;
|
|
198
|
+
if (o.date !== undefined) {
|
|
199
|
+
if (o.from !== undefined || o.to !== undefined)
|
|
200
|
+
throw new Error("Pass date, or from and to, not both.");
|
|
201
|
+
from = to = assertDate(o.date, "date");
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
({ from, to } = assertRange({ from: o.from, to: o.to }));
|
|
205
|
+
if (daysBetween(from, to) > 30)
|
|
206
|
+
throw new Error("A chores range is at most 31 days.");
|
|
207
|
+
}
|
|
208
|
+
// `before` is inclusive: the one-day call has always sent after = before = the day.
|
|
209
|
+
const result = await getChores({ after: from, before: to, includeLate: false, includeUpForGrabs: true });
|
|
210
|
+
const names = new Map(result.categories.map((c) => [String(c.id), c.attributes.label ?? ""]));
|
|
211
|
+
let chores = result.chores.map((c) => toChore(c, names));
|
|
212
|
+
if (o.profile !== undefined) {
|
|
213
|
+
if (typeof o.profile !== "string")
|
|
214
|
+
throw new Error("profile must be a profile name.");
|
|
215
|
+
const wanted = o.profile.trim().toLowerCase();
|
|
216
|
+
chores = chores.filter((c) => c.profile?.toLowerCase() === wanted);
|
|
217
|
+
}
|
|
218
|
+
return chores;
|
|
219
|
+
}),
|
|
220
|
+
},
|
|
221
|
+
meals: {
|
|
222
|
+
sittings: (range) => run(async () => {
|
|
223
|
+
const { from, to } = assertRange(range);
|
|
224
|
+
const [sittings, categories] = await Promise.all([
|
|
225
|
+
getMealSittings({ dateMin: from, dateMax: addDays(to, 1) }),
|
|
226
|
+
getMealCategories(),
|
|
227
|
+
]);
|
|
228
|
+
const names = new Map(categories.map((c) => [String(c.id), mealCategoryName(c)]));
|
|
229
|
+
return sittings.map((s) => {
|
|
230
|
+
const a = s.attributes;
|
|
231
|
+
const dates = a.instances?.length ? a.instances : a.date ? [a.date] : [];
|
|
232
|
+
const cid = s.relationships?.meal_category?.data?.id;
|
|
233
|
+
const rid = s.relationships?.meal_recipe?.data?.id;
|
|
234
|
+
return {
|
|
235
|
+
id: String(s.id),
|
|
236
|
+
dates: dates.filter((d) => DATE.test(d) && d >= from && d <= to),
|
|
237
|
+
title: str(a.summary),
|
|
238
|
+
category: cid ? (names.get(String(cid)) ?? null) : null,
|
|
239
|
+
recipeId: rid ? String(rid) : null,
|
|
240
|
+
recurring: a.recurring === true || Boolean(a.rrule),
|
|
241
|
+
};
|
|
242
|
+
});
|
|
243
|
+
}),
|
|
244
|
+
recipes: () => run(async () => (await getRecipes()).map((r) => ({ id: String(r.id), title: str(r.attributes.summary) }))),
|
|
245
|
+
categories: () => run(async () => (await getMealCategories()).map((c) => ({ id: String(c.id), name: mealCategoryName(c) }))),
|
|
246
|
+
},
|
|
247
|
+
lists: {
|
|
248
|
+
list: () => run(async () => (await getLists()).map((l) => ({
|
|
249
|
+
id: String(l.id),
|
|
250
|
+
label: str(l.attributes.label) ?? "",
|
|
251
|
+
kind: str(l.attributes.kind) ?? "",
|
|
252
|
+
color: str(l.attributes.color),
|
|
253
|
+
}))),
|
|
254
|
+
items: (listId) => run(async () => {
|
|
255
|
+
if (typeof listId !== "string" || !/^\d+$/.test(listId))
|
|
256
|
+
throw new Error("listId must be a numeric list id.");
|
|
257
|
+
const { items } = await getListWithItems(listId);
|
|
258
|
+
return items.map((i) => ({
|
|
259
|
+
id: String(i.id),
|
|
260
|
+
label: str(i.attributes.label) ?? "",
|
|
261
|
+
done: i.attributes.status === "completed",
|
|
262
|
+
section: str(i.attributes.section),
|
|
263
|
+
}));
|
|
264
|
+
}),
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=lib.js.map
|
package/dist/lib.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,i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C,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;oBAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;gBAC9G,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,gBAAgB,CAAC,MAAM,CAAC,CAAC;gBACjD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBACvB,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;oBAChB,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE;oBACpC,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC,MAAM,KAAK,WAAW;oBACzC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC;iBACnC,CAAC,CAAC,CAAC;YACN,CAAC,CAAC;SACL;KACF,CAAC;AACJ,CAAC"}
|
package/dist/setup.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { CredentialStore } from "./api/credential-types.js";
|
|
2
|
+
export type { CredentialStore };
|
|
3
|
+
/**
|
|
4
|
+
* Where the pending login lives between `beginLogin` and `completeLogin`. The value is an
|
|
5
|
+
* opaque string: store it as given, never log it, and make `take` atomic (return the value
|
|
6
|
+
* and delete it in one step) so a pending login cannot be used twice.
|
|
7
|
+
*/
|
|
8
|
+
export interface PendingLoginStore {
|
|
9
|
+
save(value: string): Promise<void>;
|
|
10
|
+
take(): Promise<string | null>;
|
|
11
|
+
}
|
|
12
|
+
export type SetupErrorCode = "bad_options" | "no_pending_login" | "expired" | "bad_redirect_url" | "state_mismatch" | "skylight_refused" | "store_failed";
|
|
13
|
+
/** Errors thrown here are plain `Error`s with `name` "SkylightSetupError" and a `code`. */
|
|
14
|
+
export interface SkylightSetupError extends Error {
|
|
15
|
+
name: "SkylightSetupError";
|
|
16
|
+
code: SetupErrorCode;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Start a sign-in. Saves the pending login in your store and returns the address to open in
|
|
20
|
+
* the person's browser. They sign in at Skylight, which then shows an address starting
|
|
21
|
+
* https://ourskylight.com/welcome?code=... ; pass that address to `completeLogin`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function beginLogin(options: {
|
|
24
|
+
pending: PendingLoginStore;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
loginUrl: string;
|
|
27
|
+
expiresInMinutes: number;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Finish a sign-in. Takes the pending login (so it cannot be used again, whatever happens
|
|
31
|
+
* next), checks the pasted address, exchanges the code at the pinned API host and writes the
|
|
32
|
+
* credential into your store. Nothing secret is returned. On any failure the credential
|
|
33
|
+
* store is not written.
|
|
34
|
+
*/
|
|
35
|
+
export declare function completeLogin(options: {
|
|
36
|
+
pending: PendingLoginStore;
|
|
37
|
+
credential: CredentialStore;
|
|
38
|
+
redirectUrl: string;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
signedIn: true;
|
|
41
|
+
expiresAt: number;
|
|
42
|
+
}>;
|
|
43
|
+
/** Whether your store holds a credential. Returns no part of it. */
|
|
44
|
+
export declare function loginStatus(options: {
|
|
45
|
+
credential: CredentialStore;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
signedIn: boolean;
|
|
48
|
+
expired: boolean;
|
|
49
|
+
expiresAt: number | null;
|
|
50
|
+
}>;
|
|
51
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAWjE,YAAY,EAAE,eAAe,EAAE,CAAC;AAEhC;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,IA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