@stll/agent-input 0.2.1 → 0.3.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/dist/country.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { t as Normalized } from "./normalized-B9RxhmIz.js";
2
1
  import { CountryAlpha3Code, CountryCode } from "@stll/country-codes";
2
+ import { t as Normalized } from "./normalized-B9RxhmIz.js";
3
3
  //#region src/country.d.ts
4
4
  /**
5
5
  * Jurisdictions that publish law without being ISO 3166-1 countries.
@@ -62,4 +62,5 @@ export declare const countryCodeIn: (value: CountryValue, spelling?: CountrySpel
62
62
  * question about Czech law with Slovak decisions.
63
63
  */
64
64
  export declare const normalizeCountry: (input: unknown, options?: CountryOptions) => Normalized<CountryValue>;
65
- //#endregion
65
+ //#endregion
66
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { a as askForFix, i as NormalizedOptional, n as NormalizedAbsent, o as askSentence, r as NormalizedAsk, s as readAsAbsent, t as Normalized } from "./normalized-B9RxhmIz.js";
2
1
  import { COUNTRY_INPUT_MAX_CHARS, CountryAlpha2, CountryAlpha3, CountryOptions, CountrySpelling, CountryValue, countryCodeIn, normalizeCountry } from "./country.js";
3
2
  import { DATE_VALUE_HINT, DateBound, DateBoundOptions, DateValueOptions, normalizeDateBound, normalizeDateValue } from "./date-value.js";
4
- import { isPlausibleLocale, normalizeLocale } from "./locale.js";
5
- import { StringListOptions, normalizeStringList } from "./string-list.js";
6
3
  import { DateFormatStyle } from "@stll/template-conditions";
4
+ import { StringListOptions, normalizeStringList } from "./string-list.js";
5
+ import { a as askForFix, i as NormalizedOptional, n as NormalizedAbsent, o as askSentence, r as NormalizedAsk, s as readAsAbsent, t as Normalized } from "./normalized-B9RxhmIz.js";
6
+ import { isPlausibleLocale, normalizeLocale } from "./locale.js";
7
7
  //#region src/absent.d.ts
8
8
  /**
9
9
  * Placeholders on optional filters.
@@ -139,6 +139,9 @@ export declare const AGENT_INPUT_NORMALIZATION_KEY = "x-stella-agent-input";
139
139
  export declare const AGENT_INPUT_NORMALIZATION_KIND: {
140
140
  readonly boolean: "boolean";
141
141
  readonly country: "country";
142
+ readonly currency: "currency";
143
+ readonly dataBox: "data-box";
144
+ readonly email: "email";
142
145
  readonly date: "date";
143
146
  readonly dateFormat: "date-format";
144
147
  readonly eli: "eli";
@@ -146,6 +149,7 @@ export declare const AGENT_INPUT_NORMALIZATION_KIND: {
146
149
  readonly filter: "filter";
147
150
  readonly locale: "locale";
148
151
  readonly number: "number";
152
+ readonly slug: "slug";
149
153
  readonly stringList: "string-list";
150
154
  readonly uuid: "uuid";
151
155
  };
@@ -243,4 +247,10 @@ export declare const normalizeAgentInput: ({ path, placeholders, readers, schema
243
247
  value: unknown;
244
248
  }) => AgentInputNormalizationResult;
245
249
  //#endregion
250
+ //#region src/email-address.d.ts
251
+ export declare const EMAIL_ADDRESS_PATTERN: RegExp;
252
+ //#endregion
253
+ //#region src/data-box-id.d.ts
254
+ export declare const DATA_BOX_ID_PATTERN: RegExp;
255
+ //#endregion
246
256
  export { type AgentInputCountryAnnotation, type AgentInputNormalizationAnnotation, type AgentInputNormalizationIssue, type AgentInputNormalizationKind, type AgentInputNormalizationResult, type AgentInputPlaceholderPolicy, type AgentInputReaders, COUNTRY_INPUT_MAX_CHARS, type CountryAlpha2, type CountryAlpha3, type CountryOptions, type CountrySpelling, type CountryValue, DATE_VALUE_HINT, type DateBound, type DateBoundOptions, type DateValueOptions, type EliOptions, type Normalized, type NormalizedAbsent, type NormalizedAsk, type NormalizedOptional, type NumberInRangeOptions, type NumberOptions, type StringListOptions, type UuidOptions, type VocabularyEntry, type VocabularyOptions, askForFix, askSentence, countryCodeIn, isPlausibleLocale, normalizeCountry, normalizeDateBound, normalizeDateValue, normalizeLocale, normalizeStringList, readAsAbsent };
package/dist/index.js CHANGED
@@ -663,11 +663,59 @@ const normalizeVocabularyValue = (input, entries, options = {}) => {
663
663
  return otherContaining.length === 0 ? readValueAs(input, onlyContaining) : askAmong(containing);
664
664
  };
665
665
  //#endregion
666
+ //#region src/currency-code.ts
667
+ const normalizeCurrencyCode = (input) => {
668
+ const value = typeof input === "string" ? input.trim().toUpperCase() : void 0;
669
+ return value !== void 0 && /^[A-Z]{3}$/u.test(value) ? readValueAs(input, value) : askForFix({
670
+ input,
671
+ expected: "a three-letter currency code",
672
+ hint: "Pass a three-letter currency code, such as EUR or CZK."
673
+ });
674
+ };
675
+ //#endregion
676
+ //#region src/data-box-id.ts
677
+ const DATA_BOX_ID_PATTERN = /^[A-Za-z0-9]{7}$/u;
678
+ /** Data box identifiers are case-sensitive external keys, never record UUIDs. */
679
+ const normalizeDataBoxId = (input) => {
680
+ const value = typeof input === "string" ? input.trim() : void 0;
681
+ return value !== void 0 && DATA_BOX_ID_PATTERN.test(value) ? readValueAs(input, value) : askForFix({
682
+ input,
683
+ expected: "a seven-character data box ID",
684
+ hint: "Pass the seven letters and digits of the recipient's data box ID."
685
+ });
686
+ };
687
+ //#endregion
688
+ //#region src/email-address.ts
689
+ const EMAIL_ADDRESS_PATTERN = /^[\w+-]+(?:\.[\w+-]+)*@[\da-zA-Z]+(?:[.-][\da-zA-Z]+)*\.[a-zA-Z]{2,}$/u;
690
+ /** Preserve the local part's case: contact addresses are not account identity keys. */
691
+ const normalizeEmailAddress = (input) => {
692
+ const value = typeof input === "string" ? input.trim() : void 0;
693
+ return value !== void 0 && value.length <= 320 && EMAIL_ADDRESS_PATTERN.test(value) ? readValueAs(input, value) : askForFix({
694
+ input,
695
+ expected: "an email address",
696
+ hint: "Pass one email address, such as name@example.com, without a display name."
697
+ });
698
+ };
699
+ //#endregion
700
+ //#region src/slug.ts
701
+ /** Case and internal separators identify a different slug; only outer whitespace is noise. */
702
+ const normalizeSlug = (input) => {
703
+ if (typeof input === "string" && /^[a-z0-9-]+$/u.test(input.trim())) return readValueAs(input, input.trim());
704
+ return askForFix({
705
+ input,
706
+ expected: "a lowercase slug",
707
+ hint: "Use lowercase ASCII letters, digits or hyphens, without spaces."
708
+ });
709
+ };
710
+ //#endregion
666
711
  //#region src/schema.ts
667
712
  const AGENT_INPUT_NORMALIZATION_KEY = "x-stella-agent-input";
668
713
  const AGENT_INPUT_NORMALIZATION_KIND = {
669
714
  boolean: "boolean",
670
715
  country: "country",
716
+ currency: "currency",
717
+ dataBox: "data-box",
718
+ email: "email",
671
719
  date: "date",
672
720
  dateFormat: "date-format",
673
721
  eli: "eli",
@@ -675,6 +723,7 @@ const AGENT_INPUT_NORMALIZATION_KIND = {
675
723
  filter: "filter",
676
724
  locale: "locale",
677
725
  number: "number",
726
+ slug: "slug",
678
727
  stringList: "string-list",
679
728
  uuid: "uuid"
680
729
  };
@@ -685,6 +734,9 @@ const agentInputNormalizationGuidance = (annotation) => {
685
734
  switch (annotation.kind) {
686
735
  case "boolean": return "Use a JSON boolean; common unambiguous yes/no words are normalized.";
687
736
  case "country": return "An ISO 3166-1 alpha-3 or alpha-2 code, or the country's name, is read.";
737
+ case "currency": return "Use a three-letter currency code; case and surrounding whitespace are normalized.";
738
+ case "data-box": return "Use the seven-character data box ID; surrounding whitespace is trimmed.";
739
+ case "email": return "Use an email address; surrounding whitespace is trimmed.";
688
740
  case "date": return annotation.bound === void 0 ? "Use ISO YYYY-MM-DD; unambiguous localized calendar dates are normalized." : `Use ISO YYYY-MM-DD; a bare year or year-month reads as its ${annotation.bound === "start" ? "first" : "last"} day.`;
689
741
  case "date-format": return "Use an object with a BCP-47 locale, such as {\"locale\":\"en-GB\",\"style\":\"short\"}; an unambiguous combined string such as \"en-GB-short\" is normalized.";
690
742
  case "eli": return "A short, prefix-less or reordered ELI is read as the canonical one.";
@@ -692,6 +744,7 @@ const agentInputNormalizationGuidance = (annotation) => {
692
744
  case "filter": return "Omit it to search without this filter; a placeholder such as \"all\" or \"-\" reads as no filter.";
693
745
  case "locale": return "Use a BCP-47 language tag, for example \"cs\" or \"en-GB\".";
694
746
  case "number": return annotation.range === "clamp" ? "Use a JSON number; a value outside the range is clamped to it." : "Use a JSON number; unambiguous localized numeric notation is normalized.";
747
+ case "slug": return "Use a-z, 0-9 or hyphens; outer whitespace is trimmed.";
695
748
  case "string-list": return "Use a JSON array of strings; a single string is read as a one-item list.";
696
749
  case "uuid": return "Use an id a previous call returned; a placeholder id such as all zeros reads as no value.";
697
750
  default: return panic("Unhandled agent input normalization kind");
@@ -809,6 +862,9 @@ const normalizeLeaf = ({ annotation, path, readers, schema, value }) => {
809
862
  path,
810
863
  value
811
864
  });
865
+ case "currency": return normalizeCurrencyCode(value);
866
+ case "data-box": return normalizeDataBoxId(value);
867
+ case "email": return normalizeEmailAddress(value);
812
868
  case "date": {
813
869
  const locales = annotation.locale === void 0 ? void 0 : [annotation.locale];
814
870
  return annotation.bound === void 0 ? normalizeDateValue(value, locales === void 0 ? void 0 : { locales }) : normalizeDateBound(value, {
@@ -839,6 +895,7 @@ const normalizeLeaf = ({ annotation, path, readers, schema, value }) => {
839
895
  });
840
896
  return normalizeNumber(value, locale === void 0 ? void 0 : { locale });
841
897
  }
898
+ case "slug": return normalizeSlug(value);
842
899
  case "string-list": return normalizeStringList(value, { split: "never" });
843
900
  case "uuid": return normalizeUuid(value);
844
901
  default: return panic("Unhandled agent input normalization kind");
@@ -1197,4 +1254,4 @@ const normalizeAgentInput = ({ path = "", placeholders = "absent", readers = {},
1197
1254
  };
1198
1255
  };
1199
1256
  //#endregion
1200
- export { ABSENT_PLACEHOLDERS, AGENT_INPUT_NORMALIZATION_KEY, AGENT_INPUT_NORMALIZATION_KIND, COUNTRY_INPUT_MAX_CHARS, DATE_FORMAT_SPEC_HINT, DATE_VALUE_HINT, SENTINEL_UUIDS, agentInputNormalization, agentInputNormalizationGuidance, agentInputNormalizationMetadata, askForFix, askSentence, countryCodeIn, isAbsentPlaceholder, isPlausibleLocale, isSentinelUuid, normalizeAgentInput, normalizeBoolean, normalizeCountry, normalizeDateBound, normalizeDateFormatSpec, normalizeDateValue, normalizeEli, normalizeEnumValue, normalizeLocale, normalizeNumber, normalizeNumberInRange, normalizeStringList, normalizeUuid, normalizeVocabularyValue, readAsAbsent };
1257
+ export { ABSENT_PLACEHOLDERS, AGENT_INPUT_NORMALIZATION_KEY, AGENT_INPUT_NORMALIZATION_KIND, COUNTRY_INPUT_MAX_CHARS, DATA_BOX_ID_PATTERN, DATE_FORMAT_SPEC_HINT, DATE_VALUE_HINT, EMAIL_ADDRESS_PATTERN, SENTINEL_UUIDS, agentInputNormalization, agentInputNormalizationGuidance, agentInputNormalizationMetadata, askForFix, askSentence, countryCodeIn, isAbsentPlaceholder, isPlausibleLocale, isSentinelUuid, normalizeAgentInput, normalizeBoolean, normalizeCountry, normalizeDateBound, normalizeDateFormatSpec, normalizeDateValue, normalizeEli, normalizeEnumValue, normalizeLocale, normalizeNumber, normalizeNumberInRange, normalizeStringList, normalizeUuid, normalizeVocabularyValue, readAsAbsent };
@@ -15,4 +15,5 @@ export type NumericTokenOptions = {
15
15
  export declare const parseIntegerToken: (input: unknown, options?: NumericTokenOptions) => Result<number, InvalidNumericTokenError>;
16
16
  /** Grammar: `-?[0-9]+(\.[0-9]+)?`; no grouping, exponent or implicit whitespace. */
17
17
  export declare const parseDecimalToken: (input: unknown, options?: NumericTokenOptions) => Result<number, InvalidNumericTokenError>;
18
- //#endregion
18
+ //#endregion
19
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/agent-input",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Lenient readers for values agents write: dates, date bounds, date-format specs, numbers, booleans, locales, countries, enum and vocabulary values, ids, ELIs, string lists",
5
5
  "keywords": [
6
6
  "agent",
@@ -71,7 +71,7 @@
71
71
  "@stll/country-codes": "^0.2.0",
72
72
  "@stll/fuzzy-search": "1.4.0",
73
73
  "@stll/template-conditions": "^0.6.4",
74
- "@stll/text-normalize": "^0.4.0",
74
+ "@stll/text-normalize": "^0.5.2",
75
75
  "@stll/time": "0.4.1",
76
76
  "better-result": "3.0.1"
77
77
  },
@@ -80,7 +80,7 @@
80
80
  "@stll/typescript-config": "0.0.0",
81
81
  "bun-types": "1.4.4",
82
82
  "fast-check": "^4.10.2",
83
- "tsdown": "0.23.0",
83
+ "tsdown": "0.23.1",
84
84
  "tsrs": "0.18.0-ts7.1.0-dev.20260929"
85
85
  },
86
86
  "main": "./dist/index.js",