Skip to content

Commit dec36d4

Browse files
Merge pull request #305 from contentstack/enh/dx-3905
Added assetFields for DAM2.0 support
2 parents 980ac69 + 9344f8f commit dec36d4

File tree

15 files changed

+287
-57
lines changed

15 files changed

+287
-57
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Version: 5.1.0
2+
#### Date: Mar-02-2026
3+
Fix: Added support of asset fields in assets & entries class.
4+
15
### Version: 5.0.1
26
#### Date: feb-23-2026
37
Fix: Added support of special symbols in regex method with safe pattern.

package-lock.json

Lines changed: 58 additions & 55 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/delivery-sdk",
3-
"version": "5.0.1",
3+
"version": "5.1.0",
44
"type": "module",
55
"license": "MIT",
66
"engines": {

src/assets/asset.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AxiosInstance, getData } from '@contentstack/core';
33
export class Asset {
44
private _client: AxiosInstance;
55
private _urlPath: string;
6-
_queryParams: { [key: string]: string | number } = {};
6+
_queryParams: { [key: string]: string | number | string[] } = {};
77

88
constructor(client: AxiosInstance, assetUid: string) {
99
this._client = client;
@@ -129,6 +129,27 @@ export class Asset {
129129
return this;
130130
}
131131

132+
/**
133+
* @method assetFields
134+
* @memberof Asset
135+
* @description Include specific asset fields in the response (CDA getAssets - single asset).
136+
* Use with asset_fields[]: user_defined_fields, embedded, ai_suggested, visual_markups.
137+
* @example
138+
* import contentstack from '@contentstack/delivery-sdk'
139+
*
140+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
141+
* const result = await stack.asset("assetUid").assetFields("user_defined_fields", "embedded_metadata").fetch();
142+
*
143+
* @param {...string} fields - Asset field names to include (e.g. user_defined_fields, embedded, ai_suggested, visual_markups)
144+
* @returns {Asset} - Returns the Asset instance for chaining.
145+
*/
146+
assetFields(...fields: string[]): this {
147+
if (fields.length > 0) {
148+
this._queryParams['asset_fields[]'] = fields;
149+
}
150+
return this;
151+
}
152+
132153
/**
133154
* @method fetch
134155
* @memberof Asset

src/entries/entries.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,27 @@ export class Entries extends BaseQuery {
277277
return this;
278278
}
279279

280+
/**
281+
* @method assetFields
282+
* @memberof Entries
283+
* @description Include specific asset fields in the response (CDA getEntry/entries).
284+
* Use with asset_fields[]: user_defined_fields, embedded, ai_suggested, visual_markups.
285+
* @example
286+
* import contentstack from '@contentstack/delivery-sdk'
287+
*
288+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
289+
* const result = await stack.contentType("contentTypeUid").entry().assetFields("user_defined_fields", "embedded_metadata").find();
290+
*
291+
* @param {...string} fields - Asset field names to include (e.g. user_defined_fields, embedded, ai_suggested, visual_markups)
292+
* @returns {Entries} - Returns the Entries instance for chaining.
293+
*/
294+
assetFields(...fields: string[]): this {
295+
if (fields.length > 0) {
296+
this._queryParams['asset_fields[]'] = fields;
297+
}
298+
return this;
299+
}
300+
280301
/**
281302
* Override find method to include content type UID directly for better caching
282303
*/

src/entries/entry.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,25 @@ export class Entry {
273273
}
274274
return this;
275275
}
276+
277+
/**
278+
* @method assetFields
279+
* @memberof Entry
280+
* @description Include specific asset fields in the response (CDA getEntry).
281+
* Use with asset_fields[]: user_defined_fields, embedded, ai_suggested, visual_markups.
282+
* @example
283+
* import contentstack from '@contentstack/delivery-sdk'
284+
*
285+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
286+
* const result = await stack.contentType("contentTypeUid").entry("entryUid").assetFields("user_defined_fields", "embedded_metadata").fetch();
287+
*
288+
* @param {...string} fields - Asset field names to include (e.g. user_defined_fields, embedded, ai_suggested, visual_markups)
289+
* @returns {Entry} - Returns the Entry instance for chaining.
290+
*/
291+
assetFields(...fields: string[]): this {
292+
if (fields.length > 0) {
293+
this._queryParams['asset_fields[]'] = fields;
294+
}
295+
return this;
296+
}
276297
}

src/query/asset-query.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,28 @@ export class AssetQuery extends BaseQuery {
126126

127127
return this;
128128
}
129+
130+
/**
131+
* @method assetFields
132+
* @memberof AssetQuery
133+
* @description Include specific asset fields in the response (CDA getAssets).
134+
* Use with asset_fields[]: user_defined_fields, embedded, ai_suggested, visual_markups.
135+
* @example
136+
* import contentstack from '@contentstack/delivery-sdk'
137+
*
138+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
139+
* const result = await stack.asset().assetFields("user_defined_fields", "embedded_metadata").find();
140+
*
141+
* @param {...string} fields - Asset field names to include (e.g. user_defined_fields, embedded, ai_suggested, visual_markups)
142+
* @returns {AssetQuery} - Returns the AssetQuery instance for chaining.
143+
*/
144+
assetFields(...fields: string[]): this {
145+
if (fields.length > 0) {
146+
this._queryParams['asset_fields[]'] = fields;
147+
}
148+
return this;
149+
}
150+
129151
/**
130152
* @method query
131153
* @memberof AssetQuery

0 commit comments

Comments
 (0)