@nibgate/sdk 0.2.2 → 0.2.5
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/SKILL.md +9 -0
- package/dist/nibgate.js +24 -4
- package/dist/nibgate.js.map +2 -2
- package/dist/nibgate.min.js +2 -2
- package/dist/nibgate.min.js.map +3 -3
- package/package.json +2 -2
- package/src/core/resource.js +29 -4
- package/src/server/hub.js +1 -1
package/src/core/resource.js
CHANGED
|
@@ -48,6 +48,28 @@ export function normalizeUnlockPolicy(value = {}) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
function browserEnv() {
|
|
52
|
+
return typeof window !== 'undefined' ? window : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function metaContent(name) {
|
|
56
|
+
const win = browserEnv();
|
|
57
|
+
if (!win) return '';
|
|
58
|
+
const selector = `meta[name="${name}"], meta[property="${name}"]`;
|
|
59
|
+
const node = win.document.querySelector(selector);
|
|
60
|
+
return node ? node.getAttribute('content') || '' : '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function autoDeriveUrl(path) {
|
|
64
|
+
const win = browserEnv();
|
|
65
|
+
if (!win || !path) return undefined;
|
|
66
|
+
return `${win.location.origin}${path.startsWith('/') ? path : '/' + path}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function autoDeriveImage() {
|
|
70
|
+
return metaContent('og:image') || undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
51
73
|
export function normalizeResource(resource = {}) {
|
|
52
74
|
const input = typeof resource === 'string' ? { id: resource } : (resource || {});
|
|
53
75
|
const {
|
|
@@ -63,6 +85,9 @@ export function normalizeResource(resource = {}) {
|
|
|
63
85
|
...v1Input
|
|
64
86
|
} = input;
|
|
65
87
|
|
|
88
|
+
const path = input.path || input.route || undefined;
|
|
89
|
+
const url = input.url || autoDeriveUrl(path) || undefined;
|
|
90
|
+
|
|
66
91
|
return {
|
|
67
92
|
...v1Input,
|
|
68
93
|
id: String(input.id || input.contentId || input.slug || '').trim(),
|
|
@@ -72,9 +97,9 @@ export function normalizeResource(resource = {}) {
|
|
|
72
97
|
paymentRail: normalizePaymentRail(input.paymentRail || input.paymentMode || input.rail),
|
|
73
98
|
recipient: input.recipient || input.receiver || input.receiverAddress || input.payTo || input.creatorWallet || undefined,
|
|
74
99
|
payTo: input.payTo || input.recipient || input.receiver || input.receiverAddress || input.creatorWallet || undefined,
|
|
75
|
-
path
|
|
76
|
-
url
|
|
77
|
-
imageUrl: input.imageUrl || input.image || undefined,
|
|
100
|
+
path,
|
|
101
|
+
url,
|
|
102
|
+
imageUrl: input.imageUrl || input.image || autoDeriveImage() || undefined,
|
|
78
103
|
tags: input.tags || undefined,
|
|
79
104
|
access: normalizeAccessPolicy(input.access),
|
|
80
105
|
unlock: normalizeUnlockPolicy(input.unlock),
|
|
@@ -123,7 +148,7 @@ export function validateResourceMetadata(resource = {}, options = {}) {
|
|
|
123
148
|
|
|
124
149
|
if (isPaidResource(normalized)) {
|
|
125
150
|
if (!hasValue(normalized.price)) errors.push('Paid content requires price.');
|
|
126
|
-
if (!hasValue(normalized.recipient || normalized.payTo))
|
|
151
|
+
if (!hasValue(normalized.recipient || normalized.payTo)) warnings.push('Paid content should include recipient/payTo (server value from 402 challenge is used for actual payment).');
|
|
127
152
|
}
|
|
128
153
|
|
|
129
154
|
const score = Math.max(0, 100 - errors.length * 20 - warnings.length * 8);
|
package/src/server/hub.js
CHANGED
|
@@ -12,7 +12,7 @@ export async function emitHubEvent(event, resourceInput, options = {}) {
|
|
|
12
12
|
return { skipped: true, reason: 'Missing NIBGATE_SITE_ID or NIBGATE_SITE_TOKEN' };
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const response = await fetch(`${apiBaseUrl}/api/hub/
|
|
15
|
+
const response = await fetch(`${apiBaseUrl}/api/hub/evt`, {
|
|
16
16
|
method: 'POST',
|
|
17
17
|
headers: {
|
|
18
18
|
'content-type': 'application/json',
|