Skip to content

Development #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish --tag latest --access public
Expand All @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
node-version: '20.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@contentstack'
- run: npm ci
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## Change log
### Version: 4.4.1
#### Date: October-21-2024
Fix: getData to receive params and headers both in data

### Version: 4.4.0
#### Date: October-21-2024
Enh: Node version bump
Refactor: Package type changed to be module instead of CommonJS

### Version: 4.3.0
#### Date: Septmber-09-2024
Expand Down
9 changes: 7 additions & 2 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const path = require('path');
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';

module.exports = {
// Replicating __dirname in ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export default {
mode: 'production',
entry: './src/index.ts',
output: {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/delivery-sdk",
"version": "4.3.0",
"type": "commonjs",
"version": "4.4.1",
"type": "module",
"main": "./dist/cjs/src/index.js",
"types": "./dist/types/src/index.d.ts",
"scripts": {
Expand Down
16 changes: 8 additions & 8 deletions src/lib/asset-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class AssetQuery extends BaseQuery {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().version(1).find();
*/
version(version: number): AssetQuery {
Expand All @@ -33,7 +33,7 @@ export class AssetQuery extends BaseQuery {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeDimension().find();
*/
includeDimension(): AssetQuery {
Expand All @@ -50,7 +50,7 @@ export class AssetQuery extends BaseQuery {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeBranch().find();
*/
includeBranch(): AssetQuery {
Expand All @@ -67,7 +67,7 @@ export class AssetQuery extends BaseQuery {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeMetadata().fetch();
*/
includeMetadata(): AssetQuery {
Expand All @@ -84,7 +84,7 @@ export class AssetQuery extends BaseQuery {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().relativeUrls().find();
*/
relativeUrls(): AssetQuery {
Expand All @@ -101,7 +101,7 @@ export class AssetQuery extends BaseQuery {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeFallback().find();
*/
includeFallback(): AssetQuery {
Expand All @@ -118,7 +118,7 @@ export class AssetQuery extends BaseQuery {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().locale('en-us').find();
*/
locale(locale: string): AssetQuery {
Expand All @@ -134,7 +134,7 @@ export class AssetQuery extends BaseQuery {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().query().where('fieldUid', queryOperators, 'value').find();
*/
query() {
Expand Down
18 changes: 9 additions & 9 deletions src/lib/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Asset {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').includeFallback().fetch();
*/
includeFallback(): Asset {
Expand All @@ -35,7 +35,7 @@ export class Asset {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').includeMetadata().fetch();
*/
includeMetadata(): Asset {
Expand All @@ -52,7 +52,7 @@ export class Asset {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').includeDimension().fetch();
*/
includeDimension(): Asset {
Expand All @@ -69,7 +69,7 @@ export class Asset {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').includeBranch().fetch();
*/
includeBranch(): Asset {
Expand All @@ -86,7 +86,7 @@ export class Asset {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').relativeUrls().fetch();
*/
relativeUrls(): Asset {
Expand All @@ -103,7 +103,7 @@ export class Asset {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').version(1).fetch();
*/
version(version: number): Asset {
Expand All @@ -120,7 +120,7 @@ export class Asset {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').locale('en-us').fetch();
*/
locale(locale: string): Asset {
Expand All @@ -137,11 +137,11 @@ export class Asset {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').fetch();
*/
async fetch<T>(): Promise<T> {
const response = await getData(this._client, this._urlPath, this._queryParams);
const response = await getData(this._client, this._urlPath, { params: this._queryParams});

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

Expand Down
39 changes: 26 additions & 13 deletions src/lib/base-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class BaseQuery extends Pagination {

protected _client!: AxiosInstance;
protected _urlPath!: string;
protected _variants!: string;

/**
* @method includeCount
Expand All @@ -16,7 +17,7 @@ export class BaseQuery extends Pagination {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.includeCount().find()
* // OR
Expand All @@ -37,7 +38,7 @@ export class BaseQuery extends Pagination {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.orderByAscending("field_uid").find()
* // OR
Expand All @@ -58,7 +59,7 @@ export class BaseQuery extends Pagination {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.orderByDescending("field_uid").find()
* // OR
Expand All @@ -79,7 +80,7 @@ export class BaseQuery extends Pagination {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.limit("limit_value").find()
* // OR
Expand All @@ -100,7 +101,7 @@ export class BaseQuery extends Pagination {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.skip("skip_value").find()
* // OR
Expand All @@ -123,7 +124,7 @@ export class BaseQuery extends Pagination {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.param("key", "value").find()
* // OR
Expand All @@ -144,7 +145,7 @@ export class BaseQuery extends Pagination {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.addParams({"key": "value"}).find()
* // OR
Expand All @@ -165,7 +166,7 @@ export class BaseQuery extends Pagination {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.removeParam("query_param_key").find()
* // OR
Expand All @@ -187,25 +188,37 @@ export class BaseQuery extends Pagination {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().find();
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType("contentType1Uid").entry().query().find();
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset(asset_uid).fetch();
*/

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

const response = await getData(this._client, this._urlPath, requestParams);
if (Object.keys(this._parameters).length > 0) {
requestParams = { ...this._queryParams, query: { ...this._parameters } };
}

const getRequestOptions: any = { params: requestParams };

if (this._variants) {
getRequestOptions.headers = {
...getRequestOptions.headers,
'x-cs-variant-uid': this._variants
};
}

const response = await getData(this._client, this._urlPath, getRequestOptions);

return response as FindResponse<T>;
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ContentType {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const entry = stack.contentType("contentTypeUid").entry("entryUid");
*/
entry(uid: string): Entry;
Expand All @@ -45,8 +45,8 @@ export class ContentType {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType(asset_uid).fetch();
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType(contenttype_uid).fetch();
*/
async fetch<T>(): Promise<T> {
const response = await getData(this._client, this._urlPath);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/contentstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ let version = '{{VERSION}}';
*
* @example
* import contentstack from '@contentstack/delivery-sdk'
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* @example
* import contentstack from '@contentstack/delivery-sdk'
* const stack = contentstack.Stack({
* const stack = contentstack.stack({
* apiKey: "apiKey",
* deliveryToken: "deliveryToken",
* environment: "environment",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/contenttype-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ContentTypeQuery {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const contentTypeQuery = stack.contentType();
* const result = await contentTypeQuery.includeGlobalFieldSchema().find();
*/
Expand All @@ -35,12 +35,12 @@ export class ContentTypeQuery {
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const contentTypeQuery = stack.contentType();
* const result = await contentTypeQuery.find();
*/
async find<T>(): Promise<FindResponse<T>> {
const response = await getData(this._client, this._urlPath, this._queryParams);
const response = await getData(this._client, this._urlPath, { params: this._queryParams });

return response as FindResponse<T>;
}
Expand Down
Loading
Loading