@plasmicpkgs/cms 0.0.2
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.md +21 -0
- package/README.md +1 -0
- package/dist/index.d.ts +171 -0
- package/dist/index.esm.js +361 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +391 -0
- package/dist/index.js.map +7 -0
- package/package.json +41 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Plasmic
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Plasmic CMS custom functions
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { ApiCmsRow } from './schema';
|
|
2
|
+
import { ApiCmsTable } from './schema';
|
|
3
|
+
|
|
4
|
+
export declare class _API {
|
|
5
|
+
private config;
|
|
6
|
+
constructor(config: _DatabaseConfig);
|
|
7
|
+
get(endpoint: string, params?: any): Promise<any>;
|
|
8
|
+
fetchTables(): Promise<_ApiCmsTable[]>;
|
|
9
|
+
private useDraftForTable;
|
|
10
|
+
query(table: string, params?: _QueryParams): Promise<_ApiCmsRow[]>;
|
|
11
|
+
count(table: string, params?: Pick<_QueryParams, "where" | "useDraft">): Promise<number>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export declare interface _ApiCmsQuery {
|
|
15
|
+
where?: FilterClause;
|
|
16
|
+
limit?: number;
|
|
17
|
+
offset?: number;
|
|
18
|
+
order?: (string | {
|
|
19
|
+
field: string;
|
|
20
|
+
dir: "asc" | "desc";
|
|
21
|
+
})[];
|
|
22
|
+
fields?: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare interface _ApiCmsRow {
|
|
26
|
+
identifier: string | null;
|
|
27
|
+
data: Record<string, any> | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export declare interface _ApiCmsTable {
|
|
31
|
+
identifier: string;
|
|
32
|
+
name: string;
|
|
33
|
+
schema: _CmsTableSchema;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare interface _CmsBaseType {
|
|
37
|
+
identifier: string;
|
|
38
|
+
name: string;
|
|
39
|
+
helperText: string;
|
|
40
|
+
required: boolean;
|
|
41
|
+
hidden: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export declare interface _CmsBoolean extends _CmsBaseType {
|
|
45
|
+
type: _CmsMetaType.BOOLEAN;
|
|
46
|
+
defaultValue?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export declare interface _CmsDateTime extends _CmsBaseType {
|
|
50
|
+
type: _CmsMetaType.DATE_TIME;
|
|
51
|
+
defaultValue?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export declare interface _CmsEnum extends _CmsBaseType {
|
|
55
|
+
type: _CmsMetaType.ENUM;
|
|
56
|
+
defaultValue?: string;
|
|
57
|
+
options: string[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export declare type _CmsFieldMeta = _CmsText | _CmsLongText | _CmsNumber | _CmsBoolean | _CmsImage | _CmsFile | _CmsDateTime | _CmsRef | _CmsRichText | _CmsEnum;
|
|
61
|
+
|
|
62
|
+
export declare interface _CmsFile extends _CmsBaseType {
|
|
63
|
+
type: _CmsMetaType.FILE;
|
|
64
|
+
defaultValue?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export declare interface _CmsImage extends _CmsBaseType {
|
|
68
|
+
type: _CmsMetaType.IMAGE;
|
|
69
|
+
defaultValue?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export declare interface _CmsLongText extends _CmsBaseType, _CmsTextLike {
|
|
73
|
+
type: _CmsMetaType.LONG_TEXT;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export declare enum _CmsMetaType {
|
|
77
|
+
TEXT = "text",
|
|
78
|
+
LONG_TEXT = "long-text",
|
|
79
|
+
NUMBER = "number",
|
|
80
|
+
IMAGE = "image",
|
|
81
|
+
FILE = "file",
|
|
82
|
+
DATE_TIME = "date-time",
|
|
83
|
+
BOOLEAN = "boolean",
|
|
84
|
+
COLOR = "color",
|
|
85
|
+
RICH_TEXT = "rich-text",
|
|
86
|
+
REF = "ref",
|
|
87
|
+
LIST = "list",
|
|
88
|
+
OBJECT = "object",
|
|
89
|
+
ENUM = "enum"
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export declare interface _CmsNumber extends _CmsBaseType {
|
|
93
|
+
type: _CmsMetaType.NUMBER;
|
|
94
|
+
defaultValue?: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export declare interface _CmsRef extends _CmsBaseType {
|
|
98
|
+
type: _CmsMetaType.REF;
|
|
99
|
+
defaultValue?: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export declare interface _CmsRichText extends _CmsBaseType {
|
|
103
|
+
type: _CmsMetaType.RICH_TEXT;
|
|
104
|
+
defaultValue?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export declare interface _CmsTableSchema {
|
|
108
|
+
fields: _CmsFieldMeta[];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export declare interface _CmsText extends _CmsBaseType, _CmsTextLike {
|
|
112
|
+
type: _CmsMetaType.TEXT;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export declare interface _CmsTextLike {
|
|
116
|
+
defaultValue?: string;
|
|
117
|
+
minChars?: number;
|
|
118
|
+
maxChars?: number;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export declare type _CmsType = _CmsFieldMeta["type"];
|
|
122
|
+
|
|
123
|
+
export declare interface _DatabaseConfig {
|
|
124
|
+
host: string;
|
|
125
|
+
databaseId: string;
|
|
126
|
+
databaseToken: string;
|
|
127
|
+
locale?: string;
|
|
128
|
+
useDraft?: boolean | string[];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export declare const _DEFAULT_HOST = "https://data.plasmic.app";
|
|
132
|
+
|
|
133
|
+
export declare function fetchContent(cmsId: string, cmsPublicToken: string, tableId: string, params: _QueryParams, useDraft: boolean, locale: string): Promise<ApiCmsRow[]>;
|
|
134
|
+
|
|
135
|
+
export declare function fetchCount(cmsId: string, cmsPublicToken: string, tableId: string, params: _QueryParams, useDraft: boolean): Promise<number>;
|
|
136
|
+
|
|
137
|
+
export declare function fetchTables(cmsId: string, cmsPublicToken: string): Promise<ApiCmsTable[]>;
|
|
138
|
+
|
|
139
|
+
declare type FilterClause = any;
|
|
140
|
+
|
|
141
|
+
export declare class _HttpError extends Error {
|
|
142
|
+
status: number;
|
|
143
|
+
constructor(status: number, message: string);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export declare function _mkApi(config: _DatabaseConfig | undefined): _API;
|
|
147
|
+
|
|
148
|
+
export declare function _mkFieldOptions(tables: _ApiCmsTable[] | undefined, tableIdentifier: string | undefined, types?: _CmsType[]): ValueLabelPair[];
|
|
149
|
+
|
|
150
|
+
export declare function _mkTableOptions(tables: _ApiCmsTable[] | undefined): ValueLabelPair[];
|
|
151
|
+
|
|
152
|
+
export declare interface _QueryParams {
|
|
153
|
+
useDraft?: boolean;
|
|
154
|
+
where?: any;
|
|
155
|
+
orderBy?: string;
|
|
156
|
+
desc?: boolean;
|
|
157
|
+
limit?: number;
|
|
158
|
+
offset?: number;
|
|
159
|
+
fields?: string[];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export declare function registerAllCmsFunctions(loader?: {
|
|
163
|
+
registerFunction: any;
|
|
164
|
+
}): void;
|
|
165
|
+
|
|
166
|
+
declare type ValueLabelPair = {
|
|
167
|
+
value: string;
|
|
168
|
+
label: string;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export { }
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
import registerFunction from "@plasmicapp/host/registerFunction";
|
|
24
|
+
|
|
25
|
+
// src/api.ts
|
|
26
|
+
function queryParamsToApi(params) {
|
|
27
|
+
return {
|
|
28
|
+
where: params.where,
|
|
29
|
+
limit: params.limit,
|
|
30
|
+
offset: params.offset,
|
|
31
|
+
order: params.orderBy ? [
|
|
32
|
+
{
|
|
33
|
+
field: params.orderBy,
|
|
34
|
+
dir: params.desc ? "desc" : "asc"
|
|
35
|
+
}
|
|
36
|
+
] : void 0,
|
|
37
|
+
fields: params.fields
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
var HttpError = class extends Error {
|
|
41
|
+
constructor(status, message) {
|
|
42
|
+
super(message);
|
|
43
|
+
this.status = status;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var API = class {
|
|
47
|
+
constructor(config) {
|
|
48
|
+
this.config = config;
|
|
49
|
+
}
|
|
50
|
+
get(_0) {
|
|
51
|
+
return __async(this, arguments, function* (endpoint, params = {}) {
|
|
52
|
+
var _a;
|
|
53
|
+
const url = new URL(
|
|
54
|
+
`${this.config.host}/api/v1/cms/databases/${this.config.databaseId}${endpoint}`
|
|
55
|
+
);
|
|
56
|
+
const fixedParams = Object.keys(params).reduce((newObj, key) => {
|
|
57
|
+
const value = params[key];
|
|
58
|
+
if (value != null) {
|
|
59
|
+
newObj[key] = value;
|
|
60
|
+
}
|
|
61
|
+
return newObj;
|
|
62
|
+
}, {});
|
|
63
|
+
url.search = new URLSearchParams(fixedParams).toString();
|
|
64
|
+
const response = yield fetch(url.toString(), {
|
|
65
|
+
method: "GET",
|
|
66
|
+
headers: {
|
|
67
|
+
accept: "*/*",
|
|
68
|
+
"x-plasmic-api-cms-tokens": `${this.config.databaseId}:${this.config.databaseToken}`
|
|
69
|
+
},
|
|
70
|
+
mode: "cors"
|
|
71
|
+
});
|
|
72
|
+
if (response.status !== 200) {
|
|
73
|
+
let message = yield response.text();
|
|
74
|
+
try {
|
|
75
|
+
const json = JSON.parse(message);
|
|
76
|
+
if ((_a = json.error) == null ? void 0 : _a.message) {
|
|
77
|
+
message = json.error.message;
|
|
78
|
+
}
|
|
79
|
+
} catch (e) {
|
|
80
|
+
}
|
|
81
|
+
throw new HttpError(response.status, message);
|
|
82
|
+
}
|
|
83
|
+
return yield response.json();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
fetchTables() {
|
|
87
|
+
return __async(this, null, function* () {
|
|
88
|
+
try {
|
|
89
|
+
const response = yield this.get(``);
|
|
90
|
+
return response.tables;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.error(e);
|
|
93
|
+
throw e;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
useDraftForTable(table) {
|
|
98
|
+
var _a;
|
|
99
|
+
if (Array.isArray(this.config.useDraft)) {
|
|
100
|
+
return this.config.useDraft.includes(table);
|
|
101
|
+
} else {
|
|
102
|
+
return (_a = this.config.useDraft) != null ? _a : false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
query(_0) {
|
|
106
|
+
return __async(this, arguments, function* (table, params = {}) {
|
|
107
|
+
try {
|
|
108
|
+
const response = yield this.get(`/tables/${table}/query`, {
|
|
109
|
+
q: JSON.stringify(queryParamsToApi(params)),
|
|
110
|
+
draft: Number(this.useDraftForTable(table) || params.useDraft),
|
|
111
|
+
locale: this.config.locale
|
|
112
|
+
});
|
|
113
|
+
return response.rows;
|
|
114
|
+
} catch (e) {
|
|
115
|
+
console.error(e);
|
|
116
|
+
throw e;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
count(_0) {
|
|
121
|
+
return __async(this, arguments, function* (table, params = {}) {
|
|
122
|
+
try {
|
|
123
|
+
const response = yield this.get(`/tables/${table}/count`, {
|
|
124
|
+
q: JSON.stringify(queryParamsToApi(params)),
|
|
125
|
+
draft: Number(this.useDraftForTable(table) || params.useDraft)
|
|
126
|
+
});
|
|
127
|
+
return response.count;
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.error(e);
|
|
130
|
+
throw e;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
function mkApi(config) {
|
|
136
|
+
if (!config) {
|
|
137
|
+
throw new Error("Component must be wrapped in 'CMS Data Provider'.");
|
|
138
|
+
}
|
|
139
|
+
return new API(config);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/constants.ts
|
|
143
|
+
var DEFAULT_HOST = "https://data.plasmic.app";
|
|
144
|
+
|
|
145
|
+
// src/schema.ts
|
|
146
|
+
var CmsMetaType = /* @__PURE__ */ ((CmsMetaType2) => {
|
|
147
|
+
CmsMetaType2["TEXT"] = "text";
|
|
148
|
+
CmsMetaType2["LONG_TEXT"] = "long-text";
|
|
149
|
+
CmsMetaType2["NUMBER"] = "number";
|
|
150
|
+
CmsMetaType2["IMAGE"] = "image";
|
|
151
|
+
CmsMetaType2["FILE"] = "file";
|
|
152
|
+
CmsMetaType2["DATE_TIME"] = "date-time";
|
|
153
|
+
CmsMetaType2["BOOLEAN"] = "boolean";
|
|
154
|
+
CmsMetaType2["COLOR"] = "color";
|
|
155
|
+
CmsMetaType2["RICH_TEXT"] = "rich-text";
|
|
156
|
+
CmsMetaType2["REF"] = "ref";
|
|
157
|
+
CmsMetaType2["LIST"] = "list";
|
|
158
|
+
CmsMetaType2["OBJECT"] = "object";
|
|
159
|
+
CmsMetaType2["ENUM"] = "enum";
|
|
160
|
+
return CmsMetaType2;
|
|
161
|
+
})(CmsMetaType || {});
|
|
162
|
+
|
|
163
|
+
// src/util.ts
|
|
164
|
+
function mkTableOptions(tables) {
|
|
165
|
+
if (!tables) {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
return tables.map((table) => ({
|
|
169
|
+
value: table.identifier,
|
|
170
|
+
label: table.name
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
function mkFieldOptions(tables, tableIdentifier, types) {
|
|
174
|
+
if (!tables) {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
const table = tables.find((t) => t.identifier === tableIdentifier);
|
|
178
|
+
if (!table) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
let fields = table.schema.fields;
|
|
182
|
+
if (types) {
|
|
183
|
+
fields = fields.filter((f) => types.includes(f.type));
|
|
184
|
+
}
|
|
185
|
+
const options = fields.map((f) => ({
|
|
186
|
+
value: f.identifier,
|
|
187
|
+
label: f.name || f.identifier
|
|
188
|
+
}));
|
|
189
|
+
if (!options.some((option) => option.value === "_id")) {
|
|
190
|
+
options.push({
|
|
191
|
+
label: "System-assigned ID",
|
|
192
|
+
value: "_id"
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return options;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/index.ts
|
|
199
|
+
function getCmsHost() {
|
|
200
|
+
var _a;
|
|
201
|
+
return (_a = globalThis["__PLASMIC_CMS_HOST__"]) != null ? _a : DEFAULT_HOST;
|
|
202
|
+
}
|
|
203
|
+
function createTableOptions(_args, ctx) {
|
|
204
|
+
if (!(ctx == null ? void 0 : ctx.tables)) {
|
|
205
|
+
return [];
|
|
206
|
+
}
|
|
207
|
+
return ctx.tables.map((table) => ({
|
|
208
|
+
value: table.identifier,
|
|
209
|
+
label: table.name
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
var sharedTableFnContext = (cmsId, cmsPublicToken, ..._args) => {
|
|
213
|
+
if (!cmsId || !cmsPublicToken) {
|
|
214
|
+
return {
|
|
215
|
+
dataKey: "",
|
|
216
|
+
fetcher: () => __async(void 0, null, function* () {
|
|
217
|
+
return { tables: [] };
|
|
218
|
+
})
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
dataKey: `cms_tables/${JSON.stringify({
|
|
223
|
+
cmsId,
|
|
224
|
+
cmsPublicToken
|
|
225
|
+
})}`,
|
|
226
|
+
fetcher: () => __async(void 0, null, function* () {
|
|
227
|
+
const api = mkApi({
|
|
228
|
+
databaseId: cmsId,
|
|
229
|
+
databaseToken: cmsPublicToken,
|
|
230
|
+
host: getCmsHost()
|
|
231
|
+
});
|
|
232
|
+
const tables = yield api.fetchTables();
|
|
233
|
+
return { tables };
|
|
234
|
+
})
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
var cmsIdParam = {
|
|
238
|
+
name: "cmsId",
|
|
239
|
+
type: "string",
|
|
240
|
+
description: "The cms ID"
|
|
241
|
+
};
|
|
242
|
+
var cmsPublicTokenParam = {
|
|
243
|
+
name: "cmsPublicToken",
|
|
244
|
+
type: "string",
|
|
245
|
+
description: "The cms public token"
|
|
246
|
+
};
|
|
247
|
+
var tableIdParam = {
|
|
248
|
+
name: "tableId",
|
|
249
|
+
type: "choice",
|
|
250
|
+
options: createTableOptions
|
|
251
|
+
};
|
|
252
|
+
var paramsParam = {
|
|
253
|
+
name: "params",
|
|
254
|
+
type: "object",
|
|
255
|
+
description: "The parameters to filter the content (e.g., for sorting, limit, offset, advanced queries)"
|
|
256
|
+
};
|
|
257
|
+
var useDraftParam = {
|
|
258
|
+
name: "useDraft",
|
|
259
|
+
type: "boolean",
|
|
260
|
+
description: "Whether to use draft data. Defaults to false."
|
|
261
|
+
};
|
|
262
|
+
var localeParam = {
|
|
263
|
+
name: "locale",
|
|
264
|
+
type: "string",
|
|
265
|
+
description: "The locale to use. Defaults to empty string."
|
|
266
|
+
};
|
|
267
|
+
function fetchTables(cmsId, cmsPublicToken) {
|
|
268
|
+
return __async(this, null, function* () {
|
|
269
|
+
const api = mkApi({
|
|
270
|
+
databaseId: cmsId,
|
|
271
|
+
databaseToken: cmsPublicToken,
|
|
272
|
+
host: getCmsHost()
|
|
273
|
+
});
|
|
274
|
+
return api.fetchTables();
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
function fetchContent(cmsId, cmsPublicToken, tableId, params, useDraft, locale) {
|
|
278
|
+
return __async(this, null, function* () {
|
|
279
|
+
const api = mkApi({
|
|
280
|
+
databaseId: cmsId,
|
|
281
|
+
databaseToken: cmsPublicToken,
|
|
282
|
+
host: getCmsHost(),
|
|
283
|
+
useDraft,
|
|
284
|
+
locale
|
|
285
|
+
});
|
|
286
|
+
return api.query(tableId, params);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function fetchCount(cmsId, cmsPublicToken, tableId, params, useDraft) {
|
|
290
|
+
return __async(this, null, function* () {
|
|
291
|
+
const api = mkApi({
|
|
292
|
+
databaseId: cmsId,
|
|
293
|
+
databaseToken: cmsPublicToken,
|
|
294
|
+
host: getCmsHost(),
|
|
295
|
+
useDraft
|
|
296
|
+
});
|
|
297
|
+
return api.count(tableId, params);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
function registerAllCmsFunctions(loader) {
|
|
301
|
+
function _registerFunction(fn, meta) {
|
|
302
|
+
if (loader) {
|
|
303
|
+
loader.registerFunction(fn, meta);
|
|
304
|
+
} else {
|
|
305
|
+
registerFunction(fn, meta);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
_registerFunction(fetchTables, {
|
|
309
|
+
name: "fetchTables",
|
|
310
|
+
namespace: "plasmicCms",
|
|
311
|
+
displayName: "Fetch Plasmic CMS Tables",
|
|
312
|
+
description: "Fetches table metadata from Plasmic CMS",
|
|
313
|
+
importPath: "@plasmicpkgs/cms",
|
|
314
|
+
params: [cmsIdParam, cmsPublicTokenParam]
|
|
315
|
+
});
|
|
316
|
+
_registerFunction(fetchContent, {
|
|
317
|
+
name: "fetchContent",
|
|
318
|
+
namespace: "plasmicCms",
|
|
319
|
+
displayName: "Fetch Plasmic CMS Content",
|
|
320
|
+
description: "Fetch content from a Plasmic CMS table",
|
|
321
|
+
importPath: "@plasmicpkgs/cms",
|
|
322
|
+
params: [
|
|
323
|
+
cmsIdParam,
|
|
324
|
+
cmsPublicTokenParam,
|
|
325
|
+
tableIdParam,
|
|
326
|
+
paramsParam,
|
|
327
|
+
useDraftParam,
|
|
328
|
+
localeParam
|
|
329
|
+
],
|
|
330
|
+
fnContext: sharedTableFnContext
|
|
331
|
+
});
|
|
332
|
+
_registerFunction(fetchCount, {
|
|
333
|
+
name: "fetchCount",
|
|
334
|
+
namespace: "plasmicCms",
|
|
335
|
+
displayName: "Fetch Plasmic CMS Count",
|
|
336
|
+
description: "Fetch the count of entries from a Plasmic CMS table",
|
|
337
|
+
importPath: "@plasmicpkgs/cms",
|
|
338
|
+
params: [
|
|
339
|
+
cmsIdParam,
|
|
340
|
+
cmsPublicTokenParam,
|
|
341
|
+
tableIdParam,
|
|
342
|
+
paramsParam,
|
|
343
|
+
useDraftParam
|
|
344
|
+
],
|
|
345
|
+
fnContext: sharedTableFnContext
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
export {
|
|
349
|
+
API as _API,
|
|
350
|
+
CmsMetaType as _CmsMetaType,
|
|
351
|
+
DEFAULT_HOST as _DEFAULT_HOST,
|
|
352
|
+
HttpError as _HttpError,
|
|
353
|
+
mkApi as _mkApi,
|
|
354
|
+
mkFieldOptions as _mkFieldOptions,
|
|
355
|
+
mkTableOptions as _mkTableOptions,
|
|
356
|
+
fetchContent,
|
|
357
|
+
fetchCount,
|
|
358
|
+
fetchTables,
|
|
359
|
+
registerAllCmsFunctions
|
|
360
|
+
};
|
|
361
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/api.ts", "../src/constants.ts", "../src/schema.ts", "../src/util.ts"],
|
|
4
|
+
"sourcesContent": ["import registerFunction, {\n CustomFunctionMeta,\n} from \"@plasmicapp/host/registerFunction\";\n\nimport { QueryParams, mkApi } from \"./api\";\nimport { DEFAULT_HOST } from \"./constants\";\n\nfunction getCmsHost() {\n return (globalThis as any)[\"__PLASMIC_CMS_HOST__\"] ?? DEFAULT_HOST;\n}\n\nfunction createTableOptions(\n _args: unknown[],\n ctx: { tables: Array<{ identifier: string; name: string }> } | undefined\n): Array<{ value: string; label: string }> {\n if (!ctx?.tables) {\n return [];\n }\n return ctx.tables.map((table: { identifier: string; name: string }) => ({\n value: table.identifier,\n label: table.name,\n }));\n}\n\nconst sharedTableFnContext = (\n cmsId?: string,\n cmsPublicToken?: string,\n ..._args: unknown[]\n) => {\n if (!cmsId || !cmsPublicToken) {\n return {\n dataKey: \"\",\n fetcher: async () => ({ tables: [] }),\n };\n }\n return {\n dataKey: `cms_tables/${JSON.stringify({\n cmsId,\n cmsPublicToken,\n })}`,\n fetcher: async () => {\n const api = mkApi({\n databaseId: cmsId,\n databaseToken: cmsPublicToken,\n host: getCmsHost(),\n });\n const tables = await api.fetchTables();\n return { tables };\n },\n };\n};\n\n// TODO: Handle markdown in descriptions and link to https://docs.plasmic.app/learn/plasmic-cms-api-reference/#find-your-cms-ids-public-token-and-secret-token\nconst cmsIdParam = {\n name: \"cmsId\",\n type: \"string\",\n description: \"The cms ID\",\n} as const;\n\nconst cmsPublicTokenParam = {\n name: \"cmsPublicToken\",\n type: \"string\",\n description: \"The cms public token\",\n} as const;\n\nconst tableIdParam = {\n name: \"tableId\",\n type: \"choice\",\n options: createTableOptions,\n} as const;\n\n// TODO: Directly handle the inner params available options\nconst paramsParam = {\n name: \"params\",\n type: \"object\",\n description:\n \"The parameters to filter the content (e.g., for sorting, limit, offset, advanced queries)\",\n} as const;\n\nconst useDraftParam = {\n name: \"useDraft\",\n type: \"boolean\",\n description: \"Whether to use draft data. Defaults to false.\",\n} as const;\n\nconst localeParam = {\n name: \"locale\",\n type: \"string\",\n description: \"The locale to use. Defaults to empty string.\",\n} as const;\n\nexport async function fetchTables(cmsId: string, cmsPublicToken: string) {\n const api = mkApi({\n databaseId: cmsId,\n databaseToken: cmsPublicToken,\n host: getCmsHost(),\n });\n\n return api.fetchTables();\n}\n\nexport async function fetchContent(\n cmsId: string,\n cmsPublicToken: string,\n tableId: string,\n params: QueryParams,\n useDraft: boolean,\n locale: string\n) {\n const api = mkApi({\n databaseId: cmsId,\n databaseToken: cmsPublicToken,\n host: getCmsHost(),\n useDraft,\n locale,\n });\n\n return api.query(tableId, params);\n}\n\nexport async function fetchCount(\n cmsId: string,\n cmsPublicToken: string,\n tableId: string,\n params: QueryParams,\n useDraft: boolean\n) {\n const api = mkApi({\n databaseId: cmsId,\n databaseToken: cmsPublicToken,\n host: getCmsHost(),\n useDraft,\n });\n\n return api.count(tableId, params);\n}\n\nexport function registerAllCmsFunctions(loader?: { registerFunction: any }) {\n function _registerFunction<T extends (...args: any[]) => any>(\n fn: T,\n meta: CustomFunctionMeta<T>\n ) {\n if (loader) {\n loader.registerFunction(fn, meta);\n } else {\n registerFunction(fn, meta);\n }\n }\n\n _registerFunction(fetchTables, {\n name: \"fetchTables\",\n namespace: \"plasmicCms\",\n displayName: \"Fetch Plasmic CMS Tables\",\n description: \"Fetches table metadata from Plasmic CMS\",\n importPath: \"@plasmicpkgs/cms\",\n params: [cmsIdParam, cmsPublicTokenParam],\n });\n\n _registerFunction(fetchContent, {\n name: \"fetchContent\",\n namespace: \"plasmicCms\",\n displayName: \"Fetch Plasmic CMS Content\",\n description: \"Fetch content from a Plasmic CMS table\",\n importPath: \"@plasmicpkgs/cms\",\n params: [\n cmsIdParam,\n cmsPublicTokenParam,\n tableIdParam,\n paramsParam,\n useDraftParam,\n localeParam,\n ],\n fnContext: sharedTableFnContext,\n });\n\n _registerFunction(fetchCount, {\n name: \"fetchCount\",\n namespace: \"plasmicCms\",\n displayName: \"Fetch Plasmic CMS Count\",\n description: \"Fetch the count of entries from a Plasmic CMS table\",\n importPath: \"@plasmicpkgs/cms\",\n params: [\n cmsIdParam,\n cmsPublicTokenParam,\n tableIdParam,\n paramsParam,\n useDraftParam,\n ],\n fnContext: sharedTableFnContext,\n });\n}\n\n// Export utilities and types with underscore prefix\nexport { API as _API, HttpError as _HttpError, mkApi as _mkApi } from \"./api\";\n\nexport type {\n DatabaseConfig as _DatabaseConfig,\n QueryParams as _QueryParams,\n} from \"./api\";\n\nexport { DEFAULT_HOST as _DEFAULT_HOST } from \"./constants\";\n\nexport { CmsMetaType as _CmsMetaType } from \"./schema\";\nexport type {\n ApiCmsQuery as _ApiCmsQuery,\n ApiCmsRow as _ApiCmsRow,\n ApiCmsTable as _ApiCmsTable,\n} from \"./schema\";\n\nexport type {\n CmsBaseType as _CmsBaseType,\n CmsBoolean as _CmsBoolean,\n CmsDateTime as _CmsDateTime,\n CmsEnum as _CmsEnum,\n CmsFieldMeta as _CmsFieldMeta,\n CmsFile as _CmsFile,\n CmsImage as _CmsImage,\n CmsLongText as _CmsLongText,\n CmsNumber as _CmsNumber,\n CmsRef as _CmsRef,\n CmsRichText as _CmsRichText,\n CmsTableSchema as _CmsTableSchema,\n CmsText as _CmsText,\n CmsTextLike as _CmsTextLike,\n CmsType as _CmsType,\n} from \"./schema\";\n\nexport {\n mkFieldOptions as _mkFieldOptions,\n mkTableOptions as _mkTableOptions,\n} from \"./util\";\n", "import { ApiCmsQuery, ApiCmsRow, ApiCmsTable } from \"./schema\";\n\nexport interface DatabaseConfig {\n host: string;\n databaseId: string;\n databaseToken: string;\n locale?: string;\n useDraft?: boolean | string[];\n}\n\nexport interface QueryParams {\n useDraft?: boolean;\n where?: any;\n orderBy?: string;\n desc?: boolean;\n limit?: number;\n offset?: number;\n fields?: string[];\n}\n\nfunction queryParamsToApi(params: QueryParams): ApiCmsQuery {\n return {\n where: params.where,\n limit: params.limit,\n offset: params.offset,\n order: params.orderBy\n ? [\n {\n field: params.orderBy,\n dir: params.desc ? \"desc\" : \"asc\",\n },\n ]\n : undefined,\n fields: params.fields,\n };\n}\n\nexport class HttpError extends Error {\n constructor(public status: number, message: string) {\n super(message);\n }\n}\n\nexport class API {\n constructor(private config: DatabaseConfig) {}\n\n async get(endpoint: string, params: any = {}) {\n const url = new URL(\n `${this.config.host}/api/v1/cms/databases/${this.config.databaseId}${endpoint}`\n );\n const fixedParams = Object.keys(params).reduce((newObj, key) => {\n const value = params[key];\n if (value != null) {\n newObj[key] = value;\n }\n return newObj;\n }, {} as any);\n url.search = new URLSearchParams(fixedParams).toString();\n const response = await fetch(url.toString(), {\n method: \"GET\",\n headers: {\n accept: \"*/*\",\n \"x-plasmic-api-cms-tokens\": `${this.config.databaseId}:${this.config.databaseToken}`,\n },\n mode: \"cors\",\n });\n\n if (response.status !== 200) {\n let message = await response.text();\n try {\n const json = JSON.parse(message);\n if (json.error?.message) {\n message = json.error.message;\n }\n } catch {\n // ignored\n }\n throw new HttpError(response.status, message);\n }\n\n return await response.json();\n }\n\n async fetchTables(): Promise<ApiCmsTable[]> {\n try {\n const response = await this.get(``);\n return response.tables;\n } catch (e) {\n console.error(e);\n throw e;\n }\n }\n\n private useDraftForTable(table: string) {\n if (Array.isArray(this.config.useDraft)) {\n return this.config.useDraft.includes(table);\n } else {\n return this.config.useDraft ?? false;\n }\n }\n\n async query(table: string, params: QueryParams = {}): Promise<ApiCmsRow[]> {\n try {\n const response = await this.get(`/tables/${table}/query`, {\n q: JSON.stringify(queryParamsToApi(params)),\n draft: Number(this.useDraftForTable(table) || params.useDraft),\n locale: this.config.locale,\n });\n return response.rows;\n } catch (e) {\n console.error(e);\n throw e;\n }\n }\n\n async count(\n table: string,\n params: Pick<QueryParams, \"where\" | \"useDraft\"> = {}\n ): Promise<number> {\n try {\n const response = await this.get(`/tables/${table}/count`, {\n q: JSON.stringify(queryParamsToApi(params)),\n draft: Number(this.useDraftForTable(table) || params.useDraft),\n });\n return response.count;\n } catch (e) {\n console.error(e);\n throw e;\n }\n }\n}\n\nexport function mkApi(config: DatabaseConfig | undefined) {\n if (!config) {\n throw new Error(\"Component must be wrapped in 'CMS Data Provider'.\");\n }\n\n return new API(config);\n}\n", "export const DEFAULT_HOST = \"https://data.plasmic.app\";\n", "// This should be kept in sync with wab/ApiSchema.\n\n// eslint-disable-next-line no-shadow\nexport enum CmsMetaType {\n TEXT = \"text\",\n LONG_TEXT = \"long-text\",\n NUMBER = \"number\",\n IMAGE = \"image\",\n FILE = \"file\",\n DATE_TIME = \"date-time\",\n BOOLEAN = \"boolean\",\n COLOR = \"color\",\n RICH_TEXT = \"rich-text\",\n REF = \"ref\",\n LIST = \"list\",\n OBJECT = \"object\",\n ENUM = \"enum\",\n}\n\nexport interface CmsBaseType {\n identifier: string;\n name: string;\n helperText: string;\n required: boolean;\n hidden: boolean;\n}\n\nexport interface CmsTextLike {\n defaultValue?: string;\n minChars?: number;\n maxChars?: number;\n}\n\nexport interface CmsText extends CmsBaseType, CmsTextLike {\n type: CmsMetaType.TEXT;\n}\n\nexport interface CmsLongText extends CmsBaseType, CmsTextLike {\n type: CmsMetaType.LONG_TEXT;\n}\n\nexport interface CmsNumber extends CmsBaseType {\n type: CmsMetaType.NUMBER;\n defaultValue?: number;\n}\n\nexport interface CmsBoolean extends CmsBaseType {\n type: CmsMetaType.BOOLEAN;\n defaultValue?: boolean;\n}\n\nexport interface CmsImage extends CmsBaseType {\n type: CmsMetaType.IMAGE;\n defaultValue?: string;\n}\n\nexport interface CmsDateTime extends CmsBaseType {\n type: CmsMetaType.DATE_TIME;\n defaultValue?: string;\n}\n\nexport interface CmsRichText extends CmsBaseType {\n type: CmsMetaType.RICH_TEXT;\n defaultValue?: string;\n}\n\nexport interface CmsFile extends CmsBaseType {\n type: CmsMetaType.FILE;\n defaultValue?: string;\n}\n\nexport interface CmsRef extends CmsBaseType {\n type: CmsMetaType.REF;\n defaultValue?: string;\n}\n\nexport interface CmsEnum extends CmsBaseType {\n type: CmsMetaType.ENUM;\n defaultValue?: string;\n options: string[];\n}\n\nexport type CmsFieldMeta =\n | CmsText\n | CmsLongText\n | CmsNumber\n | CmsBoolean\n | CmsImage\n | CmsFile\n | CmsDateTime\n | CmsRef\n | CmsRichText\n | CmsEnum;\n\nexport type CmsType = CmsFieldMeta[\"type\"];\n\nexport interface CmsTableSchema {\n fields: CmsFieldMeta[];\n}\n\nexport interface ApiCmsTable {\n identifier: string;\n name: string;\n schema: CmsTableSchema;\n}\n\nexport interface ApiCmsRow {\n identifier: string | null;\n data: Record<string, any> | null;\n}\n\ntype FilterClause = any;\n\nexport interface ApiCmsQuery {\n where?: FilterClause;\n limit?: number;\n offset?: number;\n order?: (string | { field: string; dir: \"asc\" | \"desc\" })[];\n fields?: string[];\n}\n", "import { ApiCmsTable, CmsType } from \"./schema\";\n\ntype ValueLabelPair = {\n value: string;\n label: string;\n};\n\nexport function mkTableOptions(\n tables: ApiCmsTable[] | undefined\n): ValueLabelPair[] {\n if (!tables) {\n return [];\n }\n\n return tables.map((table) => ({\n value: table.identifier,\n label: table.name,\n }));\n}\n\nexport function mkFieldOptions(\n tables: ApiCmsTable[] | undefined,\n tableIdentifier: string | undefined,\n types?: CmsType[]\n): ValueLabelPair[] {\n if (!tables) {\n return [];\n }\n\n const table = tables.find((t) => t.identifier === tableIdentifier);\n if (!table) {\n return [];\n }\n\n let fields = table.schema.fields;\n if (types) {\n fields = fields.filter((f) => types.includes(f.type));\n }\n const options = fields.map((f) => ({\n value: f.identifier,\n label: f.name || f.identifier,\n }));\n if (!options.some((option) => option.value === \"_id\")) {\n options.push({\n label: \"System-assigned ID\",\n value: \"_id\",\n });\n }\n\n return options;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,sBAEA;;;ACkBP,SAAS,iBAAiB,QAAkC;AAC1D,SAAO;AAAA,IACL,OAAO,OAAO;AAAA,IACd,OAAO,OAAO;AAAA,IACd,QAAQ,OAAO;AAAA,IACf,OAAO,OAAO,UACV;AAAA,MACE;AAAA,QACE,OAAO,OAAO;AAAA,QACd,KAAK,OAAO,OAAO,SAAS;AAAA,MAC9B;AAAA,IACF,IACA;AAAA,IACJ,QAAQ,OAAO;AAAA,EACjB;AACF;AAEO,IAAM,YAAN,cAAwB,MAAM;AAAA,EACnC,YAAmB,QAAgB,SAAiB;AAClD,UAAM,OAAO;AADI;AAAA,EAEnB;AACF;AAE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",
|
|
6
|
+
"names": ["CmsMetaType"]
|
|
7
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var __async = (__this, __arguments, generator) => {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
var fulfilled = (value) => {
|
|
32
|
+
try {
|
|
33
|
+
step(generator.next(value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var rejected = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.throw(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
46
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/index.ts
|
|
51
|
+
var src_exports = {};
|
|
52
|
+
__export(src_exports, {
|
|
53
|
+
_API: () => API,
|
|
54
|
+
_CmsMetaType: () => CmsMetaType,
|
|
55
|
+
_DEFAULT_HOST: () => DEFAULT_HOST,
|
|
56
|
+
_HttpError: () => HttpError,
|
|
57
|
+
_mkApi: () => mkApi,
|
|
58
|
+
_mkFieldOptions: () => mkFieldOptions,
|
|
59
|
+
_mkTableOptions: () => mkTableOptions,
|
|
60
|
+
fetchContent: () => fetchContent,
|
|
61
|
+
fetchCount: () => fetchCount,
|
|
62
|
+
fetchTables: () => fetchTables,
|
|
63
|
+
registerAllCmsFunctions: () => registerAllCmsFunctions
|
|
64
|
+
});
|
|
65
|
+
module.exports = __toCommonJS(src_exports);
|
|
66
|
+
var import_registerFunction = __toESM(require("@plasmicapp/host/registerFunction"));
|
|
67
|
+
|
|
68
|
+
// src/api.ts
|
|
69
|
+
function queryParamsToApi(params) {
|
|
70
|
+
return {
|
|
71
|
+
where: params.where,
|
|
72
|
+
limit: params.limit,
|
|
73
|
+
offset: params.offset,
|
|
74
|
+
order: params.orderBy ? [
|
|
75
|
+
{
|
|
76
|
+
field: params.orderBy,
|
|
77
|
+
dir: params.desc ? "desc" : "asc"
|
|
78
|
+
}
|
|
79
|
+
] : void 0,
|
|
80
|
+
fields: params.fields
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
var HttpError = class extends Error {
|
|
84
|
+
constructor(status, message) {
|
|
85
|
+
super(message);
|
|
86
|
+
this.status = status;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var API = class {
|
|
90
|
+
constructor(config) {
|
|
91
|
+
this.config = config;
|
|
92
|
+
}
|
|
93
|
+
get(_0) {
|
|
94
|
+
return __async(this, arguments, function* (endpoint, params = {}) {
|
|
95
|
+
var _a;
|
|
96
|
+
const url = new URL(
|
|
97
|
+
`${this.config.host}/api/v1/cms/databases/${this.config.databaseId}${endpoint}`
|
|
98
|
+
);
|
|
99
|
+
const fixedParams = Object.keys(params).reduce((newObj, key) => {
|
|
100
|
+
const value = params[key];
|
|
101
|
+
if (value != null) {
|
|
102
|
+
newObj[key] = value;
|
|
103
|
+
}
|
|
104
|
+
return newObj;
|
|
105
|
+
}, {});
|
|
106
|
+
url.search = new URLSearchParams(fixedParams).toString();
|
|
107
|
+
const response = yield fetch(url.toString(), {
|
|
108
|
+
method: "GET",
|
|
109
|
+
headers: {
|
|
110
|
+
accept: "*/*",
|
|
111
|
+
"x-plasmic-api-cms-tokens": `${this.config.databaseId}:${this.config.databaseToken}`
|
|
112
|
+
},
|
|
113
|
+
mode: "cors"
|
|
114
|
+
});
|
|
115
|
+
if (response.status !== 200) {
|
|
116
|
+
let message = yield response.text();
|
|
117
|
+
try {
|
|
118
|
+
const json = JSON.parse(message);
|
|
119
|
+
if ((_a = json.error) == null ? void 0 : _a.message) {
|
|
120
|
+
message = json.error.message;
|
|
121
|
+
}
|
|
122
|
+
} catch (e) {
|
|
123
|
+
}
|
|
124
|
+
throw new HttpError(response.status, message);
|
|
125
|
+
}
|
|
126
|
+
return yield response.json();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
fetchTables() {
|
|
130
|
+
return __async(this, null, function* () {
|
|
131
|
+
try {
|
|
132
|
+
const response = yield this.get(``);
|
|
133
|
+
return response.tables;
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.error(e);
|
|
136
|
+
throw e;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
useDraftForTable(table) {
|
|
141
|
+
var _a;
|
|
142
|
+
if (Array.isArray(this.config.useDraft)) {
|
|
143
|
+
return this.config.useDraft.includes(table);
|
|
144
|
+
} else {
|
|
145
|
+
return (_a = this.config.useDraft) != null ? _a : false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
query(_0) {
|
|
149
|
+
return __async(this, arguments, function* (table, params = {}) {
|
|
150
|
+
try {
|
|
151
|
+
const response = yield this.get(`/tables/${table}/query`, {
|
|
152
|
+
q: JSON.stringify(queryParamsToApi(params)),
|
|
153
|
+
draft: Number(this.useDraftForTable(table) || params.useDraft),
|
|
154
|
+
locale: this.config.locale
|
|
155
|
+
});
|
|
156
|
+
return response.rows;
|
|
157
|
+
} catch (e) {
|
|
158
|
+
console.error(e);
|
|
159
|
+
throw e;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
count(_0) {
|
|
164
|
+
return __async(this, arguments, function* (table, params = {}) {
|
|
165
|
+
try {
|
|
166
|
+
const response = yield this.get(`/tables/${table}/count`, {
|
|
167
|
+
q: JSON.stringify(queryParamsToApi(params)),
|
|
168
|
+
draft: Number(this.useDraftForTable(table) || params.useDraft)
|
|
169
|
+
});
|
|
170
|
+
return response.count;
|
|
171
|
+
} catch (e) {
|
|
172
|
+
console.error(e);
|
|
173
|
+
throw e;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
function mkApi(config) {
|
|
179
|
+
if (!config) {
|
|
180
|
+
throw new Error("Component must be wrapped in 'CMS Data Provider'.");
|
|
181
|
+
}
|
|
182
|
+
return new API(config);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/constants.ts
|
|
186
|
+
var DEFAULT_HOST = "https://data.plasmic.app";
|
|
187
|
+
|
|
188
|
+
// src/schema.ts
|
|
189
|
+
var CmsMetaType = /* @__PURE__ */ ((CmsMetaType2) => {
|
|
190
|
+
CmsMetaType2["TEXT"] = "text";
|
|
191
|
+
CmsMetaType2["LONG_TEXT"] = "long-text";
|
|
192
|
+
CmsMetaType2["NUMBER"] = "number";
|
|
193
|
+
CmsMetaType2["IMAGE"] = "image";
|
|
194
|
+
CmsMetaType2["FILE"] = "file";
|
|
195
|
+
CmsMetaType2["DATE_TIME"] = "date-time";
|
|
196
|
+
CmsMetaType2["BOOLEAN"] = "boolean";
|
|
197
|
+
CmsMetaType2["COLOR"] = "color";
|
|
198
|
+
CmsMetaType2["RICH_TEXT"] = "rich-text";
|
|
199
|
+
CmsMetaType2["REF"] = "ref";
|
|
200
|
+
CmsMetaType2["LIST"] = "list";
|
|
201
|
+
CmsMetaType2["OBJECT"] = "object";
|
|
202
|
+
CmsMetaType2["ENUM"] = "enum";
|
|
203
|
+
return CmsMetaType2;
|
|
204
|
+
})(CmsMetaType || {});
|
|
205
|
+
|
|
206
|
+
// src/util.ts
|
|
207
|
+
function mkTableOptions(tables) {
|
|
208
|
+
if (!tables) {
|
|
209
|
+
return [];
|
|
210
|
+
}
|
|
211
|
+
return tables.map((table) => ({
|
|
212
|
+
value: table.identifier,
|
|
213
|
+
label: table.name
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
function mkFieldOptions(tables, tableIdentifier, types) {
|
|
217
|
+
if (!tables) {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
const table = tables.find((t) => t.identifier === tableIdentifier);
|
|
221
|
+
if (!table) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
let fields = table.schema.fields;
|
|
225
|
+
if (types) {
|
|
226
|
+
fields = fields.filter((f) => types.includes(f.type));
|
|
227
|
+
}
|
|
228
|
+
const options = fields.map((f) => ({
|
|
229
|
+
value: f.identifier,
|
|
230
|
+
label: f.name || f.identifier
|
|
231
|
+
}));
|
|
232
|
+
if (!options.some((option) => option.value === "_id")) {
|
|
233
|
+
options.push({
|
|
234
|
+
label: "System-assigned ID",
|
|
235
|
+
value: "_id"
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return options;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/index.ts
|
|
242
|
+
function getCmsHost() {
|
|
243
|
+
var _a;
|
|
244
|
+
return (_a = globalThis["__PLASMIC_CMS_HOST__"]) != null ? _a : DEFAULT_HOST;
|
|
245
|
+
}
|
|
246
|
+
function createTableOptions(_args, ctx) {
|
|
247
|
+
if (!(ctx == null ? void 0 : ctx.tables)) {
|
|
248
|
+
return [];
|
|
249
|
+
}
|
|
250
|
+
return ctx.tables.map((table) => ({
|
|
251
|
+
value: table.identifier,
|
|
252
|
+
label: table.name
|
|
253
|
+
}));
|
|
254
|
+
}
|
|
255
|
+
var sharedTableFnContext = (cmsId, cmsPublicToken, ..._args) => {
|
|
256
|
+
if (!cmsId || !cmsPublicToken) {
|
|
257
|
+
return {
|
|
258
|
+
dataKey: "",
|
|
259
|
+
fetcher: () => __async(void 0, null, function* () {
|
|
260
|
+
return { tables: [] };
|
|
261
|
+
})
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
dataKey: `cms_tables/${JSON.stringify({
|
|
266
|
+
cmsId,
|
|
267
|
+
cmsPublicToken
|
|
268
|
+
})}`,
|
|
269
|
+
fetcher: () => __async(void 0, null, function* () {
|
|
270
|
+
const api = mkApi({
|
|
271
|
+
databaseId: cmsId,
|
|
272
|
+
databaseToken: cmsPublicToken,
|
|
273
|
+
host: getCmsHost()
|
|
274
|
+
});
|
|
275
|
+
const tables = yield api.fetchTables();
|
|
276
|
+
return { tables };
|
|
277
|
+
})
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
var cmsIdParam = {
|
|
281
|
+
name: "cmsId",
|
|
282
|
+
type: "string",
|
|
283
|
+
description: "The cms ID"
|
|
284
|
+
};
|
|
285
|
+
var cmsPublicTokenParam = {
|
|
286
|
+
name: "cmsPublicToken",
|
|
287
|
+
type: "string",
|
|
288
|
+
description: "The cms public token"
|
|
289
|
+
};
|
|
290
|
+
var tableIdParam = {
|
|
291
|
+
name: "tableId",
|
|
292
|
+
type: "choice",
|
|
293
|
+
options: createTableOptions
|
|
294
|
+
};
|
|
295
|
+
var paramsParam = {
|
|
296
|
+
name: "params",
|
|
297
|
+
type: "object",
|
|
298
|
+
description: "The parameters to filter the content (e.g., for sorting, limit, offset, advanced queries)"
|
|
299
|
+
};
|
|
300
|
+
var useDraftParam = {
|
|
301
|
+
name: "useDraft",
|
|
302
|
+
type: "boolean",
|
|
303
|
+
description: "Whether to use draft data. Defaults to false."
|
|
304
|
+
};
|
|
305
|
+
var localeParam = {
|
|
306
|
+
name: "locale",
|
|
307
|
+
type: "string",
|
|
308
|
+
description: "The locale to use. Defaults to empty string."
|
|
309
|
+
};
|
|
310
|
+
function fetchTables(cmsId, cmsPublicToken) {
|
|
311
|
+
return __async(this, null, function* () {
|
|
312
|
+
const api = mkApi({
|
|
313
|
+
databaseId: cmsId,
|
|
314
|
+
databaseToken: cmsPublicToken,
|
|
315
|
+
host: getCmsHost()
|
|
316
|
+
});
|
|
317
|
+
return api.fetchTables();
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
function fetchContent(cmsId, cmsPublicToken, tableId, params, useDraft, locale) {
|
|
321
|
+
return __async(this, null, function* () {
|
|
322
|
+
const api = mkApi({
|
|
323
|
+
databaseId: cmsId,
|
|
324
|
+
databaseToken: cmsPublicToken,
|
|
325
|
+
host: getCmsHost(),
|
|
326
|
+
useDraft,
|
|
327
|
+
locale
|
|
328
|
+
});
|
|
329
|
+
return api.query(tableId, params);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
function fetchCount(cmsId, cmsPublicToken, tableId, params, useDraft) {
|
|
333
|
+
return __async(this, null, function* () {
|
|
334
|
+
const api = mkApi({
|
|
335
|
+
databaseId: cmsId,
|
|
336
|
+
databaseToken: cmsPublicToken,
|
|
337
|
+
host: getCmsHost(),
|
|
338
|
+
useDraft
|
|
339
|
+
});
|
|
340
|
+
return api.count(tableId, params);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
function registerAllCmsFunctions(loader) {
|
|
344
|
+
function _registerFunction(fn, meta) {
|
|
345
|
+
if (loader) {
|
|
346
|
+
loader.registerFunction(fn, meta);
|
|
347
|
+
} else {
|
|
348
|
+
(0, import_registerFunction.default)(fn, meta);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
_registerFunction(fetchTables, {
|
|
352
|
+
name: "fetchTables",
|
|
353
|
+
namespace: "plasmicCms",
|
|
354
|
+
displayName: "Fetch Plasmic CMS Tables",
|
|
355
|
+
description: "Fetches table metadata from Plasmic CMS",
|
|
356
|
+
importPath: "@plasmicpkgs/cms",
|
|
357
|
+
params: [cmsIdParam, cmsPublicTokenParam]
|
|
358
|
+
});
|
|
359
|
+
_registerFunction(fetchContent, {
|
|
360
|
+
name: "fetchContent",
|
|
361
|
+
namespace: "plasmicCms",
|
|
362
|
+
displayName: "Fetch Plasmic CMS Content",
|
|
363
|
+
description: "Fetch content from a Plasmic CMS table",
|
|
364
|
+
importPath: "@plasmicpkgs/cms",
|
|
365
|
+
params: [
|
|
366
|
+
cmsIdParam,
|
|
367
|
+
cmsPublicTokenParam,
|
|
368
|
+
tableIdParam,
|
|
369
|
+
paramsParam,
|
|
370
|
+
useDraftParam,
|
|
371
|
+
localeParam
|
|
372
|
+
],
|
|
373
|
+
fnContext: sharedTableFnContext
|
|
374
|
+
});
|
|
375
|
+
_registerFunction(fetchCount, {
|
|
376
|
+
name: "fetchCount",
|
|
377
|
+
namespace: "plasmicCms",
|
|
378
|
+
displayName: "Fetch Plasmic CMS Count",
|
|
379
|
+
description: "Fetch the count of entries from a Plasmic CMS table",
|
|
380
|
+
importPath: "@plasmicpkgs/cms",
|
|
381
|
+
params: [
|
|
382
|
+
cmsIdParam,
|
|
383
|
+
cmsPublicTokenParam,
|
|
384
|
+
tableIdParam,
|
|
385
|
+
paramsParam,
|
|
386
|
+
useDraftParam
|
|
387
|
+
],
|
|
388
|
+
fnContext: sharedTableFnContext
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/api.ts", "../src/constants.ts", "../src/schema.ts", "../src/util.ts"],
|
|
4
|
+
"sourcesContent": ["import registerFunction, {\n CustomFunctionMeta,\n} from \"@plasmicapp/host/registerFunction\";\n\nimport { QueryParams, mkApi } from \"./api\";\nimport { DEFAULT_HOST } from \"./constants\";\n\nfunction getCmsHost() {\n return (globalThis as any)[\"__PLASMIC_CMS_HOST__\"] ?? DEFAULT_HOST;\n}\n\nfunction createTableOptions(\n _args: unknown[],\n ctx: { tables: Array<{ identifier: string; name: string }> } | undefined\n): Array<{ value: string; label: string }> {\n if (!ctx?.tables) {\n return [];\n }\n return ctx.tables.map((table: { identifier: string; name: string }) => ({\n value: table.identifier,\n label: table.name,\n }));\n}\n\nconst sharedTableFnContext = (\n cmsId?: string,\n cmsPublicToken?: string,\n ..._args: unknown[]\n) => {\n if (!cmsId || !cmsPublicToken) {\n return {\n dataKey: \"\",\n fetcher: async () => ({ tables: [] }),\n };\n }\n return {\n dataKey: `cms_tables/${JSON.stringify({\n cmsId,\n cmsPublicToken,\n })}`,\n fetcher: async () => {\n const api = mkApi({\n databaseId: cmsId,\n databaseToken: cmsPublicToken,\n host: getCmsHost(),\n });\n const tables = await api.fetchTables();\n return { tables };\n },\n };\n};\n\n// TODO: Handle markdown in descriptions and link to https://docs.plasmic.app/learn/plasmic-cms-api-reference/#find-your-cms-ids-public-token-and-secret-token\nconst cmsIdParam = {\n name: \"cmsId\",\n type: \"string\",\n description: \"The cms ID\",\n} as const;\n\nconst cmsPublicTokenParam = {\n name: \"cmsPublicToken\",\n type: \"string\",\n description: \"The cms public token\",\n} as const;\n\nconst tableIdParam = {\n name: \"tableId\",\n type: \"choice\",\n options: createTableOptions,\n} as const;\n\n// TODO: Directly handle the inner params available options\nconst paramsParam = {\n name: \"params\",\n type: \"object\",\n description:\n \"The parameters to filter the content (e.g., for sorting, limit, offset, advanced queries)\",\n} as const;\n\nconst useDraftParam = {\n name: \"useDraft\",\n type: \"boolean\",\n description: \"Whether to use draft data. Defaults to false.\",\n} as const;\n\nconst localeParam = {\n name: \"locale\",\n type: \"string\",\n description: \"The locale to use. Defaults to empty string.\",\n} as const;\n\nexport async function fetchTables(cmsId: string, cmsPublicToken: string) {\n const api = mkApi({\n databaseId: cmsId,\n databaseToken: cmsPublicToken,\n host: getCmsHost(),\n });\n\n return api.fetchTables();\n}\n\nexport async function fetchContent(\n cmsId: string,\n cmsPublicToken: string,\n tableId: string,\n params: QueryParams,\n useDraft: boolean,\n locale: string\n) {\n const api = mkApi({\n databaseId: cmsId,\n databaseToken: cmsPublicToken,\n host: getCmsHost(),\n useDraft,\n locale,\n });\n\n return api.query(tableId, params);\n}\n\nexport async function fetchCount(\n cmsId: string,\n cmsPublicToken: string,\n tableId: string,\n params: QueryParams,\n useDraft: boolean\n) {\n const api = mkApi({\n databaseId: cmsId,\n databaseToken: cmsPublicToken,\n host: getCmsHost(),\n useDraft,\n });\n\n return api.count(tableId, params);\n}\n\nexport function registerAllCmsFunctions(loader?: { registerFunction: any }) {\n function _registerFunction<T extends (...args: any[]) => any>(\n fn: T,\n meta: CustomFunctionMeta<T>\n ) {\n if (loader) {\n loader.registerFunction(fn, meta);\n } else {\n registerFunction(fn, meta);\n }\n }\n\n _registerFunction(fetchTables, {\n name: \"fetchTables\",\n namespace: \"plasmicCms\",\n displayName: \"Fetch Plasmic CMS Tables\",\n description: \"Fetches table metadata from Plasmic CMS\",\n importPath: \"@plasmicpkgs/cms\",\n params: [cmsIdParam, cmsPublicTokenParam],\n });\n\n _registerFunction(fetchContent, {\n name: \"fetchContent\",\n namespace: \"plasmicCms\",\n displayName: \"Fetch Plasmic CMS Content\",\n description: \"Fetch content from a Plasmic CMS table\",\n importPath: \"@plasmicpkgs/cms\",\n params: [\n cmsIdParam,\n cmsPublicTokenParam,\n tableIdParam,\n paramsParam,\n useDraftParam,\n localeParam,\n ],\n fnContext: sharedTableFnContext,\n });\n\n _registerFunction(fetchCount, {\n name: \"fetchCount\",\n namespace: \"plasmicCms\",\n displayName: \"Fetch Plasmic CMS Count\",\n description: \"Fetch the count of entries from a Plasmic CMS table\",\n importPath: \"@plasmicpkgs/cms\",\n params: [\n cmsIdParam,\n cmsPublicTokenParam,\n tableIdParam,\n paramsParam,\n useDraftParam,\n ],\n fnContext: sharedTableFnContext,\n });\n}\n\n// Export utilities and types with underscore prefix\nexport { API as _API, HttpError as _HttpError, mkApi as _mkApi } from \"./api\";\n\nexport type {\n DatabaseConfig as _DatabaseConfig,\n QueryParams as _QueryParams,\n} from \"./api\";\n\nexport { DEFAULT_HOST as _DEFAULT_HOST } from \"./constants\";\n\nexport { CmsMetaType as _CmsMetaType } from \"./schema\";\nexport type {\n ApiCmsQuery as _ApiCmsQuery,\n ApiCmsRow as _ApiCmsRow,\n ApiCmsTable as _ApiCmsTable,\n} from \"./schema\";\n\nexport type {\n CmsBaseType as _CmsBaseType,\n CmsBoolean as _CmsBoolean,\n CmsDateTime as _CmsDateTime,\n CmsEnum as _CmsEnum,\n CmsFieldMeta as _CmsFieldMeta,\n CmsFile as _CmsFile,\n CmsImage as _CmsImage,\n CmsLongText as _CmsLongText,\n CmsNumber as _CmsNumber,\n CmsRef as _CmsRef,\n CmsRichText as _CmsRichText,\n CmsTableSchema as _CmsTableSchema,\n CmsText as _CmsText,\n CmsTextLike as _CmsTextLike,\n CmsType as _CmsType,\n} from \"./schema\";\n\nexport {\n mkFieldOptions as _mkFieldOptions,\n mkTableOptions as _mkTableOptions,\n} from \"./util\";\n", "import { ApiCmsQuery, ApiCmsRow, ApiCmsTable } from \"./schema\";\n\nexport interface DatabaseConfig {\n host: string;\n databaseId: string;\n databaseToken: string;\n locale?: string;\n useDraft?: boolean | string[];\n}\n\nexport interface QueryParams {\n useDraft?: boolean;\n where?: any;\n orderBy?: string;\n desc?: boolean;\n limit?: number;\n offset?: number;\n fields?: string[];\n}\n\nfunction queryParamsToApi(params: QueryParams): ApiCmsQuery {\n return {\n where: params.where,\n limit: params.limit,\n offset: params.offset,\n order: params.orderBy\n ? [\n {\n field: params.orderBy,\n dir: params.desc ? \"desc\" : \"asc\",\n },\n ]\n : undefined,\n fields: params.fields,\n };\n}\n\nexport class HttpError extends Error {\n constructor(public status: number, message: string) {\n super(message);\n }\n}\n\nexport class API {\n constructor(private config: DatabaseConfig) {}\n\n async get(endpoint: string, params: any = {}) {\n const url = new URL(\n `${this.config.host}/api/v1/cms/databases/${this.config.databaseId}${endpoint}`\n );\n const fixedParams = Object.keys(params).reduce((newObj, key) => {\n const value = params[key];\n if (value != null) {\n newObj[key] = value;\n }\n return newObj;\n }, {} as any);\n url.search = new URLSearchParams(fixedParams).toString();\n const response = await fetch(url.toString(), {\n method: \"GET\",\n headers: {\n accept: \"*/*\",\n \"x-plasmic-api-cms-tokens\": `${this.config.databaseId}:${this.config.databaseToken}`,\n },\n mode: \"cors\",\n });\n\n if (response.status !== 200) {\n let message = await response.text();\n try {\n const json = JSON.parse(message);\n if (json.error?.message) {\n message = json.error.message;\n }\n } catch {\n // ignored\n }\n throw new HttpError(response.status, message);\n }\n\n return await response.json();\n }\n\n async fetchTables(): Promise<ApiCmsTable[]> {\n try {\n const response = await this.get(``);\n return response.tables;\n } catch (e) {\n console.error(e);\n throw e;\n }\n }\n\n private useDraftForTable(table: string) {\n if (Array.isArray(this.config.useDraft)) {\n return this.config.useDraft.includes(table);\n } else {\n return this.config.useDraft ?? false;\n }\n }\n\n async query(table: string, params: QueryParams = {}): Promise<ApiCmsRow[]> {\n try {\n const response = await this.get(`/tables/${table}/query`, {\n q: JSON.stringify(queryParamsToApi(params)),\n draft: Number(this.useDraftForTable(table) || params.useDraft),\n locale: this.config.locale,\n });\n return response.rows;\n } catch (e) {\n console.error(e);\n throw e;\n }\n }\n\n async count(\n table: string,\n params: Pick<QueryParams, \"where\" | \"useDraft\"> = {}\n ): Promise<number> {\n try {\n const response = await this.get(`/tables/${table}/count`, {\n q: JSON.stringify(queryParamsToApi(params)),\n draft: Number(this.useDraftForTable(table) || params.useDraft),\n });\n return response.count;\n } catch (e) {\n console.error(e);\n throw e;\n }\n }\n}\n\nexport function mkApi(config: DatabaseConfig | undefined) {\n if (!config) {\n throw new Error(\"Component must be wrapped in 'CMS Data Provider'.\");\n }\n\n return new API(config);\n}\n", "export const DEFAULT_HOST = \"https://data.plasmic.app\";\n", "// This should be kept in sync with wab/ApiSchema.\n\n// eslint-disable-next-line no-shadow\nexport enum CmsMetaType {\n TEXT = \"text\",\n LONG_TEXT = \"long-text\",\n NUMBER = \"number\",\n IMAGE = \"image\",\n FILE = \"file\",\n DATE_TIME = \"date-time\",\n BOOLEAN = \"boolean\",\n COLOR = \"color\",\n RICH_TEXT = \"rich-text\",\n REF = \"ref\",\n LIST = \"list\",\n OBJECT = \"object\",\n ENUM = \"enum\",\n}\n\nexport interface CmsBaseType {\n identifier: string;\n name: string;\n helperText: string;\n required: boolean;\n hidden: boolean;\n}\n\nexport interface CmsTextLike {\n defaultValue?: string;\n minChars?: number;\n maxChars?: number;\n}\n\nexport interface CmsText extends CmsBaseType, CmsTextLike {\n type: CmsMetaType.TEXT;\n}\n\nexport interface CmsLongText extends CmsBaseType, CmsTextLike {\n type: CmsMetaType.LONG_TEXT;\n}\n\nexport interface CmsNumber extends CmsBaseType {\n type: CmsMetaType.NUMBER;\n defaultValue?: number;\n}\n\nexport interface CmsBoolean extends CmsBaseType {\n type: CmsMetaType.BOOLEAN;\n defaultValue?: boolean;\n}\n\nexport interface CmsImage extends CmsBaseType {\n type: CmsMetaType.IMAGE;\n defaultValue?: string;\n}\n\nexport interface CmsDateTime extends CmsBaseType {\n type: CmsMetaType.DATE_TIME;\n defaultValue?: string;\n}\n\nexport interface CmsRichText extends CmsBaseType {\n type: CmsMetaType.RICH_TEXT;\n defaultValue?: string;\n}\n\nexport interface CmsFile extends CmsBaseType {\n type: CmsMetaType.FILE;\n defaultValue?: string;\n}\n\nexport interface CmsRef extends CmsBaseType {\n type: CmsMetaType.REF;\n defaultValue?: string;\n}\n\nexport interface CmsEnum extends CmsBaseType {\n type: CmsMetaType.ENUM;\n defaultValue?: string;\n options: string[];\n}\n\nexport type CmsFieldMeta =\n | CmsText\n | CmsLongText\n | CmsNumber\n | CmsBoolean\n | CmsImage\n | CmsFile\n | CmsDateTime\n | CmsRef\n | CmsRichText\n | CmsEnum;\n\nexport type CmsType = CmsFieldMeta[\"type\"];\n\nexport interface CmsTableSchema {\n fields: CmsFieldMeta[];\n}\n\nexport interface ApiCmsTable {\n identifier: string;\n name: string;\n schema: CmsTableSchema;\n}\n\nexport interface ApiCmsRow {\n identifier: string | null;\n data: Record<string, any> | null;\n}\n\ntype FilterClause = any;\n\nexport interface ApiCmsQuery {\n where?: FilterClause;\n limit?: number;\n offset?: number;\n order?: (string | { field: string; dir: \"asc\" | \"desc\" })[];\n fields?: string[];\n}\n", "import { ApiCmsTable, CmsType } from \"./schema\";\n\ntype ValueLabelPair = {\n value: string;\n label: string;\n};\n\nexport function mkTableOptions(\n tables: ApiCmsTable[] | undefined\n): ValueLabelPair[] {\n if (!tables) {\n return [];\n }\n\n return tables.map((table) => ({\n value: table.identifier,\n label: table.name,\n }));\n}\n\nexport function mkFieldOptions(\n tables: ApiCmsTable[] | undefined,\n tableIdentifier: string | undefined,\n types?: CmsType[]\n): ValueLabelPair[] {\n if (!tables) {\n return [];\n }\n\n const table = tables.find((t) => t.identifier === tableIdentifier);\n if (!table) {\n return [];\n }\n\n let fields = table.schema.fields;\n if (types) {\n fields = fields.filter((f) => types.includes(f.type));\n }\n const options = fields.map((f) => ({\n value: f.identifier,\n label: f.name || f.identifier,\n }));\n if (!options.some((option)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IAAI;AAAA,IAC3B;AAAA,EACF;AAEA,oBAAkB,aAAa;AAAA,IAC7B,MAAM;AAAA,IACN,WAAW;AAAA,IACX,aAAa;AAAA,IACb,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,QAAQ,CAAC,YAAY,mBAAmB;AAAA,EAC1C,CAAC;AAED,oBAAkB,cAAc;AAAA,IAC9B,MAAM;AAAA,IACN,WAAW;AAAA,IACX,aAAa;AAAA,IACb,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,QAAQ;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,WAAW;AAAA,EACb,CAAC;AAED,oBAAkB,YAAY;AAAA,IAC5B,MAAM;AAAA,IACN,WAAW;AAAA,IACX,aAAa;AAAA,IACb,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,QAAQ;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,WAAW;AAAA,EACb,CAAC;AACH;",
|
|
6
|
+
"names": ["CmsMetaType", "registerFunction"]
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plasmicpkgs/cms",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Plasmic CMS custom functions",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/plasmicapp/plasmic.git",
|
|
8
|
+
"directory": "plasmicpkgs/cms"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"module": "./dist/index.esm.js",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.esm.js",
|
|
20
|
+
"require": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "yarn build:types && yarn build:index",
|
|
28
|
+
"build:types": "yarn tsc",
|
|
29
|
+
"build:index": "node ../../build.mjs ./src/index.ts",
|
|
30
|
+
"prepublishOnly": "npm run build",
|
|
31
|
+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@plasmicapp/host": "1.0.227",
|
|
35
|
+
"@types/node": "^17.0.14"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@plasmicapp/host": "^1.0.211"
|
|
39
|
+
},
|
|
40
|
+
"gitHead": "321143c8400191ade22323400503db285443416b"
|
|
41
|
+
}
|