Skip to content

Commit 29c5dc4

Browse files
authored
Merge pull request #61 from contentstack/development
Development
2 parents 20d8938 + 2bb4ecc commit 29c5dc4

25 files changed

+200
-160
lines changed

.github/workflows/npm-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-node@v3
1515
with:
16-
node-version: '18.x'
16+
node-version: '20.x'
1717
registry-url: 'https://registry.npmjs.org'
1818
- run: npm ci
1919
- run: npm publish --tag latest --access public
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@v3
2626
- uses: actions/setup-node@v3
2727
with:
28-
node-version: '18.x'
28+
node-version: '20.x'
2929
registry-url: 'https://npm.pkg.github.com'
3030
scope: '@contentstack'
3131
- run: npm ci

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
## Change log
1+
### Version: 4.4.1
2+
#### Date: October-21-2024
3+
Fix: getData to receive params and headers both in data
4+
5+
### Version: 4.4.0
6+
#### Date: October-21-2024
7+
Enh: Node version bump
8+
Refactor: Package type changed to be module instead of CommonJS
29

310
### Version: 4.3.0
411
#### Date: Septmber-09-2024

config/webpack.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
const path = require('path');
1+
import path, { dirname } from 'path';
2+
import { fileURLToPath } from 'url';
23

3-
module.exports = {
4+
// Replicating __dirname in ES modules
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = dirname(__filename);
7+
8+
export default {
49
mode: 'production',
510
entry: './src/index.ts',
611
output: {

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/delivery-sdk",
3-
"version": "4.3.0",
4-
"type": "commonjs",
3+
"version": "4.4.1",
4+
"type": "module",
55
"main": "./dist/cjs/src/index.js",
66
"types": "./dist/types/src/index.d.ts",
77
"scripts": {

src/lib/asset-query.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class AssetQuery extends BaseQuery {
1616
* @example
1717
* import contentstack from '@contentstack/delivery-sdk'
1818
*
19-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
19+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
2020
* const result = await stack.asset().version(1).find();
2121
*/
2222
version(version: number): AssetQuery {
@@ -33,7 +33,7 @@ export class AssetQuery extends BaseQuery {
3333
* @example
3434
* import contentstack from '@contentstack/delivery-sdk'
3535
*
36-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
36+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
3737
* const result = await stack.asset().includeDimension().find();
3838
*/
3939
includeDimension(): AssetQuery {
@@ -50,7 +50,7 @@ export class AssetQuery extends BaseQuery {
5050
* @example
5151
* import contentstack from '@contentstack/delivery-sdk'
5252
*
53-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
53+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
5454
* const result = await stack.asset().includeBranch().find();
5555
*/
5656
includeBranch(): AssetQuery {
@@ -67,7 +67,7 @@ export class AssetQuery extends BaseQuery {
6767
* @example
6868
* import contentstack from '@contentstack/delivery-sdk'
6969
*
70-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
70+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
7171
* const result = await stack.asset().includeMetadata().fetch();
7272
*/
7373
includeMetadata(): AssetQuery {
@@ -84,7 +84,7 @@ export class AssetQuery extends BaseQuery {
8484
* @example
8585
* import contentstack from '@contentstack/delivery-sdk'
8686
*
87-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
87+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
8888
* const result = await stack.asset().relativeUrls().find();
8989
*/
9090
relativeUrls(): AssetQuery {
@@ -101,7 +101,7 @@ export class AssetQuery extends BaseQuery {
101101
* @example
102102
* import contentstack from '@contentstack/delivery-sdk'
103103
*
104-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
104+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
105105
* const result = await stack.asset().includeFallback().find();
106106
*/
107107
includeFallback(): AssetQuery {
@@ -118,7 +118,7 @@ export class AssetQuery extends BaseQuery {
118118
* @example
119119
* import contentstack from '@contentstack/delivery-sdk'
120120
*
121-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
121+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
122122
* const result = await stack.asset().locale('en-us').find();
123123
*/
124124
locale(locale: string): AssetQuery {
@@ -134,7 +134,7 @@ export class AssetQuery extends BaseQuery {
134134
* @example
135135
* import contentstack from '@contentstack/delivery-sdk'
136136
*
137-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
137+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
138138
* const result = await stack.asset().query().where('fieldUid', queryOperators, 'value').find();
139139
*/
140140
query() {

src/lib/asset.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Asset {
1818
* @example
1919
* import contentstack from '@contentstack/delivery-sdk'
2020
*
21-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
21+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
2222
* const result = await stack.asset('asset_uid').includeFallback().fetch();
2323
*/
2424
includeFallback(): Asset {
@@ -35,7 +35,7 @@ export class Asset {
3535
* @example
3636
* import contentstack from '@contentstack/delivery-sdk'
3737
*
38-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
38+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
3939
* const result = await stack.asset('asset_uid').includeMetadata().fetch();
4040
*/
4141
includeMetadata(): Asset {
@@ -52,7 +52,7 @@ export class Asset {
5252
* @example
5353
* import contentstack from '@contentstack/delivery-sdk'
5454
*
55-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
55+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
5656
* const result = await stack.asset('asset_uid').includeDimension().fetch();
5757
*/
5858
includeDimension(): Asset {
@@ -69,7 +69,7 @@ export class Asset {
6969
* @example
7070
* import contentstack from '@contentstack/delivery-sdk'
7171
*
72-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
72+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
7373
* const result = await stack.asset('asset_uid').includeBranch().fetch();
7474
*/
7575
includeBranch(): Asset {
@@ -86,7 +86,7 @@ export class Asset {
8686
* @example
8787
* import contentstack from '@contentstack/delivery-sdk'
8888
*
89-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
89+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
9090
* const result = await stack.asset('asset_uid').relativeUrls().fetch();
9191
*/
9292
relativeUrls(): Asset {
@@ -103,7 +103,7 @@ export class Asset {
103103
* @example
104104
* import contentstack from '@contentstack/delivery-sdk'
105105
*
106-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
106+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
107107
* const result = await stack.asset('asset_uid').version(1).fetch();
108108
*/
109109
version(version: number): Asset {
@@ -120,7 +120,7 @@ export class Asset {
120120
* @example
121121
* import contentstack from '@contentstack/delivery-sdk'
122122
*
123-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
123+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
124124
* const result = await stack.asset('asset_uid').locale('en-us').fetch();
125125
*/
126126
locale(locale: string): Asset {
@@ -137,11 +137,11 @@ export class Asset {
137137
* @example
138138
* import contentstack from '@contentstack/delivery-sdk'
139139
*
140-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
140+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
141141
* const result = await stack.asset('asset_uid').fetch();
142142
*/
143143
async fetch<T>(): Promise<T> {
144-
const response = await getData(this._client, this._urlPath, this._queryParams);
144+
const response = await getData(this._client, this._urlPath, { params: this._queryParams});
145145

146146
if (response.asset) return response.asset as T;
147147

src/lib/base-query.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export class BaseQuery extends Pagination {
88

99
protected _client!: AxiosInstance;
1010
protected _urlPath!: string;
11+
protected _variants!: string;
1112

1213
/**
1314
* @method includeCount
@@ -16,7 +17,7 @@ export class BaseQuery extends Pagination {
1617
* @example
1718
* import contentstack from '@contentstack/delivery-sdk'
1819
*
19-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
20+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
2021
* const query = stack.contentType("contentTypeUid").entry().query();
2122
* const result = await query.includeCount().find()
2223
* // OR
@@ -37,7 +38,7 @@ export class BaseQuery extends Pagination {
3738
* @example
3839
* import contentstack from '@contentstack/delivery-sdk'
3940
*
40-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
41+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
4142
* const query = stack.contentType("contentTypeUid").entry().query();
4243
* const result = await query.orderByAscending("field_uid").find()
4344
* // OR
@@ -58,7 +59,7 @@ export class BaseQuery extends Pagination {
5859
* @example
5960
* import contentstack from '@contentstack/delivery-sdk'
6061
*
61-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
62+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
6263
* const query = stack.contentType("contentTypeUid").entry().query();
6364
* const result = await query.orderByDescending("field_uid").find()
6465
* // OR
@@ -79,7 +80,7 @@ export class BaseQuery extends Pagination {
7980
* @example
8081
* import contentstack from '@contentstack/delivery-sdk'
8182
*
82-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
83+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
8384
* const query = stack.contentType("contentTypeUid").entry().query();
8485
* const result = await query.limit("limit_value").find()
8586
* // OR
@@ -100,7 +101,7 @@ export class BaseQuery extends Pagination {
100101
* @example
101102
* import contentstack from '@contentstack/delivery-sdk'
102103
*
103-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
104+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
104105
* const query = stack.contentType("contentTypeUid").entry().query();
105106
* const result = await query.skip("skip_value").find()
106107
* // OR
@@ -123,7 +124,7 @@ export class BaseQuery extends Pagination {
123124
* @example
124125
* import contentstack from '@contentstack/delivery-sdk'
125126
*
126-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
127+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
127128
* const query = stack.contentType("contentTypeUid").entry().query();
128129
* const result = await query.param("key", "value").find()
129130
* // OR
@@ -144,7 +145,7 @@ export class BaseQuery extends Pagination {
144145
* @example
145146
* import contentstack from '@contentstack/delivery-sdk'
146147
*
147-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
148+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
148149
* const query = stack.contentType("contentTypeUid").entry().query();
149150
* const result = await query.addParams({"key": "value"}).find()
150151
* // OR
@@ -165,7 +166,7 @@ export class BaseQuery extends Pagination {
165166
* @example
166167
* import contentstack from '@contentstack/delivery-sdk'
167168
*
168-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
169+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
169170
* const query = stack.contentType("contentTypeUid").entry().query();
170171
* const result = await query.removeParam("query_param_key").find()
171172
* // OR
@@ -187,25 +188,37 @@ export class BaseQuery extends Pagination {
187188
* @example
188189
* import contentstack from '@contentstack/delivery-sdk'
189190
*
190-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
191+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
191192
* const result = await stack.asset().find();
192193
* @example
193194
* import contentstack from '@contentstack/delivery-sdk'
194195
*
195-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
196+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
196197
* const result = await stack.contentType("contentType1Uid").entry().query().find();
197198
* @example
198199
* import contentstack from '@contentstack/delivery-sdk'
199200
*
200-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
201+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
201202
* const result = await stack.asset(asset_uid).fetch();
202203
*/
203204

204205
async find<T>(): Promise<FindResponse<T>> {
205206
let requestParams: { [key: string]: any } = this._queryParams;
206-
if (Object.keys(this._parameters)) requestParams = { ...this._queryParams, query: { ...this._parameters } };
207207

208-
const response = await getData(this._client, this._urlPath, requestParams);
208+
if (Object.keys(this._parameters).length > 0) {
209+
requestParams = { ...this._queryParams, query: { ...this._parameters } };
210+
}
211+
212+
const getRequestOptions: any = { params: requestParams };
213+
214+
if (this._variants) {
215+
getRequestOptions.headers = {
216+
...getRequestOptions.headers,
217+
'x-cs-variant-uid': this._variants
218+
};
219+
}
220+
221+
const response = await getData(this._client, this._urlPath, getRequestOptions);
209222

210223
return response as FindResponse<T>;
211224
}

src/lib/content-type.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class ContentType {
2626
* @example
2727
* import contentstack from '@contentstack/delivery-sdk'
2828
*
29-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
29+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
3030
* const entry = stack.contentType("contentTypeUid").entry("entryUid");
3131
*/
3232
entry(uid: string): Entry;
@@ -45,8 +45,8 @@ export class ContentType {
4545
* @example
4646
* import contentstack from '@contentstack/delivery-sdk'
4747
*
48-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
49-
* const result = await stack.contentType(asset_uid).fetch();
48+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
49+
* const result = await stack.contentType(contenttype_uid).fetch();
5050
*/
5151
async fetch<T>(): Promise<T> {
5252
const response = await getData(this._client, this._urlPath);

src/lib/contentstack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ let version = '{{VERSION}}';
1616
*
1717
* @example
1818
* import contentstack from '@contentstack/delivery-sdk'
19-
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
19+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
2020
* @example
2121
* import contentstack from '@contentstack/delivery-sdk'
22-
* const stack = contentstack.Stack({
22+
* const stack = contentstack.stack({
2323
* apiKey: "apiKey",
2424
* deliveryToken: "deliveryToken",
2525
* environment: "environment",

0 commit comments

Comments
 (0)