@wix/agent-skills 1.24.0 → 1.26.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/README.md +1 -0
- package/package.json +2 -1
- package/skills/wix-app/SKILL.md +16 -14
- package/skills/wix-app/references/BUSINESS_MANAGER_THEME.md +107 -0
- package/skills/wix-app/references/BUSINESS_MANAGER_TOKENS.md +81 -0
- package/skills/wix-app/references/DASHBOARD_MODAL.md +41 -0
- package/skills/wix-app/references/DASHBOARD_PAGE.md +13 -11
- package/skills/wix-app/references/DASHBOARD_PLUGIN.md +19 -4
- package/skills/wix-app/references/WIX_PATTERNS_DOCS.md +3 -2
- package/skills/wix-app/references/dashboard-page/DRAFT_TEMPLATE.md +66 -68
- package/skills/wix-app/references/dashboard-page/DYNAMIC_PARAMETERS.md +21 -38
- package/skills/wix-app/references/data-collection/LIFECYCLE.md +6 -4
- package/skills/wix-headless/SKILL.md +0 -1
- package/skills/wix-headless/references/CAPABILITIES.md +3 -3
- package/skills/wix-headless/references/DISCOVERY.md +1 -1
- package/skills/wix-headless/references/SDK_HANDOFF.md +1 -1
- package/skills/wix-headless/references/SEED.md +1 -1
- package/skills/wix-headless/references/SETUP.md +1 -1
- package/skills/wix-headless/references/inline-recipes/how-to-code-restaurant-reservations.md +1 -1
- package/skills/wix-headless/references/inline-recipes/setup-restaurant-experiences.md +2 -2
- package/skills/wix-headless/references/managed/AUTHENTICATION.md +3 -14
- package/skills/wix-headless/scripts/bootstrap.mjs +156 -0
- package/skills/wix-headless-kit/SKILL.md +4 -4
- package/skills/wix-headless-kit/install/AGENTS.md +2 -2
- package/skills/wix-headless-kit/install/bootstrap.mjs +156 -0
- package/skills/wix-headless-kit/install/check.mjs +1 -1
- package/skills/wix-manage/SKILL.md +2 -8
- package/skills/wix-manage/references/cms/cms-data-items-crud.md +250 -18
- package/skills/wix-manage/references/cms/cms-schema-management.md +52 -1
- package/skills/wix-app/references/dashboard-page/DRAFT_TEMPLATE_COLLECTION.md +0 -184
- package/skills/wix-app/references/dashboard-page/DRAFT_TEMPLATE_ROUTER.md +0 -203
- package/skills/wix-app/references/dashboard-page/DRAFT_TEMPLATE_SETTINGS.md +0 -44
- package/skills/wix-manage/references/cms/cms-data-operations-extended.md +0 -263
- package/skills/wix-manage/references/cms/cms-references-and-relationships.md +0 -162
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: "CMS Data Items CRUD"
|
|
3
|
-
description: "Add, query, update, and delete items in CMS collections
|
|
3
|
+
description: "Add, query, update, and delete items in CMS collections, one at a time or in bulk. Also covers counting items, upserting with bulk save, truncating a collection, aggregating data with a pipeline, linking items through single- and multi-reference fields, and reading items with their referenced items expanded."
|
|
4
4
|
---
|
|
5
5
|
# CMS Data Items CRUD
|
|
6
6
|
|
|
7
7
|
> **Standard call shape (every curl below).** The `<AUTH>` placeholder is shorthand for `Authorization: Bearer <TOKEN>` only. Body-bearing requests also need `Content-Type: application/json`.
|
|
8
8
|
|
|
9
|
-
This recipe covers
|
|
9
|
+
This recipe covers Create, Read, Update, Delete (CRUD) operations for Wix CMS data items, plus count, upsert, truncate, aggregate, and reference-field links.
|
|
10
10
|
|
|
11
11
|
## Prerequisites
|
|
12
12
|
|
|
@@ -231,6 +231,8 @@ Unlike Update, this only modifies the specified fields — all other fields rema
|
|
|
231
231
|
|
|
232
232
|
**Endpoint**: `POST https://www.wixapis.com/wix-data/v2/bulk/items/update`
|
|
233
233
|
|
|
234
|
+
> There is no update-by-filter endpoint. To update the items matching a filter, query them first (see [Query Data Items](#query-data-items)), then send their ids to bulk update or bulk patch.
|
|
235
|
+
|
|
234
236
|
> **Important**: Use `id` (not `_id`) at the element level. The `data` object should NOT contain `_id`.
|
|
235
237
|
|
|
236
238
|
```json
|
|
@@ -297,7 +299,7 @@ Unlike bulk update, this only modifies the specified fields - other fields remai
|
|
|
297
299
|
}
|
|
298
300
|
```
|
|
299
301
|
|
|
300
|
-
**Setting a
|
|
302
|
+
**Setting a single `REFERENCE` field** (the value is one item ID; for `MULTI_REFERENCE` the value shape differs, see the next example):
|
|
301
303
|
```json
|
|
302
304
|
{
|
|
303
305
|
"dataCollectionId": "events",
|
|
@@ -318,26 +320,39 @@ Unlike bulk update, this only modifies the specified fields - other fields remai
|
|
|
318
320
|
}
|
|
319
321
|
```
|
|
320
322
|
|
|
323
|
+
**Setting a `MULTI_REFERENCE` field** (verified live): the value is an **array of item IDs**, and `SET_FIELD` **replaces the whole link set**. To add links without dropping the existing ones, use [Insert Multi-Reference Links](#insert-multi-reference-links) instead. A plain string, or `APPEND_TO_ARRAY`, fails per item with `WDE0303` inside a 200 bulk response — check `results[].itemMetadata`.
|
|
324
|
+
```json
|
|
325
|
+
{
|
|
326
|
+
"dataCollectionId": "Projects",
|
|
327
|
+
"patches": [
|
|
328
|
+
{
|
|
329
|
+
"dataItemId": "project-item-id",
|
|
330
|
+
"fieldModifications": [
|
|
331
|
+
{
|
|
332
|
+
"fieldPath": "team",
|
|
333
|
+
"action": "SET_FIELD",
|
|
334
|
+
"setFieldOptions": {
|
|
335
|
+
"value": ["alice-item-id", "bob-item-id"]
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
]
|
|
339
|
+
}
|
|
340
|
+
]
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
321
344
|
**Available actions**: `SET_FIELD`, `REMOVE_FIELD`, `INCREMENT_FIELD`, `APPEND_TO_ARRAY`, `REMOVE_FROM_ARRAY`
|
|
322
345
|
|
|
323
346
|
> **Common error**: If you get `WDE0080: patches must not be empty`, you sent `dataItems` instead of `patches`. Use the format above.
|
|
324
347
|
|
|
325
348
|
> **Recommended**: Use bulk patch instead of bulk update when you only need to change specific fields.
|
|
326
349
|
|
|
327
|
-
> **Reference Fields
|
|
328
|
-
> - **Single REFERENCE**: CAN be set during insert/update by providing the referenced item's ID as the field value (e.g., `"venue": "venue-item-id"`)
|
|
329
|
-
> - **MULTI_REFERENCE**: **STOP** - You cannot use this recipe for multi-reference fields. They cannot be set via insert/update/patch.
|
|
330
|
-
>
|
|
331
|
-
> **For MULTI_REFERENCE operations (add speakers, assign tags, link categories, etc.):**
|
|
332
|
-
> **READ [CMS References & Relationships](cms-references-and-relationships.md)** for the exact endpoints and request bodies:
|
|
333
|
-
> - `POST https://www.wixapis.com/wix-data/v2/bulk/items/insert-references` - add references
|
|
334
|
-
> - `POST https://www.wixapis.com/wix-data/v2/items/replace-references` - replace all references
|
|
335
|
-
> - `POST https://www.wixapis.com/wix-data/v2/bulk/items/remove-references` - remove references
|
|
336
|
-
>
|
|
337
|
-
> Error `WDE0303` occurs when attempting to set multi-reference fields via data operations.
|
|
350
|
+
> **Reference fields**: a single `REFERENCE` field is set like any other value (`"venue": "venue-item-id"`, as above). `MULTI_REFERENCE` links are written only by a `SET_FIELD` patch (single or bulk) or by the reference endpoints in [Reference Fields](#reference-fields) below; insert, bulk insert, bulk save, PUT and bulk update all return 200 but silently drop multi-reference values (verified live) — read the item back after any of them.
|
|
338
351
|
|
|
339
352
|
## Delete Data Item
|
|
340
353
|
|
|
354
|
+
> Deletes are irreversible. Confirm with the user before calling either delete endpoint unless the request already names the items to remove.
|
|
355
|
+
|
|
341
356
|
**Endpoint**: `DELETE https://www.wixapis.com/wix-data/v2/items/{itemId}?dataCollectionId={collectionId}`
|
|
342
357
|
|
|
343
358
|
```bash
|
|
@@ -357,6 +372,225 @@ curl -X DELETE \
|
|
|
357
372
|
}
|
|
358
373
|
```
|
|
359
374
|
|
|
375
|
+
## Count Data Items
|
|
376
|
+
|
|
377
|
+
Count items in a collection, optionally with filters.
|
|
378
|
+
|
|
379
|
+
**Endpoint**: `POST https://www.wixapis.com/wix-data/v2/items/count`
|
|
380
|
+
|
|
381
|
+
**Count All Items**:
|
|
382
|
+
```json
|
|
383
|
+
{
|
|
384
|
+
"dataCollectionId": "Products"
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
**Response**:
|
|
389
|
+
```json
|
|
390
|
+
{
|
|
391
|
+
"totalCount": 42
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
**Count with Filter**:
|
|
396
|
+
```json
|
|
397
|
+
{
|
|
398
|
+
"dataCollectionId": "Products",
|
|
399
|
+
"filter": {
|
|
400
|
+
"$and": [
|
|
401
|
+
{ "inStock": true },
|
|
402
|
+
{ "price": { "$gte": 50 } }
|
|
403
|
+
]
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
Count returns only `totalCount`. When the user needs to know *which* items match, run Query Data Items with the same filter instead of, or after, counting.
|
|
409
|
+
|
|
410
|
+
## Bulk Save (Upsert)
|
|
411
|
+
|
|
412
|
+
Insert new items or update existing items in a single operation. This is useful for syncing data.
|
|
413
|
+
|
|
414
|
+
**Endpoint**: `POST https://www.wixapis.com/wix-data/v2/bulk/items/save`
|
|
415
|
+
|
|
416
|
+
```json
|
|
417
|
+
{
|
|
418
|
+
"dataCollectionId": "Products",
|
|
419
|
+
"dataItems": [
|
|
420
|
+
{
|
|
421
|
+
"id": "existing-item-id",
|
|
422
|
+
"data": {
|
|
423
|
+
"title": "Updated Product",
|
|
424
|
+
"price": 199.99,
|
|
425
|
+
"inStock": true
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
"data": {
|
|
430
|
+
"title": "New Product",
|
|
431
|
+
"price": 79.99,
|
|
432
|
+
"inStock": true
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
],
|
|
436
|
+
"returnEntity": true
|
|
437
|
+
}
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
| Scenario | Action |
|
|
441
|
+
|----------|--------|
|
|
442
|
+
| No `id` provided | INSERT - Creates new item with generated ID |
|
|
443
|
+
| `id` provided, doesn't exist | INSERT - Creates new item with provided ID |
|
|
444
|
+
| `id` provided, exists | UPDATE - Replaces existing item |
|
|
445
|
+
|
|
446
|
+
> **Warning**: When updating, the entire item is replaced. Include all fields you want to keep. Confirm with the user before saving over existing items.
|
|
447
|
+
|
|
448
|
+
## Truncate Collection
|
|
449
|
+
|
|
450
|
+
Remove all items from a collection.
|
|
451
|
+
|
|
452
|
+
**Endpoint**: `POST https://www.wixapis.com/wix-data/v2/items/truncate`
|
|
453
|
+
|
|
454
|
+
```json
|
|
455
|
+
{
|
|
456
|
+
"dataCollectionId": "TestCollection"
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
> **Warning**: This permanently deletes ALL items in the collection and cannot be undone. Ask the user to confirm before calling it.
|
|
461
|
+
|
|
462
|
+
## Aggregate Data
|
|
463
|
+
|
|
464
|
+
Perform calculations on collection data using a pipeline of sequential stages. The example shows one `group` stage; the full set of stages (`filter`, `group`, `sort`, `projection`, `unwindArray`, `skip`, `limit`) and accumulators is in the [Aggregate Pipeline Data Items reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/aggregate-pipeline-data-items).
|
|
465
|
+
|
|
466
|
+
**Endpoint**: `POST https://www.wixapis.com/wix-data/v2/items/aggregate-pipeline`
|
|
467
|
+
|
|
468
|
+
**Count by Category**:
|
|
469
|
+
```json
|
|
470
|
+
{
|
|
471
|
+
"dataCollectionId": "Products",
|
|
472
|
+
"pipeline": {
|
|
473
|
+
"stages": [
|
|
474
|
+
{
|
|
475
|
+
"group": {
|
|
476
|
+
"groupIds": [
|
|
477
|
+
{"key": "category", "expression": {"fieldPath": "category"}}
|
|
478
|
+
],
|
|
479
|
+
"accumulators": [
|
|
480
|
+
{
|
|
481
|
+
"resultFieldName": "count",
|
|
482
|
+
"sum": {"expression": {"numeric": 1}}
|
|
483
|
+
}
|
|
484
|
+
]
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
]
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
## Operation Comparison
|
|
493
|
+
|
|
494
|
+
| Operation | Use Case | Behavior |
|
|
495
|
+
|-----------|----------|----------|
|
|
496
|
+
| **Bulk Insert** | Add new items only | Fails if ID exists |
|
|
497
|
+
| **Bulk Update** | Update existing items | Fails if ID doesn't exist, replaces entire item |
|
|
498
|
+
| **Bulk Save** | Upsert (insert or update) | Creates or updates based on ID |
|
|
499
|
+
| **Bulk Patch** | Partial update | Only modifies specified fields |
|
|
500
|
+
|
|
501
|
+
## Reference Fields
|
|
502
|
+
|
|
503
|
+
Reference fields link items across collections. A single `REFERENCE` field holds one item ID and is set like any other value in insert, update, or patch. A `MULTI_REFERENCE` field holds many links, and only two kinds of write create them: a `SET_FIELD` patch on the field (single or bulk), or the reference endpoints below, which add, replace, or remove links without touching the rest of the item. To add a reference field to a collection, see [Add a Reference Field](cms-schema-management.md#add-a-reference-field).
|
|
504
|
+
|
|
505
|
+
> **Warning (verified live)**: writing IDs into a `MULTI_REFERENCE` field through insert, bulk insert, bulk save, or PUT update returns **200 and silently drops that field's value** — no error is raised. Bulk update is a full-item replace like PUT and does the same: `success: true`, value dropped (verified live, bulk save on both its insert and update paths). Never trust the write response for reference links: read the item back with `includeReferencedItems` and confirm the linked items are there.
|
|
506
|
+
|
|
507
|
+
Linking flow, every time:
|
|
508
|
+
|
|
509
|
+
1. Resolve the referring item ID and the referenced item IDs (query by a field value; never guess IDs).
|
|
510
|
+
2. Write the links with the reference endpoints below, or with a `SET_FIELD` patch on the reference field. If the field already has links, `insert-references` adds without dropping them; `replace-references` and `SET_FIELD` discard the rest — confirm with the user before replacing unless the request says to.
|
|
511
|
+
3. **Read the referring item back** with Query Data Items and `includeReferencedItems: ["<field>"]` (or `includeReferences: [{ "field": "<field>" }]`), and confirm the linked items are present. The write's 200 is not proof; only the read-back is.
|
|
512
|
+
|
|
513
|
+
### Insert Multi-Reference Links
|
|
514
|
+
|
|
515
|
+
**Endpoint**: `POST https://www.wixapis.com/wix-data/v2/bulk/items/insert-references`
|
|
516
|
+
|
|
517
|
+
```json
|
|
518
|
+
{
|
|
519
|
+
"dataCollectionId": "Products",
|
|
520
|
+
"dataItemReferences": [
|
|
521
|
+
{
|
|
522
|
+
"referringItemId": "product-item-id",
|
|
523
|
+
"referringItemFieldName": "tags",
|
|
524
|
+
"referencedItemId": "tag-1-item-id"
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
"referringItemId": "product-item-id",
|
|
528
|
+
"referringItemFieldName": "tags",
|
|
529
|
+
"referencedItemId": "tag-2-item-id"
|
|
530
|
+
}
|
|
531
|
+
],
|
|
532
|
+
"returnEntity": true
|
|
533
|
+
}
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
### Replace All References
|
|
537
|
+
|
|
538
|
+
**Endpoint**: `POST https://www.wixapis.com/wix-data/v2/items/replace-references`
|
|
539
|
+
|
|
540
|
+
```json
|
|
541
|
+
{
|
|
542
|
+
"dataCollectionId": "Products",
|
|
543
|
+
"referringItemId": "product-item-id",
|
|
544
|
+
"referringItemFieldName": "tags",
|
|
545
|
+
"newReferencedItemIds": ["new-tag-1-id", "new-tag-2-id", "new-tag-3-id"]
|
|
546
|
+
}
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
> **Note**: To remove all references, pass an empty array for `newReferencedItemIds`.
|
|
550
|
+
|
|
551
|
+
### Remove References (Bulk)
|
|
552
|
+
|
|
553
|
+
**Endpoint**: `POST https://www.wixapis.com/wix-data/v2/bulk/items/remove-references`
|
|
554
|
+
|
|
555
|
+
```json
|
|
556
|
+
{
|
|
557
|
+
"dataCollectionId": "Products",
|
|
558
|
+
"dataItemReferences": [
|
|
559
|
+
{
|
|
560
|
+
"referringItemId": "product-id-1",
|
|
561
|
+
"referringItemFieldName": "tags",
|
|
562
|
+
"referencedItemId": "tag-to-remove-id"
|
|
563
|
+
}
|
|
564
|
+
]
|
|
565
|
+
}
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
### Query with Referenced Items Expanded
|
|
569
|
+
|
|
570
|
+
**Endpoint**: `POST https://www.wixapis.com/wix-data/v2/items/query`
|
|
571
|
+
|
|
572
|
+
```json
|
|
573
|
+
{
|
|
574
|
+
"dataCollectionId": "Products",
|
|
575
|
+
"query": {
|
|
576
|
+
"filter": {
|
|
577
|
+
"inStock": true
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
"includeReferencedItems": ["category", "tags"]
|
|
581
|
+
}
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
The method article documents the same expansion as `"includeReferences": [{ "field": "category" }, { "field": "tags", "limit": 50 }]`; both forms work (verified live). Either way the expanded value is an **array of item objects** (with `_id`, `name`, …), not an array of IDs. Without one of these properties a `MULTI_REFERENCE` field is absent from the returned item, and a single `REFERENCE` field is returned as the item ID string (it is stored on the item; verified live).
|
|
585
|
+
|
|
586
|
+
### Reference Query Operators
|
|
587
|
+
|
|
588
|
+
| Operator | Description | Example |
|
|
589
|
+
|----------|-------------|---------|
|
|
590
|
+
| `$eq` | Exact match (single reference) | `{ "category": "id" }` |
|
|
591
|
+
| `$hasSome` | Has at least one of | `{ "tags": { "$hasSome": ["id1", "id2"] } }` |
|
|
592
|
+
| `$hasAll` | Has all of | `{ "tags": { "$hasAll": ["id1", "id2"] } }` |
|
|
593
|
+
|
|
360
594
|
## Field Types Reference
|
|
361
595
|
|
|
362
596
|
| Type | Description | Example Value |
|
|
@@ -379,7 +613,7 @@ curl -X DELETE \
|
|
|
379
613
|
| `ARRAY_STRING` | Array of strings | `["tag1", "tag2"]` |
|
|
380
614
|
| `OBJECT` | JSON object | `{"key": "value"}` |
|
|
381
615
|
| `REFERENCE` | Single reference | Item ID string |
|
|
382
|
-
| `MULTI_REFERENCE` | Multiple references,
|
|
616
|
+
| `MULTI_REFERENCE` | Multiple references. Write with a `SET_FIELD` patch (array of item IDs, replaces the set) or the *reference* endpoints (add / replace / remove); expand in queries with `includeReferencedItems` or `includeReferences` | Write: array of item IDs (`SET_FIELD`). Read: absent unless expanded with `includeReferencedItems` / `includeReferences`, then an array of item objects |
|
|
383
617
|
|
|
384
618
|
---
|
|
385
619
|
|
|
@@ -465,7 +699,7 @@ confirmation before performing the install.
|
|
|
465
699
|
| `PERMISSION_DENIED` | Insufficient access | Check API permissions |
|
|
466
700
|
| `WDE0007` | Bulk update: wrong ID field name | Use `id` not `_id` at element level |
|
|
467
701
|
| `WDE0080` | Validation failed (multiple causes) | Bulk update: don't include `_id` in `data`; Bulk patch: use `patches` array not `dataItems` |
|
|
468
|
-
| `WDE0303` |
|
|
702
|
+
| `WDE0303` | Multi-reference field value is not an array of item IDs (a single ID string, or `APPEND_TO_ARRAY`); reported per item inside a 200 bulk response | Send `"value": ["id1", "id2"]` with `SET_FIELD`, or use the reference endpoints |
|
|
469
703
|
| `WDE0110` | Wix CMS (Wix Data) application is not installed | Install application with appDefId: `e593b0bd-b783-45b8-97c2-873d42aacaf4` |
|
|
470
704
|
|
|
471
705
|
---
|
|
@@ -474,6 +708,4 @@ confirmation before performing the install.
|
|
|
474
708
|
|
|
475
709
|
- [Data Items API Reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/introduction)
|
|
476
710
|
- [CMS Schema Management](cms-schema-management.md) - Creating and modifying collections
|
|
477
|
-
- [CMS References & Relationships](cms-references-and-relationships.md) - Linking collections
|
|
478
|
-
- [CMS Data Operations Extended](cms-data-operations-extended.md) - Count, upsert, aggregate
|
|
479
711
|
- [CMS Draft & Publish Workflow](cms-publishing-flow.md) - Collections gated behind a draft/publish (Draft Items plugin) workflow
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: "CMS Schema Management"
|
|
3
|
-
description: Create and modify CMS collection structures. Covers listing collections, creating collections with fields, adding/removing fields, and updating collection settings.
|
|
3
|
+
description: Create and modify CMS collection structures. Covers listing collections, creating collections with fields, adding/removing fields (including single- and multi-reference fields that link two collections), and updating collection settings.
|
|
4
4
|
---
|
|
5
5
|
# CMS Schema Management
|
|
6
6
|
|
|
@@ -86,6 +86,55 @@ curl -X GET \
|
|
|
86
86
|
}
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
### Add a Reference Field
|
|
90
|
+
|
|
91
|
+
Same endpoint as above: `POST https://www.wixapis.com/wix-data/v2/collections/create-field`. The two bodies below differ only in `type` and `typeMetadata`; omitting `typeMetadata` fails with `WDE0075` (see Error Handling).
|
|
92
|
+
|
|
93
|
+
| Type | Field Type | Relationship | Example |
|
|
94
|
+
|------|------------|--------------|---------|
|
|
95
|
+
| Single Reference | `REFERENCE` | One-to-one, Many-to-one | Product → Category |
|
|
96
|
+
| Multi-Reference | `MULTI_REFERENCE` | One-to-many, Many-to-many | Product → Tags |
|
|
97
|
+
|
|
98
|
+
**Single reference** — `typeMetadata.reference` names the referenced collection:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"dataCollectionId": "Products",
|
|
103
|
+
"field": {
|
|
104
|
+
"key": "category",
|
|
105
|
+
"displayName": "Category",
|
|
106
|
+
"type": "REFERENCE",
|
|
107
|
+
"typeMetadata": {
|
|
108
|
+
"reference": {
|
|
109
|
+
"referencedCollectionId": "Categories"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Multi-reference** — `typeMetadata.multiReference` also names the field created on the other collection:
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"dataCollectionId": "Products",
|
|
121
|
+
"field": {
|
|
122
|
+
"key": "tags",
|
|
123
|
+
"displayName": "Tags",
|
|
124
|
+
"type": "MULTI_REFERENCE",
|
|
125
|
+
"typeMetadata": {
|
|
126
|
+
"multiReference": {
|
|
127
|
+
"referencedCollectionId": "Tags",
|
|
128
|
+
"referencingFieldKey": "products",
|
|
129
|
+
"referencingDisplayName": "Products"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
To link items through these fields, see [Reference Fields](cms-data-items-crud.md#reference-fields) in the CMS Data Items CRUD recipe.
|
|
137
|
+
|
|
89
138
|
## Delete a Field from Collection
|
|
90
139
|
|
|
91
140
|
> **Warning**: This permanently deletes all data stored in this field across all items.
|
|
@@ -170,6 +219,8 @@ Don't delete and recreate a collection just to change its permissions — this f
|
|
|
170
219
|
|
|
171
220
|
| Error | Cause | Solution |
|
|
172
221
|
|-------|-------|----------|
|
|
222
|
+
| `WDE0075` (`Metadata for Reference type field not provided`) | `create-field` with `type` REFERENCE or MULTI_REFERENCE but no `typeMetadata` | Send `typeMetadata.reference.referencedCollectionId` (or `typeMetadata.multiReference…`), see Add a Reference Field |
|
|
223
|
+
| `WDE0075` (`Not recognized role provided in permissions`) | `PATCH /collections/{id}` with a `permissions` change | Use the full-replace `PUT /collections` (see Update Collection Settings) or the Data Permissions API |
|
|
173
224
|
| `WDE0110` | Wix CMS (Wix Data) app is not installed on the site | Install it: `POST https://www.wixapis.com/apps-installer-service/v1/app-instance/install` with body `{"tenant":{"tenantType":"SITE","id":"<SITE_ID>"},"appInstance":{"appDefId":"e593b0bd-b783-45b8-97c2-873d42aacaf4"}}`, then retry. See the [Install Wix Apps recipe](../app-installation/install-wix-apps.md). |
|
|
174
225
|
|
|
175
226
|
## Related Documentation
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
# Draft Template — Collection page (Cases A, B and D)
|
|
2
|
-
|
|
3
|
-
> Pick your case in [DRAFT_TEMPLATE.md](DRAFT_TEMPLATE.md) first. This page is shared by A, B
|
|
4
|
-
> and D.
|
|
5
|
-
|
|
6
|
-
> **You write `fetchData`, the filters and the columns.** This holds whatever the rows are: for a
|
|
7
|
-
> CMS collection `fetchData` calls `@wix/data` `items.query()`
|
|
8
|
-
> ([WIX_DATA.md](../data-collection/WIX_DATA.md)) and nothing else on this page changes.
|
|
9
|
-
|
|
10
|
-
## Two rules this skeleton encodes, so read them before editing it
|
|
11
|
-
|
|
12
|
-
**Every row opens a page of its own, never a panel.** `onRowClick` navigates —
|
|
13
|
-
`navigateToEntityPage` to an `EntityPage` route when the record is editable, or to a read-only
|
|
14
|
-
detail route when the page is display-only ([DRAFT_TEMPLATE_ROUTER.md § 4](DRAFT_TEMPLATE_ROUTER.md#4-read-only-detail-route--case-a)).
|
|
15
|
-
A WDS `SidePanel` is not the drill-in: in Cairo it is the host for a page's own side panels — the
|
|
16
|
-
fields card's "Manage fields", a table's column panel — and `example-bm` uses it as a row drill-in
|
|
17
|
-
in exactly nothing. Every collection example there navigates.
|
|
18
|
-
|
|
19
|
-
**No `SummaryBar` unless the request asked for one.** Not "unless the page seems to want one" —
|
|
20
|
-
unless the prompt named a total, a count, or a "how many / how much" figure. It is absent from this
|
|
21
|
-
skeleton on purpose; adding one uninvited pushes the rows down the page and puts a number on screen
|
|
22
|
-
nobody has to be right about. When you do add one, wire it from
|
|
23
|
-
[SKILL.md § Step 2](../../SKILL.md) — no `SummaryBar` unless the request asked for one.
|
|
24
|
-
|
|
25
|
-
## The collection page
|
|
26
|
-
|
|
27
|
-
This is the file [Step 4c's UX Completeness Self-Audit](../../SKILL.md#step-4c-ux-completeness-self-audit)
|
|
28
|
-
is about: a working filter, named filters, and a row that opens.
|
|
29
|
-
|
|
30
|
-
```tsx
|
|
31
|
-
// {Feature}CollectionPage.tsx — Case A, B, D
|
|
32
|
-
import type { FC } from 'react';
|
|
33
|
-
import {
|
|
34
|
-
CollectionEmptyState, CollectionErrorState, CollectionNoResultsState, CollectionSearch, CollectionToolbarFilters,
|
|
35
|
-
MultiSelectCheckboxFilter, Table, stringsArrayFilter,
|
|
36
|
-
useStaticListFilterCollection, useTableCollection,
|
|
37
|
-
} from '@wix/patterns';
|
|
38
|
-
import { CollectionPage } from '@wix/patterns/page';
|
|
39
|
-
import { usePatternsNavigate } from '@wix/patterns/router';
|
|
40
|
-
import { fetch{Feature}Page, type {Entity}Row } from './{feature}-api';
|
|
41
|
-
|
|
42
|
-
const STATUS_LABELS: Record<string, string> = { ACTIVE: 'Active', ARCHIVED: 'Archived' };
|
|
43
|
-
// Filter factories are module-level: one instance per page, not per render.
|
|
44
|
-
const statusFilter = stringsArrayFilter<'ACTIVE' | 'ARCHIVED'>({
|
|
45
|
-
// `name` is NOT the visible title — it feeds a11y legends, BI grouping and dataHooks.
|
|
46
|
-
// The title comes from the label props in the JSX below; the package's own
|
|
47
|
-
// `Collection Toolkit.md` guide has the prop model.
|
|
48
|
-
name: 'Status',
|
|
49
|
-
itemKey: (item) => item,
|
|
50
|
-
itemName: (item) => STATUS_LABELS[item] ?? item,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
export const {Feature}CollectionPage: FC = () => {
|
|
54
|
-
const { navigateToEntityPage } = usePatternsNavigate<{Entity}Row>();
|
|
55
|
-
|
|
56
|
-
const state = useTableCollection<{Entity}Row, { status: typeof statusFilter }>({
|
|
57
|
-
queryName: '{feature}',
|
|
58
|
-
paginationMode: 'cursor', // 'offset' if your API pages by offset
|
|
59
|
-
itemKey: (item) => item.id,
|
|
60
|
-
itemName: (item) => item.name,
|
|
61
|
-
filters: { status: statusFilter },
|
|
62
|
-
// Every declared filter AND the search box are read here — one that never
|
|
63
|
-
// reaches the query renders fine and narrows nothing.
|
|
64
|
-
fetchData: async (query) =>
|
|
65
|
-
fetch{Feature}Page({
|
|
66
|
-
limit: query.limit,
|
|
67
|
-
cursor: query.cursor ?? undefined, // return `cursor: next || undefined` — key always
|
|
68
|
-
// present, '' walks pages forever
|
|
69
|
-
search: query.search,
|
|
70
|
-
filters: { status: query.filters.status },
|
|
71
|
-
}),
|
|
72
|
-
// fetchTotal is for a requested aggregate, so it is commented out here. Uncommented, it
|
|
73
|
-
// must RESOLVE A NUMBER from an endpoint that counts, and it OVERRIDES the fallback to the
|
|
74
|
-
// loaded-rows count — so a wrong one reports 0 beside a full table while tsc stays green.
|
|
75
|
-
// Read QUERY_AND_PAGING.md, "What fetchTotal is allowed to call", before uncommenting.
|
|
76
|
-
// fetchTotal: async (query) => count{Feature}({ search: query.search, filters: query.filters }),
|
|
77
|
-
fetchErrorMessage: ({ err }) => (err instanceof Error ? err.message : 'Failed to load {feature}'),
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const statusOptions = useStaticListFilterCollection(statusFilter, ['ACTIVE', 'ARCHIVED']);
|
|
81
|
-
|
|
82
|
-
// Nothing here reads `state` directly: the Table observes it internally. The moment you
|
|
83
|
-
// DO derive a number from it in this component — a header figure, a badge, a requested
|
|
84
|
-
// SummaryBar — it is MobX, and a plain read is computed once while the collection is still
|
|
85
|
-
// empty and never recomputed. Wrap it in `useSelector` and select a primitive: TABLE_STATE.md.
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<CollectionPage>
|
|
89
|
-
<CollectionPage.Header title={{ text: '{Page Title}' }} />
|
|
90
|
-
<CollectionPage.Content>
|
|
91
|
-
<Table
|
|
92
|
-
state={state}
|
|
93
|
-
// `search` defaults to ON, so omitting it ships a box that reaches no
|
|
94
|
-
// query. Wire it AND read query.search above. If the API has no
|
|
95
|
-
// free-text filter, resolve the term to one it does support.
|
|
96
|
-
search={<CollectionSearch placeholder="Search {feature}" />}
|
|
97
|
-
filters={
|
|
98
|
-
<CollectionToolbarFilters>
|
|
99
|
-
{/* BOTH label props, same string, and never accordionItemProps.title.
|
|
100
|
-
The resolution model is the package's own `Collection Toolkit.md` guide. */}
|
|
101
|
-
<MultiSelectCheckboxFilter
|
|
102
|
-
filter={statusFilter} collection={statusOptions}
|
|
103
|
-
toolbarItemProps={{ label: 'Status' }}
|
|
104
|
-
accordionItemProps={{ label: 'Status' }}
|
|
105
|
-
/>
|
|
106
|
-
</CollectionToolbarFilters>
|
|
107
|
-
}
|
|
108
|
-
// Three distinct messages. Without errorState a failed query looks
|
|
109
|
-
// exactly like a slow one: skeletons, forever.
|
|
110
|
-
emptyState={<CollectionEmptyState title="No {feature} yet" />}
|
|
111
|
-
// Name what excluded the rows — a seeded default or a missing scope
|
|
112
|
-
// looks exactly like "nothing matched", and only one is actionable.
|
|
113
|
-
noResultsState={<CollectionNoResultsState title="No {feature} match" subtitle="…" />}
|
|
114
|
-
// errorState is a RENDER FUNCTION: (err, { retry }) => ReactElement.
|
|
115
|
-
errorState={(err, { retry }) => (
|
|
116
|
-
<CollectionErrorState
|
|
117
|
-
title="Couldn't load {feature}"
|
|
118
|
-
subtitle={String(err)}
|
|
119
|
-
action={{ text: 'Retry', onClick: retry }}
|
|
120
|
-
/>
|
|
121
|
-
)}
|
|
122
|
-
// The drill-in. Editable record → the EntityPage route (`/${item.id}`).
|
|
123
|
-
// Display-only → the read-only route, DRAFT_TEMPLATE_ROUTER.md §4. Either way a
|
|
124
|
-
// route, and passing `entity` lets the target title itself before its fetch lands.
|
|
125
|
-
onRowClick={(item) => navigateToEntityPage({ path: `/${item.id}`, entity: item })}
|
|
126
|
-
columns={[
|
|
127
|
-
// One column per field the prompt names; verify each source field —
|
|
128
|
-
// DATA_SOURCES.md, "A column must show what its header promises."
|
|
129
|
-
{ id: 'name', title: 'Name', render: (item) => item.name },
|
|
130
|
-
]}
|
|
131
|
-
/>
|
|
132
|
-
</CollectionPage.Content>
|
|
133
|
-
</CollectionPage>
|
|
134
|
-
);
|
|
135
|
-
};
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
## Turning `query.search` into a query
|
|
139
|
-
|
|
140
|
-
`{feature}-api.ts` turns one term into a filter over *several* fields — an OR. **This is where
|
|
141
|
-
search ships broken**: it renders, it reaches the query, and still returns every row, so nothing
|
|
142
|
-
looks wrong until someone counts results.
|
|
143
|
-
|
|
144
|
-
### A CMS collection — `@wix/data`
|
|
145
|
-
|
|
146
|
-
`or()` combines two filters; it is **not** a condition. Called on a query or filter holding no
|
|
147
|
-
condition yet it contributes an empty `{}` branch, and `{} OR x` matches the whole collection. Seed
|
|
148
|
-
the filter with the first field, `or()` the rest onto it, then `and()` it onto the query — which is
|
|
149
|
-
also what keeps the facet filters applying to *every* branch:
|
|
150
|
-
|
|
151
|
-
```ts
|
|
152
|
-
// SHORT_TEXT / LONG_TEXT fields only: `contains` on a number, date or
|
|
153
|
-
// reference field is not a narrower match, it is no match.
|
|
154
|
-
const searchFilter = (term: string, fields: string[]) =>
|
|
155
|
-
fields.map((f) => items.filter().contains(f, term)).reduce((acc, f) => acc.or(f));
|
|
156
|
-
|
|
157
|
-
let query = items.query(COLLECTION_ID).eq('status', status).limit(limit);
|
|
158
|
-
const term = search?.trim();
|
|
159
|
-
if (term) query = query.and(searchFilter(term, ['companyName', 'contactEmail']));
|
|
160
|
-
|
|
161
|
-
// ❌ or() onto a query holding no condition — empty $or branch, every row matches
|
|
162
|
-
items.query(ID).or(items.filter().contains('a', t)).or(items.filter().contains('b', t));
|
|
163
|
-
// ❌ or() onto the query itself — `status` survives only on the first branch
|
|
164
|
-
items.query(ID).eq('status', s).contains('a', t).or(items.filter().contains('b', t));
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
### A vertical SDK — `@wix/bookings`, `@wix/ecom`, …
|
|
168
|
-
|
|
169
|
-
No shared free-text operator; the shape differs per endpoint. Read its *Supported Filters* page
|
|
170
|
-
([QUERY_AND_PAGING.md](QUERY_AND_PAGING.md#the-filterable-fields-are-a-closed-list-published-per-endpoint)),
|
|
171
|
-
then `$or` one clause per identity field it lists. Never route the term to a single field by its
|
|
172
|
-
shape — a measured run shipped this, and one branch is always dead:
|
|
173
|
-
|
|
174
|
-
```ts
|
|
175
|
-
query = term.includes('@')
|
|
176
|
-
? query.startsWith('loginEmail', term)
|
|
177
|
-
: query.startsWith('contact.firstName', term); // a surname matches nothing, ever
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
`startsWith` is prefix-only too — "Smith" never finds "John Smith" — so prefer the containment
|
|
181
|
-
operator when the endpoint declares one, and say which you used in `noResultsState`.
|
|
182
|
-
|
|
183
|
-
**Whatever the shape, prove it narrows.** Run one term you expect to hit a known row and one you
|
|
184
|
-
expect to hit nothing, and check the row count changes for both.
|