Appearance
Workspace Configuration (Beta)
WARNING
defineWorkspace() and defineApp() are beta. Their options and behavior may change in a future release.
A defineConfig() config describes one application together with the services it deploys. Several applications in one workspace need one config each, and an application borrows a service another config owns by declaring it external: true. defineWorkspace() instead declares every service of the workspace in one tailor.config.ts, keyed by name, and lists for each application which of those services its GraphQL API exposes.
typescript
import { defineAuth, definePlugins, defineWorkspace } from "@tailor-platform/sdk";
import { kyselyTypePlugin } from "@tailor-platform/sdk/plugin/kysely-type";
import { user } from "./db/customer/user";
const corpAuth = defineAuth("corp-auth", {
userProfile: { type: user, usernameField: "email", attributes: { role: true } },
machineUsers: { "db-seeder": { attributes: { role: "ADMIN" } } },
});
export default defineWorkspace({
env: { APP_ENV: process.env.APP_ENV ?? "DEV", PAGE_SIZE: 50 },
db: {
"customer-db": { files: ["./db/customer/**/*.ts"] },
"order-db": { files: ["./db/order/**/*.ts"] },
"ledger-db": { files: ["./db/ledger/**/*.ts"] },
},
resolver: {
"shop-api": { files: ["./apps/shop/resolvers/**/*.ts"] },
"backoffice-api": { files: ["./apps/backoffice/resolvers/**/*.ts"], env: { PAGE_SIZE: 200 } },
},
executor: { files: ["./executors/**/*.ts"] },
workflow: { files: ["./workflows/**/*.ts"] },
auth: { "corp-auth": corpAuth },
apps: {
shop: { db: ["customer-db", "order-db"], resolver: ["shop-api"], auth: "corp-auth" },
backoffice: {
db: ["customer-db", "order-db"],
resolver: ["backoffice-api"],
auth: "corp-auth",
allowedIpAddresses: ["192.168.1.0/24"],
},
},
});
export const plugins = definePlugins(kyselyTypePlugin({ distPath: "./generated/tailordb.ts" }));The file is still named tailor.config.ts. The function its default export is made with, defineConfig(), defineApp(), or defineWorkspace(), decides how the SDK reads it. The file holds no workspace ID, so the same file deploys to the workspace of each environment (see Multi-Environment Configuration).
Services and Applications
The top-level keys declare the services the workspace owns:
db,resolver: TailorDB and resolver namespaces, keyed by namespace name. A resolver namespace can overrideenvvalues (see Environment Variables).executor,workflow: the executor and workflow files. Executors and workflows belong to the workspace, not to an application.auth: Auth services, each keyed by the name passed todefineAuth().idp: built-in IdPs, each keyed by the name passed todefineIdp().staticWebsites,aiGateways,secrets,httpAdapter,buildOptions,defaultDateRepresentation, andmaintenanceModetake the same values as indefineConfig().httpAdapterrequires exactly one application; with several,deploystops withHTTP_ADAPTER_MULTIPLE_APPLICATIONS.
Each entry of apps is one application, keyed by its name. db, resolver, auth, and idp name the services its GraphQL API exposes (auth takes one name, the others a list, such as idp: ["shop-idp"]), and cors, allowedIpAddresses, disableIntrospection, and metadata are its own settings, as described in Application Settings.
- A name the workspace does not declare is a type error. Loading the config also rejects it with
CONFIG_INVALID. - An application lists at least one TailorDB namespace, resolver namespace, IdP, or Auth service.
- Several applications can list the same service.
- A TailorDB namespace that no application lists is in no GraphQL API. Functions still read and write it with
getDB(), andtailor generatewrites its types; see Typed SQL Access. - TailorDB table names must be unique across all TailorDB namespaces of the workspace.
Environment Variables
The root env holds the values every function of the workspace receives, as described in Environment Variables. A resolver namespace, executor, and workflow can each set an env that overrides some of those values for their own functions:
typescript
export default defineWorkspace({
env: { APP_ENV: "DEV", PAGE_SIZE: 50 },
resolver: {
"backoffice-api": { files: ["./apps/backoffice/resolvers/**/*.ts"], env: { PAGE_SIZE: 200 } },
},
executor: { files: ["./executors/**/*.ts"], env: { APP_ENV: "DEV-BATCH" } },
// ...
});- An override can only set keys of the root
env. Any other key is a type error, and loading the config rejects it withCONFIG_INVALID. - A function receives the root values with its override laid over them, key by key.
tailor function runandtailor workflow runapply the same override asdeploy. - The
Envtype intailor.d.tscomes from the rootenvalone, so give an override the same type as the root value it replaces. - An application has no
env.maintenanceMode,defaultDateRepresentation, andpluginsalso apply to the whole workspace.
Several Auth Services
A workspace can define several Auth services. A machine user is then found by its name across all of them:
- A string
invokerof a resolver or executor resolves to the Auth service that defines that machine user. When two Auth services define it,deploystops withINVOKER_MACHINE_USER_AMBIGUOUS; name the Auth service withinvoker: { namespace: "corp-auth", machineUserName: "db-seeder" }.tailor generatedoes not check this. - A string literal
invokerpassed toworkflow.start()is resolved the same way whendeploybundles the function, and an invoker it cannot read, such as a variable, is rejected; see Starting a Workflow from a Resolver. - An
authAccessToken*Trigger()needsauthto name the Auth service it subscribes to (EXECUTOR_AUTH_AMBIGUOUS). - A TailorDB namespace with migration scripts needs
migration.machineUser(MACHINE_USER_REQUIRED). It takes a machine user name only, so the name must be defined by one Auth service (MACHINE_USER_AMBIGUOUS); rename one of the machine users otherwise. See Machine User and Permissions. Attributesintailor.d.tsholds the attributes of every Auth service, since a caller may come from any of them. An attribute is optional unless every Auth service requires it.- On the command line,
--machine-user,TAILOR_PLATFORM_MACHINE_USER_NAME, and a profile's machine user take<auth>/<name>to name the Auth service, as intailor query -m corp-auth/db-seeder. A bare name that two Auth services define stops withMACHINE_USER_AMBIGUOUS.tailor oauth2client gettakes<auth>/<client>the same way. - An AI gateway needs
authNamespaceset to one of them.
IdPs
An application lists at most one IdP in idp. Its GraphQL API exposes that IdP's user management operations, whose names are the same for every IdP, so two IdPs cannot share one API. Function code reaches any IdP of the workspace, listed or not, with new idp.Client({ namespace: "<idp name>" }) from @tailor-platform/sdk/runtime.
idpUser*Trigger() subscribes to any IdP of the workspace. With several IdPs, set idp on the trigger (EXECUTOR_IDP_AMBIGUOUS).
GraphQL Operations of Executors
An executor's graphql operation runs against the application its appName names. With several applications, set appName; deploy stops with EXECUTOR_APP_NAME_AMBIGUOUS otherwise. Without appName, a workspace with a single application uses that application, and a workspace without applications stops with EXECUTOR_APP_NAME_REQUIRED.
Typed SQL Access
The getDB() that kyselyTypePlugin provides covers every TailorDB namespace of the workspace, including those no application lists. To keep the code of one application to its own namespaces, create a narrowed getDB and forbid imports of the unrestricted one, as described in Plugins. The narrowing is a type check only: at runtime, every function can reach every namespace.
Single-Application Projects: defineApp()
A project with one application can use defineApp(). It takes the options of defineConfig() without id, without services declared external, without the deprecated top-level inlineSourcemap and logLevel (set them in buildOptions), with idp as a single IdP, and with auth as a single Auth service:
typescript
import { defineApp } from "@tailor-platform/sdk";
import { auth } from "./auth";
import { idp } from "./idp";
export default defineApp({
name: "my-app",
env: { APP_ENV: "DEV" },
db: { "my-db": { files: ["./db/**/*.ts"] } },
resolver: { "my-resolver": { files: ["./resolvers/**/*.ts"] } },
auth,
idp,
});The SDK reads it as a workspace with one application named name that lists every service the config defines. Everything this page says about workspace configs applies to it, except that a resolver namespace, executor, and workflow cannot override env; use defineWorkspace() for that.
deploy of a defineApp() config stops with DEPLOY_OTHER_CONFIG_RESOURCES when the workspace holds resources another config deployed, or an application another workspace config deployed, since the deploy would take them over or delete them. Move every config deployed to that workspace into one defineWorkspace() config, or give each its own workspace. To rename the application of a defineApp() config, deploy once with a defineWorkspace() config that lists the new name, then return to defineApp().
Choosing the Config File
CLI commands use the nearest tailor.config.ts, looking in the current directory and then in each parent directory, whichever function it uses. --config and TAILOR_CONFIG_PATH choose another file. A workspace config is always the only config of a command: tailor deploy stops with DEPLOY_WORKSPACE_CONFIG_WITH_OTHERS when --config also lists other configs.
Deploying
tailor deploy plans and applies the whole workspace in one run; there is no option to deploy one application. Only what changed is applied.
- Every resource the deploy manages carries the label
sdk-managed: workspace. Each application, and each TailorDB namespace, resolver namespace with its resolver functions, Auth service, and IdP that an application lists, also carries onesdk-on-app-<application>label for each application that lists it. Searching the Resources page of the Tailor Platform console forsdk-on-app-shop, for example, lists the resources ofshop. - A resource holds at most 20 labels. When the
sdk-on-app-*labels of a resource do not fit,deploywrites as many as fit, warns, and completes; with--json, the result lists them underwarnings. - An application removed from
appsis deleted. The deletion needs confirmation, like the deletion of a TailorDB table. - A service that an application stops listing stays deployed while the workspace declares it; only the application's GraphQL API changes. A service removed from the config is deleted.
First Deploy After defineConfig()
The first deploy of a workspace config to a workspace that defineConfig() configs deployed to takes their resources over. It lists the resources it takes over and the ones it deletes because the workspace config does not have them, including executors, resolver namespaces, and IdPs, and asks for confirmation. In a non-interactive environment without --yes, it stops with INTERACTIVE_PROMPT_REQUIRED.
The workflows that tailor setup ci generates deploy with --yes, so in CI the takeover and its deletions go ahead without asking. Check the list in the plan that the pull request workflow posts, or with tailor deploy --dry-run locally, before the change reaches the deploy job. Running the first deploy locally lets you answer the prompt yourself.
After the takeover, deploying a defineConfig() config to the workspace again asks to take the resources back from the workspace config.
Commands
tailor showandtailor opentake--appto choose an application. Without it, a workspace with several applications makesshowlist every deployed application, warning about the ones not deployed yet, andopenopens the workspace's application list.tailor query --engine sqlruns in the namespace--namespacenames, or in the one namespace that has the table.--engine gqlruns against the application--appnames, which a workspace with several applications requires (CONFIG_APP_REQUIRED), as a machine user of that application's Auth service.tailor removestops withCONFIG_KIND_UNSUPPORTED. To remove an application or service, remove it from the config and runtailor deploy. To remove everything, runtailor workspace delete.tailor machineuser listandtailor oauth2client listlist the entries of every Auth service, each with its Auth service.tailor data clonewithout--nameclones the only application; a workspace with several applications needs--name. A TailorDB namespace that the cloned application does not list is not cloned.tailor tailordb migration test --data clonecopies one application's data, so it needs a workspace that deploys one application listing every namespace with pending migrations. Use--data seedotherwise.tailor setup citakes the workspace config's directory as its only--dir. AdefineWorkspace()config needs--name; adefineApp()config defaults to its application name. The generated workflow generates, checks, plans, and deploys the whole workspace once, and.github/tailor.lockrecords the config underworkspaces.--migration-testneeds a config that deploys one application listing every TailorDB namespace with migrations, since the migration test copies that application's data.
Not supported yet for a workspace config:
tailor tailordb erd export,serve, anddeploy, andtailor setup ci --erd-preview.- The built-in seed plugin with several Auth services that use a built-in IdP:
tailor generateandtailor deploystop withSEED_IDP_USER_AUTH_AMBIGUOUS.
Plugins
definePlugins() is exported as plugins from the workspace config, as described in Plugins. For what plugin hooks receive from a workspace config, see Custom Plugins.
Unsupported Setups
- One workspace deployed from several configs or repositories. One
tailor.config.tsowns the whole workspace: its deploy deletes the resources another config deployed, once it has taken over the workspace. - Resources created outside the SDK, such as with the console or Terraform, attached with
external: true. A workspace config declares only services it owns.
Moving From Several defineConfig() Configs
A project that deploys several defineConfig() configs to one workspace, with tailor deploy -c a,b, a comma-separated TAILOR_CONFIG_PATH, or tailor setup ci with several --dir, moves to one workspace config:
- Write a
tailor.config.tswithdefineWorkspace()at the directory that contains the configs. Move each config's services under the top-level keys, adjusting the paths relative to the old config, such asfilespatterns,migration.directory, and plugindistPath, to the new directory, and make each config anappsentry that lists its services and keeps itscors,allowedIpAddresses,disableIntrospection, andmetadata. Drop services declaredexternal: the config that owns them now declares them once. - Merge the
envof every config into the rootenv. A key with different values in different configs becomes an override on the resolver namespaces, executors, or workflows that need the other value. - Name the Auth service, IdP, or application wherever the merge makes a name ambiguous: string
invokers andworkflow.start()invokers,idpUser*Trigger()andauthAccessToken*Trigger()withoutidporauth,graphqloperations withoutappName, and migrations withoutmigration.machineUser.tailor deploy --dry-runstops at the first one it finds, so run it again after each fix. - Delete the old configs, and their
appIdsentries in.github/tailor.lockif the project has one. - Run
tailor setup ciagain for the new config with the same--nameas the existing workflow, so the workflow deploys the new config instead ofTAILOR_CONFIG_PATH. A new--namegenerates a second workflow; delete the old one withtailor setup delete. - Run the first deploy as described in First Deploy After
defineConfig().
On the upgrade to v3, tailor upgrade runs the v3/config-to-workspace codemod, which does steps 1 to 4 for the configs it finds deployed together. It reports what it leaves for a manual change; configs that set one env key differently, for example, stay as they are. Then run tailor setup update in place of step 5, and the first deploy. The v3/config-to-app codemod rewrites a config deployed on its own to defineApp().