@agility/content-sync 1.2.0 → 1.2.4

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.
@@ -0,0 +1,33 @@
1
+ name: Publish to npm
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ paths:
8
+ - package.json
9
+
10
+ jobs:
11
+ publish:
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ id-token: write
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - uses: actions/setup-node@v4
19
+ with:
20
+ node-version: 20
21
+ registry-url: https://registry.npmjs.org
22
+
23
+ - name: Upgrade npm for Trusted Publisher OIDC support
24
+ run: npm install -g npm@latest
25
+
26
+ - name: Install dependencies
27
+ run: npm ci
28
+
29
+ - name: Build
30
+ run: npm run build
31
+
32
+ - name: Publish
33
+ run: npm publish --access public --provenance
@@ -14482,21 +14482,21 @@ main_default.a.config({
14482
14482
  * @param {String} params.itemType - The type of item being saved/updated, expected values are `item`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
14483
14483
  * @param {String} params.languageCode - The locale code associated to the item being saved/updated
14484
14484
  * @param {(String|Number)} params.itemID - The ID of the item being saved/updated - this could be a string or number depending on the itemType
14485
- * @returns {Void}
14485
+ * @returns {promise<void>}
14486
14486
  */
14487
14487
  var saveItem = /*#__PURE__*/function () {var _ref2 = asyncToGenerator_default()(/*#__PURE__*/regenerator_default.a.mark(function _callee(_ref) {var options, item, itemType, languageCode, itemID, filePath, dirPath, json;return regenerator_default.a.wrap(function (_context) {while (1) switch (_context.prev = _context.next) {case 0:options = _ref.options, item = _ref.item, itemType = _ref.itemType, languageCode = _ref.languageCode, itemID = _ref.itemID;
14488
14488
 
14489
14489
  filePath = store_interface_filesystem_getFilePath({ options: options, itemType: itemType, languageCode: languageCode, itemID: itemID });
14490
14490
 
14491
- dirPath = external_path_default.a.dirname(filePath);
14491
+ dirPath = external_path_default.a.dirname(filePath);if (
14492
14492
 
14493
14493
 
14494
- if (!external_fs_default.a.existsSync(dirPath)) {
14495
- external_fs_default.a.mkdirSync(dirPath, { recursive: true });
14496
- }
14494
+ external_fs_default.a.existsSync(dirPath)) {_context.next = 1;break;}_context.next = 1;return (
14495
+ external_fs_default.a.promises.mkdir(dirPath, { recursive: true }));case 1:
14496
+
14497
14497
 
14498
- json = JSON.stringify(item);
14499
- external_fs_default.a.writeFileSync(filePath, json);case 1:case "end":return _context.stop();}}, _callee);}));return function saveItem(_x) {return _ref2.apply(this, arguments);};}();
14498
+ json = JSON.stringify(item);_context.next = 2;return (
14499
+ external_fs_default.a.promises.writeFile(filePath, json));case 2:case "end":return _context.stop();}}, _callee);}));return function saveItem(_x) {return _ref2.apply(this, arguments);};}();
14500
14500
 
14501
14501
  /**
14502
14502
  * The function to handle deleting an item to your storage. This could be a Content Item, Page, Url Redirections, Sync State (state), or Sitemap.
@@ -14506,15 +14506,15 @@ var saveItem = /*#__PURE__*/function () {var _ref2 = asyncToGenerator_default()(
14506
14506
  * @param {String} params.itemType - The type of item being deleted, expected values are `item`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
14507
14507
  * @param {String} params.languageCode - The locale code associated to the item being saved/updated
14508
14508
  * @param {(String|Number)} params.itemID - The ID of the item being deleted - this could be a string or number depending on the itemType
14509
- * @returns {Void}
14509
+ * @returns {promise<void>}
14510
14510
  */
14511
14511
  var deleteItem = /*#__PURE__*/function () {var _ref4 = asyncToGenerator_default()(/*#__PURE__*/regenerator_default.a.mark(function _callee2(_ref3) {var options, itemType, languageCode, itemID, filePath;return regenerator_default.a.wrap(function (_context2) {while (1) switch (_context2.prev = _context2.next) {case 0:options = _ref3.options, itemType = _ref3.itemType, languageCode = _ref3.languageCode, itemID = _ref3.itemID;
14512
14512
 
14513
- filePath = store_interface_filesystem_getFilePath({ options: options, itemType: itemType, languageCode: languageCode, itemID: itemID });
14513
+ filePath = store_interface_filesystem_getFilePath({ options: options, itemType: itemType, languageCode: languageCode, itemID: itemID });if (!
14514
+
14515
+ external_fs_default.a.existsSync(filePath)) {_context2.next = 1;break;}_context2.next = 1;return (
14516
+ external_fs_default.a.promises.unlink(filePath));case 1:case "end":return _context2.stop();}}, _callee2);}));return function deleteItem(_x2) {return _ref4.apply(this, arguments);};}();
14514
14517
 
14515
- if (external_fs_default.a.existsSync(filePath)) {
14516
- external_fs_default.a.unlinkSync(filePath);
14517
- }case 1:case "end":return _context2.stop();}}, _callee2);}));return function deleteItem(_x2) {return _ref4.apply(this, arguments);};}();
14518
14518
 
14519
14519
 
14520
14520
  /**
@@ -14527,7 +14527,7 @@ var deleteItem = /*#__PURE__*/function () {var _ref4 = asyncToGenerator_default(
14527
14527
  * @param {(String|Number)} params.itemID - The ID of the item being updated - this could be a string or number depending on the itemType
14528
14528
  * @param {String} params.referenceName - The reference name of the Content List that this Content Item should be added to
14529
14529
  * @param {String} params.definitionName - The Model name that the Content Item is based on
14530
- * @returns {Void}
14530
+ * @returns {Promise<void>}
14531
14531
  */
14532
14532
  var mergeItemToList = /*#__PURE__*/function () {var _ref6 = asyncToGenerator_default()(/*#__PURE__*/regenerator_default.a.mark(function _callee3(_ref5) {var options, item, languageCode, itemID, referenceName, definitionName, contentList, cIndex;return regenerator_default.a.wrap(function (_context3) {while (1) switch (_context3.prev = _context3.next) {case 0:options = _ref5.options, item = _ref5.item, languageCode = _ref5.languageCode, itemID = _ref5.itemID, referenceName = _ref5.referenceName, definitionName = _ref5.definitionName;_context3.next = 1;return (
14533
14533
 
@@ -14571,15 +14571,15 @@ var mergeItemToList = /*#__PURE__*/function () {var _ref6 = asyncToGenerator_def
14571
14571
  * @param {String} params.itemType - The type of item being accessed, expected values are `item`, `list`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
14572
14572
  * @param {String} params.languageCode - The locale code associated to the item being accessed
14573
14573
  * @param {(String|Number)} params.itemID - The ID of the item being accessed - this could be a string or number depending on the itemType
14574
- * @returns {Object}
14574
+ * @returns {Promise<Object>}
14575
14575
  */
14576
14576
  var getItem = /*#__PURE__*/function () {var _ref8 = asyncToGenerator_default()(/*#__PURE__*/regenerator_default.a.mark(function _callee4(_ref7) {var options, itemType, languageCode, itemID, filePath, json;return regenerator_default.a.wrap(function (_context4) {while (1) switch (_context4.prev = _context4.next) {case 0:options = _ref7.options, itemType = _ref7.itemType, languageCode = _ref7.languageCode, itemID = _ref7.itemID;
14577
14577
  filePath = store_interface_filesystem_getFilePath({ options: options, itemType: itemType, languageCode: languageCode, itemID: itemID });if (
14578
14578
 
14579
- external_fs_default.a.existsSync(filePath)) {_context4.next = 1;break;}return _context4.abrupt("return", null);case 1:
14579
+ external_fs_default.a.existsSync(filePath)) {_context4.next = 1;break;}return _context4.abrupt("return", null);case 1:_context4.next = 2;return (
14580
14580
 
14581
- json = external_fs_default.a.readFileSync(filePath, 'utf8');return _context4.abrupt("return",
14582
- JSON.parse(json));case 2:case "end":return _context4.stop();}}, _callee4);}));return function getItem(_x4) {return _ref8.apply(this, arguments);};}();
14581
+ external_fs_default.a.promises.readFile(filePath, 'utf8'));case 2:json = _context4.sent;return _context4.abrupt("return",
14582
+ JSON.parse(json));case 3:case "end":return _context4.stop();}}, _callee4);}));return function getItem(_x4) {return _ref8.apply(this, arguments);};}();
14583
14583
 
14584
14584
 
14585
14585
  /**
@@ -14587,10 +14587,10 @@ var getItem = /*#__PURE__*/function () {var _ref8 = asyncToGenerator_default()(/
14587
14587
  * @param {Object} params - The parameters object
14588
14588
  * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
14589
14589
  * @param {String} params.options.rootPath - The path to store/access the content as JSON
14590
- * @returns {Void}
14590
+ * @returns {Promise<void>}
14591
14591
  */
14592
- var clearItems = /*#__PURE__*/function () {var _ref0 = asyncToGenerator_default()(/*#__PURE__*/regenerator_default.a.mark(function _callee5(_ref9) {var options;return regenerator_default.a.wrap(function (_context5) {while (1) switch (_context5.prev = _context5.next) {case 0:options = _ref9.options;
14593
- external_fs_default.a.rmdirSync(options.rootPath, { recursive: true });case 1:case "end":return _context5.stop();}}, _callee5);}));return function clearItems(_x5) {return _ref0.apply(this, arguments);};}();
14592
+ var clearItems = /*#__PURE__*/function () {var _ref0 = asyncToGenerator_default()(/*#__PURE__*/regenerator_default.a.mark(function _callee5(_ref9) {var options;return regenerator_default.a.wrap(function (_context5) {while (1) switch (_context5.prev = _context5.next) {case 0:options = _ref9.options;_context5.next = 1;return (
14593
+ external_fs_default.a.promises.rmdir(options.rootPath, { recursive: true }));case 1:case "end":return _context5.stop();}}, _callee5);}));return function clearItems(_x5) {return _ref0.apply(this, arguments);};}();
14594
14594
 
14595
14595
 
14596
14596
 
@@ -14603,37 +14603,37 @@ var mutexLock = /*#__PURE__*/function () {var _ref1 = asyncToGenerator_default()
14603
14603
 
14604
14604
 
14605
14605
  dir = external_os_default.a.tmpdir();
14606
- lockFile = "".concat(dir, "/", "agility-sync", ".mutex");
14607
- if (!external_fs_default.a.existsSync(lockFile)) {
14608
- external_fs_default.a.writeFileSync(lockFile, "agility-sync");
14609
- }
14606
+ lockFile = "".concat(dir, "/", "agility-sync", ".mutex");if (
14607
+ external_fs_default.a.existsSync(lockFile)) {_context6.next = 1;break;}_context6.next = 1;return (
14608
+ external_fs_default.a.promises.writeFile(lockFile, "agility-sync"));case 1:_context6.next = 2;return (
14609
+
14610
+
14610
14611
 
14611
- //THE LOCK IS ALREADY HELD - WAIT UP!
14612
- _context6.next = 1;return waitOnLock(lockFile);case 1:_context6.prev = 1;return _context6.abrupt("return",
14612
+ waitOnLock(lockFile));case 2:_context6.prev = 2;return _context6.abrupt("return",
14613
14613
 
14614
14614
 
14615
- Object(proper_lockfile["lockSync"])(lockFile));case 2:_context6.prev = 2;_t = _context6["catch"](1);if (!(
14615
+ Object(proper_lockfile["lockSync"])(lockFile));case 3:_context6.prev = 3;_t = _context6["catch"](2);if (!(
14616
14616
 
14617
- "".concat(_t).indexOf("Lock file is already being held") !== -1)) {_context6.next = 8;break;}_context6.next = 3;return (
14617
+ "".concat(_t).indexOf("Lock file is already being held") !== -1)) {_context6.next = 9;break;}_context6.next = 4;return (
14618
14618
 
14619
14619
 
14620
- sleep(100));case 3:_context6.next = 4;return (
14621
- waitOnLock(lockFile));case 4:_context6.prev = 4;return _context6.abrupt("return",
14620
+ sleep(100));case 4:_context6.next = 5;return (
14621
+ waitOnLock(lockFile));case 5:_context6.prev = 5;return _context6.abrupt("return",
14622
14622
 
14623
14623
 
14624
- Object(proper_lockfile["lockSync"])(lockFile));case 5:_context6.prev = 5;_t2 = _context6["catch"](4);if (!(
14624
+ Object(proper_lockfile["lockSync"])(lockFile));case 6:_context6.prev = 6;_t2 = _context6["catch"](5);if (!(
14625
14625
 
14626
- "".concat(_t).indexOf("Lock file is already being held") !== -1)) {_context6.next = 8;break;}_context6.next = 6;return (
14626
+ "".concat(_t).indexOf("Lock file is already being held") !== -1)) {_context6.next = 9;break;}_context6.next = 7;return (
14627
14627
 
14628
14628
 
14629
- sleep(100));case 6:_context6.next = 7;return (
14630
- waitOnLock(lockFile));case 7:return _context6.abrupt("return",
14631
- Object(proper_lockfile["lockSync"])(lockFile));case 8:throw (
14629
+ sleep(100));case 7:_context6.next = 8;return (
14630
+ waitOnLock(lockFile));case 8:return _context6.abrupt("return",
14631
+ Object(proper_lockfile["lockSync"])(lockFile));case 9:throw (
14632
14632
 
14633
14633
 
14634
14634
 
14635
14635
 
14636
- Error("The mutex lock could not be obtained."));case 9:case "end":return _context6.stop();}}, _callee6, null, [[1, 2], [4, 5]]);}));return function mutexLock() {return _ref1.apply(this, arguments);};}();
14636
+ Error("The mutex lock could not be obtained."));case 10:case "end":return _context6.stop();}}, _callee6, null, [[2, 3], [5, 6]]);}));return function mutexLock() {return _ref1.apply(this, arguments);};}();
14637
14637
 
14638
14638
 
14639
14639
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agility/content-sync",
3
- "version": "1.2.0",
3
+ "version": "1.2.4",
4
4
  "description": "JavaScript SDK for synchronizing content from Agility CMS",
5
5
  "main": "dist/agility-sync-sdk.node.js",
6
6
  "scripts": {
@@ -1,8 +1,8 @@
1
1
  import fs from 'fs'
2
2
  import os from 'os'
3
3
  import path from 'path'
4
- import { sleep } from "./util.js"
5
- import { lockSync, unlockSync, checkSync, check } from "proper-lockfile"
4
+ import { sleep } from "./util"
5
+ import { lockSync, check } from "proper-lockfile"
6
6
  import dotenv from "dotenv"
7
7
 
8
8
  dotenv.config({
@@ -18,7 +18,7 @@ dotenv.config({
18
18
  * @param {String} params.itemType - The type of item being saved/updated, expected values are `item`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
19
19
  * @param {String} params.languageCode - The locale code associated to the item being saved/updated
20
20
  * @param {(String|Number)} params.itemID - The ID of the item being saved/updated - this could be a string or number depending on the itemType
21
- * @returns {Void}
21
+ * @returns {promise<void>}
22
22
  */
23
23
  const saveItem = async ({ options, item, itemType, languageCode, itemID }) => {
24
24
 
@@ -28,11 +28,11 @@ const saveItem = async ({ options, item, itemType, languageCode, itemID }) => {
28
28
 
29
29
 
30
30
  if (!fs.existsSync(dirPath)) {
31
- fs.mkdirSync(dirPath, { recursive: true });
31
+ await fs.promises.mkdir(dirPath, { recursive: true });
32
32
  }
33
33
 
34
34
  let json = JSON.stringify(item);
35
- fs.writeFileSync(filePath, json);
35
+ await fs.promises.writeFile(filePath, json);
36
36
  }
37
37
  /**
38
38
  * The function to handle deleting an item to your storage. This could be a Content Item, Page, Url Redirections, Sync State (state), or Sitemap.
@@ -42,14 +42,14 @@ const saveItem = async ({ options, item, itemType, languageCode, itemID }) => {
42
42
  * @param {String} params.itemType - The type of item being deleted, expected values are `item`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
43
43
  * @param {String} params.languageCode - The locale code associated to the item being saved/updated
44
44
  * @param {(String|Number)} params.itemID - The ID of the item being deleted - this could be a string or number depending on the itemType
45
- * @returns {Void}
45
+ * @returns {promise<void>}
46
46
  */
47
47
  const deleteItem = async ({ options, itemType, languageCode, itemID }) => {
48
48
 
49
49
  let filePath = getFilePath({ options, itemType, languageCode, itemID });
50
50
 
51
51
  if (fs.existsSync(filePath)) {
52
- fs.unlinkSync(filePath);
52
+ await fs.promises.unlink(filePath);
53
53
  }
54
54
 
55
55
  }
@@ -63,7 +63,7 @@ const deleteItem = async ({ options, itemType, languageCode, itemID }) => {
63
63
  * @param {(String|Number)} params.itemID - The ID of the item being updated - this could be a string or number depending on the itemType
64
64
  * @param {String} params.referenceName - The reference name of the Content List that this Content Item should be added to
65
65
  * @param {String} params.definitionName - The Model name that the Content Item is based on
66
- * @returns {Void}
66
+ * @returns {Promise<void>}
67
67
  */
68
68
  const mergeItemToList = async ({ options, item, languageCode, itemID, referenceName, definitionName }) => {
69
69
 
@@ -107,14 +107,14 @@ const mergeItemToList = async ({ options, item, languageCode, itemID, referenceN
107
107
  * @param {String} params.itemType - The type of item being accessed, expected values are `item`, `list`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
108
108
  * @param {String} params.languageCode - The locale code associated to the item being accessed
109
109
  * @param {(String|Number)} params.itemID - The ID of the item being accessed - this could be a string or number depending on the itemType
110
- * @returns {Object}
110
+ * @returns {Promise<Object>}
111
111
  */
112
112
  const getItem = async ({ options, itemType, languageCode, itemID }) => {
113
113
  let filePath = getFilePath({ options, itemType, languageCode, itemID });
114
114
 
115
115
  if (!fs.existsSync(filePath)) return null;
116
116
 
117
- let json = fs.readFileSync(filePath, 'utf8');
117
+ let json = await fs.promises.readFile(filePath, 'utf8');
118
118
  return JSON.parse(json);
119
119
  }
120
120
 
@@ -123,10 +123,10 @@ const getItem = async ({ options, itemType, languageCode, itemID }) => {
123
123
  * @param {Object} params - The parameters object
124
124
  * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
125
125
  * @param {String} params.options.rootPath - The path to store/access the content as JSON
126
- * @returns {Void}
126
+ * @returns {Promise<void>}
127
127
  */
128
128
  const clearItems = async ({ options }) => {
129
- fs.rmdirSync(options.rootPath, { recursive: true })
129
+ await fs.promises.rmdir(options.rootPath, { recursive: true })
130
130
  }
131
131
 
132
132
 
@@ -141,7 +141,7 @@ const mutexLock = async () => {
141
141
  const dir = os.tmpdir();
142
142
  const lockFile = `${dir}/${"agility-sync"}.mutex`
143
143
  if (! fs.existsSync(lockFile)) {
144
- fs.writeFileSync(lockFile, "agility-sync");
144
+ await fs.promises.writeFile(lockFile, "agility-sync");
145
145
  }
146
146
 
147
147
  //THE LOCK IS ALREADY HELD - WAIT UP!
@@ -199,4 +199,4 @@ export default {
199
199
  getItem,
200
200
  clearItems,
201
201
  mutexLock
202
- }
202
+ }
@@ -1,29 +0,0 @@
1
- name: Publish to NPM
2
-
3
- on:
4
- release:
5
- types: [published]
6
-
7
- jobs:
8
- publish:
9
- runs-on: ubuntu-latest
10
-
11
- steps:
12
- - uses: actions/checkout@v4
13
-
14
- - name: Use Node.js 20
15
- uses: actions/setup-node@v4
16
- with:
17
- node-version: '20'
18
- registry-url: 'https://registry.npmjs.org/'
19
-
20
- - name: Install dependencies
21
- run: npm ci
22
-
23
- - name: Run tests
24
- run: npm test
25
-
26
- - name: Publish to NPM
27
- run: npm publish
28
- env:
29
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}