Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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 package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/app-sdk",
"version": "2.0.1",
"version": "2.0.2",
"types": "dist/src/index.d.ts",
"description": "The Contentstack App SDK allows you to customize your Contentstack applications.",
"main": "dist/index.js",
Expand Down
50 changes: 50 additions & 0 deletions src/stack/api/content-type/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
includeSchema,
includeReference,
} from "../../utils";
import { GenericObjectType } from "../../../types/common.types";

let connection = {};
let contentTypeUid = "";
Expand Down Expand Up @@ -375,6 +376,55 @@ class Entry extends Base {
this._query.locale = locale;
return this.fetch("updateEntry", payload);
}
/**
* @see {@link https://www.contentstack.com/docs/apis/content-management-api| fetch variant}
* @name Stack#ContentType#Entry#fetchVariant
* @function
* @description This call allows you to fetch variant customization of an entry.
* @param {string} variant_uid - parameter for the request
* @example appSDK.stack.ContentType('contenttype_uid').Entry('bltsomething123').fetchVariant('variant_uid').then(...).catch(...);
* @return {external:Promise}
*/

fetchVariant(variant_uid: string) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getVariant

if (!variant_uid || typeof variant_uid !== "string") {
return Promise.reject(new Error("Kindly provide valid parameters"));
}
this._query.variant_uid = variant_uid;
return this.fetch("fetchVariant");
}

/**
* @see {@link https://www.contentstack.com/docs/apis/content-management-api| update variant}
* @name Stack#ContentType#Entry#updateVariant
* @function
* @description This call allows you to update variant customization of an entry.
* @param {string} variant_uid - parameter for the request
* @param {object} payload - parameter for the request
* @example appSDK.stack.ContentType('contenttype_uid').Entry('bltsomething123').updateVariant('variant_uid',
* { "entry": {
"title": "test variant entry",
"url": "/variant-url",
"_variant": {
"_change_set": ["title", "url"]
}
}
}).then(...).catch(...);
* @return {external:Promise}
*/

updateVariant(variant_uid: string, payload: GenericObjectType) {
if (
!variant_uid ||
typeof variant_uid !== "string" ||
typeof payload !== "object" ||
payload instanceof Array
) {
return Promise.reject(new Error("Kindly provide valid parameters"));
}
this._query.variant_uid = variant_uid;
return this.fetch("updateVariant", payload);
}
}

export default (uiConnection: any, contentType: string) => {
Expand Down
24 changes: 24 additions & 0 deletions src/stack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import ContentType from './api/content-type/index';
import { onData, onError } from "../utils/utils";
import { BranchDetail, GetAllStacksOptions, StackAdditionalData, StackDetail, StackSearchQuery } from '../types/stack.types';
import { IManagementTokenDetails } from '../types';
import VariantGroup from "../variantGroup";
import { GenericObjectType } from "../types/common.types";


/**
Expand All @@ -18,6 +20,7 @@ class Stack {
_data: StackDetail
ContentType: any
Asset: any
VariantGroup: any
private _currentBranch: BranchDetail | null = null;


Expand All @@ -43,6 +46,16 @@ class Stack {
* */
this.Asset = Asset(connection);

/**
* @constructor
* @hideconstructor
* @desc An initializer is responsible for creating an VariantGroup object.
* @see {@link https://www.contentstack.com/docs/apis/content-management-api/| VariantGroup}
* @param {string} uid - variant group uid.
* @example appSDK.stack.VariantGroup('variant_group_uid')
* */
this.VariantGroup = VariantGroup(connection);

const currentBranch = additionalData.currentBranch || ""

if (currentBranch) {
Expand Down Expand Up @@ -272,6 +285,17 @@ class Stack {
getCurrentBranch(): BranchDetail | null {
return this._currentBranch;
}

/**
* Returns variant groups of the current stack.
* @returns variant groups of the current stack
*/
getVariantGroups(query = {}, params = {}) {
const optionParams: GenericObjectType = params;
optionParams.query = query;
const options = { params: optionParams, action: 'getVariantGroups' };
return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getVariantInfo


export default Stack;
4 changes: 3 additions & 1 deletion src/types/entry.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Field from "../field";
import { AnyProperty } from "./common.types";
import { AnyProperty, GenericObjectType } from "./common.types";

export declare interface IGetFieldOptions {
/**
Expand Down Expand Up @@ -47,4 +47,6 @@ export interface Entry extends AnyProperty {
publish_details: Array<any>;
locale: string;
url?: string;
_variant?: GenericObjectType ;
variant_id?: string
}
65 changes: 65 additions & 0 deletions src/variantGroup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import Base from "../stack/api/base";
import { GenericObjectType } from "../types/common.types";

/**
* Class representing the Variant Group.
*/

let connection = {};

class VariantGroup extends Base {
constructor(uid: string) {
if (!uid) {
throw new Error("uid is required");
}
super(uid);
this._query = {};
return this;
}

static get connection() {
return connection;
}

/**
* @function
* @name Stack#VariantGroup#createVariant
* @description This method creates a new variant in a group.
* @example appSDK.stack.VariantGroup("variant_group_uid").createVariant(variant_payload);
* @return {external:Promise}
*/
createVariant(payload: GenericObjectType) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not have it now.

return this.fetch("createVariant", payload);
}
/**
* @function
* @name Stack#VariantGroup#getVariantsByGroup
* @description This method returns all the variants within a group.
* @example appSDK.stack.VariantGroup("variant_group_uid").getVariantsByGroup();
* @return {external:Promise}
*/
getVariantsByGroup() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getVariants

return this.fetch("getVariantsByGroup");
}

/**
* @function
* @name Stack#VariantGroup#getVariantsByGroup#deleteVariant
* @description This method deletes a specified variant from a group.
* @example appSDK.stack.VariantGroup("variant_group_uid").deleteVariant("variant_uid");
* @return {external:Promise}
*/
deleteVariant(variant_uid: string) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not expose it now

this._query.variant_uid = variant_uid;
return this.fetch("deleteVariant");
}
}

export default (uiConnection: GenericObjectType) => {
connection = uiConnection;
return new Proxy(VariantGroup, {
apply(Target: any, thisArg, argumentsList: any[]) {
return new Target(...argumentsList);
},
});
};