@empty-complete-org/medusa-product-attributes 0.12.2 → 0.14.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/.medusa/server/src/admin/index.js +396 -29
- package/.medusa/server/src/admin/index.mjs +371 -21
- package/.medusa/server/src/api/admin/attribute-presets/[id]/apply/route.d.ts +2 -0
- package/.medusa/server/src/api/admin/attribute-presets/[id]/apply/route.js +12 -0
- package/.medusa/server/src/api/admin/attribute-presets/[id]/apply/route.js.map +1 -0
- package/.medusa/server/src/api/admin/attribute-presets/route.d.ts +4 -0
- package/.medusa/server/src/api/admin/attribute-presets/route.js +24 -0
- package/.medusa/server/src/api/admin/attribute-presets/route.js.map +1 -0
- package/.medusa/server/src/modules/product-attributes/index.d.ts +14 -0
- package/.medusa/server/src/modules/product-attributes/migrations/Migration20260406120000.d.ts +5 -0
- package/.medusa/server/src/modules/product-attributes/migrations/Migration20260406120000.js +32 -0
- package/.medusa/server/src/modules/product-attributes/migrations/Migration20260406120000.js.map +1 -0
- package/.medusa/server/src/modules/product-attributes/models/attribute-preset.d.ts +9 -0
- package/.medusa/server/src/modules/product-attributes/models/attribute-preset.js +13 -0
- package/.medusa/server/src/modules/product-attributes/models/attribute-preset.js.map +1 -0
- package/.medusa/server/src/modules/product-attributes/service.d.ts +78 -0
- package/.medusa/server/src/modules/product-attributes/service.js +38 -4
- package/.medusa/server/src/modules/product-attributes/service.js.map +1 -1
- package/package.json +4 -1
|
@@ -35,6 +35,14 @@ declare const CustomAttributeService_base: import("@medusajs/framework/utils").M
|
|
|
35
35
|
product_custom_attributes: import("@medusajs/framework/utils").HasMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "product_custom_attribute">>;
|
|
36
36
|
}>, "category_custom_attribute">, undefined>;
|
|
37
37
|
}>, "product_custom_attribute">;
|
|
38
|
+
AttributePreset: import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
|
|
39
|
+
id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
|
|
40
|
+
key: import("@medusajs/framework/utils").TextProperty;
|
|
41
|
+
label: import("@medusajs/framework/utils").TextProperty;
|
|
42
|
+
type: import("@medusajs/framework/utils").TextProperty;
|
|
43
|
+
unit: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
|
|
44
|
+
description: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
|
|
45
|
+
}>, "attribute_preset">;
|
|
38
46
|
}>>;
|
|
39
47
|
declare class CustomAttributeService extends CustomAttributeService_base {
|
|
40
48
|
getCategoryAttributes(categoryId: string): Promise<{
|
|
@@ -218,6 +226,76 @@ declare class CustomAttributeService extends CustomAttributeService_base {
|
|
|
218
226
|
deleted_at: Date | null;
|
|
219
227
|
category_custom_attribute_id: string;
|
|
220
228
|
}[]>;
|
|
229
|
+
listPresets(): Promise<{
|
|
230
|
+
id: string;
|
|
231
|
+
key: string;
|
|
232
|
+
label: string;
|
|
233
|
+
type: string;
|
|
234
|
+
unit: string | null;
|
|
235
|
+
description: string | null;
|
|
236
|
+
created_at: Date;
|
|
237
|
+
updated_at: Date;
|
|
238
|
+
deleted_at: Date | null;
|
|
239
|
+
}[]>;
|
|
240
|
+
createPreset(data: {
|
|
241
|
+
label: string;
|
|
242
|
+
type?: string;
|
|
243
|
+
unit?: string | null;
|
|
244
|
+
description?: string | null;
|
|
245
|
+
}): Promise<{
|
|
246
|
+
id: string;
|
|
247
|
+
key: string;
|
|
248
|
+
label: string;
|
|
249
|
+
type: string;
|
|
250
|
+
unit: string | null;
|
|
251
|
+
description: string | null;
|
|
252
|
+
created_at: Date;
|
|
253
|
+
updated_at: Date;
|
|
254
|
+
deleted_at: Date | null;
|
|
255
|
+
}>;
|
|
256
|
+
updatePreset(id: string, data: {
|
|
257
|
+
label?: string;
|
|
258
|
+
type?: string;
|
|
259
|
+
unit?: string | null;
|
|
260
|
+
description?: string | null;
|
|
261
|
+
deleted_at?: string;
|
|
262
|
+
}): Promise<{
|
|
263
|
+
id: string;
|
|
264
|
+
key: string;
|
|
265
|
+
label: string;
|
|
266
|
+
type: string;
|
|
267
|
+
unit: string | null;
|
|
268
|
+
description: string | null;
|
|
269
|
+
created_at: Date;
|
|
270
|
+
updated_at: Date;
|
|
271
|
+
deleted_at: Date | null;
|
|
272
|
+
}[]>;
|
|
273
|
+
applyPresetToCategory(presetId: string, categoryId: string): Promise<{
|
|
274
|
+
id: string;
|
|
275
|
+
key: string;
|
|
276
|
+
type: string;
|
|
277
|
+
label: string;
|
|
278
|
+
unit: string | null;
|
|
279
|
+
sort_order: number;
|
|
280
|
+
category_id: string;
|
|
281
|
+
is_standard: boolean;
|
|
282
|
+
product_custom_attributes: {
|
|
283
|
+
id: string;
|
|
284
|
+
product_id: string;
|
|
285
|
+
value: string;
|
|
286
|
+
value_numeric: number | null;
|
|
287
|
+
value_file: string | null;
|
|
288
|
+
category_custom_attribute: /*elided*/ any;
|
|
289
|
+
raw_value_numeric: Record<string, unknown> | null;
|
|
290
|
+
created_at: Date;
|
|
291
|
+
updated_at: Date;
|
|
292
|
+
deleted_at: Date | null;
|
|
293
|
+
category_custom_attribute_id: string;
|
|
294
|
+
}[];
|
|
295
|
+
created_at: Date;
|
|
296
|
+
updated_at: Date;
|
|
297
|
+
deleted_at: Date | null;
|
|
298
|
+
}>;
|
|
221
299
|
private generateKey;
|
|
222
300
|
}
|
|
223
301
|
export default CustomAttributeService;
|
|
@@ -4,11 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const utils_1 = require("@medusajs/framework/utils");
|
|
7
|
+
const transliteration_1 = require("transliteration");
|
|
7
8
|
const category_custom_attribute_1 = __importDefault(require("./models/category-custom-attribute"));
|
|
8
9
|
const product_custom_attribute_1 = __importDefault(require("./models/product-custom-attribute"));
|
|
10
|
+
const attribute_preset_1 = __importDefault(require("./models/attribute-preset"));
|
|
9
11
|
const models = {
|
|
10
12
|
CategoryCustomAttribute: category_custom_attribute_1.default,
|
|
11
13
|
ProductCustomAttribute: product_custom_attribute_1.default,
|
|
14
|
+
AttributePreset: attribute_preset_1.default,
|
|
12
15
|
};
|
|
13
16
|
// @ts-ignore - MedusaService dynamically generates methods based on models
|
|
14
17
|
class CustomAttributeService extends (0, utils_1.MedusaService)(models) {
|
|
@@ -73,11 +76,42 @@ class CustomAttributeService extends (0, utils_1.MedusaService)(models) {
|
|
|
73
76
|
relations: ["category_custom_attribute"],
|
|
74
77
|
});
|
|
75
78
|
}
|
|
79
|
+
async listPresets() {
|
|
80
|
+
// @ts-ignore - generated
|
|
81
|
+
return await this.listAttributePresets({ deleted_at: null });
|
|
82
|
+
}
|
|
83
|
+
async createPreset(data) {
|
|
84
|
+
const key = this.generateKey(data.label);
|
|
85
|
+
// @ts-ignore - generated
|
|
86
|
+
return await this.createAttributePresets({
|
|
87
|
+
label: data.label,
|
|
88
|
+
key,
|
|
89
|
+
type: data.type || "text",
|
|
90
|
+
unit: data.unit ?? null,
|
|
91
|
+
description: data.description ?? null,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async updatePreset(id, data) {
|
|
95
|
+
const updateData = { ...data };
|
|
96
|
+
if (data.label) {
|
|
97
|
+
updateData.key = this.generateKey(data.label);
|
|
98
|
+
}
|
|
99
|
+
// @ts-ignore - generated
|
|
100
|
+
return await this.updateAttributePresets([{ id, ...updateData }]);
|
|
101
|
+
}
|
|
102
|
+
async applyPresetToCategory(presetId, categoryId) {
|
|
103
|
+
// @ts-ignore - generated
|
|
104
|
+
const preset = await this.retrieveAttributePreset(presetId);
|
|
105
|
+
return await this.createCategoryAttribute({
|
|
106
|
+
label: preset.label,
|
|
107
|
+
type: preset.type,
|
|
108
|
+
unit: preset.unit,
|
|
109
|
+
category_id: categoryId,
|
|
110
|
+
is_standard: true,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
76
113
|
generateKey(label) {
|
|
77
|
-
return label
|
|
78
|
-
.toLowerCase()
|
|
79
|
-
.replace(/[^a-z0-9]+/g, "_")
|
|
80
|
-
.replace(/^_|_$/g, "");
|
|
114
|
+
return (0, transliteration_1.slugify)(label, { separator: "_", lowercase: true }) || "attr";
|
|
81
115
|
}
|
|
82
116
|
}
|
|
83
117
|
exports.default = CustomAttributeService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../../src/modules/product-attributes/service.ts"],"names":[],"mappings":";;;;;AAAA,qDAAyD;AACzD,mGAAwE;AACxE,iGAAsE;
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../../src/modules/product-attributes/service.ts"],"names":[],"mappings":";;;;;AAAA,qDAAyD;AACzD,qDAAyC;AACzC,mGAAwE;AACxE,iGAAsE;AACtE,iFAAuD;AAEvD,MAAM,MAAM,GAAG;IACb,uBAAuB,EAAvB,mCAAuB;IACvB,sBAAsB,EAAtB,kCAAsB;IACtB,eAAe,EAAf,0BAAe;CAChB,CAAA;AAID,2EAA2E;AAC3E,MAAM,sBAAuB,SAAQ,IAAA,qBAAa,EAAC,MAAM,CAAC;IACxD,KAAK,CAAC,qBAAqB,CAAC,UAAkB;QAC5C,iDAAiD;QACjD,OAAO,MAAM,IAAI,CAAC,4BAA4B,CAAC;YAC7C,WAAW,EAAE,UAAU;YACvB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,0BAA0B,CAAC,WAAqB;QACpD,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7C,OAAO,EAAE,CAAA;QACX,CAAC;QACD,iDAAiD;QACjD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,4BAA4B,CAAC;YACzD,W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AC,EAAE,EAAE,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,CAAA;IACnE,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,QAAgB,EAAE,UAAkB;QAC9D,yBAAyB;QACzB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAA;QAC3D,OAAO,MAAM,IAAI,CAAC,uBAAuB,CAAC;YACxC,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,WAAW,EAAE,UAAU;YACvB,WAAW,EAAE,IAAI;SAClB,CAAC,CAAA;IACJ,CAAC;IAEO,WAAW,CAAC,KAAa;QAC/B,OAAO,IAAA,yBAAO,EAAC,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,IAAI,MAAM,CAAA;IACtE,CAAC;CACF;AAED,kBAAe,sBAAsB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empty-complete-org/medusa-product-attributes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Custom attributes module for Medusa v2 with support for text, number, file types and units of measurement",
|
|
5
5
|
"author": "empty-complete",
|
|
6
6
|
"license": "MIT",
|
|
@@ -82,5 +82,8 @@
|
|
|
82
82
|
},
|
|
83
83
|
"publishConfig": {
|
|
84
84
|
"registry": "https://registry.npmjs.org"
|
|
85
|
+
},
|
|
86
|
+
"dependencies": {
|
|
87
|
+
"transliteration": "^2.6.1"
|
|
85
88
|
}
|
|
86
89
|
}
|