mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-19 00:02:03 +00:00
e47aedac0a
* feat: add datatable_migrations table * feat: add route to run datatable migrations * feat: sync datatable migrations as .up.sql/.down.sql files * feat: add datatable migrate up/down commands and post-push run prompt * feat: add datatable migrate new command to scaffold migrations * feat: add datatable migrations management UI * feat: prompt to create migration on DDL in datatable SQL editors * feat: support running a single specific datatable migration * feat: view migration content, run single migration, fix stacked modal * feat: per-row revert button with out-of-order warning * fix: avoid migrations list flicker on refresh after an action * feat: generate initial datatable migration via pg_dump * fix: surface datatable migration API error details in toasts * fix: revert created migration if create-and-run fails to run * fix: include postgres error detail in migration run/rollback failures * feat: sync datatable migrations as files via the workspace export * refactor: move datatable migrations to migrations/datatable/ path * fix: drop redundant datatable_migration label in sync output * fix: exclude datatable migration sql files from script metadata generation * feat: run datatable migrations as user-permissioned labeled jobs * feat: reject invalid datatable migrations on sync push * feat: datatable migrate up/down default to all datatables, --datatable to target one * fix: surface postgres error detail when datatable migrations fail to run * chore: regenerate CLI docs for datatable migrate commands * feat: default new datatable migration to a BEGIN/END transaction template * fix: validate datatable migration name and datatable at the API boundary * fix: ensure detected DDL ends with semicolon when wrapped in transaction * fix: re-prompt instead of stripping DDL when new-migration modal is cancelled * feat: refresh datatable schema after running a migration from the SQL REPL * feat: record db manager DDL on data tables as migrations * feat: make datatable migrations opt-in per data table * fix: make migration view editor read-only so its code can scroll * fix: don't re-prompt DDL guard when creating a migration without running * feat: generate down migrations for db manager DDL (postgres) * fix: correct down migration for db manager alters (no double-wrap, serial) * feat: explain migrations purpose with a tooltip in the migrations modal * compare paeg * feat: add datatable_migration kind to workspace diff pipeline * chore: point ee-repo-ref at datatable_migration git-sync companion * fix: harden datatable migration version allocation and initial-migration bookkeeping, add tests * feat: deploy and run datatable migrations on workspace merge Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Refactor + handle datatable setting delete/rename * refactor: move datatable migration rename/delete cascade into module Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(windmill-utils-internal): bump to 1.7.1 for datatable migration deploy provider methods Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(db-manager): add Migrations button to top bar, make Refresh icon-only Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * BEGIN/END placeholder in down migration * feat: autofocus migration name input and flag it red when empty Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(datatable-migrations): allow non-admins to create/run/revert migrations, gate only opt in/out Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * border nits * refresh db manager schema on migrations * BEGIN/END scaffold in CLI * feat(cli): push local datatable migrations before running on migrate up Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat: flag invalid migration name with red border, not just empty Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor: drop random slug from auto-generated migration names Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat: offer revert-and-delete when deleting an installed migration Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat: record fork merge as a migration when target datatable opts in * nit * clone migrations on fork * windmill-utils-internal * fix(datatable-migrations): serialize run/rollback with a per-db advisory lock Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(db-manager): fail closed when migrations-status check errors on DDL apply Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs: fix generate_initial migration ordering comment to match code * chore(datatable-migrations): remove unused update_datatable_migrations endpoint Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: run DDL migration guard on the script editor Test button Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * split * ee-repo-ref * chore(frontend): sync package-lock with package.json (@emnapi deps) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(datatable-migrations): never resolve instance credentials into migration job args datatable_database_arg eagerly resolved instance data-table credentials (including the shared instance-wide Postgres password) and passed them as the migration job's plaintext `database` arg, landing in v2_job.args. Since the run route has no admin gate, a non-admin could run a migration and read args.database to recover the password, granting cross-workspace psql access to all instance data-table DBs. Pass a `datatable://<name>` reference for both resource-backed and instance data tables instead; the pg executor already resolves it to real credentials server-side at run time, so nothing sensitive is ever stored in the job args. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * nit * fix: handle dollar-quoting and comments when splitting SQL statements * feat: deploy datatable migrations on merge with explicit opt-in error * fix(frontend): sync package-lock with npm 11 peer-dep resolution npm ci failed with 'Missing: @emnapi/core@1.11.2 / @emnapi/runtime@1.11.2 from lock file'. @napi-rs/wasm-runtime declares @emnapi/core|runtime ^1.7.1 as peerDependencies while @rolldown/binding-wasm32-wasi pins them to exactly 1.10.0. Newer npm (bundled with node 24 in CI) installs the peer deps at the highest match (1.11.2) alongside rolldown's nested 1.10.0, so the ideal tree needs both versions; the committed lock only had 1.10.0. Regenerate the lock with npm 11.18 so it carries both 1.11.2 (top-level, for the peer deps) and 1.10.0 (nested, for rolldown's pin). Verified npm ci passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * nit npm publish * fix: fail closed on migrations-status error in fork schema merge * nit CI emnapi/core version * prevent initial_datatable_migration if migrations already exist * fix(datatable-migrations): validate persisted data table names as path segments edit_datatable_config only validated rename segments, not the actual settings.datatables keys, so a data table could be saved directly under a name like '..' or one containing '/'. Since new tables default to migrations_enabled = true, generate_initial_datatable_migration would then insert a migration row and the sync export would build migrations/datatable/<name>/... paths from that name, producing malformed or directory-escaping export paths. Validate every persisted data table name in edit_datatable_config (alongside the existing rename checks) and add validate_datatable_path_segment to generate_initial_datatable_migration for defense in depth. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: scope datatable _wm_migrations by data table and cascade renames/deletes Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(system_prompts): resolve nested local command groups in CLI docs generator The CLI docs generator anchored on the first `new Command()` in a file and never resolved locally-defined command groups passed as `.command("name", localCmd)`. For datatable this flattened the nested `migrate` group: it emitted `datatable new/up/down` plus a bare `datatable migrate`, and mislabeled the datatable command with the migrate group's description. jobs was broken the same way (its description was pull's, and pull/push rendered empty). Anchor block extraction on the `export default`ed command, recurse into locally-defined `const x = new Command()` groups mounted as subcommands, and render nested sub-subcommands. Regenerated docs now show `datatable migrate new/up/down` and `jobs pull/push` with their real options. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor: drop unreleased _wm_migrations legacy-upgrade handling Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: return datatable migration SQL from getItemValue for the diff drawer Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(frontend): use windmill-utils-internal 1.8.2 for migration diff drawer Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * nit * nit * fix: handle datatable migration renames on push and dedupe timestamps * fix: reject rewriting an already-applied datatable migration on upsert Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(frontend): add missing @emnapi/core and @emnapi/runtime lockfile entries Resolves npm ci EUSAGE failure: the optional cpu:wasm32 @rolldown/binding-wasm32-wasi declares deps on @emnapi/core@1.11.2 and @emnapi/runtime@1.11.2 that had no resolved lockfile entries. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(cli): datatable migrate up/down default to main datatable, not all Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: fail closed when applied status unreadable on datatable migration rewrite Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: surface full error detail in Database Manager DDL/query errors * "See migration" button in the toast * feat: add Enter shortcut to Create-a-migration in the DDL guard * fix(frontend): warn before running a newly-created datatable migration out of order The row-level Run action warns when earlier migrations are still pending, but the create-and-run paths ran a just-created migration with `only` directly, applying it ahead of older pending migrations without that confirmation. Reuse the same "Run migration out of order" confirmation across all create-and-run paths via a shared helper (datatableMigrationUtils): - NewDataTableMigrationModal "Create and run" (and the DDL guard path) - DatatableSchemaDiff fork→parent merge - dbOps schema ops (DB manager create/alter/drop) — the pure factory throws a MigrationRunCancelled sentinel on decline, which DBTableEditor treats as a silent cancel Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: keep renamed datatable migrations visible in compare view * fix: record per-migration deployment on datatable migrations disable * fix(cli): run deployed datatable migrations after workspace merge The merge command upserted datatable_migration definitions into the target workspace and reported the item as successfully deployed, but never ran the migrations. For forked datatables backed by separate databases, this left the target schema unchanged until someone manually ran `wmill datatable migrate up`, while the CLI reported a successful merge. Collect the datatable migrations deployed (not deleted) into the target and, after the deploy loop, offer to run them via the existing offerToRunNewMigrations helper — the same post-deploy run prompt the push/sync path uses (interactive only; `--yes`/non-TTY skip the mutating run, matching push behavior). Export parseDatatableMigrationDeployPath so the merge path can parse the deployed items. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(backend): serialize datatable migration edits/deletes with the run lock A migration run snapshots a migration's code_up from datatable_migrations and only records its version in the data table's _wm_migrations after the job succeeds. upsert_datatable_migration checked _wm_migrations before allowing an edit but took no lock, so a concurrent edit could read "not applied yet", rewrite code_up/code_down, and then the in-flight run would record the version for the old SQL — leaving _wm_migrations pointing at SQL that was never applied (migrate up then skips it; rollback runs a down that doesn't match). Serialize definition rewrites and deletes with the same per-database advisory lock the run/rollback paths use: - Factor the connect+advisory-lock into lock_datatable_migration_runs and the applied-versions read into read_applied_versions_on_client. - run_datatable_migrations now snapshots the definitions AFTER taking the lock, so code_up can't change between snapshot and version-record. - upsert (when changing an existing def) and delete take the lock across the applied-check and the write; delete now rejects deleting an already-applied migration (would orphan its _wm_migrations record), symmetric with upsert. Both fail closed if the data table database is unreachable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(frontend): stack the out-of-order migration confirm above the DB editor preview Creating a table on a migrations-enabled data table opened the DB table editor's "Confirm running the following" preview modal, whose confirm triggers applyDdl, which then asks for out-of-order confirmation. Both are ConfirmationModals with a hardcoded z-[9999]; the out-of-order one lives in DBManagerContent (mounted before the editor), so it rendered behind the still-open preview modal. Add an optional zIndexClass prop to ConfirmationModal (default z-[9999], backward-compatible) and give the DB-manager out-of-order confirm z-[10000] so it stacks on top. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore: update ee-repo-ref to 27672e37df5d9dfde94f19963d5ffcdf8dd5448c This commit updates the EE repository reference after PR #623 was merged in windmill-ee-private. Previous ee-repo-ref: 6c287041cd7edd4a77a4bc07ad0e156cec32cce4 New ee-repo-ref: 27672e37df5d9dfde94f19963d5ffcdf8dd5448c Automated by sync-ee-ref workflow. --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
962 lines
31 KiB
TypeScript
962 lines
31 KiB
TypeScript
/**
|
|
* Shared deploy logic for workspace fork/merge operations.
|
|
*
|
|
* Used by both the CLI (`wmill workspace merge`) and the frontend
|
|
* (`CompareWorkspaces.svelte`). The caller provides a {@link DeployProvider}
|
|
* that wraps the concrete API client (class-based for the frontend,
|
|
* standalone functions for the CLI).
|
|
*/
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Types
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export type DeployKind =
|
|
| "script"
|
|
| "flow"
|
|
| "app"
|
|
| "raw_app"
|
|
| "resource"
|
|
| "variable"
|
|
| "resource_type"
|
|
| "folder"
|
|
| "schedule"
|
|
| "datatable_migration"
|
|
| "http_trigger"
|
|
| "websocket_trigger"
|
|
| "kafka_trigger"
|
|
| "nats_trigger"
|
|
| "postgres_trigger"
|
|
| "mqtt_trigger"
|
|
| "sqs_trigger"
|
|
| "gcp_trigger"
|
|
| "azure_trigger"
|
|
| "email_trigger";
|
|
|
|
export const TRIGGER_KINDS = [
|
|
"http_trigger",
|
|
"websocket_trigger",
|
|
"kafka_trigger",
|
|
"nats_trigger",
|
|
"postgres_trigger",
|
|
"mqtt_trigger",
|
|
"sqs_trigger",
|
|
"gcp_trigger",
|
|
"azure_trigger",
|
|
"email_trigger",
|
|
] as const satisfies readonly DeployKind[];
|
|
|
|
export type TriggerDeployKind = (typeof TRIGGER_KINDS)[number];
|
|
|
|
export function isTriggerKind(kind: string): kind is TriggerDeployKind {
|
|
return (TRIGGER_KINDS as readonly string[]).includes(kind);
|
|
}
|
|
|
|
/** True for any kind that deploys via a trigger or schedule API. */
|
|
export function isTriggerOrScheduleKind(
|
|
kind: string
|
|
): kind is TriggerDeployKind | "schedule" {
|
|
return kind === "schedule" || isTriggerKind(kind);
|
|
}
|
|
|
|
export interface DeployResult {
|
|
success: boolean;
|
|
error?: string;
|
|
}
|
|
|
|
/**
|
|
* Abstraction over the generated API client.
|
|
* Both the frontend (class-based services) and the CLI (standalone functions)
|
|
* can satisfy this interface with a thin adapter.
|
|
*/
|
|
export interface DeployProvider {
|
|
// Existence checks
|
|
existsFlowByPath(p: { workspace: string; path: string }): Promise<boolean>;
|
|
existsScriptByPath(p: { workspace: string; path: string }): Promise<boolean>;
|
|
existsApp(p: { workspace: string; path: string }): Promise<boolean>;
|
|
existsVariable(p: { workspace: string; path: string }): Promise<boolean>;
|
|
existsResource(p: { workspace: string; path: string }): Promise<boolean>;
|
|
existsResourceType(p: { workspace: string; path: string }): Promise<boolean>;
|
|
existsFolder(p: { workspace: string; name: string }): Promise<boolean>;
|
|
// Flows
|
|
getFlowByPath(p: { workspace: string; path: string }): Promise<any>;
|
|
createFlow(p: { workspace: string; requestBody: any }): Promise<any>;
|
|
updateFlow(p: {
|
|
workspace: string;
|
|
path: string;
|
|
requestBody: any;
|
|
}): Promise<any>;
|
|
archiveFlowByPath(p: {
|
|
workspace: string;
|
|
path: string;
|
|
requestBody: any;
|
|
}): Promise<any>;
|
|
// Scripts
|
|
getScriptByPath(p: { workspace: string; path: string }): Promise<any>;
|
|
createScript(p: { workspace: string; requestBody: any }): Promise<any>;
|
|
archiveScriptByPath(p: {
|
|
workspace: string;
|
|
path: string;
|
|
}): Promise<any>;
|
|
// Apps
|
|
getAppByPath(p: { workspace: string; path: string }): Promise<any>;
|
|
createApp(p: { workspace: string; requestBody: any }): Promise<any>;
|
|
updateApp(p: {
|
|
workspace: string;
|
|
path: string;
|
|
requestBody: any;
|
|
}): Promise<any>;
|
|
createAppRaw(p: { workspace: string; formData: any }): Promise<any>;
|
|
updateAppRaw(p: {
|
|
workspace: string;
|
|
path: string;
|
|
formData: any;
|
|
}): Promise<any>;
|
|
getPublicSecretOfLatestVersionOfApp(p: {
|
|
workspace: string;
|
|
path: string;
|
|
}): Promise<any>;
|
|
getRawAppData(p: {
|
|
secretWithExtension: string;
|
|
workspace: string;
|
|
}): Promise<any>;
|
|
deleteApp(p: { workspace: string; path: string }): Promise<any>;
|
|
// Variables
|
|
getVariable(p: {
|
|
workspace: string;
|
|
path: string;
|
|
decryptSecret?: boolean;
|
|
}): Promise<any>;
|
|
createVariable(p: { workspace: string; requestBody: any }): Promise<any>;
|
|
updateVariable(p: {
|
|
workspace: string;
|
|
path: string;
|
|
requestBody: any;
|
|
alreadyEncrypted?: boolean;
|
|
}): Promise<any>;
|
|
deleteVariable(p: { workspace: string; path: string }): Promise<any>;
|
|
// Resources
|
|
getResource(p: { workspace: string; path: string }): Promise<any>;
|
|
createResource(p: { workspace: string; requestBody: any }): Promise<any>;
|
|
updateResource(p: {
|
|
workspace: string;
|
|
path: string;
|
|
requestBody: any;
|
|
}): Promise<any>;
|
|
deleteResource(p: { workspace: string; path: string }): Promise<any>;
|
|
// Resource types
|
|
getResourceType(p: { workspace: string; path: string }): Promise<any>;
|
|
createResourceType(p: { workspace: string; requestBody: any }): Promise<any>;
|
|
updateResourceType(p: {
|
|
workspace: string;
|
|
path: string;
|
|
requestBody: any;
|
|
}): Promise<any>;
|
|
deleteResourceType(p: { workspace: string; path: string }): Promise<any>;
|
|
// Folders
|
|
getFolder(p: { workspace: string; name: string }): Promise<any>;
|
|
createFolder(p: { workspace: string; requestBody: any }): Promise<any>;
|
|
updateFolder(p: {
|
|
workspace: string;
|
|
name: string;
|
|
requestBody: any;
|
|
}): Promise<any>;
|
|
deleteFolder(p: { workspace: string; name: string }): Promise<any>;
|
|
// Datatable migrations. In the diff, an item's `path` is
|
|
// `<datatable>/<timestamp>_<name>` (see `parseDatatableMigrationDeployPath`).
|
|
listDatatableMigrations(p: { workspace: string }): Promise<any>;
|
|
upsertDatatableMigration(p: {
|
|
workspace: string;
|
|
datatableName: string;
|
|
requestBody: {
|
|
timestamp: number;
|
|
name: string;
|
|
code_up: string;
|
|
code_down?: string;
|
|
};
|
|
}): Promise<any>;
|
|
deleteDatatableMigration(p: {
|
|
workspace: string;
|
|
datatableName: string;
|
|
timestamp: number;
|
|
}): Promise<any>;
|
|
// Triggers — per-kind dispatch is delegated to the implementor so the shared
|
|
// module doesn't need to know about each of the 9 trigger services.
|
|
existsTriggerByKind(
|
|
kind: TriggerDeployKind,
|
|
p: { workspace: string; path: string }
|
|
): Promise<boolean>;
|
|
/**
|
|
* Get a trigger as it should be sent to create/update. Includes any kind-specific
|
|
* transforms the implementor wants to apply before deploy (e.g. wiping GCP
|
|
* subscription_id so the target workspace can create its own subscription).
|
|
*
|
|
* Operational-state handling (strip `mode`/`enabled` on update, pass through
|
|
* on create) is applied by `deployItem` at the dispatch layer — implementors
|
|
* should return the full row including `mode`/`enabled` and let the shared
|
|
* dispatch decide.
|
|
*/
|
|
getTriggerForDeploy(
|
|
kind: TriggerDeployKind,
|
|
p: { workspace: string; path: string; onBehalfOf?: string }
|
|
): Promise<any>;
|
|
createTriggerByKind(
|
|
kind: TriggerDeployKind,
|
|
p: { workspace: string; requestBody: any }
|
|
): Promise<any>;
|
|
updateTriggerByKind(
|
|
kind: TriggerDeployKind,
|
|
p: { workspace: string; path: string; requestBody: any }
|
|
): Promise<any>;
|
|
deleteTriggerByKind(
|
|
kind: TriggerDeployKind,
|
|
p: { workspace: string; path: string }
|
|
): Promise<any>;
|
|
/** Stripped trigger row used for the diff drawer (config fields only). */
|
|
getTriggerValue(
|
|
kind: TriggerDeployKind,
|
|
p: { workspace: string; path: string }
|
|
): Promise<unknown>;
|
|
/** Returns the trigger's `permissioned_as` for `--preserve-on-behalf-of`. */
|
|
getTriggerPermissionedAs(
|
|
kind: TriggerDeployKind,
|
|
p: { workspace: string; path: string }
|
|
): Promise<string | undefined>;
|
|
// Schedules
|
|
existsSchedule(p: { workspace: string; path: string }): Promise<boolean>;
|
|
getSchedule(p: { workspace: string; path: string }): Promise<any>;
|
|
createSchedule(p: { workspace: string; requestBody: any }): Promise<any>;
|
|
updateSchedule(p: {
|
|
workspace: string;
|
|
path: string;
|
|
requestBody: any;
|
|
}): Promise<any>;
|
|
deleteSchedule(p: { workspace: string; path: string }): Promise<any>;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Helpers
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** Folder diff paths carry the `f/` prefix; folder API endpoints expect just the name. */
|
|
export function folderName(path: string): string {
|
|
return path.replace(/^f\//, "");
|
|
}
|
|
|
|
/**
|
|
* Strip operational state (`mode`, `enabled`) from a trigger/schedule payload
|
|
* when deploying as an update; pass through unchanged on create.
|
|
*
|
|
* On update the strip lets the backend preserve the target row's existing
|
|
* state via `is_mode_unspecified()` (triggers) or via `EditSchedule` lacking
|
|
* `enabled` (schedules). On create there's no target state to preserve, so
|
|
* the source's flag is sent through — fork-only items land with whatever
|
|
* state the fork creator chose, and missing flags fall back to the backend
|
|
* default of enabled (`BaseTriggerData::mode()` / schedule insert default).
|
|
*/
|
|
export function stripOperationalStateOnUpdate<T extends Record<string, any>>(
|
|
payload: T,
|
|
alreadyExists: boolean
|
|
): T {
|
|
if (!alreadyExists) return payload;
|
|
const { mode: _mode, enabled: _enabled, ...rest } = payload;
|
|
return rest as T;
|
|
}
|
|
|
|
function getSubModules(flowModule: any): any[][] {
|
|
const type = flowModule?.value?.type;
|
|
if (type === "forloopflow" || type === "whileloopflow") {
|
|
return [flowModule.value.modules ?? []];
|
|
} else if (type === "branchall") {
|
|
return (flowModule.value.branches ?? []).map(
|
|
(branch: any) => branch.modules ?? []
|
|
);
|
|
} else if (type === "branchone") {
|
|
return [
|
|
...(flowModule.value.branches ?? []).map((b: any) => b.modules ?? []),
|
|
flowModule.value.default ?? [],
|
|
];
|
|
} else if (type === "aiagent") {
|
|
if (flowModule.value.tools) {
|
|
return [
|
|
flowModule.value.tools
|
|
.filter(
|
|
(t: any) =>
|
|
t.value?.type === "script" || t.value?.type === "flow"
|
|
)
|
|
.map((t: any) => ({
|
|
id: t.id,
|
|
value: t.value,
|
|
summary: t.summary,
|
|
})),
|
|
];
|
|
}
|
|
}
|
|
return [];
|
|
}
|
|
|
|
function getAllSubmodules(flowModule: any): any[] {
|
|
return getSubModules(flowModule)
|
|
.map((modules) => modules.flatMap((m: any) => [m, ...getAllSubmodules(m)]))
|
|
.flat();
|
|
}
|
|
|
|
/** Recursively collect all modules from a flow definition, including the failure module. */
|
|
export function getAllModules(
|
|
flowModules: any[],
|
|
failureModule?: any
|
|
): any[] {
|
|
return [
|
|
...flowModules,
|
|
...flowModules.flatMap((x) => getAllSubmodules(x)),
|
|
...(failureModule ? [failureModule] : []),
|
|
];
|
|
}
|
|
|
|
function toError(e: unknown): string {
|
|
const err = e as { body?: string; message?: string };
|
|
return err.body || err.message || String(e);
|
|
}
|
|
|
|
// A datatable-migration diff item's path is `<datatable>/<timestamp>_<name>`
|
|
// (mirrors the backend, e.g. `mydt/20260101000001_create_users`).
|
|
export function parseDatatableMigrationDeployPath(path: string): {
|
|
datatable: string;
|
|
timestamp: number;
|
|
name: string;
|
|
} {
|
|
const slash = path.indexOf("/");
|
|
const underscore = slash >= 0 ? path.indexOf("_", slash + 1) : -1;
|
|
if (slash < 0 || underscore < 0) {
|
|
throw new Error(`Invalid datatable migration path: ${path}`);
|
|
}
|
|
const datatable = path.slice(0, slash);
|
|
const timestamp = Number(path.slice(slash + 1, underscore));
|
|
const name = path.slice(underscore + 1);
|
|
if (!datatable || !Number.isFinite(timestamp) || !name) {
|
|
throw new Error(`Invalid datatable migration path: ${path}`);
|
|
}
|
|
return { datatable, timestamp, name };
|
|
}
|
|
|
|
// The backend rejects `upsertDatatableMigration` when the target data table
|
|
// hasn't opted in to migrations. Turn that opaque 400 into an explicit,
|
|
// deploy-context message (falls back to the original error otherwise).
|
|
function asMigrationsDisabledError(e: unknown, datatable: string): unknown {
|
|
const msg = (e as { body?: string; message?: string })?.body ?? ''
|
|
if (typeof msg === "string" && /migrations are not enabled/i.test(msg)) {
|
|
return new Error(
|
|
`Data table '${datatable}' has not opted in to migrations on the target workspace; enable migrations for it there before deploying its migrations.`
|
|
);
|
|
}
|
|
return e;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// checkItemExists
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function checkItemExists(
|
|
provider: DeployProvider,
|
|
kind: DeployKind,
|
|
path: string,
|
|
workspace: string
|
|
): Promise<boolean> {
|
|
if (kind === "flow") {
|
|
return provider.existsFlowByPath({ workspace, path });
|
|
} else if (kind === "script") {
|
|
return provider.existsScriptByPath({ workspace, path });
|
|
} else if (kind === "app" || kind === "raw_app") {
|
|
return provider.existsApp({ workspace, path });
|
|
} else if (kind === "variable") {
|
|
return provider.existsVariable({ workspace, path });
|
|
} else if (kind === "resource") {
|
|
return provider.existsResource({ workspace, path });
|
|
} else if (kind === "resource_type") {
|
|
return provider.existsResourceType({ workspace, path });
|
|
} else if (kind === "folder") {
|
|
return provider.existsFolder({ workspace, name: folderName(path) });
|
|
} else if (kind === "schedule") {
|
|
return provider.existsSchedule({ workspace, path });
|
|
} else if (kind === "datatable_migration") {
|
|
const { datatable, timestamp } = parseDatatableMigrationDeployPath(path);
|
|
const migrations = await provider.listDatatableMigrations({ workspace });
|
|
return (migrations as { datatable: string; timestamp: number }[]).some(
|
|
(m) => m.datatable === datatable && m.timestamp === timestamp
|
|
);
|
|
} else if (isTriggerKind(kind)) {
|
|
return provider.existsTriggerByKind(kind, { workspace, path });
|
|
}
|
|
throw new Error(`Unknown kind: ${kind}`);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// deployItem
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function deployItem(
|
|
provider: DeployProvider,
|
|
kind: DeployKind,
|
|
path: string,
|
|
workspaceFrom: string,
|
|
workspaceTo: string,
|
|
onBehalfOf?: string
|
|
): Promise<DeployResult> {
|
|
const preserveOnBehalfOf = onBehalfOf !== undefined;
|
|
|
|
try {
|
|
const alreadyExists = await checkItemExists(
|
|
provider,
|
|
kind,
|
|
path,
|
|
workspaceTo
|
|
);
|
|
|
|
if (kind === "flow") {
|
|
const flow = await provider.getFlowByPath({
|
|
workspace: workspaceFrom,
|
|
path,
|
|
});
|
|
// Clear inline script hashes so the target workspace resolves by path
|
|
getAllModules(
|
|
flow.value?.modules ?? [],
|
|
flow.value?.failure_module
|
|
).forEach((x: any) => {
|
|
if (x.value?.type === "script" && x.value.hash != undefined) {
|
|
x.value.hash = undefined;
|
|
}
|
|
});
|
|
if (alreadyExists) {
|
|
await provider.updateFlow({
|
|
workspace: workspaceTo,
|
|
path,
|
|
requestBody: {
|
|
...flow,
|
|
preserve_on_behalf_of: preserveOnBehalfOf,
|
|
on_behalf_of_email: onBehalfOf,
|
|
},
|
|
});
|
|
} else {
|
|
await provider.createFlow({
|
|
workspace: workspaceTo,
|
|
requestBody: {
|
|
...flow,
|
|
preserve_on_behalf_of: preserveOnBehalfOf,
|
|
on_behalf_of_email: onBehalfOf,
|
|
},
|
|
});
|
|
}
|
|
} else if (kind === "script") {
|
|
const script = await provider.getScriptByPath({
|
|
workspace: workspaceFrom,
|
|
path,
|
|
});
|
|
let parentHash: string | undefined;
|
|
if (alreadyExists) {
|
|
const existing = await provider.getScriptByPath({
|
|
workspace: workspaceTo,
|
|
path,
|
|
});
|
|
parentHash = existing.hash;
|
|
}
|
|
await provider.createScript({
|
|
workspace: workspaceTo,
|
|
requestBody: {
|
|
...script,
|
|
lock: script.lock,
|
|
parent_hash: parentHash,
|
|
preserve_on_behalf_of: preserveOnBehalfOf,
|
|
on_behalf_of_email: onBehalfOf,
|
|
},
|
|
});
|
|
} else if (kind === "app" || kind === "raw_app") {
|
|
const app = await provider.getAppByPath({
|
|
workspace: workspaceFrom,
|
|
path,
|
|
});
|
|
if (alreadyExists) {
|
|
if (app.raw_app) {
|
|
const secret = await provider.getPublicSecretOfLatestVersionOfApp({
|
|
workspace: workspaceFrom,
|
|
path: app.path,
|
|
});
|
|
const js = await provider.getRawAppData({
|
|
secretWithExtension: `${secret}.js`,
|
|
workspace: workspaceFrom,
|
|
});
|
|
const css = await provider.getRawAppData({
|
|
secretWithExtension: `${secret}.css`,
|
|
workspace: workspaceFrom,
|
|
});
|
|
await provider.updateAppRaw({
|
|
workspace: workspaceTo,
|
|
path,
|
|
formData: {
|
|
app: { ...app, preserve_on_behalf_of: preserveOnBehalfOf },
|
|
css,
|
|
js,
|
|
},
|
|
});
|
|
} else {
|
|
await provider.updateApp({
|
|
workspace: workspaceTo,
|
|
path,
|
|
requestBody: {
|
|
...app,
|
|
preserve_on_behalf_of: preserveOnBehalfOf,
|
|
},
|
|
});
|
|
}
|
|
} else {
|
|
if (app.raw_app) {
|
|
const secret = await provider.getPublicSecretOfLatestVersionOfApp({
|
|
workspace: workspaceFrom,
|
|
path: app.path,
|
|
});
|
|
const js = await provider.getRawAppData({
|
|
secretWithExtension: `${secret}.js`,
|
|
workspace: workspaceFrom,
|
|
});
|
|
const css = await provider.getRawAppData({
|
|
secretWithExtension: `${secret}.css`,
|
|
workspace: workspaceFrom,
|
|
});
|
|
await provider.createAppRaw({
|
|
workspace: workspaceTo,
|
|
formData: {
|
|
app: { ...app, preserve_on_behalf_of: preserveOnBehalfOf },
|
|
css,
|
|
js,
|
|
},
|
|
});
|
|
} else {
|
|
await provider.createApp({
|
|
workspace: workspaceTo,
|
|
requestBody: {
|
|
...app,
|
|
preserve_on_behalf_of: preserveOnBehalfOf,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
} else if (kind === "variable") {
|
|
const variable = await provider.getVariable({
|
|
workspace: workspaceFrom,
|
|
path,
|
|
decryptSecret: true,
|
|
});
|
|
if (alreadyExists) {
|
|
await provider.updateVariable({
|
|
workspace: workspaceTo,
|
|
path,
|
|
requestBody: {
|
|
path,
|
|
value: variable.value ?? "",
|
|
is_secret: variable.is_secret,
|
|
description: variable.description ?? "",
|
|
},
|
|
alreadyEncrypted: false,
|
|
});
|
|
} else {
|
|
await provider.createVariable({
|
|
workspace: workspaceTo,
|
|
requestBody: {
|
|
path,
|
|
value: variable.value ?? "",
|
|
is_secret: variable.is_secret,
|
|
description: variable.description ?? "",
|
|
},
|
|
});
|
|
}
|
|
} else if (kind === "resource") {
|
|
const resource = await provider.getResource({
|
|
workspace: workspaceFrom,
|
|
path,
|
|
});
|
|
if (alreadyExists) {
|
|
await provider.updateResource({
|
|
workspace: workspaceTo,
|
|
path,
|
|
requestBody: {
|
|
path,
|
|
value: resource.value ?? "",
|
|
description: resource.description ?? "",
|
|
},
|
|
});
|
|
} else {
|
|
await provider.createResource({
|
|
workspace: workspaceTo,
|
|
requestBody: {
|
|
path,
|
|
value: resource.value ?? "",
|
|
resource_type: resource.resource_type,
|
|
description: resource.description ?? "",
|
|
},
|
|
});
|
|
}
|
|
} else if (kind === "resource_type") {
|
|
const rt = await provider.getResourceType({
|
|
workspace: workspaceFrom,
|
|
path,
|
|
});
|
|
if (alreadyExists) {
|
|
await provider.updateResourceType({
|
|
workspace: workspaceTo,
|
|
path,
|
|
requestBody: {
|
|
schema: rt.schema,
|
|
description: rt.description ?? "",
|
|
},
|
|
});
|
|
} else {
|
|
await provider.createResourceType({
|
|
workspace: workspaceTo,
|
|
requestBody: {
|
|
name: rt.name,
|
|
schema: rt.schema,
|
|
description: rt.description ?? "",
|
|
},
|
|
});
|
|
}
|
|
} else if (kind === "folder") {
|
|
const name = folderName(path);
|
|
const folder = await provider.getFolder({
|
|
workspace: workspaceFrom,
|
|
name,
|
|
});
|
|
if (alreadyExists) {
|
|
await provider.updateFolder({
|
|
workspace: workspaceTo,
|
|
name,
|
|
requestBody: {
|
|
owners: folder.owners,
|
|
extra_perms: folder.extra_perms,
|
|
summary: folder.summary ?? undefined,
|
|
},
|
|
});
|
|
} else {
|
|
await provider.createFolder({
|
|
workspace: workspaceTo,
|
|
requestBody: {
|
|
name,
|
|
owners: folder.owners,
|
|
extra_perms: folder.extra_perms,
|
|
summary: folder.summary ?? undefined,
|
|
},
|
|
});
|
|
}
|
|
} else if (kind === "schedule") {
|
|
const schedule = await provider.getSchedule({
|
|
workspace: workspaceFrom,
|
|
path,
|
|
});
|
|
// Operational-state handling — same shape as triggers below:
|
|
// - Update: strip `enabled` so the target's existing state is preserved
|
|
// (`EditSchedule` lacks `enabled` server-side, so this is also
|
|
// enforced by the type, but stripping keeps the intent explicit).
|
|
// - Create: pass `enabled` through so a fork-only schedule lands with
|
|
// the state the fork creator chose.
|
|
const baseBody = stripOperationalStateOnUpdate(schedule, alreadyExists);
|
|
const requestBody = {
|
|
...baseBody,
|
|
permissioned_as: onBehalfOf,
|
|
preserve_permissioned_as: preserveOnBehalfOf,
|
|
};
|
|
if (alreadyExists) {
|
|
await provider.updateSchedule({
|
|
workspace: workspaceTo,
|
|
path,
|
|
requestBody,
|
|
});
|
|
} else {
|
|
await provider.createSchedule({
|
|
workspace: workspaceTo,
|
|
requestBody,
|
|
});
|
|
}
|
|
} else if (isTriggerKind(kind)) {
|
|
const triggerBody = await provider.getTriggerForDeploy(kind, {
|
|
workspace: workspaceFrom,
|
|
path,
|
|
onBehalfOf,
|
|
});
|
|
// Strip operational state on update; pass through on create. The
|
|
// implementor's `getTriggerForDeploy` is responsible only for kind-specific
|
|
// transforms (e.g. GCP subscription_id wipe) — the operational-state
|
|
// strip lives here so it stays consistent with the schedule branch and
|
|
// with the legacy `kind === 'trigger'` path in the frontend.
|
|
const requestBody = stripOperationalStateOnUpdate(triggerBody, alreadyExists);
|
|
if (alreadyExists) {
|
|
await provider.updateTriggerByKind(kind, {
|
|
workspace: workspaceTo,
|
|
path,
|
|
requestBody,
|
|
});
|
|
} else {
|
|
await provider.createTriggerByKind(kind, {
|
|
workspace: workspaceTo,
|
|
requestBody,
|
|
});
|
|
}
|
|
} else if (kind === "datatable_migration") {
|
|
const { datatable, timestamp } = parseDatatableMigrationDeployPath(path);
|
|
const migrations = await provider.listDatatableMigrations({
|
|
workspace: workspaceFrom,
|
|
});
|
|
const migration = (
|
|
migrations as {
|
|
datatable: string;
|
|
timestamp: number;
|
|
name: string;
|
|
code_up: string;
|
|
code_down?: string;
|
|
}[]
|
|
).find((m) => m.datatable === datatable && m.timestamp === timestamp);
|
|
if (!migration) {
|
|
throw new Error(
|
|
`Datatable migration ${path} not found in ${workspaceFrom}`
|
|
);
|
|
}
|
|
try {
|
|
await provider.upsertDatatableMigration({
|
|
workspace: workspaceTo,
|
|
datatableName: datatable,
|
|
requestBody: {
|
|
timestamp: migration.timestamp,
|
|
name: migration.name,
|
|
code_up: migration.code_up,
|
|
...(migration.code_down != null
|
|
? { code_down: migration.code_down }
|
|
: {}),
|
|
},
|
|
});
|
|
} catch (e) {
|
|
throw asMigrationsDisabledError(e, datatable);
|
|
}
|
|
} else {
|
|
throw new Error(`Unknown kind: ${kind}`);
|
|
}
|
|
|
|
return { success: true };
|
|
} catch (e: unknown) {
|
|
return { success: false, error: toError(e) };
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// deleteItemInWorkspace
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Delete/archive an item in a workspace.
|
|
* Scripts and flows are archived (reversible). Other types are deleted.
|
|
*/
|
|
export async function deleteItemInWorkspace(
|
|
provider: DeployProvider,
|
|
kind: DeployKind,
|
|
path: string,
|
|
workspace: string
|
|
): Promise<DeployResult> {
|
|
try {
|
|
if (kind === "script") {
|
|
await provider.archiveScriptByPath({ workspace, path });
|
|
} else if (kind === "flow") {
|
|
await provider.archiveFlowByPath({
|
|
workspace,
|
|
path,
|
|
requestBody: { archived: true },
|
|
});
|
|
} else if (kind === "app" || kind === "raw_app") {
|
|
await provider.deleteApp({ workspace, path });
|
|
} else if (kind === "variable") {
|
|
await provider.deleteVariable({ workspace, path });
|
|
} else if (kind === "resource") {
|
|
await provider.deleteResource({ workspace, path });
|
|
} else if (kind === "resource_type") {
|
|
await provider.deleteResourceType({ workspace, path });
|
|
} else if (kind === "folder") {
|
|
await provider.deleteFolder({ workspace, name: folderName(path) });
|
|
} else if (kind === "schedule") {
|
|
await provider.deleteSchedule({ workspace, path });
|
|
} else if (kind === "datatable_migration") {
|
|
const { datatable, timestamp } = parseDatatableMigrationDeployPath(path);
|
|
await provider.deleteDatatableMigration({
|
|
workspace,
|
|
datatableName: datatable,
|
|
timestamp,
|
|
});
|
|
} else if (isTriggerKind(kind)) {
|
|
await provider.deleteTriggerByKind(kind, { workspace, path });
|
|
} else {
|
|
throw new Error(`Deletion not supported for kind: ${kind}`);
|
|
}
|
|
return { success: true };
|
|
} catch (e: unknown) {
|
|
return { success: false, error: toError(e) };
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// getOnBehalfOf
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Get the value of an item for diff comparison.
|
|
* Returns a normalized representation suitable for JSON comparison.
|
|
*/
|
|
export async function getItemValue(
|
|
provider: DeployProvider,
|
|
kind: DeployKind,
|
|
path: string,
|
|
workspace: string
|
|
): Promise<unknown> {
|
|
try {
|
|
if (kind === "flow") {
|
|
const flow = await provider.getFlowByPath({ workspace, path });
|
|
getAllModules(flow.value?.modules ?? [], flow.value?.failure_module).forEach(
|
|
(x: any) => {
|
|
if (x.value?.type === "script" && x.value.hash != undefined) {
|
|
x.value.hash = undefined;
|
|
}
|
|
}
|
|
);
|
|
return {
|
|
summary: flow.summary,
|
|
description: flow.description,
|
|
value: flow.value,
|
|
};
|
|
} else if (kind === "script") {
|
|
const script = await provider.getScriptByPath({ workspace, path });
|
|
return {
|
|
content: script.content,
|
|
lock: script.lock,
|
|
schema: script.schema,
|
|
summary: script.summary,
|
|
language: script.language,
|
|
};
|
|
} else if (kind === "app" || kind === "raw_app") {
|
|
return await provider.getAppByPath({ workspace, path });
|
|
} else if (kind === "variable") {
|
|
const variable = await provider.getVariable({
|
|
workspace,
|
|
path,
|
|
decryptSecret: true,
|
|
});
|
|
return variable.value;
|
|
} else if (kind === "resource") {
|
|
const resource = await provider.getResource({ workspace, path });
|
|
return resource.value;
|
|
} else if (kind === "resource_type") {
|
|
const rt = await provider.getResourceType({ workspace, path });
|
|
return rt.schema;
|
|
} else if (kind === "folder") {
|
|
const folder = await provider.getFolder({
|
|
workspace,
|
|
name: folderName(path),
|
|
});
|
|
return {
|
|
name: folder.name,
|
|
owners: folder.owners,
|
|
extra_perms: folder.extra_perms,
|
|
summary: folder.summary,
|
|
};
|
|
} else if (kind === "schedule") {
|
|
// Mirror the runtime-fields-ignore set used server-side so the diff drawer
|
|
// matches the merge UI's "did config change?" semantics.
|
|
const schedule = await provider.getSchedule({ workspace, path });
|
|
return stripTriggerOrScheduleRuntimeFields(schedule);
|
|
} else if (isTriggerKind(kind)) {
|
|
const trigger = await provider.getTriggerValue(kind, { workspace, path });
|
|
return stripTriggerOrScheduleRuntimeFields(trigger);
|
|
} else if (kind === "datatable_migration") {
|
|
// Surface the migration SQL so the diff drawer shows the up/down bodies a
|
|
// reviewer needs to inspect before deploying.
|
|
const { datatable, timestamp } = parseDatatableMigrationDeployPath(path);
|
|
const migrations = (await provider.listDatatableMigrations({
|
|
workspace,
|
|
})) as {
|
|
datatable: string;
|
|
timestamp: number;
|
|
name: string;
|
|
code_up: string;
|
|
code_down?: string;
|
|
}[];
|
|
const migration = migrations.find(
|
|
(m) => m.datatable === datatable && m.timestamp === timestamp
|
|
);
|
|
if (migration) {
|
|
return {
|
|
name: migration.name,
|
|
code_up: migration.code_up,
|
|
code_down: migration.code_down ?? null,
|
|
};
|
|
}
|
|
}
|
|
} catch {
|
|
// Item may not exist
|
|
}
|
|
return {};
|
|
}
|
|
|
|
/**
|
|
* Strip runtime fields from a trigger or schedule row so the diff drawer
|
|
* shows only config differences. Mirrors the backend's
|
|
* `TRIGGER_COMPARE_IGNORE` constant.
|
|
*/
|
|
function stripTriggerOrScheduleRuntimeFields(row: unknown): unknown {
|
|
if (!row || typeof row !== "object") return row;
|
|
const ignore = new Set([
|
|
"workspace_id",
|
|
"edited_by",
|
|
"edited_at",
|
|
"email",
|
|
"error",
|
|
"enabled",
|
|
"mode",
|
|
"server_id",
|
|
"last_server_ping",
|
|
"extra_perms",
|
|
"permissioned_as",
|
|
// Server-managed (kept in sync with backend `TRIGGER_COMPARE_IGNORE`).
|
|
"subscription_id",
|
|
"push_auth_config",
|
|
]);
|
|
const out: Record<string, unknown> = {};
|
|
for (const [k, v] of Object.entries(row as Record<string, unknown>)) {
|
|
if (!ignore.has(k)) out[k] = v;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
/**
|
|
* Fetch the on_behalf_of value for a deployable item.
|
|
* Returns an email for flows/scripts/apps, or undefined if not applicable.
|
|
*/
|
|
export async function getOnBehalfOf(
|
|
provider: DeployProvider,
|
|
kind: DeployKind,
|
|
path: string,
|
|
workspace: string
|
|
): Promise<string | undefined> {
|
|
try {
|
|
if (kind === "flow") {
|
|
const flow = await provider.getFlowByPath({ workspace, path });
|
|
return flow.on_behalf_of_email;
|
|
} else if (kind === "script") {
|
|
const script = await provider.getScriptByPath({ workspace, path });
|
|
return script.on_behalf_of_email;
|
|
} else if (kind === "app" || kind === "raw_app") {
|
|
const app = await provider.getAppByPath({ workspace, path });
|
|
return app.policy?.on_behalf_of_email;
|
|
} else if (kind === "schedule") {
|
|
const schedule = await provider.getSchedule({ workspace, path });
|
|
return schedule.permissioned_as;
|
|
} else if (isTriggerKind(kind)) {
|
|
return await provider.getTriggerPermissionedAs(kind, { workspace, path });
|
|
}
|
|
} catch {
|
|
// Item may not exist
|
|
}
|
|
return undefined;
|
|
}
|