@n8n/backend-module-apps 0.0.0-stage → 0.0.0-tp-setup

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 (66) hide show
  1. package/dist/app-artifact.entity.d.ts +10 -0
  2. package/dist/app-artifact.entity.js +48 -0
  3. package/dist/app-artifact.entity.js.map +1 -0
  4. package/dist/app-artifact.repository.d.ts +15 -0
  5. package/dist/app-artifact.repository.js +104 -0
  6. package/dist/app-artifact.repository.js.map +1 -0
  7. package/dist/app-artifact.service.d.ts +20 -0
  8. package/dist/app-artifact.service.js +118 -0
  9. package/dist/app-artifact.service.js.map +1 -0
  10. package/dist/app-retention.service.d.ts +16 -0
  11. package/dist/app-retention.service.js +74 -0
  12. package/dist/app-retention.service.js.map +1 -0
  13. package/dist/app-storage-cleanup.task.d.ts +17 -0
  14. package/dist/app-storage-cleanup.task.js +57 -0
  15. package/dist/app-storage-cleanup.task.js.map +1 -0
  16. package/dist/app-storage-lock.d.ts +1 -0
  17. package/dist/app-storage-lock.js +8 -0
  18. package/dist/app-storage-lock.js.map +1 -0
  19. package/dist/app-version.entity.d.ts +12 -0
  20. package/dist/app-version.entity.js +56 -0
  21. package/dist/app-version.entity.js.map +1 -0
  22. package/dist/app-version.repository.d.ts +18 -0
  23. package/dist/app-version.repository.js +90 -0
  24. package/dist/app-version.repository.js.map +1 -0
  25. package/dist/app-version.service.d.ts +30 -0
  26. package/dist/app-version.service.js +124 -0
  27. package/dist/app-version.service.js.map +1 -0
  28. package/dist/app.entity.d.ts +11 -0
  29. package/dist/app.entity.js +53 -0
  30. package/dist/app.entity.js.map +1 -0
  31. package/dist/app.repository.d.ts +19 -0
  32. package/dist/app.repository.js +116 -0
  33. package/dist/app.repository.js.map +1 -0
  34. package/dist/apps-list.controller.d.ts +9 -0
  35. package/dist/apps-list.controller.js +39 -0
  36. package/dist/apps-list.controller.js.map +1 -0
  37. package/dist/apps.config.d.ts +8 -0
  38. package/dist/apps.config.js +54 -0
  39. package/dist/apps.config.js.map +1 -0
  40. package/dist/apps.controller.d.ts +48 -0
  41. package/dist/apps.controller.js +82 -0
  42. package/dist/apps.controller.js.map +1 -0
  43. package/dist/apps.module.d.ts +9 -0
  44. package/dist/apps.module.js +43 -0
  45. package/dist/apps.module.js.map +1 -0
  46. package/dist/apps.service.d.ts +18 -0
  47. package/dist/apps.service.js +93 -0
  48. package/dist/apps.service.js.map +1 -0
  49. package/dist/build.tsbuildinfo +1 -0
  50. package/dist/index.d.ts +10 -0
  51. package/dist/index.js +25 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/storage/app-archive.d.ts +16 -0
  54. package/dist/storage/app-archive.js +180 -0
  55. package/dist/storage/app-archive.js.map +1 -0
  56. package/dist/storage/app-blob-store.d.ts +21 -0
  57. package/dist/storage/app-blob-store.js +93 -0
  58. package/dist/storage/app-blob-store.js.map +1 -0
  59. package/dist/storage/app-version-stores.d.ts +20 -0
  60. package/dist/storage/app-version-stores.js +10 -0
  61. package/dist/storage/app-version-stores.js.map +1 -0
  62. package/dist/storage/snapshot-app-version-stores.d.ts +30 -0
  63. package/dist/storage/snapshot-app-version-stores.js +122 -0
  64. package/dist/storage/snapshot-app-version-stores.js.map +1 -0
  65. package/package.json +67 -4
  66. package/README.md +0 -3
@@ -0,0 +1,10 @@
1
+ export { App } from './app.entity';
2
+ export { AppVersion } from './app-version.entity';
3
+ export { AppArtifact, type AppArtifactRef } from './app-artifact.entity';
4
+ export { AppRepository } from './app.repository';
5
+ export { AppsService } from './apps.service';
6
+ export { AppVersionService } from './app-version.service';
7
+ export { AppVersionRepository } from './app-version.repository';
8
+ export { AppArtifactService } from './app-artifact.service';
9
+ export { AppArtifactRepository } from './app-artifact.repository';
10
+ export { AppSourceVersionStore, AppBuildResultStore, type AppFiles, type NewSourceVersion, } from './storage/app-version-stores';
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppBuildResultStore = exports.AppSourceVersionStore = exports.AppArtifactRepository = exports.AppArtifactService = exports.AppVersionRepository = exports.AppVersionService = exports.AppsService = exports.AppRepository = exports.AppArtifact = exports.AppVersion = exports.App = void 0;
4
+ var app_entity_1 = require("./app.entity");
5
+ Object.defineProperty(exports, "App", { enumerable: true, get: function () { return app_entity_1.App; } });
6
+ var app_version_entity_1 = require("./app-version.entity");
7
+ Object.defineProperty(exports, "AppVersion", { enumerable: true, get: function () { return app_version_entity_1.AppVersion; } });
8
+ var app_artifact_entity_1 = require("./app-artifact.entity");
9
+ Object.defineProperty(exports, "AppArtifact", { enumerable: true, get: function () { return app_artifact_entity_1.AppArtifact; } });
10
+ var app_repository_1 = require("./app.repository");
11
+ Object.defineProperty(exports, "AppRepository", { enumerable: true, get: function () { return app_repository_1.AppRepository; } });
12
+ var apps_service_1 = require("./apps.service");
13
+ Object.defineProperty(exports, "AppsService", { enumerable: true, get: function () { return apps_service_1.AppsService; } });
14
+ var app_version_service_1 = require("./app-version.service");
15
+ Object.defineProperty(exports, "AppVersionService", { enumerable: true, get: function () { return app_version_service_1.AppVersionService; } });
16
+ var app_version_repository_1 = require("./app-version.repository");
17
+ Object.defineProperty(exports, "AppVersionRepository", { enumerable: true, get: function () { return app_version_repository_1.AppVersionRepository; } });
18
+ var app_artifact_service_1 = require("./app-artifact.service");
19
+ Object.defineProperty(exports, "AppArtifactService", { enumerable: true, get: function () { return app_artifact_service_1.AppArtifactService; } });
20
+ var app_artifact_repository_1 = require("./app-artifact.repository");
21
+ Object.defineProperty(exports, "AppArtifactRepository", { enumerable: true, get: function () { return app_artifact_repository_1.AppArtifactRepository; } });
22
+ var app_version_stores_1 = require("./storage/app-version-stores");
23
+ Object.defineProperty(exports, "AppSourceVersionStore", { enumerable: true, get: function () { return app_version_stores_1.AppSourceVersionStore; } });
24
+ Object.defineProperty(exports, "AppBuildResultStore", { enumerable: true, get: function () { return app_version_stores_1.AppBuildResultStore; } });
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAAmC;AAA1B,iGAAA,GAAG,OAAA;AACZ,2DAAkD;AAAzC,gHAAA,UAAU,OAAA;AACnB,6DAAyE;AAAhE,kHAAA,WAAW,OAAA;AACpB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,6DAA0D;AAAjD,wHAAA,iBAAiB,OAAA;AAC1B,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA;AAC7B,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA;AAC3B,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAC9B,mEAKsC;AAJrC,2HAAA,qBAAqB,OAAA;AACrB,yHAAA,mBAAmB,OAAA"}
@@ -0,0 +1,16 @@
1
+ import type { AppFiles } from './app-version-stores';
2
+ import { AppsConfig } from '../apps.config';
3
+ export declare class AppArchive {
4
+ private readonly config;
5
+ constructor(config: AppsConfig);
6
+ pack(files: AppFiles, bundle?: boolean): Promise<Buffer>;
7
+ unpack(body: Buffer, bundle?: boolean): Promise<Map<string, Buffer>>;
8
+ listFiles(body: Buffer): Promise<string[]>;
9
+ readFile(body: Buffer, filePath: string): Promise<Buffer | null>;
10
+ private parse;
11
+ private filePath;
12
+ private checkFilePaths;
13
+ private checkLimits;
14
+ private checkCompressedSize;
15
+ private checkBundle;
16
+ }
@@ -0,0 +1,180 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AppArchive = void 0;
16
+ const di_1 = require("@n8n/di");
17
+ const errors_1 = require("@n8n/errors");
18
+ const node_path_1 = __importDefault(require("node:path"));
19
+ const node_stream_1 = require("node:stream");
20
+ const promises_1 = require("node:stream/promises");
21
+ const apps_config_1 = require("../apps.config");
22
+ const CHUNK_SIZE = 64 * 1024;
23
+ function* slices(body) {
24
+ for (let offset = 0; offset < body.length; offset += CHUNK_SIZE) {
25
+ yield body.subarray(offset, offset + CHUNK_SIZE);
26
+ }
27
+ }
28
+ let AppArchive = class AppArchive {
29
+ constructor(config) {
30
+ this.config = config;
31
+ }
32
+ async pack(files, bundle = false) {
33
+ const normalized = new Map();
34
+ let size = 0;
35
+ for (const [name, content] of files) {
36
+ const filePath = this.filePath(name);
37
+ if (normalized.has(filePath))
38
+ throw new errors_1.BadRequestError('App artifact contains duplicate paths.');
39
+ normalized.set(filePath, content);
40
+ size += content.length;
41
+ this.checkLimits(size, normalized.size + 1);
42
+ }
43
+ this.checkFilePaths(new Set(normalized.keys()));
44
+ this.checkBundle(normalized, bundle);
45
+ const { Header, Pack, ReadEntry } = await import('tar');
46
+ const archive = new Pack({ gzip: { portable: true }, portable: true, noMtime: true });
47
+ const root = new ReadEntry(new Header({ path: './', size: 0, mode: 0o755, type: 'Directory' }));
48
+ root.end();
49
+ archive.write(root);
50
+ for (const [name, content] of normalized) {
51
+ const entry = new ReadEntry(new Header({ path: name, size: content.length, mode: 0o644, type: 'File' }));
52
+ entry.end(content);
53
+ archive.write(entry);
54
+ }
55
+ archive.end();
56
+ const chunks = [];
57
+ let compressedSize = 0;
58
+ for await (const chunk of archive) {
59
+ compressedSize += chunk.length;
60
+ this.checkCompressedSize(compressedSize);
61
+ chunks.push(chunk);
62
+ }
63
+ return Buffer.concat(chunks);
64
+ }
65
+ async unpack(body, bundle = false) {
66
+ const { files } = await this.parse(body, () => true);
67
+ this.checkBundle(files, bundle);
68
+ return files;
69
+ }
70
+ async listFiles(body) {
71
+ const { fileNames } = await this.parse(body, () => false);
72
+ return [...fileNames].sort();
73
+ }
74
+ async readFile(body, filePath) {
75
+ const normalizedPath = this.filePath(filePath);
76
+ const { files } = await this.parse(body, (name) => name === normalizedPath);
77
+ return files.get(normalizedPath) ?? null;
78
+ }
79
+ async parse(body, includeFile) {
80
+ this.checkCompressedSize(body.length);
81
+ if (body.length < 2 || body[0] !== 0x1f || body[1] !== 0x8b) {
82
+ throw new errors_1.BadRequestError('App artifact must be a gzip archive. Save the source or bundle again.');
83
+ }
84
+ const { Parser } = await import('tar');
85
+ const files = new Map();
86
+ const fileNames = new Set();
87
+ const paths = new Set();
88
+ let size = 0;
89
+ let entries = 0;
90
+ const parser = new Parser({
91
+ strict: true,
92
+ filter: (_name, entry) => {
93
+ try {
94
+ if (!('type' in entry))
95
+ return false;
96
+ this.checkLimits(size, ++entries);
97
+ if (entry.type !== 'File' && entry.type !== 'Directory') {
98
+ throw new errors_1.BadRequestError('App artifacts can contain only files and directories.');
99
+ }
100
+ if (entry.type === 'Directory' && /^(\.\/)*\.?\/?$/.test(entry.path))
101
+ return false;
102
+ const name = this.filePath(entry.path);
103
+ if (paths.has(name))
104
+ throw new errors_1.BadRequestError('App artifact contains duplicate paths.');
105
+ paths.add(name);
106
+ if (!Number.isSafeInteger(entry.size) || entry.size < 0) {
107
+ throw new errors_1.BadRequestError('App artifact contains an invalid file size.');
108
+ }
109
+ size += entry.size;
110
+ this.checkLimits(size, entries);
111
+ if (entry.type !== 'File')
112
+ return false;
113
+ fileNames.add(name);
114
+ return includeFile(name);
115
+ }
116
+ catch (error) {
117
+ parser.abort(error instanceof Error ? error : new Error(String(error)));
118
+ return false;
119
+ }
120
+ },
121
+ onReadEntry: (entry) => {
122
+ const chunks = [];
123
+ entry.on('data', (chunk) => chunks.push(chunk));
124
+ entry.on('end', () => files.set(this.filePath(entry.path), Buffer.concat(chunks)));
125
+ },
126
+ });
127
+ try {
128
+ await (0, promises_1.pipeline)(node_stream_1.Readable.from(slices(body)), parser);
129
+ }
130
+ catch (error) {
131
+ throw errors_1.BadRequestError.wrap('App artifact is invalid or exceeds the archive limits. Check the files and configured limits.', error);
132
+ }
133
+ this.checkFilePaths(fileNames);
134
+ return { files, fileNames };
135
+ }
136
+ filePath(value) {
137
+ const relative = value.replace(/^(\.\/)+/, '').replace(/\/$/, '');
138
+ if (!relative ||
139
+ relative.includes('\\') ||
140
+ relative.includes('\0') ||
141
+ node_path_1.default.posix.isAbsolute(relative) ||
142
+ /^[a-z]:/i.test(relative) ||
143
+ relative.split('/').some((part) => !part || part === '.' || part === '..')) {
144
+ throw new errors_1.BadRequestError('App artifact contains an invalid file path. Use relative paths without parent directory segments.');
145
+ }
146
+ return relative;
147
+ }
148
+ checkFilePaths(fileNames) {
149
+ for (const name of fileNames) {
150
+ let parent = node_path_1.default.posix.dirname(name);
151
+ while (parent !== '.') {
152
+ if (fileNames.has(parent))
153
+ throw new errors_1.BadRequestError('App artifact contains conflicting file paths.');
154
+ parent = node_path_1.default.posix.dirname(parent);
155
+ }
156
+ }
157
+ }
158
+ checkLimits(bytes, entries) {
159
+ if (bytes > this.config.maxArtifactUnpackedSizeBytes ||
160
+ entries > this.config.maxArtifactEntries) {
161
+ throw new errors_1.BadRequestError('App artifact exceeds the unpacked size or entry limit. Reduce the files or increase the artifact limits.');
162
+ }
163
+ }
164
+ checkCompressedSize(bytes) {
165
+ if (bytes > this.config.maxArtifactSizeBytes) {
166
+ throw new errors_1.BadRequestError('App artifact exceeds the compressed size limit. Reduce its size or increase the artifact limit.');
167
+ }
168
+ }
169
+ checkBundle(files, bundle) {
170
+ if (bundle && !files.has('index.html')) {
171
+ throw new errors_1.BadRequestError('App bundle must contain index.html at its root. Check the build output.');
172
+ }
173
+ }
174
+ };
175
+ exports.AppArchive = AppArchive;
176
+ exports.AppArchive = AppArchive = __decorate([
177
+ (0, di_1.Service)(),
178
+ __metadata("design:paramtypes", [apps_config_1.AppsConfig])
179
+ ], AppArchive);
180
+ //# sourceMappingURL=app-archive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-archive.js","sourceRoot":"","sources":["../../src/storage/app-archive.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gCAAkC;AAClC,wCAA8C;AAC9C,0DAA6B;AAC7B,6CAAuC;AACvC,mDAAgD;AAGhD,gDAA4C;AAE5C,MAAM,UAAU,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7B,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAY;IAC5B,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,UAAU,EAAE,CAAC;QACjE,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC;IAClD,CAAC;AACF,CAAC;AAGM,IAAM,UAAU,GAAhB,MAAM,UAAU;IACtB,YAA6B,MAAkB;sBAAlB,MAAM;IAAe,CAAC;IAEnD,KAAK,CAAC,IAAI,CAAC,KAAe,EAAE,MAAM,GAAG,KAAK;QACzC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC7C,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,EAAE,CAAC;YACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACrC,IAAI,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC;gBAC3B,MAAM,IAAI,wBAAe,CAAC,wCAAwC,CAAC,C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AE,CAAC;gBACvB,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC;oBACxB,MAAM,IAAI,wBAAe,CAAC,+CAA+C,CAAC,CAAC;gBAC5E,MAAM,GAAG,mBAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACrC,CAAC;QACF,CAAC;IACF,CAAC;IAEO,WAAW,CAAC,KAAa,EAAE,OAAe;QACjD,IACC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,4BAA4B;YAChD,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,kBAAkB,EACvC,CAAC;YACF,MAAM,IAAI,wBAAe,CACxB,0GAA0G,CAC1G,CAAC;QACH,CAAC;IACF,CAAC;IAEO,mBAAmB,CAAC,KAAa;QACxC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,CAAC;YAC9C,MAAM,IAAI,wBAAe,CACxB,iGAAiG,CACjG,CAAC;QACH,CAAC;IACF,CAAC;IAEO,WAAW,CAAC,KAAe,EAAE,MAAe;QACnD,IAAI,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YACxC,MAAM,IAAI,wBAAe,CACxB,yEAAyE,CACzE,CAAC;QACH,CAAC;IACF,CAAC;CACD,CAAA;;qBAvKY,UAAU;IADtB,IAAA,YAAO,GAAE;qCAE4B,wBAAU;GADnC,UAAU,CAuKtB"}
@@ -0,0 +1,21 @@
1
+ import { BinaryDataRepository, DbLockService, type ExecutionDataStorageLocation } from '@n8n/db';
2
+ import { FsByteStoreService, StorageConfig } from 'n8n-core';
3
+ import type { AppArtifactRef } from '../app-artifact.entity';
4
+ import { AppArtifactRepository } from '../app-artifact.repository';
5
+ export type AppBlob = {
6
+ storedAt: ExecutionDataStorageLocation;
7
+ storageKey: string;
8
+ };
9
+ export declare class AppBlobStore {
10
+ private readonly config;
11
+ private readonly binaryData;
12
+ private readonly artifacts;
13
+ private readonly locks;
14
+ private readonly stores;
15
+ constructor(fs: FsByteStoreService, config: StorageConfig, binaryData: BinaryDataRepository, artifacts: AppArtifactRepository, locks: DbLockService);
16
+ init(): Promise<void>;
17
+ newBlob(): AppBlob;
18
+ write(blob: AppBlob & AppArtifactRef, body: Buffer): Promise<void>;
19
+ read(blob: AppBlob): Promise<Buffer | null>;
20
+ delete(blob: AppBlob): Promise<void>;
21
+ }
@@ -0,0 +1,93 @@
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.AppBlobStore = void 0;
13
+ const blob_storage_1 = require("@n8n/blob-storage");
14
+ const db_1 = require("@n8n/db");
15
+ const di_1 = require("@n8n/di");
16
+ const n8n_core_1 = require("n8n-core");
17
+ const uuid_1 = require("uuid");
18
+ const app_artifact_repository_1 = require("../app-artifact.repository");
19
+ const app_storage_lock_1 = require("../app-storage-lock");
20
+ let AppBlobStore = class AppBlobStore {
21
+ constructor(fs, config, binaryData, artifacts, locks) {
22
+ this.config = config;
23
+ this.binaryData = binaryData;
24
+ this.artifacts = artifacts;
25
+ this.locks = locks;
26
+ this.stores = new blob_storage_1.ByteStoreRegistry({ fs });
27
+ }
28
+ async init() {
29
+ if (di_1.Container.get(blob_storage_1.ObjectStoreConfig).bucket.name) {
30
+ try {
31
+ const { ObjectStoreService } = await import('@n8n/blob-storage/object-store');
32
+ const store = di_1.Container.get(ObjectStoreService);
33
+ await store.checkConnection();
34
+ this.stores.register('s3', new blob_storage_1.S3ByteStore(store));
35
+ }
36
+ catch (error) {
37
+ if (this.config.modeTag === 's3')
38
+ throw error;
39
+ }
40
+ }
41
+ if (di_1.Container.get(blob_storage_1.AzureBlobConfig).containerName) {
42
+ try {
43
+ const { AzureBlobService } = await import('@n8n/blob-storage/azure-blob');
44
+ const store = di_1.Container.get(AzureBlobService);
45
+ await store.checkConnection();
46
+ this.stores.register('az', new blob_storage_1.AzureByteStore(store));
47
+ }
48
+ catch (error) {
49
+ if (this.config.modeTag === 'az')
50
+ throw error;
51
+ }
52
+ }
53
+ if (this.config.modeTag !== 'db')
54
+ this.stores.get(this.config.modeTag);
55
+ }
56
+ newBlob() {
57
+ const storedAt = this.config.modeTag;
58
+ const id = (0, uuid_1.v7)();
59
+ return { storedAt, storageKey: storedAt === 'db' ? id : `apps/artifacts/${id}.tgz` };
60
+ }
61
+ async write(blob, body) {
62
+ if (blob.storedAt === 'db') {
63
+ await this.locks.withLockContext(1010, async (ctx) => {
64
+ await this.artifacts.storeDatabaseContent(blob, body, ctx);
65
+ }, { subKey: (0, app_storage_lock_1.appStorageLockSubKey)(blob.appId) });
66
+ }
67
+ else {
68
+ await this.stores.get(blob.storedAt).write(blob.storageKey, body, {
69
+ mimeType: 'application/gzip',
70
+ fileName: 'artifact.tgz',
71
+ });
72
+ }
73
+ }
74
+ async read(blob) {
75
+ if (blob.storedAt === 'db')
76
+ return await this.binaryData.findContentByFileId(blob.storageKey);
77
+ return await this.stores.get(blob.storedAt).read(blob.storageKey);
78
+ }
79
+ async delete(blob) {
80
+ if (blob.storedAt === 'db') {
81
+ await this.binaryData.deleteByFileIds([blob.storageKey]);
82
+ }
83
+ else {
84
+ await this.stores.get(blob.storedAt).delete([blob.storageKey]);
85
+ }
86
+ }
87
+ };
88
+ exports.AppBlobStore = AppBlobStore;
89
+ exports.AppBlobStore = AppBlobStore = __decorate([
90
+ (0, di_1.Service)(),
91
+ __metadata("design:paramtypes", [n8n_core_1.FsByteStoreService, n8n_core_1.StorageConfig, db_1.BinaryDataRepository, app_artifact_repository_1.AppArtifactRepository, db_1.DbLockService])
92
+ ], AppBlobStore);
93
+ //# sourceMappingURL=app-blob-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-blob-store.js","sourceRoot":"","sources":["../../src/storage/app-blob-store.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAM2B;AAC3B,gCAKiB;AACjB,gCAA6C;AAC7C,uCAA6D;AAC7D,+BAAoC;AAGpC,wEAAmE;AACnE,0DAA2D;AAKpD,IAAM,YAAY,GAAlB,MAAM,YAAY;IAGxB,YACC,EAAsB,EACL,MAAqB,EACrB,UAAgC,EAChC,SAAgC,EAChC,KAAoB;sBAHpB,MAAM;0BACN,UAAU;yBACV,SAAS;qBACT,KAAK;QAEtB,IAAI,CAAC,MAAM,GAAG,IAAI,gCAAiB,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,IAAI;QACT,IAAI,cAAS,CAAC,GAAG,CAAC,gCAAiB,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAClD,IAAI,CAAC;gBACJ,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,CAAC;gBAC9E,MAAM,KAAK,GAAG,cAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;gBAChD,MAAM,KAAK,CAAC,eAAe,EAAE,CAAC;gBAC9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,0BAAW,CAAC,KAAK,CAAC,CAAC,CAAC;YACpD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,KAAK,IAAI;oBAAE,MAAM,KAAK,CAAC;YAC/C,CAAC;QACF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<string, Buffer>;
3
+ export type NewSourceVersion = {
4
+ id: string;
5
+ appId: string;
6
+ expectedDraftVersionId: string | null;
7
+ label: string | null;
8
+ };
9
+ export declare abstract class AppSourceVersionStore {
10
+ abstract createVersion(version: NewSourceVersion, files: AppFiles): Promise<void>;
11
+ abstract readSource(versionId: string): Promise<AppFiles>;
12
+ abstract listSourceFiles(versionId: string): Promise<string[]>;
13
+ abstract readSourceFile(versionId: string, filePath: string): Promise<Buffer | null>;
14
+ abstract removeVersions(versionIds: string[], ctx: OperationContext): Promise<void>;
15
+ }
16
+ export declare abstract class AppBuildResultStore {
17
+ abstract recordSuccess(appId: string, versionId: string, files: AppFiles): Promise<void>;
18
+ abstract readBundle(versionId: string): Promise<AppFiles>;
19
+ abstract removeBundles(versionIds: string[], ctx: OperationContext): Promise<void>;
20
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppBuildResultStore = exports.AppSourceVersionStore = void 0;
4
+ class AppSourceVersionStore {
5
+ }
6
+ exports.AppSourceVersionStore = AppSourceVersionStore;
7
+ class AppBuildResultStore {
8
+ }
9
+ exports.AppBuildResultStore = AppBuildResultStore;
10
+ //# sourceMappingURL=app-version-stores.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-version-stores.js","sourceRoot":"","sources":["../../src/storage/app-version-stores.ts"],"names":[],"mappings":";;;AAWA;CAYC;;AAED;CAQC"}
@@ -0,0 +1,30 @@
1
+ import { DbLockService, type OperationContext } from '@n8n/db';
2
+ import { AppArchive } from './app-archive';
3
+ import { AppSourceVersionStore, AppBuildResultStore, type AppFiles, type NewSourceVersion } from './app-version-stores';
4
+ import { AppArtifactService } from '../app-artifact.service';
5
+ import { AppVersionRepository } from '../app-version.repository';
6
+ import { AppRepository } from '../app.repository';
7
+ export declare class SnapshotAppSourceVersionStore extends AppSourceVersionStore {
8
+ private readonly archives;
9
+ private readonly artifacts;
10
+ private readonly versions;
11
+ private readonly apps;
12
+ private readonly locks;
13
+ constructor(archives: AppArchive, artifacts: AppArtifactService, versions: AppVersionRepository, apps: AppRepository, locks: DbLockService);
14
+ createVersion(version: NewSourceVersion, files: AppFiles): Promise<void>;
15
+ readSource(versionId: string): Promise<AppFiles>;
16
+ listSourceFiles(versionId: string): Promise<string[]>;
17
+ readSourceFile(versionId: string, filePath: string): Promise<Buffer | null>;
18
+ private readSourceArchive;
19
+ removeVersions(versionIds: string[], ctx: OperationContext): Promise<void>;
20
+ }
21
+ export declare class SnapshotAppBuildResultStore extends AppBuildResultStore {
22
+ private readonly archives;
23
+ private readonly artifacts;
24
+ private readonly versions;
25
+ private readonly locks;
26
+ constructor(archives: AppArchive, artifacts: AppArtifactService, versions: AppVersionRepository, locks: DbLockService);
27
+ recordSuccess(appId: string, versionId: string, files: AppFiles): Promise<void>;
28
+ readBundle(versionId: string): Promise<AppFiles>;
29
+ removeBundles(versionIds: string[], ctx: OperationContext): Promise<void>;
30
+ }
@@ -0,0 +1,122 @@
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.SnapshotAppBuildResultStore = exports.SnapshotAppSourceVersionStore = void 0;
13
+ const db_1 = require("@n8n/db");
14
+ const di_1 = require("@n8n/di");
15
+ const errors_1 = require("@n8n/errors");
16
+ const app_archive_1 = require("./app-archive");
17
+ const app_version_stores_1 = require("./app-version-stores");
18
+ const app_artifact_service_1 = require("../app-artifact.service");
19
+ const app_storage_lock_1 = require("../app-storage-lock");
20
+ const app_version_repository_1 = require("../app-version.repository");
21
+ const app_repository_1 = require("../app.repository");
22
+ let SnapshotAppSourceVersionStore = class SnapshotAppSourceVersionStore extends app_version_stores_1.AppSourceVersionStore {
23
+ constructor(archives, artifacts, versions, apps, locks) {
24
+ super();
25
+ this.archives = archives;
26
+ this.artifacts = artifacts;
27
+ this.versions = versions;
28
+ this.apps = apps;
29
+ this.locks = locks;
30
+ }
31
+ async createVersion(version, files) {
32
+ const artifact = await this.artifacts.upload(version.appId, await this.archives.pack(files));
33
+ try {
34
+ await this.locks.withLockContext(1010, async (ctx) => {
35
+ if (!(await this.apps.findById(version.appId, ctx))) {
36
+ throw new errors_1.NotFoundError('App not found.');
37
+ }
38
+ await this.artifacts.completeUpload(artifact, ctx);
39
+ await this.versions.insertVersion({
40
+ id: version.id,
41
+ appId: version.appId,
42
+ label: version.label,
43
+ sourceArtifactId: artifact.id,
44
+ }, ctx);
45
+ if (!(await this.apps.advanceDraft(version.appId, version.expectedDraftVersionId, version.id, ctx))) {
46
+ throw new errors_1.ConflictError('The app draft changed. Reload the source before saving.');
47
+ }
48
+ }, { subKey: (0, app_storage_lock_1.appStorageLockSubKey)(version.appId) });
49
+ }
50
+ catch (error) {
51
+ await this.artifacts.discard(artifact);
52
+ throw error;
53
+ }
54
+ }
55
+ async readSource(versionId) {
56
+ return await this.archives.unpack(await this.readSourceArchive(versionId));
57
+ }
58
+ async listSourceFiles(versionId) {
59
+ return await this.archives.listFiles(await this.readSourceArchive(versionId));
60
+ }
61
+ async readSourceFile(versionId, filePath) {
62
+ return await this.archives.readFile(await this.readSourceArchive(versionId), filePath);
63
+ }
64
+ async readSourceArchive(versionId) {
65
+ const version = await this.versions.findVersionById(versionId);
66
+ if (!version)
67
+ throw new errors_1.NotFoundError('App version not found.');
68
+ return await this.artifacts.read(version.sourceArtifactId);
69
+ }
70
+ async removeVersions(versionIds, ctx) {
71
+ await this.versions.removeVersions(versionIds, ctx);
72
+ }
73
+ };
74
+ exports.SnapshotAppSourceVersionStore = SnapshotAppSourceVersionStore;
75
+ exports.SnapshotAppSourceVersionStore = SnapshotAppSourceVersionStore = __decorate([
76
+ (0, di_1.Service)(),
77
+ __metadata("design:paramtypes", [app_archive_1.AppArchive, app_artifact_service_1.AppArtifactService, app_version_repository_1.AppVersionRepository, app_repository_1.AppRepository, db_1.DbLockService])
78
+ ], SnapshotAppSourceVersionStore);
79
+ let SnapshotAppBuildResultStore = class SnapshotAppBuildResultStore extends app_version_stores_1.AppBuildResultStore {
80
+ constructor(archives, artifacts, versions, locks) {
81
+ super();
82
+ this.archives = archives;
83
+ this.artifacts = artifacts;
84
+ this.versions = versions;
85
+ this.locks = locks;
86
+ }
87
+ async recordSuccess(appId, versionId, files) {
88
+ const artifact = await this.artifacts.upload(appId, await this.archives.pack(files, true));
89
+ try {
90
+ await this.locks.withLockContext(1010, async (ctx) => {
91
+ const version = await this.versions.findVersionById(versionId, ctx);
92
+ if (!version || version.appId !== appId)
93
+ throw new errors_1.NotFoundError('App version not found.');
94
+ await this.artifacts.completeUpload(artifact, ctx);
95
+ if (!(await this.versions.attachBundle(versionId, artifact.id, ctx))) {
96
+ throw new errors_1.ConflictError('This app version cannot accept a bundle. Check its build status.');
97
+ }
98
+ }, { subKey: (0, app_storage_lock_1.appStorageLockSubKey)(appId) });
99
+ }
100
+ catch (error) {
101
+ await this.artifacts.discard(artifact);
102
+ throw error;
103
+ }
104
+ }
105
+ async readBundle(versionId) {
106
+ const version = await this.versions.findVersionById(versionId);
107
+ if (!version)
108
+ throw new errors_1.NotFoundError('App version not found.');
109
+ if (version.bundleArtifactId === null)
110
+ throw new errors_1.NotFoundError('App bundle not found.');
111
+ return await this.archives.unpack(await this.artifacts.read(version.bundleArtifactId), true);
112
+ }
113
+ async removeBundles(versionIds, ctx) {
114
+ await this.versions.clearBundles(versionIds, ctx);
115
+ }
116
+ };
117
+ exports.SnapshotAppBuildResultStore = SnapshotAppBuildResultStore;
118
+ exports.SnapshotAppBuildResultStore = SnapshotAppBuildResultStore = __decorate([
119
+ (0, di_1.Service)(),
120
+ __metadata("design:paramtypes", [app_archive_1.AppArchive, app_artifact_service_1.AppArtifactService, app_version_repository_1.AppVersionRepository, db_1.DbLockService])
121
+ ], SnapshotAppBuildResultStore);
122
+ //# sourceMappingURL=snapshot-app-version-stores.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot-app-version-stores.js","sourceRoot":"","sources":["../../src/storage/snapshot-app-version-stores.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gCAAuE;AACvE,gCAAkC;AAClC,wCAA2D;AAE3D,+CAA2C;AAC3C,6DAK8B;AAC9B,kEAA6D;AAC7D,0DAA2D;AAC3D,sEAAiE;AACjE,sDAAkD;AAG3C,IAAM,6BAA6B,GAAnC,MAAM,6BAA8B,SAAQ,0CAAqB;IACvE,YACkB,QAAoB,EACpB,SAA6B,EAC7B,QAA8B,EAC9B,IAAmB,EACnB,KAAoB;QAErC,KAAK,EAAE,CAAC;wBANS,QAAQ;yBACR,SAAS;wBACT,QAAQ;oBACR,IAAI;qBACJ,KAAK;IAGvB,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAyB,EAAE,KAAe;QAC7D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7F,IAAI,CAAC;YACJ,MAAM,IAAI,CAAC,KAAK,CAAC,eAAe,OAE/B,KAAK,EAAE,GAAG,EAAE,EAAE;gBACb,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,EAAE,CA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