Skip to content

Commit 9a6dd7e

Browse files
Merge pull request #36 from contentstack/development
DX | 10-11-2025 | Release
2 parents a8444f3 + d29d792 commit 9a6dd7e

File tree

8 files changed

+88
-16
lines changed

8 files changed

+88
-16
lines changed

.talismanrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@ fileignoreconfig:
44
- filecontent
55
- filename: package-lock.json
66
checksum: 20cc76958aec3163d9b695e49bcdfbef7244fc473e31f8eb69b88133622f4fb4
7+
- filename: src/index.ts
8+
checksum: 3563972e6fef958b021444c41ef04f5f32e83d1d51f7faea62ad1633130b6f1a
9+
- filename: src/messages.ts
10+
checksum: 5fc01b165e2fec0c969b954b15ab9201eaabcdce766c8b007907377f015f0043
11+
- filename: typings/messages.d.ts
12+
checksum: f79568b5a95311acea1892c644554091c2b38d169a4867380693fa09e2639d95
713
version: ""

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/datasync-asset-store-filesystem",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"description": "Fillesystem asset store for DataSync libraries. Stores Contentstack asset-files in filesystem",
55
"main": "./dist",
66
"types": "./typings",

src/filesystem.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
validateUnPublishAsset,
3131
sanitizePath
3232
} from './utils'
33+
import { messages } from './messages'
3334

3435
const debug = Debug('asset-store-filesystem')
3536

@@ -76,7 +77,7 @@ export class FSAssetStore {
7677
* @returns {Promise} returns the asset object, if successful.
7778
*/
7879
public download(asset) {
79-
debug('Asset download invoked ' + JSON.stringify(asset))
80+
debug(messages.info.assetDownloadInitiated(asset))
8081

8182
return new Promise((resolve, reject) => {
8283
try {
@@ -112,12 +113,12 @@ export class FSAssetStore {
112113
return resolve(asset)
113114
})
114115
} else {
115-
return reject(`Failed to download asset ${JSON.stringify(asset)}`)
116+
return reject(messages.errors.assetDownloadFailed(asset))
116117
}
117118
})
118119
.catch(reject)
119120
} catch (error) {
120-
debug(`${asset.uid} asset download failed`)
121+
debug(messages.info.assetDownloadFailed(asset.uid))
121122

122123
return reject(error)
123124
}
@@ -132,7 +133,7 @@ export class FSAssetStore {
132133
* @returns {Promise} returns the asset object, if successful.
133134
*/
134135
public delete(assets: IAsset[]) {
135-
debug('Asset deletion called for', JSON.stringify(assets))
136+
debug(messages.info.assetDeletionInitiated(), JSON.stringify(assets))
136137
const asset = assets[0]
137138

138139
return new Promise((resolve, reject) => {
@@ -147,11 +148,11 @@ export class FSAssetStore {
147148
.then(() => rimraf(folderPath))
148149
.then(() => resolve(asset))
149150
.catch((error) => {
150-
debug(`Error while removing ${folderPath} asset file`);
151+
debug(messages.info.assetFileRemovalError(folderPath));
151152
return reject(error);
152153
});
153154
} else {
154-
debug(`${folderPath} did not exist!`)
155+
debug(messages.info.folderPathNotExist(folderPath))
155156

156157
return resolve(asset)
157158
}
@@ -169,7 +170,7 @@ export class FSAssetStore {
169170
* @returns {Promise} returns the asset object, if successful.
170171
*/
171172
public unpublish(asset: IAsset) {
172-
debug(`Asset unpublish called ${JSON.stringify(asset)}`)
173+
debug(messages.info.assetUnpublishInitiated(asset))
173174

174175
return new Promise((resolve, reject) => {
175176
try {
@@ -181,11 +182,11 @@ export class FSAssetStore {
181182
.then(() => rimraf(filePath))
182183
.then(() => resolve(asset))
183184
.catch((error) => {
184-
debug(`Error while removing ${filePath} asset file`);
185+
debug(messages.info.assetFileRemovalError(filePath));
185186
return reject(error);
186187
});
187188
}
188-
debug(`${filePath} did not exist!`)
189+
debug(messages.info.filePathNotExist(filePath))
189190

190191
return resolve(asset)
191192
} catch (error) {

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { compact, merge } from 'lodash'
99
import { join } from 'path'
1010
import { defaultConfig } from './config'
1111
import { FSAssetStore } from './filesystem'
12+
import { messages } from './messages'
1213

1314
let assetStoreConfig
1415
let assetStoreInstance
@@ -45,7 +46,7 @@ export const getAssetLocation = (asset, config) => {
4546
if (asset[k]) {
4647
values.push(asset[k])
4748
} else {
48-
throw new TypeError(`The key ${keys[i]} did not exist on ${JSON.stringify(asset)}`)
49+
throw new TypeError(messages.errors.keyNotExist(keys[i], asset))
4950
}
5051
} else {
5152
values.push(keys[i])
@@ -89,7 +90,7 @@ export const getFileLocation = (asset, config) => {
8990
if (asset[k]) {
9091
values.push(asset[k])
9192
} else {
92-
throw new TypeError(`The key ${keys[i]} did not exist on ${JSON.stringify(asset)}`)
93+
throw new TypeError(messages.errors.keyNotExist(keys[i], asset))
9394
}
9495
} else {
9596
values.push(keys[i])
@@ -132,7 +133,7 @@ export function start(config) {
132133
assetStoreInstance = new FSAssetStore(assetStoreConfig)
133134
return resolve(assetStoreInstance)
134135
} catch (error) {
135-
debug('Failed to load content-store due to', error)
136+
debug(messages.errors.contentStoreLoadFailed(), error)
136137
reject(error)
137138
}
138139
})

src/messages.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*!
2+
* contentstack-sync-asset-store-filesystem
3+
* copyright (c) Contentstack LLC
4+
* MIT Licensed
5+
*/
6+
7+
/**
8+
* Centralized error and log messages for the asset store filesystem
9+
*/
10+
export const messages = {
11+
// Error messages
12+
errors: {
13+
keyNotExist: (key: string, asset: any) =>
14+
`The key '${key}' does not exist on: ${JSON.stringify(asset)}`,
15+
contentStoreLoadFailed: () =>
16+
'Failed to load content store:',
17+
assetDownloadFailed: (asset: any) =>
18+
`Failed to download asset ${JSON.stringify(asset)}`,
19+
},
20+
21+
// Info/Debug messages
22+
info: {
23+
assetDownloadInitiated: (asset: any) =>
24+
`Asset download initiated for: ${JSON.stringify(asset)}`,
25+
assetDownloadFailed: (uid: string) =>
26+
`Download failed for asset: ${uid}`,
27+
assetDeletionInitiated: () =>
28+
'Asset deletion initiated:',
29+
assetFileRemovalError: (path: string) =>
30+
`An error occurred while removing the asset file at: ${path}`,
31+
folderPathNotExist: (path: string) =>
32+
`Folder path does not exist: ${path}`,
33+
assetUnpublishInitiated: (asset: any) =>
34+
`Asset unpublish initiated for: ${JSON.stringify(asset)}`,
35+
filePathNotExist: (path: string) =>
36+
`File path does not exist: ${path}`,
37+
},
38+
}
39+

test/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
const assetConnector = require('../dist')
99
const config = require('../dist/config')
1010
const filesystem = require('fs')
11+
const { messages } = require('../dist/messages')
1112
let connector = null
1213

1314
let conf = {
@@ -128,7 +129,8 @@ describe('# asset test', function () {
128129
test('# download non existent asset', function () {
129130
return connector.download(asset_data2).then(function () {
130131
}).catch(error =>{
131-
expect(error).toBe('blt9c4ef3c49f7b18h9 Asset download failed')
132+
// Verify that download fails with correct error message
133+
expect(error).toBe(messages.errors.assetDownloadFailed(asset_data2))
132134
})
133135
})
134136

typings/messages.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*!
2+
* contentstack-sync-asset-store-filesystem
3+
* copyright (c) Contentstack LLC
4+
* MIT Licensed
5+
*/
6+
7+
export declare const messages: {
8+
errors: {
9+
keyNotExist: (key: string, asset: any) => string;
10+
contentStoreLoadFailed: () => string;
11+
assetDownloadFailed: (asset: any) => string;
12+
};
13+
info: {
14+
assetDownloadInitiated: (asset: any) => string;
15+
assetDownloadFailed: (uid: string) => string;
16+
assetDeletionInitiated: () => string;
17+
assetFileRemovalError: (path: string) => string;
18+
folderPathNotExist: (path: string) => string;
19+
assetUnpublishInitiated: (asset: any) => string;
20+
filePathNotExist: (path: string) => string;
21+
};
22+
};
23+

0 commit comments

Comments
 (0)