@vitrine-kit/payload-blueprint 0.2.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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +150 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vitrine Kit (Max Davydov)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @vitrine-kit/payload-blueprint
|
|
2
|
+
|
|
3
|
+
Базовые Payload-коллекции Vitrine и API `extend()` для **аддитивного** расширения их полей фичами (контракт 5, §5 спеки).
|
|
4
|
+
|
|
5
|
+
Фича добавляет поля (`extend('product', { addFields })`), не ломая существующие. Версионируется как пакет.
|
|
6
|
+
|
|
7
|
+
Скелет (M0). Наполняется в M2.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BlueprintFieldDef, Extend } from '@vitrine-kit/contracts';
|
|
2
|
+
|
|
3
|
+
interface BlueprintCollectionConfig {
|
|
4
|
+
slug: string;
|
|
5
|
+
fields: BlueprintFieldDef[];
|
|
6
|
+
/** Прочие опции коллекции Payload (admin, access, hooks, upload, auth, …). */
|
|
7
|
+
[option: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
declare const categoriesCollection: BlueprintCollectionConfig;
|
|
10
|
+
declare const mediaCollection: BlueprintCollectionConfig;
|
|
11
|
+
declare const usersCollection: BlueprintCollectionConfig;
|
|
12
|
+
declare const variantsCollection: BlueprintCollectionConfig;
|
|
13
|
+
declare const productsCollection: BlueprintCollectionConfig;
|
|
14
|
+
declare const ordersCollection: BlueprintCollectionConfig;
|
|
15
|
+
declare const cartsCollection: BlueprintCollectionConfig;
|
|
16
|
+
/** Базовые коллекции в стабильном порядке. */
|
|
17
|
+
declare const baseCollections: BlueprintCollectionConfig[];
|
|
18
|
+
|
|
19
|
+
interface Blueprint {
|
|
20
|
+
extend: Extend;
|
|
21
|
+
/** Собирает базовые коллекции + аддитивные расширения. */
|
|
22
|
+
build(): BlueprintCollectionConfig[];
|
|
23
|
+
}
|
|
24
|
+
declare function createBlueprint(): Blueprint;
|
|
25
|
+
|
|
26
|
+
declare const PAYLOAD_BLUEPRINT_VERSION: "0.1.0";
|
|
27
|
+
|
|
28
|
+
export { type Blueprint, type BlueprintCollectionConfig, PAYLOAD_BLUEPRINT_VERSION, baseCollections, cartsCollection, categoriesCollection, createBlueprint, mediaCollection, ordersCollection, productsCollection, usersCollection, variantsCollection };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// src/collections.ts
|
|
2
|
+
var f = (name, type, extra = {}) => ({ name, type, ...extra });
|
|
3
|
+
var authenticated = ({ req }) => Boolean(req?.user);
|
|
4
|
+
var adminOnly = { read: authenticated, create: authenticated, update: authenticated, delete: authenticated };
|
|
5
|
+
var categoriesCollection = {
|
|
6
|
+
slug: "categories",
|
|
7
|
+
admin: { useAsTitle: "title" },
|
|
8
|
+
fields: [
|
|
9
|
+
f("title", "text", { required: true }),
|
|
10
|
+
f("slug", "text", { required: true, unique: true, index: true }),
|
|
11
|
+
f("description", "textarea"),
|
|
12
|
+
f("parent", "relationship", { relationTo: "categories" })
|
|
13
|
+
]
|
|
14
|
+
};
|
|
15
|
+
var mediaCollection = {
|
|
16
|
+
slug: "media",
|
|
17
|
+
upload: true,
|
|
18
|
+
fields: [f("alt", "text")]
|
|
19
|
+
};
|
|
20
|
+
var usersCollection = {
|
|
21
|
+
slug: "users",
|
|
22
|
+
auth: true,
|
|
23
|
+
fields: [f("email", "text", { required: true })]
|
|
24
|
+
};
|
|
25
|
+
var variantsCollection = {
|
|
26
|
+
slug: "variants",
|
|
27
|
+
admin: { useAsTitle: "sku" },
|
|
28
|
+
fields: [
|
|
29
|
+
f("sku", "text", { required: true, unique: true, index: true }),
|
|
30
|
+
f("product", "relationship", { relationTo: "products", required: true }),
|
|
31
|
+
f("price", "number", { required: true }),
|
|
32
|
+
// минимальные единицы (копейки)
|
|
33
|
+
f("stock", "number"),
|
|
34
|
+
f("options", "json")
|
|
35
|
+
// { size: 'M', color: 'red' }
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
var productsCollection = {
|
|
39
|
+
slug: "products",
|
|
40
|
+
admin: { useAsTitle: "title" },
|
|
41
|
+
fields: [
|
|
42
|
+
f("title", "text", { required: true }),
|
|
43
|
+
f("slug", "text", { required: true, unique: true, index: true }),
|
|
44
|
+
f("description", "richText"),
|
|
45
|
+
f("categories", "relationship", { relationTo: "categories", hasMany: true }),
|
|
46
|
+
f("images", "relationship", { relationTo: "media", hasMany: true }),
|
|
47
|
+
f("seo", "group", {
|
|
48
|
+
fields: [f("title", "text"), f("description", "textarea"), f("image", "relationship", { relationTo: "media" })]
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
var ordersCollection = {
|
|
53
|
+
slug: "orders",
|
|
54
|
+
admin: { useAsTitle: "id" },
|
|
55
|
+
access: adminOnly,
|
|
56
|
+
fields: [
|
|
57
|
+
f("status", "select", {
|
|
58
|
+
options: ["pending", "paid", "fulfilled", "cancelled", "refunded"],
|
|
59
|
+
defaultValue: "pending"
|
|
60
|
+
}),
|
|
61
|
+
f("email", "text"),
|
|
62
|
+
f("currency", "text"),
|
|
63
|
+
f("subtotal", "number"),
|
|
64
|
+
f("total", "number"),
|
|
65
|
+
f("lines", "json"),
|
|
66
|
+
f("paymentProvider", "text"),
|
|
67
|
+
// 'stripe' | 'paddle' | 'yookassa'
|
|
68
|
+
f("paymentRef", "text", { index: true }),
|
|
69
|
+
// идемпотентность webhook (дедуп по референсу платежа)
|
|
70
|
+
f("createdAt", "date")
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
var cartsCollection = {
|
|
74
|
+
slug: "carts",
|
|
75
|
+
admin: { useAsTitle: "id" },
|
|
76
|
+
access: adminOnly,
|
|
77
|
+
fields: [
|
|
78
|
+
f("lines", "json"),
|
|
79
|
+
// CartLine[] (контракт); арифметика — в @vitrine-kit/core
|
|
80
|
+
f("currency", "text"),
|
|
81
|
+
f("subtotal", "number"),
|
|
82
|
+
f("discountTotal", "number"),
|
|
83
|
+
f("total", "number"),
|
|
84
|
+
f("status", "select", {
|
|
85
|
+
options: ["active", "converted", "abandoned"],
|
|
86
|
+
defaultValue: "active"
|
|
87
|
+
}),
|
|
88
|
+
f("paymentRef", "text", { index: true })
|
|
89
|
+
]
|
|
90
|
+
};
|
|
91
|
+
var baseCollections = [
|
|
92
|
+
categoriesCollection,
|
|
93
|
+
mediaCollection,
|
|
94
|
+
usersCollection,
|
|
95
|
+
productsCollection,
|
|
96
|
+
variantsCollection,
|
|
97
|
+
ordersCollection,
|
|
98
|
+
cartsCollection
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
// src/blueprint.ts
|
|
102
|
+
var SLUG_BY_COLLECTION = {
|
|
103
|
+
product: "products",
|
|
104
|
+
variant: "variants",
|
|
105
|
+
category: "categories",
|
|
106
|
+
media: "media",
|
|
107
|
+
order: "orders",
|
|
108
|
+
user: "users"
|
|
109
|
+
};
|
|
110
|
+
function createBlueprint() {
|
|
111
|
+
const additions = /* @__PURE__ */ new Map();
|
|
112
|
+
const extend = (collection, patch) => {
|
|
113
|
+
const slug = SLUG_BY_COLLECTION[collection];
|
|
114
|
+
const list = additions.get(slug) ?? [];
|
|
115
|
+
list.push(...patch.addFields);
|
|
116
|
+
additions.set(slug, list);
|
|
117
|
+
};
|
|
118
|
+
function build() {
|
|
119
|
+
return baseCollections.map((base) => {
|
|
120
|
+
const adds = additions.get(base.slug) ?? [];
|
|
121
|
+
if (adds.length === 0) return base;
|
|
122
|
+
const existing = new Set(base.fields.map((field) => field.name));
|
|
123
|
+
for (const field of adds) {
|
|
124
|
+
if (existing.has(field.name)) {
|
|
125
|
+
throw new Error(
|
|
126
|
+
`[vitrine] blueprint: \u043F\u043E\u043B\u0435 "${field.name}" \u0443\u0436\u0435 \u0435\u0441\u0442\u044C \u0432 "${base.slug}" \u2014 extend() \u0442\u043E\u043B\u044C\u043A\u043E \u0430\u0434\u0434\u0438\u0442\u0438\u0432\u0435\u043D`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
existing.add(field.name);
|
|
130
|
+
}
|
|
131
|
+
return { ...base, fields: [...base.fields, ...adds] };
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return { extend, build };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/index.ts
|
|
138
|
+
var PAYLOAD_BLUEPRINT_VERSION = "0.1.0";
|
|
139
|
+
export {
|
|
140
|
+
PAYLOAD_BLUEPRINT_VERSION,
|
|
141
|
+
baseCollections,
|
|
142
|
+
cartsCollection,
|
|
143
|
+
categoriesCollection,
|
|
144
|
+
createBlueprint,
|
|
145
|
+
mediaCollection,
|
|
146
|
+
ordersCollection,
|
|
147
|
+
productsCollection,
|
|
148
|
+
usersCollection,
|
|
149
|
+
variantsCollection
|
|
150
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vitrine-kit/payload-blueprint",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Vitrine — базовые Payload-коллекции + аддитивный extend().",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/vitrine-kit/vitrine.git",
|
|
25
|
+
"directory": "packages/payload-blueprint"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@vitrine-kit/contracts": "1.1.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"test": "vitest run --passWithNoTests"
|
|
34
|
+
}
|
|
35
|
+
}
|