create-dig-app 0.1.1 → 0.2.3
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/lib/nft-metadata.js
CHANGED
|
@@ -57,6 +57,9 @@ function attrValue(v) {
|
|
|
57
57
|
* Normalize a list of `{trait_type,value}` (accepting `traitType` too) into the canonical attribute
|
|
58
58
|
* array: trimmed string `trait_type` + stringified `value`, dropping any entry with an empty
|
|
59
59
|
* trait_type. Order is preserved (CHIP-0007 does not sort attributes).
|
|
60
|
+
*
|
|
61
|
+
* This is for NFT-**item** attributes only. Collection-level attributes use `type`, not
|
|
62
|
+
* `trait_type` — see {@link normalizeCollectionAttributes} (#189).
|
|
60
63
|
* @param {Array<{trait_type?:string,traitType?:string,value:unknown}>} attrs
|
|
61
64
|
* @returns {Array<{trait_type:string,value:string}>}
|
|
62
65
|
*/
|
|
@@ -66,6 +69,31 @@ function normalizeAttributes(attrs) {
|
|
|
66
69
|
.filter((a) => a.trait_type !== "");
|
|
67
70
|
}
|
|
68
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Normalize a list of **collection-level** attributes (icon/banner/website/twitter/etc) into the
|
|
74
|
+
* canonical shape: trimmed string `type` + stringified `value`, dropping any entry with an empty
|
|
75
|
+
* `type`. Order is preserved.
|
|
76
|
+
*
|
|
77
|
+
* Per CHIP-0007, a collection's attributes use the field `type` — DISTINCT from an NFT item's
|
|
78
|
+
* `trait_type` ({@link normalizeAttributes}). Issue #189 (the emit-side twin of digstore's #187 and
|
|
79
|
+
* chip35_dl_coin's own fix): this repo's generator was reusing the item shape for collection
|
|
80
|
+
* attributes too, emitting non-conformant `trait_type` for the collection block. This function
|
|
81
|
+
* always WRITES `type`; it still ACCEPTS the legacy `trait_type`/`traitType` spellings on input
|
|
82
|
+
* (back-compat with already-authored `collection.json` files and the wasm boundary's alias), so
|
|
83
|
+
* existing scaffolded projects keep working unchanged while newly generated metadata becomes
|
|
84
|
+
* CHIP-0007-conformant.
|
|
85
|
+
* @param {Array<{type?:string,trait_type?:string,traitType?:string,value:unknown}>} attrs
|
|
86
|
+
* @returns {Array<{type:string,value:string}>}
|
|
87
|
+
*/
|
|
88
|
+
function normalizeCollectionAttributes(attrs) {
|
|
89
|
+
return (attrs ?? [])
|
|
90
|
+
.map((a) => ({
|
|
91
|
+
type: String(a?.type ?? a?.trait_type ?? a?.traitType ?? "").trim(),
|
|
92
|
+
value: attrValue(a?.value),
|
|
93
|
+
}))
|
|
94
|
+
.filter((a) => a.type !== "");
|
|
95
|
+
}
|
|
96
|
+
|
|
69
97
|
/**
|
|
70
98
|
* Build a canonical CHIP-0007 metadata object from loose inputs. The returned object's keys are in
|
|
71
99
|
* the pinned field order and omit empty/false/None fields, so {@link canonicalJson} of it is
|
|
@@ -76,7 +104,8 @@ function normalizeAttributes(attrs) {
|
|
|
76
104
|
* @param {string} [input.description] Optional; omitted when empty/undefined.
|
|
77
105
|
* @param {boolean} [input.sensitive_content] Omitted when falsey.
|
|
78
106
|
* @param {{id:string,name:string,attributes?:Array}} [input.collection] Collection ref; its
|
|
79
|
-
* `attributes` are omitted when
|
|
107
|
+
* `attributes` (CHIP-0007 `type`/`value` pairs — NOT `trait_type`, see #189) are omitted when
|
|
108
|
+
* empty.
|
|
80
109
|
* @param {Array<{trait_type?:string,traitType?:string,value:unknown}>} [input.attributes] Per-item traits.
|
|
81
110
|
* @param {number} [input.series_number] 1-based position; omitted when undefined.
|
|
82
111
|
* @param {number} [input.series_total] Series size; omitted when undefined.
|
|
@@ -94,7 +123,7 @@ export function buildChip0007Metadata(input) {
|
|
|
94
123
|
if (input?.collection) {
|
|
95
124
|
const c = input.collection;
|
|
96
125
|
const ref = { id: String(c.id ?? ""), name: String(c.name ?? "") };
|
|
97
|
-
const cattrs =
|
|
126
|
+
const cattrs = normalizeCollectionAttributes(c.attributes);
|
|
98
127
|
if (cattrs.length > 0) ref.attributes = cattrs;
|
|
99
128
|
md.collection = ref;
|
|
100
129
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-dig-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Scaffold a wallet-wired, deployable DIG Network app — free, no mint. The JS front door for building dapps, frontends, and NFT collections on Chia.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "DIG Network",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"node": ">=18"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"test": "node --test
|
|
45
|
-
"coverage": "c8 node --test
|
|
44
|
+
"test": "node --test",
|
|
45
|
+
"coverage": "c8 node --test",
|
|
46
46
|
"start": "node bin/create-dig-app.js"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
@@ -56,6 +56,18 @@ function normalizeAttributes(attrs) {
|
|
|
56
56
|
.filter((a) => a.trait_type !== "");
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
// Collection-level attributes use CHIP-0007's `type` field, NOT the item shape's `trait_type`
|
|
60
|
+
// (#189 — the emit-side twin of digstore's #187 / chip35_dl_coin's own fix). Still accepts the
|
|
61
|
+
// legacy `trait_type`/`traitType` spellings on input so an existing collection.json keeps working.
|
|
62
|
+
function normalizeCollectionAttributes(attrs) {
|
|
63
|
+
return (attrs ?? [])
|
|
64
|
+
.map((a) => ({
|
|
65
|
+
type: String(a?.type ?? a?.trait_type ?? a?.traitType ?? "").trim(),
|
|
66
|
+
value: attrValue(a?.value),
|
|
67
|
+
}))
|
|
68
|
+
.filter((a) => a.type !== "");
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
function buildChip0007Metadata(input) {
|
|
60
72
|
const md = { format: CHIP0007_FORMAT, name: String(input?.name ?? "") };
|
|
61
73
|
const description = input?.description;
|
|
@@ -64,7 +76,7 @@ function buildChip0007Metadata(input) {
|
|
|
64
76
|
if (input?.collection) {
|
|
65
77
|
const c = input.collection;
|
|
66
78
|
const ref = { id: String(c.id ?? ""), name: String(c.name ?? "") };
|
|
67
|
-
const cattrs =
|
|
79
|
+
const cattrs = normalizeCollectionAttributes(c.attributes);
|
|
68
80
|
if (cattrs.length > 0) ref.attributes = cattrs;
|
|
69
81
|
md.collection = ref;
|
|
70
82
|
}
|