@agility/content-sync 1.2.0-beta.7 → 1.2.0-beta.8.1

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/README.md CHANGED
@@ -35,6 +35,24 @@ Install `@agility/content-sync`:
35
35
  npm install @agility/content-sync
36
36
  ```
37
37
 
38
+ ## Import Patterns
39
+
40
+ ```javascript
41
+ // Default import
42
+ import getSyncClient from '@agility/content-sync';
43
+ const syncClient = getSyncClient({...});
44
+
45
+ // Named import
46
+ import { getSyncClient } from '@agility/content-sync';
47
+ const syncClient = getSyncClient({...});
48
+
49
+ // CommonJS
50
+ const getSyncClient = require('@agility/content-sync');
51
+ const syncClient = getSyncClient({...});
52
+ ```
53
+
54
+ > **Note:** If upgrading and encountering `Cannot read properties of undefined (reading 'getSyncClient')`, use `require('@agility/content-sync').default.getSyncClient` for compatibility with transpiled code.
55
+
38
56
  ## Sync to Filesystem (using Defaults)
39
57
  1. Create a sync client:
40
58
  ```javascript
@@ -62,7 +80,7 @@ npm install @agility/content-sync
62
80
  ## Accessing Content
63
81
  Once content is in your sync store, you can easily access it as you need it:
64
82
  ```javascript
65
- import agilitySync from '@agility/constent-sync'
83
+ import agilitySync from '@agility/content-sync'
66
84
  const syncClient = agilitySync.getSyncClient({
67
85
  //your 'guid' from Agility CMS
68
86
  guid: 'some-guid',
@@ -175,7 +193,7 @@ module.exports = {
175
193
  ```
176
194
  2. Register the `syncClient` to use your **Sync Store**
177
195
  ```javascript
178
- import agilitySync from '@agility/constent-sync'
196
+ import agilitySync from '@agility/content-sync'
179
197
  import sampleSyncConsoleInterface from './store-interface-console'
180
198
  const syncClient = agilitySync.getSyncClient({
181
199
  //your 'guid' from Agility CMS
@@ -14749,7 +14749,15 @@ function createSyncClient(userConfig) {
14749
14749
  };
14750
14750
  }
14751
14751
 
14752
+ // Export for ES modules
14752
14753
 
14753
14754
 
14755
+ // Export for CommonJS - support both direct function call and .default.getSyncClient pattern
14756
+ var syncClientExport = getSyncClient;
14757
+ syncClientExport.getSyncClient = getSyncClient;
14758
+ syncClientExport["default"] = { getSyncClient: getSyncClient };
14759
+
14760
+ /* harmony default export */ var sync_client = __webpack_exports__["default"] = (syncClientExport);
14761
+
14754
14762
  /***/ })
14755
- /******/ ]);
14763
+ /******/ ])["default"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agility/content-sync",
3
- "version": "1.2.0-beta.7",
3
+ "version": "1.2.0-beta.8.1",
4
4
  "description": "JavaScript SDK for synchronizing content from Agility CMS",
5
5
  "main": "dist/agility-sync-sdk.node.js",
6
6
  "scripts": {
@@ -82,4 +82,12 @@ function createSyncClient(userConfig) {
82
82
  }
83
83
  }
84
84
 
85
- export { getSyncClient }
85
+ // Export for ES modules
86
+ export { getSyncClient }
87
+
88
+ // Export for CommonJS - support both direct function call and .default.getSyncClient pattern
89
+ const syncClientExport = getSyncClient;
90
+ syncClientExport.getSyncClient = getSyncClient;
91
+ syncClientExport.default = { getSyncClient };
92
+
93
+ export default syncClientExport
@@ -0,0 +1,99 @@
1
+ import chai from 'chai'
2
+ const assert = chai.assert;
3
+
4
+ // Test the built dist module (what gets published to npm)
5
+ const path = require('path');
6
+ const fs = require('fs');
7
+
8
+ //This tests the actual built module that gets published
9
+ describe('Built Module Export Compatibility:', function() {
10
+
11
+ this.timeout('30s');
12
+
13
+ let builtModulePath;
14
+
15
+ before(function() {
16
+ builtModulePath = path.resolve(__dirname, '../dist/agility-sync-sdk.node.js');
17
+
18
+ // Check if the built file exists
19
+ if (!fs.existsSync(builtModulePath)) {
20
+ throw new Error('Built module not found. Run "npm run build" first.');
21
+ }
22
+ });
23
+
24
+ it('should support CommonJS require() import', function(done) {
25
+ // Clear require cache to ensure fresh import
26
+ delete require.cache[builtModulePath];
27
+
28
+ const contentSync = require(builtModulePath);
29
+ assert.strictEqual(typeof contentSync, 'function', 'CommonJS import should return a function');
30
+ done();
31
+ });
32
+
33
+ it('should support customer pattern: require().default.getSyncClient', function(done) {
34
+ // This is the exact pattern that was failing: content_sync_1.default.getSyncClient
35
+ delete require.cache[builtModulePath];
36
+
37
+ const contentSync = require(builtModulePath);
38
+
39
+ assert.strictEqual(typeof contentSync.default, 'object', 'default should be an object');
40
+ assert.strictEqual(typeof contentSync.default.getSyncClient, 'function', 'default.getSyncClient should be a function');
41
+
42
+ // Test that it actually works
43
+ const syncClient = contentSync.default.getSyncClient({
44
+ guid: 'test-guid',
45
+ apiKey: 'test-key'
46
+ });
47
+
48
+ assert.strictEqual(typeof syncClient, 'object', 'Should return sync client object');
49
+ assert.strictEqual(typeof syncClient.syncContent, 'function', 'Should have syncContent method');
50
+ assert.strictEqual(typeof syncClient.syncPages, 'function', 'Should have syncPages method');
51
+ assert.strictEqual(typeof syncClient.runSync, 'function', 'Should have runSync method');
52
+ assert.strictEqual(typeof syncClient.clearSync, 'function', 'Should have clearSync method');
53
+
54
+ done();
55
+ });
56
+
57
+ it('should support alternative patterns for flexibility', function(done) {
58
+ delete require.cache[builtModulePath];
59
+
60
+ const contentSync = require(builtModulePath);
61
+ const testConfig = { guid: 'test-guid', apiKey: 'test-key' };
62
+
63
+ // Test direct function call
64
+ const client1 = contentSync(testConfig);
65
+ assert.strictEqual(typeof client1, 'object', 'Direct function call should work');
66
+
67
+ // Test .getSyncClient property
68
+ const client2 = contentSync.getSyncClient(testConfig);
69
+ assert.strictEqual(typeof client2, 'object', 'getSyncClient property should work');
70
+
71
+ done();
72
+ });
73
+
74
+ it('should maintain consistency across all import patterns', function(done) {
75
+ delete require.cache[builtModulePath];
76
+
77
+ const contentSync = require(builtModulePath);
78
+ const testConfig = { guid: 'test-guid', apiKey: 'test-key' };
79
+
80
+ const client1 = contentSync(testConfig);
81
+ const client2 = contentSync.getSyncClient(testConfig);
82
+ const client3 = contentSync.default.getSyncClient(testConfig);
83
+
84
+ // All should have the same structure
85
+ const expectedProperties = ['config', 'agilityClient', 'syncContent', 'syncPages', 'clearSync', 'runSync', 'store'];
86
+
87
+ expectedProperties.forEach(prop => {
88
+ assert.property(client1, prop, `client1 should have ${prop}`);
89
+ assert.property(client2, prop, `client2 should have ${prop}`);
90
+ assert.property(client3, prop, `client3 should have ${prop}`);
91
+
92
+ // Types should match
93
+ assert.strictEqual(typeof client1[prop], typeof client2[prop], `${prop} types should match between client1 and client2`);
94
+ assert.strictEqual(typeof client2[prop], typeof client3[prop], `${prop} types should match between client2 and client3`);
95
+ });
96
+
97
+ done();
98
+ });
99
+ });
@@ -1,7 +1,8 @@
1
1
  import chai from 'chai'
2
2
  const assert = chai.assert;
3
3
 
4
- import agilitySync from '../src/sync-client'
4
+ import * as agilitySync from '../src/sync-client'
5
+ import syncClientDefault from '../src/sync-client'
5
6
  import { createSyncClientUsingConsoleStore } from './_syncClients.config'
6
7
 
7
8
 
@@ -34,5 +35,81 @@ describe('getSyncClient:', function() {
34
35
  const syncClient = createSyncClientUsingConsoleStore()
35
36
  done();
36
37
  })
38
+
39
+ // Export compatibility tests to ensure multiple import patterns work
40
+ describe('Export Compatibility:', function() {
41
+
42
+ it('should support named import (getSyncClient)', function(done) {
43
+ assert.strictEqual(typeof agilitySync.getSyncClient, 'function', 'Named import should be a function');
44
+
45
+ const syncClient = agilitySync.getSyncClient({
46
+ guid: 'test-guid',
47
+ apiKey: 'test-key'
48
+ });
49
+ assert.strictEqual(typeof syncClient, 'object', 'Should return sync client object');
50
+ done();
51
+ })
52
+
53
+ it('should support default import as function', function(done) {
54
+ assert.strictEqual(typeof syncClientDefault, 'function', 'Default import should be a function');
55
+
56
+ const syncClient = syncClientDefault({
57
+ guid: 'test-guid',
58
+ apiKey: 'test-key'
59
+ });
60
+ assert.strictEqual(typeof syncClient, 'object', 'Should return sync client object');
61
+ done();
62
+ })
63
+
64
+ it('should support default import with getSyncClient property', function(done) {
65
+ assert.strictEqual(typeof syncClientDefault.getSyncClient, 'function', 'Default.getSyncClient should be a function');
66
+
67
+ const syncClient = syncClientDefault.getSyncClient({
68
+ guid: 'test-guid',
69
+ apiKey: 'test-key'
70
+ });
71
+ assert.strictEqual(typeof syncClient, 'object', 'Should return sync client object');
72
+ done();
73
+ })
74
+
75
+ it('should support CommonJS-style default.getSyncClient pattern', function(done) {
76
+ // This tests the pattern that was failing for the customer: content_sync_1.default.getSyncClient
77
+ assert.strictEqual(typeof syncClientDefault.default, 'object', 'Default.default should be an object');
78
+ assert.strictEqual(typeof syncClientDefault.default.getSyncClient, 'function', 'Default.default.getSyncClient should be a function');
79
+
80
+ const syncClient = syncClientDefault.default.getSyncClient({
81
+ guid: 'test-guid',
82
+ apiKey: 'test-key'
83
+ });
84
+ assert.strictEqual(typeof syncClient, 'object', 'Should return sync client object');
85
+ done();
86
+ })
87
+
88
+ it('should ensure all import patterns return equivalent sync clients', function(done) {
89
+ const config = { guid: 'test-guid', apiKey: 'test-key' };
90
+
91
+ const client1 = agilitySync.getSyncClient(config);
92
+ const client2 = syncClientDefault(config);
93
+ const client3 = syncClientDefault.getSyncClient(config);
94
+ const client4 = syncClientDefault.default.getSyncClient(config);
95
+
96
+ // All should have the same structure
97
+ assert.strictEqual(typeof client1, 'object');
98
+ assert.strictEqual(typeof client2, 'object');
99
+ assert.strictEqual(typeof client3, 'object');
100
+ assert.strictEqual(typeof client4, 'object');
101
+
102
+ // All should have the same methods
103
+ const expectedMethods = ['syncContent', 'syncPages', 'clearSync', 'runSync'];
104
+ expectedMethods.forEach(method => {
105
+ assert.strictEqual(typeof client1[method], 'function', `client1.${method} should be a function`);
106
+ assert.strictEqual(typeof client2[method], 'function', `client2.${method} should be a function`);
107
+ assert.strictEqual(typeof client3[method], 'function', `client3.${method} should be a function`);
108
+ assert.strictEqual(typeof client4[method], 'function', `client4.${method} should be a function`);
109
+ });
110
+
111
+ done();
112
+ })
113
+ })
37
114
 
38
115
  });
package/webpack.config.js CHANGED
@@ -7,7 +7,8 @@ const nodeConfig = {
7
7
  output: {
8
8
  filename: 'agility-sync-sdk.node.js',
9
9
  path: path.resolve(__dirname, 'dist'),
10
- libraryTarget: 'commonjs2'
10
+ libraryTarget: 'commonjs2',
11
+ libraryExport: 'default'
11
12
  },
12
13
  optimization: {
13
14
  minimize: false