@plitzi/sdk-shared 0.35.3 → 0.35.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @plitzi/sdk-shared
2
2
 
3
+ ## 0.35.5
4
+
5
+ ### Patch Changes
6
+
7
+ - v0.35.5
8
+
9
+ ## 0.35.4
10
+
11
+ ### Patch Changes
12
+
13
+ - v0.35.4
14
+
3
15
  ## 0.35.3
4
16
 
5
17
  ### Patch Changes
@@ -2,5 +2,7 @@ export { cronMatches, isKnownTimeZone, parseCron, zonedClock } from './cron';
2
2
  export { triggerAccess, triggerCacheMs, triggerHasStaleVerify, triggerInput, triggerVerify } from './triggerParams';
3
3
  export { actionName, actionTriggers, isActionEnabled } from './triggers';
4
4
  export { validateActionDocument } from './validateDocument';
5
+ export { isSingleEmailAddress, readSmtpCredential, SMTP_CREDENTIAL_KEYS } from './smtp';
5
6
  export type { CronExpression } from './cron';
7
+ export type { SmtpCredentialProblem, SmtpCredentialReading, SmtpSecurity, SmtpSettings } from './smtp';
6
8
  export type { ActionDocumentIssue, ActionDocumentReport } from './validateDocument';
@@ -2,4 +2,5 @@ import { cronMatches as e, isKnownTimeZone as t, parseCron as n, zonedClock as r
2
2
  import { triggerAccess as i, triggerCacheMs as a, triggerHasStaleVerify as o, triggerInput as s, triggerVerify as c } from "./triggerParams.mjs";
3
3
  import { actionName as l, actionTriggers as u, isActionEnabled as d } from "./triggers.mjs";
4
4
  import { validateActionDocument as f } from "./validateDocument.mjs";
5
- export { l as actionName, u as actionTriggers, e as cronMatches, d as isActionEnabled, t as isKnownTimeZone, n as parseCron, i as triggerAccess, a as triggerCacheMs, o as triggerHasStaleVerify, s as triggerInput, c as triggerVerify, f as validateActionDocument, r as zonedClock };
5
+ import { SMTP_CREDENTIAL_KEYS as p, isSingleEmailAddress as m, readSmtpCredential as h } from "./smtp.mjs";
6
+ export { p as SMTP_CREDENTIAL_KEYS, l as actionName, u as actionTriggers, e as cronMatches, d as isActionEnabled, t as isKnownTimeZone, m as isSingleEmailAddress, n as parseCron, h as readSmtpCredential, i as triggerAccess, a as triggerCacheMs, o as triggerHasStaleVerify, s as triggerInput, c as triggerVerify, f as validateActionDocument, r as zonedClock };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The SMTP server a space sends its flows' mail through, as its credential stores it — one rule for everybody who
3
+ * reads one: the editor saving it, the API accepting it, the check reporting on it and the `email.send` task using it.
4
+ *
5
+ * A credential is a bag of strings, so every value arrives as text and is judged here: a port that is not a port, a
6
+ * sender that is not one address, a password with no user to go with it. Each problem names the key it is about, so a
7
+ * form can put the sentence under the field.
8
+ */
9
+ export type SmtpSecurity = 'tls' | 'starttls' | 'none';
10
+ export type SmtpSettings = {
11
+ host: string;
12
+ port: number;
13
+ /** `tls` connects encrypted (usually 465); `starttls` upgrades a plain connection (usually 587); `none` never does. */
14
+ security: SmtpSecurity;
15
+ /** Empty with an empty password: a relay that authenticates by where the connection comes from. */
16
+ username: string;
17
+ password: string;
18
+ fromEmail: string;
19
+ fromName: string;
20
+ };
21
+ export type SmtpCredentialProblem = {
22
+ key: keyof SmtpSettings;
23
+ message: string;
24
+ };
25
+ export type SmtpCredentialReading = {
26
+ settings: SmtpSettings;
27
+ problems: [];
28
+ } | {
29
+ problems: SmtpCredentialProblem[];
30
+ };
31
+ /** The keys an SMTP credential holds, in the order an editor asks for them. */
32
+ export declare const SMTP_CREDENTIAL_KEYS: readonly (keyof SmtpSettings)[];
33
+ export declare const isSingleEmailAddress: (value: string) => boolean;
34
+ export declare const readSmtpCredential: (data: Record<string, unknown>) => SmtpCredentialReading;
@@ -0,0 +1,51 @@
1
+ //#region src/actions/smtp.ts
2
+ var e = [
3
+ "host",
4
+ "port",
5
+ "security",
6
+ "username",
7
+ "password",
8
+ "fromEmail",
9
+ "fromName"
10
+ ], t = [
11
+ "tls",
12
+ "starttls",
13
+ "none"
14
+ ], n = /^[A-Za-z0-9](?:[A-Za-z0-9.-]{0,251}[A-Za-z0-9])?$/, r = /^[^\s@,;<>"]+@[^\s@,;<>"]+\.[^\s@,;<>"]+$/, i = (e) => r.test(e), a = (e) => t.some((t) => t === e), o = (e, t) => {
15
+ let n = e[t];
16
+ return typeof n == "number" ? String(n) : typeof n == "string" ? n.trim() : "";
17
+ }, s = (e) => {
18
+ let t = o(e, "host"), r = Number(o(e, "port")), s = o(e, "security"), c = o(e, "username"), l = typeof e.password == "string" ? e.password : "", u = o(e, "fromEmail"), d = o(e, "fromName"), f = [];
19
+ return n.test(t) || f.push({
20
+ key: "host",
21
+ message: "A host name like smtp.example.com, with no scheme and no port"
22
+ }), (!Number.isInteger(r) || r < 1 || r > 65535) && f.push({
23
+ key: "port",
24
+ message: "A port number, usually 587 or 465"
25
+ }), a(s) || f.push({
26
+ key: "security",
27
+ message: "One of tls, starttls or none"
28
+ }), l !== "" && c === "" && f.push({
29
+ key: "username",
30
+ message: "A password needs the user it belongs to"
31
+ }), i(u) || f.push({
32
+ key: "fromEmail",
33
+ message: "The one address this server sends as"
34
+ }), (/[\r\n]/.test(d) || d.length > 100) && f.push({
35
+ key: "fromName",
36
+ message: "One line of at most 100 characters"
37
+ }), f.length > 0 || !a(s) ? { problems: f } : {
38
+ settings: {
39
+ host: t,
40
+ port: r,
41
+ security: s,
42
+ username: c,
43
+ password: l,
44
+ fromEmail: u,
45
+ fromName: d
46
+ },
47
+ problems: []
48
+ };
49
+ };
50
+ //#endregion
51
+ export { e as SMTP_CREDENTIAL_KEYS, i as isSingleEmailAddress, s as readSmtpCredential };
@@ -24,7 +24,8 @@ var a = [
24
24
  "spaceId",
25
25
  "environment",
26
26
  "trigger",
27
- "runId"
27
+ "runId",
28
+ "now"
28
29
  ]), u = /^[a-z][a-zA-Z0-9]*\.[a-z][a-zA-Z0-9]*$/, d = (e) => typeof e == "object" && !!e && !Array.isArray(e), f = (e) => typeof e == "string" && e.trim() !== "", p = (e) => {
29
30
  try {
30
31
  let t = JSON.parse(e);
@@ -99,7 +99,54 @@ var e = Symbol("twigArrowParams"), t = (e) => e == null || e === "", n = (e, t)
99
99
  }, s = "__PLITZI_RAW__", c = (e) => typeof e == "object" && !!e && e.__marker === "__PLITZI_RAW__", l = (e) => ({
100
100
  __raw: e,
101
101
  __marker: s
102
- }), u = (e) => c(e) ? e.__raw : e, d = {
102
+ }), u = (e) => c(e) ? e.__raw : e, d = [
103
+ "Sun",
104
+ "Mon",
105
+ "Tue",
106
+ "Wed",
107
+ "Thu",
108
+ "Fri",
109
+ "Sat"
110
+ ], f = /* @__PURE__ */ new Map(), p = (e) => {
111
+ if (!f.has(e)) try {
112
+ f.set(e, new Intl.DateTimeFormat("en-US", {
113
+ timeZone: e,
114
+ hourCycle: "h23",
115
+ year: "numeric",
116
+ month: "numeric",
117
+ day: "numeric",
118
+ hour: "numeric",
119
+ minute: "numeric",
120
+ second: "numeric",
121
+ weekday: "short"
122
+ }));
123
+ } catch {
124
+ f.set(e, null);
125
+ }
126
+ return f.get(e) ?? null;
127
+ }, m = (e, t) => {
128
+ if (!t) return {
129
+ year: e.getFullYear(),
130
+ month: e.getMonth() + 1,
131
+ day: e.getDate(),
132
+ hours: e.getHours(),
133
+ minutes: e.getMinutes(),
134
+ seconds: e.getSeconds(),
135
+ weekday: e.getDay()
136
+ };
137
+ let n = p(t);
138
+ if (!n) return;
139
+ let r = n.formatToParts(e), i = (e) => r.find((t) => t.type === e)?.value ?? "";
140
+ return {
141
+ year: Number(i("year")),
142
+ month: Number(i("month")),
143
+ day: Number(i("day")),
144
+ hours: Number(i("hour")),
145
+ minutes: Number(i("minute")),
146
+ seconds: Number(i("second")),
147
+ weekday: d.indexOf(i("weekday"))
148
+ };
149
+ }, h = {
103
150
  raw: (e) => l(e),
104
151
  to_json: (e) => typeof e == "object" && e ? JSON.stringify(e) : r(e),
105
152
  json_encode: (e) => typeof e == "object" && e ? JSON.stringify(e) : r(e),
@@ -262,13 +309,21 @@ var e = Symbol("twigArrowParams"), t = (e) => e == null || e === "", n = (e, t)
262
309
  if (t.length === 0) return e;
263
310
  let n = r(t[0]), i = e instanceof Date ? e : new Date(String(e));
264
311
  if (Number.isNaN(i.getTime())) return "";
265
- let a = (e) => String(e).padStart(2, "0"), o = {
266
- Y: String(i.getFullYear()),
267
- m: a(i.getMonth() + 1),
268
- d: a(i.getDate()),
269
- H: a(i.getHours()),
270
- i: a(i.getMinutes()),
271
- s: a(i.getSeconds()),
312
+ let a = m(i, t.length > 1 ? r(t[1]) : "");
313
+ if (!a) return "";
314
+ let o = (e) => String(e).padStart(2, "0"), s = {
315
+ Y: String(a.year),
316
+ m: o(a.month),
317
+ n: String(a.month),
318
+ d: o(a.day),
319
+ j: String(a.day),
320
+ H: o(a.hours),
321
+ G: String(a.hours),
322
+ i: o(a.minutes),
323
+ s: o(a.seconds),
324
+ w: String(a.weekday),
325
+ N: String(a.weekday === 0 ? 7 : a.weekday),
326
+ U: String(Math.floor(i.getTime() / 1e3)),
272
327
  l: [
273
328
  "Sunday",
274
329
  "Monday",
@@ -277,7 +332,7 @@ var e = Symbol("twigArrowParams"), t = (e) => e == null || e === "", n = (e, t)
277
332
  "Thursday",
278
333
  "Friday",
279
334
  "Saturday"
280
- ][i.getDay()],
335
+ ][a.weekday],
281
336
  F: [
282
337
  "January",
283
338
  "February",
@@ -291,7 +346,7 @@ var e = Symbol("twigArrowParams"), t = (e) => e == null || e === "", n = (e, t)
291
346
  "October",
292
347
  "November",
293
348
  "December"
294
- ][i.getMonth()],
349
+ ][a.month - 1],
295
350
  M: [
296
351
  "Jan",
297
352
  "Feb",
@@ -305,10 +360,10 @@ var e = Symbol("twigArrowParams"), t = (e) => e == null || e === "", n = (e, t)
305
360
  "Oct",
306
361
  "Nov",
307
362
  "Dec"
308
- ][i.getMonth()]
309
- }, s = "";
310
- for (let e of n) s += Object.prototype.hasOwnProperty.call(o, e) ? o[e] : e;
311
- return s;
363
+ ][a.month - 1]
364
+ }, c = "";
365
+ for (let e of n) c += Object.prototype.hasOwnProperty.call(s, e) ? s[e] : e;
366
+ return c;
312
367
  },
313
368
  base64_encode: (e) => typeof e == "string" ? i(e) : e,
314
369
  base64_decode: (e) => typeof e == "string" ? a(e) : e,
@@ -369,4 +424,4 @@ var e = Symbol("twigArrowParams"), t = (e) => e == null || e === "", n = (e, t)
369
424
  }
370
425
  };
371
426
  //#endregion
372
- export { e as ARROW_PARAMS, s as RAW_MARKER, d as filters, c as isRawMarker, u as unwrapRaw, l as wrapRaw };
427
+ export { e as ARROW_PARAMS, s as RAW_MARKER, h as filters, c as isRawMarker, u as unwrapRaw, l as wrapRaw };
@@ -93,19 +93,19 @@ export declare const spaceEventSchemas: {
93
93
  selector: z.ZodString;
94
94
  path: z.ZodOptional<z.ZodCustom<StyleCategory, StyleCategory>>;
95
95
  type: z.ZodEnum<{
96
+ id: "id";
96
97
  class: "class";
97
98
  element: "element";
98
- id: "id";
99
99
  }>;
100
100
  style: z.ZodOptional<z.ZodCustom<import('..').StyleAttributes, import('..').StyleAttributes>>;
101
101
  params: z.ZodObject<{
102
102
  componentType: z.ZodOptional<z.ZodString>;
103
103
  styleSelector: z.ZodOptional<z.ZodString>;
104
104
  styleState: z.ZodOptional<z.ZodEnum<{
105
- disabled: "disabled";
106
105
  hover: "hover";
107
106
  active: "active";
108
107
  focus: "focus";
108
+ disabled: "disabled";
109
109
  checked: "checked";
110
110
  visited: "visited";
111
111
  }>>;
@@ -124,10 +124,10 @@ export declare const spaceEventSchemas: {
124
124
  params: z.ZodObject<{
125
125
  componentType: z.ZodOptional<z.ZodString>;
126
126
  styleState: z.ZodOptional<z.ZodEnum<{
127
- disabled: "disabled";
128
127
  hover: "hover";
129
128
  active: "active";
130
129
  focus: "focus";
130
+ disabled: "disabled";
131
131
  checked: "checked";
132
132
  visited: "visited";
133
133
  }>>;
@@ -281,9 +281,9 @@ export declare const spaceEventSchemas: {
281
281
  }>;
282
282
  selector: z.ZodString;
283
283
  type: z.ZodEnum<{
284
+ id: "id";
284
285
  class: "class";
285
286
  element: "element";
286
- id: "id";
287
287
  }>;
288
288
  path: z.ZodOptional<z.ZodCustom<StyleCategory, StyleCategory>>;
289
289
  style: z.ZodOptional<z.ZodCustom<import('..').StyleAttributes, import('..').StyleAttributes>>;
@@ -291,10 +291,10 @@ export declare const spaceEventSchemas: {
291
291
  componentType: z.ZodOptional<z.ZodString>;
292
292
  styleSelector: z.ZodOptional<z.ZodString>;
293
293
  styleState: z.ZodOptional<z.ZodEnum<{
294
- disabled: "disabled";
295
294
  hover: "hover";
296
295
  active: "active";
297
296
  focus: "focus";
297
+ disabled: "disabled";
298
298
  checked: "checked";
299
299
  visited: "visited";
300
300
  }>>;
@@ -314,10 +314,10 @@ export declare const spaceEventSchemas: {
314
314
  params: z.ZodObject<{
315
315
  componentType: z.ZodOptional<z.ZodString>;
316
316
  styleState: z.ZodOptional<z.ZodEnum<{
317
- disabled: "disabled";
318
317
  hover: "hover";
319
318
  active: "active";
320
319
  focus: "focus";
320
+ disabled: "disabled";
321
321
  checked: "checked";
322
322
  visited: "visited";
323
323
  }>>;