@palbase/modules-cms 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present Palbase
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ CmsClient: () => CmsClient
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/cms-client.ts
28
+ var COLLECTION_NAME_RE = /^[a-zA-Z0-9_\-]+$/;
29
+ var CmsClient = class {
30
+ httpClient;
31
+ constructor(httpClient) {
32
+ this.httpClient = httpClient;
33
+ }
34
+ async find(collection, options) {
35
+ if (!COLLECTION_NAME_RE.test(collection)) {
36
+ throw new Error(
37
+ `Invalid collection name: "${collection}". Collection names must match ${COLLECTION_NAME_RE.source}`
38
+ );
39
+ }
40
+ const params = new URLSearchParams();
41
+ if (options?.locale) params.set("locale", options.locale);
42
+ if (options?.limit != null) params.set("limit", String(options.limit));
43
+ if (options?.offset != null) params.set("offset", String(options.offset));
44
+ if (options?.filter) params.set("filter", JSON.stringify(options.filter));
45
+ const query = params.toString();
46
+ const path = `/v1/cms/${collection}${query ? `?${query}` : ""}`;
47
+ return this.httpClient.request("GET", path);
48
+ }
49
+ async findOne(collection, id, options) {
50
+ if (!COLLECTION_NAME_RE.test(collection)) {
51
+ throw new Error(
52
+ `Invalid collection name: "${collection}". Collection names must match ${COLLECTION_NAME_RE.source}`
53
+ );
54
+ }
55
+ const params = new URLSearchParams();
56
+ if (options?.locale) params.set("locale", options.locale);
57
+ const query = params.toString();
58
+ const path = `/v1/cms/${collection}/${encodeURIComponent(id)}${query ? `?${query}` : ""}`;
59
+ return this.httpClient.request("GET", path);
60
+ }
61
+ };
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ CmsClient
65
+ });
66
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/cms-client.ts"],"sourcesContent":["export { CmsClient } from './cms-client.js';\nexport type { CmsFindOptions, CmsFindOneOptions } from './types.js';\n","import type { HttpClient, PalbaseResponse } from '@palbase/core';\nimport type { CmsFindOneOptions, CmsFindOptions } from './types.js';\n\nconst COLLECTION_NAME_RE = /^[a-zA-Z0-9_\\-]+$/;\n\nexport class CmsClient {\n private readonly httpClient: HttpClient;\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient;\n }\n\n async find<T = unknown>(\n collection: string,\n options?: CmsFindOptions,\n ): Promise<PalbaseResponse<T[]>> {\n if (!COLLECTION_NAME_RE.test(collection)) {\n throw new Error(\n `Invalid collection name: \"${collection}\". Collection names must match ${COLLECTION_NAME_RE.source}`,\n );\n }\n\n const params = new URLSearchParams();\n if (options?.locale) params.set('locale', options.locale);\n if (options?.limit != null) params.set('limit', String(options.limit));\n if (options?.offset != null) params.set('offset', String(options.offset));\n if (options?.filter) params.set('filter', JSON.stringify(options.filter));\n\n const query = params.toString();\n const path = `/v1/cms/${collection}${query ? `?${query}` : ''}`;\n\n return this.httpClient.request<T[]>('GET', path);\n }\n\n async findOne<T = unknown>(\n collection: string,\n id: string,\n options?: CmsFindOneOptions,\n ): Promise<PalbaseResponse<T>> {\n if (!COLLECTION_NAME_RE.test(collection)) {\n throw new Error(\n `Invalid collection name: \"${collection}\". Collection names must match ${COLLECTION_NAME_RE.source}`,\n );\n }\n\n const params = new URLSearchParams();\n if (options?.locale) params.set('locale', options.locale);\n\n const query = params.toString();\n const path = `/v1/cms/${collection}/${encodeURIComponent(id)}${query ? `?${query}` : ''}`;\n\n return this.httpClient.request<T>('GET', path);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,IAAM,qBAAqB;AAEpB,IAAM,YAAN,MAAgB;AAAA,EACJ;AAAA,EAEjB,YAAY,YAAwB;AAClC,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,MAAM,KACJ,YACA,SAC+B;AAC/B,QAAI,CAAC,mBAAmB,KAAK,UAAU,GAAG;AACxC,YAAM,IAAI;AAAA,QACR,6BAA6B,UAAU,kCAAkC,mBAAmB,MAAM;AAAA,MACpG;AAAA,IACF;AAEA,UAAM,SAAS,IAAI,gBAAgB;AACnC,QAAI,SAAS,OAAQ,QAAO,IAAI,UAAU,QAAQ,MAAM;AACxD,QAAI,SAAS,SAAS,KAAM,QAAO,IAAI,SAAS,OAAO,QAAQ,KAAK,CAAC;AACrE,QAAI,SAAS,UAAU,KAAM,QAAO,IAAI,UAAU,OAAO,QAAQ,MAAM,CAAC;AACxE,QAAI,SAAS,OAAQ,QAAO,IAAI,UAAU,KAAK,UAAU,QAAQ,MAAM,CAAC;AAExE,UAAM,QAAQ,OAAO,SAAS;AAC9B,UAAM,OAAO,WAAW,UAAU,GAAG,QAAQ,IAAI,KAAK,KAAK,EAAE;AAE7D,WAAO,KAAK,WAAW,QAAa,OAAO,IAAI;AAAA,EACjD;AAAA,EAEA,MAAM,QACJ,YACA,IACA,SAC6B;AAC7B,QAAI,CAAC,mBAAmB,KAAK,UAAU,GAAG;AACxC,YAAM,IAAI;AAAA,QACR,6BAA6B,UAAU,kCAAkC,mBAAmB,MAAM;AAAA,MACpG;AAAA,IACF;AAEA,UAAM,SAAS,IAAI,gBAAgB;AACnC,QAAI,SAAS,OAAQ,QAAO,IAAI,UAAU,QAAQ,MAAM;AAExD,UAAM,QAAQ,OAAO,SAAS;AAC9B,UAAM,OAAO,WAAW,UAAU,IAAI,mBAAmB,EAAE,CAAC,GAAG,QAAQ,IAAI,KAAK,KAAK,EAAE;AAEvF,WAAO,KAAK,WAAW,QAAW,OAAO,IAAI;AAAA,EAC/C;AACF;","names":[]}
@@ -0,0 +1,20 @@
1
+ import { HttpClient, PalbaseResponse } from '@palbase/core';
2
+
3
+ interface CmsFindOptions {
4
+ locale?: string;
5
+ limit?: number;
6
+ offset?: number;
7
+ filter?: Record<string, unknown>;
8
+ }
9
+ interface CmsFindOneOptions {
10
+ locale?: string;
11
+ }
12
+
13
+ declare class CmsClient {
14
+ private readonly httpClient;
15
+ constructor(httpClient: HttpClient);
16
+ find<T = unknown>(collection: string, options?: CmsFindOptions): Promise<PalbaseResponse<T[]>>;
17
+ findOne<T = unknown>(collection: string, id: string, options?: CmsFindOneOptions): Promise<PalbaseResponse<T>>;
18
+ }
19
+
20
+ export { CmsClient, type CmsFindOneOptions, type CmsFindOptions };
@@ -0,0 +1,20 @@
1
+ import { HttpClient, PalbaseResponse } from '@palbase/core';
2
+
3
+ interface CmsFindOptions {
4
+ locale?: string;
5
+ limit?: number;
6
+ offset?: number;
7
+ filter?: Record<string, unknown>;
8
+ }
9
+ interface CmsFindOneOptions {
10
+ locale?: string;
11
+ }
12
+
13
+ declare class CmsClient {
14
+ private readonly httpClient;
15
+ constructor(httpClient: HttpClient);
16
+ find<T = unknown>(collection: string, options?: CmsFindOptions): Promise<PalbaseResponse<T[]>>;
17
+ findOne<T = unknown>(collection: string, id: string, options?: CmsFindOneOptions): Promise<PalbaseResponse<T>>;
18
+ }
19
+
20
+ export { CmsClient, type CmsFindOneOptions, type CmsFindOptions };
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ // src/cms-client.ts
2
+ var COLLECTION_NAME_RE = /^[a-zA-Z0-9_\-]+$/;
3
+ var CmsClient = class {
4
+ httpClient;
5
+ constructor(httpClient) {
6
+ this.httpClient = httpClient;
7
+ }
8
+ async find(collection, options) {
9
+ if (!COLLECTION_NAME_RE.test(collection)) {
10
+ throw new Error(
11
+ `Invalid collection name: "${collection}". Collection names must match ${COLLECTION_NAME_RE.source}`
12
+ );
13
+ }
14
+ const params = new URLSearchParams();
15
+ if (options?.locale) params.set("locale", options.locale);
16
+ if (options?.limit != null) params.set("limit", String(options.limit));
17
+ if (options?.offset != null) params.set("offset", String(options.offset));
18
+ if (options?.filter) params.set("filter", JSON.stringify(options.filter));
19
+ const query = params.toString();
20
+ const path = `/v1/cms/${collection}${query ? `?${query}` : ""}`;
21
+ return this.httpClient.request("GET", path);
22
+ }
23
+ async findOne(collection, id, options) {
24
+ if (!COLLECTION_NAME_RE.test(collection)) {
25
+ throw new Error(
26
+ `Invalid collection name: "${collection}". Collection names must match ${COLLECTION_NAME_RE.source}`
27
+ );
28
+ }
29
+ const params = new URLSearchParams();
30
+ if (options?.locale) params.set("locale", options.locale);
31
+ const query = params.toString();
32
+ const path = `/v1/cms/${collection}/${encodeURIComponent(id)}${query ? `?${query}` : ""}`;
33
+ return this.httpClient.request("GET", path);
34
+ }
35
+ };
36
+ export {
37
+ CmsClient
38
+ };
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cms-client.ts"],"sourcesContent":["import type { HttpClient, PalbaseResponse } from '@palbase/core';\nimport type { CmsFindOneOptions, CmsFindOptions } from './types.js';\n\nconst COLLECTION_NAME_RE = /^[a-zA-Z0-9_\\-]+$/;\n\nexport class CmsClient {\n private readonly httpClient: HttpClient;\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient;\n }\n\n async find<T = unknown>(\n collection: string,\n options?: CmsFindOptions,\n ): Promise<PalbaseResponse<T[]>> {\n if (!COLLECTION_NAME_RE.test(collection)) {\n throw new Error(\n `Invalid collection name: \"${collection}\". Collection names must match ${COLLECTION_NAME_RE.source}`,\n );\n }\n\n const params = new URLSearchParams();\n if (options?.locale) params.set('locale', options.locale);\n if (options?.limit != null) params.set('limit', String(options.limit));\n if (options?.offset != null) params.set('offset', String(options.offset));\n if (options?.filter) params.set('filter', JSON.stringify(options.filter));\n\n const query = params.toString();\n const path = `/v1/cms/${collection}${query ? `?${query}` : ''}`;\n\n return this.httpClient.request<T[]>('GET', path);\n }\n\n async findOne<T = unknown>(\n collection: string,\n id: string,\n options?: CmsFindOneOptions,\n ): Promise<PalbaseResponse<T>> {\n if (!COLLECTION_NAME_RE.test(collection)) {\n throw new Error(\n `Invalid collection name: \"${collection}\". Collection names must match ${COLLECTION_NAME_RE.source}`,\n );\n }\n\n const params = new URLSearchParams();\n if (options?.locale) params.set('locale', options.locale);\n\n const query = params.toString();\n const path = `/v1/cms/${collection}/${encodeURIComponent(id)}${query ? `?${query}` : ''}`;\n\n return this.httpClient.request<T>('GET', path);\n }\n}\n"],"mappings":";AAGA,IAAM,qBAAqB;AAEpB,IAAM,YAAN,MAAgB;AAAA,EACJ;AAAA,EAEjB,YAAY,YAAwB;AAClC,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,MAAM,KACJ,YACA,SAC+B;AAC/B,QAAI,CAAC,mBAAmB,KAAK,UAAU,GAAG;AACxC,YAAM,IAAI;AAAA,QACR,6BAA6B,UAAU,kCAAkC,mBAAmB,MAAM;AAAA,MACpG;AAAA,IACF;AAEA,UAAM,SAAS,IAAI,gBAAgB;AACnC,QAAI,SAAS,OAAQ,QAAO,IAAI,UAAU,QAAQ,MAAM;AACxD,QAAI,SAAS,SAAS,KAAM,QAAO,IAAI,SAAS,OAAO,QAAQ,KAAK,CAAC;AACrE,QAAI,SAAS,UAAU,KAAM,QAAO,IAAI,UAAU,OAAO,QAAQ,MAAM,CAAC;AACxE,QAAI,SAAS,OAAQ,QAAO,IAAI,UAAU,KAAK,UAAU,QAAQ,MAAM,CAAC;AAExE,UAAM,QAAQ,OAAO,SAAS;AAC9B,UAAM,OAAO,WAAW,UAAU,GAAG,QAAQ,IAAI,KAAK,KAAK,EAAE;AAE7D,WAAO,KAAK,WAAW,QAAa,OAAO,IAAI;AAAA,EACjD;AAAA,EAEA,MAAM,QACJ,YACA,IACA,SAC6B;AAC7B,QAAI,CAAC,mBAAmB,KAAK,UAAU,GAAG;AACxC,YAAM,IAAI;AAAA,QACR,6BAA6B,UAAU,kCAAkC,mBAAmB,MAAM;AAAA,MACpG;AAAA,IACF;AAEA,UAAM,SAAS,IAAI,gBAAgB;AACnC,QAAI,SAAS,OAAQ,QAAO,IAAI,UAAU,QAAQ,MAAM;AAExD,UAAM,QAAQ,OAAO,SAAS;AAC9B,UAAM,OAAO,WAAW,UAAU,IAAI,mBAAmB,EAAE,CAAC,GAAG,QAAQ,IAAI,KAAK,KAAK,EAAE;AAEvF,WAAO,KAAK,WAAW,QAAW,OAAO,IAAI;AAAA,EAC/C;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@palbase/modules-cms",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "require": {
13
+ "types": "./dist/index.d.cts",
14
+ "default": "./dist/index.cjs"
15
+ }
16
+ }
17
+ },
18
+ "main": "./dist/index.cjs",
19
+ "module": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "@palbase/core": "0.1.0"
26
+ },
27
+ "devDependencies": {
28
+ "@biomejs/biome": "^2.0.0",
29
+ "tsup": "^8.4.0",
30
+ "typescript": "^5.8.0",
31
+ "vitest": "^3.1.0"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "test": "vitest run",
36
+ "lint": "biome check src/ __tests__/"
37
+ }
38
+ }