@agility/content-sync 1.1.9 → 1.2.0-beta.3

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/.babelrc +9 -6
  2. package/dist/agility-sync-sdk.node.js +9282 -8644
  3. package/dist/index.d.ts +20 -0
  4. package/dist/index.js +25 -0
  5. package/dist/methods/clearSync.d.ts +3 -0
  6. package/dist/methods/clearSync.js +21 -0
  7. package/dist/methods/runSync.d.ts +39 -0
  8. package/dist/methods/runSync.js +94 -0
  9. package/dist/methods/syncAssets.d.ts +18 -0
  10. package/dist/methods/syncAssets.js +34 -0
  11. package/dist/methods/syncContainers.d.ts +18 -0
  12. package/dist/methods/syncContainers.js +34 -0
  13. package/dist/methods/syncContent.d.ts +20 -0
  14. package/dist/methods/syncContent.js +83 -0
  15. package/dist/methods/syncContentModels.d.ts +10 -0
  16. package/dist/methods/syncContentModels.js +34 -0
  17. package/dist/methods/syncGalleries.d.ts +18 -0
  18. package/dist/methods/syncGalleries.js +34 -0
  19. package/dist/methods/syncPageModels.d.ts +18 -0
  20. package/dist/methods/syncPageModels.js +34 -0
  21. package/dist/methods/syncPages.d.ts +20 -0
  22. package/dist/methods/syncPages.js +82 -0
  23. package/dist/store-interface-console.d.ts +163 -0
  24. package/dist/store-interface-console.js +146 -0
  25. package/dist/store-interface-filesystem.d.ts +166 -0
  26. package/dist/store-interface-filesystem.js +362 -0
  27. package/dist/store-interface.d.ts +69 -0
  28. package/dist/store-interface.js +430 -0
  29. package/dist/sync-client.d.ts +29 -0
  30. package/dist/sync-client.js +126 -0
  31. package/dist/types/AgilityClient.d.ts +12 -0
  32. package/dist/types/AgilityClient.js +1 -0
  33. package/dist/types/Asset.d.ts +18 -0
  34. package/dist/types/Asset.js +1 -0
  35. package/dist/types/Container.d.ts +15 -0
  36. package/dist/types/Container.js +1 -0
  37. package/dist/types/ContentItem.d.ts +20 -0
  38. package/dist/types/ContentItem.js +1 -0
  39. package/dist/types/ContentModel.d.ts +23 -0
  40. package/dist/types/ContentModel.js +1 -0
  41. package/dist/types/Gallery.d.ts +15 -0
  42. package/dist/types/Gallery.js +1 -0
  43. package/dist/types/Page.d.ts +14 -0
  44. package/dist/types/Page.js +1 -0
  45. package/dist/types/PageModel.d.ts +36 -0
  46. package/dist/types/PageModel.js +1 -0
  47. package/dist/types/StoreInterface.d.ts +165 -0
  48. package/dist/types/StoreInterface.js +1 -0
  49. package/dist/types/SyncProgress.d.ts +11 -0
  50. package/dist/types/SyncProgress.js +1 -0
  51. package/dist/types.d.ts +11 -0
  52. package/dist/types.js +1 -0
  53. package/dist/util.d.ts +7 -0
  54. package/dist/util.js +23 -0
  55. package/package.json +7 -3
  56. package/src/methods/clearSync.js +1 -2
  57. package/src/methods/runSync.js +11 -13
  58. package/src/methods/syncContent.js +5 -5
  59. package/src/methods/syncPages.js +3 -3
  60. package/src/store-interface.js +405 -423
  61. package/src/sync-client.js +17 -10
  62. package/test/03-store.getContentItem.tests.js +6 -4
  63. package/test/04-store.getContentList.tests.js +10 -10
  64. package/test/99-clearSync.tests.js +3 -3
  65. package/test/_syncClients.config.js +3 -3
  66. package/webpack.config.js +11 -0
@@ -0,0 +1,362 @@
1
+ import { logDebug, logInfo } from './util';
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
+ export class FileSystemStore {
5
+ options;
6
+ basePath;
7
+ constructor(options) {
8
+ this.options = options;
9
+ this.basePath = options.rootPath || './data';
10
+ this.ensureDirectoryExists(this.basePath);
11
+ }
12
+ ensureDirectoryExists(dirPath) {
13
+ if (!fs.existsSync(dirPath)) {
14
+ fs.mkdirSync(dirPath, { recursive: true });
15
+ }
16
+ }
17
+ getItemPath(itemType, languageCode, itemID) {
18
+ const itemPath = path.join(this.basePath, languageCode, itemType);
19
+ this.ensureDirectoryExists(itemPath);
20
+ return path.join(itemPath, `${itemID}.json`);
21
+ }
22
+ async clearItems(options) {
23
+ logInfo('Clearing all items from filesystem store');
24
+ if (fs.existsSync(this.basePath)) {
25
+ fs.rmSync(this.basePath, { recursive: true, force: true });
26
+ }
27
+ this.ensureDirectoryExists(this.basePath);
28
+ }
29
+ async deleteItem(params) {
30
+ const filePath = this.getItemPath(params.itemType, params.languageCode, params.itemID);
31
+ if (fs.existsSync(filePath)) {
32
+ fs.unlinkSync(filePath);
33
+ logDebug(`Deleted item: ${params.itemType} - ${params.itemID} (${params.languageCode})`);
34
+ }
35
+ }
36
+ async getItem(params) {
37
+ const filePath = this.getItemPath(params.itemType, params.languageCode, params.itemID);
38
+ if (fs.existsSync(filePath)) {
39
+ const data = fs.readFileSync(filePath, 'utf8');
40
+ return JSON.parse(data);
41
+ }
42
+ return null;
43
+ }
44
+ async saveItem(params) {
45
+ const filePath = this.getItemPath(params.itemType, params.languageCode, params.itemID);
46
+ fs.writeFileSync(filePath, JSON.stringify(params.item, null, 2));
47
+ logDebug(`Saved item: ${params.itemType} - ${params.itemID} (${params.languageCode})`);
48
+ }
49
+ // Content Item methods
50
+ async getContentItem(options) {
51
+ return this.getItem({
52
+ options: this.options,
53
+ itemType: 'content',
54
+ languageCode: options.languageCode,
55
+ itemID: options.contentID
56
+ });
57
+ }
58
+ async saveContentItem(options) {
59
+ await this.saveItem({
60
+ options: this.options,
61
+ item: options.contentItem,
62
+ itemType: 'content',
63
+ languageCode: options.languageCode,
64
+ itemID: options.contentItem.contentID
65
+ });
66
+ }
67
+ async getContentItems(options) {
68
+ const contentPath = path.join(this.basePath, options.languageCode, 'content');
69
+ if (!fs.existsSync(contentPath)) {
70
+ return [];
71
+ }
72
+ const files = fs.readdirSync(contentPath);
73
+ return files.map(file => {
74
+ const data = fs.readFileSync(path.join(contentPath, file), 'utf8');
75
+ return JSON.parse(data);
76
+ });
77
+ }
78
+ async saveContentItems(options) {
79
+ for (const contentItem of options.contentItems) {
80
+ await this.saveContentItem({
81
+ contentItem,
82
+ languageCode: options.languageCode
83
+ });
84
+ }
85
+ }
86
+ // Page methods
87
+ async getPage(options) {
88
+ return this.getItem({
89
+ options: this.options,
90
+ itemType: 'page',
91
+ languageCode: options.languageCode,
92
+ itemID: options.pageID
93
+ });
94
+ }
95
+ async savePageItem(options) {
96
+ await this.saveItem({
97
+ options: this.options,
98
+ item: options.page,
99
+ itemType: 'page',
100
+ languageCode: options.languageCode,
101
+ itemID: options.page.pageID
102
+ });
103
+ }
104
+ async getPages(options) {
105
+ const pagePath = path.join(this.basePath, options.languageCode, 'page');
106
+ if (!fs.existsSync(pagePath)) {
107
+ return [];
108
+ }
109
+ const files = fs.readdirSync(pagePath);
110
+ return files.map(file => {
111
+ const data = fs.readFileSync(path.join(pagePath, file), 'utf8');
112
+ return JSON.parse(data);
113
+ });
114
+ }
115
+ async savePageItems(options) {
116
+ for (const page of options.pages) {
117
+ await this.savePageItem({
118
+ page,
119
+ languageCode: options.languageCode
120
+ });
121
+ }
122
+ }
123
+ // Asset methods
124
+ async getAsset(options) {
125
+ return this.getItem({
126
+ options: this.options,
127
+ itemType: 'asset',
128
+ languageCode: options.languageCode,
129
+ itemID: options.assetID
130
+ });
131
+ }
132
+ async saveAsset(options) {
133
+ await this.saveItem({
134
+ options: this.options,
135
+ item: options.asset,
136
+ itemType: 'asset',
137
+ languageCode: options.languageCode,
138
+ itemID: options.asset.assetID
139
+ });
140
+ }
141
+ async getAssets(options) {
142
+ const assetPath = path.join(this.basePath, options.languageCode, 'asset');
143
+ if (!fs.existsSync(assetPath)) {
144
+ return [];
145
+ }
146
+ const files = fs.readdirSync(assetPath);
147
+ return files.map(file => {
148
+ const data = fs.readFileSync(path.join(assetPath, file), 'utf8');
149
+ return JSON.parse(data);
150
+ });
151
+ }
152
+ async saveAssets(options) {
153
+ for (const asset of options.assets) {
154
+ await this.saveAsset({
155
+ asset,
156
+ languageCode: options.languageCode
157
+ });
158
+ }
159
+ }
160
+ // Gallery methods
161
+ async getGallery(options) {
162
+ return this.getItem({
163
+ options: this.options,
164
+ itemType: 'gallery',
165
+ languageCode: options.languageCode,
166
+ itemID: options.galleryID
167
+ });
168
+ }
169
+ async saveGallery(options) {
170
+ await this.saveItem({
171
+ options: this.options,
172
+ item: options.gallery,
173
+ itemType: 'gallery',
174
+ languageCode: options.languageCode,
175
+ itemID: options.gallery.id
176
+ });
177
+ }
178
+ async getGalleries(options) {
179
+ const galleryPath = path.join(this.basePath, options.languageCode, 'gallery');
180
+ if (!fs.existsSync(galleryPath)) {
181
+ return [];
182
+ }
183
+ const files = fs.readdirSync(galleryPath);
184
+ return files.map(file => {
185
+ const data = fs.readFileSync(path.join(galleryPath, file), 'utf8');
186
+ return JSON.parse(data);
187
+ });
188
+ }
189
+ async saveGalleries(options) {
190
+ for (const gallery of options.galleries) {
191
+ await this.saveGallery({
192
+ gallery,
193
+ languageCode: options.languageCode
194
+ });
195
+ }
196
+ }
197
+ // Container methods
198
+ async getContainer(options) {
199
+ return this.getItem({
200
+ options: this.options,
201
+ itemType: 'container',
202
+ languageCode: options.languageCode,
203
+ itemID: options.containerID
204
+ });
205
+ }
206
+ async saveContainer(options) {
207
+ await this.saveItem({
208
+ options: this.options,
209
+ item: options.container,
210
+ itemType: 'container',
211
+ languageCode: options.languageCode,
212
+ itemID: options.container.id
213
+ });
214
+ }
215
+ async getContainers(options) {
216
+ const containerPath = path.join(this.basePath, options.languageCode, 'container');
217
+ if (!fs.existsSync(containerPath)) {
218
+ return [];
219
+ }
220
+ const files = fs.readdirSync(containerPath);
221
+ return files.map(file => {
222
+ const data = fs.readFileSync(path.join(containerPath, file), 'utf8');
223
+ return JSON.parse(data);
224
+ });
225
+ }
226
+ async saveContainers(options) {
227
+ for (const container of options.containers) {
228
+ await this.saveContainer({
229
+ container,
230
+ languageCode: options.languageCode
231
+ });
232
+ }
233
+ }
234
+ // Content Model methods
235
+ async getContentModel(options) {
236
+ return this.getItem({
237
+ options: this.options,
238
+ itemType: 'contentmodel',
239
+ languageCode: options.languageCode,
240
+ itemID: options.contentModelID
241
+ });
242
+ }
243
+ async saveContentModel(options) {
244
+ await this.saveItem({
245
+ options: this.options,
246
+ item: options.contentModel,
247
+ itemType: 'contentmodel',
248
+ languageCode: options.languageCode,
249
+ itemID: options.contentModel.id
250
+ });
251
+ }
252
+ async getContentModels(options) {
253
+ const contentModelPath = path.join(this.basePath, options.languageCode, 'contentmodel');
254
+ if (!fs.existsSync(contentModelPath)) {
255
+ return [];
256
+ }
257
+ const files = fs.readdirSync(contentModelPath);
258
+ return files.map(file => {
259
+ const data = fs.readFileSync(path.join(contentModelPath, file), 'utf8');
260
+ return JSON.parse(data);
261
+ });
262
+ }
263
+ async saveContentModels(options) {
264
+ for (const contentModel of options.contentModels) {
265
+ await this.saveContentModel({
266
+ contentModel,
267
+ languageCode: options.languageCode
268
+ });
269
+ }
270
+ }
271
+ // Page Model methods
272
+ async getPageModel(options) {
273
+ return this.getItem({
274
+ options: this.options,
275
+ itemType: 'pagemodel',
276
+ languageCode: options.languageCode,
277
+ itemID: options.pageModelID
278
+ });
279
+ }
280
+ async savePageModel(options) {
281
+ await this.saveItem({
282
+ options: this.options,
283
+ item: options.pageModel,
284
+ itemType: 'pagemodel',
285
+ languageCode: options.languageCode,
286
+ itemID: options.pageModel.id
287
+ });
288
+ }
289
+ async getPageModels(options) {
290
+ const pageModelPath = path.join(this.basePath, options.languageCode, 'pagemodel');
291
+ if (!fs.existsSync(pageModelPath)) {
292
+ return [];
293
+ }
294
+ const files = fs.readdirSync(pageModelPath);
295
+ return files.map(file => {
296
+ const data = fs.readFileSync(path.join(pageModelPath, file), 'utf8');
297
+ return JSON.parse(data);
298
+ });
299
+ }
300
+ async savePageModels(options) {
301
+ for (const pageModel of options.pageModels) {
302
+ await this.savePageModel({
303
+ pageModel,
304
+ languageCode: options.languageCode
305
+ });
306
+ }
307
+ }
308
+ // List methods
309
+ async getList(options) {
310
+ const listPath = path.join(this.basePath, options.languageCode, 'list', `${options.listName}.json`);
311
+ if (!fs.existsSync(listPath)) {
312
+ return [];
313
+ }
314
+ const data = fs.readFileSync(listPath, 'utf8');
315
+ return JSON.parse(data);
316
+ }
317
+ async saveList(options) {
318
+ const listPath = path.join(this.basePath, options.languageCode, 'list');
319
+ this.ensureDirectoryExists(listPath);
320
+ fs.writeFileSync(path.join(listPath, `${options.listName}.json`), JSON.stringify(options.items, null, 2));
321
+ }
322
+ async mergeItemToList(params) {
323
+ const listPath = path.join(this.basePath, params.languageCode, 'list');
324
+ this.ensureDirectoryExists(listPath);
325
+ const listFile = path.join(listPath, `${params.referenceName}.json`);
326
+ let items = [];
327
+ if (fs.existsSync(listFile)) {
328
+ const data = fs.readFileSync(listFile, 'utf8');
329
+ items = JSON.parse(data);
330
+ }
331
+ const index = items.findIndex(item => item.id === params.itemID);
332
+ if (index >= 0) {
333
+ items[index] = params.item;
334
+ }
335
+ else {
336
+ items.push(params.item);
337
+ }
338
+ fs.writeFileSync(listFile, JSON.stringify(items, null, 2));
339
+ }
340
+ async removeItemFromList(options) {
341
+ const listPath = path.join(this.basePath, options.languageCode, 'list', `${options.listName}.json`);
342
+ if (!fs.existsSync(listPath)) {
343
+ return;
344
+ }
345
+ const data = fs.readFileSync(listPath, 'utf8');
346
+ const items = JSON.parse(data);
347
+ const filteredItems = items.filter((item) => item.id !== options.itemID);
348
+ fs.writeFileSync(listPath, JSON.stringify(filteredItems, null, 2));
349
+ }
350
+ // Initialization methods
351
+ async initialize(options) {
352
+ this.options = options;
353
+ this.basePath = options.rootPath || './data';
354
+ this.ensureDirectoryExists(this.basePath);
355
+ }
356
+ async clearData(options) {
357
+ const languagePath = path.join(this.basePath, options.languageCode);
358
+ if (fs.existsSync(languagePath)) {
359
+ fs.rmSync(languagePath, { recursive: true, force: true });
360
+ }
361
+ }
362
+ }
@@ -0,0 +1,69 @@
1
+ import { StoreInterface, StoreOptions } from './types/StoreInterface';
2
+ import { ContentItem } from './types/ContentItem';
3
+ import { Page } from './types/Page';
4
+ export declare const setStore: (storeToUse: StoreInterface, storeOptions: StoreOptions) => void;
5
+ export declare const getStore: () => StoreInterface | null;
6
+ export declare const saveContentItem: ({ contentItem, languageCode }: {
7
+ contentItem: ContentItem;
8
+ languageCode: string;
9
+ }) => Promise<void>;
10
+ export declare const savePageItem: ({ pageItem, languageCode }: {
11
+ pageItem: Page;
12
+ languageCode: string;
13
+ }) => Promise<void>;
14
+ export declare const saveSitemap: ({ sitemap, channelName, languageCode }: {
15
+ sitemap: any;
16
+ channelName: string;
17
+ languageCode: string;
18
+ }) => Promise<void>;
19
+ export declare const saveSitemapNested: ({ sitemapNested, channelName, languageCode }: {
20
+ sitemapNested: any;
21
+ channelName: string;
22
+ languageCode: string;
23
+ }) => Promise<void>;
24
+ export declare const saveUrlRedirections: ({ urlRedirections, languageCode }: {
25
+ urlRedirections: any;
26
+ languageCode: string;
27
+ }) => Promise<void>;
28
+ export declare const getUrlRedirections: ({ languageCode }: {
29
+ languageCode: string;
30
+ }) => Promise<any>;
31
+ export declare const saveSyncState: ({ syncState, languageCode }: {
32
+ syncState: any;
33
+ languageCode: string;
34
+ }) => Promise<void>;
35
+ export declare const getSyncState: (languageCode: string) => Promise<any>;
36
+ export declare const getContentItem: ({ contentID, languageCode, depth, contentLinkDepth, expandAllContentLinks, skip, take }: {
37
+ contentID: number;
38
+ languageCode: string;
39
+ depth?: number;
40
+ contentLinkDepth?: number;
41
+ expandAllContentLinks?: boolean;
42
+ skip?: number;
43
+ take?: number;
44
+ }) => Promise<ContentItem | null>;
45
+ export declare const getContentList: ({ referenceName, languageCode, depth, contentLinkDepth, expandAllContentLinks, skip, take }: {
46
+ referenceName: string;
47
+ languageCode: string;
48
+ depth?: number;
49
+ contentLinkDepth?: number;
50
+ expandAllContentLinks?: boolean;
51
+ skip?: number;
52
+ take?: number;
53
+ }) => Promise<any>;
54
+ export declare const getPage: ({ pageID, languageCode, depth, contentLinkDepth, expandAllContentLinks }: {
55
+ pageID: number;
56
+ languageCode: string;
57
+ depth?: number;
58
+ contentLinkDepth?: number;
59
+ expandAllContentLinks?: boolean;
60
+ }) => Promise<Page | null>;
61
+ export declare const getSitemap: ({ channelName, languageCode }: {
62
+ channelName: string;
63
+ languageCode: string;
64
+ }) => Promise<any>;
65
+ export declare const getSitemapNested: ({ channelName, languageCode }: {
66
+ channelName: string;
67
+ languageCode: string;
68
+ }) => Promise<any>;
69
+ export declare const clear: () => Promise<void>;