@couriercrow/core 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +10 -2
- package/dist/addresses.d.ts +10 -0
- package/dist/branding.d.ts +31 -0
- package/dist/changes.d.ts +114 -0
- package/dist/config.d.ts +40 -0
- package/dist/desired-state.d.ts +28 -0
- package/dist/errors.d.ts +7 -0
- package/dist/example-config.d.ts +39 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1118 -0
- package/dist/mail-rules.d.ts +78 -0
- package/dist/mail-rules.js +369 -0
- package/dist/messages.d.ts +54 -0
- package/dist/threading.d.ts +7 -0
- package/package.json +53 -4
- package/src/addresses.ts +82 -0
- package/src/branding.ts +241 -0
- package/src/changes.ts +377 -0
- package/src/config.ts +551 -0
- package/src/desired-state.ts +99 -0
- package/src/errors.ts +6 -0
- package/src/example-config.ts +17 -0
- package/src/index.ts +9 -0
- package/src/mail-rules.ts +332 -0
- package/src/messages.ts +139 -0
- package/src/threading.ts +23 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Christoffer Artmann
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @couriercrow/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The config, addresses and change planner that the [Courier Crow](https://github.com/Artmann/courier-crow) packages share.
|
|
4
|
+
|
|
5
|
+
You do not need to install this package yourself. It comes with `couriercrow`, which has the `crow` command and `defineMail`. To send mail from an app, use `@couriercrow/client`.
|
|
6
|
+
|
|
7
|
+
Start here: https://github.com/Artmann/courier-crow
|
|
8
|
+
|
|
9
|
+
## License
|
|
10
|
+
|
|
11
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Option, Schema } from 'effect';
|
|
2
|
+
export declare const domainNameTooLongMessage = "Expected a domain name of at most 253 characters";
|
|
3
|
+
export declare function isDomainNameTooLong(value: string): boolean;
|
|
4
|
+
export declare const DomainName: Schema.brand<Schema.String, "DomainName">;
|
|
5
|
+
export type DomainName = typeof DomainName.Type;
|
|
6
|
+
export declare const EmailAddress: Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">;
|
|
7
|
+
export type EmailAddress = typeof EmailAddress.Type;
|
|
8
|
+
export declare const StoredEmailAddress: Schema.brand<Schema.String, "EmailAddress">;
|
|
9
|
+
export declare function mailboxAddress(localPart: string, domain: DomainName): EmailAddress;
|
|
10
|
+
export declare function normalizeRecipient(address: string): Option.Option<EmailAddress>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const defaultAppName = "Courier Crow";
|
|
2
|
+
export declare const maxBrandNameLength = 40;
|
|
3
|
+
export declare const minimumAccentContrast = 3;
|
|
4
|
+
export interface RgbColor {
|
|
5
|
+
blue: number;
|
|
6
|
+
green: number;
|
|
7
|
+
red: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const themeSurfaces: {
|
|
10
|
+
readonly dark: readonly [readonly [0.19, 0.012, 255], readonly [0.22, 0.014, 255]];
|
|
11
|
+
readonly light: readonly [readonly [0.975, 0.004, 255], readonly [0.995, 0.002, 255]];
|
|
12
|
+
};
|
|
13
|
+
export declare function parseHexColor(text: string): RgbColor | undefined;
|
|
14
|
+
export declare function oklchToRgb(lightness: number, chroma: number, hue: number): RgbColor;
|
|
15
|
+
export declare function contrastRatio(first: RgbColor, second: RgbColor): number;
|
|
16
|
+
export declare function accentColorProblem(text: string): 'dark' | 'light' | 'notAColour' | undefined;
|
|
17
|
+
export declare const minimumTextContrast = 4.5;
|
|
18
|
+
export declare const accentSoftShare = 0.18;
|
|
19
|
+
export type Oklch = readonly [lightness: number, chroma: number, hue: number];
|
|
20
|
+
export declare function rgbToOklch(color: RgbColor): Oklch;
|
|
21
|
+
export declare function hexToOklch(text: string): Oklch;
|
|
22
|
+
export declare function rgbToHex(color: RgbColor): string;
|
|
23
|
+
export declare function oklchToHex([lightness, chroma, hue]: Oklch): string;
|
|
24
|
+
export declare function mixOklch(first: Oklch, second: Oklch, share: number): Oklch;
|
|
25
|
+
export interface ThemeAccent {
|
|
26
|
+
soft: string;
|
|
27
|
+
text: string;
|
|
28
|
+
}
|
|
29
|
+
export type AccentPalette = Record<keyof typeof themeSurfaces, ThemeAccent>;
|
|
30
|
+
export declare function accentPalette(accent: string): AccentPalette;
|
|
31
|
+
export declare function accentForeground(text: string): string;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import type { DesiredState } from './desired-state';
|
|
3
|
+
export declare const AppName: Schema.String;
|
|
4
|
+
export declare const AppSeriesSettings: Schema.Struct<{
|
|
5
|
+
readonly from: Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">;
|
|
6
|
+
readonly postalAddress: Schema.String;
|
|
7
|
+
}>;
|
|
8
|
+
export type AppSeriesSettings = typeof AppSeriesSettings.Type;
|
|
9
|
+
export declare const SeriesProviderName: Schema.Literal<"resend">;
|
|
10
|
+
export declare const CurrentState: Schema.Struct<{
|
|
11
|
+
readonly apps: Schema.$Array<Schema.Struct<{
|
|
12
|
+
readonly clientId: Schema.NullOr<Schema.String>;
|
|
13
|
+
readonly domain: Schema.brand<Schema.String, "DomainName">;
|
|
14
|
+
readonly name: Schema.String;
|
|
15
|
+
readonly senders: Schema.$Array<Schema.brand<Schema.String, "EmailAddress">>;
|
|
16
|
+
readonly series: Schema.NullOr<Schema.Struct<{
|
|
17
|
+
readonly from: Schema.brand<Schema.String, "EmailAddress">;
|
|
18
|
+
readonly postalAddress: Schema.String;
|
|
19
|
+
}>>;
|
|
20
|
+
readonly viewers: Schema.$Array<Schema.brand<Schema.String, "EmailAddress">>;
|
|
21
|
+
}>>;
|
|
22
|
+
readonly domains: Schema.$Array<Schema.brand<Schema.String, "DomainName">>;
|
|
23
|
+
readonly mailboxes: Schema.$Array<Schema.Struct<{
|
|
24
|
+
readonly address: Schema.brand<Schema.String, "EmailAddress">;
|
|
25
|
+
readonly domain: Schema.brand<Schema.String, "DomainName">;
|
|
26
|
+
readonly people: Schema.$Array<Schema.brand<Schema.String, "EmailAddress">>;
|
|
27
|
+
readonly state: Schema.Literals<readonly ["active", "archived", "purging"]>;
|
|
28
|
+
}>>;
|
|
29
|
+
readonly people: Schema.$Array<Schema.Struct<{
|
|
30
|
+
readonly email: Schema.brand<Schema.String, "EmailAddress">;
|
|
31
|
+
readonly name: Schema.String;
|
|
32
|
+
}>>;
|
|
33
|
+
readonly seriesProvider: Schema.NullOr<Schema.Literal<"resend">>;
|
|
34
|
+
}>;
|
|
35
|
+
export type CurrentState = typeof CurrentState.Type;
|
|
36
|
+
export declare const AdminState: Schema.Struct<{
|
|
37
|
+
readonly apps: Schema.$Array<Schema.Struct<{
|
|
38
|
+
readonly clientId: Schema.NullOr<Schema.String>;
|
|
39
|
+
readonly domain: Schema.brand<Schema.String, "DomainName">;
|
|
40
|
+
readonly name: Schema.String;
|
|
41
|
+
readonly senders: Schema.$Array<Schema.brand<Schema.String, "EmailAddress">>;
|
|
42
|
+
readonly series: Schema.NullOr<Schema.Struct<{
|
|
43
|
+
readonly from: Schema.brand<Schema.String, "EmailAddress">;
|
|
44
|
+
readonly postalAddress: Schema.String;
|
|
45
|
+
}>>;
|
|
46
|
+
readonly viewers: Schema.$Array<Schema.brand<Schema.String, "EmailAddress">>;
|
|
47
|
+
}>>;
|
|
48
|
+
readonly domains: Schema.$Array<Schema.brand<Schema.String, "DomainName">>;
|
|
49
|
+
readonly mailboxes: Schema.$Array<Schema.Struct<{
|
|
50
|
+
readonly address: Schema.brand<Schema.String, "EmailAddress">;
|
|
51
|
+
readonly domain: Schema.brand<Schema.String, "DomainName">;
|
|
52
|
+
readonly people: Schema.$Array<Schema.brand<Schema.String, "EmailAddress">>;
|
|
53
|
+
readonly state: Schema.Literals<readonly ["active", "archived", "purging"]>;
|
|
54
|
+
}>>;
|
|
55
|
+
readonly people: Schema.$Array<Schema.Struct<{
|
|
56
|
+
readonly email: Schema.brand<Schema.String, "EmailAddress">;
|
|
57
|
+
readonly name: Schema.String;
|
|
58
|
+
}>>;
|
|
59
|
+
readonly seriesProvider: Schema.NullOr<Schema.Literal<"resend">>;
|
|
60
|
+
readonly hasEnrollments: Schema.Boolean;
|
|
61
|
+
readonly hasSeriesProviderKey: Schema.Boolean;
|
|
62
|
+
readonly unsubscribePageNeededUntil: Schema.NullOr<Schema.String>;
|
|
63
|
+
}>;
|
|
64
|
+
export type AdminState = typeof AdminState.Type;
|
|
65
|
+
export declare const Change: Schema.Union<readonly [Schema.TaggedStruct<"AddApp", {
|
|
66
|
+
readonly domain: Schema.brand<Schema.String, "DomainName">;
|
|
67
|
+
readonly name: Schema.String;
|
|
68
|
+
}>, Schema.TaggedStruct<"AddDomain", {
|
|
69
|
+
readonly domain: Schema.brand<Schema.String, "DomainName">;
|
|
70
|
+
}>, Schema.TaggedStruct<"AddMailbox", {
|
|
71
|
+
readonly address: Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">;
|
|
72
|
+
readonly domain: Schema.brand<Schema.String, "DomainName">;
|
|
73
|
+
}>, Schema.TaggedStruct<"AddPerson", {
|
|
74
|
+
readonly email: Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">;
|
|
75
|
+
readonly name: Schema.String;
|
|
76
|
+
}>, Schema.TaggedStruct<"ArchiveMailbox", {
|
|
77
|
+
readonly address: Schema.brand<Schema.String, "EmailAddress">;
|
|
78
|
+
}>, Schema.TaggedStruct<"GrantAccess", {
|
|
79
|
+
readonly mailbox: Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">;
|
|
80
|
+
readonly person: Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">;
|
|
81
|
+
}>, Schema.TaggedStruct<"RemoveApp", {
|
|
82
|
+
readonly name: Schema.String;
|
|
83
|
+
}>, Schema.TaggedStruct<"RemoveDomain", {
|
|
84
|
+
readonly domain: Schema.brand<Schema.String, "DomainName">;
|
|
85
|
+
}>, Schema.TaggedStruct<"RemovePerson", {
|
|
86
|
+
readonly email: Schema.brand<Schema.String, "EmailAddress">;
|
|
87
|
+
}>, Schema.TaggedStruct<"RenamePerson", {
|
|
88
|
+
readonly email: Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">;
|
|
89
|
+
readonly name: Schema.String;
|
|
90
|
+
}>, Schema.TaggedStruct<"RestoreMailbox", {
|
|
91
|
+
readonly address: Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">;
|
|
92
|
+
}>, Schema.TaggedStruct<"RevokeAccess", {
|
|
93
|
+
readonly mailbox: Schema.brand<Schema.String, "EmailAddress">;
|
|
94
|
+
readonly person: Schema.brand<Schema.String, "EmailAddress">;
|
|
95
|
+
}>, Schema.TaggedStruct<"SetAppClient", {
|
|
96
|
+
readonly clientId: Schema.String;
|
|
97
|
+
readonly name: Schema.String;
|
|
98
|
+
}>, Schema.TaggedStruct<"SetAppSenders", {
|
|
99
|
+
readonly name: Schema.String;
|
|
100
|
+
readonly senders: Schema.$Array<Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">>;
|
|
101
|
+
}>, Schema.TaggedStruct<"SetAppSeries", {
|
|
102
|
+
readonly name: Schema.String;
|
|
103
|
+
readonly series: Schema.NullOr<Schema.Struct<{
|
|
104
|
+
readonly from: Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">;
|
|
105
|
+
readonly postalAddress: Schema.String;
|
|
106
|
+
}>>;
|
|
107
|
+
}>, Schema.TaggedStruct<"SetAppViewers", {
|
|
108
|
+
readonly name: Schema.String;
|
|
109
|
+
readonly viewers: Schema.$Array<Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">>;
|
|
110
|
+
}>, Schema.TaggedStruct<"SetSeriesProvider", {
|
|
111
|
+
readonly provider: Schema.NullOr<Schema.Literal<"resend">>;
|
|
112
|
+
}>]>;
|
|
113
|
+
export type Change = typeof Change.Type;
|
|
114
|
+
export declare function planChanges(desired: DesiredState, current: CurrentState): readonly Change[];
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Effect, Schema } from 'effect';
|
|
2
|
+
import { ConfigError } from './errors';
|
|
3
|
+
declare const mailConfigSchema: Schema.Struct<{
|
|
4
|
+
readonly app: Schema.Struct<{
|
|
5
|
+
readonly authenticationHost: Schema.optionalKey<Schema.brand<Schema.String, "DomainName">>;
|
|
6
|
+
readonly branding: Schema.optionalKey<Schema.Struct<{
|
|
7
|
+
readonly accentColor: Schema.optionalKey<Schema.String>;
|
|
8
|
+
readonly name: Schema.optionalKey<Schema.String>;
|
|
9
|
+
}>>;
|
|
10
|
+
readonly hostname: Schema.brand<Schema.String, "DomainName">;
|
|
11
|
+
}>;
|
|
12
|
+
readonly apps: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
|
|
13
|
+
readonly domain: Schema.brand<Schema.String, "DomainName">;
|
|
14
|
+
readonly senders: Schema.$Array<Schema.String>;
|
|
15
|
+
readonly series: Schema.optionalKey<Schema.Struct<{
|
|
16
|
+
readonly from: Schema.String;
|
|
17
|
+
readonly postalAddress: Schema.String;
|
|
18
|
+
}>>;
|
|
19
|
+
readonly viewers: Schema.$Array<Schema.String>;
|
|
20
|
+
}>>>;
|
|
21
|
+
readonly domains: Schema.$Record<Schema.brand<Schema.String, "DomainName">, Schema.Struct<{
|
|
22
|
+
readonly mailboxes: Schema.$Record<Schema.String, Schema.Struct<{
|
|
23
|
+
readonly people: Schema.$Array<Schema.String>;
|
|
24
|
+
}>>;
|
|
25
|
+
}>>;
|
|
26
|
+
readonly people: Schema.$Record<Schema.String, Schema.Struct<{
|
|
27
|
+
readonly email: Schema.brand<Schema.decodeTo<Schema.String, Schema.toEncoded<Schema.String>, never, never>, "EmailAddress">;
|
|
28
|
+
readonly name: Schema.String;
|
|
29
|
+
}>>;
|
|
30
|
+
readonly series: Schema.optionalKey<Schema.Struct<{
|
|
31
|
+
readonly provider: Schema.Literal<"resend">;
|
|
32
|
+
}>>;
|
|
33
|
+
}>;
|
|
34
|
+
export type MailConfig = typeof mailConfigSchema.Type;
|
|
35
|
+
export type MailConfigInput = typeof mailConfigSchema.Encoded;
|
|
36
|
+
export declare function defineMail(config: MailConfigInput): MailConfigInput;
|
|
37
|
+
export declare const seriesProviderMessage = "Series need a mail provider that allows them. Add series: { provider: 'resend' } to mail.config.ts, deploy, and run bunx couriercrow set-secret RESEND_API_KEY.";
|
|
38
|
+
export declare function postalAddressMessage(app: string): string;
|
|
39
|
+
export declare function validateMailConfig(input: unknown): Effect.Effect<MailConfig, ConfigError>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DomainName, EmailAddress } from './addresses';
|
|
2
|
+
import type { MailConfig } from './config';
|
|
3
|
+
export interface AppSeries {
|
|
4
|
+
from: EmailAddress;
|
|
5
|
+
postalAddress: string;
|
|
6
|
+
}
|
|
7
|
+
export type SeriesProvider = 'resend';
|
|
8
|
+
export interface DesiredState {
|
|
9
|
+
apps: readonly {
|
|
10
|
+
domain: DomainName;
|
|
11
|
+
name: string;
|
|
12
|
+
senders: readonly EmailAddress[];
|
|
13
|
+
series: AppSeries | null;
|
|
14
|
+
viewers: readonly EmailAddress[];
|
|
15
|
+
}[];
|
|
16
|
+
domains: readonly DomainName[];
|
|
17
|
+
mailboxes: readonly {
|
|
18
|
+
address: EmailAddress;
|
|
19
|
+
domain: DomainName;
|
|
20
|
+
people: readonly EmailAddress[];
|
|
21
|
+
}[];
|
|
22
|
+
people: readonly {
|
|
23
|
+
email: EmailAddress;
|
|
24
|
+
name: string;
|
|
25
|
+
}[];
|
|
26
|
+
seriesProvider: SeriesProvider | null;
|
|
27
|
+
}
|
|
28
|
+
export declare function desiredState(config: MailConfig): DesiredState;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
declare const ConfigError_base: Schema.Class<ConfigError, Schema.TaggedStruct<"ConfigError", {
|
|
3
|
+
readonly message: Schema.String;
|
|
4
|
+
}>, import("effect/Cause").YieldableError>;
|
|
5
|
+
export declare class ConfigError extends ConfigError_base {
|
|
6
|
+
}
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const exampleConfig: {
|
|
2
|
+
readonly app: {
|
|
3
|
+
readonly authenticationHost?: string;
|
|
4
|
+
readonly branding?: {
|
|
5
|
+
readonly accentColor?: string;
|
|
6
|
+
readonly name?: string;
|
|
7
|
+
};
|
|
8
|
+
readonly hostname: string;
|
|
9
|
+
};
|
|
10
|
+
readonly apps?: {
|
|
11
|
+
readonly [x: string]: {
|
|
12
|
+
readonly domain: string;
|
|
13
|
+
readonly senders: readonly string[];
|
|
14
|
+
readonly series?: {
|
|
15
|
+
readonly from: string;
|
|
16
|
+
readonly postalAddress: string;
|
|
17
|
+
};
|
|
18
|
+
readonly viewers: readonly string[];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
readonly domains: {
|
|
22
|
+
readonly [x: string]: {
|
|
23
|
+
readonly mailboxes: {
|
|
24
|
+
readonly [x: string]: {
|
|
25
|
+
readonly people: readonly string[];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
readonly people: {
|
|
31
|
+
readonly [x: string]: {
|
|
32
|
+
readonly email: string;
|
|
33
|
+
readonly name: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
readonly series?: {
|
|
37
|
+
readonly provider: "resend";
|
|
38
|
+
};
|
|
39
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './addresses';
|
|
2
|
+
export * from './changes';
|
|
3
|
+
export * from './config';
|
|
4
|
+
export * from './desired-state';
|
|
5
|
+
export * from './errors';
|
|
6
|
+
export * from './example-config';
|
|
7
|
+
export * from './mail-rules';
|
|
8
|
+
export * from './messages';
|
|
9
|
+
export * from './threading';
|