App building rules
This page covers, in full, the rules you follow when you prepare the resources and site to include in a Market App. It covers what carries over on install and how, how to write values in your build output and resource definitions, which resources you must include together, the values the installer enters, what blocks bundling, and how the plan required to install is decided. If you're new to building an app, start with Building an app, which covers what building an app means and the order you do it in.
When you create a version of a Market App, the resources you selected in your source Space are bundled into that version. This page calls that process "bundling". The rules for creating versions and submitting them for review are in App publishing and review rules, and the rules on the installing side are in App install rules.
Rules
Installing creates the included resources fresh in the installer's Space
When someone installs an app, the resources included in the version are created fresh in the installer's Space. The installer manages the installed resources (The installer manages installed copies).
- Installed resources get new IDs. Any Delivery Access Tokens and Space Access Tokens you included are issued with new values.
- References between resources are reconnected among the installed copies. For example, an installed Content's link Field references the installed Content, and an installed token is bound to the installed role. What changes for each resource is laid out in What each resource carries into the installed copy.
- For a reference to reconnect, you must also include the resource it points to (Resources you must include together).
- Installed resources are separate from the resources in your source Space. Editing or deleting the originals after the install doesn't change the installed copies. For cases where an installed site keeps using values from your source Space, see Values that change in site files.
A version includes what's saved at bundling time
- A version includes whatever is saved in your source Space at the moment it's bundled. Edits you haven't published are included too.
- Included Content Types and Content are created in a published state in the Space they're installed in, whatever their status was in the source. The same applies to Content that's Draft or Archived in the source (What installing creates in your Space). Before bundling, clean up drafts in progress and test data that installers shouldn't see.
- Bundling continues for a while after you create the version. Don't edit or delete the included resources until bundling finishes. If you delete an included resource while bundling is in progress, bundling fails for that version (Version statuses).
- Edits to the originals make it into the app only when you create a new version (One set of app info per app, resources per version).
What each resource carries into the installed copy
Settings such as names, descriptions, rules, run schedules, and on/off states carry over to the installed copy with their original values. The table below lists, for each resource, what changes to the installed copy's values, and what doesn't carry over or is decided by the installer.
| Resource | Changes to the installed copy's values | Doesn't carry over, or the installer decides |
|---|---|---|
| Content Type | The Content Types a link Field allows | None |
| Content | The items a link Field references, attached Tags, and resource IDs written in Field values (IDs written in resource definitions) | None |
| Media | Attached Tags | None |
| Tag | None | If the Space you install in already has a Tag with the same name, that Tag is used instead of creating a new one. Only Tags whose names that Space doesn't have are created |
| Locale | None | The installer decides whether to change the Space's default Locale to the app's. For the rules when the Space you install in already has a Locale with the same code, see Locales are matched to the app |
| SpaceRole, ServiceUserRole | The Content Types, Tags, and Scripts used in their rules | Among SpaceRoles, the Administrator role isn't created. Places that referenced the Administrator role in the source reference the Administrator role of the Space the app is installed in |
| Delivery Access Token, Space Access Token | The token value and the bound SpaceRole. A token bound to the Administrator role in the source is bound to the Administrator role of the Space the app is installed in | Allowed referrers doesn't carry over, so installed tokens are issued with No restriction. The installer can set it to the installed site's address (Allowed referrers decide which sites can use a token) |
| Script | Resource IDs written in Statement and Payload Schema | The values in Secrets. The app holds only the Key and Description of each secret value, and the installer enters the values (Values the installer enters) |
| Webhook | The Script it runs, and resource IDs in Filters values and in a shape to send that you wrote yourself | The values of headers whose type is Secret and of headers named Authorization, and the Username and Password for HTTP Basic Auth. The installer enters all of them (Values the installer enters) |
| Scheduler | The Script it runs | None |
| ServiceLogin | The default role, and return URLs written as the address of a site you included | The installer enters the client ID and client secret issued by each login provider, and any return URLs written as addresses outside the included site. Contact email is set to the installer's account email (When you include member login) |
| Email Account | None | Not created. The app holds only the Email Account's name, not the sending server address or the password. The installer selects one Email Account in their own Space, and installed Scripts send email through the selected Email Account |
| Web Hosting | Values written in site files (Values that change in site files), and the site address written in meta tags (The site's own address and meta tags) | A new Subdomain is set, and your own domain connected to the original site doesn't carry over (Sites installed from an app) |
Values that change in site files
An installed site has no server, so the browser calls CDA directly to load content. That means the build output itself has to say which Space to read from, what to read, and with which token. The values written in the build output are your source Space's values, but on install, WEEGLOO finds the following values in the site files and replaces them with the values of the Space the app is installed in.
- The source Space's ID
- The IDs of the resources you included
- The values of the Delivery Access Tokens and Space Access Tokens you included
- The file addresses of the Media you included. They change to the file addresses of the installed Media.
For these values to change, follow all of these rules.
- Include the resources and tokens in the app. If you don't include a resource, token, or Media, its ID, value, or file address doesn't change, so the installed site keeps reading your source Space.
- Put the values in text files. The files whose values change are web pages (
.html,.htm), styles and scripts (.css,.js,.mjs), and data (.json,.map,.xml,.txt). Values in image files (including.svg) and in files that aren't in the extension table (such as.webmanifest) don't change. The extension table is in Rules for the site file bundle. - Save text files in UTF-8. Values in files saved in another character encoding don't change.
- Write each value as one whole string, without splitting it. The entire value must appear unbroken in the build output.
Example code that writes the values in the site's config file is in Putting values into the build as they are.
Values written in the following ways don't remain as whole strings in the build output, so they don't change.
-
Reading an environment variable. An installed site has no server to inject the value.
// Doesn't work: this environment variable doesn't exist where the app is installed deliveryAccessToken: process.env.DELIVERY_ACCESS_TOKEN -
Fetching at runtime. The value doesn't remain in the build output.
-
Splitting the string. The value doesn't appear as one piece.
// Doesn't work: the whole token doesn't remain as one string in the output deliveryAccessToken: "DVRAT" + "bQ8mX2vK9pLs7Rf1Zt0Nc4Wd6Hg5Ua2Ee9Ck3PoYx8Bj6Hg5Ua2Ee9Ck3Po" -
A placeholder or a blank. There's no real value to replace.
A bundler can split or change strings while it builds, so check the build output, not the source (Checking the build output before bundling).
Don't write the text and images that installers will change in Content Studio directly into site files. Have the site load them from Content instead. Installers can't change the files of a site installed from an app (Sites installed from an app).
The site's own address and meta tags
An installed site opens at a different Subdomain address from the original site (Sites installed from an app). The original site's address written in site files is handled differently depending on where you wrote it.
| Where the address is written | On install |
|---|---|
In the tags below in an HTML file's <head>, a value written as the original site's Subdomain address | Changes to the installed site's address |
| In the same tags, a value written as your own domain address connected to the original site | Doesn't change |
| An address written in the page body or in scripts | Doesn't change |
The tags whose addresses change are <link rel="canonical">, <meta property="og:url">, og:image, og:image:url, og:image:secure_url, <meta name="twitter:image">, <link rel="icon">, <link rel="shortcut icon">, <link rel="apple-touch-icon">, and <link rel="alternate">.
- If you write links within the site as paths without the address, like
/about, they lead to the same page whatever address the site opens at. If you need the current address at runtime, get it withlocation.origin. - The following tags in
<head>aren't included in the app, so the installed site doesn't have them: search engine crawling instructions (robots,googlebot), language markers (og:locale,og:locale:alternate), and site ownership verification (google-site-verification,naver-site-verification). - After installing, the installer can edit values such as the title, description, Canonical, and image for each document in Custom Metadata (Custom metadata exists only on sites installed from an app).
IDs written in resource definitions
Resource IDs written as text in a Script, Content, or Webhook also change to the installed copies' IDs on install, as long as you include those resources. The source Space's ID changes to the ID of the Space the app is installed in too. Only certain places have IDs that change.
| Resource | Where IDs change | Where IDs don't change |
|---|---|---|
| Script | Statement, Payload Schema | Secrets, Name |
| Content | The values of all Fields | None |
| Webhook | Filters values (except Regexp and Not Regexp filters), and the shape to send written with Customize the Webhook payload | URL, headers |
- Write an ID as a separate value, with no letters or digits attached before or after it. An ID changes if it's alone inside quotes or set apart by symbols such as
/or-. An ID joined to other characters, likect3trmXRLdJF4GBlAjtcuoZ7Pnxj8dlA, doesn't change. - If you write the ID of a resource in your source Space but don't include that resource, bundling is blocked (Resources you must include together).
- A resource ID you put in Secrets doesn't change, so the installer has to look up the installed resource's new ID and enter it.
- Only addresses written in site files change to the installed Media's file addresses. When you use Media in Content, don't write the file address as text. Reference the Media with a link Field.
You can't write the ID of a resource installed later
When an app is installed, resources are created in a set order. A resource that references another resource, or has that resource's ID written in it, is created after that other resource. The following order is also fixed.
- Web Hosting is created last, after all other resources.
- Webhooks are created after all other resources except Web Hosting.
- A Scheduler is created after the Script it runs.
So if a resource's definition contains the ID of a resource that's created after it, no order works, and bundling fails. That happens in these cases.
- A Script or Content contains the ID of a Web Hosting or a Webhook
- A Script contains the ID of a Scheduler
- A Webhook contains the ID of a Web Hosting
This problem isn't caught the moment you create the version. It's found later, during bundling, and bundling fails for that version (Version statuses). Remove that ID from the definition and create a new version. For a Script, you can change it to receive that ID in payload when it runs. For the steps to clean up the failed version, see Clean up a failed version.
Values the installer enters
Put values that differ for each installer, like a payment service's secret key or an external API key, in the places the installer fills in. Values you put there aren't included in the app, and installers enter their own values when installing. Values written directly as text in a definition don't change on install, so a key of yours written that way is copied as is into every installed copy.
| Place | What the app holds | What the installer does |
|---|---|---|
| Secrets in a Script | The Key and Description of each secret value | Enters a value for each secret value |
| Headers whose type is Secret in a Webhook | The header name | Enters the value |
Headers named Authorization in a Webhook | The header name | Enters the value, whatever the type. The name isn't case-sensitive |
| HTTP Basic Auth in a Webhook | The setting that says basic authentication is used | Enters the Username and Password |
| Login providers in ServiceLogin | The list of providers that are turned on | Enters the client ID and client secret issued by each provider |
| Return URLs in ServiceLogin written as addresses outside the included site | Nothing | Enters the address (When you include member login) |
| Email Account | The Email Account's name | Selects one Email Account in their own Space |
- A header whose type is Custom has its value copied as is, unless its name is
Authorization. - The fields the installer fills in are fixed at bundling. You can't add or remove fields after you create the version, so before bundling, set up every value you need from installers as a secret value or as a header whose type is Secret.
- You set the name, guidance, and default value shown for each input field when you submit for review (Input guidance shown to installers).
- For how to put values in a Script's Secrets, see Secret values are stored separately in the definition and called by name. For Webhook header types, see Headers and basic authentication.
For example, in a Script that saves notification sign-ups and sends a confirmation text through an external SMS service, you write the ID of the Content Type that stores sign-ups as is in Statement, and you put the SMS service's API key in Secrets as the secret value SMS_API_KEY. The example definition is in Letting the installer enter values for external services.
When this Script is included in an app and installed, the two values are handled as follows.
| Source Space | App | Installer's Space | |
|---|---|---|---|
Value of SMS_API_KEY | Your API key (your source Space runs on this value) | Not included. Only the name and description go in | The key the installer entered |
| ID of the "Notification Sign-up" Content Type | Original ID | Original ID | ID of the installed Content Type |
A Webhook's URL isn't a place the installer fills in, so the address you wrote carries over as is into every installed copy. If the destination address differs for each installer, as in an app that notifies the installer's work messenger every time a new inquiry comes in, have the Webhook run a Script, and put the address that Script calls in a secret value (When it runs a Script instead of a URL).
Binding tokens to least-privilege roles
- If you put a Delivery Access Token in the build output, anyone who opens the original site can find its value in the site files. Likewise, anyone who opens an installed site can find the installed token's value.
- An installed token is bound to the copy of the role the original token was bound to. If you include a token bound to the Administrator role, the installed token is bound to the Administrator role of the Space it's installed in (What each resource carries into the installed copy), and if the token value leaks, the installer's entire Space is at risk.
- So bind a token you put in a site to a role that can read only the Content Types the site actually needs to read. The same goes when you put a Space Access Token in a site. For the rules on choosing a role to bind, see Roles you can bind.
When you include member login
If your app supports its own member sign-up and login, it uses ServiceLogin and the official client SDK (opens in a new tab), and the browser calls ACDA with the member's token. The settings are covered in ServiceLogin settings and rules, and how to connect login to your site is covered in Auth API. When you include ServiceLogin in an app, the following rules apply.
- You must also include the member role used as ServiceLogin's default role (Resources you must include together).
- The login providers' client IDs and client secrets, and Contact email, aren't included in the app. For how these values are set on install, see Values you enter when installing.
- Among the addresses written in Default Return URL and Allowed Return URLs, the Subdomain address of a site you included, or your own domain address connected to that site, changes to the installed site's address. The installer enters any other address (such as an app's address).
- If an address you used during development (such as
localhost) is left in a return URL, the installer has to enter an address to take its place. Remove it in the ServiceLogin settings before bundling. - Signed-up members (ServiceUser) aren't included in the app. You can't include resources that reference a member's ID (Resources and conditions an app can't include).
- An app that includes ServiceLogin can be installed only in a Space that has no ServiceLogin (Each Space has one ServiceLogin).
Resources you must include together
You must also include every resource that an included resource references. If even one is missing, bundling is blocked.
| Included resource | Resources you must include with it |
|---|---|
| Content | Its Content Type, the Content and Media its link Fields reference, attached Tags, and resources whose IDs are written in Field values |
| Content Type | Other Content Types its link Fields allow |
| Media | Attached Tags |
| Delivery Access Token, Space Access Token | The SpaceRole bound to the token |
| SpaceRole, ServiceUserRole | Resources used in their rules (Content Type, Tag, Script, and so on) |
| ServiceLogin, ServiceUserRole | The ServiceUserRole used as ServiceLogin's default role. If your source Space has ServiceLogin, you must include the default role even if you include only one ServiceUserRole |
| Locale | The Locale set as its Fallback Locale, and every Locale further along that Fallback Locale chain |
| Scheduler | The Script it runs |
| Webhook | The Script it runs, and resources whose IDs are written in Filters values or in a shape to send that you wrote yourself |
| Script | Resources its definition references (for example, the Email Account it sends email with), and resources whose IDs are written in Statement or Payload Schema |
For when an ID written as text means you must also include its resource, see IDs written in resource definitions.
When you select the resources to include in Content Studio, the following two are selected along with them, and you can't deselect them.
- When your source Space has ServiceLogin, selecting Include ServiceLogin settings or selecting even one ServiceUserRole also selects the ServiceUserRole used as ServiceLogin's default role.
- Selecting a Locale also selects its Fallback Locale and every Locale further along that chain.
You must select the rest of the resources in the table yourself. WEEGLOO doesn't add a resource that's missing from the request to create a version. It blocks bundling instead. So when you create a version from a program, you must include the two above yourself too.
Resources and conditions an app can't include
If any resource falls under the following, bundling is blocked.
Resources that name a specific person. Service members and Space members don't carry over to another Space, so an app can't include resources that name a specific person.
- A Script, Content, or Webhook that references a service member's (ServiceUser's) ID or contains it as text. Remove that ID. For a Script, you can change it to receive the member ID in
payloadwhen it runs. - A role (SpaceRole, ServiceUserRole) with a condition that selects a specific user in the creator field. Remove that condition or change it to The requesting user (Narrowing by creator).
- A Script whose
whereinResourceFind,ResourceForEach, orResourceCountsets the creator (createdBy) to a specific user's ID. Remove that condition or change it to":self". You can also change it to receive the ID of the person to look up inpayloadwhen it runs. - A Webhook whose Filters use the creator (User ID, created by) or the last editor (User ID, updated by) as a criterion. It's blocked whatever the value, so remove that filter.
Circular references. On install, referenced resources are created first, so you can't include a resource whose references lead back to itself.
- A Content Type that leads back to itself when you follow the Content Types its link Fields allow. This includes a link Field that allows its own Content Type.
- Content that reference one another through link Fields so that following them leads back to the start
- A Locale that leads back to itself when you follow its Fallback Locale, or a Locale whose Fallback Locale is a Locale not included in the app
Resources still processing, or whose deployment failed. You can't include Media whose file hasn't finished processing. You can include a Web Hosting only when its deployment has finished processing and its State is Serving.
- If a Web Hosting is still processing a deployment (PENDING or PROCESSING), create the version again after processing finishes.
- You also can't include a Web Hosting whose deployment failed and whose State is FAILED. This applies even when a redeployment failed and the previous site is still open. Fix the bundle and upload it again, then create the version once the deployment finishes (If a deployment fails).
Resources created by installing another app. An app can include only resources you created yourself. You can't include such resources even if you edited them after installing, or after the installation record was deleted. If you're the one who made the original app, create a new version in the Space where you made it.
Checking the build output before bundling
Search the build output with grep for the source Space ID, the token value, and the resource IDs one by one, and check that each one turns up as a single unbroken string.
grep -r "DVRATbQ8mX2vK9pLs7Rf1Zt0Nc4Wd6Hg5Ua2Ee9Ck3PoYx8Bj6Hg5Ua2Ee9Ck3Po" dist/
grep -r "HnQ32YiH" dist/
grep -r "3trmXRkRjC1x4J9h2om4QZv0jC58Nv" dist/- A value that doesn't turn up won't change on install. Fix it using Values that change in site files.
- Also check that the files it turns up in are text files whose values change (
.html,.css,.js,.json, and so on, saved in UTF-8).
Limits
Minimum plan required to install
Each version has a minimum plan required to install the app. WEEGLOO compares the counts from the app against each plan's limits and sets the minimum plan to the lowest plan whose limits fit them all. If the app doesn't fit within any plan's limits, the highest plan becomes the minimum plan.
| What's counted in the app | Plan limit it's compared against |
|---|---|
| The number included of each resource type (Content Type, Content, Media, Tag, Locale, SpaceRole, ServiceUserRole, Delivery Access Token, Space Access Token, Script, Scheduler, Webhook, Web Hosting) | The count limit for the same type |
| The number of Statements in whichever included Script has the most Statements | Max statements per Script |
The number of external service calls (Http) and email sends (EmailSend) in whichever included Script has the most of those Statements | Max external calls per Script |
- The minimum plan assumes that only this app is installed in an empty Organization. It doesn't reflect how much the target Organization already uses, the size of Media and site files, or the Locales and Tags that already exist in the target Space. Whether the app can actually be installed depends on the target Organization's usage (What's checked before you can install).
- The Administrator role, ServiceLogin, and Email Accounts aren't counted. The plan needed for the sending server an Email Account uses isn't reflected either (Which sending servers you can use).
- The limit values for each plan are in Pricing. For how Statements are counted, see the limits section of Script settings and rules.
Size your app with the plans your installers mostly use in mind. If a single Script with many Statements is pushing the minimum plan up, splitting that Script can bring the minimum plan down.
Required permissions
The permissions needed to create a Market App and its versions are covered in Organization settings and rules.
For the following types of resources, you can see their list only if you have the matching settings permission in your source Space. Without it, you can't include resources of that type in an app. If an included resource references such a resource, you can't include the referenced resource with it, so bundling is blocked.
| Resource to include | Settings permission needed in the source Space |
|---|---|
| Delivery Access Token | Manage Delivery Access Tokens |
| Space Access Token | Manage Space Access Tokens |
| Email Account | Manage Email Accounts |
| Webhook | Manage Webhooks |
| Scheduler | Manage Schedulers |
| ServiceLogin, ServiceUserRole | Manage ServiceLogin |
| Web Hosting | Manage Web Hostings |
For how to turn on settings permissions, see Settings permissions on the Settings tab.
Tasks in Content Studio
The tasks you do in Content Studio while preparing an app are laid out on each resource's page.
- Issue a Delivery Access Token: Steps for issuing the token that goes in your site, bound to a narrow role.
- Create a Script: Steps for creating a Script that keeps the values installers enter in Secrets.
- Edit a Script: Steps to follow when you move a key written as text in Statement to Secrets.
- Send the translation program's key in a Secret header: Steps for setting a Webhook header as a header whose type is Secret.
- Create a Webhook that runs a Script: Steps for making a Webhook run a Script when you want the installer to set the destination address.
- Create a Market App: Steps for creating a Market App and its first version by selecting the resources to include.
- Create a new version: Steps for selecting the resources to include again after you edit the originals, and creating a new version.
- Test-install a version: Steps for installing a version you created in a test Space and checking that the installed copy works as intended. The rules are in A test install lets you check ahead.
Troubleshooting
Problems you hit when creating a version are at the top of the table, and problems that show up after installing are further down. You can catch the after-install problems with a test install before you submit for review (A test install lets you check ahead).
| Problem | Cause | What to do |
|---|---|---|
| You can't create a version because a required resource is missing | You didn't include a resource that an included resource references. This also covers IDs of source Space resources written as text in a Script, Content, or Webhook | Include the referenced resources too (Resources you must include together) |
| You can't select a resource you need to include | You don't have the settings permission to see that type in your source Space | Ask a member with Manage Roles for that settings permission (Required permissions) |
| You can't create a version because a resource was deleted | A resource was deleted from your source Space after you selected it | Select the resources to include again |
| You can't create a version because a resource hasn't finished processing | An included Media file or Web Hosting deployment hasn't finished processing, or a Web Hosting deployment failed | Create the version again after processing finishes. For a Web Hosting whose deployment failed, fix the bundle and deploy it again (Resources and conditions an app can't include) |
| You can't create a version because a resource names a specific user | Something references a service member's ID, a condition sets the creator to a specific user, or a Webhook's Filters use the creator or the last editor as a criterion | Remove or change that condition (Resources and conditions an app can't include) |
| You can't create a version because of a problem with references between resources | References among Content Types or Content go in a circle, a Locale's Fallback Locale goes in a circle, or a Locale you didn't include is set as a Fallback Locale | Break the circular reference, or include the Locale used as the Fallback Locale too (Resources and conditions an app can't include) |
| You can't create a version because a resource was created by installing another app | An app can include only resources you created yourself | Leave that resource out and build the app from resources you created yourself |
| You created a version, but bundling fails | A definition contains the ID of a resource installed after it, or an included resource was deleted during bundling | Remove that ID and create a new version (You can't write the ID of a resource installed later) |
| The installed site reads content from your source Space | You didn't include a resource or token the site reads, a value didn't remain as a whole string in the build output, or you wrote a value in a file whose values don't change | Check Values that change in site files and create a new version |
| Images on the installed site load from your source Space's files | The Media whose addresses are written in the site isn't included in the app | Include that Media and create a new version |
| An installed Script calls an external service with your key | You wrote the key as text in Statement | Move the key to Secrets and create a new version (Values the installer enters) |
| An installed Webhook sends requests to your server | A Webhook's URL and headers whose type is Custom are copied as written | To let the installer set the destination address, have the Webhook run a Script (Values the installer enters) |
| You can't add installer input fields to a version you already created | Input fields are fixed at bundling | Add a secret value or a header whose type is Secret to the original, then create a new version |
| The installed site's addresses for search and sharing still point to the original site | You wrote that address as your own domain connected to the original site, or you wrote it in the page body or a script instead of a meta tag | Write it as the Subdomain address, or as a path without the address. The installer can edit it in Custom Metadata (The site's own address and meta tags) |
| Installers get a field asking them to enter a return URL for member login | An address outside the included site (such as a development address) is left in a return URL | Remove the address you don't use in the ServiceLogin settings and create a new version (When you include member login) |
| Drafts in progress are published in the Space the app was installed in | Whatever was saved at bundling is created in a published state | Clean up the originals, then create a new version (A version includes what's saved at bundling time) |
| The required minimum plan is higher than you expected | The number of resources, or the single Script with the most Statements or external calls, goes over a lower plan's limits | Include fewer resources or split the large Script (Minimum plan required to install) |
Related docs
- Building an app: Covers what building an app means and the order you build one in.
- App publishing and review rules: Covers the rules for creating versions, checking them with a test install, and submitting them for review.
- App install rules: Covers the conditions under which installers can install an app, and the rules after installing.
- Web Hosting settings and rules: Covers the rules for site file bundles and sites installed from an app.
- API reference: Covers the technical specifications, such as the request format your site sends when it reads content.
