From 5fac3a303484963eba25cdb17c2cc90f58519701 Mon Sep 17 00:00:00 2001 From: Netraj Patel Date: Tue, 1 Jul 2025 18:23:19 +0530 Subject: [PATCH] Added AWS-AU support --- .talismanrc | 18 +- CHANGELOG.md | 25 +- index.d.ts | 437 +++++++++++++------------- package-lock.json | 4 +- package.json | 2 +- src/core/contentstackregion.js | 1 + test/typescript/stack.test.ts | 549 ++++++++++++++++++--------------- 7 files changed, 558 insertions(+), 478 deletions(-) diff --git a/.talismanrc b/.talismanrc index c89690f5..e09434dc 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,16 +1,6 @@ fileignoreconfig: -- filename: package-lock.json - checksum: 28f8e6d0e7856b4a568fd260dcc4deb531bcdbebbbff956b008ce7dd26a0475d -- filename: test/typescript/taxonomy.test.ts - checksum: e4bdf633e147fd60d929d379f20c814eed5f68b11421d7b53ec8826e9142de37 -- filename: src/core/modules/taxonomy.js - checksum: 84589be9805c1be5fd6c56021c41d18365126cf82059ad2cbef1d418c70d08e0 -- filename: src/core/lib/utils.js - checksum: 8a37566d0372573b8fe4ec506a43f1074981c5218e9adbc551c87922c8914922 -- filename: src/core/modules/query.js - checksum: c88b336f9a271397ffedcf8c5085941ceb0bd1cd7e25ed9ada3acd8ce4f8970c -- filename: test/typescript/stack.test.ts - checksum: bbb3c425f8e1a63d4793f69ee9eaba9559294ff53f163a28f70ae54b1792276a -- filename: src/core/contentstack.js - checksum: 90a3b07300155a34f67dc3df87363107eec202123a21bc0cefda324e477a676d + - filename: index.d.ts + checksum: 22c6a7fe4027d6b2c9adf0cbeb9c525ab79b15210b07ec5189693992e6800a66 + - filename: test/typescript/stack.test.ts + checksum: 50b764c0ca6f6f27d7306a4e54327bef9b178e8436c6e3fad0d67d77343d10b3 version: "" diff --git a/CHANGELOG.md b/CHANGELOG.md index d1b89af9..af3c2443 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Change log +### Version: 3.26.0 +#### Date: July-01-2025 +##### Fix: + - Added AWS-AU support + ### Version: 3.25.3 #### Date: April-21-2025 ##### Fix: @@ -15,7 +20,7 @@ ##### Fix: - Update dependencies - Update slack notification - + ### Version: 3.25.0 #### Date: March-10-2025 ##### Fix: @@ -118,14 +123,14 @@ ### Version: 3.18.0 #### Date: January-15-2024 ##### New Features: - - added taxonomy support - - X-User-Agent updated + - added taxonomy support + - X-User-Agent updated - added region gcp_na ### Version: 3.17.2 #### Date: November-15-2023 ##### Bug fix: - Same management token in Live Preview in different stack object fixed - - X-User-Agent updated + - X-User-Agent updated ##### New Features - Early Access added to stack config @@ -178,19 +183,19 @@ #### Date: May-26-2021 ##### Dependency: - Update Utils SDK dependency version - + ### Version: 3.13.1 #### Date: Apr-16-2021 ##### Bug fix: - IE 11 request method issue resolved - + ### Version: 3.13.0 #### Date: Apr-05-2021 ##### Update API: - [Query]: Added support for method includeEmbeddedItems - [Entry]: Added support for method includeEmbeddedItems - + ### Version: 3.12.2 #### Date: Feb-19-2021 @@ -218,7 +223,7 @@ #### Date: Sept-25-2020 ##### Update API: - - Retry limit for fetch request + - Retry limit for fetch request - Retry delay options for fetch request - Retry on error occur for fetch request - Typescript definition added @@ -328,8 +333,8 @@ ##### New API: - [Asset] Image delivery support - - find - - fetch + - find + - fetch ### Version: 3.1.1 #### Date: Oct-13-2017 diff --git a/index.d.ts b/index.d.ts index b4df3b24..a6364fd9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,307 +1,328 @@ // Type definitions for contentstack v3.12.2 and above // Project: https://www.contentstack.com/ // Definitions by: Contentstack -import { EntryEmbedable, Option, RenderOption } from '@contentstack/utils' +import { EntryEmbedable, Option, RenderOption } from "@contentstack/utils"; // Utils export class Utils { - static render(option: { - entry: EntryEmbedable| EntryEmbedable[], - renderOption?: RenderOption, - paths?: string[] - }): void; - static renderContent(content: (string | string[]), option: Option): (string| string[]); - static jsonToHTML(option: { - entry: EntryEmbedable| EntryEmbedable[], - paths: string[], - renderOption?: RenderOption, - }): void; + static render(option: { + entry: EntryEmbedable | EntryEmbedable[]; + renderOption?: RenderOption; + paths?: string[]; + }): void; + static renderContent( + content: string | string[], + option: Option + ): string | string[]; + static jsonToHTML(option: { + entry: EntryEmbedable | EntryEmbedable[]; + paths: string[]; + renderOption?: RenderOption; + }): void; } //Enum for Contentstack Region export enum Region { - US = "us", - EU = "eu", - AZURE_NA = "azure-na", - AZURE_EU = "azure-eu", - GCP_NA = "gcp-na", - GCP_EU = "gcp-eu" + US = "us", + EU = "eu", + AU = "au", + AZURE_NA = "azure-na", + AZURE_EU = "azure-eu", + GCP_NA = "gcp-na", + GCP_EU = "gcp-eu", } //Enum for Contentstack CachePolicy export enum CachePolicy { - IGNORE_CACHE = -1, - ONLY_NETWORK = 0, - CACHE_ELSE_NETWORK = 1, - NETWORK_ELSE_CACHE = 2, - CACHE_THEN_NETWORK = 3 + IGNORE_CACHE = -1, + ONLY_NETWORK = 0, + CACHE_ELSE_NETWORK = 1, + NETWORK_ELSE_CACHE = 2, + CACHE_THEN_NETWORK = 3, } -// Sync Result +// Sync Result export interface SyncResult { - items: Array; - pagination_token?: string; - sync_token?: string; - skip: number; - limit: number; - total_count: number; + items: Array; + pagination_token?: string; + sync_token?: string; + skip: number; + limit: number; + total_count: number; } -// Contentstack Config +// Contentstack Config export interface Config { - api_key: string; - delivery_token: string; - environment: string; - region?: Region; - branch?: string; - live_preview?: LivePreview; - plugins?: ContentstackPlugin[]; - fetchOptions?: FetchOptions; - early_access?: string[] + api_key: string; + delivery_token: string; + environment: string; + region?: Region; + branch?: string; + live_preview?: LivePreview; + plugins?: ContentstackPlugin[]; + fetchOptions?: FetchOptions; + early_access?: string[]; } // Stack Config export interface StackConfig { - protocol: string; - host: string; - port: number; - version: string; + protocol: string; + host: string; + port: number; + version: string; } // ContentTypeCollection export interface ContentTypeCollection { - content_types: Array - count?: number + content_types: Array; + count?: number; } export type LivePreview = { - host?: string - enable: boolean -} & (LivePreivewConfigWithManagementToken | LivePreviewConfigWithPreviewToken) + host?: string; + enable: boolean; +} & (LivePreivewConfigWithManagementToken | LivePreviewConfigWithPreviewToken); export interface LivePreivewConfigWithManagementToken { - /** - * @deprecated Please use `preview_token` instead to enable live preview. - * The `management_token` will be removed in future releases. - */ - management_token: string; + /** + * @deprecated Please use `preview_token` instead to enable live preview. + * The `management_token` will be removed in future releases. + */ + management_token: string; } export interface LivePreviewConfigWithPreviewToken { - preview_token: string; + preview_token: string; } export interface LivePreviewQuery { - live_preview: string - content_type_uid: string - preview_timestamp: string - release_id: string + live_preview: string; + content_type_uid: string; + preview_timestamp: string; + release_id: string; } export interface RetryDelayOption { - base?: number - customBackoff?: (retryCount: number, error: Error) => number + base?: number; + customBackoff?: (retryCount: number, error: Error) => number; } export interface FetchOptions { - [propName: string]: any - debug?: boolean - timeout?: number - retryLimit?: number - retryDelay?: number - retryCondition?: (error: any) => boolean - logHandler?: (level: string, data: any) => void - retryDelayOptions?: RetryDelayOption + [propName: string]: any; + debug?: boolean; + timeout?: number; + retryLimit?: number; + retryDelay?: number; + retryCondition?: (error: any) => boolean; + logHandler?: (level: string, data: any) => void; + retryDelayOptions?: RetryDelayOption; } //Plugins export interface ContentstackPlugin { - onRequest?(stack: Stack, request: ContentstackRequest): ContentstackRequest; - onResponse?(stack: Stack, request: ContentstackRequest, response: any, data: any): any; + onRequest?(stack: Stack, request: ContentstackRequest): ContentstackRequest; + onResponse?( + stack: Stack, + request: ContentstackRequest, + response: any, + data: any + ): any; } export interface ContentstackRequest { - url: string; - option: object; + url: string; + option: object; } -// Stack +// Stack export class Stack { - constructor(config: Config); - /** - * @deprecated since version 3.15.0 - */ - constructor(api_key: string, delivery_token: string, environment_name: string, region?: Region, fetchOptions?: FetchOptions, live_preview?: LivePreview); - - environment: string; - cachePolicy: CachePolicy; - config: StackConfig; - fetchOptions: any; - live_preview: { enable: boolean, host: string, management_token: string } - - ContentType(uid: string): ContentType; - Assets(uid: string): Asset; - Assets(): Assets; - Taxonomies(): Taxonomies; - - setPort(port: number): Stack; - setProtocol(protocol: string): Stack; - setHost(host: string): Stack; - setCachePolicy(policy: CachePolicy): Stack; - setCacheProvider(provider: object): Stack; - livePreviewQuery(query: LivePreviewQuery): void; - clearByQuery(): Stack; - clearByContentType(): Stack; - clearAll(): Stack; - getCacheProvider(): object; - getLastActivities(): Promise; - getContentTypes(param?: object): Promise; - sync(params: object): Promise; - imageTransform(url: string, params: any): string; + constructor(config: Config); + /** + * @deprecated since version 3.15.0 + */ + constructor( + api_key: string, + delivery_token: string, + environment_name: string, + region?: Region, + fetchOptions?: FetchOptions, + live_preview?: LivePreview + ); + + environment: string; + cachePolicy: CachePolicy; + config: StackConfig; + fetchOptions: any; + live_preview: { enable: boolean; host: string; management_token: string }; + + ContentType(uid: string): ContentType; + Assets(uid: string): Asset; + Assets(): Assets; + Taxonomies(): Taxonomies; + + setPort(port: number): Stack; + setProtocol(protocol: string): Stack; + setHost(host: string): Stack; + setCachePolicy(policy: CachePolicy): Stack; + setCacheProvider(provider: object): Stack; + livePreviewQuery(query: LivePreviewQuery): void; + clearByQuery(): Stack; + clearByContentType(): Stack; + clearAll(): Stack; + getCacheProvider(): object; + getLastActivities(): Promise; + getContentTypes(param?: object): Promise; + sync(params: object): Promise; + imageTransform(url: string, params: any): string; } export function Stack(config: Config): Stack; /** * @deprecated since version 3.15.0 */ -export function Stack(api_key: string, access_token: string, environment_name: string, region?: string, fetchOptions?: FetchOptions): Stack; +export function Stack( + api_key: string, + access_token: string, + environment_name: string, + region?: string, + fetchOptions?: FetchOptions +): Stack; export function updateAssetURL(entry: object): object; export class ContentType { - constructor(); - content_type_uid: string - - Query(): Taxonomy; - Entry(uid: string): Entry; - fetch(fetchOptions?: object): Promise; + constructor(); + content_type_uid: string; + + Query(): Taxonomy; + Entry(uid: string): Entry; + fetch(fetchOptions?: object): Promise; } export class Taxonomies extends Taxonomy {} export class Assets { - constructor(); - - toJSON(): Assets; - addParam(key: string, value: any): Assets; - Query(): Query; + constructor(); + toJSON(): Assets; + addParam(key: string, value: any): Assets; + Query(): Query; } export class Asset { - constructor(); + constructor(); - asset_uid: string - _query: object; + asset_uid: string; + _query: object; - toJSON(): Asset; - addParam(key: string, value: any): Asset; - includeFallback(): Asset; - fetch(fetchOptions?: object): Promise; + toJSON(): Asset; + addParam(key: string, value: any): Asset; + includeFallback(): Asset; + fetch(fetchOptions?: object): Promise; } export class Entry { - constructor(); - - entry_uid: string; - content_type_uid: string; - _query: object; - provider: any; - cachePolicy: number; - queryCachePolicy: number; - - only(field_uid: string): this; - only(field_uids: string[]): this; - only(reference_field_uid:string, field_uid: string): this; - only(reference_field_uid:string, field_uids: string[]): this; - - except(field_uid: string): this; - except(field_uids: string[]): this; - except(reference_field_uid:string, field_uid: string): this; - except(reference_field_uid:string, field_uids: string[]): this; - - setCacheProvider(provider: object): this; - setCachePolicy(policy: number): this; - includeReference(val: string[]): this; - includeReference(...val: string[]): this; - language(language_code: string): this; - addQuery(key: string, value: string): this; - includeEmbeddedItems(): this; - includeFallback(): this; - /** - * @deprecated since version 3.3.0 - */ - includeSchema(): this; - includeReferenceContentTypeUID(): this; - includeContentType(): this; - /** - * @deprecated since version 3.3.0 - */ - includeOwner(): this; - toJSON(): this; - addParam(key: string, value: any): this; - variants(variant_headers: string | string[]): this; - fetch(fetchOptions?: object): Promise; + constructor(); + + entry_uid: string; + content_type_uid: string; + _query: object; + provider: any; + cachePolicy: number; + queryCachePolicy: number; + + only(field_uid: string): this; + only(field_uids: string[]): this; + only(reference_field_uid: string, field_uid: string): this; + only(reference_field_uid: string, field_uids: string[]): this; + + except(field_uid: string): this; + except(field_uids: string[]): this; + except(reference_field_uid: string, field_uid: string): this; + except(reference_field_uid: string, field_uids: string[]): this; + + setCacheProvider(provider: object): this; + setCachePolicy(policy: number): this; + includeReference(val: string[]): this; + includeReference(...val: string[]): this; + language(language_code: string): this; + addQuery(key: string, value: string): this; + includeEmbeddedItems(): this; + includeFallback(): this; + /** + * @deprecated since version 3.3.0 + */ + includeSchema(): this; + includeReferenceContentTypeUID(): this; + includeContentType(): this; + /** + * @deprecated since version 3.3.0 + */ + includeOwner(): this; + toJSON(): this; + addParam(key: string, value: any): this; + variants(variant_headers: string | string[]): this; + fetch(fetchOptions?: object): Promise; } export class Query extends Entry { - constructor(); - _query: object; + constructor(); + _query: object; + + getQuery(): Query; - getQuery(): Query; + includeCount(): Query; + query(query: object): Query; + count(fetchOptions?: object): Query; - includeCount(): Query; - query(query: object): Query; - count(fetchOptions?: object): Query; + referenceIn(key: string, query: Query): Query; + referenceNotIn(key: string, query: Query): Query; - referenceIn(key: string, query: Query): Query; - referenceNotIn(key: string, query: Query): Query; + tags(value: string[]): Query; - tags(value: string[]): Query; + where(key: string, value: string | number | boolean): Query; + equalTo(key: string, value: string | number | boolean): Query; + notEqualTo(key: string, value: string | number | boolean): Query; - where(key: string, value: (string | number | boolean)): Query; - equalTo(key: string, value: (string | number | boolean)): Query; - notEqualTo(key: string, value: (string | number | boolean)): Query; + lessThan(key: string, value: string | number): Query; + lessThanOrEqualTo(key: string, value: string | number): Query; - lessThan(key: string, value: (string | number)): Query; - lessThanOrEqualTo(key: string, value: (string | number)): Query; + greaterThan(key: string, value: string | number): Query; + greaterThanOrEqualTo(key: string, value: string | number): Query; - greaterThan(key: string, value: (string | number)): Query; - greaterThanOrEqualTo(key: string, value: (string | number)): Query; + containedIn(key: string, value: (string | number)[]): Query; + notContainedIn(key: string, value: (string | number)[]): Query; - containedIn(key: string, value: (string | number)[]): Query; - notContainedIn(key: string, value: (string | number)[]): Query; + exists(key: string): Query; + notExists(key: string): Query; - exists(key: string): Query; - notExists(key: string): Query; + ascending(key: string): Query; + descending(key: string): Query; - ascending(key: string): Query; - descending(key: string): Query; + beforeUid(uid: string): Query; + afterUid(uid: string): Query; - beforeUid(uid: string): Query; - afterUid(uid: string): Query; + skip(skip: number): Query; + limit(limit: number): Query; - skip(skip: number): Query; - limit(limit: number): Query; + or(...queries: Query[]): Query; + and(...queries: Query[]): Query; - or(...queries: Query[]): Query; - and(...queries: Query[]): Query; + referenceIn(key: string, query: Query | object): Query; + referenceNotIn(key: string, query: Query | object): Query; - referenceIn(key: string, query: (Query | object)): Query; - referenceNotIn(key: string, query: (Query | object)): Query; + regex(key: string, value: string, options?: string): Query; - regex(key: string, value: string, options?: string): Query; - - /** - * @deprecated since version 3.15.0 - */ - search(value: string): Query; + /** + * @deprecated since version 3.15.0 + */ + search(value: string): Query; - find(fetchOptions?: object): Promise; - findOne(): Promise; + find(fetchOptions?: object): Promise; + findOne(): Promise; } export class Taxonomy extends Query { - constructor(); - above(key: string, value: string, levels?: number): Query; - equalAndAbove(key: string, value: string, levels?: number): Query; - below(key: string, value: string, levels?: number): Query; - equalAndBelow(key: string, value: string, levels?: number): Query; + constructor(); + above(key: string, value: string, levels?: number): Query; + equalAndAbove(key: string, value: string, levels?: number): Query; + below(key: string, value: string, levels?: number): Query; + equalAndBelow(key: string, value: string, levels?: number): Query; } diff --git a/package-lock.json b/package-lock.json index a0a94e0c..e0adaea7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "contentstack", - "version": "3.25.3", + "version": "3.26.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "contentstack", - "version": "3.25.3", + "version": "3.26.0", "license": "MIT", "dependencies": { "@contentstack/utils": "^1.3.20", diff --git a/package.json b/package.json index e6437a8c..33104aec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "contentstack", - "version": "3.25.3", + "version": "3.26.0", "description": "Contentstack Javascript SDK", "homepage": "https://www.contentstack.com/", "author": { diff --git a/src/core/contentstackregion.js b/src/core/contentstackregion.js index 715dae01..f285e8ed 100644 --- a/src/core/contentstackregion.js +++ b/src/core/contentstackregion.js @@ -1,6 +1,7 @@ const ContentstackRegion = { EU: "eu", US: "us", + AU: "au", AZURE_NA: "azure-na", AZURE_EU: "azure-eu", GCP_NA: "gcp-na", diff --git a/test/typescript/stack.test.ts b/test/typescript/stack.test.ts index 50c00bfe..a50f26b0 100644 --- a/test/typescript/stack.test.ts +++ b/test/typescript/stack.test.ts @@ -1,267 +1,330 @@ -import * as Contentstack from '../..'; +import * as Contentstack from "../.."; -describe('Stack tests', () => { +describe("Stack tests", () => { + test("Stack initialization test", (done) => { + const stack = Contentstack.Stack( + "api_key", + "delivery_token", + "environment" + ); + expect(stack.ContentType).not.toEqual(undefined); + expect(stack.Assets).not.toEqual(undefined); - test('Stack initialization test', done => { - const stack = Contentstack.Stack('api_key', 'delivery_token', 'environment'); - expect(stack.ContentType).not.toEqual(undefined) - expect(stack.Assets).not.toEqual(undefined) + expect(stack.clearByQuery).not.toEqual(undefined); + expect(stack.clearByContentType).not.toEqual(undefined); + expect(stack.clearAll).not.toEqual(undefined); + expect(stack.getContentTypes).not.toEqual(undefined); + expect(stack.imageTransform).not.toEqual(undefined); + expect(stack.livePreviewQuery).not.toEqual(undefined); - expect(stack.clearByQuery).not.toEqual(undefined) - expect(stack.clearByContentType).not.toEqual(undefined) - expect(stack.clearAll).not.toEqual(undefined) - expect(stack.getContentTypes).not.toEqual(undefined) - expect(stack.imageTransform).not.toEqual(undefined) - expect(stack.livePreviewQuery).not.toEqual(undefined) + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("cdn.contentstack.io"); + expect(stack.config.port).toEqual(443); + expect(stack.config.protocol).toEqual("https"); + expect(stack.config.version).toEqual("v3"); + expect(stack.fetchOptions.retryLimit).toEqual(5); + expect(stack.fetchOptions.retryCondition).not.toEqual(undefined); + done(); + }); - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); - expect(stack.environment).toEqual('environment'); - expect(stack.config.host).toEqual('cdn.contentstack.io'); - expect(stack.config.port).toEqual(443); - expect(stack.config.protocol).toEqual("https"); - expect(stack.config.version).toEqual("v3"); - expect(stack.fetchOptions.retryLimit).toEqual(5); - expect(stack.fetchOptions.retryCondition).not.toEqual(undefined); - done(); - }); - - test('Stack set methods test', done => { - const stack = Contentstack.Stack('api_key', 'delivery_token', 'environment'); - stack.setHost('localehost'); - stack.setPort(344); - stack.setCachePolicy(Contentstack.CachePolicy.CACHE_THEN_NETWORK); - stack.setProtocol("http"); - stack.setCacheProvider({}); - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.CACHE_THEN_NETWORK); - expect(stack.config.host).toEqual('localehost'); - expect(stack.config.port).toEqual(344); - expect(stack.config.protocol).toEqual("http"); - expect(stack.getCacheProvider()).toEqual({}); - done(); + test("Stack set methods test", (done) => { + const stack = Contentstack.Stack( + "api_key", + "delivery_token", + "environment" + ); + stack.setHost("localehost"); + stack.setPort(344); + stack.setCachePolicy(Contentstack.CachePolicy.CACHE_THEN_NETWORK); + stack.setProtocol("http"); + stack.setCacheProvider({}); + expect(stack.cachePolicy).toEqual( + Contentstack.CachePolicy.CACHE_THEN_NETWORK + ); + expect(stack.config.host).toEqual("localehost"); + expect(stack.config.port).toEqual(344); + expect(stack.config.protocol).toEqual("http"); + expect(stack.getCacheProvider()).toEqual({}); + done(); + }); + + test("Stack initialization with fetchOptions test", (done) => { + const stack = Contentstack.Stack({ + api_key: "api_key", + delivery_token: "delivery_token", + environment: "environment", + fetchOptions: { + timeout: 2000, + logHandler: () => {}, + }, }); + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("cdn.contentstack.io"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + expect(stack.fetchOptions.timeout).toEqual(2000); - test('Stack initialization with fetchOptions test', done => { - const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment', fetchOptions:{ - timeout: 2000, - logHandler: () => { + done(); + }); - } - }}); - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); - expect(stack.environment).toEqual('environment'); - expect(stack.config.host).toEqual('cdn.contentstack.io'); - expect(stack.config.port).toEqual(443); - expect(stack.config.version).toEqual("v3"); - expect(stack.fetchOptions.timeout).toEqual(2000); + test("Stack initialization with Contentstack Config test", (done) => { + const config: Contentstack.Config = { + api_key: "api_key", + delivery_token: "delivery_token", + environment: "environment", + }; + const stack = Contentstack.Stack(config); - done(); - }); + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("cdn.contentstack.io"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + expect(stack.fetchOptions.retryLimit).toEqual(5); - test('Stack initialization with Contentstack Config test', done => { - const config : Contentstack.Config = { - api_key: 'api_key', - delivery_token: 'delivery_token', - environment: 'environment' - }; - const stack = Contentstack.Stack(config); - - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); - expect(stack.environment).toEqual('environment'); - expect(stack.config.host).toEqual('cdn.contentstack.io'); - expect(stack.config.port).toEqual(443); - expect(stack.config.version).toEqual("v3"); - expect(stack.fetchOptions.retryLimit).toEqual(5); + done(); + }); - done(); - }); + test("Stack initialization with Contentstack Config with fetchOptions test", (done) => { + const config: Contentstack.Config = { + api_key: "api_key", + delivery_token: "delivery_token", + environment: "environment", + fetchOptions: { + timeout: 2000, + retryLimit: 4, + retryDelay: 40, + logHandler: () => {}, + }, + }; + const stack = Contentstack.Stack(config); - test('Stack initialization with Contentstack Config with fetchOptions test', done => { - const config : Contentstack.Config = { - api_key: 'api_key', - delivery_token: 'delivery_token', - environment: 'environment', - fetchOptions:{ - timeout: 2000, - retryLimit: 4, - retryDelay: 40, - logHandler: () => { + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("cdn.contentstack.io"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + expect(stack.fetchOptions.timeout).toEqual(2000); + expect(stack.fetchOptions.retryLimit).toEqual(4); + expect(stack.fetchOptions.retryDelay).toEqual(40); + done(); + }); - } - } - }; - const stack = Contentstack.Stack(config); - - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); - expect(stack.environment).toEqual('environment'); - expect(stack.config.host).toEqual('cdn.contentstack.io'); - expect(stack.config.port).toEqual(443); - expect(stack.config.version).toEqual("v3"); - expect(stack.fetchOptions.timeout).toEqual(2000); - expect(stack.fetchOptions.retryLimit).toEqual(4); - expect(stack.fetchOptions.retryDelay).toEqual(40); - done(); - }); - - test('Stack initialization with Contentstack Config with fetchOptions, EU region test', done => { - const config : Contentstack.Config = { - api_key: 'api_key', - delivery_token: 'delivery_token', - environment: 'environment', - region: Contentstack.Region.EU, - fetchOptions:{ - timeout: 2000, - retryLimit: 4, - retryDelay: 40, - logHandler: () => { + test("Stack initialization with Contentstack Config with fetchOptions, EU region test", (done) => { + const config: Contentstack.Config = { + api_key: "api_key", + delivery_token: "delivery_token", + environment: "environment", + region: Contentstack.Region.EU, + fetchOptions: { + timeout: 2000, + retryLimit: 4, + retryDelay: 40, + logHandler: () => {}, + }, + }; + const stack = Contentstack.Stack(config); - } - } - }; - const stack = Contentstack.Stack(config); - - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); - expect(stack.environment).toEqual('environment'); - expect(stack.config.host).toEqual('eu-cdn.contentstack.com'); - expect(stack.config.port).toEqual(443); - expect(stack.config.version).toEqual("v3"); - expect(stack.fetchOptions.timeout).toEqual(2000); - expect(stack.fetchOptions.retryLimit).toEqual(4); - expect(stack.fetchOptions.retryDelay).toEqual(40); - done(); - }); - - test('Stack initialization with region EU test', done => { - const stack = Contentstack.Stack('api_key', 'delivery_token', 'environment', Contentstack.Region.EU); - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); - expect(stack.environment).toEqual('environment'); - expect(stack.config.host).toEqual('eu-cdn.contentstack.com'); - expect(stack.config.port).toEqual(443); - expect(stack.config.version).toEqual("v3"); - done(); - }); + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("eu-cdn.contentstack.com"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + expect(stack.fetchOptions.timeout).toEqual(2000); + expect(stack.fetchOptions.retryLimit).toEqual(4); + expect(stack.fetchOptions.retryDelay).toEqual(40); + done(); + }); - test('Stack initialization with Contentstack Config with fetchOptions, Azure-NA region test', done => { - const config : Contentstack.Config = { - api_key: 'api_key', - delivery_token: 'delivery_token', - environment: 'environment', - region: Contentstack.Region.AZURE_NA, - fetchOptions:{ - timeout: 2000, - retryLimit: 4, - retryDelay: 40, - logHandler: () => { + test("Stack initialization with region EU test", (done) => { + const stack = Contentstack.Stack( + "api_key", + "delivery_token", + "environment", + Contentstack.Region.EU + ); + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("eu-cdn.contentstack.com"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + done(); + }); - } - } - }; - const stack = Contentstack.Stack(config); - - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); - expect(stack.environment).toEqual('environment'); - expect(stack.config.host).toEqual('azure-na-cdn.contentstack.com'); - expect(stack.config.port).toEqual(443); - expect(stack.config.version).toEqual("v3"); - expect(stack.fetchOptions.timeout).toEqual(2000); - expect(stack.fetchOptions.retryLimit).toEqual(4); - expect(stack.fetchOptions.retryDelay).toEqual(40); - done(); - }); + test("Stack initialization with Contentstack Config with fetchOptions, AU region test", (done) => { + const config: Contentstack.Config = { + api_key: "api_key", + delivery_token: "delivery_token", + environment: "environment", + region: Contentstack.Region.AU, + fetchOptions: { + timeout: 2000, + retryLimit: 4, + retryDelay: 40, + logHandler: () => {}, + }, + }; + const stack = Contentstack.Stack(config); - test('Stack initialization with Contentstack Config with fetchOptions, GCP-NA region test', done => { - const config : Contentstack.Config = { - api_key: 'api_key', - delivery_token: 'delivery_token', - environment: 'environment', - region: Contentstack.Region.GCP_NA, - fetchOptions:{ - timeout: 2000, - retryLimit: 4, - retryDelay: 40, - logHandler: () => { + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("au-cdn.contentstack.com"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + expect(stack.fetchOptions.timeout).toEqual(2000); + expect(stack.fetchOptions.retryLimit).toEqual(4); + expect(stack.fetchOptions.retryDelay).toEqual(40); + done(); + }); - } - } - }; - const stack = Contentstack.Stack(config); - - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); - expect(stack.environment).toEqual('environment'); - expect(stack.config.host).toEqual('gcp-na-cdn.contentstack.com'); - expect(stack.config.port).toEqual(443); - expect(stack.config.version).toEqual("v3"); - expect(stack.fetchOptions.timeout).toEqual(2000); - expect(stack.fetchOptions.retryLimit).toEqual(4); - expect(stack.fetchOptions.retryDelay).toEqual(40); - done(); - }); - - test('Stack initialization with Contentstack Config with fetchOptions, GCP-EU region test', done => { - const config : Contentstack.Config = { - api_key: 'api_key', - delivery_token: 'delivery_token', - environment: 'environment', - region: Contentstack.Region.GCP_EU, - fetchOptions:{ - timeout: 2000, - retryLimit: 4, - retryDelay: 40, - logHandler: () => { + test("Stack initialization with region AU test", (done) => { + const stack = Contentstack.Stack( + "api_key", + "delivery_token", + "environment", + Contentstack.Region.AU + ); + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("au-cdn.contentstack.com"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + done(); + }); - } - } - }; - const stack = Contentstack.Stack(config); - - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); - expect(stack.environment).toEqual('environment'); - expect(stack.config.host).toEqual('gcp-eu-cdn.contentstack.com'); - expect(stack.config.port).toEqual(443); - expect(stack.config.version).toEqual("v3"); - expect(stack.fetchOptions.timeout).toEqual(2000); - expect(stack.fetchOptions.retryLimit).toEqual(4); - expect(stack.fetchOptions.retryDelay).toEqual(40); - done(); - }); + test("Stack initialization with Contentstack Config with fetchOptions, Azure-NA region test", (done) => { + const config: Contentstack.Config = { + api_key: "api_key", + delivery_token: "delivery_token", + environment: "environment", + region: Contentstack.Region.AZURE_NA, + fetchOptions: { + timeout: 2000, + retryLimit: 4, + retryDelay: 40, + logHandler: () => {}, + }, + }; + const stack = Contentstack.Stack(config); - test('Stack initialization with region EU test', done => { - const stack = Contentstack.Stack('api_key', 'delivery_token', 'environment', Contentstack.Region.AZURE_NA); - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); - expect(stack.environment).toEqual('environment'); - expect(stack.config.host).toEqual('azure-na-cdn.contentstack.com'); - expect(stack.config.port).toEqual(443); - expect(stack.config.version).toEqual("v3"); - done(); - }); + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("azure-na-cdn.contentstack.com"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + expect(stack.fetchOptions.timeout).toEqual(2000); + expect(stack.fetchOptions.retryLimit).toEqual(4); + expect(stack.fetchOptions.retryDelay).toEqual(40); + done(); + }); - test('Stack initialization with region EU and fetchOptions test', done => { - const stack = Contentstack.Stack('api_key', 'delivery_token', 'environment', Contentstack.Region.EU, { - timeout: 2000, - logHandler: () => { + test("Stack initialization with Contentstack Config with fetchOptions, GCP-NA region test", (done) => { + const config: Contentstack.Config = { + api_key: "api_key", + delivery_token: "delivery_token", + environment: "environment", + region: Contentstack.Region.GCP_NA, + fetchOptions: { + timeout: 2000, + retryLimit: 4, + retryDelay: 40, + logHandler: () => {}, + }, + }; + const stack = Contentstack.Stack(config); - } - }); - expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); - expect(stack.environment).toEqual('environment'); - expect(stack.config.host).toEqual('eu-cdn.contentstack.com'); - expect(stack.config.port).toEqual(443); - expect(stack.config.version).toEqual("v3"); - expect(stack.fetchOptions.timeout).toEqual(2000); + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("gcp-na-cdn.contentstack.com"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + expect(stack.fetchOptions.timeout).toEqual(2000); + expect(stack.fetchOptions.retryLimit).toEqual(4); + expect(stack.fetchOptions.retryDelay).toEqual(40); + done(); + }); - done(); - }); + test("Stack initialization with Contentstack Config with fetchOptions, GCP-EU region test", (done) => { + const config: Contentstack.Config = { + api_key: "api_key", + delivery_token: "delivery_token", + environment: "environment", + region: Contentstack.Region.GCP_EU, + fetchOptions: { + timeout: 2000, + retryLimit: 4, + retryDelay: 40, + logHandler: () => {}, + }, + }; + const stack = Contentstack.Stack(config); + + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("gcp-eu-cdn.contentstack.com"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + expect(stack.fetchOptions.timeout).toEqual(2000); + expect(stack.fetchOptions.retryLimit).toEqual(4); + expect(stack.fetchOptions.retryDelay).toEqual(40); + done(); + }); - test('Utils function test', done => { - const utils = Contentstack.Utils; - const string = ''; - const option = {entry: {field: string, uid: '', _embedded_items: { field: [{ uid:'',_content_type_uid: ''}]}}}; - utils.render(option); - utils.renderContent(string, option); - utils.jsonToHTML({ - ...option, - paths: [] - }); - expect(true).toBeTruthy(); - done(); - }) + test("Stack initialization with region EU test", (done) => { + const stack = Contentstack.Stack( + "api_key", + "delivery_token", + "environment", + Contentstack.Region.AZURE_NA + ); + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("azure-na-cdn.contentstack.com"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + done(); + }); + + test("Stack initialization with region EU and fetchOptions test", (done) => { + const stack = Contentstack.Stack( + "api_key", + "delivery_token", + "environment", + Contentstack.Region.EU, + { + timeout: 2000, + logHandler: () => {}, + } + ); + expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); + expect(stack.environment).toEqual("environment"); + expect(stack.config.host).toEqual("eu-cdn.contentstack.com"); + expect(stack.config.port).toEqual(443); + expect(stack.config.version).toEqual("v3"); + expect(stack.fetchOptions.timeout).toEqual(2000); + + done(); + }); + + test("Utils function test", (done) => { + const utils = Contentstack.Utils; + const string = ""; + const option = { + entry: { + field: string, + uid: "", + _embedded_items: { field: [{ uid: "", _content_type_uid: "" }] }, + }, + }; + utils.render(option); + utils.renderContent(string, option); + utils.jsonToHTML({ + ...option, + paths: [], + }); + expect(true).toBeTruthy(); + done(); + }); });