Generating a package
Section titled “Generating a package”Let us start with the honest answer to the question that usually brings a reader here: a single standalone JSON file containing every definition a working system needs is not something OSOS produces or accepts. A package is a multi-file ZIP whose parts — manifest, index, dependency edges, per-resource payloads — must agree with one another, and nothing in the platform emits or consumes a one-file bundle of everything (services/packaging-service/src/libs/zip-utils.ts defines the contract; the package format documents it). The nearest thing to a single JSON is data-service’s separate module/entity transfer, which genuinely is one file but carries modules and entities only — see Module JSON transfer. The packaging engine this contract belongs to shipped in the 1.8 line (Since 1.8); on an older deployment these endpoints and the export UI are absent.
What exists instead are three practical paths to producing, transforming, or parameterising a package. This page documents them in the order you should consider them.
Choosing a path
Section titled “Choosing a path”| Path | Supported? | Reach for it when |
|---|---|---|
| 1. Export → transform → re-import | Yes — the mainline | You want a modified or templated variant of something a real environment already contains. |
| 2. Payload overrides on an import session | Yes — the sanctioned programmatic hook | You want to inject environment-specific values into a package at import time, without forking the ZIP. |
| 3. Hand-authoring from nothing | Possible, unsupported | You are generating resources no environment has ever contained — and you accept the costs below. |
Paths 1 and 2 compose: the robust pipeline for repeated environment promotion is a reference package produced by export, parameterised per target through the override API.
Path 1 — export, transform, re-import
Section titled “Path 1 — export, transform, re-import”The only path that starts from a guaranteed-valid artifact. Export a reference package from a source environment, unzip it, transform the JSON, rebuild the archive, and import the result. You inherit a correct manifest.json, index.json and dependencies.json, and your only obligation is keeping them consistent with whatever you changed.
The round trip
Section titled “The round trip”The endpoints below are the packaging service’s export and import routes; conventions — the {success, result} envelope, tokens, error shapes — are covered by Calling the HTTP API and are not repeated here.
Selecting resources from the admin UI, Since 1.8. Before calling the export endpoint below, an admin usually picks the modules/entities/pages to include from a checkbox tree in the Administration packaging screen. A bug fix landed this cycle: unchecking a container’s only remaining child used to also uncheck the container itself, so “export this module or entity alone, with no children” was unreachable — the tree now tracks a container’s own checked state separately from its derived (any-child-checked) state, so that combination works correctly. Ticking/unticking a container still cascades to its whole subtree, as before.
export BASE="https://acme.example.com"export TOKEN="<your API token>"
# 1 — start an export jobcurl -s -X POST "$BASE/api/packaging/v1/export" \ -H "x-app-token: $TOKEN" -H "content-type: application/json" \ -d '{"resources":[{"type":"DataModule","id":"<module-id>","withChildren":true}], "name":{"en":"crm-reference"}}'# → {"success":true,"result":{"jobId":"export-<exportId>","exportId":"<exportId>"}}# (Since 1.10 the export is also kept as an export record: GET /v1/exports/<exportId>)
# 2 — poll until the job completes (note: the job's own result is nested# inside the envelope's result)curl -s "$BASE/api/packaging/v1/export/export-<exportId>/status" -H "x-app-token: $TOKEN"# → {"success":true,"result":{"status":"completed",# "result":{"fileId":"<fileId>","name":"crm-reference.zip", …}}}
# 3 — download the ZIP. The export stores it in storage-service as a# temporary file; the response is the raw file, not enveloped JSON.curl -s "$BASE/api/storage/v2/files/download/<fileId>?temp=true" \ -H "x-app-token: $TOKEN" -o package.zip
# 4 — unzip, transform the JSON under resources/, rezip
# 5 — upload the transformed archive, again as a temporary filecurl -s -X POST "$BASE/api/storage/v2/files?temp=true" \ -H "x-app-token: $TOKEN" -F "file=@package-transformed.zip"# → {"success":true,"result":[{"id":"<newFileId>", …}]}
# 6 — open an import session against it, then configure and executecurl -s -X POST "$BASE/api/packaging/v1/import/validate" \ -H "x-app-token: $TOKEN" -H "content-type: application/json" \ -d '{"fileId":"<newFileId>","fileName":"package-transformed.zip"}'# → {"success":true,"result":{"sessionId":"…","validationReport":{…},# "updateIdentifier":"…"}}From the sessionId onward this is the standard session flow — configure mappings, execute, poll — documented on the import API page and in the packaging overview. Export is a background job (POST /v1/export enqueues it and returns a job id — the general pattern is covered in Long-running work); the temp=true flag on both storage calls matches how the platform itself stores package files (and every packaging download passes it, services/packaging-service/src/services/package-export.service.ts uploads with the temp flag).
Since 1.10 the export name is a localized object and is required (400 EXPORT_NAME_REQUIRED without it); the ZIP is named from its English value, else its Arabic one. The caller needs Developer on every exported root, and resources that belong to an installed package cannot be exported at all (403 EXPORT_INSTALLED_RESOURCE) — see Export access.
Keeping the parts consistent
Section titled “Keeping the parts consistent”A transformation is safe exactly as long as the archive’s members still agree. The rules, each traceable to import-side code:
- Filenames come from
nameMap, not from names.index.json’snameMap(id → normalizedName) is the authoritative key forresources/{Type}/{name}.json; export suffixes colliding slugs with the id, and the importer id-verifies name-based hits. Rename a file, or a resource’snormalizedName, without updatingnameMapand the resource is unreachable. - Path components are strict. Every component must match
^[a-zA-Z0-9_.-]+$— deriving a filename from a user-visible name with spaces or non-Latin characters is the most common way a rebuilt archive gets rejected at extraction. - Changed references need matching edges. If your transformation adds or moves an id reference,
dependencies.jsonmust carry an edge whosepathpoints at it, or the id will never be remapped — the dependency graph explains exactly how the edges drive rewriting and ordering. - Structural fields are load-bearing. A resource’s parent pointers (
module,dataEntity, …) are what remapping and scope resolution key on; moving a resource between parents is a re-authoring exercise, not a field edit. - The manifest must still count.
resourceCountandresourceTypesare shape-checked at extraction (assertManifestShape), and theschemaVersionmust be a supported one —1.0to1.4on 1.10, only1.0or1.1on an older target. Keep the version your export was stamped with unless you add or remove the part that version describes; see Schema versioning.
Path 2 — the payload override API
Section titled “Path 2 — the payload override API”The sanctioned way to change package content programmatically — and for most readers the real answer to “can I generate this?”. Within a live import session, between validate and execute, every packaged resource’s payload can be read and replaced through one route:
GET /api/packaging/v1/import/{sessionId}/resource/{sourceType}/{sourceId}/payloadPATCH /api/packaging/v1/import/{sessionId}/resource/{sourceType}/{sourceId}/payloadDELETE /api/packaging/v1/import/{sessionId}/resource/{sourceType}/{sourceId}/payloadsourceType is the resource’s ResourceType name and sourceId its id in the package — source-environment identifiers, as listed in the session’s validation report. The ZIP itself is never touched: an override lives on the session (ResourceOverride) and is applied in place of the packaged payload, before remapping, at execution. That ordering matters — you write an override in source-environment ids, exactly as if it had been packaged, and the engine rewrites it like everything else. This is how a reference package is parameterised per environment — repointing an endpoint, adjusting a threshold, injecting tenant-specific configuration — while the artifact stays a single unforked file.
Read a resource’s payload
Section titled “Read a resource’s payload”GET returns the payload the execution will actually use — the override if one exists, otherwise the packaged original extracted from the ZIP. The response (GetResourcePayloadResponse):
| Field | Meaning |
|---|---|
sourceType, sourceId, normalizedName | The resource’s identity in the package. |
payload | What will be imported: the override when isOverride is true, else the packaged original. |
isOverride | Whether an override is currently active. |
packagedPayload | The packaged original, present only while an override is active — so a client can diff and preview a reset without a second call. |
editedBy, editedAt | Provenance of the active override. |
A resource present in the session but missing from the archive returns 404; reads are refused with 409 while the import is running.
Save an override
Section titled “Save an override”PATCH takes {payload, updateIdentifier} (SaveResourcePayloadRequest) and persists the payload on the session after validation. Saving an override for a resource that previously failed (or was cascade-skipped) also resets its status to pending, so the session’s retry picks it up — the override API doubles as the repair loop for a failed import. Every write is audit-logged with the session, resource, author and payload size.
The validator rejects:
| Condition | Response |
|---|---|
| Payload not a plain JSON object, or carrying prototype-polluting keys | 400 |
Serialized payload over 2 MB (MAX_OVERRIDE_PAYLOAD_BYTES) | 413 |
| A structural field changed from the packaged snapshot | 400 |
What an override cannot change
Section titled “What an override cannot change”Structural fields — the parent pointers that remapping and dependency resolution key on — are fingerprinted at validation (structuralSnapshot) and locked (STRUCTURAL_IMMUTABLE, same file). Changing them would silently desynchronise the payload from the package’s dependency edges:
| Resource type | Immutable fields |
|---|---|
DataEntity | module, dataModule |
DataView | module, dataModule, dataEntity, definingEntity |
DataQuery, DataReaction, DataCollection, StatisticQuery | dataEntity, definingEntity |
DataRelation | dataModule, module |
Announcement | entityId |
An override is a content hook, not a structure hook. To change where a resource lives, use the session’s mapping configuration; to change what the package contains, use path 1.
Clear an override
Section titled “Clear an override”DELETE (with the current updateIdentifier as a query parameter) removes the override so the next execution falls back to the packaged payload. Clearing an override that does not exist is a deliberate no-op 200, so an idempotent “reset” in client code needs no existence check first.
Concurrency and session state
Section titled “Concurrency and session state”All three verbs share the session’s guards: the caller’s space must own the session, and writes are refused with 409 while the session is importing or validating. Mutations are optimistically locked — each write must echo the updateIdentifier the client last saw and each response returns a rotated one to adopt; a mismatch is a 409 whose error.code is STALE_UPDATE_IDENTIFIER, distinguishable from the status-gate 409s. A generator driving this API is a loop: read the token, write, adopt the returned token, repeat.
Path 3 — hand-authoring from nothing
Section titled “Path 3 — hand-authoring from nothing”Building a package without exporting one is possible — the import trusts any archive that passes validation, wherever it came from — but it is unsupported, and the platform gives you no authoring tools for it. You are reimplementing the exporter by hand.
What you must produce
Section titled “What you must produce”Every part of the package format, mutually consistent:
- A
manifest.jsonwhose shape passesassertManifestShape—schemaVersion(a supported'1.0'/'1.1'),createdAt,resourceCount,resourceTypes— plus the source-identity fields if you want stored mapping profiles to apply. - An
index.jsonwhoseorderedResourcesis a genuine topological order over the hard edges, and whosenameMapnames every file actually present underresources/. - A
dependencies.jsonwhose edges carry correct JSONpathvalues for every internal reference — otherwise nothing is remapped and nothing is ordered (the dependency graph). - One payload per resource under
resources/{Type}/{name}.json, each matching its type’s schema — Resource schemas documents Tier 1; for the rest, the reliable procedure is to export a real specimen and copy its shape. - Nothing else: the archive’s top level is allow-listed, and an unknown entry fails extraction (
UNKNOWN_ENTRY). Stay under the safety limits — 200 MB decompressed, 10 000 entries, safe path components, no traversal.
Your only safety net
Section titled “Your only safety net”The strict validator at the extract boundary checks the container: required entries present, valid JSON, manifest shape, allow-listed top level. Its four typed failures — MISSING_ENTRY, INVALID_JSON, SCHEMA_VIOLATION, UNKNOWN_ENTRY — are the only errors that will point at your archive directly, and a producer iterating on a generator should expect to meet all four.
What it does not check is the mutual consistency the exporter normally guarantees. An index.json entry whose file is missing does not fail the import — the resource is skipped and its hard dependents are cascade-skipped with it. An edge whose path is wrong does not error — the reference is silently left unrewritten. A payload violating its resource schema surfaces as a per-resource failure from data-service at execution, in the target environment’s terms rather than your generator’s. Which is the argument, one last time, for paths 1 and 2: start from an artifact the platform built, and parameterise it through the API built for exactly that.
Platform 1.10.0 · Backend 1.11.0-alpha.11 · Frontend 1.11.0-alpha.6 · Mobile 1.10.2 · Chart 1.11.8 · Gateway 2.6.11 · MCP 0.2.0 · Grafana DS 1.2.0Docs build 2026-11-27