Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c1d2614
feat:api support for cma
Amitkanswal Jul 1, 2024
ff935d5
ref:refactored api method
Amitkanswal Jul 17, 2024
a7d4d0f
fix:updated schema for api payload
Amitkanswal Jul 17, 2024
ce19a59
ref: relocated api method and added unit test
Amitkanswal Jul 28, 2024
89072cb
refactor:updated api method implementation
Amitkanswal Oct 10, 2024
51d25a9
chore:remove uuid lib
Amitkanswal Oct 10, 2024
feea02b
Merge branch 'develop' into ref/MKT-6907-api-method
Amitkanswal Oct 11, 2024
fa09dd8
Merge pull request #125 from contentstack/ref/MKT-6907-api-method
Amitkanswal Oct 11, 2024
eb46cfd
feat:integrated js management-sdk
Amitkanswal Oct 15, 2024
e6d1d94
feat:made ids available as collection for easy access
Amitkanswal Oct 16, 2024
4bfd478
Merge pull request #126 from contentstack/feat/MKT-7352-management-sdk
Amitkanswal Oct 16, 2024
634a04c
Merge pull request #127 from contentstack/feat/MKT-6395-id-access
Amitkanswal Oct 17, 2024
b1640cf
feat:support for management-sdk and axios adapter
Amitkanswal Oct 21, 2024
4e74e54
fix:baseURL support
Amitkanswal Oct 21, 2024
ecf2d02
fix:unit test case
Amitkanswal Oct 21, 2024
e952d98
ref: refactor api method
Amitkanswal Oct 24, 2024
2f1ba36
refactor: updated adapter implementation after review
Amitkanswal Oct 29, 2024
eb783e0
fix: updated test case
Amitkanswal Oct 29, 2024
57b8dbf
feat:added check for stringify body
Amitkanswal Nov 13, 2024
5d888a5
refactor:moving body stringify logic to AEC
Amitkanswal Nov 13, 2024
d614234
fix:remove unwanted type
Amitkanswal Nov 13, 2024
8ec7400
fix:updated response type
Amitkanswal Nov 13, 2024
621dab7
Merge pull request #130 from contentstack/feat/MKT-6394-sdk-support
Amitkanswal Nov 13, 2024
82e0dd2
feat: Organization full page support
abhishek305 Jan 26, 2025
3785653
chore: version update
abhishek305 Jan 26, 2025
f10a29d
PR: feedback
abhishek305 Jan 27, 2025
9e20e26
Merge branch 'develop' into MKT-10640
abhishek305 Jan 29, 2025
802585e
fix:stack api_key null check
abhishek305 Jan 29, 2025
bbe5046
fix:update api implementation
Amitkanswal Feb 18, 2025
fc6d50e
fix:updated lock file
Amitkanswal Feb 18, 2025
495e7d3
fix:updated api method implementation
Amitkanswal Feb 20, 2025
00a0ca1
fix:addressed review changes
Amitkanswal Feb 20, 2025
58b84eb
fix:updated test case
Amitkanswal Feb 20, 2025
df7cfd4
fix:updated adapter signature
Amitkanswal Feb 21, 2025
1922233
Merge pull request #137 from contentstack/feat/MKT-11267-proxy-changes
Amitkanswal Feb 24, 2025
9976df2
feat:error handling and new region endpoint support
Amitkanswal Mar 25, 2025
386894b
fix:refactor error handling logic
Amitkanswal Apr 1, 2025
0fbf787
fix:removed response type
Amitkanswal Apr 1, 2025
72c3dcc
ref:updated error logic
Amitkanswal Apr 1, 2025
1523b08
fix:added support for network error
Amitkanswal Apr 2, 2025
f3ab178
fix:removed node-fetch and updated node version dependencies
Amitkanswal Apr 3, 2025
77e7812
Merge pull request #139 from contentstack/feat/MKT-11337-error-hostin…
Amitkanswal Apr 4, 2025
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
5 changes: 0 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"env": {
"browser": true,
"node": true
},

"rules": {
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/prefer-const": 0,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [12.x]
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish-github-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- run: npm ci
- run: npm test

Expand All @@ -28,7 +28,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
registry-url: https://npm.pkg.github.com/
- run: npm ci
- run: npm publish
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
node-version: 18
- run: npm ci
- run: npm test

Expand All @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [18.x]

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
node-version: '14.x'
node-version: '18.x'

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '14.x'
node-version: '18.x'

- name: Install deps
run: npm ci
Expand Down
1 change: 1 addition & 0 deletions __test__/assetSidebarWidget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe("AssetSidebarWidget", () => {
user: {} as any,
currentBranch: "mock_branch",
region: "region",
endpoints: { CMA: "", APP: "",DEVELOPER_HUB:"" },
};

let connection: { sendToParent: (...props: any[]) => any };
Expand Down
1 change: 1 addition & 0 deletions __test__/fieldModifierLocation/entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe("FieldModifierLocationEntry", () => {
extension_uid: "extension_uid",
installation_uid: "installation_uid",
region: "NA",
endpoints: { CMA: "", APP: "",DEVELOPER_HUB:"" },
stack: {
api_key: "api_key",
created_at: "created_at",
Expand Down
1 change: 1 addition & 0 deletions __test__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import UiLocation from "../src/uiLocation";
import { version } from "../package.json";

jest.mock("../src/uiLocation");
jest.mock("axios");

describe("ContentstackAppSDK", () => {
describe("init", () => {
Expand Down
37 changes: 37 additions & 0 deletions __test__/organizationFullPage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { IOrgFullPageLocationInitData, LocationType } from "../src/types";
import { OrganizationDetails } from "../src/types/organization.types";

const mockData: IOrgFullPageLocationInitData = {
type: LocationType.ORGANIZATION_FULL_PAGE,
app_id: "app_id",
installation_uid: "installation_uid",
extension_uid: "extension_uid",
region: "NA",
endpoints:{CMA:"",APP:"",DEVELOPER_HUB:""},
stack: {} as any,
user: {} as any,
currentBranch: "currentBranch",
organization: {} as OrganizationDetails,
};
const organizationFullPage = {
currentOrganization: mockData.organization,
};

afterEach(() => {
jest.clearAllMocks();
});

test("should return organization details", () => {
expect(organizationFullPage.currentOrganization).toBe(mockData.organization);
});

test("should handle missing organization details", () => {
const invalidData: IOrgFullPageLocationInitData = {
...mockData,
organization: null as any, // check missing organization details
};
const invalidOrganizationFullPage = {
currentOrganization: invalidData.organization,
};
expect(invalidOrganizationFullPage.currentOrganization).toBeNull();
});
129 changes: 129 additions & 0 deletions __test__/uiLocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
LocationType,
Region,
} from "../src/types";
import { RequestOption } from '../src/types/common.types';
import { RequestConfig } from '../src/types/api.type';
import { AxiosRequestConfig, AxiosResponse } from 'axios';

jest.mock("post-robot");
jest.mock("wolfy87-eventemitter");
Expand Down Expand Up @@ -57,6 +60,7 @@ const initData: IAppConfigInitData = {
installation_uid: "installation_uid",
extension_uid: "extension_uid",
region: "NA",
endpoints: { CMA: "https://api.contentstack.io", APP: "https://app.contentstack.app",DEVELOPER_HUB:"" },
stack: mockStackData,
user: {} as any,
currentBranch: "currentBranch",
Expand Down Expand Up @@ -131,6 +135,131 @@ describe("UI Location", () => {
});
});

describe('dispatchPostRobotRequest', () => {
let mockPostRobot: typeof postRobot;
let opts: RequestOption;
let uiLocationInstance: UiLocation;
let onError: jest.Mock;

beforeEach(() => {
mockPostRobot = postRobot;
opts = { method: 'GET' };
uiLocationInstance = new UiLocation(initData);
onError = jest.fn();
uiLocationInstance.api = jest.fn().mockResolvedValue({
method: 'GET',
url: "https://test.com/test?limit=10&skip=0"
});
});

it('should call sendToParent with the correct arguments and resolve with data', async () => {
const mockData = { success: true };
// Call the method that uses uiLocationInstance.api
const result = await uiLocationInstance.api("https://test.com/test?limit=10&skip=0",{
method: 'GET'
});

// Assertions
expect(uiLocationInstance.api).toHaveBeenCalledWith('https://test.com/test?limit=10&skip=0',{
method: 'GET'
});
expect(result).toEqual({
method: 'GET',
url: 'https://test.com/test?limit=10&skip=0',
});

});

it('should call onError if sendToParent rejects', async () => {
const mockError = new Error('Test error');

// Mock the api method to reject with an error
uiLocationInstance.api = jest.fn().mockRejectedValue(mockError);

// Mock the onError implementation
onError.mockImplementation((error) => {
throw error;
});

// Call the method that uses uiLocationInstance.api and expect it to throw an error
await expect(uiLocationInstance.api("https://test.com/test?limit=10&skip=0",{
method: 'GET'
})).rejects.toThrow('Test error');
});
});


describe("createSDKAdapter", () => {
let mockPostRobot: typeof postRobot;
let opts: RequestConfig;
let uiLocationInstance: UiLocation;
let onError: jest.Mock;

beforeEach(() => {
mockPostRobot = postRobot;
opts = { method: 'GET', baseURL: "https://test.com", url: "/test?limit10&skip=0" };
uiLocationInstance = new UiLocation(initData);
onError = jest.fn();
uiLocationInstance.createAdapter = jest.fn().mockImplementation(() => async (config: AxiosRequestConfig) => {
return {
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
data: {}
} as unknown as AxiosResponse;
});
});

afterEach(() => {
postRobotOnMock.mockClear();
postRobotSendToParentMock.mockClear();

jest.clearAllMocks();
window["postRobot"] = undefined;
window["iframeRef"] = undefined;
});

it('should call createAdapter with the correct arguments and resolve with data', async () => {
const mockData = { success: true };
// Call the method that uses uiLocationInstance.createAdapter
const result = await uiLocationInstance.createAdapter()({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
data: {}
});

expect(result).toEqual({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
data: {}
});
});

it('should call onError if createAdapter rejects', async () => {
const mockError = new Error('Test error');

// Mock the createAdapter method to reject with an error
uiLocationInstance.createAdapter = jest.fn().mockImplementation(() => async (config: AxiosRequestConfig) => {
throw mockError;
});

// Mock the onError implementation
onError.mockImplementation((error) => {
throw error;
});

// Call the method that uses uiLocationInstance.createAdapter and expect it to throw an error
await expect(uiLocationInstance.createAdapter()({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
data: {}
})).rejects.toThrow('Test error');
});
});

describe("getConfig", () => {
it("should return config if no installation uid present", async () => {
const uiLocation = new UiLocation(initDataJsonRte as any);
Expand Down
2 changes: 1 addition & 1 deletion __test__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ describe("formatAppRegion", () => {
});

it("should return unknown for any invalid region", () => {
expect(formatAppRegion("invalid")).toBe(Region.UNKNOWN);
expect(formatAppRegion("invalid")).toBe("invalid");
});
});
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module.exports = {
testEnvironment: "jsdom",
transform: {
"^.+\\.(ts|tsx)$": "ts-jest",
"^.+\\.(js|jsx)$": "babel-jest",
},
moduleNameMapper: {
"^axios$": "axios/dist/node/axios.cjs"
},
collectCoverageFrom: ["./src/**"],
coveragePathIgnorePatterns: ["<rootDir>.*types.ts"],
Expand Down
Loading
Loading