@webiny/sdk 0.0.0-unstable.3c5210ad37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BaseError.d.ts +17 -0
- package/BaseError.js +10 -0
- package/BaseError.js.map +1 -0
- package/CmsSdk.d.ts +23 -0
- package/CmsSdk.js +36 -0
- package/CmsSdk.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/Result.d.ts +102 -0
- package/Result.js +143 -0
- package/Result.js.map +1 -0
- package/Webiny.d.ts +8 -0
- package/Webiny.js +14 -0
- package/Webiny.js.map +1 -0
- package/errors.d.ts +29 -0
- package/errors.js +43 -0
- package/errors.js.map +1 -0
- package/index.d.ts +13 -0
- package/index.js +11 -0
- package/index.js.map +1 -0
- package/methods/cms/cmsTypes.d.ts +82 -0
- package/methods/cms/cmsTypes.js +3 -0
- package/methods/cms/cmsTypes.js.map +1 -0
- package/methods/cms/createEntry.d.ts +67 -0
- package/methods/cms/createEntry.js +59 -0
- package/methods/cms/createEntry.js.map +1 -0
- package/methods/cms/deleteEntryRevision.d.ts +20 -0
- package/methods/cms/deleteEntryRevision.js +53 -0
- package/methods/cms/deleteEntryRevision.js.map +1 -0
- package/methods/cms/getEntry.d.ts +32 -0
- package/methods/cms/getEntry.js +60 -0
- package/methods/cms/getEntry.js.map +1 -0
- package/methods/cms/listEntries.d.ts +38 -0
- package/methods/cms/listEntries.js +90 -0
- package/methods/cms/listEntries.js.map +1 -0
- package/methods/cms/publishEntryRevision.d.ts +22 -0
- package/methods/cms/publishEntryRevision.js +54 -0
- package/methods/cms/publishEntryRevision.js.map +1 -0
- package/methods/cms/unpublishEntryRevision.d.ts +22 -0
- package/methods/cms/unpublishEntryRevision.js +54 -0
- package/methods/cms/unpublishEntryRevision.js.map +1 -0
- package/methods/cms/updateEntryRevision.d.ts +67 -0
- package/methods/cms/updateEntryRevision.js +62 -0
- package/methods/cms/updateEntryRevision.js.map +1 -0
- package/methods/executeGraphQL.d.ts +4 -0
- package/methods/executeGraphQL.js +46 -0
- package/methods/executeGraphQL.js.map +1 -0
- package/package.json +25 -0
- package/types.d.ts +7 -0
- package/types.js +3 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","unpublishEntryRevision","config","fetchFn","params","modelId","revisionId","fields","executeGraphQL","query","result","isFail","data","value","cms","error","GraphQLError","fail","message","code","ok"],"sources":["unpublishEntryRevision.ts"],"sourcesContent":["import type { WebinyConfig } from \"../../types.js\";\nimport { Result } from \"../../Result.js\";\nimport type { HttpError, GraphQLError, NetworkError } from \"../../errors.js\";\nimport type { CmsEntryValues, CmsEntryData } from \"./cmsTypes.js\";\n\nexport interface UnpublishEntryRevisionParams {\n modelId: string;\n revisionId: string;\n fields: string[];\n}\n\n/**\n * Unpublishes an entry revision in the CMS.\n *\n * @template TValues - Type of the entry values object\n * @param config - SDK configuration\n * @param fetchFn - Fetch function to use for HTTP requests\n * @param params - Parameters for unpublishing the entry revision\n * @param params.modelId - The model ID of the entry to unpublish\n * @param params.revisionId - The revision ID of the entry to unpublish (e.g., \"123#0001\")\n * @param params.fields - Fields to include in response. Use \"values.\" prefix for entry values (e.g., \"values.author.name\")\n * @returns Result containing the unpublished entry data or an error\n */\nexport async function unpublishEntryRevision<TValues extends CmsEntryValues = CmsEntryValues>(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n params: UnpublishEntryRevisionParams\n): Promise<Result<CmsEntryData<TValues>, HttpError | GraphQLError | NetworkError>> {\n const { modelId, revisionId, fields } = params;\n\n const { executeGraphQL } = await import(\"../executeGraphQL.js\");\n\n const query = `\n mutation UnpublishEntryRevision($modelId: ID!, $revisionId: ID!, $fields: [String!]!) {\n cms {\n unpublishEntryRevision(modelId: $modelId, revisionId: $revisionId, fields: $fields) {\n data\n error {\n message\n code\n }\n }\n }\n }\n `;\n\n const result = await executeGraphQL(config, fetchFn, query, { modelId, revisionId, fields });\n\n if (result.isFail()) {\n return result;\n }\n\n const data = result.value;\n\n if (data.cms.unpublishEntryRevision.error) {\n const { GraphQLError } = await import(\"../../errors.js\");\n return Result.fail(\n new GraphQLError(\n data.cms.unpublishEntryRevision.error.message,\n data.cms.unpublishEntryRevision.error.code\n )\n );\n }\n\n return Result.ok(data.cms.unpublishEntryRevision.data);\n}\n"],"mappings":"AACA,SAASA,MAAM;AAUf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,sBAAsBA,CACxCC,MAAoB,EACpBC,OAAqB,EACrBC,MAAoC,EAC2C;EAC/E,MAAM;IAAEC,OAAO;IAAEC,UAAU;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAE9C,MAAM;IAAEI;EAAe,CAAC,GAAG,MAAM,MAAM,uBAAuB,CAAC;EAE/D,MAAMC,KAAK,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EAED,MAAMC,MAAM,GAAG,MAAMF,cAAc,CAACN,MAAM,EAAEC,OAAO,EAAEM,KAAK,EAAE;IAAEJ,OAAO;IAAEC,UAAU;IAAEC;EAAO,CAAC,CAAC;EAE5F,IAAIG,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;IACjB,OAAOD,MAAM;EACjB;EAEA,MAAME,IAAI,GAAGF,MAAM,CAACG,KAAK;EAEzB,IAAID,IAAI,CAACE,GAAG,CAACb,sBAAsB,CAACc,KAAK,EAAE;IACvC,MAAM;MAAEC;IAAa,CAAC,GAAG,MAAM,MAAM,kBAAkB,CAAC;IACxD,OAAOhB,MAAM,CAACiB,IAAI,CACd,IAAID,YAAY,CACZJ,IAAI,CAACE,GAAG,CAACb,sBAAsB,CAACc,KAAK,CAACG,OAAO,EAC7CN,IAAI,CAACE,GAAG,CAACb,sBAAsB,CAACc,KAAK,CAACI,IAC1C,CACJ,CAAC;EACL;EAEA,OAAOnB,MAAM,CAACoB,EAAE,CAACR,IAAI,CAACE,GAAG,CAACb,sBAAsB,CAACW,IAAI,CAAC;AAC1D","ignoreList":[]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { WebinyConfig } from "../../types.js";
|
|
2
|
+
import { Result } from "../../Result.js";
|
|
3
|
+
import type { HttpError, GraphQLError, NetworkError } from "../../errors.js";
|
|
4
|
+
import type { CmsEntryValues, CmsIdentity } from "./cmsTypes.js";
|
|
5
|
+
/**
|
|
6
|
+
* Update entry revision data.
|
|
7
|
+
*/
|
|
8
|
+
export interface UpdateCmsEntryData<TValues extends CmsEntryValues = CmsEntryValues> {
|
|
9
|
+
/**
|
|
10
|
+
* Revision-level meta fields.
|
|
11
|
+
*/
|
|
12
|
+
revisionCreatedOn?: Date | string | null;
|
|
13
|
+
revisionModifiedOn?: Date | string | null;
|
|
14
|
+
revisionSavedOn?: Date | string | null;
|
|
15
|
+
revisionDeletedOn?: Date | string | null;
|
|
16
|
+
revisionRestoredOn?: Date | string | null;
|
|
17
|
+
revisionFirstPublishedOn?: Date | string | null;
|
|
18
|
+
revisionLastPublishedOn?: Date | string | null;
|
|
19
|
+
revisionModifiedBy?: CmsIdentity | null;
|
|
20
|
+
revisionCreatedBy?: CmsIdentity | null;
|
|
21
|
+
revisionSavedBy?: CmsIdentity | null;
|
|
22
|
+
revisionDeletedBy?: CmsIdentity | null;
|
|
23
|
+
revisionRestoredBy?: CmsIdentity | null;
|
|
24
|
+
revisionFirstPublishedBy?: CmsIdentity | null;
|
|
25
|
+
revisionLastPublishedBy?: CmsIdentity | null;
|
|
26
|
+
/**
|
|
27
|
+
* Entry-level meta fields.
|
|
28
|
+
*/
|
|
29
|
+
createdOn?: Date | string | null;
|
|
30
|
+
modifiedOn?: Date | string | null;
|
|
31
|
+
savedOn?: Date | string | null;
|
|
32
|
+
deletedOn?: Date | string | null;
|
|
33
|
+
restoredOn?: Date | string | null;
|
|
34
|
+
firstPublishedOn?: Date | string | null;
|
|
35
|
+
lastPublishedOn?: Date | string | null;
|
|
36
|
+
createdBy?: CmsIdentity | null;
|
|
37
|
+
modifiedBy?: CmsIdentity | null;
|
|
38
|
+
savedBy?: CmsIdentity | null;
|
|
39
|
+
deletedBy?: CmsIdentity | null;
|
|
40
|
+
restoredBy?: CmsIdentity | null;
|
|
41
|
+
firstPublishedBy?: CmsIdentity | null;
|
|
42
|
+
lastPublishedBy?: CmsIdentity | null;
|
|
43
|
+
location?: {
|
|
44
|
+
folderId?: string | null;
|
|
45
|
+
};
|
|
46
|
+
values?: Partial<TValues>;
|
|
47
|
+
}
|
|
48
|
+
export interface UpdateEntryRevisionParams<TValues extends CmsEntryValues = CmsEntryValues> {
|
|
49
|
+
modelId: string;
|
|
50
|
+
revisionId: string;
|
|
51
|
+
data: UpdateCmsEntryData<TValues>;
|
|
52
|
+
fields: string[];
|
|
53
|
+
}
|
|
54
|
+
/**1`
|
|
55
|
+
* Updates an existing entry revision in the CMS.
|
|
56
|
+
*
|
|
57
|
+
* @template TValues - Type of the entry data object returned (typically contains id and entryId, or additional fields if specified)
|
|
58
|
+
* @param config - SDK configuration
|
|
59
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
60
|
+
* @param params - Parameters for updating the entry revision
|
|
61
|
+
* @param params.modelId - The model ID for the entry
|
|
62
|
+
* @param params.revisionId - The revision ID of the entry to update (e.g., "123#0001")
|
|
63
|
+
* @param params.data - The updated entry data
|
|
64
|
+
* @param params.fields - Fields to include in the response. Use "values." prefix for entry values (e.g., "values.author.name") or specify top-level fields like "createdOn"
|
|
65
|
+
* @returns Result containing the updated entry data or an error
|
|
66
|
+
*/
|
|
67
|
+
export declare function updateEntryRevision<TValues extends CmsEntryValues = CmsEntryValues>(config: WebinyConfig, fetchFn: typeof fetch, params: UpdateEntryRevisionParams<TValues>): Promise<Result<UpdateCmsEntryData<TValues>, HttpError | GraphQLError | NetworkError>>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Result } from "../../Result.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Update entry revision data.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**1`
|
|
8
|
+
* Updates an existing entry revision in the CMS.
|
|
9
|
+
*
|
|
10
|
+
* @template TValues - Type of the entry data object returned (typically contains id and entryId, or additional fields if specified)
|
|
11
|
+
* @param config - SDK configuration
|
|
12
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
13
|
+
* @param params - Parameters for updating the entry revision
|
|
14
|
+
* @param params.modelId - The model ID for the entry
|
|
15
|
+
* @param params.revisionId - The revision ID of the entry to update (e.g., "123#0001")
|
|
16
|
+
* @param params.data - The updated entry data
|
|
17
|
+
* @param params.fields - Fields to include in the response. Use "values." prefix for entry values (e.g., "values.author.name") or specify top-level fields like "createdOn"
|
|
18
|
+
* @returns Result containing the updated entry data or an error
|
|
19
|
+
*/
|
|
20
|
+
export async function updateEntryRevision(config, fetchFn, params) {
|
|
21
|
+
const {
|
|
22
|
+
modelId,
|
|
23
|
+
revisionId,
|
|
24
|
+
data,
|
|
25
|
+
fields
|
|
26
|
+
} = params;
|
|
27
|
+
const {
|
|
28
|
+
executeGraphQL
|
|
29
|
+
} = await import("../executeGraphQL.js");
|
|
30
|
+
const query = `
|
|
31
|
+
mutation UpdateEntryRevision($modelId: ID!, $revisionId: ID!, $data: JSON!, $fields: [String!]!) {
|
|
32
|
+
cms {
|
|
33
|
+
updateEntryRevision(modelId: $modelId, revisionId: $revisionId, data: $data, fields: $fields) {
|
|
34
|
+
data
|
|
35
|
+
error {
|
|
36
|
+
message
|
|
37
|
+
code
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
const result = await executeGraphQL(config, fetchFn, query, {
|
|
44
|
+
modelId,
|
|
45
|
+
revisionId,
|
|
46
|
+
data,
|
|
47
|
+
fields
|
|
48
|
+
});
|
|
49
|
+
if (result.isFail()) {
|
|
50
|
+
return Result.fail(result.error);
|
|
51
|
+
}
|
|
52
|
+
const responseData = result.value;
|
|
53
|
+
if (responseData.cms.updateEntryRevision.error) {
|
|
54
|
+
const {
|
|
55
|
+
GraphQLError
|
|
56
|
+
} = await import("../../errors.js");
|
|
57
|
+
return Result.fail(new GraphQLError(responseData.cms.updateEntryRevision.error.message, responseData.cms.updateEntryRevision.error.code));
|
|
58
|
+
}
|
|
59
|
+
return Result.ok(responseData.cms.updateEntryRevision.data);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=updateEntryRevision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","updateEntryRevision","config","fetchFn","params","modelId","revisionId","data","fields","executeGraphQL","query","result","isFail","fail","error","responseData","value","cms","GraphQLError","message","code","ok"],"sources":["updateEntryRevision.ts"],"sourcesContent":["import type { WebinyConfig } from \"../../types.js\";\nimport { Result } from \"../../Result.js\";\nimport type { HttpError, GraphQLError, NetworkError } from \"../../errors.js\";\nimport type { CmsEntryValues, CmsIdentity } from \"./cmsTypes.js\";\n\n/**\n * Update entry revision data.\n */\nexport interface UpdateCmsEntryData<TValues extends CmsEntryValues = CmsEntryValues> {\n /**\n * Revision-level meta fields.\n */\n revisionCreatedOn?: Date | string | null;\n revisionModifiedOn?: Date | string | null;\n revisionSavedOn?: Date | string | null;\n revisionDeletedOn?: Date | string | null;\n revisionRestoredOn?: Date | string | null;\n revisionFirstPublishedOn?: Date | string | null;\n revisionLastPublishedOn?: Date | string | null;\n revisionModifiedBy?: CmsIdentity | null;\n revisionCreatedBy?: CmsIdentity | null;\n revisionSavedBy?: CmsIdentity | null;\n revisionDeletedBy?: CmsIdentity | null;\n revisionRestoredBy?: CmsIdentity | null;\n revisionFirstPublishedBy?: CmsIdentity | null;\n revisionLastPublishedBy?: CmsIdentity | null;\n\n /**\n * Entry-level meta fields.\n */\n createdOn?: Date | string | null;\n modifiedOn?: Date | string | null;\n savedOn?: Date | string | null;\n deletedOn?: Date | string | null;\n restoredOn?: Date | string | null;\n firstPublishedOn?: Date | string | null;\n lastPublishedOn?: Date | string | null;\n createdBy?: CmsIdentity | null;\n modifiedBy?: CmsIdentity | null;\n savedBy?: CmsIdentity | null;\n deletedBy?: CmsIdentity | null;\n restoredBy?: CmsIdentity | null;\n firstPublishedBy?: CmsIdentity | null;\n lastPublishedBy?: CmsIdentity | null;\n\n location?: {\n folderId?: string | null;\n };\n\n values?: Partial<TValues>;\n}\n\nexport interface UpdateEntryRevisionParams<TValues extends CmsEntryValues = CmsEntryValues> {\n modelId: string;\n revisionId: string;\n data: UpdateCmsEntryData<TValues>;\n fields: string[];\n}\n\n/**1`\n * Updates an existing entry revision in the CMS.\n *\n * @template TValues - Type of the entry data object returned (typically contains id and entryId, or additional fields if specified)\n * @param config - SDK configuration\n * @param fetchFn - Fetch function to use for HTTP requests\n * @param params - Parameters for updating the entry revision\n * @param params.modelId - The model ID for the entry\n * @param params.revisionId - The revision ID of the entry to update (e.g., \"123#0001\")\n * @param params.data - The updated entry data\n * @param params.fields - Fields to include in the response. Use \"values.\" prefix for entry values (e.g., \"values.author.name\") or specify top-level fields like \"createdOn\"\n * @returns Result containing the updated entry data or an error\n */\nexport async function updateEntryRevision<TValues extends CmsEntryValues = CmsEntryValues>(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n params: UpdateEntryRevisionParams<TValues>\n): Promise<Result<UpdateCmsEntryData<TValues>, HttpError | GraphQLError | NetworkError>> {\n const { modelId, revisionId, data, fields } = params;\n\n const { executeGraphQL } = await import(\"../executeGraphQL.js\");\n\n const query = `\n mutation UpdateEntryRevision($modelId: ID!, $revisionId: ID!, $data: JSON!, $fields: [String!]!) {\n cms {\n updateEntryRevision(modelId: $modelId, revisionId: $revisionId, data: $data, fields: $fields) {\n data\n error {\n message\n code\n }\n }\n }\n }\n `;\n\n const result = await executeGraphQL(config, fetchFn, query, {\n modelId,\n revisionId,\n data,\n fields\n });\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const responseData = result.value;\n\n if (responseData.cms.updateEntryRevision.error) {\n const { GraphQLError } = await import(\"../../errors.js\");\n return Result.fail(\n new GraphQLError(\n responseData.cms.updateEntryRevision.error.message,\n responseData.cms.updateEntryRevision.error.code\n )\n );\n }\n\n return Result.ok(responseData.cms.updateEntryRevision.data);\n}\n"],"mappings":"AACA,SAASA,MAAM;;AAIf;AACA;AACA;;AAoDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,mBAAmBA,CACrCC,MAAoB,EACpBC,OAAqB,EACrBC,MAA0C,EAC2C;EACrF,MAAM;IAAEC,OAAO;IAAEC,UAAU;IAAEC,IAAI;IAAEC;EAAO,CAAC,GAAGJ,MAAM;EAEpD,MAAM;IAAEK;EAAe,CAAC,GAAG,MAAM,MAAM,uBAAuB,CAAC;EAE/D,MAAMC,KAAK,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EAED,MAAMC,MAAM,GAAG,MAAMF,cAAc,CAACP,MAAM,EAAEC,OAAO,EAAEO,KAAK,EAAE;IACxDL,OAAO;IACPC,UAAU;IACVC,IAAI;IACJC;EACJ,CAAC,CAAC;EAEF,IAAIG,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;IACjB,OAAOZ,MAAM,CAACa,IAAI,CAACF,MAAM,CAACG,KAAK,CAAC;EACpC;EAEA,MAAMC,YAAY,GAAGJ,MAAM,CAACK,KAAK;EAEjC,IAAID,YAAY,CAACE,GAAG,CAAChB,mBAAmB,CAACa,KAAK,EAAE;IAC5C,MAAM;MAAEI;IAAa,CAAC,GAAG,MAAM,MAAM,kBAAkB,CAAC;IACxD,OAAOlB,MAAM,CAACa,IAAI,CACd,IAAIK,YAAY,CACZH,YAAY,CAACE,GAAG,CAAChB,mBAAmB,CAACa,KAAK,CAACK,OAAO,EAClDJ,YAAY,CAACE,GAAG,CAAChB,mBAAmB,CAACa,KAAK,CAACM,IAC/C,CACJ,CAAC;EACL;EAEA,OAAOpB,MAAM,CAACqB,EAAE,CAACN,YAAY,CAACE,GAAG,CAAChB,mBAAmB,CAACM,IAAI,CAAC;AAC/D","ignoreList":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { WebinyConfig } from "../types.js";
|
|
2
|
+
import { Result } from "../Result.js";
|
|
3
|
+
import { HttpError, GraphQLError, NetworkError } from "../errors.js";
|
|
4
|
+
export declare function executeGraphQL(config: WebinyConfig, fetchFn: typeof fetch, query: string, variables?: Record<string, unknown>): Promise<Result<any, HttpError | GraphQLError | NetworkError>>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Result } from "../Result.js";
|
|
2
|
+
import { HttpError, GraphQLError, NetworkError } from "../errors.js";
|
|
3
|
+
export async function executeGraphQL(config, fetchFn, query, variables = {}) {
|
|
4
|
+
const url = `${config.endpoint}/graphql`;
|
|
5
|
+
let response;
|
|
6
|
+
try {
|
|
7
|
+
const body = JSON.stringify({
|
|
8
|
+
query,
|
|
9
|
+
variables
|
|
10
|
+
});
|
|
11
|
+
const headers = {
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
"x-tenant": config.tenant ?? "root",
|
|
14
|
+
...config.headers
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Only add Authorization header if token is provided and not already set in custom headers.
|
|
18
|
+
if (config.token && !headers.Authorization) {
|
|
19
|
+
headers.Authorization = `Bearer ${config.token}`;
|
|
20
|
+
}
|
|
21
|
+
response = await fetchFn(url, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers,
|
|
24
|
+
body,
|
|
25
|
+
credentials: "include"
|
|
26
|
+
});
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return Result.fail(new NetworkError(error instanceof Error ? error.message : "Network request failed"));
|
|
29
|
+
}
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
return Result.fail(new HttpError(response.status, `HTTP error! status: ${response.status}`));
|
|
32
|
+
}
|
|
33
|
+
let result;
|
|
34
|
+
try {
|
|
35
|
+
result = await response.json();
|
|
36
|
+
} catch {
|
|
37
|
+
return Result.fail(new NetworkError("Failed to parse response JSON"));
|
|
38
|
+
}
|
|
39
|
+
if (result.errors) {
|
|
40
|
+
const error = result.errors[0];
|
|
41
|
+
return Result.fail(new GraphQLError(error?.message || "GraphQL error", error?.code));
|
|
42
|
+
}
|
|
43
|
+
return Result.ok(result.data);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=executeGraphQL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","HttpError","GraphQLError","NetworkError","executeGraphQL","config","fetchFn","query","variables","url","endpoint","response","body","JSON","stringify","headers","tenant","token","Authorization","method","credentials","error","fail","Error","message","ok","status","result","json","errors","code","data"],"sources":["executeGraphQL.ts"],"sourcesContent":["import type { WebinyConfig } from \"../types.js\";\nimport { Result } from \"../Result.js\";\nimport { HttpError, GraphQLError, NetworkError } from \"../errors.js\";\n\nexport async function executeGraphQL(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n query: string,\n variables: Record<string, unknown> = {}\n): Promise<Result<any, HttpError | GraphQLError | NetworkError>> {\n const url = `${config.endpoint}/graphql`;\n\n let response: Response;\n\n try {\n const body = JSON.stringify({ query, variables });\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"x-tenant\": config.tenant ?? \"root\",\n ...config.headers\n };\n\n // Only add Authorization header if token is provided and not already set in custom headers.\n if (config.token && !headers.Authorization) {\n headers.Authorization = `Bearer ${config.token}`;\n }\n\n response = await fetchFn(url, {\n method: \"POST\",\n headers,\n body,\n credentials: \"include\"\n });\n } catch (error) {\n return Result.fail(\n new NetworkError(error instanceof Error ? error.message : \"Network request failed\")\n );\n }\n\n if (!response.ok) {\n return Result.fail(\n new HttpError(response.status, `HTTP error! status: ${response.status}`)\n );\n }\n\n let result: any;\n try {\n result = await response.json();\n } catch {\n return Result.fail(new NetworkError(\"Failed to parse response JSON\"));\n }\n\n if (result.errors) {\n const error = result.errors[0];\n return Result.fail(new GraphQLError(error?.message || \"GraphQL error\", error?.code));\n }\n\n return Result.ok(result.data);\n}\n"],"mappings":"AACA,SAASA,MAAM;AACf,SAASC,SAAS,EAAEC,YAAY,EAAEC,YAAY;AAE9C,OAAO,eAAeC,cAAcA,CAChCC,MAAoB,EACpBC,OAAqB,EACrBC,KAAa,EACbC,SAAkC,GAAG,CAAC,CAAC,EACsB;EAC7D,MAAMC,GAAG,GAAG,GAAGJ,MAAM,CAACK,QAAQ,UAAU;EAExC,IAAIC,QAAkB;EAEtB,IAAI;IACA,MAAMC,IAAI,GAAGC,IAAI,CAACC,SAAS,CAAC;MAAEP,KAAK;MAAEC;IAAU,CAAC,CAAC;IAEjD,MAAMO,OAA+B,GAAG;MACpC,cAAc,EAAE,kBAAkB;MAClC,UAAU,EAAEV,MAAM,CAACW,MAAM,IAAI,MAAM;MACnC,GAAGX,MAAM,CAACU;IACd,CAAC;;IAED;IACA,IAAIV,MAAM,CAACY,KAAK,IAAI,CAACF,OAAO,CAACG,aAAa,EAAE;MACxCH,OAAO,CAACG,aAAa,GAAG,UAAUb,MAAM,CAACY,KAAK,EAAE;IACpD;IAEAN,QAAQ,GAAG,MAAML,OAAO,CAACG,GAAG,EAAE;MAC1BU,MAAM,EAAE,MAAM;MACdJ,OAAO;MACPH,IAAI;MACJQ,WAAW,EAAE;IACjB,CAAC,CAAC;EACN,CAAC,CAAC,OAAOC,KAAK,EAAE;IACZ,OAAOrB,MAAM,CAACsB,IAAI,CACd,IAAInB,YAAY,CAACkB,KAAK,YAAYE,KAAK,GAAGF,KAAK,CAACG,OAAO,GAAG,wBAAwB,CACtF,CAAC;EACL;EAEA,IAAI,CAACb,QAAQ,CAACc,EAAE,EAAE;IACd,OAAOzB,MAAM,CAACsB,IAAI,CACd,IAAIrB,SAAS,CAACU,QAAQ,CAACe,MAAM,EAAE,uBAAuBf,QAAQ,CAACe,MAAM,EAAE,CAC3E,CAAC;EACL;EAEA,IAAIC,MAAW;EACf,IAAI;IACAA,MAAM,GAAG,MAAMhB,QAAQ,CAACiB,IAAI,CAAC,CAAC;EAClC,CAAC,CAAC,MAAM;IACJ,OAAO5B,MAAM,CAACsB,IAAI,CAAC,IAAInB,YAAY,CAAC,+BAA+B,CAAC,CAAC;EACzE;EAEA,IAAIwB,MAAM,CAACE,MAAM,EAAE;IACf,MAAMR,KAAK,GAAGM,MAAM,CAACE,MAAM,CAAC,CAAC,CAAC;IAC9B,OAAO7B,MAAM,CAACsB,IAAI,CAAC,IAAIpB,YAAY,CAACmB,KAAK,EAAEG,OAAO,IAAI,eAAe,EAAEH,KAAK,EAAES,IAAI,CAAC,CAAC;EACxF;EAEA,OAAO9B,MAAM,CAACyB,EAAE,CAACE,MAAM,CAACI,IAAI,CAAC;AACjC","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/sdk",
|
|
3
|
+
"version": "0.0.0-unstable.3c5210ad37",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./index.js"
|
|
12
|
+
},
|
|
13
|
+
"author": "Webiny",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@webiny/build-tools": "0.0.0-unstable.3c5210ad37",
|
|
17
|
+
"typescript": "5.9.3",
|
|
18
|
+
"vitest": "4.0.18"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"directory": "dist"
|
|
23
|
+
},
|
|
24
|
+
"gitHead": "3c5210ad37c29bfabfeb8a91d3220115352b2ea9"
|
|
25
|
+
}
|
package/types.d.ts
ADDED
package/types.js
ADDED
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface WebinyConfig {\n token?: string;\n endpoint: string;\n tenant?: string;\n headers?: Record<string, string>;\n fetch?: typeof fetch;\n}\n"],"mappings":"","ignoreList":[]}
|