@withstudiocms/sdk 0.0.0-beta.0 → 0.1.0-beta.1

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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -0
  3. package/dist/cache.d.ts +109 -0
  4. package/dist/cache.js +94 -0
  5. package/dist/consts.d.ts +28 -0
  6. package/dist/consts.js +26 -0
  7. package/dist/context.d.ts +188 -0
  8. package/dist/context.js +33 -0
  9. package/dist/index.d.ts +1136 -0
  10. package/dist/index.js +24 -0
  11. package/dist/lib/diff.d.ts +39 -0
  12. package/dist/lib/diff.js +29 -0
  13. package/dist/lib/logger.d.ts +31 -0
  14. package/dist/lib/logger.js +131 -0
  15. package/dist/lib/pluginUtils.d.ts +221 -0
  16. package/dist/lib/pluginUtils.js +80 -0
  17. package/dist/modules/auth/index.d.ts +463 -0
  18. package/dist/modules/auth/index.js +412 -0
  19. package/dist/modules/clear/index.d.ts +72 -0
  20. package/dist/modules/clear/index.js +52 -0
  21. package/dist/modules/config/consts.d.ts +32 -0
  22. package/dist/modules/config/consts.js +18 -0
  23. package/dist/modules/config/index.d.ts +100 -0
  24. package/dist/modules/config/index.js +205 -0
  25. package/dist/modules/config/templates/mailer.d.ts +36 -0
  26. package/dist/modules/config/templates/mailer.js +218 -0
  27. package/dist/modules/config/type-utils.d.ts +13 -0
  28. package/dist/modules/config/type-utils.js +11 -0
  29. package/dist/modules/delete/index.d.ts +140 -0
  30. package/dist/modules/delete/index.js +274 -0
  31. package/dist/modules/diffTracking/index.d.ts +188 -0
  32. package/dist/modules/diffTracking/index.js +276 -0
  33. package/dist/modules/get/index.d.ts +272 -0
  34. package/dist/modules/get/index.js +466 -0
  35. package/dist/modules/index.d.ts +1003 -0
  36. package/dist/modules/index.js +37 -0
  37. package/dist/modules/init/index.d.ts +60 -0
  38. package/dist/modules/init/index.js +38 -0
  39. package/dist/modules/middleware/index.d.ts +56 -0
  40. package/dist/modules/middleware/index.js +50 -0
  41. package/dist/modules/notificationSettings/index.d.ts +57 -0
  42. package/dist/modules/notificationSettings/index.js +39 -0
  43. package/dist/modules/plugins/index.d.ts +166 -0
  44. package/dist/modules/plugins/index.js +261 -0
  45. package/dist/modules/post/index.d.ts +305 -0
  46. package/dist/modules/post/index.js +305 -0
  47. package/dist/modules/resetTokenBucket/index.d.ts +91 -0
  48. package/dist/modules/resetTokenBucket/index.js +93 -0
  49. package/dist/modules/rest_api/index.d.ts +92 -0
  50. package/dist/modules/rest_api/index.js +113 -0
  51. package/dist/modules/update/index.d.ts +184 -0
  52. package/dist/modules/update/index.js +174 -0
  53. package/dist/modules/util/collectors.d.ts +261 -0
  54. package/dist/modules/util/collectors.js +141 -0
  55. package/dist/modules/util/folderTree.d.ts +100 -0
  56. package/dist/modules/util/folderTree.js +176 -0
  57. package/dist/modules/util/generators.d.ts +83 -0
  58. package/dist/modules/util/generators.js +106 -0
  59. package/dist/modules/util/getFromNPM.d.ts +191 -0
  60. package/dist/modules/util/getFromNPM.js +100 -0
  61. package/dist/modules/util/index.d.ts +236 -0
  62. package/dist/modules/util/index.js +20 -0
  63. package/dist/modules/util/parsers.d.ts +60 -0
  64. package/dist/modules/util/parsers.js +43 -0
  65. package/dist/modules/util/slugify.d.ts +22 -0
  66. package/dist/modules/util/slugify.js +19 -0
  67. package/dist/modules/util/users.d.ts +99 -0
  68. package/dist/modules/util/users.js +78 -0
  69. package/dist/types.d.ts +360 -0
  70. package/dist/types.js +10 -0
  71. package/package.json +55 -7
@@ -0,0 +1,360 @@
1
+ import type { Effect } from '@withstudiocms/effect';
2
+ import type { DBCallbackFailure, OptionalNullable } from '@withstudiocms/kysely/core/client';
3
+ import type { DatabaseError } from '@withstudiocms/kysely/core/errors';
4
+ import type { StudioCMSAPIKeys, StudioCMSDiffTracking, StudioCMSDynamicConfigSettings, StudioCMSEmailVerificationTokens, StudioCMSOAuthAccounts, StudioCMSPageContent, StudioCMSPageData, StudioCMSPageDataCategories, StudioCMSPageDataTags, StudioCMSPageFolderStructure, StudioCMSPermissions, StudioCMSPluginData, StudioCMSSessionTable, StudioCMSUserResetTokens, StudioCMSUsersTable } from '@withstudiocms/kysely/tables';
5
+ export * from './lib/pluginUtils.js';
6
+ export type tsPageDataCategories = typeof StudioCMSPageDataCategories;
7
+ export type tsPageDataTags = typeof StudioCMSPageDataTags;
8
+ export type tsPageData = typeof StudioCMSPageData;
9
+ export type tsPageContent = typeof StudioCMSPageContent;
10
+ export type tsSiteConfig = typeof StudioCMSDynamicConfigSettings;
11
+ export type tsUsers = typeof StudioCMSUsersTable;
12
+ export type tsPageFolder = typeof StudioCMSPageFolderStructure;
13
+ export type tsAPIKeys = typeof StudioCMSAPIKeys;
14
+ export type tsDiffTracking = typeof StudioCMSDiffTracking;
15
+ export type tsEmailVerificationTokens = typeof StudioCMSEmailVerificationTokens;
16
+ export type tsOAuthAccounts = typeof StudioCMSOAuthAccounts;
17
+ export type tsPermissions = typeof StudioCMSPermissions;
18
+ export type tsPluginData = typeof StudioCMSPluginData;
19
+ export type tsSessionTable = typeof StudioCMSSessionTable;
20
+ export type tsUserResetTokens = typeof StudioCMSUserResetTokens;
21
+ export type tsPageDataCategoriesSelect = tsPageDataCategories['Select']['Type'];
22
+ export type tsPageDataTagsSelect = tsPageDataTags['Select']['Type'];
23
+ export type tsPageContentSelect = tsPageContent['Select']['Type'];
24
+ export type tsUsersSelect = tsUsers['Select']['Type'];
25
+ export type tsPageFolderSelect = tsPageFolder['Select']['Type'];
26
+ export type tsPageDataSelect = tsPageData['Select']['Type'];
27
+ export type tsOAuthAccountsSelect = tsOAuthAccounts['Select']['Type'];
28
+ export type tsPermissionsSelect = tsPermissions['Select']['Type'];
29
+ /**
30
+ * Represents a type that combines the properties of `tsPageContentInsert`
31
+ * excluding 'id' and 'contentId'.
32
+ *
33
+ * This type is useful when you need to insert content without specifying
34
+ * the 'id' and 'contentId' fields, which might be auto-generated or
35
+ * handled separately.
36
+ */
37
+ export type CombinedInsertContent = Omit<tsPageContentSelect, 'id' | 'contentId'>;
38
+ /**
39
+ * Interface representing combined user data.
40
+ *
41
+ * This interface extends `tsUsersSelect` and includes additional properties
42
+ * for OAuth data and permissions data.
43
+ *
44
+ * @interface CombinedUserData
45
+ * @extends {tsUsersSelect}
46
+ *
47
+ * @property {tsOAuthAccountsSelect[] | undefined} oAuthData - An array of OAuth account data or undefined.
48
+ * @property {tsPermissionsSelect | undefined} permissionsData - Permissions data or undefined.
49
+ */
50
+ export interface CombinedUserData extends tsUsersSelect {
51
+ oAuthData: tsOAuthAccountsSelect[] | undefined;
52
+ permissionsData: tsPermissionsSelect | undefined;
53
+ }
54
+ /**
55
+ * Represents a stripped-down version of the `tsPageDataSelect` type,
56
+ * excluding the properties 'categories', 'tags', and 'contributorIds'.
57
+ */
58
+ export type PageDataStripped = Omit<tsPageDataSelect, 'categories' | 'tags' | 'contributorIds'>;
59
+ /**
60
+ * Represents the combined data for a page, extending the stripped page data.
61
+ *
62
+ * @interface CombinedPageData
63
+ * @extends PageDataStripped
64
+ *
65
+ * @property {string[]} contributorIds - An array of contributor IDs associated with the page.
66
+ * @property {tsPageDataCategoriesSelect[]} categories - An array of categories selected for the page.
67
+ * @property {tsPageDataTagsSelect[]} tags - An array of tags selected for the page.
68
+ * @property {tsPageContentSelect[]} content - An array of content selected for the page.
69
+ */
70
+ export interface CombinedPageData extends PageDataStripped {
71
+ contributorIds: string[];
72
+ categories: tsPageDataCategoriesSelect[];
73
+ tags: tsPageDataTagsSelect[];
74
+ multiLangContent: tsPageContentSelect[];
75
+ defaultContent: tsPageContentSelect | undefined;
76
+ urlRoute: string;
77
+ authorData: tsUsersSelect | undefined;
78
+ contributorsData: tsUsersSelect[];
79
+ }
80
+ /**
81
+ * Represents page data containing only metadata fields, excluding multilingual and default content.
82
+ *
83
+ * This type omits the `multiLangContent` and `defaultContent` properties from `CombinedPageData`.
84
+ */
85
+ export type MetaOnlyPageData = Omit<CombinedPageData, 'multiLangContent' | 'defaultContent'>;
86
+ /**
87
+ * Conditional type that returns either `MetaOnlyPageData` or an array of `MetaOnlyPageData`
88
+ * based on whether the generic type `T` extends `CombinedPageData`.
89
+ *
90
+ * @template T - The type to check against `CombinedPageData`.
91
+ * @returns If `T` extends `CombinedPageData`, returns `MetaOnlyPageData`; otherwise, returns `MetaOnlyPageData[]`.
92
+ */
93
+ export type PageDataReturnType<T> = T extends CombinedPageData ? MetaOnlyPageData : MetaOnlyPageData[];
94
+ /**
95
+ * Represents a node in a folder structure, which may contain child nodes and page data.
96
+ *
97
+ * @property id - Unique identifier for the folder node.
98
+ * @property name - Name of the folder node.
99
+ * @property page - Indicates whether this node represents a page.
100
+ * @property pageData - Data associated with the page, or `null` if not applicable.
101
+ * @property children - Array of child folder nodes.
102
+ */
103
+ export interface FolderNode {
104
+ id: string;
105
+ name: string;
106
+ page: boolean;
107
+ pageData: CombinedPageData | null;
108
+ children: FolderNode[];
109
+ }
110
+ /**
111
+ * Represents a folder item in a list, including its unique identifier, name, and optional parent folder.
112
+ *
113
+ * @property id - The unique identifier for the folder.
114
+ * @property name - The display name of the folder.
115
+ * @property parent - The identifier of the parent folder, or `null` if the folder is at the root level.
116
+ */
117
+ export interface FolderListItem {
118
+ id: string;
119
+ name: string;
120
+ parent?: string | null;
121
+ }
122
+ /**
123
+ * Represents a database query function for retrieving dynamic configuration entries.
124
+ *
125
+ * This function takes an input object containing an optional nullable `id` string
126
+ * and returns an effect that yields a dynamic configuration entry with its `id`
127
+ * and `data` properties, or a `DatabaseError` if the operation fails.
128
+ *
129
+ * @param input - An object containing an optional nullable `id` string.
130
+ * @returns An effect that yields the dynamic configuration entry or a database error.
131
+ */
132
+ export type DbQueryFn = (input: OptionalNullable<{
133
+ readonly id: string;
134
+ readonly data: string;
135
+ }>) => Effect.Effect<{
136
+ readonly id: string;
137
+ readonly data: {
138
+ readonly [x: string]: unknown;
139
+ };
140
+ }, DBCallbackFailure | DatabaseError, never>;
141
+ /**
142
+ * Represents a dynamic configuration entry with a unique identifier and associated data.
143
+ *
144
+ * @template T - The type of the data stored in the configuration entry.
145
+ * @property id - A unique string identifier for the configuration entry.
146
+ * @property data - The configuration data of type T.
147
+ */
148
+ export type DynamicConfigEntry<T> = {
149
+ id: string;
150
+ data: T;
151
+ };
152
+ /**
153
+ * Base interface for dynamic configuration objects in StudioCMS.
154
+ *
155
+ * @property _config_version - The version identifier for the configuration schema.
156
+ */
157
+ export interface StudioCMSDynamicConfigBase {
158
+ _config_version: string;
159
+ }
160
+ /**
161
+ * A version of a dynamic StudioCMS configuration with the internal version field removed.
162
+ *
163
+ * This utility type produces a configuration type based on `T` (which must extend
164
+ * `StudioCMSDynamicConfigBase`) but omits the internal `_config_version` property.
165
+ * It is intended for use when exposing or working with the final, consumer-facing
166
+ * shape of configuration where the internal version metadata should not be present.
167
+ *
168
+ * @template T - The dynamic configuration type extending `StudioCMSDynamicConfigBase`.
169
+ *
170
+ * @remarks
171
+ * Preserves all other properties of `T`.
172
+ */
173
+ export type ConfigFinal<T extends StudioCMSDynamicConfigBase> = Omit<T, '_config_version'>;
174
+ /**
175
+ * Represents the site configuration type for StudioCMS.
176
+ *
177
+ * This interface extends the base dynamic configuration and includes various
178
+ * properties related to site settings such as description, title, images,
179
+ * mailer options, and more.
180
+ */
181
+ export interface StudioCMSSiteConfig extends StudioCMSDynamicConfigBase {
182
+ description: string;
183
+ title: string;
184
+ defaultOgImage?: string | null | undefined;
185
+ siteIcon?: string | null | undefined;
186
+ loginPageBackground?: string | undefined;
187
+ loginPageCustomImage?: string | null | undefined;
188
+ enableDiffs?: boolean | undefined;
189
+ diffPerPage?: number | undefined;
190
+ gridItems?: string[];
191
+ enableMailer?: boolean | undefined;
192
+ hideDefaultIndex?: boolean | undefined;
193
+ }
194
+ /**
195
+ * Represents the mailer configuration type for StudioCMS.
196
+ *
197
+ * This interface extends the base dynamic configuration and includes various
198
+ * properties related to mail server settings such as host, port, security,
199
+ * authentication, and default sender information.
200
+ */
201
+ export interface StudioCMSMailerConfig extends StudioCMSDynamicConfigBase {
202
+ host: string;
203
+ port: number;
204
+ secure: boolean;
205
+ proxy?: string | null | undefined;
206
+ auth_user?: string | null | undefined;
207
+ auth_pass?: string | null | undefined;
208
+ tls_rejectUnauthorized?: boolean | null | undefined;
209
+ tls_servername?: string | null | undefined;
210
+ default_sender: string;
211
+ }
212
+ /**
213
+ * Represents the notification settings configuration type for StudioCMS.
214
+ *
215
+ * This interface extends the base dynamic configuration and includes various
216
+ * boolean properties that determine the behavior of email verification and
217
+ * user verification requirements.
218
+ */
219
+ export interface StudioCMSNotificationSettings extends StudioCMSDynamicConfigBase {
220
+ emailVerification?: boolean | undefined;
221
+ requireAdminVerification?: boolean | undefined;
222
+ requireEditorVerification?: boolean | undefined;
223
+ oAuthBypassVerification?: boolean | undefined;
224
+ }
225
+ /**
226
+ * Represents the template configuration type for StudioCMS.
227
+ *
228
+ * This interface extends the base dynamic configuration and includes optional
229
+ * properties for various email templates used in notifications, password resets,
230
+ * user invitations, and email verification.
231
+ */
232
+ export interface StudioCMSTemplateConfig extends StudioCMSDynamicConfigBase {
233
+ notifications?: string;
234
+ passwordReset?: string;
235
+ userInvite?: string;
236
+ verifyEmail?: string;
237
+ }
238
+ /**
239
+ * JWT Header structure.
240
+ */
241
+ export type JwtHeader = {
242
+ alg: string;
243
+ typ: string;
244
+ };
245
+ /**
246
+ * JWT Payload structure.
247
+ */
248
+ export type JwtPayload = {
249
+ userId: string;
250
+ exp?: number;
251
+ iat?: number;
252
+ };
253
+ /**
254
+ * Represents the result of verifying a JWT (JSON Web Token).
255
+ *
256
+ * @property isValid - Indicates whether the JWT is valid.
257
+ * @property userId - The user ID extracted from the token, if available. This is optional and may be undefined if the token is invalid.
258
+ */
259
+ export interface JwtVerificationResult {
260
+ isValid: boolean;
261
+ userId?: string;
262
+ }
263
+ /**
264
+ * Represents a single difference item for a page, including metadata and content changes.
265
+ *
266
+ * @property id - Unique identifier for the diff item.
267
+ * @property userId - Identifier of the user who made the change.
268
+ * @property pageId - Identifier of the page associated with the diff.
269
+ * @property timestamp - The date and time when the diff was created, or null if not set.
270
+ * @property pageMetaData - Metadata associated with the page; type is unknown.
271
+ * @property pageContentStart - The initial content of the page before the diff.
272
+ * @property diff - The difference content as a string, or null if not available.
273
+ */
274
+ export interface diffItem {
275
+ id: string;
276
+ userId: string;
277
+ pageId: string;
278
+ timestamp: Date | null;
279
+ pageMetaData: unknown;
280
+ pageContentStart: string;
281
+ diff: string | null;
282
+ }
283
+ /**
284
+ * Represents the result of a diff operation, extending {@link diffItem} but replacing the `pageMetaData` property.
285
+ *
286
+ * @remarks
287
+ * The `pageMetaData` property contains the starting and ending states of page metadata,
288
+ * each represented as a partial selection of {@link tsPageDataSelect}.
289
+ *
290
+ * @see diffItem
291
+ * @see tsPageDataSelect
292
+ */
293
+ export interface diffReturn extends Omit<diffItem, 'pageMetaData'> {
294
+ pageMetaData: {
295
+ start: tsPageDataSelect;
296
+ end: tsPageDataSelect;
297
+ };
298
+ }
299
+ /**
300
+ * Determines the return type based on whether the generic type `T` extends `diffItem`.
301
+ * If `T` extends `diffItem`, returns `diffReturn`; otherwise, returns an array of `diffReturn`.
302
+ *
303
+ * @template T - The type to check against `diffItem`.
304
+ * @returns `diffReturn` if `T` extends `diffItem`, otherwise `diffReturn[]`.
305
+ */
306
+ export type DiffReturnType<T> = T extends diffItem ? diffReturn : diffReturn[];
307
+ /**
308
+ * Represents a single rank with an identifier and a name.
309
+ */
310
+ export interface SingleRank {
311
+ id: string;
312
+ name: string;
313
+ }
314
+ /**
315
+ * Represents a combined rank with associated details.
316
+ *
317
+ * @property {string} rank - The rank of the entity.
318
+ * @property {string} id - The unique identifier for the rank.
319
+ * @property {string} name - The name associated with the rank.
320
+ */
321
+ export interface CombinedRank extends SingleRank {
322
+ rank: string;
323
+ }
324
+ /**
325
+ * Represents the different types of user lists available in the system.
326
+ *
327
+ * - 'owners': List of owners.
328
+ * - 'admins': List of administrators.
329
+ * - 'editors': List of editors.
330
+ * - 'visitors': List of visitors.
331
+ * - 'all': List of all users.
332
+ */
333
+ export type AvailableLists = 'owners' | 'admins' | 'editors' | 'visitors' | 'all';
334
+ /**
335
+ * An array of authentication error tag entries.
336
+ */
337
+ export declare const AuthErrorTagsEntries: readonly ["DBCallbackFailure", "NotFoundError", "QueryError", "QueryParseError"];
338
+ /**
339
+ * Represents the different error tags that can occur during authentication operations.
340
+ */
341
+ export type AuthErrorTags = (typeof AuthErrorTagsEntries)[number];
342
+ /**
343
+ * Represents the data returned after an authentication deletion operation.
344
+ */
345
+ export type AuthDeletionData = {
346
+ status: 'success' | 'error';
347
+ message: string;
348
+ };
349
+ /**
350
+ * Represents the effect type for authentication deletion responses.
351
+ */
352
+ export type AuthDeletionResponse = Effect.Effect<AuthDeletionData, never, never>;
353
+ /**
354
+ * Represents a mapping of authentication error tags to their corresponding error handler functions.
355
+ *
356
+ * Each handler function returns an `AuthDeletionResponse`.
357
+ */
358
+ export type AuthErrorHandlers = {
359
+ [K in AuthErrorTags]: () => AuthDeletionResponse;
360
+ };
package/dist/types.js ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./lib/pluginUtils.js";
2
+ const AuthErrorTagsEntries = [
3
+ "DBCallbackFailure",
4
+ "NotFoundError",
5
+ "QueryError",
6
+ "QueryParseError"
7
+ ];
8
+ export {
9
+ AuthErrorTagsEntries
10
+ };
package/package.json CHANGED
@@ -1,14 +1,62 @@
1
1
  {
2
2
  "name": "@withstudiocms/sdk",
3
- "version": "0.0.0-beta.0",
4
- "description": "",
5
- "publishConfig": {
6
- "access": "public"
3
+ "version": "0.1.0-beta.1",
4
+ "description": "StudioCMS Database SDK",
5
+ "author": {
6
+ "name": "withstudiocms",
7
+ "url": "https://studiocms.dev"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/withstudiocms/studiocms.git",
12
+ "directory": "packages/@withstudiocms/sdk"
7
13
  },
8
- "keywords": [],
9
- "author": "",
14
+ "contributors": [
15
+ "Adammatthiesen",
16
+ "jdtjenkins",
17
+ "dreyfus92",
18
+ "code.spirit"
19
+ ],
10
20
  "license": "MIT",
21
+ "homepage": "https://studiocms.dev",
22
+ "publishConfig": {
23
+ "access": "public",
24
+ "provenance": true
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ },
34
+ "./context": {
35
+ "types": "./dist/context.d.ts",
36
+ "default": "./dist/context.js"
37
+ },
38
+ "./types": {
39
+ "types": "./dist/types.d.ts",
40
+ "default": "./dist/types.js"
41
+ },
42
+ "./*": "./dist/*"
43
+ },
44
+ "type": "module",
45
+ "dependencies": {
46
+ "diff": "^8.0.2",
47
+ "diff2html": "^3.4.52",
48
+ "zod": "^3.25.76"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^22.0.0"
52
+ },
53
+ "peerDependencies": {
54
+ "@withstudiocms/effect": "0.1.0-beta.7",
55
+ "@withstudiocms/kysely": "0.1.0-beta.1"
56
+ },
11
57
  "scripts": {
12
- "pre": "pnpm publish --tag beta"
58
+ "build": "pnpm buildkit build 'src/**/*.{ts,json}'",
59
+ "dev": "pnpm buildkit dev 'src/**/*.{ts,json}'",
60
+ "typecheck": "tspc -p tsconfig.tspc.json"
13
61
  }
14
62
  }