Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.github/workflows/policy-scan.yml @contentstack/security-admin

.github/workflows/issues-jira.yml @contentstack/security-admin
.github/workflows/issues-jira.yml @contentstack/security-admin
2 changes: 1 addition & 1 deletion __test__/entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe("Entry", () => {
dataWithoutEntry.entry = {};
entry = new Entry(dataWithoutEntry, connection as any, emitter);
expect(() => entry.getField("invaliduid")).toThrowError(
"The data is unsaved. Save the data before requesting the field."
"Invalid uid, Field not found"
);
});

Expand Down
25 changes: 14 additions & 11 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.3.3",
"version": "2.3.5",
"types": "dist/src/index.d.ts",
"description": "The Contentstack App SDK allows you to customize your Contentstack applications.",
"main": "dist/index.js",
Expand Down
8 changes: 0 additions & 8 deletions src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,6 @@ class Entry {
: this._data;
let schema: Schema[0] = this.content_type.schema;

const isDataEmpty = Object.keys(value).length === 0;

if (isDataEmpty) {
throw new Error(
"The data is unsaved. Save the data before requesting the field."
);
}

try {
let skipNext = false;
let skipNextTwo = false;
Expand Down
9 changes: 7 additions & 2 deletions src/stack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,15 @@ class Stack {
* Gets the results of the search based on user query
* @param queries Array of key value pair of query parameters
* @param apiKey API key of the stack
* @param config Optional configuration. Only pass this if you need to query a specific branch using `{ branch: 'branch-name' }. If not provided, queries the default branch.`
* @returns Result of the query
*/
search(queries: StackSearchQuery, apiKey: string | null = this._data.api_key) {
const options = { params: queries, api_key: apiKey, action: "search" };
search(queries: StackSearchQuery, apiKey: string | null = this._data.api_key, config: { [key: string]: any } = {}) {
const { branch } = config;
const options: any = { params: queries, api_key: apiKey, action: "search" };
if (branch) {
options.headers = { branch };
}
return this._connection
.sendToParent("stackQuery", options)
.then(onData)
Expand Down
14 changes: 4 additions & 10 deletions src/utils/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ import { axiosToFetchResponse, fetchToAxiosConfig } from "./utils";
export const dispatchAdapter =
(postRobot: typeof PostRobot) =>
(
config: AxiosRequestConfig,
context?: { installationUID: string; extensionUID: string }
config: AxiosRequestConfig
) => {
return new Promise((resolve, reject) => {
postRobot
.sendToParent("apiAdapter", {
data: config,
extension: context,
})
.sendToParent("apiAdapter", config)
.then((event: unknown) => {
const { data: response } = event as { data: AxiosResponse };

Expand Down Expand Up @@ -63,14 +59,12 @@ export const dispatchAdapter =
*/
export const dispatchApiRequest = async (
url: string,
options?: RequestInit,
context?: { installationUID: string; extensionUID: string }
options?: RequestInit
): Promise<Response> => {
try {
const config = fetchToAxiosConfig(url, options);
const axiosResponse = (await dispatchAdapter(PostRobot)(
config,
context
config
)) as AxiosResponse;

return axiosToFetchResponse(axiosResponse);
Expand Down