@collective-intelligence/external-apps-server-sdk-payload 0.0.0-stage → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +49 -0
- package/README.md +121 -2
- package/dist/ci-generate/declarations/ci-generate/generate.d.ts +10 -0
- package/dist/ci-generate/declarations/entrypoints/ci-generate.d.ts +6 -0
- package/dist/ci-generate/declarations/knowledge/body.d.ts +32 -0
- package/dist/ci-generate/declarations/knowledge/files.d.ts +42 -0
- package/dist/ci-generate/declarations/knowledge/manifest.d.ts +19 -0
- package/dist/ci-generate/declarations/package/builder.d.ts +63 -0
- package/dist/ci-generate/declarations/package/contract.d.ts +16 -0
- package/dist/ci-generate/declarations/package/stamped-fields.d.ts +7 -0
- package/dist/ci-generate/declarations/plugin/editor-field.d.ts +20 -0
- package/dist/ci-generate/declarations/plugin/integration-user.d.ts +11 -0
- package/dist/ci-generate/declarations/plugin/parts.d.ts +81 -0
- package/dist/ci-generate.d.ts +1 -0
- package/dist/ci-generate.js +2 -0
- package/dist/index/declarations/ci-generate/generate.d.ts +10 -0
- package/dist/index/declarations/entrypoints/index.d.ts +6 -0
- package/dist/index/declarations/knowledge/body.d.ts +32 -0
- package/dist/index/declarations/knowledge/files.d.ts +42 -0
- package/dist/index/declarations/knowledge/identity.d.ts +27 -0
- package/dist/index/declarations/knowledge/manifest.d.ts +19 -0
- package/dist/index/declarations/knowledge/push-job.d.ts +8 -0
- package/dist/index/declarations/knowledge/source.d.ts +24 -0
- package/dist/index/declarations/operations/conflict.d.ts +22 -0
- package/dist/index/declarations/operations/markdown.d.ts +25 -0
- package/dist/index/declarations/operations/operations.d.ts +30 -0
- package/dist/index/declarations/operations/write-back.d.ts +8 -0
- package/dist/index/declarations/package/builder.d.ts +63 -0
- package/dist/index/declarations/package/contract.d.ts +16 -0
- package/dist/index/declarations/package/stamped-fields.d.ts +7 -0
- package/dist/index/declarations/plugin/editor-field.d.ts +20 -0
- package/dist/index/declarations/plugin/grant-store.d.ts +21 -0
- package/dist/index/declarations/plugin/integration-user.d.ts +11 -0
- package/dist/index/declarations/plugin/parts.d.ts +81 -0
- package/dist/index/declarations/plugin/plugin.d.ts +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -0
- package/dist/package.d.ts +134 -0
- package/dist/package.js +24 -0
- package/docs/guide/ai/index.md +379 -0
- package/docs/guide/ai/studio.md +245 -0
- package/docs/guide/data/connectors.md +267 -0
- package/docs/guide/data/datasets.md +145 -0
- package/docs/guide/data/documents.md +235 -0
- package/docs/guide/data/index.md +62 -0
- package/docs/guide/data/knowledge.md +214 -0
- package/docs/guide/develop/extensions.md +299 -0
- package/docs/guide/develop/external-apps.md +289 -0
- package/docs/guide/develop/infrastructure.md +135 -0
- package/docs/guide/develop/sdks.md +252 -0
- package/docs/guide/index.md +83 -0
- package/docs/guide/platform/access.md +311 -0
- package/docs/guide/platform/architecture.md +166 -0
- package/docs/guide/platform/built-ins.md +225 -0
- package/docs/guide/platform/entrypoints.md +320 -0
- package/docs/guide/scenarios/index.md +130 -0
- package/docs/guide/template/index.md +295 -0
- package/docs/guide/template/state-machines.md +294 -0
- package/docs/payload-connector.md +890 -0
- package/docs/payload-page-editor-skill.md +284 -0
- package/package.json +79 -4
package/AGENTS.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# `@collective-intelligence/external-apps-server-sdk-payload`: agent guide
|
|
2
|
+
|
|
3
|
+
The Payload SDK: the CMS SDK that connects a Payload Site to Collective
|
|
4
|
+
Intelligence (CI) through a Gateway. It holds the Payload Plugin (`.`), the
|
|
5
|
+
Payload Package Helpers and the Payload Operation Contract (`./package`), and
|
|
6
|
+
the `payload ci-generate` bin script (`./ci-generate`). The package
|
|
7
|
+
`README.md` holds the entries.
|
|
8
|
+
|
|
9
|
+
## Rules
|
|
10
|
+
|
|
11
|
+
- Import `ciPayloadPlugin` from the root in `payload.config.ts`. Import the
|
|
12
|
+
Payload Package Helpers and `payloadOperationContract` from `/package` in
|
|
13
|
+
the site's extension package: `/package` loads no Payload module.
|
|
14
|
+
- Install `@collective-intelligence/extensions-sdk` at the exact version that
|
|
15
|
+
this SDK names as its peer, and keep one copy in the extension package. The
|
|
16
|
+
helpers declare each component with that copy. Install no other version of
|
|
17
|
+
the server SDK: this SDK pins it as a dependency.
|
|
18
|
+
- Declare the CI side of the site with the helpers: `payloadGateway`,
|
|
19
|
+
`payloadKnowledge`, `payloadGatewayPushGrant` and `payloadPageEditor`. Put
|
|
20
|
+
each returned Gateway and each `components` list into `declarePackage`, and
|
|
21
|
+
`payloadPackageDependencies` into the manifest `dependencies`.
|
|
22
|
+
- Give `payloadKnowledge` a `schedules` list, so that a scheduled full import
|
|
23
|
+
repairs the pushes that the site missed. Without `schedules`, the connector
|
|
24
|
+
instance has no pipeline.
|
|
25
|
+
- Declare the website search yourself: the visitor Data Policy, the member
|
|
26
|
+
policy, the site app with its Access Profiles, and the visitor Agent with
|
|
27
|
+
`dataAccess: { knowledge: "user" }`. No helper declares them.
|
|
28
|
+
- A finished component does not change. To change a schema or a binding that
|
|
29
|
+
`payloadKnowledge` gives, declare it again from its `manifest`.
|
|
30
|
+
- Run the jobs of the `ci-gateway` queue on the site, and make a site
|
|
31
|
+
migration after you add the plugin and after each `writable: true`.
|
|
32
|
+
- Deploy the site before the package release. Add `--check` of
|
|
33
|
+
`payload ci-generate` to the site build.
|
|
34
|
+
|
|
35
|
+
## Index
|
|
36
|
+
|
|
37
|
+
- [docs/payload-connector.md](docs/payload-connector.md): read when you
|
|
38
|
+
connect a Payload Site to CI: `ciPayloadPlugin`, the job runner, the Payload
|
|
39
|
+
Declarations File, the Payload Package Helpers, deploy order, first import,
|
|
40
|
+
website search, upload fields, or the Dashboard setup path.
|
|
41
|
+
- [docs/payload-page-editor-skill.md](docs/payload-page-editor-skill.md):
|
|
42
|
+
read when an Agent writes the pages of a Payload Site: `payloadPageEditor`,
|
|
43
|
+
its instruction text and approvals, the operation inputs, or Knowledge
|
|
44
|
+
Mutate on Payload schemas.
|
|
45
|
+
|
|
46
|
+
## Platform guide
|
|
47
|
+
|
|
48
|
+
- [docs/guide/index.md](docs/guide/index.md): read before choosing CI primitives for a solution or demo, or when a task needs the platform model (architecture, access, data, AI, template).
|
|
49
|
+
- [docs/guide/platform/built-ins.md](docs/guide/platform/built-ins.md): read before declaring a tool, workflow node, trigger, connector, connection, schema or notification channel, to reuse the `builtin.` FQN that CI already ships and to check which built-in packages an Organization has installed.
|
package/README.md
CHANGED
|
@@ -1,3 +1,122 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @collective-intelligence/external-apps-server-sdk-payload
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Payload SDK: the CMS SDK that connects a Payload Site to Collective
|
|
4
|
+
Intelligence (CI) through a Gateway. It holds everything Payload: the Payload
|
|
5
|
+
Plugin that the site runs, the Payload Package Helpers that the site's
|
|
6
|
+
extension package calls, and the `payload ci-generate` command.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @collective-intelligence/external-apps-server-sdk-payload \
|
|
12
|
+
@collective-intelligence/extensions-sdk payload effect
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The package pins the server SDK
|
|
16
|
+
(`@collective-intelligence/external-apps-server-sdk`) as a dependency at the
|
|
17
|
+
same release. Its peers are required:
|
|
18
|
+
|
|
19
|
+
| Peer | Range |
|
|
20
|
+
| ----------------------------------------- | ----------------------------- |
|
|
21
|
+
| `payload` | `>=3 <4` |
|
|
22
|
+
| `effect` | `^4.1.0` |
|
|
23
|
+
| `@collective-intelligence/extensions-sdk` | the same release, exact match |
|
|
24
|
+
|
|
25
|
+
The extensions SDK is a peer so that the site's extension package and the
|
|
26
|
+
Payload Package Helpers share one extensions SDK copy.
|
|
27
|
+
|
|
28
|
+
## Entries
|
|
29
|
+
|
|
30
|
+
| Entry | Use |
|
|
31
|
+
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
32
|
+
| `.` | `ciPayloadPlugin` and its types `CiPayloadPluginOptions`, `PayloadCollectionOptions`, `PayloadDocument`: add the plugin to the `plugins` of `payload.config` |
|
|
33
|
+
| `./package` | The Payload Package Helpers `payloadGateway`, `payloadKnowledge`, `payloadGatewayPushGrant`, `payloadPageEditor` and `payloadPackageDependencies`, their input and result types, and the Payload Operation Contract `payloadOperationContract` with `PayloadOperationId`, for the site's extension package; it imports no Payload module |
|
|
34
|
+
| `./ci-generate` | The `payload ci-generate` bin script that `ciPayloadPlugin` adds to the Payload configuration; Payload's bin runner loads it |
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
// payload.config.ts
|
|
38
|
+
import { ciPayloadPlugin } from "@collective-intelligence/external-apps-server-sdk-payload"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
# Write the Payload Declarations File that the extension package reads.
|
|
43
|
+
payload ci-generate --out ci-package/payload-declarations.json
|
|
44
|
+
# Fail the site build when the file does not match the configuration.
|
|
45
|
+
payload ci-generate --out ci-package/payload-declarations.json --check
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The Payload Package Helpers declare each component that every Payload Site
|
|
49
|
+
needs with the site's own extensions SDK copy, and return finished
|
|
50
|
+
components. Put them into `declarePackage`:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// The site's extension package
|
|
54
|
+
import { declarePackage } from "@collective-intelligence/extensions-sdk"
|
|
55
|
+
import {
|
|
56
|
+
payloadGateway,
|
|
57
|
+
payloadGatewayPushGrant,
|
|
58
|
+
payloadKnowledge,
|
|
59
|
+
payloadPackageDependencies,
|
|
60
|
+
payloadPageEditor
|
|
61
|
+
} from "@collective-intelligence/external-apps-server-sdk-payload/package"
|
|
62
|
+
|
|
63
|
+
import declarations from "./payload-declarations.json" with { type: "json" }
|
|
64
|
+
|
|
65
|
+
const version = "1.0.0"
|
|
66
|
+
const gateway = payloadGateway({
|
|
67
|
+
displayName: "Museum site",
|
|
68
|
+
fqn: "acme.site.gateways.payload",
|
|
69
|
+
version
|
|
70
|
+
})
|
|
71
|
+
const knowledge = payloadKnowledge(declarations, {
|
|
72
|
+
collections: { pages: { draftImport: "published_and_drafts" }, posts: {} },
|
|
73
|
+
domainFqn: "acme.site.domains.website",
|
|
74
|
+
gateway,
|
|
75
|
+
manifest: { fqn: "acme.site.knowledge", version },
|
|
76
|
+
presentation: { displayName: "Museum site content" },
|
|
77
|
+
// Each schedule runs a full import that repairs missed pushes.
|
|
78
|
+
schedules: [{ cronExpression: "0 3 * * *", key: "nightly" }]
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
export default declarePackage({
|
|
82
|
+
components: [
|
|
83
|
+
// Also the domain of `domainFqn` and the website search components.
|
|
84
|
+
gateway,
|
|
85
|
+
...knowledge.components,
|
|
86
|
+
// The server Access Profile and grant that let the Gateway's app push.
|
|
87
|
+
...payloadGatewayPushGrant({
|
|
88
|
+
fqn: "acme.site.gateway-push",
|
|
89
|
+
gateway,
|
|
90
|
+
version
|
|
91
|
+
}).components,
|
|
92
|
+
// The page editor Skill and the Agent that holds it.
|
|
93
|
+
...payloadPageEditor({
|
|
94
|
+
agentFqn: "acme.site.agents.page-editor",
|
|
95
|
+
gateway,
|
|
96
|
+
skillFqn: "acme.site.skills.page-editor",
|
|
97
|
+
version
|
|
98
|
+
}).components
|
|
99
|
+
],
|
|
100
|
+
manifest: {
|
|
101
|
+
// The Knowledge Gateway template of builtin.core.external-apps.
|
|
102
|
+
dependencies: payloadPackageDependencies,
|
|
103
|
+
fqn: "acme.site",
|
|
104
|
+
name: "Acme site",
|
|
105
|
+
version
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
| Helper | Result |
|
|
111
|
+
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
112
|
+
| `payloadGateway` | The Gateway, with the Payload Operation Contract; `operation(id)` takes a Payload operation id |
|
|
113
|
+
| `payloadKnowledge` | `schemas` (one entity schema for each chosen collection, by collection name), `connectorInstance` and `components`; with `schedules`, the connector instance has the pipeline `repair`, which runs a full import on each schedule |
|
|
114
|
+
| `payloadGatewayPushGrant` | `profile` (`<fqn>.profile`, `data.knowledge` at `manage`), `grant` (`<fqn>.grant`, to `<gateway fqn>.application`) and `components` |
|
|
115
|
+
| `payloadPageEditor` | `skill`, `agent` (it holds the Skill and binds `read` as `read-page`) and `components`; `instructions` and `approvals` (by operation id) replace the defaults |
|
|
116
|
+
| `payloadPackageDependencies` | `[{ fqn: "builtin.core.external-apps" }]`, for the manifest `dependencies` |
|
|
117
|
+
|
|
118
|
+
A finished component does not change: to change a schema or a binding, declare
|
|
119
|
+
it again from its `manifest`. The site keeps its own website search setup: the
|
|
120
|
+
visitor Data Policy, the member policy, the site app and the visitor Agent.
|
|
121
|
+
|
|
122
|
+
The CHANGELOG lists the changes of each release.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SanitizedConfig } from "payload";
|
|
2
|
+
import type { PayloadPluginPart } from "../plugin/parts.js";
|
|
3
|
+
/**
|
|
4
|
+
* The `payload ci-generate --out <file> [--check]` bin script (Q104): it
|
|
5
|
+
* writes the Payload Declarations File, or with `--check` fails when the
|
|
6
|
+
* file is out of date.
|
|
7
|
+
*/
|
|
8
|
+
export declare const script: (config: SanitizedConfig) => Promise<void>;
|
|
9
|
+
/** Adds the `payload ci-generate` bin script to the site configuration (ARC-003). */
|
|
10
|
+
export declare const generatePart: PayloadPluginPart;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ResourceJsonValue } from "@collective-intelligence/external-apps-server-sdk/resources";
|
|
2
|
+
import type { FlattenedBlocksField, FlattenedField, SanitizedCollectionConfig, SanitizedConfig } from "payload";
|
|
3
|
+
import type { PayloadDocument } from "../plugin/parts.js";
|
|
4
|
+
/** The fields of one group, named tab, array row or block, with their data. */
|
|
5
|
+
export type Subfields = Readonly<{
|
|
6
|
+
data: PayloadDocument;
|
|
7
|
+
fields: readonly FlattenedField[];
|
|
8
|
+
/** The field path segment: `<field>`, or `<field>.<block slug>` for a block. */
|
|
9
|
+
path: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const objectOf: (value: ResourceJsonValue | undefined) => PayloadDocument | undefined;
|
|
12
|
+
/** The block of one row of a blocks field: the block of the row's `blockType`. */
|
|
13
|
+
export declare const blockOf: (config: SanitizedConfig, field: FlattenedBlocksField, row: PayloadDocument) => import("payload").FlattenedBlock | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The subfields of a group, named tab, array or blocks field, in field and
|
|
16
|
+
* row order, each with the data that it reads in the field's value.
|
|
17
|
+
*/
|
|
18
|
+
export declare const subfields: (config: SanitizedConfig, field: FlattenedField, value: ResourceJsonValue | undefined) => readonly Subfields[];
|
|
19
|
+
/**
|
|
20
|
+
* The Document Body of a document: all its visible text in field order, as
|
|
21
|
+
* one Markdown text (Q10). The collection's title field is the top heading;
|
|
22
|
+
* rich text keeps its headings and lists. A field with `admin.hidden`, and
|
|
23
|
+
* each field path that the developer skips, stay out (Q21). A field path
|
|
24
|
+
* names the fields from the document root, with the block slug after a
|
|
25
|
+
* blocks field: `meta.description`, `layout.hero.heading`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const documentBody: ({ collection, config, document, skip }: Readonly<{
|
|
28
|
+
collection: SanitizedCollectionConfig;
|
|
29
|
+
config: SanitizedConfig;
|
|
30
|
+
document: PayloadDocument;
|
|
31
|
+
skip?: readonly string[] | undefined;
|
|
32
|
+
}>) => string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ResourceJsonValue } from "@collective-intelligence/external-apps-server-sdk/resources";
|
|
2
|
+
import type { FlattenedField, Payload, UploadField } from "payload";
|
|
3
|
+
import type { PayloadDocument, PayloadPluginPart } from "../plugin/parts.js";
|
|
4
|
+
/** A stored file of an upload collection. */
|
|
5
|
+
type StoredFile = Readonly<{
|
|
6
|
+
collection: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** The signed link of a connector file source, and when it stops serving the file. */
|
|
10
|
+
type FileLink = Readonly<{
|
|
11
|
+
url: string;
|
|
12
|
+
url_expires_at: string;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Signs links of the file route under `gatewayUrl`, the Gateway URL that CI
|
|
16
|
+
* calls: a link names one stored file and serves it until it expires.
|
|
17
|
+
*/
|
|
18
|
+
export declare const fileLinker: (payload: Payload, gatewayUrl: string) => (file: StoredFile) => FileLink;
|
|
19
|
+
/** An upload field names files of upload collections. */
|
|
20
|
+
export declare const isUploadField: (field: FlattenedField) => field is UploadField;
|
|
21
|
+
/**
|
|
22
|
+
* The manifest schema of an upload field: a connector file source, or null
|
|
23
|
+
* for no readable file, or a list of sources for a has-many field (Q13).
|
|
24
|
+
*/
|
|
25
|
+
export declare const uploadFieldSchema: (field: UploadField) => ResourceJsonValue;
|
|
26
|
+
/**
|
|
27
|
+
* The upload fields of a document as connector file sources, by field name:
|
|
28
|
+
* one source or null, or a list for a has-many field. `linked` adds to each
|
|
29
|
+
* source the signed link of the file route; `revision` has no links, because
|
|
30
|
+
* a link changes with each read and its file does not. Without a Gateway URL
|
|
31
|
+
* (no CI trust) no field holds a file.
|
|
32
|
+
*/
|
|
33
|
+
export declare const documentFiles: (fields: readonly UploadField[], doc: PayloadDocument, link: ((file: StoredFile) => FileLink) | undefined) => {
|
|
34
|
+
linked: Readonly<Record<string, ResourceJsonValue>>;
|
|
35
|
+
revision: Readonly<Record<string, ResourceJsonValue>>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The file route (ARC-004): CI downloads the file of a mapped Knowledge File
|
|
39
|
+
* field from the signed link of its connector file source (Q13).
|
|
40
|
+
*/
|
|
41
|
+
export declare const filePart: PayloadPluginPart;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GatewayKnowledgeRelation, GatewayPublicationState } from "@collective-intelligence/external-apps-server-sdk/gateway/contracts";
|
|
2
|
+
import type { ResourceDefinition, ResourceJsonValue } from "@collective-intelligence/external-apps-server-sdk/resources";
|
|
3
|
+
import type { SanitizedConfig } from "payload";
|
|
4
|
+
type JsonObject = Readonly<Record<string, ResourceJsonValue>>;
|
|
5
|
+
/** The manifest part of one exposed Payload Collection (ARC-003). */
|
|
6
|
+
export type PayloadKnowledgeResource = Readonly<{
|
|
7
|
+
definition: ResourceDefinition<JsonObject>;
|
|
8
|
+
/** Only for a collection with drafts (Q65). */
|
|
9
|
+
publicationState?: GatewayPublicationState;
|
|
10
|
+
relations: readonly GatewayKnowledgeRelation[];
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Turns the exposed Payload Collections of a site into the Knowledge
|
|
14
|
+
* resources of its Gateway manifest, from `configToJSONSchema` and each
|
|
15
|
+
* collection's flattened fields (Q53). A Payload global is never a resource
|
|
16
|
+
* (INV-001).
|
|
17
|
+
*/
|
|
18
|
+
export declare const payloadKnowledgeResources: (config: SanitizedConfig, slugs: readonly string[]) => readonly PayloadKnowledgeResource[];
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ComponentManifest, ComponentPresentation, DeclarationHandle, DeclaredComponent, JsonObject, KnowledgeConnectorInstanceDeclaration, KnowledgeConnectorInstanceEntityBinding, KnowledgeConnectorInstanceSchedule, KnowledgeEntitySchemaDeclaration, PackageDependency } from "@collective-intelligence/extensions-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* The Payload Declarations File that `payload ci-generate` writes from the
|
|
4
|
+
* site's Payload configuration, as JSON. A JSON import types each string as
|
|
5
|
+
* `string`, so the builder checks the field types and cardinalities.
|
|
6
|
+
*/
|
|
7
|
+
export type PayloadDeclarationsFile = Readonly<{
|
|
8
|
+
collections: Readonly<Record<string, Readonly<{
|
|
9
|
+
/** The schema fields; each reads the `remote` field: the field map. */
|
|
10
|
+
fields: Readonly<Record<string, Readonly<{
|
|
11
|
+
options?: readonly string[];
|
|
12
|
+
remote: string;
|
|
13
|
+
/** `boolean`, `number`, `string` or `string_select`. */
|
|
14
|
+
type: string;
|
|
15
|
+
}>>>;
|
|
16
|
+
label: string;
|
|
17
|
+
/** Each relation field and the collection whose items it names. */
|
|
18
|
+
relations: readonly Readonly<{
|
|
19
|
+
/** `one` or `many`. */
|
|
20
|
+
cardinality: string;
|
|
21
|
+
field: string;
|
|
22
|
+
target: string;
|
|
23
|
+
}>[];
|
|
24
|
+
/** The entity schema of the collection in the Gateway manifest (AC-121). */
|
|
25
|
+
schema: JsonObject;
|
|
26
|
+
}>>>;
|
|
27
|
+
}>;
|
|
28
|
+
export type PayloadKnowledgeInput<File extends PayloadDeclarationsFile, Collection extends Extract<keyof File["collections"], string> = Extract<keyof File["collections"], string>> = Readonly<{
|
|
29
|
+
/**
|
|
30
|
+
* The chosen collections, each with the package's binding choices (Q105).
|
|
31
|
+
* Leave a collection out to not choose it: each key gets a schema.
|
|
32
|
+
*/
|
|
33
|
+
collections: Readonly<Record<Collection, Readonly<Pick<KnowledgeConnectorInstanceEntityBinding, "draftImport" | "importExclusionRules">>>>;
|
|
34
|
+
domainFqn: string;
|
|
35
|
+
gateway: DeclarationHandle<"externalAppGateway">;
|
|
36
|
+
/** The connector instance; each schema FQN is `<fqn>.<collection>`. */
|
|
37
|
+
manifest: ComponentManifest;
|
|
38
|
+
presentation: ComponentPresentation;
|
|
39
|
+
/** Each schedule runs a full import of every chosen collection (Q18). */
|
|
40
|
+
schedules?: readonly Readonly<Pick<KnowledgeConnectorInstanceSchedule, "cronExpression" | "key">>[];
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* The declared Knowledge of the chosen collections: the schema of each, by
|
|
44
|
+
* collection name, and the connector instance; `components` lists them all.
|
|
45
|
+
*/
|
|
46
|
+
export type PayloadKnowledge<Collection extends string = string> = Readonly<{
|
|
47
|
+
components: readonly DeclaredComponent<KnowledgeConnectorInstanceDeclaration | KnowledgeEntitySchemaDeclaration>[];
|
|
48
|
+
connectorInstance: DeclaredComponent<KnowledgeConnectorInstanceDeclaration>;
|
|
49
|
+
schemas: Readonly<Record<Collection, DeclaredComponent<KnowledgeEntitySchemaDeclaration>>>;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* The package dependencies of a Payload Site's extension package: the
|
|
53
|
+
* connector instance runs on the Knowledge Gateway template of the External
|
|
54
|
+
* Apps package (Q17).
|
|
55
|
+
*/
|
|
56
|
+
export declare const payloadPackageDependencies: readonly PackageDependency[];
|
|
57
|
+
/**
|
|
58
|
+
* Declares the Knowledge of the chosen collections from the Payload
|
|
59
|
+
* Declarations File (Q99, Q105, Q17): a relation to a chosen collection fills
|
|
60
|
+
* a relation field through a `reference` rule; a relation to any other
|
|
61
|
+
* collection keeps its `<field>_title` text (Q117).
|
|
62
|
+
*/
|
|
63
|
+
export declare const payloadKnowledge: <const File extends PayloadDeclarationsFile, Collection extends Extract<keyof File["collections"], string>>(file: File, input: PayloadKnowledgeInput<File, Collection>) => PayloadKnowledge<Collection>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { OperationDomainDeclaration, PortableOperationDeclaration, PortableOperationGatewayContract } from "@collective-intelligence/extensions-sdk";
|
|
2
|
+
/** The six operations that every Payload Site serves (Q59, Q93). */
|
|
3
|
+
export type PayloadOperationId = "create" | "delete" | "publish" | "read" | "unpublish" | "update";
|
|
4
|
+
/** The Payload Operation Contract; its type keeps each operation id. */
|
|
5
|
+
export type PayloadOperationContract = Omit<PortableOperationGatewayContract, "operationDomains"> & Readonly<{
|
|
6
|
+
operationDomains: readonly OperationDomainDeclaration<PortableOperationDeclaration & Readonly<{
|
|
7
|
+
canonicalReference: string;
|
|
8
|
+
id: PayloadOperationId;
|
|
9
|
+
}>>[];
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* The fixed operation contract of every Payload Site: six operations, each
|
|
13
|
+
* with a plain-text `collection` input. Only an SDK upgrade changes it. An
|
|
14
|
+
* extension package passes it to one `declareExternalAppGateway` call.
|
|
15
|
+
*/
|
|
16
|
+
export declare const payloadOperationContract: PayloadOperationContract;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fields that Payload stamps; `_status` holds the Publication State. A
|
|
3
|
+
* Knowledge write never writes them (Q40): the site refuses them, and a
|
|
4
|
+
* package binding imports them only. This module imports nothing, so the
|
|
5
|
+
* Payload package entry stays free of Payload.
|
|
6
|
+
*/
|
|
7
|
+
export declare const stampedFields: ReadonlySet<string>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GatewayWriteActor } from "@collective-intelligence/external-apps-server-sdk/auth";
|
|
2
|
+
import type { RequestContext } from "payload";
|
|
3
|
+
import type { PayloadPluginPart } from "./parts.js";
|
|
4
|
+
/**
|
|
5
|
+
* The CI Editor field on each writable collection (Q79). It is stored on the
|
|
6
|
+
* Payload Document only: the Knowledge manifest leaves it out.
|
|
7
|
+
*/
|
|
8
|
+
export declare const editorField = "ciEditor";
|
|
9
|
+
/**
|
|
10
|
+
* The request context of a CI write: the CI user's name and email from the
|
|
11
|
+
* Write Actor. A CI write without a Write Actor has none.
|
|
12
|
+
*/
|
|
13
|
+
export declare const editorContext: (actor: GatewayWriteActor | undefined) => RequestContext;
|
|
14
|
+
/**
|
|
15
|
+
* Adds the CI Editor field to each writable collection: hidden in the edit
|
|
16
|
+
* view and read-only, but stored with each version, so version history shows
|
|
17
|
+
* the CI user of each CI write to the site's admin users (ARC-006, Q45). An
|
|
18
|
+
* API-hidden field would not show there.
|
|
19
|
+
*/
|
|
20
|
+
export declare const editorFieldPart: PayloadPluginPart;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Payload } from "payload";
|
|
2
|
+
import type { PayloadPluginSettings } from "./parts.js";
|
|
3
|
+
/**
|
|
4
|
+
* The Integration User, as the `user` of a Local API call or a request:
|
|
5
|
+
* each part reads and writes as this user, with the site's access rules on
|
|
6
|
+
* (Q45).
|
|
7
|
+
*/
|
|
8
|
+
export declare const readIntegrationUser: (payload: Payload, settings: PayloadPluginSettings) => Promise<{
|
|
9
|
+
collection: string;
|
|
10
|
+
id: number | string;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { ConfidentialCredentials } from "@collective-intelligence/external-apps-server-sdk";
|
|
2
|
+
import type { GatewayPackageEnrollmentConfig } from "@collective-intelligence/external-apps-server-sdk/auth";
|
|
3
|
+
import type { GatewayKernelConfig } from "@collective-intelligence/external-apps-server-sdk/gateway";
|
|
4
|
+
import type { GatewayKnowledgeResourceExposure, GatewayOperationHandler } from "@collective-intelligence/external-apps-server-sdk/gateway/contracts";
|
|
5
|
+
import type { ResourceJsonValue } from "@collective-intelligence/external-apps-server-sdk/resources";
|
|
6
|
+
import type { Config, Payload, PayloadTypes } from "payload";
|
|
7
|
+
import type { PayloadOperationId } from "../package/contract.js";
|
|
8
|
+
/** The Gateway path under the site's Payload API route (Q44). */
|
|
9
|
+
export declare const gatewayMountPath = "/ci-gateway";
|
|
10
|
+
/** A Payload Document as the Payload Plugin reads it. */
|
|
11
|
+
export type PayloadDocument = Readonly<Record<string, ResourceJsonValue>>;
|
|
12
|
+
/**
|
|
13
|
+
* CI trust: the Gateway URL that CI signs caller tokens for, the CI tenants
|
|
14
|
+
* that the site trusts, and how CI connects the site. A package Gateway names
|
|
15
|
+
* the packages that may enroll it. A Gateway that an administrator registers
|
|
16
|
+
* in the Dashboard has the setup credentials of its registration and the
|
|
17
|
+
* client credentials of the administrator's confidential External App, which
|
|
18
|
+
* its Push Job signs in with (Q31, AC-200). Without CI trust, the Gateway
|
|
19
|
+
* refuses every CI call.
|
|
20
|
+
*/
|
|
21
|
+
export type PayloadCiTrust = Omit<GatewayPackageEnrollmentConfig, "allowedPackages" | "store"> & Readonly<{
|
|
22
|
+
allowedPackages?: GatewayPackageEnrollmentConfig["allowedPackages"];
|
|
23
|
+
dashboard?: Readonly<{
|
|
24
|
+
app: ConfidentialCredentials;
|
|
25
|
+
setupCredentials: readonly string[];
|
|
26
|
+
}>;
|
|
27
|
+
}>;
|
|
28
|
+
/** The settings of one exposed Payload Collection. */
|
|
29
|
+
export type PayloadCollectionOptions = Readonly<{
|
|
30
|
+
/** Field paths that the Document Body skips (Q21). */
|
|
31
|
+
bodyExclude?: readonly string[];
|
|
32
|
+
/** The URL Rule: the Public URL of a document (Q22). */
|
|
33
|
+
urlRule: (document: PayloadDocument) => string;
|
|
34
|
+
/** The page-write operations can write the collection (Q59). */
|
|
35
|
+
writable?: boolean;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* The `ciPayloadPlugin` options. With the site's generated Payload types, the
|
|
39
|
+
* exposed collections accept only Payload Collection slugs, never a global
|
|
40
|
+
* (INV-001).
|
|
41
|
+
*/
|
|
42
|
+
export type CiPayloadPluginOptions<Types extends Pick<PayloadTypes, "collections"> = PayloadTypes> = Readonly<{
|
|
43
|
+
ci?: PayloadCiTrust;
|
|
44
|
+
collections: Readonly<Partial<Record<Extract<keyof Types["collections"], string>, PayloadCollectionOptions>>>;
|
|
45
|
+
/** The Integration User: the plugin reads and writes as this user, with the site's access rules on (Q45). */
|
|
46
|
+
integrationUser: Readonly<{
|
|
47
|
+
collection: Extract<keyof Types["collections"], string>;
|
|
48
|
+
id: number | string;
|
|
49
|
+
}>;
|
|
50
|
+
}>;
|
|
51
|
+
/** The plugin options as each part reads them. */
|
|
52
|
+
export type PayloadPluginSettings = Readonly<{
|
|
53
|
+
ci?: PayloadCiTrust;
|
|
54
|
+
collections: Readonly<Partial<Record<string, PayloadCollectionOptions>>>;
|
|
55
|
+
integrationUser: Readonly<{
|
|
56
|
+
collection: string;
|
|
57
|
+
id: number | string;
|
|
58
|
+
}>;
|
|
59
|
+
}>;
|
|
60
|
+
/** What one part serves through the Gateway of a running site. */
|
|
61
|
+
export type PayloadServing = Readonly<{
|
|
62
|
+
/** Checks CI callers and enrolls Gateway Connections. */
|
|
63
|
+
connection?: Partial<Pick<GatewayKernelConfig, "enrollConnection" | "enrollPackageConnection" | "verifyCaller" | "verifySetupCredential">>;
|
|
64
|
+
/** Adds the part's record handlers and capabilities to the Knowledge resource of one exposed collection. */
|
|
65
|
+
knowledge?: (exposure: GatewayKnowledgeResourceExposure) => GatewayKnowledgeResourceExposure;
|
|
66
|
+
/** Handlers of the Payload Operation Contract. */
|
|
67
|
+
operations?: Partial<Record<PayloadOperationId, GatewayOperationHandler>>;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* One part of the Payload Plugin. `plugin.ts` composes the parts, so each
|
|
71
|
+
* concern keeps its own module (Migration Ledger M1 to M7, M9).
|
|
72
|
+
*/
|
|
73
|
+
export type PayloadPluginPart = Readonly<{
|
|
74
|
+
/** Adds the part's collections, fields, hooks, jobs or `bin` scripts to the site configuration. */
|
|
75
|
+
config?: (config: Config, settings: PayloadPluginSettings) => Config;
|
|
76
|
+
/** Made once for each Payload instance, at the first Gateway request. */
|
|
77
|
+
serve?: (site: Readonly<{
|
|
78
|
+
payload: Payload;
|
|
79
|
+
settings: PayloadPluginSettings;
|
|
80
|
+
}>) => PayloadServing;
|
|
81
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ci-generate/declarations/entrypoints/ci-generate.js"
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{readFile,writeFile}from"node:fs/promises";import path from"node:path";import{parseArgs}from"node:util";var objectOf=(value)=>typeof value==="object"&&value!==null&&!Array.isArray(value)?Object.fromEntries(Object.entries(value)):undefined;import{configToJSONSchema}from"payload";import{fieldIsLocalized,hasDraftsEnabled}from"payload/shared";import*as Predicate from"effect/Predicate";var editorField="ciEditor";var gatewayMountPath="/ci-gateway";var linkLifetimeSeconds=60*60;var filesPath=`${gatewayMountPath}/files`;var fileSourceSchema={additionalProperties:false,description:"A stored file of the site. CI imports it only into a mapped Knowledge File field.",properties:{external_hash:{type:"string"},external_modified_at:{format:"date-time",type:"string"},filename:{type:"string"},source_id:{type:"string"},url:{format:"uri",type:"string"},url_expires_at:{format:"date-time",type:"string"}},required:["external_hash","external_modified_at","filename","source_id","url","url_expires_at"]};var uploadFieldSchema=(field)=>field.hasMany===true?{items:{...fileSourceSchema,type:"object"},type:"array"}:{...fileSourceSchema,type:["object","null"]};var publicationState={draftValue:"draft",field:"ciPublicationState"};var object=(value)=>{if(value===undefined||value===null||typeof value!=="object"||Array.isArray(value)){throw new TypeError("The Payload JSON schema is not an object")}return Object.fromEntries(Object.entries(value))};var definitionRef=/^#\/definitions\/(?<name>.+)$/u;var referencedDefinitions=(schema,definitions,found=new Map)=>{if(typeof schema!=="object"||schema===null){return found}const name="$ref"in schema?definitionRef.exec(String(schema.$ref))?.groups?.name:undefined;const definition=name===undefined?undefined:definitions[name];if(name!==undefined&&definition!==undefined&&!found.has(name)){found.set(name,definition);referencedDefinitions(definition,definitions,found)}for(const value of Object.values(schema)){referencedDefinitions(value,definitions,found)}return found};var withRelatedIds=(schema,collections)=>{if(Array.isArray(schema)){return schema.map((entry)=>withRelatedIds(entry,collections))}if(typeof schema!=="object"||schema===null){return schema}const{oneOf,...node}=Object.fromEntries(Object.entries(schema).map(([key,value])=>[key,withRelatedIds(value,collections)]));if(!Array.isArray(oneOf)){return oneOf===undefined?node:{...node,oneOf}}const ids=oneOf.filter((alternative)=>{const name=typeof alternative==="object"&&alternative!==null&&"$ref"in alternative?definitionRef.exec(String(alternative.$ref))?.groups?.name:undefined;return name===undefined||!collections.has(name)});if(ids.length===oneOf.length){return{...node,oneOf}}const[id]=ids;return ids.length===1&&id!==undefined?{...node,...object(id)}:{...node,oneOf:ids}};var payloadKnowledgeResources=(config,slugs)=>{const collectionOf=(slug)=>{const collection=config.collections.find((candidate)=>candidate.slug===slug);if(collection===undefined){throw new TypeError(`ciPayloadPlugin names "${slug}", which is not a Payload Collection of the site`)}return collection};const definitions=object(withRelatedIds(object(configToJSONSchema(config,config.db.defaultIDType)).definitions,new Set(config.collections.map(({slug})=>slug))));const locales=config.localization===false?[]:config.localization.localeCodes;const block=(reference)=>typeof reference==="string"?config.blocks?.find(({slug})=>slug===reference):reference;const hasLocalizedField=(fields)=>fields.some((field)=>fieldIsLocalized(field)||("flattenedFields"in field)&&hasLocalizedField(field.flattenedFields)||field.type==="blocks"&&[...field.blocks,...field.blockReferences??[]].some((reference)=>hasLocalizedField(block(reference)?.flattenedFields??[])));const identityFields=(collection)=>["id",...locales.length>0&&hasLocalizedField(collection.flattenedFields)?["ciLanguage"]:[],"ciPublicationState"];return slugs.map(collectionOf).map((collection)=>{const entity=object(definitions[collection.slug]);const payloadProperties=object(entity.properties);const kept=new Set(["id",...collection.flattenedFields.filter((field)=>field.hidden!==true&&field.name!==editorField).map(({name})=>name)]);const properties={};const add=(name,schema)=>{if(name in properties){throw new TypeError(`The field "${name}" of "${collection.slug}" has the name of a field that the Payload Plugin adds`)}properties[name]=schema};const relations=[];for(const[name,schema]of Object.entries(payloadProperties)){const field=collection.flattenedFields.find((candidate)=>candidate.name===name);if(field?.type==="relationship"){const{relationTo}=field;const polymorphic=Array.isArray(relationTo);const cardinality=field.hasMany===true?"many":"one";const nullable=polymorphic||field.required!==true;const text=(description)=>({description,type:nullable?["string","null"]:"string"});const identities=(description)=>cardinality==="many"?{description,items:{type:"string"},type:nullable?["array","null"]:"array"}:text(description);for(const target of Array.isArray(relationTo)?relationTo:[relationTo]){const relationField=polymorphic?`${name}_${target}`:name;add(relationField,identities(`Item Identity of a ${target} item.`));add(`${relationField}_title`,text(`Title of the related ${target} document.`));relations.push({cardinality,field:relationField,targetIdentityFields:identityFields(collectionOf(target)),targetResourceId:target})}}else if(field?.type==="upload"&&kept.has(name)){add(name,uploadFieldSchema(field))}else if(kept.has(name)){add(name,schema)}}const drafts=hasDraftsEnabled(collection);const[,...itemFields]=identityFields(collection);add("ciBody",{description:"Document Body: all visible text of the document as Markdown.",type:"string"});add("ciUrl",{description:"Public URL of the live page of the item.",type:"string"});add("ciPublicationState",{description:"Publication State of the item.",enum:drafts?["draft","published"]:["published"],type:"string"});if(itemFields.includes("ciLanguage")){add("ciLanguage",{description:"Locale of the item.",enum:locales,type:"string"})}const required=[...(Array.isArray(entity.required)?entity.required:[]).filter((name)=>(String(name)in properties)),...itemFields,"ciBody","ciUrl"];const definition={capabilities:{search:true},concurrency:"revision",id:collection.slug,identity:{fields:[{name:"id",type:object(payloadProperties.id).type==="number"?"number":"string"},...itemFields.map((name)=>({name,type:"string"}))]},query:{filterableFields:[],pagination:{modes:["cursor"]},sortableFields:[]},schemas:{entity:{...entity,definitions:Object.fromEntries(referencedDefinitions(properties,definitions)),properties,required}},version:"1"};return drafts?{definition,publicationState,relations}:{definition,relations}})};var customKey="ciPayloadPlugin";var fieldOf=(remote,value)=>{const schema=objectOf(value);const types=[schema?.type].flat().filter((type)=>type!=="null");if(types.length!==1){return}const[type]=types;if(type==="boolean"){return{remote,type}}if(type==="integer"||type==="number"){return{remote,type:"number"}}if(type!=="string"){return}const options=Array.isArray(schema?.enum)?schema.enum.flatMap((option)=>option===null?[]:[String(option)]):[];return options.length>0?{options,remote,type:"string_select"}:{remote,type}};var payloadDeclarations=(config)=>{const exposed=config.custom?.[customKey];if(!Array.isArray(exposed)){throw new TypeError("payload ci-generate needs ciPayloadPlugin in the plugins of the Payload configuration")}const resources=payloadKnowledgeResources(config,exposed.map(String));return{collections:Object.fromEntries(resources.map(({definition,relations})=>{const schema=definition.schemas.entity;const related=new Set(relations.flatMap(({field})=>[field,`${field}_title`]));const fields=Object.entries(objectOf(schema.properties)??{}).filter(([name])=>name!=="id"&&!related.has(name)).flatMap(([name,property])=>{const field=fieldOf(name,property);return field===undefined?[]:[[name,field]]});const label=config.collections.find(({slug})=>slug===definition.id)?.labels.singular;return[definition.id,{fields:Object.fromEntries(fields),label:typeof label==="string"?label:definition.id,relations:relations.map(({cardinality,field,targetResourceId})=>({cardinality,field,target:targetResourceId})),schema}]}))}};var script=async(config)=>{try{const{values}=parseArgs({allowPositionals:true,options:{check:{type:"boolean"},out:{type:"string"}}});const{out}=values;if(out===undefined){throw new TypeError("payload ci-generate needs --out <file>")}const declarations=payloadDeclarations(config);const file=path.resolve(out);if(values.check===true){const current=await readFile(file,"utf-8").then((text)=>JSON.stringify(JSON.parse(text))===JSON.stringify(declarations)).catch(()=>false);if(!current){throw new Error(`${out} is out of date: run payload ci-generate --out ${out}`)}console.log(`${out} is up to date`);return}await writeFile(file,`${JSON.stringify(declarations,null,2)}
|
|
2
|
+
`);console.log(`payload ci-generate wrote ${out}`)}catch(error){console.error(error instanceof Error?error.message:error);process.exit(1)}};export{script};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SanitizedConfig } from "payload";
|
|
2
|
+
import type { PayloadPluginPart } from "../plugin/parts.js";
|
|
3
|
+
/**
|
|
4
|
+
* The `payload ci-generate --out <file> [--check]` bin script (Q104): it
|
|
5
|
+
* writes the Payload Declarations File, or with `--check` fails when the
|
|
6
|
+
* file is out of date.
|
|
7
|
+
*/
|
|
8
|
+
export declare const script: (config: SanitizedConfig) => Promise<void>;
|
|
9
|
+
/** Adds the `payload ci-generate` bin script to the site configuration (ARC-003). */
|
|
10
|
+
export declare const generatePart: PayloadPluginPart;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Payload Plugin of the Payload SDK for Payload Sites. Add
|
|
3
|
+
* `ciPayloadPlugin` to the `plugins` of `payload.config` (Q43, Q75).
|
|
4
|
+
*/
|
|
5
|
+
export { ciPayloadPlugin } from "../plugin/plugin.js";
|
|
6
|
+
export type { CiPayloadPluginOptions, PayloadCollectionOptions, PayloadDocument } from "../plugin/parts.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ResourceJsonValue } from "@collective-intelligence/external-apps-server-sdk/resources";
|
|
2
|
+
import type { FlattenedBlocksField, FlattenedField, SanitizedCollectionConfig, SanitizedConfig } from "payload";
|
|
3
|
+
import type { PayloadDocument } from "../plugin/parts.js";
|
|
4
|
+
/** The fields of one group, named tab, array row or block, with their data. */
|
|
5
|
+
export type Subfields = Readonly<{
|
|
6
|
+
data: PayloadDocument;
|
|
7
|
+
fields: readonly FlattenedField[];
|
|
8
|
+
/** The field path segment: `<field>`, or `<field>.<block slug>` for a block. */
|
|
9
|
+
path: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const objectOf: (value: ResourceJsonValue | undefined) => PayloadDocument | undefined;
|
|
12
|
+
/** The block of one row of a blocks field: the block of the row's `blockType`. */
|
|
13
|
+
export declare const blockOf: (config: SanitizedConfig, field: FlattenedBlocksField, row: PayloadDocument) => import("payload").FlattenedBlock | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The subfields of a group, named tab, array or blocks field, in field and
|
|
16
|
+
* row order, each with the data that it reads in the field's value.
|
|
17
|
+
*/
|
|
18
|
+
export declare const subfields: (config: SanitizedConfig, field: FlattenedField, value: ResourceJsonValue | undefined) => readonly Subfields[];
|
|
19
|
+
/**
|
|
20
|
+
* The Document Body of a document: all its visible text in field order, as
|
|
21
|
+
* one Markdown text (Q10). The collection's title field is the top heading;
|
|
22
|
+
* rich text keeps its headings and lists. A field with `admin.hidden`, and
|
|
23
|
+
* each field path that the developer skips, stay out (Q21). A field path
|
|
24
|
+
* names the fields from the document root, with the block slug after a
|
|
25
|
+
* blocks field: `meta.description`, `layout.hero.heading`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const documentBody: ({ collection, config, document, skip }: Readonly<{
|
|
28
|
+
collection: SanitizedCollectionConfig;
|
|
29
|
+
config: SanitizedConfig;
|
|
30
|
+
document: PayloadDocument;
|
|
31
|
+
skip?: readonly string[] | undefined;
|
|
32
|
+
}>) => string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ResourceJsonValue } from "@collective-intelligence/external-apps-server-sdk/resources";
|
|
2
|
+
import type { FlattenedField, Payload, UploadField } from "payload";
|
|
3
|
+
import type { PayloadDocument, PayloadPluginPart } from "../plugin/parts.js";
|
|
4
|
+
/** A stored file of an upload collection. */
|
|
5
|
+
type StoredFile = Readonly<{
|
|
6
|
+
collection: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** The signed link of a connector file source, and when it stops serving the file. */
|
|
10
|
+
type FileLink = Readonly<{
|
|
11
|
+
url: string;
|
|
12
|
+
url_expires_at: string;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Signs links of the file route under `gatewayUrl`, the Gateway URL that CI
|
|
16
|
+
* calls: a link names one stored file and serves it until it expires.
|
|
17
|
+
*/
|
|
18
|
+
export declare const fileLinker: (payload: Payload, gatewayUrl: string) => (file: StoredFile) => FileLink;
|
|
19
|
+
/** An upload field names files of upload collections. */
|
|
20
|
+
export declare const isUploadField: (field: FlattenedField) => field is UploadField;
|
|
21
|
+
/**
|
|
22
|
+
* The manifest schema of an upload field: a connector file source, or null
|
|
23
|
+
* for no readable file, or a list of sources for a has-many field (Q13).
|
|
24
|
+
*/
|
|
25
|
+
export declare const uploadFieldSchema: (field: UploadField) => ResourceJsonValue;
|
|
26
|
+
/**
|
|
27
|
+
* The upload fields of a document as connector file sources, by field name:
|
|
28
|
+
* one source or null, or a list for a has-many field. `linked` adds to each
|
|
29
|
+
* source the signed link of the file route; `revision` has no links, because
|
|
30
|
+
* a link changes with each read and its file does not. Without a Gateway URL
|
|
31
|
+
* (no CI trust) no field holds a file.
|
|
32
|
+
*/
|
|
33
|
+
export declare const documentFiles: (fields: readonly UploadField[], doc: PayloadDocument, link: ((file: StoredFile) => FileLink) | undefined) => {
|
|
34
|
+
linked: Readonly<Record<string, ResourceJsonValue>>;
|
|
35
|
+
revision: Readonly<Record<string, ResourceJsonValue>>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The file route (ARC-004): CI downloads the file of a mapped Knowledge File
|
|
39
|
+
* field from the signed link of its connector file source (Q13).
|
|
40
|
+
*/
|
|
41
|
+
export declare const filePart: PayloadPluginPart;
|
|
42
|
+
export {};
|