@happyvertical/icalendar 0.0.0-stage → 0.100.2
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/AGENT.md +31 -0
- package/LICENSE +7 -0
- package/README.md +18 -2
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/metadata.json +30 -0
- package/package.json +50 -3
package/AGENT.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @happyvertical/icalendar
|
|
2
|
+
|
|
3
|
+
<!-- BEGIN AGENT:GENERATED -->
|
|
4
|
+
## Purpose
|
|
5
|
+
Bounded RFC 5545 iCalendar parsing facade
|
|
6
|
+
|
|
7
|
+
## Package Map
|
|
8
|
+
- Package: `@happyvertical/icalendar`
|
|
9
|
+
- Hierarchy path: `@happyvertical/sdk > packages > icalendar`
|
|
10
|
+
- Workspace position: `15 of 33` local packages
|
|
11
|
+
- Internal dependencies: none
|
|
12
|
+
- Internal dependents: none
|
|
13
|
+
- Knowledge graph files: `AGENT.md`, `metadata.json`, `ecosystem-manifest.json`
|
|
14
|
+
|
|
15
|
+
## Build & Test
|
|
16
|
+
```bash
|
|
17
|
+
pnpm --filter @happyvertical/icalendar build
|
|
18
|
+
pnpm --filter @happyvertical/icalendar test
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Agent Correction Loops
|
|
22
|
+
- If Vite or TypeScript reports missing packages, run `pnpm install` at the repo root and rerun `pnpm --filter @happyvertical/icalendar build`.
|
|
23
|
+
- If a change only affects runtime behavior, rerun `pnpm --filter @happyvertical/icalendar test` after rebuilding the package to confirm the failure is local.
|
|
24
|
+
- If failures span multiple packages or Turborepo ordering looks wrong, run `pnpm build` and `pnpm typecheck` from the repo root before retrying package-scoped commands.
|
|
25
|
+
|
|
26
|
+
## Ecosystem Relationships
|
|
27
|
+
- Provides: Bounded RFC 5545 iCalendar parsing facade
|
|
28
|
+
- Implements: none
|
|
29
|
+
- Requires: ical.js
|
|
30
|
+
- Stability: stable (Primary package surface is described as implemented and production-oriented.)
|
|
31
|
+
<!-- END AGENT:GENERATED -->
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright <2025> <Happy Vertical Corporation>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @happyvertical/icalendar
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@happyvertical/icalendar` provides a bounded, network-free RFC 5545 parsing
|
|
4
|
+
entry point. It delegates grammar and component handling to `ical.js`; callers
|
|
5
|
+
use the returned `ICAL.Component` to read standard properties.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { parseICalendar } from '@happyvertical/icalendar';
|
|
11
|
+
|
|
12
|
+
const calendar = parseICalendar(icsText);
|
|
13
|
+
const event = calendar.component.getFirstSubcomponent('vevent');
|
|
14
|
+
const uid = event?.getFirstPropertyValue('uid');
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`parseICalendar` enforces input, physical-line, unfolded-line, and component
|
|
18
|
+
limits before returning a single `VCALENDAR` document. It does not fetch URLs,
|
|
19
|
+
apply a floating-time policy, expand recurrence, or persist calendar data.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { default as ICAL } from 'ical.js';
|
|
2
|
+
export { ICAL };
|
|
3
|
+
/** An `ical.js` component available to calendar consumers. */
|
|
4
|
+
export type ICalendarComponent = InstanceType<typeof ICAL.Component>;
|
|
5
|
+
/** An `ical.js` property available to calendar consumers. */
|
|
6
|
+
export type ICalendarProperty = InstanceType<typeof ICAL.Property>;
|
|
7
|
+
/** A value returned by an `ical.js` property. */
|
|
8
|
+
export type ICalendarPropertyValue = ReturnType<ICalendarProperty['getFirstValue']>;
|
|
9
|
+
/** Resource limits applied before and immediately after RFC 5545 parsing. */
|
|
10
|
+
export interface ICalendarParseLimits {
|
|
11
|
+
/** Maximum UTF-8 bytes in the input. Default: 1 MiB. */
|
|
12
|
+
maxInputBytes?: number;
|
|
13
|
+
/** Maximum UTF-8 bytes in an individual physical line. Default: 16 KiB. */
|
|
14
|
+
maxPhysicalLineBytes?: number;
|
|
15
|
+
/** Maximum UTF-8 bytes in an unfolded logical line. Default: 64 KiB. */
|
|
16
|
+
maxUnfoldedLineBytes?: number;
|
|
17
|
+
/** Maximum component count, including the `VCALENDAR` root. Default: 10,000. */
|
|
18
|
+
maxComponents?: number;
|
|
19
|
+
}
|
|
20
|
+
/** Fully resolved limits reported with resource-limit failures. */
|
|
21
|
+
export interface ResolvedICalendarParseLimits {
|
|
22
|
+
maxInputBytes: number;
|
|
23
|
+
maxPhysicalLineBytes: number;
|
|
24
|
+
maxUnfoldedLineBytes: number;
|
|
25
|
+
maxComponents: number;
|
|
26
|
+
}
|
|
27
|
+
/** A parsed RFC 5545 document with a single `VCALENDAR` root component. */
|
|
28
|
+
export interface ICalendarDocument {
|
|
29
|
+
component: ICalendarComponent;
|
|
30
|
+
limits: ResolvedICalendarParseLimits;
|
|
31
|
+
}
|
|
32
|
+
/** Base class for the public iCalendar parser error contract. */
|
|
33
|
+
export declare class ICalendarError extends Error {
|
|
34
|
+
constructor(message: string, options?: ErrorOptions);
|
|
35
|
+
}
|
|
36
|
+
/** The input exceeded a configured parser resource limit. */
|
|
37
|
+
export declare class ICalendarLimitError extends ICalendarError {
|
|
38
|
+
readonly limit: keyof ResolvedICalendarParseLimits;
|
|
39
|
+
readonly actual: number;
|
|
40
|
+
readonly maximum: number;
|
|
41
|
+
constructor(limit: keyof ResolvedICalendarParseLimits, actual: number, maximum: number);
|
|
42
|
+
}
|
|
43
|
+
/** `ical.js` rejected malformed RFC 5545 input. */
|
|
44
|
+
export declare class ICalendarParseError extends ICalendarError {
|
|
45
|
+
}
|
|
46
|
+
/** Parsed input did not contain exactly one `VCALENDAR` document root. */
|
|
47
|
+
export declare class ICalendarDocumentError extends ICalendarError {
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parse one bounded RFC 5545 `VCALENDAR` document.
|
|
51
|
+
*
|
|
52
|
+
* This function deliberately does not fetch a feed, choose a floating-time
|
|
53
|
+
* policy, expand recurrence, or persist parsed input. Consumers can use the
|
|
54
|
+
* returned public `ical.js` component API to apply their own domain rules.
|
|
55
|
+
*/
|
|
56
|
+
export declare function parseICalendar(input: string, limits?: ICalendarParseLimits): ICalendarDocument;
|
|
57
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,8DAA8D;AAC9D,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC,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BAAuB,SAAQ,cAAc;CAAG;AAiH7D;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,oBAAoB,GAC5B,iBAAiB,CAkDnB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import ICAL from "ical.js";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
/** Base class for the public iCalendar parser error contract. */
|
|
4
|
+
var ICalendarError = class extends Error {
|
|
5
|
+
constructor(message, options) {
|
|
6
|
+
super(message, options);
|
|
7
|
+
this.name = new.target.name;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
/** The input exceeded a configured parser resource limit. */
|
|
11
|
+
var ICalendarLimitError = class extends ICalendarError {
|
|
12
|
+
limit;
|
|
13
|
+
actual;
|
|
14
|
+
maximum;
|
|
15
|
+
constructor(limit, actual, maximum) {
|
|
16
|
+
super(`${limit} limit exceeded: ${actual} > ${maximum}`);
|
|
17
|
+
this.limit = limit;
|
|
18
|
+
this.actual = actual;
|
|
19
|
+
this.maximum = maximum;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/** `ical.js` rejected malformed RFC 5545 input. */
|
|
23
|
+
var ICalendarParseError = class extends ICalendarError {};
|
|
24
|
+
/** Parsed input did not contain exactly one `VCALENDAR` document root. */
|
|
25
|
+
var ICalendarDocumentError = class extends ICalendarError {};
|
|
26
|
+
var DEFAULT_LIMITS = {
|
|
27
|
+
maxInputBytes: 1024 * 1024,
|
|
28
|
+
maxPhysicalLineBytes: 16 * 1024,
|
|
29
|
+
maxUnfoldedLineBytes: 64 * 1024,
|
|
30
|
+
maxComponents: 1e4
|
|
31
|
+
};
|
|
32
|
+
function resolveLimits(limits) {
|
|
33
|
+
const resolved = {
|
|
34
|
+
...DEFAULT_LIMITS,
|
|
35
|
+
...limits
|
|
36
|
+
};
|
|
37
|
+
for (const [name, value] of Object.entries(resolved)) if (!Number.isSafeInteger(value) || value < 1) throw new RangeError(`${name} must be a positive safe integer`);
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
function utf8ByteLength(value) {
|
|
41
|
+
return new TextEncoder().encode(value).byteLength;
|
|
42
|
+
}
|
|
43
|
+
function enforceLineLimits(input, limits) {
|
|
44
|
+
let logicalLine = "";
|
|
45
|
+
let hasLogicalLine = false;
|
|
46
|
+
const logicalLines = [];
|
|
47
|
+
const checkLogicalLine = () => {
|
|
48
|
+
if (!hasLogicalLine) return;
|
|
49
|
+
const byteLength = utf8ByteLength(logicalLine);
|
|
50
|
+
if (byteLength > limits.maxUnfoldedLineBytes) throw new ICalendarLimitError("maxUnfoldedLineBytes", byteLength, limits.maxUnfoldedLineBytes);
|
|
51
|
+
logicalLines.push(logicalLine);
|
|
52
|
+
};
|
|
53
|
+
for (const physicalLine of input.split(/\r\n|[\n\r]/)) {
|
|
54
|
+
const byteLength = utf8ByteLength(physicalLine);
|
|
55
|
+
if (byteLength > limits.maxPhysicalLineBytes) throw new ICalendarLimitError("maxPhysicalLineBytes", byteLength, limits.maxPhysicalLineBytes);
|
|
56
|
+
if (hasLogicalLine && (physicalLine.startsWith(" ") || physicalLine.startsWith(" "))) {
|
|
57
|
+
logicalLine += physicalLine.slice(1);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
checkLogicalLine();
|
|
61
|
+
logicalLine = physicalLine;
|
|
62
|
+
hasLogicalLine = true;
|
|
63
|
+
}
|
|
64
|
+
checkLogicalLine();
|
|
65
|
+
return logicalLines;
|
|
66
|
+
}
|
|
67
|
+
function assertExactlyOneCalendarDocument(logicalLines) {
|
|
68
|
+
let componentDepth = 0;
|
|
69
|
+
let calendarRoots = 0;
|
|
70
|
+
for (const logicalLine of logicalLines) {
|
|
71
|
+
const begin = /^BEGIN:([^;:]+)$/i.exec(logicalLine);
|
|
72
|
+
if (begin) {
|
|
73
|
+
if (componentDepth === 0 && begin[1].toUpperCase() === "VCALENDAR") calendarRoots += 1;
|
|
74
|
+
componentDepth += 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (/^END:[^;:]+$/i.test(logicalLine)) componentDepth = Math.max(0, componentDepth - 1);
|
|
78
|
+
}
|
|
79
|
+
if (calendarRoots !== 1) throw new ICalendarDocumentError("Expected exactly one top-level VCALENDAR document");
|
|
80
|
+
}
|
|
81
|
+
function countComponents(component) {
|
|
82
|
+
let count = 0;
|
|
83
|
+
const pending = [component];
|
|
84
|
+
while (pending.length > 0) {
|
|
85
|
+
const current = pending.pop();
|
|
86
|
+
if (!current) continue;
|
|
87
|
+
count += 1;
|
|
88
|
+
pending.push(...current.getAllSubcomponents());
|
|
89
|
+
}
|
|
90
|
+
return count;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Parse one bounded RFC 5545 `VCALENDAR` document.
|
|
94
|
+
*
|
|
95
|
+
* This function deliberately does not fetch a feed, choose a floating-time
|
|
96
|
+
* policy, expand recurrence, or persist parsed input. Consumers can use the
|
|
97
|
+
* returned public `ical.js` component API to apply their own domain rules.
|
|
98
|
+
*/
|
|
99
|
+
function parseICalendar(input, limits) {
|
|
100
|
+
const resolvedLimits = resolveLimits(limits);
|
|
101
|
+
const inputBytes = utf8ByteLength(input);
|
|
102
|
+
if (inputBytes > resolvedLimits.maxInputBytes) throw new ICalendarLimitError("maxInputBytes", inputBytes, resolvedLimits.maxInputBytes);
|
|
103
|
+
assertExactlyOneCalendarDocument(enforceLineLimits(input, resolvedLimits));
|
|
104
|
+
let parsed;
|
|
105
|
+
try {
|
|
106
|
+
parsed = ICAL.parse(input);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
throw new ICalendarParseError("Invalid RFC 5545 input", { cause: error });
|
|
109
|
+
}
|
|
110
|
+
if (!Array.isArray(parsed) || typeof parsed[0] !== "string") throw new ICalendarDocumentError("Expected exactly one RFC 5545 calendar document");
|
|
111
|
+
let component;
|
|
112
|
+
try {
|
|
113
|
+
component = new ICAL.Component(parsed);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
throw new ICalendarParseError("Invalid RFC 5545 component", { cause: error });
|
|
116
|
+
}
|
|
117
|
+
if (component.name !== "vcalendar") throw new ICalendarDocumentError("Expected a VCALENDAR document root");
|
|
118
|
+
const componentCount = countComponents(component);
|
|
119
|
+
if (componentCount > resolvedLimits.maxComponents) throw new ICalendarLimitError("maxComponents", componentCount, resolvedLimits.maxComponents);
|
|
120
|
+
return {
|
|
121
|
+
component,
|
|
122
|
+
limits: resolvedLimits
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { ICAL, ICalendarDocumentError, ICalendarError, ICalendarLimitError, ICalendarParseError, parseICalendar };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import ICAL from 'ical.js';\n\nexport { ICAL };\n\n/** An `ical.js` component available to calendar consumers. */\nexport type ICalendarComponent = InstanceType<typeof ICAL.Component>;\n/** An `ical.js` property available to calendar consumers. */\nexport type ICalendarProperty = InstanceType<typeof ICAL.Property>;\n/** A value returned by an `ical.js` property. */\nexport type ICalendarPropertyValue = ReturnType<\n ICalendarProperty['getFirstValue']\n>;\n\n/** Resource limits applied before and immediately after RFC 5545 parsing. */\nexport interface ICalendarParseLimits {\n /** Maximum UTF-8 bytes in the input. Default: 1 MiB. */\n maxInputBytes?: number;\n /** Maximum UTF-8 bytes in an individual physical line. Default: 16 KiB. */\n maxPhysicalLineBytes?: number;\n /** Maximum UTF-8 bytes in an unfolded logical line. Default: 64 KiB. */\n maxUnfoldedLineBytes?: number;\n /** Maximum component count, including the `VCALENDAR` root. Default: 10,000. */\n maxComponents?: number;\n}\n\n/** Fully resolved limits reported with resource-limit failures. */\nexport interface ResolvedICalendarParseLimits {\n maxInputBytes: number;\n maxPhysicalLineBytes: number;\n maxUnfoldedLineBytes: number;\n maxComponents: number;\n}\n\n/** A parsed RFC 5545 document with a single `VCALENDAR` root component. */\nexport interface ICalendarDocument {\n component: ICalendarComponent;\n limits: ResolvedICalendarParseLimits;\n}\n\n/** Base class for the public iCalendar parser error contract. */\nexport class ICalendarError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n }\n}\n\n/** The input exceeded a configured parser resource limit. */\nexport class ICalendarLimitError extends ICalendarError {\n constructor(\n readonly limit: keyof ResolvedICalendarParseLimits,\n readonly actual: number,\n readonly maximum: number,\n ) {\n super(`${limit} limit exceeded: ${actual} > ${maximum}`);\n }\n}\n\n/** `ical.js` rejected malformed RFC 5545 input. */\nexport class ICalendarParseError extends ICalendarError {}\n\n/** Parsed input did not contain exactly one `VCALENDAR` document root. */\nexport class ICalendarDocumentError extends ICalendarError {}\n\nconst DEFAULT_LIMITS: ResolvedICalendarParseLimits = {\n maxInputBytes: 1024 * 1024,\n maxPhysicalLineBytes: 16 * 1024,\n maxUnfoldedLineBytes: 64 * 1024,\n maxComponents: 10_000,\n};\n\nfunction resolveLimits(\n limits: ICalendarParseLimits | undefined,\n): ResolvedICalendarParseLimits {\n const resolved = { ...DEFAULT_LIMITS, ...limits };\n for (const [name, value] of Object.entries(resolved)) {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new RangeError(`${name} must be a positive safe integer`);\n }\n }\n return resolved;\n}\n\nfunction utf8ByteLength(value: string): number {\n return new TextEncoder().encode(value).byteLength;\n}\n\nfunction enforceLineLimits(\n input: string,\n limits: ResolvedICalendarParseLimits,\n): string[] {\n let logicalLine = '';\n let hasLogicalLine = false;\n const logicalLines: string[] = [];\n\n const checkLogicalLine = (): void => {\n if (!hasLogicalLine) return;\n const byteLength = utf8ByteLength(logicalLine);\n if (byteLength > limits.maxUnfoldedLineBytes) {\n throw new ICalendarLimitError(\n 'maxUnfoldedLineBytes',\n byteLength,\n limits.maxUnfoldedLineBytes,\n );\n }\n logicalLines.push(logicalLine);\n };\n\n for (const physicalLine of input.split(/\\r\\n|[\\n\\r]/)) {\n const byteLength = utf8ByteLength(physicalLine);\n if (byteLength > limits.maxPhysicalLineBytes) {\n throw new ICalendarLimitError(\n 'maxPhysicalLineBytes',\n byteLength,\n limits.maxPhysicalLineBytes,\n );\n }\n\n if (\n hasLogicalLine &&\n (physicalLine.startsWith(' ') || physicalLine.startsWith('\\t'))\n ) {\n logicalLine += physicalLine.slice(1);\n continue;\n }\n\n checkLogicalLine();\n logicalLine = physicalLine;\n hasLogicalLine = true;\n }\n\n checkLogicalLine();\n return logicalLines;\n}\n\nfunction assertExactlyOneCalendarDocument(logicalLines: string[]): void {\n let componentDepth = 0;\n let calendarRoots = 0;\n\n for (const logicalLine of logicalLines) {\n const begin = /^BEGIN:([^;:]+)$/i.exec(logicalLine);\n if (begin) {\n if (componentDepth === 0 && begin[1].toUpperCase() === 'VCALENDAR') {\n calendarRoots += 1;\n }\n componentDepth += 1;\n continue;\n }\n\n if (/^END:[^;:]+$/i.test(logicalLine)) {\n componentDepth = Math.max(0, componentDepth - 1);\n }\n }\n\n if (calendarRoots !== 1) {\n throw new ICalendarDocumentError(\n 'Expected exactly one top-level VCALENDAR document',\n );\n }\n}\n\nfunction countComponents(component: ICalendarComponent): number {\n let count = 0;\n const pending = [component];\n\n while (pending.length > 0) {\n const current = pending.pop();\n if (!current) continue;\n count += 1;\n pending.push(...current.getAllSubcomponents());\n }\n\n return count;\n}\n\n/**\n * Parse one bounded RFC 5545 `VCALENDAR` document.\n *\n * This function deliberately does not fetch a feed, choose a floating-time\n * policy, expand recurrence, or persist parsed input. Consumers can use the\n * returned public `ical.js` component API to apply their own domain rules.\n */\nexport function parseICalendar(\n input: string,\n limits?: ICalendarParseLimits,\n): ICalendarDocument {\n const resolvedLimits = resolveLimits(limits);\n const inputBytes = utf8ByteLength(input);\n if (inputBytes > resolvedLimits.maxInputBytes) {\n throw new ICalendarLimitError(\n 'maxInputBytes',\n inputBytes,\n resolvedLimits.maxInputBytes,\n );\n }\n\n const logicalLines = enforceLineLimits(input, resolvedLimits);\n assertExactlyOneCalendarDocument(logicalLines);\n\n let parsed: unknown;\n try {\n parsed = ICAL.parse(input);\n } catch (error) {\n throw new ICalendarParseError('Invalid RFC 5545 input', { cause: error });\n }\n\n if (!Array.isArray(parsed) || typeof parsed[0] !== 'string') {\n throw new ICalendarDocumentError(\n 'Expected exactly one RFC 5545 calendar document',\n );\n }\n\n let component: ICalendarComponent;\n try {\n component = new ICAL.Component(parsed);\n } catch (error) {\n throw new ICalendarParseError('Invalid RFC 5545 component', {\n cause: error,\n });\n }\n\n if (component.name !== 'vcalendar') {\n throw new ICalendarDocumentError('Expected a VCALENDAR document root');\n }\n\n const componentCount = countComponents(component);\n if (componentCount > resolvedLimits.maxComponents) {\n throw new ICalendarLimitError(\n 'maxComponents',\n componentCount,\n resolvedLimits.maxComponents,\n );\n }\n\n return { component, limits: resolvedLimits };\n}\n"],"mappings":";;;AAwCA,IAAa,iBAAb,cAAoC,MAAM;CACxC,YAAY,SAAiB,SAAwB;EACnD,MAAM,SAAS,OAAO;EACtB,KAAK,OAAO,IAAI,OAAO;CACzB;AACF;;AAGA,IAAa,sBAAb,cAAyC,eAAe;CAE3C;CACA;CACA;CAHX,YACE,OACA,QACA,SACA;EACA,MAAM,GAAG,MAAM,mBAAmB,OAAO,KAAK,SAAS;EAJ9C,KAAA,QAAA;EACA,KAAA,SAAA;EACA,KAAA,UAAA;CAGX;AACF;;AAGA,IAAa,sBAAb,cAAyC,eAAe,CAAC;;AAGzD,IAAa,yBAAb,cAA4C,eAAe,CAAC;AAE5D,IAAM,iBAA+C;CACnD,eAAe,OAAO;CACtB,sBAAsB,KAAK;CAC3B,sBAAsB,KAAK;CAC3B,eAAe;AACjB;AAEA,SAAS,cACP,QAC8B;CAC9B,MAAM,WAAW;EAAE,GAAG;EAAgB,GAAG;CAAO;CAChD,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,QAAQ,GACjD,IAAI,CAAC,OAAO,c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AQ;CACZ,MAAM,UAAU,CAAC,SAAS;CAE1B,OAAO,QAAQ,SAAS,GAAG;EACzB,MAAM,UAAU,QAAQ,IAAI;EAC5B,IAAI,CAAC,SAAS;EACd,SAAS;EACT,QAAQ,KAAK,GAAG,QAAQ,oBAAoB,CAAC;CAC/C;CAEA,OAAO;AACT;;;;;;;;AASA,SAAgB,eACd,OACA,QACmB;CACnB,MAAM,iBAAiB,cAAc,MAAM;CAC3C,MAAM,aAAa,eAAe,KAAK;CACvC,IAAI,aAAa,eAAe,eAC9B,MAAM,IAAI,oBACR,iBACA,YACA,eAAe,aACjB;CAIF,iCADqB,kBAAkB,OAAO,cACb,CAAY;CAE7C,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,KAAK;CAC3B,SAAS,OAAO;EACd,MAAM,IAAI,oBAAoB,0BAA0B,EAAE,OAAO,MAAM,CAAC;CAC1E;CAEA,IAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,OAAO,OAAO,OAAO,UACjD,MAAM,IAAI,uBACR,iDACF;CAGF,IAAI;CACJ,IAAI;EACF,YAAY,IAAI,KAAK,UAAU,MAAM;CACvC,SAAS,OAAO;EACd,MAAM,IAAI,oBAAoB,8BAA8B,EAC1D,OAAO,MACT,CAAC;CACH;CAEA,IAAI,UAAU,SAAS,aACrB,MAAM,IAAI,uBAAuB,oCAAoC;CAGvE,MAAM,iBAAiB,gBAAgB,SAAS;CAChD,IAAI,iBAAiB,eAAe,eAClC,MAAM,IAAI,oBACR,iBACA,gBACA,eAAe,aACjB;CAGF,OAAO;EAAE;EAAW,QAAQ;CAAe;AAC7C"}
|
package/metadata.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@happyvertical/icalendar",
|
|
3
|
+
"path": "packages/icalendar",
|
|
4
|
+
"position": {
|
|
5
|
+
"index": 15,
|
|
6
|
+
"count": 33
|
|
7
|
+
},
|
|
8
|
+
"description": "Bounded RFC 5545 iCalendar parsing facade",
|
|
9
|
+
"provides": [
|
|
10
|
+
"Bounded RFC 5545 iCalendar parsing facade"
|
|
11
|
+
],
|
|
12
|
+
"implements": [],
|
|
13
|
+
"requires": {
|
|
14
|
+
"workspace": [],
|
|
15
|
+
"externalHappyVertical": [],
|
|
16
|
+
"external": [
|
|
17
|
+
"ical.js"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"dependents": [],
|
|
21
|
+
"stability": {
|
|
22
|
+
"level": "stable",
|
|
23
|
+
"reason": "Primary package surface is described as implemented and production-oriented."
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"icalendar",
|
|
27
|
+
"rfc5545",
|
|
28
|
+
"calendar"
|
|
29
|
+
]
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/icalendar",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.100.2",
|
|
4
|
+
"description": "Bounded RFC 5545 iCalendar parsing facade",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md",
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"AGENT.md",
|
|
13
|
+
"metadata.json"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"icalendar",
|
|
23
|
+
"ics",
|
|
24
|
+
"rfc5545",
|
|
25
|
+
"calendar"
|
|
26
|
+
],
|
|
27
|
+
"author": "HappyVertical",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/happyvertical/sdk.git",
|
|
32
|
+
"directory": "packages/icalendar"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org",
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"ical.js": "2.2.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "25.0.10",
|
|
43
|
+
"typescript": "5.9.3",
|
|
44
|
+
"vite": "8.1.4",
|
|
45
|
+
"vite-plugin-dts": "4.5.4",
|
|
46
|
+
"vitest": "4.1.10"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "vite build",
|
|
50
|
+
"test": "vitest --config ../../vitest.package.config.ts run",
|
|
51
|
+
"test:watch": "vitest --config ../../vitest.package.config.ts"
|
|
52
|
+
}
|
|
6
53
|
}
|