@rebilder/render-md 0.4.0 → 0.5.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/index.d.ts CHANGED
@@ -145,8 +145,8 @@ declare function renderCatalogMarkdown(items: CatalogItemSource[], opts?: Render
145
145
  *
146
146
  * The same guarantee as the commerce types applies to every field here: it is
147
147
  * authoritative merchant data, and the renderers only transform format. They
148
- * never invent, estimate, or reword a value found on these types (CLAUDE.md
149
- * source validation).
148
+ * never invent, estimate, or reword a value found on these types (project
149
+ * convention: source validation).
150
150
  *
151
151
  * Why two types (document + collection) and not one per vertical: see the
152
152
  * promotion bar in README.md. Every vertical evaluated so far reduces to
@@ -437,6 +437,28 @@ declare function renderCollectionMarkdown(collection: CollectionSource, opts?: R
437
437
  * `renderProductJsonLd`.
438
438
  */
439
439
  declare function renderCollectionJsonLd(collection: CollectionSource): Record<string, unknown>;
440
+ type PricingEntityType = 'SoftwareApplication' | 'Product' | 'Service';
441
+ interface RenderPricingJsonLdOptions {
442
+ /**
443
+ * Schema.org top-level type for the priced offering.
444
+ * Defaults to `'SoftwareApplication'`; callers may also pass `'Product'` or `'Service'`.
445
+ */
446
+ entityType?: PricingEntityType;
447
+ /** Optional schema.org `applicationCategory` (emitted only when `entityType` is `'SoftwareApplication'`). */
448
+ applicationCategory?: string;
449
+ /** Optional schema.org `operatingSystem` (emitted only when `entityType` is `'SoftwareApplication'`). */
450
+ operatingSystem?: string;
451
+ }
452
+ /**
453
+ * Render multi-tier pricing JSON-LD (`SoftwareApplication` / `Product` /
454
+ * `Service` with `Offer[]` + `UnitPriceSpecification` + numeric quota
455
+ * `PropertyValue`s) from a `CollectionSource` of plan items.
456
+ *
457
+ * Pure, deterministic, injection-only: every price, currency, billing period,
458
+ * unit, and URL comes verbatim from the source object. Throws on non-integer
459
+ * minor units or contradictory money ranges, matching `formatMoney`.
460
+ */
461
+ declare function renderPricingJsonLd(collection: CollectionSource, options?: RenderPricingJsonLdOptions): Record<string, unknown>;
440
462
 
441
463
  /**
442
464
  * Fact rendering: the deterministic `FactValue` → markdown mapping, the fixed
@@ -563,4 +585,4 @@ declare const FRONTMATTER_MAX_BYTES = 2048;
563
585
  */
564
586
  declare function renderFrontmatter(fields: FrontmatterFields): string;
565
587
 
566
- export { ACCESS_LABELS, ALLOWED_URL_SCHEMES, type ActionKind, type ActionSource, type Availability, BASELINE_PROFILE, BOOLEAN_LABELS, type BillingPeriod, CLOSED_LABEL, COMPATIBILITY_RUNTIME_VERSION, type CatalogItemSource, type CollectionItemSource, type CollectionSource, type CompatibilityProfile, type CompatibilityRendering, type ContactSource, type DocumentAccess, type DocumentKind, type DocumentSectionSource, type DocumentSource, FRONTMATTER_MAX_BYTES, type Fact, type FactValue, type FrontmatterFields, type HoursException, type HoursInterval, type HoursRule, type HoursSpec, type LinkSource, type Money, NOT_STATED_LABEL, PERIOD_SUFFIX, type PolicySource, type ProductSource, type ProductVariantSource, type RenderOptions, type ReturnsSource, SEE_PAGE_LABEL, type ShippingSource, WEEKDAY_LABELS, WEEKDAY_ORDER, type Weekday, applyCompatibilityProfile, formatMoney, renderCatalogMarkdown, renderCollectionJsonLd, renderCollectionMarkdown, renderDocumentMarkdown, renderFrontmatter, renderPolicyMarkdown, renderProductJsonLd, renderProductMarkdown, validateCompatibilityProfile };
588
+ export { ACCESS_LABELS, ALLOWED_URL_SCHEMES, type ActionKind, type ActionSource, type Availability, BASELINE_PROFILE, BOOLEAN_LABELS, type BillingPeriod, CLOSED_LABEL, COMPATIBILITY_RUNTIME_VERSION, type CatalogItemSource, type CollectionItemSource, type CollectionSource, type CompatibilityProfile, type CompatibilityRendering, type ContactSource, type DocumentAccess, type DocumentKind, type DocumentSectionSource, type DocumentSource, FRONTMATTER_MAX_BYTES, type Fact, type FactValue, type FrontmatterFields, type HoursException, type HoursInterval, type HoursRule, type HoursSpec, type LinkSource, type Money, NOT_STATED_LABEL, PERIOD_SUFFIX, type PolicySource, type PricingEntityType, type ProductSource, type ProductVariantSource, type RenderOptions, type RenderPricingJsonLdOptions, type ReturnsSource, SEE_PAGE_LABEL, type ShippingSource, WEEKDAY_LABELS, WEEKDAY_ORDER, type Weekday, applyCompatibilityProfile, formatMoney, renderCatalogMarkdown, renderCollectionJsonLd, renderCollectionMarkdown, renderDocumentMarkdown, renderFrontmatter, renderPolicyMarkdown, renderPricingJsonLd, renderProductJsonLd, renderProductMarkdown, validateCompatibilityProfile };
package/dist/index.js CHANGED
@@ -781,6 +781,165 @@ function renderCollectionJsonLd(collection) {
781
781
  }
782
782
  return out;
783
783
  }
784
+ var PERIOD_UNIT_CODE = {
785
+ hour: "HUR",
786
+ day: "DAY",
787
+ week: "WEE",
788
+ month: "MON",
789
+ quarter: "QAN",
790
+ year: "ANN"
791
+ };
792
+ var PERIOD_UNIT_TEXT = {
793
+ one_time: "one-time",
794
+ hour: "hour",
795
+ day: "day",
796
+ week: "week",
797
+ month: "month",
798
+ quarter: "quarter",
799
+ year: "year"
800
+ };
801
+ function unitPriceSpec(v, label, includeName) {
802
+ const currency = v.value.currency.toUpperCase();
803
+ const minPrice = toDecimalString(v.value);
804
+ const spec = {
805
+ "@type": "UnitPriceSpecification"
806
+ };
807
+ if (includeName && label.trim().length > 0) {
808
+ spec.name = label.trim();
809
+ }
810
+ if (v.maxValue !== void 0) {
811
+ if (v.maxValue.currency.toUpperCase() !== currency) {
812
+ throw new TypeError(
813
+ `Money range currencies must match, got: ${v.value.currency} and ${v.maxValue.currency}`
814
+ );
815
+ }
816
+ if (v.maxValue.amount < v.value.amount) {
817
+ throw new TypeError(
818
+ `Money range maxValue must not be below value, got: ${String(v.value.amount)} and ${String(v.maxValue.amount)}`
819
+ );
820
+ }
821
+ spec.minPrice = minPrice;
822
+ spec.maxPrice = toDecimalString(v.maxValue);
823
+ } else {
824
+ spec.price = minPrice;
825
+ }
826
+ spec.priceCurrency = currency;
827
+ const perText = v.per?.trim();
828
+ if (v.period !== void 0) {
829
+ const unitCode = PERIOD_UNIT_CODE[v.period];
830
+ if (unitCode !== void 0) spec.unitCode = unitCode;
831
+ spec.unitText = PERIOD_UNIT_TEXT[v.period];
832
+ } else if (perText !== void 0 && perText.length > 0) {
833
+ spec.unitText = perText;
834
+ }
835
+ if (perText !== void 0 && perText.length > 0) {
836
+ spec.referenceQuantity = {
837
+ "@type": "QuantitativeValue",
838
+ value: 1,
839
+ unitText: perText
840
+ };
841
+ }
842
+ return spec;
843
+ }
844
+ function propertyValueFor(fact) {
845
+ const name = fact.label.trim();
846
+ if (name.length === 0) return null;
847
+ switch (fact.value.type) {
848
+ case "number": {
849
+ if (!Number.isFinite(fact.value.value)) return null;
850
+ const text2 = String(fact.value.value);
851
+ if (text2.includes("e") || text2.includes("E")) return null;
852
+ const prop = {
853
+ "@type": "PropertyValue",
854
+ name,
855
+ value: fact.value.value
856
+ };
857
+ const unit = fact.value.unit?.trim();
858
+ if (unit !== void 0 && unit.length > 0) prop.unitText = unit;
859
+ return prop;
860
+ }
861
+ case "boolean":
862
+ return { "@type": "PropertyValue", name, value: fact.value.value };
863
+ case "text": {
864
+ const value = fact.value.value.trim();
865
+ return value.length > 0 ? { "@type": "PropertyValue", name, value } : null;
866
+ }
867
+ case "list":
868
+ return fact.value.value.length > 0 ? { "@type": "PropertyValue", name, value: fact.value.value.join(", ") } : null;
869
+ case "date":
870
+ return isIsoDate(fact.value.value) ? { "@type": "PropertyValue", name, value: fact.value.value } : null;
871
+ case "url":
872
+ return isAllowedUrl(fact.value.value) ? { "@type": "PropertyValue", name, value: fact.value.value } : null;
873
+ case "money":
874
+ case "hours":
875
+ return null;
876
+ }
877
+ }
878
+ function pricingOffer(item) {
879
+ const out = {
880
+ "@type": "Offer",
881
+ name: item.title
882
+ };
883
+ if (isAllowedUrl(item.url)) out.url = item.url;
884
+ if (item.summary !== void 0 && item.summary.trim().length > 0) {
885
+ out.description = item.summary;
886
+ }
887
+ const facts = item.facts ?? [];
888
+ const moneyFacts = [];
889
+ const additionalProperties = [];
890
+ for (const fact of facts) {
891
+ if (fact.value.type === "money") {
892
+ moneyFacts.push({ label: fact.label, value: fact.value });
893
+ } else {
894
+ const prop = propertyValueFor(fact);
895
+ if (prop !== null) additionalProperties.push(prop);
896
+ }
897
+ }
898
+ if (moneyFacts.length > 0) {
899
+ const specs = moneyFacts.map(
900
+ (mf) => unitPriceSpec(mf.value, mf.label, moneyFacts.length > 1)
901
+ );
902
+ const primary = moneyFacts[0];
903
+ if (primary.value.maxValue === void 0) {
904
+ out.price = toDecimalString(primary.value.value);
905
+ }
906
+ out.priceCurrency = primary.value.value.currency.toUpperCase();
907
+ out.priceSpecification = specs.length === 1 ? specs[0] : specs;
908
+ }
909
+ if (additionalProperties.length > 0) {
910
+ out.itemOffered = {
911
+ "@type": "Service",
912
+ name: item.title,
913
+ additionalProperty: additionalProperties
914
+ };
915
+ }
916
+ return out;
917
+ }
918
+ function renderPricingJsonLd(collection, options = {}) {
919
+ const entityType = options.entityType ?? "SoftwareApplication";
920
+ const out = {
921
+ "@context": "https://schema.org",
922
+ "@type": entityType
923
+ };
924
+ if (isAllowedUrl(collection.url)) out.url = collection.url;
925
+ if (collection.title !== void 0) out.name = collection.title;
926
+ if (collection.language !== void 0 && isLanguageTag(collection.language)) {
927
+ out.inLanguage = collection.language;
928
+ }
929
+ if (entityType === "SoftwareApplication") {
930
+ if (options.applicationCategory !== void 0 && options.applicationCategory.trim().length > 0) {
931
+ out.applicationCategory = options.applicationCategory.trim();
932
+ }
933
+ if (options.operatingSystem !== void 0 && options.operatingSystem.trim().length > 0) {
934
+ out.operatingSystem = options.operatingSystem.trim();
935
+ }
936
+ }
937
+ out.offers = collection.items.slice(0, MAX_COLLECTION_ROWS).map(pricingOffer);
938
+ if (collection.updated !== void 0 && isIsoDate(collection.updated)) {
939
+ out.dateModified = collection.updated;
940
+ }
941
+ return out;
942
+ }
784
943
 
785
944
  // src/compatibility.ts
786
945
  var BASELINE_PROFILE = Object.freeze({
@@ -898,6 +1057,6 @@ function renderFrontmatter(fields) {
898
1057
  return byteLength(short) <= FRONTMATTER_MAX_BYTES ? short : "";
899
1058
  }
900
1059
 
901
- export { ACCESS_LABELS, ALLOWED_URL_SCHEMES, BASELINE_PROFILE, BOOLEAN_LABELS, CLOSED_LABEL, COMPATIBILITY_RUNTIME_VERSION, FRONTMATTER_MAX_BYTES, NOT_STATED_LABEL, PERIOD_SUFFIX, SEE_PAGE_LABEL, WEEKDAY_LABELS, WEEKDAY_ORDER, applyCompatibilityProfile, formatMoney, renderCatalogMarkdown, renderCollectionJsonLd, renderCollectionMarkdown, renderDocumentMarkdown, renderFrontmatter, renderPolicyMarkdown, renderProductJsonLd, renderProductMarkdown, validateCompatibilityProfile };
1060
+ export { ACCESS_LABELS, ALLOWED_URL_SCHEMES, BASELINE_PROFILE, BOOLEAN_LABELS, CLOSED_LABEL, COMPATIBILITY_RUNTIME_VERSION, FRONTMATTER_MAX_BYTES, NOT_STATED_LABEL, PERIOD_SUFFIX, SEE_PAGE_LABEL, WEEKDAY_LABELS, WEEKDAY_ORDER, applyCompatibilityProfile, formatMoney, renderCatalogMarkdown, renderCollectionJsonLd, renderCollectionMarkdown, renderDocumentMarkdown, renderFrontmatter, renderPolicyMarkdown, renderPricingJsonLd, renderProductJsonLd, renderProductMarkdown, validateCompatibilityProfile };
902
1061
  //# sourceMappingURL=index.js.map
903
1062
  //# sourceMappingURL=index.js.map