@turbofy-ai/app-runtime 0.0.8 → 0.0.10

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/src/dsl.d.ts CHANGED
@@ -1639,8 +1639,30 @@ export interface ITableDataChangeTrigger<TName extends string, TOperation extend
1639
1639
  new: ITriggerData;
1640
1640
  } : ITriggerData;
1641
1641
  }
1642
+ export type IScheduleRateUnit = "minutes" | "hours" | "days";
1643
+ export interface IScheduleRate {
1644
+ value: number;
1645
+ unit: IScheduleRateUnit;
1646
+ }
1642
1647
  export interface IScheduledTrigger<TName extends string> extends ISharedTriggerDeclaration<TName> {
1643
1648
  variant: TriggerVariantEnum.SCHEDULE;
1649
+ /**
1650
+ * AWS 6-field cron expression: minutes hours day-of-month month
1651
+ * day-of-week year (e.g. "0 9 * * ? *" — daily at 9:00).
1652
+ * Exactly one of `cron` and `rate` must be set for the trigger to fire.
1653
+ */
1654
+ cron?: string;
1655
+ /** Fixed-interval alternative to `cron` (e.g. every 10 minutes). */
1656
+ rate?: IScheduleRate;
1657
+ /** IANA timezone the cron expression is evaluated in. Defaults to UTC. */
1658
+ timezone?: string;
1659
+ /**
1660
+ * ISO 8601 date (e.g. "2026-08-01") or datetime before which the schedule
1661
+ * does not fire. Date-only values are interpreted as midnight UTC.
1662
+ */
1663
+ startDate?: string;
1664
+ /** ISO 8601 date or datetime after which the schedule no longer fires. */
1665
+ endDate?: string;
1644
1666
  _tsTriggerData: unknown;
1645
1667
  }
1646
1668
  export interface IManualTrigger<TName extends string> extends ISharedTriggerDeclaration<TName> {
@@ -1874,7 +1896,10 @@ export interface IPageOutput {
1874
1896
  id?: string;
1875
1897
  name: string;
1876
1898
  slugConfig: IPageSlugConfig;
1899
+ /** @deprecated Prefer `localizations`. Kept for the local DSL / old MCP. */
1877
1900
  defaultLocalization?: LocalizationDictionary;
1901
+ /** Per-locale page copies / SEO meta (`{locale}_page_{pageId}`). */
1902
+ localizations?: ILocalizationsByLocale;
1878
1903
  localizedConfig?: string;
1879
1904
  blocks: IBlockOutput[];
1880
1905
  }
@@ -1943,6 +1968,33 @@ export interface ITableDataChangeTriggerOptions {
1943
1968
  export interface ISharedTriggerOptions {
1944
1969
  condition?: string;
1945
1970
  }
1971
+ export type IScheduleTriggerOptions = ISharedTriggerOptions & {
1972
+ /**
1973
+ * ISO 8601 date (e.g. "2026-08-01") or datetime before which the schedule
1974
+ * does not fire. Date-only values are interpreted as midnight UTC.
1975
+ */
1976
+ startDate?: string;
1977
+ /** ISO 8601 date or datetime after which the schedule no longer fires. */
1978
+ endDate?: string;
1979
+ } & ({
1980
+ /**
1981
+ * AWS 6-field cron expression: minutes hours day-of-month month
1982
+ * day-of-week year (e.g. "0 9 * * ? *" — daily at 9:00).
1983
+ */
1984
+ cron: string;
1985
+ /** IANA timezone the cron expression is evaluated in. Defaults to UTC. */
1986
+ timezone?: string;
1987
+ rate?: never;
1988
+ } | {
1989
+ /** Fixed interval, e.g. { value: 10, unit: "minutes" }. */
1990
+ rate: IScheduleRate;
1991
+ cron?: never;
1992
+ timezone?: never;
1993
+ } | {
1994
+ cron?: never;
1995
+ rate?: never;
1996
+ timezone?: never;
1997
+ });
1946
1998
  export type IFlowTriggerDefinition = {
1947
1999
  variant: TriggerVariantEnum.TABLE_DATA_CHANGE;
1948
2000
  tableId: string;
@@ -1950,6 +2002,11 @@ export type IFlowTriggerDefinition = {
1950
2002
  condition?: string;
1951
2003
  } | {
1952
2004
  variant: TriggerVariantEnum.SCHEDULE;
2005
+ cron?: string;
2006
+ rate?: IScheduleRate;
2007
+ timezone?: string;
2008
+ startDate?: string;
2009
+ endDate?: string;
1953
2010
  condition?: string;
1954
2011
  } | {
1955
2012
  variant: TriggerVariantEnum.MANUAL;
@@ -1957,7 +2014,7 @@ export type IFlowTriggerDefinition = {
1957
2014
  };
1958
2015
  declare const trigger: {
1959
2016
  tableDataChange(opts: ITableDataChangeTriggerOptions): IFlowTriggerDefinition;
1960
- schedule(opts?: ISharedTriggerOptions): IFlowTriggerDefinition;
2017
+ schedule(opts?: IScheduleTriggerOptions): IFlowTriggerDefinition;
1961
2018
  manual(opts?: ISharedTriggerOptions): IFlowTriggerDefinition;
1962
2019
  };
1963
2020
  export type DeepParamObject<P> = P extends object ? {
@@ -2086,7 +2143,7 @@ export interface IValidateFlowsOptions {
2086
2143
  export declare function validateFlows(flows: IValidatableFlow[], opts?: IValidateFlowsOptions): IFlowValidationResult;
2087
2144
 
2088
2145
  declare namespace flowBuilder {
2089
- export { IFlowOptions, IFlowOutput, IFlowStepDefinition, IFlowStepOptions, IFlowTriggerDefinition, ISharedTriggerOptions, IStepParamsInput, ITableDataChangeTriggerOptions, TABLE_ID_PARAM_NAMES, buildFlow, js, secret, step, trigger };
2146
+ export { IFlowOptions, IFlowOutput, IFlowStepDefinition, IFlowStepOptions, IFlowTriggerDefinition, IScheduleTriggerOptions, ISharedTriggerOptions, IStepParamsInput, ITableDataChangeTriggerOptions, TABLE_ID_PARAM_NAMES, buildFlow, js, secret, step, trigger };
2090
2147
  }
2091
2148
  declare namespace dataBuilder {
2092
2149
  export { TableDef, TableOpts, TableSearchConfig, build, enumType, fields, table };
package/dist/src/dsl.js CHANGED
@@ -430,7 +430,26 @@ function pageLocalizedConfigCode() {
430
430
  const slugConfig = $$self.slugConfig;
431
431
  const appId = $$self.appId ?? '';
432
432
  const lang = $$args.lang ?? 'en';
433
- const activeSlug = slugConfig?.[lang]?.slug ?? slugConfig?.en?.slug ?? '/';
433
+ const resolveFallbackLocale = () => {
434
+ if (!appId) return 'en';
435
+ const appRecord = $$std.getRecord('cmsapp', appId);
436
+ if (!appRecord || typeof appRecord !== 'object') return 'en';
437
+ const settings = $$std.get(appRecord, 'settings');
438
+ const i18n = settings && typeof settings === 'object' ? settings.i18n : null;
439
+ if (!i18n || typeof i18n !== 'object') return 'en';
440
+ if (typeof i18n.fallback === 'string' && i18n.fallback) return i18n.fallback;
441
+ if (typeof i18n.default === 'string' && i18n.default) return i18n.default;
442
+ if (Array.isArray(i18n.locales) && typeof i18n.locales[0] === 'string' && i18n.locales[0]) {
443
+ return i18n.locales[0];
444
+ }
445
+ return 'en';
446
+ };
447
+ const fallbackLocale = resolveFallbackLocale();
448
+ const activeSlug =
449
+ slugConfig?.[lang]?.slug ??
450
+ slugConfig?.[fallbackLocale]?.slug ??
451
+ slugConfig?.en?.slug ??
452
+ '/';
434
453
  const activeSlugArray = activeSlug.split('/').filter(Boolean);
435
454
 
436
455
  const canonicalPathArray = [lang, ...activeSlugArray];
@@ -524,8 +543,8 @@ function pageLocalizedConfigCode() {
524
543
 
525
544
  const layers = [];
526
545
  for (const suffix of suffixes) {
527
- if (lang !== 'en') {
528
- const fallbackLayer = fetchLocalizationDictionary('en', suffix);
546
+ if (lang !== fallbackLocale) {
547
+ const fallbackLayer = fetchLocalizationDictionary(fallbackLocale, suffix);
529
548
  if (fallbackLayer) layers.push(fallbackLayer);
530
549
  }
531
550
  const activeLayer = fetchLocalizationDictionary(lang, suffix);
@@ -16622,6 +16641,112 @@ var schemas = {
16622
16641
  genericAI: genericAIStepSchema
16623
16642
  };
16624
16643
 
16644
+ // ../declarations/src/flows/schedule.ts
16645
+ var SCHEDULE_RATE_UNITS = [
16646
+ "minutes",
16647
+ "hours",
16648
+ "days"
16649
+ ];
16650
+ var CRON_MINUTES_PATTERN = /^[\d,\-*/]+$/;
16651
+ var CRON_HOURS_PATTERN = /^[\d,\-*/]+$/;
16652
+ var CRON_DAY_OF_MONTH_PATTERN = /^[\d,\-*/?LW]+$/i;
16653
+ var CRON_MONTH_PATTERN = /^(?:[\d,\-*/]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)+$/i;
16654
+ var CRON_DAY_OF_WEEK_PATTERN = /^(?:[\d,\-*/?L#]|SUN|MON|TUE|WED|THU|FRI|SAT)+$/i;
16655
+ var CRON_YEAR_PATTERN = /^[\d,\-*/]+$/;
16656
+ var CRON_FIELDS = [
16657
+ { label: "minutes", pattern: CRON_MINUTES_PATTERN },
16658
+ { label: "hours", pattern: CRON_HOURS_PATTERN },
16659
+ { label: "day-of-month", pattern: CRON_DAY_OF_MONTH_PATTERN },
16660
+ { label: "month", pattern: CRON_MONTH_PATTERN },
16661
+ { label: "day-of-week", pattern: CRON_DAY_OF_WEEK_PATTERN },
16662
+ { label: "year", pattern: CRON_YEAR_PATTERN }
16663
+ ];
16664
+ function validateCronExpression(cron) {
16665
+ const fields2 = cron.trim().split(/\s+/);
16666
+ if (fields2.length !== 6) {
16667
+ return [
16668
+ `Cron expression "${cron}" must have 6 fields (minutes hours day-of-month month day-of-week year), got ${fields2.length}`
16669
+ ];
16670
+ }
16671
+ const errors = [];
16672
+ fields2.forEach((field, index) => {
16673
+ if (!CRON_FIELDS[index].pattern.test(field)) {
16674
+ errors.push(
16675
+ `Cron expression "${cron}": invalid ${CRON_FIELDS[index].label} field "${field}"`
16676
+ );
16677
+ }
16678
+ });
16679
+ const dayOfMonth = fields2[2];
16680
+ const dayOfWeek = fields2[4];
16681
+ if (dayOfMonth !== "?" && dayOfWeek !== "?") {
16682
+ errors.push(
16683
+ `Cron expression "${cron}": one of day-of-month and day-of-week must be "?"`
16684
+ );
16685
+ }
16686
+ return errors;
16687
+ }
16688
+ function isValidScheduleDate(date5) {
16689
+ return !Number.isNaN(Date.parse(date5));
16690
+ }
16691
+ function isValidTimezone(timezone) {
16692
+ try {
16693
+ new Intl.DateTimeFormat("en-US", { timeZone: timezone });
16694
+ return true;
16695
+ } catch {
16696
+ return false;
16697
+ }
16698
+ }
16699
+ function validateRate(rate) {
16700
+ const errors = [];
16701
+ if (!Number.isInteger(rate.value) || rate.value < 1) {
16702
+ errors.push(
16703
+ `Schedule rate value must be a positive integer, got ${rate.value}`
16704
+ );
16705
+ }
16706
+ if (!SCHEDULE_RATE_UNITS.includes(rate.unit)) {
16707
+ errors.push(
16708
+ `Schedule rate unit must be one of ${SCHEDULE_RATE_UNITS.join(", ")}, got "${rate.unit}"`
16709
+ );
16710
+ }
16711
+ return errors;
16712
+ }
16713
+ function validateScheduleConfig(config2) {
16714
+ if (config2.cron !== void 0 && config2.rate !== void 0) {
16715
+ return ['Schedule triggers must set either "cron" or "rate", not both'];
16716
+ }
16717
+ const errors = [];
16718
+ if (config2.cron !== void 0) {
16719
+ errors.push(...validateCronExpression(config2.cron));
16720
+ }
16721
+ if (config2.rate !== void 0) {
16722
+ errors.push(...validateRate(config2.rate));
16723
+ }
16724
+ if (config2.timezone !== void 0) {
16725
+ if (config2.cron === void 0) {
16726
+ errors.push('Schedule "timezone" is only supported with "cron"');
16727
+ } else if (!isValidTimezone(config2.timezone)) {
16728
+ errors.push(`Unknown timezone "${config2.timezone}"`);
16729
+ }
16730
+ }
16731
+ if (config2.startDate !== void 0 && !isValidScheduleDate(config2.startDate)) {
16732
+ errors.push(
16733
+ `Schedule "startDate" must be an ISO 8601 date, got "${config2.startDate}"`
16734
+ );
16735
+ }
16736
+ if (config2.endDate !== void 0 && !isValidScheduleDate(config2.endDate)) {
16737
+ errors.push(
16738
+ `Schedule "endDate" must be an ISO 8601 date, got "${config2.endDate}"`
16739
+ );
16740
+ }
16741
+ if (config2.startDate !== void 0 && config2.endDate !== void 0 && isValidScheduleDate(config2.startDate) && isValidScheduleDate(config2.endDate) && Date.parse(config2.endDate) <= Date.parse(config2.startDate)) {
16742
+ errors.push('Schedule "endDate" must be after "startDate"');
16743
+ }
16744
+ return errors;
16745
+ }
16746
+ function hasScheduleExpression(config2) {
16747
+ return config2.cron !== void 0 || config2.rate !== void 0;
16748
+ }
16749
+
16625
16750
  // ../dsl-builders/src/apps/app-builder.ts
16626
16751
  var app_builder_exports = {};
16627
16752
  __export(app_builder_exports, {
@@ -22944,7 +23069,11 @@ function collectWriteSteps(declaration) {
22944
23069
  const params = step2.params;
22945
23070
  const ofTypeConfig = step2.paramsConfig?.ofType;
22946
23071
  if (isStaticParamConfig(ofTypeConfig) && typeof params.ofType === "string") {
22947
- staticWrites.push({ stepName: step2.name, ofType: params.ofType, operation });
23072
+ staticWrites.push({
23073
+ stepName: step2.name,
23074
+ ofType: params.ofType,
23075
+ operation
23076
+ });
22948
23077
  } else {
22949
23078
  dynamicWrites.push({
22950
23079
  stepName: step2.name,
@@ -23144,6 +23273,28 @@ function validateFlow(declaration, ctx) {
23144
23273
  for (const step2 of Object.values(steps)) {
23145
23274
  validateStepParams(step2, issue2, errors, warnings);
23146
23275
  }
23276
+ for (const [triggerName, trigger2] of Object.entries(
23277
+ declaration.triggers ?? {}
23278
+ )) {
23279
+ if (trigger2.variant !== "SCHEDULE" /* SCHEDULE */) continue;
23280
+ const scheduleErrors = validateScheduleConfig(trigger2);
23281
+ for (const message of scheduleErrors) {
23282
+ errors.push(
23283
+ issue2(
23284
+ `triggers.${triggerName}`,
23285
+ `Trigger "${triggerName}": ${message}`
23286
+ )
23287
+ );
23288
+ }
23289
+ if (scheduleErrors.length === 0 && !hasScheduleExpression(trigger2)) {
23290
+ warnings.push(
23291
+ issue2(
23292
+ `triggers.${triggerName}`,
23293
+ `Trigger "${triggerName}": schedule trigger has neither "cron" nor "rate" and will never fire`
23294
+ )
23295
+ );
23296
+ }
23297
+ }
23147
23298
  const { staticWrites, dynamicWrites } = collectWriteSteps(declaration);
23148
23299
  const tableTriggers = collectTableDataChangeTriggers(declaration);
23149
23300
  for (const write of staticWrites) {
@@ -23294,9 +23445,19 @@ var trigger = {
23294
23445
  ...opts.condition !== void 0 ? { condition: opts.condition } : {}
23295
23446
  };
23296
23447
  },
23448
+ // opts stays optional for round-trip fidelity: legacy declarations may
23449
+ // hold a schedule trigger without an expression (it never fires and is
23450
+ // reported as a validation warning).
23297
23451
  schedule(opts) {
23298
23452
  return {
23299
23453
  variant: "SCHEDULE" /* SCHEDULE */,
23454
+ ...opts && "cron" in opts ? {
23455
+ cron: opts.cron,
23456
+ ...opts.timezone !== void 0 ? { timezone: opts.timezone } : {}
23457
+ } : {},
23458
+ ...opts && "rate" in opts ? { rate: opts.rate } : {},
23459
+ ...opts?.startDate !== void 0 ? { startDate: opts.startDate } : {},
23460
+ ...opts?.endDate !== void 0 ? { endDate: opts.endDate } : {},
23300
23461
  ...opts?.condition !== void 0 ? { condition: opts.condition } : {}
23301
23462
  };
23302
23463
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbofy-ai/app-runtime",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -30,6 +30,7 @@
30
30
  ],
31
31
  "scripts": {
32
32
  "build": "npm run generate && tsc && tsx scripts/bundle-dsl.ts",
33
+ "prepublishOnly": "npm run build",
33
34
  "generate": "tsx scripts/write-ui-reexports.ts",
34
35
  "pretypecheck": "npm run generate",
35
36
  "typecheck": "tsc --noEmit"