@haus-tech/product-import-export-plugin 3.0.4 → 3.0.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.
Files changed (52) hide show
  1. package/package.json +1 -1
  2. package/dist/api/plugin.controller.d.ts +0 -8
  3. package/dist/api/plugin.controller.js +0 -49
  4. package/dist/api/product-export.controller.d.ts +0 -14
  5. package/dist/api/product-export.controller.js +0 -117
  6. package/dist/api/product-import.controller.d.ts +0 -11
  7. package/dist/api/product-import.controller.js +0 -63
  8. package/dist/constants.d.ts +0 -2
  9. package/dist/constants.js +0 -5
  10. package/dist/helpers/generate-asset-hash.d.ts +0 -2
  11. package/dist/helpers/generate-asset-hash.js +0 -15
  12. package/dist/helpers/normalize-string.d.ts +0 -1
  13. package/dist/helpers/normalize-string.js +0 -16
  14. package/dist/helpers/remove-update-at-fields.d.ts +0 -5
  15. package/dist/helpers/remove-update-at-fields.js +0 -19
  16. package/dist/index.d.ts +0 -1
  17. package/dist/index.js +0 -17
  18. package/dist/product-import-export.plugin.d.ts +0 -13
  19. package/dist/product-import-export.plugin.js +0 -153
  20. package/dist/providers/import-providers/asset-importer.d.ts +0 -31
  21. package/dist/providers/import-providers/asset-importer.js +0 -158
  22. package/dist/providers/import-providers/import-parser.d.ts +0 -137
  23. package/dist/providers/import-providers/import-parser.js +0 -600
  24. package/dist/providers/import-providers/product-importer.d.ts +0 -48
  25. package/dist/providers/import-providers/product-importer.js +0 -753
  26. package/dist/services/extended-fast-importer.service.d.ts +0 -44
  27. package/dist/services/extended-fast-importer.service.js +0 -462
  28. package/dist/services/product-export.service.d.ts +0 -23
  29. package/dist/services/product-export.service.js +0 -344
  30. package/dist/services/product-import.service.d.ts +0 -22
  31. package/dist/services/product-import.service.js +0 -84
  32. package/dist/types.d.ts +0 -41
  33. package/dist/types.js +0 -2
  34. package/dist/ui/components/export-dialog.component.d.ts +0 -43
  35. package/dist/ui/components/export-dialog.component.html +0 -78
  36. package/dist/ui/components/export-dialog.component.js +0 -108
  37. package/dist/ui/components/export-dialog.component.ts +0 -142
  38. package/dist/ui/components/product-import.component.d.ts +0 -57
  39. package/dist/ui/components/product-import.component.html +0 -123
  40. package/dist/ui/components/product-import.component.js +0 -413
  41. package/dist/ui/components/product-import.component.ts +0 -550
  42. package/dist/ui/product-export.service.d.ts +0 -14
  43. package/dist/ui/product-export.service.js +0 -107
  44. package/dist/ui/product-export.service.ts +0 -107
  45. package/dist/ui/providers.d.ts +0 -2
  46. package/dist/ui/providers.js +0 -49
  47. package/dist/ui/providers.ts +0 -57
  48. package/dist/ui/routes.d.ts +0 -31
  49. package/dist/ui/routes.js +0 -12
  50. package/dist/ui/routes.ts +0 -11
  51. package/dist/ui/translations/en.json +0 -52
  52. package/dist/ui/translations/sv.json +0 -52
@@ -1,158 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ExtendedAssetImporter = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const core_1 = require("@vendure/core");
15
- const generate_asset_hash_1 = require("../../helpers/generate-asset-hash");
16
- /**
17
- * @description
18
- * This service creates new {@link Asset} entities based on string paths provided in the CSV
19
- * import format. The source files are resolved by joining the value of `importExportOptions.importAssetsDir`
20
- * with the asset path. This service is used internally by the {@link Importer} service.
21
- *
22
- * @docsCategory import-export
23
- */
24
- let ExtendedAssetImporter = class ExtendedAssetImporter {
25
- configService;
26
- assetService;
27
- connection;
28
- channelService;
29
- assetMap = new Map();
30
- defaultChannel;
31
- /** @internal */
32
- constructor(configService, assetService, connection, channelService) {
33
- this.configService = configService;
34
- this.assetService = assetService;
35
- this.connection = connection;
36
- this.channelService = channelService;
37
- }
38
- async onModuleInit() {
39
- this.defaultChannel = await this.channelService.getDefaultChannel();
40
- }
41
- /**
42
- * @description
43
- * Creates Asset entities for the given paths, using the assetMap cache to prevent the
44
- * creation of duplicates.
45
- */
46
- async getAssets(assetPaths, ctx) {
47
- const assets = [];
48
- const errors = [];
49
- const { assetImportStrategy } = this.configService.importExportOptions;
50
- const uniqueAssetPaths = new Set(assetPaths);
51
- for (const assetPath of uniqueAssetPaths.values()) {
52
- const cachedAsset = this.assetMap.get(assetPath.url);
53
- if (cachedAsset) {
54
- if (cachedAsset.channels.some((channel) => channel.id !== ctx?.channelId)) {
55
- await this.connection
56
- .getRepository(ctx, core_1.Asset)
57
- .createQueryBuilder()
58
- .relation(core_1.Asset, 'channels')
59
- .of(cachedAsset.id)
60
- .add(ctx?.channel);
61
- cachedAsset.channels.push(ctx?.channel);
62
- }
63
- if (cachedAsset.name !== assetPath.name && assetPath.name) {
64
- this.connection.getRepository(ctx, core_1.Asset).update(cachedAsset.id, {
65
- name: assetPath.name,
66
- });
67
- // Update the cached asset with the new name
68
- this.assetMap.set(assetPath.url, { ...cachedAsset, name: assetPath.name });
69
- assets.push({ ...cachedAsset, name: assetPath.name });
70
- }
71
- else {
72
- assets.push(cachedAsset);
73
- }
74
- }
75
- else {
76
- try {
77
- const assetHash = (0, generate_asset_hash_1.generateAssetHash)({
78
- source: assetPath.url,
79
- });
80
- const assetFromHash = await this.connection.getRepository(ctx, core_1.Asset).findOne({
81
- where: {
82
- customFields: {
83
- hash: assetHash,
84
- },
85
- },
86
- relations: ['channels'],
87
- });
88
- if (assetFromHash) {
89
- // Check if the asset name has changed
90
- if ((assetPath.name && assetFromHash.name !== assetPath.name) ||
91
- assetFromHash.channels.some((channel) => channel.id !== ctx?.channelId)) {
92
- assetFromHash.name = assetPath.name || assetFromHash.name;
93
- assetFromHash.channels.push(ctx?.channel);
94
- await this.connection.getRepository(ctx, core_1.Asset).save(assetFromHash);
95
- }
96
- this.assetMap.set(assetPath.url, assetFromHash);
97
- assets.push(assetFromHash);
98
- continue;
99
- }
100
- const stream = await assetImportStrategy.getStreamFromPath(assetPath.url);
101
- if (stream) {
102
- const createdAsset = await this.assetService.createFromFileStream(stream, assetPath.url, ctx);
103
- if ((0, core_1.isGraphQlErrorResult)(createdAsset)) {
104
- errors.push(createdAsset.message);
105
- }
106
- else {
107
- let assetToUpdate = createdAsset;
108
- let shouldDeleteCreatedAsset = false;
109
- const assetFromHash = await this.connection.getRepository(ctx, core_1.Asset).findOne({
110
- where: {
111
- customFields: {
112
- hash: assetHash,
113
- },
114
- },
115
- relations: ['channels'],
116
- });
117
- if (assetFromHash) {
118
- shouldDeleteCreatedAsset = true;
119
- assetToUpdate = { ...assetFromHash, name: assetPath.name || assetFromHash.name };
120
- }
121
- if (assetPath.id) {
122
- shouldDeleteCreatedAsset = true;
123
- assetToUpdate = {
124
- ...assetToUpdate,
125
- id: assetPath.id,
126
- };
127
- }
128
- this.assetMap.set(assetPath.url, assetToUpdate);
129
- assets.push(assetToUpdate);
130
- assetToUpdate.name = assetPath.name || assetToUpdate.name;
131
- assetToUpdate.channels.push(ctx?.channel);
132
- assetToUpdate.customFields = {
133
- ...assetToUpdate.customFields,
134
- hash: assetHash,
135
- };
136
- await this.connection.getRepository(ctx, core_1.Asset).save(assetToUpdate);
137
- if (shouldDeleteCreatedAsset) {
138
- this.connection.getRepository(ctx, core_1.Asset).delete(createdAsset.id);
139
- }
140
- }
141
- }
142
- }
143
- catch (e) {
144
- errors.push(e.message);
145
- }
146
- }
147
- }
148
- return { assets, errors };
149
- }
150
- };
151
- ExtendedAssetImporter = __decorate([
152
- (0, common_1.Injectable)(),
153
- __metadata("design:paramtypes", [core_1.ConfigService,
154
- core_1.AssetService,
155
- core_1.TransactionalConnection,
156
- core_1.ChannelService])
157
- ], ExtendedAssetImporter);
158
- exports.ExtendedAssetImporter = ExtendedAssetImporter;
@@ -1,137 +0,0 @@
1
- /// <reference types="node" />
2
- import { GlobalFlag, LanguageCode } from '@vendure/common/lib/generated-types';
3
- import { ConfigService } from '@vendure/core';
4
- import { Stream } from 'stream';
5
- /**
6
- * @description
7
- * The intermediate representation of an OptionGroup after it has been parsed
8
- * by the {@link ImportParser}.
9
- *
10
- * @docsCategory import-export
11
- * @docsPage ImportParser
12
- */
13
- export interface ParsedOptionGroup {
14
- translations: Array<{
15
- languageCode: LanguageCode;
16
- name: string;
17
- values: string[];
18
- }>;
19
- }
20
- /**
21
- * @description
22
- * The intermediate representation of a Facet after it has been parsed
23
- * by the {@link ImportParser}.
24
- *
25
- * @docsCategory import-export
26
- * @docsPage ImportParser
27
- */
28
- export interface ParsedFacet {
29
- translations: Array<{
30
- languageCode: LanguageCode;
31
- facet: string;
32
- value: string;
33
- }>;
34
- }
35
- export interface ParsedAsset {
36
- id?: string;
37
- url: string;
38
- name?: string;
39
- }
40
- /**
41
- * @description
42
- * The intermediate representation of a ProductVariant after it has been parsed
43
- * by the {@link ImportParser}.
44
- *
45
- * @docsCategory import-export
46
- * @docsPage ImportParser
47
- */
48
- export interface ParsedProductVariant {
49
- sku: string;
50
- price: number;
51
- taxCategory: string;
52
- stockOnHand: number;
53
- trackInventory: GlobalFlag;
54
- assetPaths: string[];
55
- assetsJson?: ParsedAsset[];
56
- facets: ParsedFacet[];
57
- translations: Array<{
58
- languageCode: LanguageCode;
59
- optionValues: string[];
60
- customFields: {
61
- [name: string]: string;
62
- };
63
- }>;
64
- }
65
- /**
66
- * @description
67
- * The intermediate representation of a Product after it has been parsed
68
- * by the {@link ImportParser}.
69
- *
70
- * @docsCategory import-export
71
- * @docsPage ImportParser
72
- */
73
- export interface ParsedProduct {
74
- assetPaths: string[];
75
- assetsJson?: ParsedAsset[];
76
- optionGroups: ParsedOptionGroup[];
77
- facets: ParsedFacet[];
78
- translations: Array<{
79
- languageCode: LanguageCode;
80
- name: string;
81
- slug: string;
82
- description: string;
83
- customFields: {
84
- [name: string]: string;
85
- };
86
- }>;
87
- }
88
- /**
89
- * @description
90
- * The data structure into which an import CSV file is parsed by the
91
- * {@link ImportParser} `parseProducts()` method.
92
- *
93
- * @docsCategory import-export
94
- * @docsPage ImportParser
95
- */
96
- export interface ParsedProductWithVariants {
97
- product: ParsedProduct;
98
- variants: ParsedProductVariant[];
99
- }
100
- /**
101
- * @description
102
- * The result returned by the {@link ImportParser} `parseProducts()` method.
103
- *
104
- * @docsCategory import-export
105
- * @docsPage ImportParser
106
- */
107
- export interface ParseResult<T> {
108
- results: T[];
109
- errors: string[];
110
- processed: number;
111
- }
112
- /**
113
- * @description
114
- * Validates and parses CSV files into a data structure which can then be used to created new entities.
115
- * This is used internally by the {@link Importer}.
116
- *
117
- * @docsCategory import-export
118
- * @docsPage ImportParser
119
- * @docsWeight 0
120
- */
121
- export declare class ImportParser {
122
- private configService;
123
- /** @internal */
124
- constructor(configService: ConfigService);
125
- /**
126
- * @description
127
- * Parses the contents of the [product import CSV file](/guides/developer-guide/importing-data/#product-import-format) and
128
- * returns a data structure which can then be used to populate Vendure using the {@link FastImporterService}.
129
- */
130
- parseProducts(input: string | Stream, mainLanguage?: LanguageCode): Promise<ParseResult<ParsedProductWithVariants>>;
131
- private processRawRecords;
132
- private validateCustomFields;
133
- private isTranslatable;
134
- private validateHeaderTranslations;
135
- private parseProductFromRecord;
136
- private parseVariantFromRecord;
137
- }