@aglyn/plugins-data 1.0.0-beta.218 → 1.0.0-beta.220
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/README.md +1 -1
- package/package.json +11 -9
- package/src/lib/constants/bundle-common.d.ts +8 -0
- package/src/lib/constants/bundle-common.js +6 -0
- package/src/lib/constants/bundle-common.js.map +1 -1
- package/src/lib/declarations.console-server.d.ts +47 -0
- package/src/lib/declarations.console-server.js +74 -0
- package/src/lib/declarations.console-server.js.map +1 -0
- package/src/lib/declarations.server.d.ts +43 -0
- package/src/lib/declarations.server.js +73 -0
- package/src/lib/declarations.server.js.map +1 -0
- package/src/lib/form-target/dataset-form-record-target.server.d.ts +40 -0
- package/src/lib/form-target/dataset-form-record-target.server.js +160 -0
- package/src/lib/form-target/dataset-form-record-target.server.js.map +1 -0
- package/src/lib/form-target/form-dataset-binding-token.d.ts +35 -0
- package/src/lib/form-target/form-dataset-binding-token.js +107 -0
- package/src/lib/form-target/form-dataset-binding-token.js.map +1 -0
- package/src/lib/form-target/form-dataset-binding.d.ts +50 -0
- package/src/lib/form-target/form-dataset-binding.js +74 -0
- package/src/lib/form-target/form-dataset-binding.js.map +1 -0
- package/src/lib/form-target/stamp-form-dataset-bindings.d.ts +39 -0
- package/src/lib/form-target/stamp-form-dataset-bindings.js +65 -0
- package/src/lib/form-target/stamp-form-dataset-bindings.js.map +1 -0
- package/src/lib/model/dataset-csv.d.ts +36 -0
- package/src/lib/model/dataset-csv.js +85 -0
- package/src/lib/model/dataset-csv.js.map +1 -0
- package/src/lib/model/dataset-io.d.ts +8 -7
- package/src/lib/model/dataset-io.js +9 -8
- package/src/lib/model/dataset-io.js.map +1 -1
- package/src/lib/model/dataset-record-list.d.ts +40 -0
- package/src/lib/model/dataset-record-list.js +61 -0
- package/src/lib/model/dataset-record-list.js.map +1 -0
- package/src/lib/model/dataset-record.d.ts +33 -0
- package/src/lib/model/dataset-record.js +68 -0
- package/src/lib/model/dataset-record.js.map +1 -0
- package/src/lib/plugin.js +3 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/repeat/dataset-repeat-rows.d.ts +2 -2
- package/src/lib/repeat/dataset-repeat-rows.js +2 -2
- package/src/lib/repeat/dataset-repeat-rows.js.map +1 -1
- package/src/lib/repeat/dataset-repeat-rows.server.d.ts +43 -0
- package/src/lib/repeat/dataset-repeat-rows.server.js +170 -0
- package/src/lib/repeat/dataset-repeat-rows.server.js.map +1 -0
- package/src/lib/repeat/dataset-repeat-source.js +3 -1
- package/src/lib/repeat/dataset-repeat-source.js.map +1 -1
- package/src/lib/server/announce-dataset-records.d.ts +37 -0
- package/src/lib/server/announce-dataset-records.js +54 -0
- package/src/lib/server/announce-dataset-records.js.map +1 -0
- package/src/lib/server/api-v1/datasets.d.ts +18 -0
- package/src/lib/server/api-v1/datasets.js +646 -0
- package/src/lib/server/api-v1/datasets.js.map +1 -0
- package/src/lib/server/api-v1/openapi.d.ts +26 -0
- package/src/lib/server/api-v1/openapi.js +260 -0
- package/src/lib/server/api-v1/openapi.js.map +1 -0
- package/src/lib/server/api-v1/usage.d.ts +26 -0
- package/src/lib/server/api-v1/usage.js +33 -0
- package/src/lib/server/api-v1/usage.js.map +1 -0
- package/src/lib/server/custom-field-types.d.ts +39 -0
- package/src/lib/server/custom-field-types.js +41 -0
- package/src/lib/server/custom-field-types.js.map +1 -0
- package/src/lib/server/dataset-figures.d.ts +61 -0
- package/src/lib/server/dataset-figures.js +413 -0
- package/src/lib/server/dataset-figures.js.map +1 -0
- package/src/lib/server/dataset-record-index.d.ts +18 -0
- package/src/lib/server/dataset-record-index.js +62 -0
- package/src/lib/server/dataset-record-index.js.map +1 -0
- package/src/lib/server/dataset-storage-meter.d.ts +29 -0
- package/src/lib/server/dataset-storage-meter.js +82 -0
- package/src/lib/server/dataset-storage-meter.js.map +1 -0
- package/src/lib/server/datasets-export-route.d.ts +57 -0
- package/src/lib/server/datasets-export-route.js +229 -0
- package/src/lib/server/datasets-export-route.js.map +1 -0
- package/src/lib/server/datasets-route.d.ts +38 -0
- package/src/lib/server/datasets-route.js +614 -0
- package/src/lib/server/datasets-route.js.map +1 -0
- package/src/lib/server.d.ts +23 -0
- package/src/lib/server.js +54 -0
- package/src/lib/server.js.map +1 -0
- package/src/lib/site-bundle/datasets-site-bundle.server.d.ts +87 -0
- package/src/lib/site-bundle/datasets-site-bundle.server.js +184 -0
- package/src/lib/site-bundle/datasets-site-bundle.server.js.map +1 -0
- package/src/lib/usage-axes.d.ts +24 -0
- package/src/lib/usage-axes.js +32 -0
- package/src/lib/usage-axes.js.map +1 -0
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ The plugin is console-only and declares one registrar, `registerDataConsole` (th
|
|
|
32
32
|
|
|
33
33
|
| import | contents |
|
|
34
34
|
| -- | -- |
|
|
35
|
-
| `@aglyn/plugins-data` | `BUNDLE_ID`, `registerDataConsole`, `HostDatasetsCard`, and the import/export model: `parseImportRows`, `mapImportColumns`,
|
|
35
|
+
| `@aglyn/plugins-data` | `BUNDLE_ID`, `registerDataConsole`, `HostDatasetsCard`, and the import/export model: `parseImportRows`, `mapImportColumns`, the dataset CSV/JSON writers (`datasetRecordsToCsv`, `datasetCsvHeader`, `datasetCsvRow`, `datasetRecordToJson`, `serializeDatasetValue`), and the platform's CSV helpers re-exported from the core (`parseCsv`, `countCsvDataRows`, `exportShortfall`) |
|
|
36
36
|
| `@aglyn/plugins-data/*` | any module under `src/lib/`, for example `@aglyn/plugins-data/model/dataset-record-view` (`datasetRecordFields`, `describeDatasetValue`) |
|
|
37
37
|
|
|
38
38
|
## Usage
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-data",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.220",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,19 +25,21 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.0.0-beta.
|
|
29
|
-
"@aglyn/shared-data-mdi": "1.0.0-beta.
|
|
30
|
-
"@aglyn/shared-ui-jsx": "1.0.0-beta.
|
|
31
|
-
"@aglyn/shared-ui-snackstack": "1.0.0-beta.
|
|
32
|
-
"@aglyn/shared-util-http": "1.0.0-beta.
|
|
33
|
-
"@aglyn/shared-util-timestamp": "1.0.0-beta.
|
|
34
|
-
"@aglyn/tenant-
|
|
35
|
-
"@aglyn/tenant-
|
|
28
|
+
"@aglyn/aglyn": "1.0.0-beta.220",
|
|
29
|
+
"@aglyn/shared-data-mdi": "1.0.0-beta.220",
|
|
30
|
+
"@aglyn/shared-ui-jsx": "1.0.0-beta.220",
|
|
31
|
+
"@aglyn/shared-ui-snackstack": "1.0.0-beta.220",
|
|
32
|
+
"@aglyn/shared-util-http": "1.0.0-beta.220",
|
|
33
|
+
"@aglyn/shared-util-timestamp": "1.0.0-beta.220",
|
|
34
|
+
"@aglyn/tenant-data-admin": "1.0.0-beta.220",
|
|
35
|
+
"@aglyn/tenant-feature-instance": "1.0.0-beta.220",
|
|
36
|
+
"@aglyn/tenant-runtime": "1.0.0-beta.220",
|
|
36
37
|
"@swc/helpers": "0.5.23"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
39
40
|
"@mui/material": "^9.3.1",
|
|
40
41
|
"firebase": "^12.18.0",
|
|
42
|
+
"firebase-admin": "^14.3.0",
|
|
41
43
|
"react": "^19.2.8"
|
|
42
44
|
},
|
|
43
45
|
"sideEffects": false,
|
|
@@ -6,3 +6,11 @@
|
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
7
7
|
*/
|
|
8
8
|
export declare const BUNDLE_ID = "data";
|
|
9
|
+
/**
|
|
10
|
+
* The id datasets are a repeat source under — the editor's source
|
|
11
|
+
* (`repeat-sources.ts`) and the published page's reader (`repeat-rows.ts`)
|
|
12
|
+
* alike, and the `repeatSource` this plugin declares in `plugins.config.json`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DATASET_REPEAT_SOURCE_ID = "dataset";
|
|
15
|
+
/** The dataset storage meter in the monthly usage sweep (`server/dataset-storage-meter.ts`). */
|
|
16
|
+
export declare const DATASET_STORAGE_METER_ID = "dataset-storage";
|
|
@@ -5,5 +5,11 @@
|
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
7
7
|
*/ export const BUNDLE_ID = 'data';
|
|
8
|
+
/**
|
|
9
|
+
* The id datasets are a repeat source under — the editor's source
|
|
10
|
+
* (`repeat-sources.ts`) and the published page's reader (`repeat-rows.ts`)
|
|
11
|
+
* alike, and the `repeatSource` this plugin declares in `plugins.config.json`.
|
|
12
|
+
*/ export const DATASET_REPEAT_SOURCE_ID = 'dataset';
|
|
13
|
+
/** The dataset storage meter in the monthly usage sweep (`server/dataset-storage-meter.ts`). */ export const DATASET_STORAGE_METER_ID = 'dataset-storage';
|
|
8
14
|
|
|
9
15
|
//# sourceMappingURL=bundle-common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/constants/bundle-common.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n */\n\nexport const BUNDLE_ID = 'data'\n"],"names":["BUNDLE_ID"],"mappings":"AAAA;;;;;;CAMC,GAED,OAAO,MAAMA,YAAY,OAAM"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/constants/bundle-common.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n */\n\nexport const BUNDLE_ID = 'data'\n\n/**\n * The id datasets are a repeat source under — the editor's source\n * (`repeat-sources.ts`) and the published page's reader (`repeat-rows.ts`)\n * alike, and the `repeatSource` this plugin declares in `plugins.config.json`.\n */\nexport const DATASET_REPEAT_SOURCE_ID = 'dataset'\n\n/** The dataset storage meter in the monthly usage sweep (`server/dataset-storage-meter.ts`). */\nexport const DATASET_STORAGE_METER_ID = 'dataset-storage'\n"],"names":["BUNDLE_ID","DATASET_REPEAT_SOURCE_ID","DATASET_STORAGE_METER_ID"],"mappings":"AAAA;;;;;;CAMC,GAED,OAAO,MAAMA,YAAY,OAAM;AAE/B;;;;CAIC,GACD,OAAO,MAAMC,2BAA2B,UAAS;AAEjD,8FAA8F,GAC9F,OAAO,MAAMC,2BAA2B,kBAAiB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The data plugin's CONSOLE-ONLY server declarations, named under
|
|
19
|
+
* `consoleServerDeclarations` in `plugins.config.json` and run at the
|
|
20
|
+
* console's boot. Everything here is the console's alone, so the tenant
|
|
21
|
+
* runtime does not register any of it.
|
|
22
|
+
*
|
|
23
|
+
* It serves the organization's datasets on the customer REST API,
|
|
24
|
+
* `/v1/datasets/…`: the console's router owns the pipeline in front — the
|
|
25
|
+
* key, the plan's API access, the quota, the rate limit, the error envelope —
|
|
26
|
+
* and hands every request under `/v1/datasets` here once the key is
|
|
27
|
+
* authenticated. No plan feature is named on the registration: the handler
|
|
28
|
+
* answers reads on every plan and refuses a create the plan does not carry
|
|
29
|
+
* (`dataStore`) with its own sentence, as it always has. The resource brings
|
|
30
|
+
* its description for the API's OpenAPI document, and the datasets band
|
|
31
|
+
* joins `GET /v1/usage`.
|
|
32
|
+
*
|
|
33
|
+
* And another plugin that works over the workspace's datasets — an AI job
|
|
34
|
+
* naming a dataset in an automation, a planner listing what a site already
|
|
35
|
+
* has, an insight summarizing a dataset's fields — runs on the console's
|
|
36
|
+
* server, and reads them here rather than from the datasets collection:
|
|
37
|
+
* through the `dataset` record index, and through the dataset figure readers
|
|
38
|
+
* an insight asks.
|
|
39
|
+
*
|
|
40
|
+
* Light at boot: the API handler is imported with its first request, the
|
|
41
|
+
* description when the document is first built, the usage reader with the
|
|
42
|
+
* first usage call and the index's reader with its first read; the figure
|
|
43
|
+
* readers reach Firestore only when one is asked. Registering again replaces
|
|
44
|
+
* this plugin's own entries, so a second call (a hot reload, a spec) is
|
|
45
|
+
* harmless.
|
|
46
|
+
*/
|
|
47
|
+
export declare function registerDataConsoleServerDeclarations(): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ // The registries' own modules, not the data layer's or the plugin-manager's
|
|
17
|
+
// barrel: boot needs these registries, not the whole server surface or the
|
|
18
|
+
// console's client contexts.
|
|
19
|
+
import { registerPluginRecordIndex } from "@aglyn/aglyn/plugin-manager/plugin-record-index";
|
|
20
|
+
import { registerApiV1Resource, registerApiV1UsageFigures } from "@aglyn/tenant-data-admin/server/api-v1-resources";
|
|
21
|
+
import { firebaseAdmin } from "@aglyn/tenant-data-admin/server/firebase-admin";
|
|
22
|
+
import { BUNDLE_ID } from "./constants/bundle-common.js";
|
|
23
|
+
import { registerDatasetFigureReaders } from "./server/dataset-figures.js";
|
|
24
|
+
/**
|
|
25
|
+
* The data plugin's CONSOLE-ONLY server declarations, named under
|
|
26
|
+
* `consoleServerDeclarations` in `plugins.config.json` and run at the
|
|
27
|
+
* console's boot. Everything here is the console's alone, so the tenant
|
|
28
|
+
* runtime does not register any of it.
|
|
29
|
+
*
|
|
30
|
+
* It serves the organization's datasets on the customer REST API,
|
|
31
|
+
* `/v1/datasets/…`: the console's router owns the pipeline in front — the
|
|
32
|
+
* key, the plan's API access, the quota, the rate limit, the error envelope —
|
|
33
|
+
* and hands every request under `/v1/datasets` here once the key is
|
|
34
|
+
* authenticated. No plan feature is named on the registration: the handler
|
|
35
|
+
* answers reads on every plan and refuses a create the plan does not carry
|
|
36
|
+
* (`dataStore`) with its own sentence, as it always has. The resource brings
|
|
37
|
+
* its description for the API's OpenAPI document, and the datasets band
|
|
38
|
+
* joins `GET /v1/usage`.
|
|
39
|
+
*
|
|
40
|
+
* And another plugin that works over the workspace's datasets — an AI job
|
|
41
|
+
* naming a dataset in an automation, a planner listing what a site already
|
|
42
|
+
* has, an insight summarizing a dataset's fields — runs on the console's
|
|
43
|
+
* server, and reads them here rather than from the datasets collection:
|
|
44
|
+
* through the `dataset` record index, and through the dataset figure readers
|
|
45
|
+
* an insight asks.
|
|
46
|
+
*
|
|
47
|
+
* Light at boot: the API handler is imported with its first request, the
|
|
48
|
+
* description when the document is first built, the usage reader with the
|
|
49
|
+
* first usage call and the index's reader with its first read; the figure
|
|
50
|
+
* readers reach Firestore only when one is asked. Registering again replaces
|
|
51
|
+
* this plugin's own entries, so a second call (a hot reload, a spec) is
|
|
52
|
+
* harmless.
|
|
53
|
+
*/ export function registerDataConsoleServerDeclarations() {
|
|
54
|
+
registerApiV1Resource('datasets', {
|
|
55
|
+
handle: async (...args)=>(await import("./server/api-v1/datasets.js")).handleDatasets(...args),
|
|
56
|
+
describe: async ()=>(await import("./server/api-v1/openapi.js")).DATASETS_API_V1_DESCRIPTION
|
|
57
|
+
}, {
|
|
58
|
+
pluginId: BUNDLE_ID
|
|
59
|
+
});
|
|
60
|
+
registerApiV1UsageFigures(async (ctx)=>(await import("./server/api-v1/usage.js")).datasetUsageFigures(ctx), {
|
|
61
|
+
pluginId: BUNDLE_ID
|
|
62
|
+
});
|
|
63
|
+
registerPluginRecordIndex('dataset', lazyDatasetIndex, {
|
|
64
|
+
pluginId: BUNDLE_ID
|
|
65
|
+
});
|
|
66
|
+
registerDatasetFigureReaders(()=>firebaseAdmin.app().firestore());
|
|
67
|
+
}
|
|
68
|
+
const loadDatasetIndex = async ()=>(await import("./server/dataset-record-index.js")).datasetRecordIndex;
|
|
69
|
+
const lazyDatasetIndex = {
|
|
70
|
+
list: async (request)=>(await loadDatasetIndex()).list(request),
|
|
71
|
+
get: async (request)=>(await loadDatasetIndex()).get(request)
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=declarations.console-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/plugins/data/src/lib/declarations.console-server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// The registries' own modules, not the data layer's or the plugin-manager's\n// barrel: boot needs these registries, not the whole server surface or the\n// console's client contexts.\nimport {\n registerPluginRecordIndex,\n type PluginRecordIndex,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-index'\nimport {\n registerApiV1Resource,\n registerApiV1UsageFigures,\n} from '@aglyn/tenant-data-admin/server/api-v1-resources'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport { BUNDLE_ID } from './constants/bundle-common'\nimport { registerDatasetFigureReaders } from './server/dataset-figures'\n\n/**\n * The data plugin's CONSOLE-ONLY server declarations, named under\n * `consoleServerDeclarations` in `plugins.config.json` and run at the\n * console's boot. Everything here is the console's alone, so the tenant\n * runtime does not register any of it.\n *\n * It serves the organization's datasets on the customer REST API,\n * `/v1/datasets/…`: the console's router owns the pipeline in front — the\n * key, the plan's API access, the quota, the rate limit, the error envelope —\n * and hands every request under `/v1/datasets` here once the key is\n * authenticated. No plan feature is named on the registration: the handler\n * answers reads on every plan and refuses a create the plan does not carry\n * (`dataStore`) with its own sentence, as it always has. The resource brings\n * its description for the API's OpenAPI document, and the datasets band\n * joins `GET /v1/usage`.\n *\n * And another plugin that works over the workspace's datasets — an AI job\n * naming a dataset in an automation, a planner listing what a site already\n * has, an insight summarizing a dataset's fields — runs on the console's\n * server, and reads them here rather than from the datasets collection:\n * through the `dataset` record index, and through the dataset figure readers\n * an insight asks.\n *\n * Light at boot: the API handler is imported with its first request, the\n * description when the document is first built, the usage reader with the\n * first usage call and the index's reader with its first read; the figure\n * readers reach Firestore only when one is asked. Registering again replaces\n * this plugin's own entries, so a second call (a hot reload, a spec) is\n * harmless.\n */\nexport function registerDataConsoleServerDeclarations(): void {\n registerApiV1Resource(\n 'datasets',\n {\n handle: async (...args) =>\n (await import('./server/api-v1/datasets')).handleDatasets(...args),\n describe: async () =>\n (await import('./server/api-v1/openapi')).DATASETS_API_V1_DESCRIPTION,\n },\n { pluginId: BUNDLE_ID },\n )\n registerApiV1UsageFigures(\n async (ctx) => (await import('./server/api-v1/usage')).datasetUsageFigures(ctx),\n { pluginId: BUNDLE_ID },\n )\n registerPluginRecordIndex('dataset', lazyDatasetIndex, { pluginId: BUNDLE_ID })\n registerDatasetFigureReaders(() => firebaseAdmin.app().firestore())\n}\n\nconst loadDatasetIndex = async () => (await import('./server/dataset-record-index')).datasetRecordIndex\n\nconst lazyDatasetIndex: PluginRecordIndex = {\n list: async (request) => (await loadDatasetIndex()).list(request),\n get: async (request) => (await loadDatasetIndex()).get(request),\n}\n"],"names":["registerPluginRecordIndex","registerApiV1Resource","registerApiV1UsageFigures","firebaseAdmin","BUNDLE_ID","registerDatasetFigureReaders","registerDataConsoleServerDeclarations","handle","args","handleDatasets","describe","DATASETS_API_V1_DESCRIPTION","pluginId","ctx","datasetUsageFigures","lazyDatasetIndex","app","firestore","loadDatasetIndex","datasetRecordIndex","list","request","get"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,4EAA4E;AAC5E,2EAA2E;AAC3E,6BAA6B;AAC7B,SACEA,yBAAyB,QAEpB,kDAAiD;AACxD,SACEC,qBAAqB,EACrBC,yBAAyB,QACpB,mDAAkD;AACzD,SAASC,aAAa,QAAQ,iDAAgD;AAC9E,SAASC,SAAS,QAAQ,+BAA2B;AACrD,SAASC,4BAA4B,QAAQ,8BAA0B;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BC,GACD,OAAO,SAASC;IACdL,sBACE,YACA;QACEM,QAAQ,OAAO,GAAGC,OAChB,AAAC,CAAA,MAAM,MAAM,CAAC,8BAA0B,EAAGC,cAAc,IAAID;QAC/DE,UAAU,UACR,AAAC,CAAA,MAAM,MAAM,CAAC,6BAAyB,EAAGC,2BAA2B;IACzE,GACA;QAAEC,UAAUR;IAAU;IAExBF,0BACE,OAAOW,MAAQ,AAAC,CAAA,MAAM,MAAM,CAAC,2BAAuB,EAAGC,mBAAmB,CAACD,MAC3E;QAAED,UAAUR;IAAU;IAExBJ,0BAA0B,WAAWe,kBAAkB;QAAEH,UAAUR;IAAU;IAC7EC,6BAA6B,IAAMF,cAAca,GAAG,GAAGC,SAAS;AAClE;AAEA,MAAMC,mBAAmB,UAAY,AAAC,CAAA,MAAM,MAAM,CAAC,mCAA+B,EAAGC,kBAAkB;AAEvG,MAAMJ,mBAAsC;IAC1CK,MAAM,OAAOC,UAAY,AAAC,CAAA,MAAMH,kBAAiB,EAAGE,IAAI,CAACC;IACzDC,KAAK,OAAOD,UAAY,AAAC,CAAA,MAAMH,kBAAiB,EAAGI,GAAG,CAACD;AACzD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The data plugin's server declarations: the light registrations core reads
|
|
19
|
+
* at boot, before any surface loads.
|
|
20
|
+
*
|
|
21
|
+
* A published page that repeats an element over a dataset asks the platform
|
|
22
|
+
* for the rows, and this is who answers — in every process that composes a
|
|
23
|
+
* page, the tenant's and the console's previews alike. The reader, and the
|
|
24
|
+
* Admin SDK with it, loads on the first page that repeats, not at boot.
|
|
25
|
+
* `plugins.config.json` declares the same source (`repeatSource`), so a boot
|
|
26
|
+
* that skipped this is refused rather than rendered as "no rows".
|
|
27
|
+
*
|
|
28
|
+
* A form can also file every submission as a dataset record, and this is the
|
|
29
|
+
* target that stamps such a form with its signed binding when a page renders
|
|
30
|
+
* and writes the record when the submission comes back. Declared the same way
|
|
31
|
+
* (`formRecordTarget`), and just as light: both halves load on first use.
|
|
32
|
+
*
|
|
33
|
+
* A site's datasets are also its section of the whole-site backup: the
|
|
34
|
+
* console's export and restore ask this plugin for them. Declared too
|
|
35
|
+
* (`siteBundleSections`), so a boot that skipped this fails the export rather
|
|
36
|
+
* than shipping a backup without them; the answers load when a backup is made
|
|
37
|
+
* or restored.
|
|
38
|
+
*
|
|
39
|
+
* And the monthly usage sweep, a core cron, measures what the datasets store
|
|
40
|
+
* through this plugin's meter — declared in `usageAxes`, so the sweep refuses
|
|
41
|
+
* to bill a month without it. Its reads load with the first sweep.
|
|
42
|
+
*/
|
|
43
|
+
export declare function registerDataServerDeclarations(): void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ // The seam from its own module, not the plugin-manager barrel: boot needs the
|
|
17
|
+
// registry and nothing else, and the barrel reaches the client contexts.
|
|
18
|
+
import { registerFormRecordTarget } from "@aglyn/aglyn/plugin-manager/submission-record-target";
|
|
19
|
+
import { registerRepeatRowReader } from "@aglyn/aglyn/plugin-manager/repeat-rows";
|
|
20
|
+
import { registerPluginSiteBundleSection } from "@aglyn/aglyn/plugin-manager/plugin-site-bundle";
|
|
21
|
+
import { registerPluginUsageMeter } from "@aglyn/aglyn/plugin-manager/plugin-usage-meters";
|
|
22
|
+
import { BUNDLE_ID, DATASET_REPEAT_SOURCE_ID, DATASET_STORAGE_METER_ID } from "./constants/bundle-common.js";
|
|
23
|
+
/**
|
|
24
|
+
* The data plugin's server declarations: the light registrations core reads
|
|
25
|
+
* at boot, before any surface loads.
|
|
26
|
+
*
|
|
27
|
+
* A published page that repeats an element over a dataset asks the platform
|
|
28
|
+
* for the rows, and this is who answers — in every process that composes a
|
|
29
|
+
* page, the tenant's and the console's previews alike. The reader, and the
|
|
30
|
+
* Admin SDK with it, loads on the first page that repeats, not at boot.
|
|
31
|
+
* `plugins.config.json` declares the same source (`repeatSource`), so a boot
|
|
32
|
+
* that skipped this is refused rather than rendered as "no rows".
|
|
33
|
+
*
|
|
34
|
+
* A form can also file every submission as a dataset record, and this is the
|
|
35
|
+
* target that stamps such a form with its signed binding when a page renders
|
|
36
|
+
* and writes the record when the submission comes back. Declared the same way
|
|
37
|
+
* (`formRecordTarget`), and just as light: both halves load on first use.
|
|
38
|
+
*
|
|
39
|
+
* A site's datasets are also its section of the whole-site backup: the
|
|
40
|
+
* console's export and restore ask this plugin for them. Declared too
|
|
41
|
+
* (`siteBundleSections`), so a boot that skipped this fails the export rather
|
|
42
|
+
* than shipping a backup without them; the answers load when a backup is made
|
|
43
|
+
* or restored.
|
|
44
|
+
*
|
|
45
|
+
* And the monthly usage sweep, a core cron, measures what the datasets store
|
|
46
|
+
* through this plugin's meter — declared in `usageAxes`, so the sweep refuses
|
|
47
|
+
* to bill a month without it. Its reads load with the first sweep.
|
|
48
|
+
*/ export function registerDataServerDeclarations() {
|
|
49
|
+
registerRepeatRowReader(DATASET_REPEAT_SOURCE_ID, async (request)=>(await import("./repeat/dataset-repeat-rows.server.js")).readPublishedDatasetRows(request), {
|
|
50
|
+
pluginId: BUNDLE_ID
|
|
51
|
+
});
|
|
52
|
+
registerFormRecordTarget({
|
|
53
|
+
stamp: async (nodes, hostId)=>(await import("./form-target/stamp-form-dataset-bindings.js")).stampFormDatasetBindings(nodes, hostId),
|
|
54
|
+
write: async (request)=>(await import("./form-target/dataset-form-record-target.server.js")).writeFormSubmissionRecord(request)
|
|
55
|
+
}, {
|
|
56
|
+
pluginId: BUNDLE_ID
|
|
57
|
+
});
|
|
58
|
+
const datasets = ()=>import("./site-bundle/datasets-site-bundle.server.js");
|
|
59
|
+
registerPluginSiteBundleSection('datasets', {
|
|
60
|
+
export: async (request)=>(await datasets()).exportSiteDatasets(request),
|
|
61
|
+
refusal: async (request)=>(await datasets()).siteDatasetsRefusal(request),
|
|
62
|
+
import: async (request)=>(await datasets()).importSiteDatasets(request)
|
|
63
|
+
}, {
|
|
64
|
+
pluginId: BUNDLE_ID
|
|
65
|
+
});
|
|
66
|
+
registerPluginUsageMeter({
|
|
67
|
+
pluginId: BUNDLE_ID,
|
|
68
|
+
id: DATASET_STORAGE_METER_ID,
|
|
69
|
+
measure: async (context)=>(await import("./server/dataset-storage-meter.js")).measureDatasetStorage(context)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=declarations.server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/plugins/data/src/lib/declarations.server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// The seam from its own module, not the plugin-manager barrel: boot needs the\n// registry and nothing else, and the barrel reaches the client contexts.\nimport { registerFormRecordTarget } from '@aglyn/aglyn/plugin-manager/submission-record-target'\nimport { registerRepeatRowReader } from '@aglyn/aglyn/plugin-manager/repeat-rows'\nimport { registerPluginSiteBundleSection } from '@aglyn/aglyn/plugin-manager/plugin-site-bundle'\nimport { registerPluginUsageMeter } from '@aglyn/aglyn/plugin-manager/plugin-usage-meters'\nimport {\n BUNDLE_ID,\n DATASET_REPEAT_SOURCE_ID,\n DATASET_STORAGE_METER_ID,\n} from './constants/bundle-common'\n\n/**\n * The data plugin's server declarations: the light registrations core reads\n * at boot, before any surface loads.\n *\n * A published page that repeats an element over a dataset asks the platform\n * for the rows, and this is who answers — in every process that composes a\n * page, the tenant's and the console's previews alike. The reader, and the\n * Admin SDK with it, loads on the first page that repeats, not at boot.\n * `plugins.config.json` declares the same source (`repeatSource`), so a boot\n * that skipped this is refused rather than rendered as \"no rows\".\n *\n * A form can also file every submission as a dataset record, and this is the\n * target that stamps such a form with its signed binding when a page renders\n * and writes the record when the submission comes back. Declared the same way\n * (`formRecordTarget`), and just as light: both halves load on first use.\n *\n * A site's datasets are also its section of the whole-site backup: the\n * console's export and restore ask this plugin for them. Declared too\n * (`siteBundleSections`), so a boot that skipped this fails the export rather\n * than shipping a backup without them; the answers load when a backup is made\n * or restored.\n *\n * And the monthly usage sweep, a core cron, measures what the datasets store\n * through this plugin's meter — declared in `usageAxes`, so the sweep refuses\n * to bill a month without it. Its reads load with the first sweep.\n */\nexport function registerDataServerDeclarations(): void {\n registerRepeatRowReader(\n DATASET_REPEAT_SOURCE_ID,\n async (request) =>\n (await import('./repeat/dataset-repeat-rows.server')).readPublishedDatasetRows(\n request,\n ),\n { pluginId: BUNDLE_ID },\n )\n registerFormRecordTarget(\n {\n stamp: async (nodes, hostId) =>\n (await import('./form-target/stamp-form-dataset-bindings')).stampFormDatasetBindings(\n nodes,\n hostId,\n ),\n write: async (request) =>\n (await import('./form-target/dataset-form-record-target.server')).writeFormSubmissionRecord(\n request,\n ),\n },\n { pluginId: BUNDLE_ID },\n )\n const datasets = () => import('./site-bundle/datasets-site-bundle.server')\n registerPluginSiteBundleSection(\n 'datasets',\n {\n export: async (request) => (await datasets()).exportSiteDatasets(request),\n refusal: async (request) => (await datasets()).siteDatasetsRefusal(request),\n import: async (request) => (await datasets()).importSiteDatasets(request),\n },\n { pluginId: BUNDLE_ID },\n )\n registerPluginUsageMeter({\n pluginId: BUNDLE_ID,\n id: DATASET_STORAGE_METER_ID,\n measure: async (context) =>\n (await import('./server/dataset-storage-meter')).measureDatasetStorage(context),\n })\n}\n"],"names":["registerFormRecordTarget","registerRepeatRowReader","registerPluginSiteBundleSection","registerPluginUsageMeter","BUNDLE_ID","DATASET_REPEAT_SOURCE_ID","DATASET_STORAGE_METER_ID","registerDataServerDeclarations","request","readPublishedDatasetRows","pluginId","stamp","nodes","hostId","stampFormDatasetBindings","write","writeFormSubmissionRecord","datasets","export","exportSiteDatasets","refusal","siteDatasetsRefusal","import","importSiteDatasets","id","measure","context","measureDatasetStorage"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,8EAA8E;AAC9E,yEAAyE;AACzE,SAASA,wBAAwB,QAAQ,uDAAsD;AAC/F,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,+BAA+B,QAAQ,iDAAgD;AAChG,SAASC,wBAAwB,QAAQ,kDAAiD;AAC1F,SACEC,SAAS,EACTC,wBAAwB,EACxBC,wBAAwB,QACnB,+BAA2B;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,SAASC;IACdN,wBACEI,0BACA,OAAOG,UACL,AAAC,CAAA,MAAM,MAAM,CAAC,yCAAqC,EAAGC,wBAAwB,CAC5ED,UAEJ;QAAEE,UAAUN;IAAU;IAExBJ,yBACE;QACEW,OAAO,OAAOC,OAAOC,SACnB,AAAC,CAAA,MAAM,MAAM,CAAC,+CAA2C,EAAGC,wBAAwB,CAClFF,OACAC;QAEJE,OAAO,OAAOP,UACZ,AAAC,CAAA,MAAM,MAAM,CAAC,qDAAiD,EAAGQ,yBAAyB,CACzFR;IAEN,GACA;QAAEE,UAAUN;IAAU;IAExB,MAAMa,WAAW,IAAM,MAAM,CAAC;IAC9Bf,gCACE,YACA;QACEgB,QAAQ,OAAOV,UAAY,AAAC,CAAA,MAAMS,UAAS,EAAGE,kBAAkB,CAACX;QACjEY,SAAS,OAAOZ,UAAY,AAAC,CAAA,MAAMS,UAAS,EAAGI,mBAAmB,CAACb;QACnEc,QAAQ,OAAOd,UAAY,AAAC,CAAA,MAAMS,UAAS,EAAGM,kBAAkB,CAACf;IACnE,GACA;QAAEE,UAAUN;IAAU;IAExBD,yBAAyB;QACvBO,UAAUN;QACVoB,IAAIlB;QACJmB,SAAS,OAAOC,UACd,AAAC,CAAA,MAAM,MAAM,CAAC,oCAAgC,EAAGC,qBAAqB,CAACD;IAC3E;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { FormRecordWriteOutcome, FormRecordWriteRequest } from '@aglyn/aglyn/plugin-manager/submission-record-target';
|
|
18
|
+
/**
|
|
19
|
+
* THE DATASET A SUBMISSION ALSO WRITES A RECORD TO (AGL-141/556), decided on
|
|
20
|
+
* the server — this plugin's answer to the platform's contract
|
|
21
|
+
* (`plugin-manager/submission-record-target.ts`), asked by the submit route
|
|
22
|
+
* after the submission itself is stored.
|
|
23
|
+
*
|
|
24
|
+
* The body is public and unauthenticated, so nothing in it may choose where a
|
|
25
|
+
* record lands: a dataset id or field map taken from it let anyone add rows to
|
|
26
|
+
* any dataset the site can see and send any submitted value into any of its
|
|
27
|
+
* fields. The binding is the one the page's compose read off this form and
|
|
28
|
+
* signed (`stampFormDatasetBindings`): for this site only, and exactly what the
|
|
29
|
+
* form's own props and fields declare, so a form writes where it always wrote.
|
|
30
|
+
* Without a valid signature there is no record. The Inbox copy is canonical
|
|
31
|
+
* either way.
|
|
32
|
+
*
|
|
33
|
+
* What it answers is the submission's `routing`: `dataset` — where the record
|
|
34
|
+
* went — or `datasetRefused` — which values the dataset could not hold. Both
|
|
35
|
+
* are read by the Inbox.
|
|
36
|
+
*
|
|
37
|
+
* Best-effort: a missing dataset or a full record quota never fails the
|
|
38
|
+
* submission, and never claims a row that was not written.
|
|
39
|
+
*/
|
|
40
|
+
export declare function writeFormSubmissionRecord(request: FormRecordWriteRequest): Promise<FormRecordWriteOutcome>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ import { checkQuota, datasetIntegrityFields, effectiveDatasetModel, ensureDeclaredCustomFieldTypes, prepareDatasetRecordWrite } from "@aglyn/aglyn/server";
|
|
18
|
+
import { dataStorageRefusal, firebaseAdmin, orgDataCollectionForHost } from "@aglyn/tenant-data-admin";
|
|
19
|
+
import { announceDatasetRecordChange } from "@aglyn/tenant-data-admin/server/dataset-live-pages";
|
|
20
|
+
import { resolveDatasetDoc } from "@aglyn/tenant-runtime/resolve-dataset";
|
|
21
|
+
import { FieldValue } from "firebase-admin/firestore";
|
|
22
|
+
import { verifyFormDatasetBinding } from "./form-dataset-binding-token.js";
|
|
23
|
+
import { FORM_DATASET_BINDING_FIELD } from "./stamp-form-dataset-bindings.js";
|
|
24
|
+
/**
|
|
25
|
+
* THE DATASET A SUBMISSION ALSO WRITES A RECORD TO (AGL-141/556), decided on
|
|
26
|
+
* the server — this plugin's answer to the platform's contract
|
|
27
|
+
* (`plugin-manager/submission-record-target.ts`), asked by the submit route
|
|
28
|
+
* after the submission itself is stored.
|
|
29
|
+
*
|
|
30
|
+
* The body is public and unauthenticated, so nothing in it may choose where a
|
|
31
|
+
* record lands: a dataset id or field map taken from it let anyone add rows to
|
|
32
|
+
* any dataset the site can see and send any submitted value into any of its
|
|
33
|
+
* fields. The binding is the one the page's compose read off this form and
|
|
34
|
+
* signed (`stampFormDatasetBindings`): for this site only, and exactly what the
|
|
35
|
+
* form's own props and fields declare, so a form writes where it always wrote.
|
|
36
|
+
* Without a valid signature there is no record. The Inbox copy is canonical
|
|
37
|
+
* either way.
|
|
38
|
+
*
|
|
39
|
+
* What it answers is the submission's `routing`: `dataset` — where the record
|
|
40
|
+
* went — or `datasetRefused` — which values the dataset could not hold. Both
|
|
41
|
+
* are read by the Inbox.
|
|
42
|
+
*
|
|
43
|
+
* Best-effort: a missing dataset or a full record quota never fails the
|
|
44
|
+
* submission, and never claims a row that was not written.
|
|
45
|
+
*/ export async function writeFormSubmissionRecord(request) {
|
|
46
|
+
const { hostId, orgId, fields } = request;
|
|
47
|
+
const orgBilling = request.orgBilling;
|
|
48
|
+
const binding = verifyFormDatasetBinding(hostId, request.body[FORM_DATASET_BINDING_FIELD]);
|
|
49
|
+
if (!binding) return {};
|
|
50
|
+
try {
|
|
51
|
+
var _ref, _ref1, _datasetDoc_get;
|
|
52
|
+
const firestore = firebaseAdmin.app().firestore();
|
|
53
|
+
// Org-scoped datasets (AGL-237): the form's dataset resolves against the
|
|
54
|
+
// org so every host shares it.
|
|
55
|
+
const datasetsRef = await orgDataCollectionForHost(hostId, 'datasets');
|
|
56
|
+
const datasetDoc = await resolveDatasetDoc(datasetsRef, {
|
|
57
|
+
datasetId: binding.datasetId,
|
|
58
|
+
datasetName: binding.datasetName
|
|
59
|
+
}, hostId);
|
|
60
|
+
if (!(datasetDoc == null ? void 0 : datasetDoc.exists) || datasetDoc.get('deletedAt')) return {};
|
|
61
|
+
const bound = {
|
|
62
|
+
model: datasetDoc.get('model'),
|
|
63
|
+
fields: Array.isArray(datasetDoc.get('fields')) ? datasetDoc.get('fields') : []
|
|
64
|
+
};
|
|
65
|
+
const boundModel = effectiveDatasetModel(bound);
|
|
66
|
+
// `displayName` first, then the legacy `name`, then the name the form was
|
|
67
|
+
// bound by — the same precedence `findDatasetByName` resolves in. Reading
|
|
68
|
+
// only `name` would leave every modern dataset's chip unnamed.
|
|
69
|
+
const datasetLabel = String((_ref = (_ref1 = (_datasetDoc_get = datasetDoc.get('displayName')) != null ? _datasetDoc_get : datasetDoc.get('name')) != null ? _ref1 : binding.datasetName) != null ? _ref : '').slice(0, 60);
|
|
70
|
+
/*
|
|
71
|
+
* CHECKED AGAINST THE MODEL (AGL-2773, option B). Each value is coerced to
|
|
72
|
+
* its field's type and held to the field's rules, the same pair the
|
|
73
|
+
* console and `/v1` run, custom field types included — so a plugin's
|
|
74
|
+
* validator has to be registered first.
|
|
75
|
+
*
|
|
76
|
+
* A refused record is not written, and the submission is kept: the Inbox
|
|
77
|
+
* copy is the visitor's, and a value the dataset cannot hold is no reason
|
|
78
|
+
* to lose it. The refusal is noted on the submission, per field, so the
|
|
79
|
+
* Inbox can say why the row is missing instead of leaving the owner to
|
|
80
|
+
* guess.
|
|
81
|
+
*/ await ensureDeclaredCustomFieldTypes(boundModel);
|
|
82
|
+
const write = prepareDatasetRecordWrite(bound, fields, {
|
|
83
|
+
fieldMap: binding.fieldMap
|
|
84
|
+
});
|
|
85
|
+
if (Object.keys(write.errors).length) {
|
|
86
|
+
return {
|
|
87
|
+
routing: {
|
|
88
|
+
datasetRefused: {
|
|
89
|
+
id: datasetDoc.id,
|
|
90
|
+
name: datasetLabel,
|
|
91
|
+
errors: write.errors
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const values = write.values;
|
|
97
|
+
if (!Object.keys(values).length) return {};
|
|
98
|
+
const recordCount = (await datasetDoc.ref.collection('records').count().get()).data().count;
|
|
99
|
+
if (!checkQuota(orgBilling, 'recordsPerDataset', recordCount).allowed) {
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
102
|
+
/*
|
|
103
|
+
* BYTES, not just rows (AGL-2253). This leg checked `recordsPerDataset`
|
|
104
|
+
* and never `dataStorageMbPerOrg`, so a public form wired to a dataset
|
|
105
|
+
* wrote past a byte band the console route hard-blocks at — the one
|
|
106
|
+
* dataset-writing path a visitor can drive without an account, and
|
|
107
|
+
* therefore the one where the volume is not the customer's to control.
|
|
108
|
+
*
|
|
109
|
+
* Costs nothing on a metered plan: `dataStorageRefusal` answers `null`
|
|
110
|
+
* with no read whenever the plan carries an `extraDataGbMonthlyUsd` rate,
|
|
111
|
+
* which is every plan that sells the data store. The read is paid only on
|
|
112
|
+
* the two unmetered shapes.
|
|
113
|
+
*
|
|
114
|
+
* Refused like the row quota above — the submission still lands in the
|
|
115
|
+
* Inbox, and `routing.dataset` is not stamped. A lost lead is the worse
|
|
116
|
+
* error here.
|
|
117
|
+
*/ if (orgId && await dataStorageRefusal(orgBilling, firestore.collection('orgs').doc(orgId))) {
|
|
118
|
+
return {};
|
|
119
|
+
}
|
|
120
|
+
const recordRef = await datasetDoc.ref.collection('records').add(_extends({
|
|
121
|
+
values
|
|
122
|
+
}, datasetIntegrityFields(boundModel, values), {
|
|
123
|
+
createdAt: FieldValue.serverTimestamp()
|
|
124
|
+
}));
|
|
125
|
+
/*
|
|
126
|
+
* The pages repeating over the dataset are refreshed (AGL-3113).
|
|
127
|
+
*
|
|
128
|
+
* This is the path the Datasets page's own claim rests on — bind an
|
|
129
|
+
* element to a dataset, publish, and a record written later shows within
|
|
130
|
+
* seconds. Best effort: a refusal from the cache must never turn a stored
|
|
131
|
+
* lead into a lost one.
|
|
132
|
+
*/ if (orgId) {
|
|
133
|
+
await announceDatasetRecordChange({
|
|
134
|
+
firestore,
|
|
135
|
+
orgId,
|
|
136
|
+
datasetId: datasetDoc.id
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/*
|
|
140
|
+
* Provenance (AGL-2168). `/product/forms`'s hero mockup shows the detail
|
|
141
|
+
* pane carrying `Added to "Leads" dataset` under the fields, so the record
|
|
142
|
+
* is named on the submission — only on this path, where a record was
|
|
143
|
+
* really created. A chip claiming a row that a deleted dataset or a full
|
|
144
|
+
* quota refused would be worse than the silence it replaced.
|
|
145
|
+
*/ return {
|
|
146
|
+
routing: {
|
|
147
|
+
dataset: {
|
|
148
|
+
id: datasetDoc.id,
|
|
149
|
+
name: datasetLabel,
|
|
150
|
+
recordId: recordRef.id
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
} catch (error) {
|
|
155
|
+
console.error('form dataset append failed', error);
|
|
156
|
+
return {};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
//# sourceMappingURL=dataset-form-record-target.server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/form-target/dataset-form-record-target.server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n checkQuota,\n datasetIntegrityFields,\n effectiveDatasetModel,\n ensureDeclaredCustomFieldTypes,\n prepareDatasetRecordWrite,\n} from '@aglyn/aglyn/server'\nimport type {\n FormRecordWriteOutcome,\n FormRecordWriteRequest,\n} from '@aglyn/aglyn/plugin-manager/submission-record-target'\nimport {\n dataStorageRefusal,\n firebaseAdmin,\n orgDataCollectionForHost,\n} from '@aglyn/tenant-data-admin'\nimport { announceDatasetRecordChange } from '@aglyn/tenant-data-admin/server/dataset-live-pages'\nimport { resolveDatasetDoc } from '@aglyn/tenant-runtime/resolve-dataset'\nimport { FieldValue } from 'firebase-admin/firestore'\nimport { verifyFormDatasetBinding } from './form-dataset-binding-token'\nimport { FORM_DATASET_BINDING_FIELD } from './stamp-form-dataset-bindings'\n\n/**\n * THE DATASET A SUBMISSION ALSO WRITES A RECORD TO (AGL-141/556), decided on\n * the server — this plugin's answer to the platform's contract\n * (`plugin-manager/submission-record-target.ts`), asked by the submit route\n * after the submission itself is stored.\n *\n * The body is public and unauthenticated, so nothing in it may choose where a\n * record lands: a dataset id or field map taken from it let anyone add rows to\n * any dataset the site can see and send any submitted value into any of its\n * fields. The binding is the one the page's compose read off this form and\n * signed (`stampFormDatasetBindings`): for this site only, and exactly what the\n * form's own props and fields declare, so a form writes where it always wrote.\n * Without a valid signature there is no record. The Inbox copy is canonical\n * either way.\n *\n * What it answers is the submission's `routing`: `dataset` — where the record\n * went — or `datasetRefused` — which values the dataset could not hold. Both\n * are read by the Inbox.\n *\n * Best-effort: a missing dataset or a full record quota never fails the\n * submission, and never claims a row that was not written.\n */\nexport async function writeFormSubmissionRecord(\n request: FormRecordWriteRequest,\n): Promise<FormRecordWriteOutcome> {\n const { hostId, orgId, fields } = request\n const orgBilling = request.orgBilling as Record<string, unknown> | undefined\n const binding = verifyFormDatasetBinding(\n hostId,\n request.body[FORM_DATASET_BINDING_FIELD],\n )\n if (!binding) return {}\n try {\n const firestore = firebaseAdmin.app().firestore()\n // Org-scoped datasets (AGL-237): the form's dataset resolves against the\n // org so every host shares it.\n const datasetsRef = await orgDataCollectionForHost(hostId, 'datasets')\n const datasetDoc = await resolveDatasetDoc(\n datasetsRef,\n { datasetId: binding.datasetId, datasetName: binding.datasetName },\n hostId,\n )\n if (!datasetDoc?.exists || datasetDoc.get('deletedAt')) return {}\n const bound = {\n model: datasetDoc.get('model'),\n fields: Array.isArray(datasetDoc.get('fields'))\n ? datasetDoc.get('fields')\n : [],\n }\n const boundModel = effectiveDatasetModel(bound)\n // `displayName` first, then the legacy `name`, then the name the form was\n // bound by — the same precedence `findDatasetByName` resolves in. Reading\n // only `name` would leave every modern dataset's chip unnamed.\n const datasetLabel = String(\n datasetDoc.get('displayName') ??\n datasetDoc.get('name') ??\n binding.datasetName ??\n '',\n ).slice(0, 60)\n /*\n * CHECKED AGAINST THE MODEL (AGL-2773, option B). Each value is coerced to\n * its field's type and held to the field's rules, the same pair the\n * console and `/v1` run, custom field types included — so a plugin's\n * validator has to be registered first.\n *\n * A refused record is not written, and the submission is kept: the Inbox\n * copy is the visitor's, and a value the dataset cannot hold is no reason\n * to lose it. The refusal is noted on the submission, per field, so the\n * Inbox can say why the row is missing instead of leaving the owner to\n * guess.\n */\n await ensureDeclaredCustomFieldTypes(boundModel)\n const write = prepareDatasetRecordWrite(bound, fields, {\n fieldMap: binding.fieldMap,\n })\n if (Object.keys(write.errors).length) {\n return {\n routing: {\n datasetRefused: {\n id: datasetDoc.id,\n name: datasetLabel,\n errors: write.errors,\n },\n },\n }\n }\n const values = write.values\n if (!Object.keys(values).length) return {}\n const recordCount = (\n await datasetDoc.ref.collection('records').count().get()\n ).data().count\n if (\n !checkQuota(orgBilling as never, 'recordsPerDataset', recordCount).allowed\n ) {\n return {}\n }\n /*\n * BYTES, not just rows (AGL-2253). This leg checked `recordsPerDataset`\n * and never `dataStorageMbPerOrg`, so a public form wired to a dataset\n * wrote past a byte band the console route hard-blocks at — the one\n * dataset-writing path a visitor can drive without an account, and\n * therefore the one where the volume is not the customer's to control.\n *\n * Costs nothing on a metered plan: `dataStorageRefusal` answers `null`\n * with no read whenever the plan carries an `extraDataGbMonthlyUsd` rate,\n * which is every plan that sells the data store. The read is paid only on\n * the two unmetered shapes.\n *\n * Refused like the row quota above — the submission still lands in the\n * Inbox, and `routing.dataset` is not stamped. A lost lead is the worse\n * error here.\n */\n if (\n orgId &&\n (await dataStorageRefusal(\n orgBilling as never,\n firestore.collection('orgs').doc(orgId),\n ))\n ) {\n return {}\n }\n const recordRef = await datasetDoc.ref.collection('records').add({\n values,\n // The integrity index the console's delete check queries. A submission\n // can land in a reference field through a bound form, so this leg\n // carries it like every other write that sets `values`.\n ...datasetIntegrityFields(boundModel, values),\n createdAt: FieldValue.serverTimestamp(),\n })\n /*\n * The pages repeating over the dataset are refreshed (AGL-3113).\n *\n * This is the path the Datasets page's own claim rests on — bind an\n * element to a dataset, publish, and a record written later shows within\n * seconds. Best effort: a refusal from the cache must never turn a stored\n * lead into a lost one.\n */\n if (orgId) {\n await announceDatasetRecordChange({\n firestore,\n orgId,\n datasetId: datasetDoc.id,\n })\n }\n /*\n * Provenance (AGL-2168). `/product/forms`'s hero mockup shows the detail\n * pane carrying `Added to \"Leads\" dataset` under the fields, so the record\n * is named on the submission — only on this path, where a record was\n * really created. A chip claiming a row that a deleted dataset or a full\n * quota refused would be worse than the silence it replaced.\n */\n return {\n routing: {\n dataset: {\n id: datasetDoc.id,\n name: datasetLabel,\n recordId: recordRef.id,\n },\n },\n }\n } catch (error) {\n console.error('form dataset append failed', error)\n return {}\n }\n}\n"],"names":["checkQuota","datasetIntegrityFields","effectiveDatasetModel","ensureDeclaredCustomFieldTypes","prepareDatasetRecordWrite","dataStorageRefusal","firebaseAdmin","orgDataCollectionForHost","announceDatasetRecordChange","resolveDatasetDoc","FieldValue","verifyFormDatasetBinding","FORM_DATASET_BINDING_FIELD","writeFormSubmissionRecord","request","hostId","orgId","fields","orgBilling","binding","body","datasetDoc","firestore","app","datasetsRef","datasetId","datasetName","exists","get","bound","model","Array","isArray","boundModel","datasetLabel","String","slice","write","fieldMap","Object","keys","errors","length","routing","datasetRefused","id","name","values","recordCount","ref","collection","count","data","allowed","doc","recordRef","add","createdAt","serverTimestamp","dataset","recordId","error","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,UAAU,EACVC,sBAAsB,EACtBC,qBAAqB,EACrBC,8BAA8B,EAC9BC,yBAAyB,QACpB,sBAAqB;AAK5B,SACEC,kBAAkB,EAClBC,aAAa,EACbC,wBAAwB,QACnB,2BAA0B;AACjC,SAASC,2BAA2B,QAAQ,qDAAoD;AAChG,SAASC,iBAAiB,QAAQ,wCAAuC;AACzE,SAASC,UAAU,QAAQ,2BAA0B;AACrD,SAASC,wBAAwB,QAAQ,kCAA8B;AACvE,SAASC,0BAA0B,QAAQ,mCAA+B;AAE1E;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,eAAeC,0BACpBC,OAA+B;IAE/B,MAAM,EAAEC,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAGH;IAClC,MAAMI,aAAaJ,QAAQI,UAAU;IACrC,MAAMC,UAAUR,yBACdI,QACAD,QAAQM,IAAI,CAACR,2BAA2B;IAE1C,IAAI,CAACO,SAAS,OAAO,CAAC;IACtB,IAAI;YAsBAE,MAAAA,OAAAA;QArBF,MAAMC,YAAYhB,cAAciB,GAAG,GAAGD,SAAS;QAC/C,yEAAyE;QACzE,+BAA+B;QAC/B,MAAME,cAAc,MAAMjB,yBAAyBQ,QAAQ;QAC3D,MAAMM,aAAa,MAAMZ,kBACvBe,aACA;YAAEC,WAAWN,QAAQM,SAAS;YAAEC,aAAaP,QAAQO,WAAW;QAAC,GACjEX;QAEF,IAAI,EAACM,8BAAAA,WAAYM,MAAM,KAAIN,WAAWO,GAAG,CAAC,cAAc,OAAO,CAAC;QAChE,MAAMC,QAAQ;YACZC,OAAOT,WAAWO,GAAG,CAAC;YACtBX,QAAQc,MAAMC,OAAO,CAACX,WAAWO,GAAG,CAAC,aACjCP,WAAWO,GAAG,CAAC,YACf,EAAE;QACR;QACA,MAAMK,aAAa/B,sBAAsB2B;QACzC,0EAA0E;QAC1E,0EAA0E;QAC1E,+DAA+D;QAC/D,MAAMK,eAAeC,QACnBd,QAAAA,SAAAA,kBAAAA,WAAWO,GAAG,CAAC,0BAAfP,kBACEA,WAAWO,GAAG,CAAC,mBADjBP,QAEEF,QAAQO,WAAW,YAFrBL,OAGE,IACFe,KAAK,CAAC,GAAG;QACX;;;;;;;;;;;KAWC,GACD,MAAMjC,+BAA+B8B;QACrC,MAAMI,QAAQjC,0BAA0ByB,OAAOZ,QAAQ;YACrDqB,UAAUnB,QAAQmB,QAAQ;QAC5B;QACA,IAAIC,OAAOC,IAAI,CAACH,MAAMI,MAAM,EAAEC,MAAM,EAAE;YACpC,OAAO;gBACLC,SAAS;oBACPC,gBAAgB;wBACdC,IAAIxB,WAAWwB,EAAE;wBACjBC,MAAMZ;wBACNO,QAAQJ,MAAMI,MAAM;oBACtB;gBACF;YACF;QACF;QACA,MAAMM,SAASV,MAAMU,MAAM;QAC3B,IAAI,CAACR,OAAOC,IAAI,CAACO,QAAQL,MAAM,EAAE,OAAO,CAAC;QACzC,MAAMM,cAAc,AAClB,CAAA,MAAM3B,WAAW4B,GAAG,CAACC,UAAU,CAAC,WAAWC,KAAK,GAAGvB,GAAG,EAAC,EACvDwB,IAAI,GAAGD,KAAK;QACd,IACE,CAACnD,WAAWkB,YAAqB,qBAAqB8B,aAAaK,OAAO,EAC1E;YACA,OAAO,CAAC;QACV;QACA;;;;;;;;;;;;;;;KAeC,GACD,IACErC,SACC,MAAMX,mBACLa,YACAI,UAAU4B,UAAU,CAAC,QAAQI,GAAG,CAACtC,SAEnC;YACA,OAAO,CAAC;QACV;QACA,MAAMuC,YAAY,MAAMlC,WAAW4B,GAAG,CAACC,UAAU,CAAC,WAAWM,GAAG,CAAC;YAC/DT;WAIG9C,uBAAuBgC,YAAYc;YACtCU,WAAW/C,WAAWgD,eAAe;;QAEvC;;;;;;;KAOC,GACD,IAAI1C,OAAO;YACT,MAAMR,4BAA4B;gBAChCc;gBACAN;gBACAS,WAAWJ,WAAWwB,EAAE;YAC1B;QACF;QACA;;;;;;KAMC,GACD,OAAO;YACLF,SAAS;gBACPgB,SAAS;oBACPd,IAAIxB,WAAWwB,EAAE;oBACjBC,MAAMZ;oBACN0B,UAAUL,UAAUV,EAAE;gBACxB;YACF;QACF;IACF,EAAE,OAAOgB,OAAO;QACdC,QAAQD,KAAK,CAAC,8BAA8BA;QAC5C,OAAO,CAAC;IACV;AACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { FormDatasetBinding } from './form-dataset-binding';
|
|
18
|
+
/**
|
|
19
|
+
* The token a page carries for one form's binding on one site.
|
|
20
|
+
*
|
|
21
|
+
* Throws when `TOKEN_SIGNING_SECRET` is not configured, like every token this
|
|
22
|
+
* secret signs; a caller that renders a page decides what an unsigned form
|
|
23
|
+
* does.
|
|
24
|
+
*/
|
|
25
|
+
export declare function signFormDatasetBinding(hostId: string, binding: FormDatasetBinding): string;
|
|
26
|
+
/**
|
|
27
|
+
* The binding a token carries, or null when it is not a valid token for
|
|
28
|
+
* `hostId`.
|
|
29
|
+
*
|
|
30
|
+
* Null for anything else at all — not a string, oversized, another version, a
|
|
31
|
+
* signature that does not match, a site other than this one, or no signing
|
|
32
|
+
* secret — because the only safe reading of a binding that cannot be verified
|
|
33
|
+
* is that there is none.
|
|
34
|
+
*/
|
|
35
|
+
export declare function verifyFormDatasetBinding(hostId: string, token: unknown): FormDatasetBinding | null;
|