@dotcms/client 0.0.1-alpha.1 → 0.0.1-alpha.11

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.
@@ -1,171 +0,0 @@
1
- export interface ClientConfig {
2
- /**
3
- * The URL of the dotCMS instance.
4
- *
5
- * @description This is the URL of the dotCMS instance you want to interact with. Ensure to include the protocol (http or https).
6
- * @example `https://demo.dotcms.com`
7
- * @type {string}
8
- * @required
9
- */
10
- dotcmsUrl: string;
11
- /**
12
- * The id of the site you want to interact with.
13
- *
14
- * @description to get the site id, go to the site you want to interact with and copy the id from the History tab
15
- *
16
- * @type {string}
17
- * @required
18
- */
19
- siteId?: string;
20
- /**
21
- * The authentication token to use for the requests. If not provided, it will fallback to default site.
22
- *
23
- * @description you can get the auth token from our UI {@link https://www.dotcms.com/docs/latest/rest-api-authentication#creating-an-api-token-in-the-ui}
24
- *
25
- * @type {string}
26
- * @required
27
- */
28
- authToken: string;
29
- }
30
- type PageApiOptions = {
31
- /**
32
- * The path of the page you want to retrieve.
33
- *
34
- * @type {string}
35
- */
36
- path: string;
37
- /**
38
- * The id of the site you want to interact with. If not provided, the one from the config will be used.
39
- *
40
- * @type {number}
41
- */
42
- siteId?: string;
43
- /**
44
- * The language id of the page you want to retrieve. If not provided will use the default language of the site.
45
- *
46
- * @type {number}
47
- */
48
- language_id?: number;
49
- /**
50
- * The id of the persona you want to retrieve the page for.
51
- *
52
- * @type {string}
53
- */
54
- personaId?: string;
55
- /**
56
- * If you want to fire the rules set on the page
57
- *
58
- * @type {boolean}
59
- */
60
- fireRules?: boolean;
61
- /**
62
- * Allows access to related content via the Relationship fields of contentlets on a Page; 0 (default)
63
- *
64
- * @type {number}
65
- */
66
- depth?: number;
67
- };
68
- type NavApiOptions = {
69
- /**
70
- * The root path to begin traversing the folder tree.
71
- *
72
- * @example
73
- * `/api/v1/nav/` starts from the root of the site
74
- * @example
75
- * `/about-us` starts from the "About Us" folder
76
- *
77
- * @type {string}
78
- */
79
- path: string;
80
- /**
81
- * The depth of the folder tree to return.
82
- * @example
83
- * `1` returns only the element specified in the path.
84
- * @example
85
- * `2` returns the element specified in the path, and if that element is a folder, returns all direct children of that folder.
86
- * @example
87
- * `3` returns all children and grandchildren of the element specified in the path.
88
- *
89
- * @type {number}
90
- */
91
- depth?: number;
92
- /**
93
- * The language ID of content to return.
94
- * @example
95
- * `1` (or unspecified) returns content in the default language of the site.
96
- *
97
- * @link https://www.dotcms.com/docs/latest/system-language-properties#DefaultLanguage
98
- * @link https://www.dotcms.com/docs/latest/adding-and-editing-languages#LanguageID
99
- * @type {number}
100
- */
101
- languageId?: number;
102
- };
103
- /**
104
- * `DotCmsClient` is a TypeScript class that provides methods to interact with the DotCMS REST API.
105
- * It requires a configuration object on instantiation, which includes the DotCMS URL, site ID, and authentication token.
106
- *
107
- * @class DotCmsClient
108
- *
109
- * @property {ClientConfig} config - The configuration object for the DotCMS client.
110
- *
111
- * @method constructor(config: ClientConfig) - Constructs a new instance of the DotCmsClient class.
112
- *
113
- * @method getPage(options: PageApiOptions): Promise<unknown> - Retrieves all the elements of any Page in your dotCMS system in JSON format.
114
- *
115
- * @method getNav(options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }): Promise<unknown> - Retrieves information about the dotCMS file and folder tree.
116
- *
117
- */
118
- export declare class DotCmsClient {
119
- private config;
120
- constructor(config: ClientConfig);
121
- /**
122
- * `getPage` is an asynchronous method of the `DotCmsClient` class that retrieves all the elements of any Page in your dotCMS system in JSON format.
123
- * It takes a `PageApiOptions` object as a parameter and returns a Promise that resolves to the response from the DotCMS API.
124
- *
125
- * The Page API enables you to retrieve all the elements of any Page in your dotCMS system.
126
- * The elements may be retrieved in JSON format.
127
- *
128
- * @link https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas
129
- * @method getPage
130
- * @async
131
- * @param {PageApiOptions} options - The options for the Page API call.
132
- * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
133
- * @throws {Error} - Throws an error if the options are not valid.
134
- */
135
- getPage(options: PageApiOptions): Promise<unknown>;
136
- /**
137
- * `getNav` is an asynchronous method of the `DotCmsClient` class that retrieves information about the dotCMS file and folder tree.
138
- * It takes a `NavApiOptions` object as a parameter (with default values) and returns a Promise that resolves to the response from the DotCMS API.
139
- *
140
- * The navigation REST API enables you to retrieve information about the dotCMS file and folder tree through REST API calls.
141
- * @link https://www.dotcms.com/docs/latest/navigation-rest-api
142
- * @method getNav
143
- * @async
144
- * @param {NavApiOptions} options - The options for the Nav API call. Defaults to `{ depth: 0, path: '/', languageId: 1 }`.
145
- * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
146
- * @throws {Error} - Throws an error if the options are not valid.
147
- */
148
- getNav(options?: NavApiOptions): Promise<unknown>;
149
- private validatePageOptions;
150
- private validateNavOptions;
151
- }
152
- /**
153
- * `dotcmsClient` is an object that provides a method to initialize the DotCMS SDK client.
154
- * It has a single method `init` which takes a configuration object and returns an instance of the `DotCmsClient` class.
155
- *
156
- * @namespace dotcmsClient
157
- *
158
- * @method init(config: ClientConfig): DotCmsClient - Initializes the SDK client.
159
- */
160
- export declare const dotcmsClient: {
161
- /**
162
- * `init` is a method of the `dotcmsClient` object that initializes the SDK client.
163
- * It takes a configuration object as a parameter and returns an instance of the `DotCmsClient` class.
164
- *
165
- * @method init
166
- * @param {ClientConfig} config - The configuration object for the DotCMS client.
167
- * @returns {DotCmsClient} - An instance of the {@link DotCmsClient} class.
168
- */
169
- init: (config: ClientConfig) => DotCmsClient;
170
- };
171
- export {};
@@ -1,150 +0,0 @@
1
- import { __awaiter, __rest } from "tslib";
2
- function isValidUrl(url) {
3
- try {
4
- new URL(url);
5
- return true;
6
- }
7
- catch (error) {
8
- return false;
9
- }
10
- }
11
- /**
12
- * `DotCmsClient` is a TypeScript class that provides methods to interact with the DotCMS REST API.
13
- * It requires a configuration object on instantiation, which includes the DotCMS URL, site ID, and authentication token.
14
- *
15
- * @class DotCmsClient
16
- *
17
- * @property {ClientConfig} config - The configuration object for the DotCMS client.
18
- *
19
- * @method constructor(config: ClientConfig) - Constructs a new instance of the DotCmsClient class.
20
- *
21
- * @method getPage(options: PageApiOptions): Promise<unknown> - Retrieves all the elements of any Page in your dotCMS system in JSON format.
22
- *
23
- * @method getNav(options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }): Promise<unknown> - Retrieves information about the dotCMS file and folder tree.
24
- *
25
- */
26
- export class DotCmsClient {
27
- constructor(config) {
28
- if (!config.dotcmsUrl) {
29
- throw new Error("Invalid configuration - 'dotcmsUrl' is required");
30
- }
31
- if (!isValidUrl(config.dotcmsUrl)) {
32
- throw new Error("Invalid configuration - 'dotcmsUrl' must be a valid URL");
33
- }
34
- if (!config.authToken) {
35
- throw new Error("Invalid configuration - 'authToken' is required");
36
- }
37
- this.config = config;
38
- }
39
- /**
40
- * `getPage` is an asynchronous method of the `DotCmsClient` class that retrieves all the elements of any Page in your dotCMS system in JSON format.
41
- * It takes a `PageApiOptions` object as a parameter and returns a Promise that resolves to the response from the DotCMS API.
42
- *
43
- * The Page API enables you to retrieve all the elements of any Page in your dotCMS system.
44
- * The elements may be retrieved in JSON format.
45
- *
46
- * @link https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas
47
- * @method getPage
48
- * @async
49
- * @param {PageApiOptions} options - The options for the Page API call.
50
- * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
51
- * @throws {Error} - Throws an error if the options are not valid.
52
- */
53
- getPage(options) {
54
- var _a, _b;
55
- return __awaiter(this, void 0, void 0, function* () {
56
- this.validatePageOptions(options);
57
- const queryParamsObj = {};
58
- for (const [key, value] of Object.entries(options)) {
59
- if (value === undefined || key === 'path' || key === 'siteId')
60
- continue;
61
- if (key === 'personaId') {
62
- queryParamsObj['com.dotmarketing.persona.id'] = String(value);
63
- }
64
- else {
65
- queryParamsObj[key] = String(value);
66
- }
67
- }
68
- const queryHostId = (_b = (_a = options.siteId) !== null && _a !== void 0 ? _a : this.config.siteId) !== null && _b !== void 0 ? _b : '';
69
- if (queryHostId) {
70
- queryParamsObj['host_id'] = queryHostId;
71
- }
72
- const queryParams = new URLSearchParams(queryParamsObj).toString();
73
- const formattedPath = options.path.startsWith('/') ? options.path : `/${options.path}`;
74
- const url = `${this.config.dotcmsUrl}/api/v1/page/json${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
75
- const response = yield fetch(url, {
76
- headers: {
77
- Authorization: `Bearer ${this.config.authToken}`
78
- }
79
- });
80
- return response.json();
81
- });
82
- }
83
- /**
84
- * `getNav` is an asynchronous method of the `DotCmsClient` class that retrieves information about the dotCMS file and folder tree.
85
- * It takes a `NavApiOptions` object as a parameter (with default values) and returns a Promise that resolves to the response from the DotCMS API.
86
- *
87
- * The navigation REST API enables you to retrieve information about the dotCMS file and folder tree through REST API calls.
88
- * @link https://www.dotcms.com/docs/latest/navigation-rest-api
89
- * @method getNav
90
- * @async
91
- * @param {NavApiOptions} options - The options for the Nav API call. Defaults to `{ depth: 0, path: '/', languageId: 1 }`.
92
- * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
93
- * @throws {Error} - Throws an error if the options are not valid.
94
- */
95
- getNav(options = { depth: 0, path: '/', languageId: 1 }) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- this.validateNavOptions(options);
98
- // Extract the 'path' from the options and prepare the rest as query parameters
99
- const { path } = options, queryParamsOptions = __rest(options, ["path"]);
100
- const queryParamsObj = {};
101
- Object.entries(queryParamsOptions).forEach(([key, value]) => {
102
- if (value !== undefined) {
103
- queryParamsObj[key] = String(value);
104
- }
105
- });
106
- const queryParams = new URLSearchParams(queryParamsObj).toString();
107
- // Format the URL correctly depending on the 'path' value
108
- const formattedPath = path === '/' ? '/' : `/${path}`;
109
- const url = `${this.config.dotcmsUrl}/api/v1/nav${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
110
- const response = yield fetch(url, {
111
- headers: {
112
- Authorization: `Bearer ${this.config.authToken}`
113
- }
114
- });
115
- return response.json();
116
- });
117
- }
118
- validatePageOptions(options) {
119
- if (!options.path) {
120
- throw new Error("The 'path' parameter is required for the Page API");
121
- }
122
- }
123
- validateNavOptions(options) {
124
- if (!options.path) {
125
- throw new Error("The 'path' parameter is required for the Nav API");
126
- }
127
- }
128
- }
129
- /**
130
- * `dotcmsClient` is an object that provides a method to initialize the DotCMS SDK client.
131
- * It has a single method `init` which takes a configuration object and returns an instance of the `DotCmsClient` class.
132
- *
133
- * @namespace dotcmsClient
134
- *
135
- * @method init(config: ClientConfig): DotCmsClient - Initializes the SDK client.
136
- */
137
- export const dotcmsClient = {
138
- /**
139
- * `init` is a method of the `dotcmsClient` object that initializes the SDK client.
140
- * It takes a configuration object as a parameter and returns an instance of the `DotCmsClient` class.
141
- *
142
- * @method init
143
- * @param {ClientConfig} config - The configuration object for the DotCMS client.
144
- * @returns {DotCmsClient} - An instance of the {@link DotCmsClient} class.
145
- */
146
- init: (config) => {
147
- return new DotCmsClient(config);
148
- }
149
- };
150
- //# sourceMappingURL=sdk-js-client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sdk-js-client.js","sourceRoot":"","sources":["../../../../../../libs/sdk/client/src/lib/sdk-js-client.ts"],"names":[],"mappings":";AAyGA,SAAS,UAAU,CAAC,GAAW;IAC3B,IAAI;QACA,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAEb,OAAO,IAAI,CAAC;KACf;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,KAAK,CAAC;KAChB;AACL,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,YAAY;IAGrB,YAAY,MAAoB;QAC5B,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;SACtE;QAED,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;SA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