Skip to content

Commit

Permalink
added classfication as iCalendar CLASS Value (adamgibbons#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flowr-es authored Dec 4, 2021
1 parent 31d4496 commit badba85
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ The following properties are accepted:
| recurrenceRule | A recurrence rule, commonly referred to as an RRULE, defines the repeat pattern or rule for to-dos, journal entries and events. If specified, RRULE can be used to compute the recurrence set (the complete set of recurrence instances in a calendar component). You can use a generator like this [one](https://www.textmagic.com/free-tools/rrule-generator) | `FREQ=DAILY`
| sequence | For sending an update for an event (with the same uid), defines the revision sequence number. | `2`
| busyStatus | Used to specify busy status for Microsoft applications, like Outlook. See [Microsoft spec](https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcical/cd68eae7-ed65-4dd3-8ea7-ad585c76c736). | `'BUSY'` OR `'FREE'` OR `'TENTATIVE`' OR `'OOF'`
| classification | This property defines the access classification for a calendar component. See [iCalender spec](https://icalendar.org/iCalendar-RFC-5545/3-8-1-3-classification.html). | `'PUBLIC'` OR `'PRIVATE'` OR `'CONFIDENTIAL`' OR any non-standard string
| created | Date-time representing event's creation date. Provide a date-time in UTC | [2000, 1, 5, 10, 0] (January 5, 2000 GMT +00:00)
| lastModified | Date-time representing date when event was last modified. Provide a date-time in UTC | [2000, 1, 5, 10, 0] (January 5, 2000 GMT +00:00)
| calName | Specifies the _calendar_ (not event) name. Used by Apple iCal and Microsoft Outlook; see [Open Specification](https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcical/1da58449-b97e-46bd-b018-a1ce576f3e6d) | `'Example Calendar'` |
Expand Down
12 changes: 9 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export type Attendee = Person & {

export type ActionType = 'audio' | 'display' | 'email' | 'procedure';

/**
* This property defines the access classification for a calendar component.
*/
export type classificationType = 'PUBLIC' | 'PRIVATE' | 'CONFIDENTIAL' | string;

export type Alarm = {
action?: ActionType;
trigger?: DurationObject; // @todo DateArray | DurationObject;
Expand All @@ -73,19 +78,20 @@ export type EventAttributes = {
url?: string;
status?: EventStatus;
busyStatus?: 'FREE' | 'BUSY' | 'TENTATIVE' | 'OOF';

organizer?: Person;
attendees?: Attendee[];

categories?: string[];
alarms?: Alarm[];

productId?: string;
uid?: string;
method?: string;
recurrenceRule?: string;
sequence?: number;
calName?: string;
classification?: classificationType;
created?: DateArray;
lastModified?: DateArray;
} & ({ end: DateArray } | { duration: DurationObject });
Expand Down
2 changes: 1 addition & 1 deletion notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TZID=America/New_York:19980119T020000
- [x] dtstart

### OPTIONAL but MUST NOT occur more than once
- [ ] class
- [x] class
- [ ] created
- [x] description
- [x] geo
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ics",
"version": "2.31.0",
"version": "2.32.0",
"description": "iCal (ics) file generator",
"main": "index.js",
"types": "index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/pipeline/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default function formatEvent(attributes = {}) {
alarms,
recurrenceRule,
busyStatus,
classification,
created,
lastModified,
calName
Expand Down Expand Up @@ -75,6 +76,7 @@ export default function formatEvent(attributes = {}) {
icsFormat += categories ? (foldLine(`CATEGORIES:${categories}`) + '\r\n') : ''
icsFormat += organizer ? (foldLine(`ORGANIZER;${setOrganizer(organizer)}`) + '\r\n') : ''
icsFormat += busyStatus ? (foldLine(`X-MICROSOFT-CDO-BUSYSTATUS:${busyStatus}`) + '\r\n') : ''
icsFormat += classification ? (foldLine(`CLASS:${classification}`) + '\r\n') : ''
icsFormat += created ? ('CREATED:' + formatDate(created) + '\r\n') : ''
icsFormat += lastModified ? ('LAST-MODIFIED:' + formatDate(lastModified) + '\r\n') : ''
if (attendees) {
Expand Down
1 change: 1 addition & 0 deletions src/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const schema = yup.object().shape({
alarms: yup.array().of(alarmSchema),
recurrenceRule: yup.string(),
busyStatus: yup.string().matches(/TENTATIVE|FREE|BUSY|OOF/i),
classification: yup.string(),
created: dateTimeSchema,
lastModified: dateTimeSchema,
calName: yup.string()
Expand Down
14 changes: 14 additions & 0 deletions test/pipeline/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ describe('pipeline.formatEvent', () => {
expect(formattedEventTent).to.contain('X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE')
expect(formattedEventOOF).to.contain('X-MICROSOFT-CDO-BUSYSTATUS:OOF')
})
it('writes a access classification', () => {
const eventPublic = buildEvent({ classification: "PUBLIC" })
const eventPrivate = buildEvent({ classification: "PRIVATE"})
const eventConfidential = buildEvent({ classification: "CONFIDENTIAL"})
const eventAnyClass = buildEvent({ classification: "non-standard-property" })
const formattedEventPublic = formatEvent(eventPublic)
const formattedEventPrivate = formatEvent(eventPrivate)
const formattedEventConfidential = formatEvent(eventConfidential)
const formattedEventAnyClass = formatEvent(eventAnyClass)
expect(formattedEventPublic).to.contain('CLASS:PUBLIC')
expect(formattedEventPrivate).to.contain('CLASS:PRIVATE')
expect(formattedEventConfidential).to.contain('CLASS:CONFIDENTIAL')
expect(formattedEventAnyClass).to.contain('CLASS:non-standard-property')
})
it('writes an organizer', () => {
const event = formatEvent({ organizer: {
name: 'Adam Gibbons',
Expand Down

0 comments on commit badba85

Please sign in to comment.