@plentymarkets/shop-core 1.23.2 → 1.23.4
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/dist/module.d.mts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +138 -8
- package/dist/runtime/types/extensions.d.ts +26 -0
- package/dist/runtime/types/extensions.js +4 -0
- package/dist/runtime/types/index.d.ts +1 -0
- package/dist/runtime/types/index.js +1 -0
- package/dist/types.d.mts +1 -1
- package/package.json +2 -2
package/dist/module.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { ModuleOptions } from '../dist/runtime/types/module.js';
|
|
3
|
-
export { CacheControlMeta, Cookie, CookieGroup, CookieGroupFromNuxtConfig, Events, JsonCookie, LocalizationMessage, Notification, PaymentButtonComponent, PaymentButtonComponentProps, SSRMetrics, ShopCoreConfigInput } from '../dist/runtime/types/index.js';
|
|
3
|
+
export { CacheControlMeta, Cookie, CookieGroup, CookieGroupFromNuxtConfig, Events, ExtensionEntry, JsonCookie, LocalizationMessage, Notification, PaymentButtonComponent, PaymentButtonComponentProps, SSRMetrics, ShopCoreConfigInput } from '../dist/runtime/types/index.js';
|
|
4
4
|
|
|
5
5
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
6
6
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addTypeTemplate, addTemplate, addImportsSources, addComponent, addPlugin, addImports } from '@nuxt/kit';
|
|
2
2
|
import { ofetch } from 'ofetch';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { existsSync, readFileSync, constants } from 'node:fs';
|
|
4
|
+
import { readFile, access, mkdir, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { resolve, join } from 'node:path';
|
|
6
|
+
import { MANIFEST_FILENAME, LOG_PREFIX, DANGEROUS_IDS, DEFAULT_PRIORITY } from '../dist/runtime/types/extensions.js';
|
|
6
7
|
import { genInlineTypeImport } from 'knitwork';
|
|
7
8
|
|
|
8
9
|
const fetchAllTranslations = async (url, configId) => {
|
|
@@ -17,22 +18,151 @@ const fetchAllTranslations = async (url, configId) => {
|
|
|
17
18
|
);
|
|
18
19
|
};
|
|
19
20
|
|
|
21
|
+
const isNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
22
|
+
const isSafeId = (value) => isNonEmptyString(value) && !DANGEROUS_IDS.has(value);
|
|
23
|
+
const isEntryOptions = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
24
|
+
const isModuleEntry = (value) => isNonEmptyString(value) || Array.isArray(value) && value.length === 2 && isNonEmptyString(value[0]) && isEntryOptions(value[1]);
|
|
25
|
+
const validateEntries = (rawEntries) => {
|
|
26
|
+
const valid = [];
|
|
27
|
+
for (const entry of rawEntries) {
|
|
28
|
+
if (!entry || typeof entry !== "object") {
|
|
29
|
+
console.warn(`${LOG_PREFIX} Skipping invalid entry in ${MANIFEST_FILENAME} \u2014 must be an object:`, entry);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const candidate = entry;
|
|
33
|
+
if (!isSafeId(candidate.id) || !isModuleEntry(candidate.entry)) {
|
|
34
|
+
console.warn(
|
|
35
|
+
`${LOG_PREFIX} Skipping invalid entry in ${MANIFEST_FILENAME} \u2014 id must be a safe non-empty string and entry must be a string or [string, object] tuple:`,
|
|
36
|
+
entry
|
|
37
|
+
);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
valid.push({ ...candidate, id: candidate.id, entry: candidate.entry });
|
|
41
|
+
}
|
|
42
|
+
return valid;
|
|
43
|
+
};
|
|
44
|
+
const findManifestPath = async (rootDir) => {
|
|
45
|
+
const candidates = [resolve(rootDir, MANIFEST_FILENAME), resolve(rootDir, `build/${MANIFEST_FILENAME}`)];
|
|
46
|
+
for (const p of candidates) {
|
|
47
|
+
try {
|
|
48
|
+
await access(p);
|
|
49
|
+
return p;
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
const loadExtensionsSync = (rootDir) => {
|
|
56
|
+
const candidates = [resolve(rootDir, MANIFEST_FILENAME), resolve(rootDir, `build/${MANIFEST_FILENAME}`)];
|
|
57
|
+
const manifestPath = candidates.find((p) => existsSync(p));
|
|
58
|
+
if (!manifestPath) {
|
|
59
|
+
console.log(`${LOG_PREFIX} No ${MANIFEST_FILENAME} found \u2014 no extensions will be loaded.`);
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const rawEntries = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
64
|
+
if (!Array.isArray(rawEntries)) {
|
|
65
|
+
console.warn(`${LOG_PREFIX} ${MANIFEST_FILENAME} does not contain an array \u2014 skipping extensions.`);
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
const validEntries = validateEntries([...rawEntries]);
|
|
69
|
+
console.log(
|
|
70
|
+
`${LOG_PREFIX} Loaded ${validEntries.length} of ${rawEntries.length} extension(s) from ${manifestPath}`
|
|
71
|
+
);
|
|
72
|
+
return validEntries;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error(`${LOG_PREFIX} Failed to parse ${MANIFEST_FILENAME} \u2014 skipping extensions.`, error);
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const loadExtensions = async (rootDir) => {
|
|
79
|
+
const manifestPath = await findManifestPath(rootDir);
|
|
80
|
+
if (!manifestPath) {
|
|
81
|
+
console.log(`${LOG_PREFIX} No ${MANIFEST_FILENAME} found \u2014 no extensions will be loaded.`);
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const rawEntries = JSON.parse(await readFile(manifestPath, "utf-8"));
|
|
86
|
+
if (!Array.isArray(rawEntries)) {
|
|
87
|
+
console.warn(`${LOG_PREFIX} ${MANIFEST_FILENAME} does not contain an array \u2014 skipping extensions.`);
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
const valid = validateEntries([...rawEntries]);
|
|
91
|
+
console.log(`${LOG_PREFIX} Loaded ${valid.length} of ${rawEntries.length} extension(s) from ${manifestPath}`);
|
|
92
|
+
return valid;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error(`${LOG_PREFIX} Failed to parse ${MANIFEST_FILENAME} \u2014 skipping extensions.`, error);
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const setupExtensions = async (nuxt, preloaded) => {
|
|
100
|
+
const extensions = preloaded ?? await loadExtensions(nuxt.options.rootDir);
|
|
101
|
+
const sorted = [...extensions].sort((a, b) => (a.priority ?? DEFAULT_PRIORITY) - (b.priority ?? DEFAULT_PRIORITY));
|
|
102
|
+
const enabled = [];
|
|
103
|
+
const skipped = [];
|
|
104
|
+
for (const ext of sorted) {
|
|
105
|
+
(ext.enabled === false ? skipped : enabled).push(ext);
|
|
106
|
+
}
|
|
107
|
+
if (skipped.length > 0) {
|
|
108
|
+
console.log(
|
|
109
|
+
`${LOG_PREFIX} Skipping ${skipped.length} disabled extension(s): ${skipped.map((e) => e.id || "(no id)").join(", ")}`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (enabled.length === 0) {
|
|
113
|
+
console.log(`${LOG_PREFIX} No extensions to load.`);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const loadOrder = enabled.map((e) => `${e.id} (priority ${e.priority ?? DEFAULT_PRIORITY})`).join(", ");
|
|
117
|
+
console.log(`${LOG_PREFIX} Loading ${enabled.length} extension(s) in priority order: ${loadOrder}`);
|
|
118
|
+
for (const ext of enabled) {
|
|
119
|
+
console.log(`${LOG_PREFIX}:${ext.id} Applying runtime config...`);
|
|
120
|
+
if (DANGEROUS_IDS.has(ext.id)) {
|
|
121
|
+
console.warn(`${LOG_PREFIX}:${ext.id} Skipping runtimeConfig injection \u2014 unsafe extension id.`);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (ext.settings && Object.keys(ext.settings).length > 0) {
|
|
125
|
+
nuxt.options.runtimeConfig.public[ext.id] = ext.settings;
|
|
126
|
+
console.log(
|
|
127
|
+
`${LOG_PREFIX}:${ext.id} Injected ${Object.keys(ext.settings).length} public setting(s) into runtimeConfig.public.${ext.id}`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
if (ext.privateSettings && Object.keys(ext.privateSettings).length > 0) {
|
|
131
|
+
nuxt.options.runtimeConfig[ext.id] = ext.privateSettings;
|
|
132
|
+
console.log(
|
|
133
|
+
`${LOG_PREFIX}:${ext.id} Injected ${Object.keys(ext.privateSettings).length} private setting(s) into server-only runtimeConfig.${ext.id} (values not logged)`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
let _cachedExtensions;
|
|
20
140
|
const module$1 = defineNuxtModule({
|
|
21
141
|
meta: {
|
|
22
142
|
name: "@plentymarkets/shop-core",
|
|
23
143
|
configKey: "shopCore"
|
|
24
144
|
},
|
|
25
145
|
defaults: {},
|
|
26
|
-
moduleDependencies
|
|
27
|
-
|
|
28
|
-
|
|
146
|
+
moduleDependencies(nuxt) {
|
|
147
|
+
_cachedExtensions = loadExtensionsSync(nuxt.options._layers[0]?.config.rootDir ?? nuxt.options.rootDir);
|
|
148
|
+
const deps = {
|
|
149
|
+
"@nuxtjs/i18n": { version: ">=9.5.4" }
|
|
150
|
+
};
|
|
151
|
+
for (const ext of _cachedExtensions.toSorted(
|
|
152
|
+
(a, b) => (a.priority ?? DEFAULT_PRIORITY) - (b.priority ?? DEFAULT_PRIORITY)
|
|
153
|
+
)) {
|
|
154
|
+
if (ext.enabled === false) continue;
|
|
155
|
+
const name = Array.isArray(ext.entry) ? ext.entry[0] : ext.entry;
|
|
156
|
+
const options = Array.isArray(ext.entry) ? ext.entry[1] ?? {} : {};
|
|
157
|
+
deps[name] = { defaults: options };
|
|
29
158
|
}
|
|
159
|
+
return deps;
|
|
30
160
|
},
|
|
31
161
|
async setup(_options, nuxt) {
|
|
32
162
|
const resolver = createResolver(import.meta.url);
|
|
33
|
-
const
|
|
34
|
-
const projectRootResolver = createResolver(projectLayer.config.rootDir);
|
|
163
|
+
const projectRootResolver = createResolver(nuxt.options._layers[0]?.config.rootDir ?? nuxt.options.rootDir);
|
|
35
164
|
const buildDirectoryResolver = createResolver(nuxt.options.buildDir);
|
|
165
|
+
await setupExtensions(nuxt, _cachedExtensions);
|
|
36
166
|
nuxt.options.runtimeConfig.public.shopCore = {
|
|
37
167
|
apiUrl: _options.apiUrl,
|
|
38
168
|
configId: _options.configId,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A module entry is either:
|
|
3
|
+
* - a plain package name: `"@agency-x/payments"`
|
|
4
|
+
* - a tuple with inline options: `["@agency-x/payments", { region: "eu" }]`
|
|
5
|
+
*/
|
|
6
|
+
export type ModuleEntry = string | [string, Record<string, unknown>];
|
|
7
|
+
export declare const DEFAULT_PRIORITY = 500;
|
|
8
|
+
export declare const MANIFEST_FILENAME = "module.manifest.json";
|
|
9
|
+
export declare const LOG_PREFIX = "[shop-core | extensions]";
|
|
10
|
+
export declare const DANGEROUS_IDS: Set<string>;
|
|
11
|
+
export interface ExtensionEntry {
|
|
12
|
+
/** Unique identifier for the extension (used as runtimeConfig key). */
|
|
13
|
+
id: string;
|
|
14
|
+
/** The Nuxt module entry point. Supports string or [name, options] tuple. */
|
|
15
|
+
entry: ModuleEntry;
|
|
16
|
+
/** npm version range used by the CLI to add the dependency. Unused at runtime. */
|
|
17
|
+
version?: string;
|
|
18
|
+
/** Load priority — lower numbers load first. */
|
|
19
|
+
priority?: number;
|
|
20
|
+
/** Arbitrary settings injected into runtimeConfig.public[id]. */
|
|
21
|
+
settings?: Record<string, unknown>;
|
|
22
|
+
/** Server-only settings — NOT exposed to the client. */
|
|
23
|
+
privateSettings?: Record<string, unknown>;
|
|
24
|
+
/** Set to false to skip loading this extension. Defaults to true. */
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
}
|
package/dist/types.d.mts
CHANGED
|
@@ -4,6 +4,6 @@ import type { default as Module } from './module.mjs'
|
|
|
4
4
|
|
|
5
5
|
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
6
|
|
|
7
|
-
export { type CacheControlMeta, type Cookie, type CookieGroup, type CookieGroupFromNuxtConfig, type Events, type JsonCookie, type LocalizationMessage, type Notification, type PaymentButtonComponent, type PaymentButtonComponentProps, type SSRMetrics, type ShopCoreConfigInput } from '../dist/runtime/types/index.js'
|
|
7
|
+
export { type CacheControlMeta, type Cookie, type CookieGroup, type CookieGroupFromNuxtConfig, type Events, type ExtensionEntry, type JsonCookie, type LocalizationMessage, type Notification, type PaymentButtonComponent, type PaymentButtonComponentProps, type SSRMetrics, type ShopCoreConfigInput } from '../dist/runtime/types/index.js'
|
|
8
8
|
|
|
9
9
|
export { default } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plentymarkets/shop-core",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.4",
|
|
4
4
|
"description": "Core module for PlentyONE Shop",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@noble/hashes": "^2.0.1",
|
|
53
|
-
"@plentymarkets/shop-api": "^0.
|
|
53
|
+
"@plentymarkets/shop-api": "^0.165.1",
|
|
54
54
|
"@vue-storefront/sdk": "^3.4.1",
|
|
55
55
|
"cookie-es": "^2.0.0",
|
|
56
56
|
"knitwork": "^1.3.0",
|