@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,412 @@
1
+ import { Effect, Schema } from "@withstudiocms/effect";
2
+ import {
3
+ StudioCMSEmailVerificationTokens,
4
+ StudioCMSOAuthAccounts,
5
+ StudioCMSPermissions,
6
+ StudioCMSSessionTable,
7
+ StudioCMSUsersTable
8
+ } from "@withstudiocms/kysely";
9
+ import { DBClientLive, SDKDefaults } from "../../context.js";
10
+ import {
11
+ AuthErrorTagsEntries
12
+ } from "../../types.js";
13
+ import { SDKGenerators } from "../util/generators.js";
14
+ const SDKAuthModule = Effect.gen(function* () {
15
+ const [{ withCodec, withEncoder }, { generateToken }, { GhostUserDefaults }] = yield* Effect.all([
16
+ DBClientLive,
17
+ SDKGenerators,
18
+ SDKDefaults
19
+ ]);
20
+ const _getVerificationToken = withCodec({
21
+ encoder: Schema.String,
22
+ decoder: Schema.UndefinedOr(StudioCMSEmailVerificationTokens.Select),
23
+ callbackFn: (db, id) => db(
24
+ (client) => client.selectFrom("StudioCMSEmailVerificationTokens").selectAll().where("id", "=", id).executeTakeFirst()
25
+ )
26
+ });
27
+ const _deleteVerificationToken = withEncoder({
28
+ encoder: Schema.String,
29
+ callbackFn: (db, id) => db(
30
+ (client) => client.deleteFrom("StudioCMSEmailVerificationTokens").where("userId", "=", id).executeTakeFirst()
31
+ )
32
+ });
33
+ const _insertVerificationToken = withCodec({
34
+ encoder: StudioCMSEmailVerificationTokens.Insert,
35
+ decoder: StudioCMSEmailVerificationTokens.Select,
36
+ callbackFn: (db, data) => db(
37
+ (client) => client.insertInto("StudioCMSEmailVerificationTokens").values(data).returningAll().executeTakeFirstOrThrow()
38
+ )
39
+ });
40
+ const _createNewOAuthAccount = withCodec({
41
+ encoder: StudioCMSOAuthAccounts.Insert,
42
+ decoder: StudioCMSOAuthAccounts.Select,
43
+ callbackFn: (db, data) => db(
44
+ (client) => client.insertInto("StudioCMSOAuthAccounts").values(data).returningAll().executeTakeFirstOrThrow()
45
+ )
46
+ });
47
+ const _deleteOAuthUserAccount = withEncoder({
48
+ encoder: Schema.Struct({
49
+ userId: Schema.String,
50
+ provider: Schema.String
51
+ }),
52
+ callbackFn: (db, { userId, provider }) => db(
53
+ (client) => client.deleteFrom("StudioCMSOAuthAccounts").where((eb) => eb.and([eb("userId", "=", userId), eb("provider", "=", provider)])).executeTakeFirst()
54
+ )
55
+ });
56
+ const _searchOAuthAccountByProviderId = withCodec({
57
+ encoder: Schema.Struct({
58
+ providerUserId: Schema.String,
59
+ userId: Schema.String
60
+ }),
61
+ decoder: Schema.UndefinedOr(StudioCMSOAuthAccounts.Select),
62
+ callbackFn: (db, { providerUserId, userId }) => db(
63
+ (client) => client.selectFrom("StudioCMSOAuthAccounts").selectAll().where(
64
+ (eb) => eb.and([eb("providerUserId", "=", providerUserId), eb("userId", "=", userId)])
65
+ ).executeTakeFirst()
66
+ )
67
+ });
68
+ const _searchOauthProvidersForId = withCodec({
69
+ encoder: Schema.Struct({
70
+ providerId: Schema.String,
71
+ userId: Schema.String
72
+ }),
73
+ decoder: Schema.UndefinedOr(StudioCMSOAuthAccounts.Select),
74
+ callbackFn: (db, { providerId, userId }) => db(
75
+ (client) => client.selectFrom("StudioCMSOAuthAccounts").selectAll().where((eb) => eb.and([eb("provider", "=", providerId), eb("userId", "=", userId)])).executeTakeFirst()
76
+ )
77
+ });
78
+ const _getCurrentPermission = withCodec({
79
+ encoder: Schema.String,
80
+ decoder: Schema.UndefinedOr(StudioCMSPermissions.Select),
81
+ callbackFn: (db, id) => db(
82
+ (client) => client.selectFrom("StudioCMSPermissions").selectAll().where("user", "=", id).executeTakeFirst()
83
+ )
84
+ });
85
+ const _createNewSession = withCodec({
86
+ encoder: StudioCMSSessionTable.Insert,
87
+ decoder: StudioCMSSessionTable.Select,
88
+ callbackFn: (db, data) => db(
89
+ (client) => client.insertInto("StudioCMSSessionTable").values(data).returningAll().executeTakeFirstOrThrow()
90
+ )
91
+ });
92
+ const _getUserById = withCodec({
93
+ encoder: Schema.String,
94
+ decoder: Schema.UndefinedOr(StudioCMSUsersTable.Select),
95
+ callbackFn: (db, id) => db(
96
+ (client) => client.selectFrom("StudioCMSUsersTable").selectAll().where("id", "=", id).executeTakeFirst()
97
+ )
98
+ });
99
+ const _getSessionById = withCodec({
100
+ encoder: Schema.String,
101
+ decoder: Schema.UndefinedOr(StudioCMSSessionTable.Select),
102
+ callbackFn: (db, id) => db(
103
+ (client) => client.selectFrom("StudioCMSSessionTable").selectAll().where("id", "=", id).executeTakeFirst()
104
+ )
105
+ });
106
+ const _deleteSession = withEncoder({
107
+ encoder: Schema.String,
108
+ callbackFn: (db, id) => db(
109
+ (client) => client.deleteFrom("StudioCMSSessionTable").where("id", "=", id).executeTakeFirst()
110
+ )
111
+ });
112
+ const _updateSession = withCodec({
113
+ encoder: Schema.Struct({
114
+ id: Schema.String,
115
+ newDate: Schema.Date
116
+ }),
117
+ decoder: StudioCMSSessionTable.Select,
118
+ callbackFn: (db, { id, newDate }) => db(
119
+ (client) => client.updateTable("StudioCMSSessionTable").set({ expiresAt: newDate }).where("id", "=", id).returningAll().executeTakeFirstOrThrow()
120
+ )
121
+ });
122
+ const _createNewUser = withCodec({
123
+ encoder: StudioCMSUsersTable.Insert,
124
+ decoder: StudioCMSUsersTable.Select,
125
+ callbackFn: (db, data) => db(
126
+ (client) => client.insertInto("StudioCMSUsersTable").values(data).returningAll().executeTakeFirstOrThrow()
127
+ )
128
+ });
129
+ const _createUserPermission = withCodec({
130
+ encoder: StudioCMSPermissions.Insert,
131
+ decoder: StudioCMSPermissions.Select,
132
+ callbackFn: (db, data) => db(
133
+ (client) => client.insertInto("StudioCMSPermissions").values(data).returningAll().executeTakeFirstOrThrow()
134
+ )
135
+ });
136
+ const _updateUserData = withCodec({
137
+ encoder: Schema.Struct({
138
+ userId: Schema.String,
139
+ userData: StudioCMSUsersTable.Update
140
+ }),
141
+ decoder: StudioCMSUsersTable.Select,
142
+ callbackFn: (db, { userId, userData }) => db(
143
+ (client) => client.updateTable("StudioCMSUsersTable").set(userData).where("id", "=", userId).returningAll().executeTakeFirstOrThrow()
144
+ )
145
+ });
146
+ const _searchForUsername = withCodec({
147
+ encoder: Schema.String,
148
+ decoder: Schema.Array(StudioCMSUsersTable.Select),
149
+ callbackFn: (db, username) => db(
150
+ (client) => client.selectFrom("StudioCMSUsersTable").selectAll().where("username", "=", username).execute()
151
+ )
152
+ });
153
+ const _searchForEmail = withCodec({
154
+ encoder: Schema.String,
155
+ decoder: Schema.Array(StudioCMSUsersTable.Select),
156
+ callbackFn: (db, email) => db(
157
+ (client) => client.selectFrom("StudioCMSUsersTable").selectAll().where("email", "=", email).execute()
158
+ )
159
+ });
160
+ const _pippedInsertToken = (userId) => Effect.fn(
161
+ (token) => _insertVerificationToken({
162
+ id: crypto.randomUUID(),
163
+ userId,
164
+ token,
165
+ expiresAt: new Date(Date.now() + 1e3 * 60 * 60 * 24).toISOString()
166
+ })
167
+ );
168
+ const _createVerificationToken = Effect.fn(
169
+ (userId) => generateToken(userId).pipe(
170
+ Effect.tap(() => _deleteVerificationToken(userId)),
171
+ Effect.flatMap(_pippedInsertToken(userId))
172
+ )
173
+ );
174
+ const _getSessionWithUserById = Effect.fn(function* (sessionId) {
175
+ const session2 = yield* _getSessionById(sessionId);
176
+ if (!session2) return void 0;
177
+ const user2 = yield* _getUserById(session2.userId);
178
+ if (!user2) return void 0;
179
+ return {
180
+ session: session2,
181
+ user: user2
182
+ };
183
+ });
184
+ const _createNewUserWithPermission = Effect.fn(
185
+ (userData, rank) => _createNewUser(userData).pipe(
186
+ Effect.tap(
187
+ ({ id: user2 }) => _createUserPermission({
188
+ user: user2,
189
+ rank
190
+ })
191
+ )
192
+ )
193
+ );
194
+ const _searchForUsernameOrEmail = Effect.fn(function* (username, email) {
195
+ const usernameSearch = [];
196
+ const emailSearch = [];
197
+ if (username) {
198
+ const results = yield* _searchForUsername(username);
199
+ usernameSearch.push(...results);
200
+ }
201
+ if (email) {
202
+ const results = yield* _searchForEmail(email);
203
+ emailSearch.push(...results);
204
+ }
205
+ return { usernameSearch, emailSearch };
206
+ });
207
+ const _verifyGhostUserExists = Effect.fn(
208
+ () => _getUserById(GhostUserDefaults.id).pipe(Effect.map((user2) => !!user2))
209
+ );
210
+ const _createGhostUser = Effect.fn(
211
+ () => _getUserById(GhostUserDefaults.id).pipe(
212
+ Effect.flatMap(
213
+ (user2) => user2 ? Effect.succeed(user2) : _createNewUser({
214
+ ...GhostUserDefaults,
215
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
216
+ emailVerified: false
217
+ })
218
+ )
219
+ )
220
+ );
221
+ const _getGhostUser = Effect.fn(
222
+ () => _getUserById(GhostUserDefaults.id).pipe(
223
+ Effect.flatMap((user2) => user2 ? Effect.succeed(user2) : _createGhostUser())
224
+ )
225
+ );
226
+ const _CatchErrs = (capt) => Effect.catchTags(
227
+ AuthErrorTagsEntries.reduce(
228
+ (acc, tag) => {
229
+ acc[tag] = () => Effect.succeed({
230
+ status: "error",
231
+ message: `An error occurred while deleting ${capt}`
232
+ });
233
+ return acc;
234
+ },
235
+ {}
236
+ )
237
+ );
238
+ const verifyEmail = {
239
+ /**
240
+ * Retrieves an email verification token by its ID.
241
+ *
242
+ * @param id - The ID of the email verification token to retrieve.
243
+ * @returns A promise that resolves to the email verification token if found, otherwise undefined.
244
+ */
245
+ get: _getVerificationToken,
246
+ /**
247
+ * Creates a new email verification token in the database.
248
+ *
249
+ * @param userId - The ID of the user to create the token for.
250
+ * @returns A promise that resolves to the created email verification token.
251
+ */
252
+ create: _createVerificationToken,
253
+ /**
254
+ * Deletes an email verification token from the database.
255
+ *
256
+ * @param userId - The ID of the user associated with the token.
257
+ * @returns A promise that resolves to the deletion response.
258
+ */
259
+ delete: _deleteVerificationToken
260
+ };
261
+ const oAuth = {
262
+ /**
263
+ * Creates a new OAuth account in the database.
264
+ *
265
+ * @param input - The OAuth account data to create.
266
+ * @returns A promise that resolves to the created OAuth account.
267
+ */
268
+ create: _createNewOAuthAccount,
269
+ /**
270
+ * Deletes an OAuth user account from the database.
271
+ *
272
+ * @param input - An object containing the userId and provider of the OAuth account to delete.
273
+ * @returns A promise that resolves to a status and message indicating the result of the deletion.
274
+ */
275
+ delete: (input) => _deleteOAuthUserAccount(input).pipe(
276
+ Effect.flatMap(
277
+ () => Effect.succeed({
278
+ status: "success",
279
+ message: "OAuth account deleted successfully"
280
+ })
281
+ ),
282
+ _CatchErrs("OAuth account")
283
+ ),
284
+ /**
285
+ * Searches for an OAuth account by provider user ID and user ID.
286
+ *
287
+ * @param input - An object containing the providerUserId and userId to search for.
288
+ * @returns A promise that resolves to the found OAuth account if it exists, otherwise undefined.
289
+ */
290
+ searchByProviderId: _searchOAuthAccountByProviderId,
291
+ /**
292
+ * Searches for OAuth providers for a given user ID.
293
+ *
294
+ * @param input - An object containing the providerId and userId to search for.
295
+ * @returns A promise that resolves to the found OAuth account if it exists, otherwise undefined.
296
+ */
297
+ searchProvidersForId: _searchOauthProvidersForId
298
+ };
299
+ const permission = {
300
+ /**
301
+ * Retrieves the current permission for a user by their ID.
302
+ *
303
+ * @param id - The ID of the user whose permission is to be retrieved.
304
+ * @returns A promise that resolves to the user's permission if found, otherwise undefined.
305
+ */
306
+ currentStatus: _getCurrentPermission
307
+ };
308
+ const session = {
309
+ /**
310
+ * Creates a new session for a user.
311
+ *
312
+ * @param data - The session data to create.
313
+ * @returns A promise that resolves to the created session.
314
+ */
315
+ create: _createNewSession,
316
+ /**
317
+ * Retrieves a user's Session by its ID.
318
+ *
319
+ * @param id - The ID of the session to retrieve.
320
+ * @returns A promise that resolves to the session if found, otherwise undefined.
321
+ */
322
+ getById: _getSessionById,
323
+ /**
324
+ * Retrieves a session along with its associated user by session ID.
325
+ *
326
+ * @param sessionId - The ID of the session to retrieve.
327
+ * @returns A promise that resolves to an object containing the session and user if found, otherwise undefined.
328
+ */
329
+ sessionWithUser: _getSessionWithUserById,
330
+ /**
331
+ * Deletes a session by its ID.
332
+ *
333
+ * @param input - The ID of the session to delete.
334
+ * @returns A promise that resolves to a status and message indicating the result of the deletion.
335
+ */
336
+ delete: (input) => _deleteSession(input).pipe(
337
+ Effect.flatMap(
338
+ () => Effect.succeed({ status: "success", message: "Session deleted successfully" })
339
+ ),
340
+ _CatchErrs("Session")
341
+ ),
342
+ /**
343
+ * Updates a session's expiration date.
344
+ *
345
+ * @param input - An object containing the session ID and the new expiration date.
346
+ * @returns A promise that resolves to the updated session.
347
+ */
348
+ update: _updateSession
349
+ };
350
+ const user = {
351
+ /**
352
+ * Creates a new user with the specified permissions.
353
+ *
354
+ * @param userData - The data for the new user.
355
+ * @param rank - The permission rank for the new user.
356
+ * @returns A promise that resolves to the created user.
357
+ */
358
+ create: _createNewUserWithPermission,
359
+ /**
360
+ * Updates user data for a specified user.
361
+ *
362
+ * @param input - An object containing the userId and the userData to update.
363
+ * @returns A promise that resolves to the updated user.
364
+ */
365
+ update: _updateUserData,
366
+ /**
367
+ * Searches for users by username.
368
+ *
369
+ * @param username - The username to search for.
370
+ * @param email - The email to search for.
371
+ * @returns A promise that resolves to an array of users matching the username.
372
+ */
373
+ searchUsersForUsernameOrEmail: _searchForUsernameOrEmail,
374
+ /**
375
+ * Verifies the existence of the ghost user.
376
+ *
377
+ * @returns A promise that resolves to true if the ghost user exists, otherwise false.
378
+ */
379
+ ghost: {
380
+ /**
381
+ * Verifies the existence of the ghost user.
382
+ *
383
+ * @returns A promise that resolves to true if the ghost user exists, otherwise false.
384
+ */
385
+ verifyExists: _verifyGhostUserExists,
386
+ /**
387
+ * Creates the ghost user if it does not already exist.
388
+ *
389
+ * @returns A promise that resolves to the ghost user.
390
+ */
391
+ create: _createGhostUser,
392
+ /**
393
+ * Retrieves the ghost user.
394
+ *
395
+ * @returns A promise that resolves to the ghost user.
396
+ */
397
+ get: _getGhostUser
398
+ }
399
+ };
400
+ return {
401
+ verifyEmail,
402
+ oAuth,
403
+ permission,
404
+ session,
405
+ user
406
+ };
407
+ });
408
+ var auth_default = SDKAuthModule;
409
+ export {
410
+ SDKAuthModule,
411
+ auth_default as default
412
+ };
@@ -0,0 +1,72 @@
1
+ import { Effect } from '@withstudiocms/effect';
2
+ import CacheService from '../../cache.js';
3
+ /**
4
+ * Effect that provides a collection of cache-clearing helpers for the SDK.
5
+ *
6
+ * This generator yields the CacheService and returns a CLEAR object containing effects and effect-creating
7
+ * functions to delete individual cache entries or invalidate groups of cache tags used across the system.
8
+ *
9
+ * Returned CLEAR shape:
10
+ * - page.byId(id: string): Effect<void>
11
+ * Deletes a single cached page entry by its ID (uses cacheKeyGetters.page and CacheService.delete).
12
+ *
13
+ * - pages: Effect<void>
14
+ * Invalidates tags related to pages, page folder trees, folder trees and folder lists.
15
+ *
16
+ * - latestVersion: Effect<void>
17
+ * Invalidates tags for NPM package metadata (e.g. cached latest package versions).
18
+ *
19
+ * - folderTree: Effect<void>
20
+ * Invalidates folder tree and page folder tree tags.
21
+ *
22
+ * - folderList: Effect<void>
23
+ * Invalidates the folder list tags.
24
+ *
25
+ * Remarks:
26
+ * - Each member is an Effect (or a function returning an Effect) that resolves when the cache operation completes.
27
+ * - The module internally depends on CacheService as well as cacheKeyGetters and cacheTags.
28
+ *
29
+ * @returns An Effect that resolves to an object exposing the described cache-clearing helpers.
30
+ *
31
+ * @example
32
+ * // within an Effect.gen or other Effect context:
33
+ * const CLEAR = yield* SDKClearModule;
34
+ * yield* CLEAR.page.byId("some-page-id");
35
+ * yield* CLEAR.pages;
36
+ */
37
+ export declare const SDKClearModule: Effect.Effect<{
38
+ /**
39
+ * Clears a cached page by its ID.
40
+ * @param id - The ID of the page to clear from the cache.
41
+ * @returns An Effect that resolves when the operation is complete.
42
+ */
43
+ page: {
44
+ /**
45
+ * Clears a cached page by its ID.
46
+ * @param id - The ID of the page to clear from the cache.
47
+ * @returns An Effect that resolves when the operation is complete.
48
+ */
49
+ byId: (id: string) => Effect.Effect<void, never, never>;
50
+ };
51
+ /**
52
+ * Clears cached data related to various entities.
53
+ * @returns An Effect that resolves when the operation is complete.
54
+ */
55
+ pages: Effect.Effect<void, never, never>;
56
+ /**
57
+ * Clears cached data related to the latest NPM package versions.
58
+ * @returns An Effect that resolves when the operation is complete.
59
+ */
60
+ latestVersion: Effect.Effect<void, never, never>;
61
+ /**
62
+ * Clears cached folder trees and page folder trees.
63
+ * @returns An Effect that resolves when the operation is complete.
64
+ */
65
+ folderTree: Effect.Effect<void, never, never>;
66
+ /**
67
+ * Clears the cached folder list.
68
+ * @returns An Effect that resolves when the operation is complete.
69
+ */
70
+ folderList: Effect.Effect<void, never, never>;
71
+ }, never, CacheService>;
72
+ export default SDKClearModule;
@@ -0,0 +1,52 @@
1
+ import { Effect } from "@withstudiocms/effect";
2
+ import CacheService from "../../cache.js";
3
+ import { cacheKeyGetters, cacheTags } from "../../consts.js";
4
+ const SDKClearModule = Effect.gen(function* () {
5
+ const { invalidateTags, delete: deleteEntry } = yield* CacheService;
6
+ const CLEAR = {
7
+ /**
8
+ * Clears a cached page by its ID.
9
+ * @param id - The ID of the page to clear from the cache.
10
+ * @returns An Effect that resolves when the operation is complete.
11
+ */
12
+ page: {
13
+ /**
14
+ * Clears a cached page by its ID.
15
+ * @param id - The ID of the page to clear from the cache.
16
+ * @returns An Effect that resolves when the operation is complete.
17
+ */
18
+ byId: Effect.fn((id) => deleteEntry(cacheKeyGetters.page(id)))
19
+ },
20
+ /**
21
+ * Clears cached data related to various entities.
22
+ * @returns An Effect that resolves when the operation is complete.
23
+ */
24
+ pages: invalidateTags([
25
+ ...cacheTags.pages,
26
+ ...cacheTags.pageFolderTree,
27
+ ...cacheTags.folderTree,
28
+ ...cacheTags.folderList
29
+ ]),
30
+ /**
31
+ * Clears cached data related to the latest NPM package versions.
32
+ * @returns An Effect that resolves when the operation is complete.
33
+ */
34
+ latestVersion: invalidateTags(cacheTags.npmPackage),
35
+ /**
36
+ * Clears cached folder trees and page folder trees.
37
+ * @returns An Effect that resolves when the operation is complete.
38
+ */
39
+ folderTree: invalidateTags([...cacheTags.folderTree, ...cacheTags.pageFolderTree]),
40
+ /**
41
+ * Clears the cached folder list.
42
+ * @returns An Effect that resolves when the operation is complete.
43
+ */
44
+ folderList: invalidateTags(cacheTags.folderList)
45
+ };
46
+ return CLEAR;
47
+ });
48
+ var clear_default = SDKClearModule;
49
+ export {
50
+ SDKClearModule,
51
+ clear_default as default
52
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Constants for configuration entries.
3
+ */
4
+ export declare const SiteConfigId: string;
5
+ /**
6
+ * Version of the site configuration.
7
+ */
8
+ export declare const SiteConfigVersion = "1.0.0";
9
+ /**
10
+ * Constants for mailer configuration entries.
11
+ */
12
+ export declare const MailerConfigId: string;
13
+ /**
14
+ * Version of the mailer configuration.
15
+ */
16
+ export declare const MailerConfigVersion = "1.0.0";
17
+ /**
18
+ * Constants for notification settings configuration entries.
19
+ */
20
+ export declare const NotificationSettingsId: string;
21
+ /**
22
+ * Version of the notification settings configuration.
23
+ */
24
+ export declare const NotificationSettingsVersion = "1.0.0";
25
+ /**
26
+ * Constants for template configuration entries.
27
+ */
28
+ export declare const TemplateConfigId: string;
29
+ /**
30
+ * Version of the template configuration.
31
+ */
32
+ export declare const TemplateConfigVersion = "1.0.0";
@@ -0,0 +1,18 @@
1
+ const SiteConfigId = "SCMS_SITE_CONFIG_1";
2
+ const SiteConfigVersion = "1.0.0";
3
+ const MailerConfigId = "SCMS_MAILER_CONFIG_1";
4
+ const MailerConfigVersion = "1.0.0";
5
+ const NotificationSettingsId = "SCMS_NOTIFICATION_SETTINGS_1";
6
+ const NotificationSettingsVersion = "1.0.0";
7
+ const TemplateConfigId = "SCMS_EMAIL_TEMPLATES_1";
8
+ const TemplateConfigVersion = "1.0.0";
9
+ export {
10
+ MailerConfigId,
11
+ MailerConfigVersion,
12
+ NotificationSettingsId,
13
+ NotificationSettingsVersion,
14
+ SiteConfigId,
15
+ SiteConfigVersion,
16
+ TemplateConfigId,
17
+ TemplateConfigVersion
18
+ };
@@ -0,0 +1,100 @@
1
+ import { Deepmerge, Effect } from '@withstudiocms/effect';
2
+ import type { DBCallbackFailure } from '@withstudiocms/kysely';
3
+ import type { DatabaseError } from '@withstudiocms/kysely/core/errors';
4
+ import { CacheService } from '../../cache.js';
5
+ import { DBClientLive } from '../../context.js';
6
+ import type { ConfigFinal, DynamicConfigEntry, StudioCMSMailerConfig, StudioCMSNotificationSettings, StudioCMSSiteConfig, StudioCMSTemplateConfig } from '../../types.js';
7
+ /**
8
+ * StudioCMS Configuration Modules
9
+ */
10
+ export declare const SDKConfigModule: Effect.Effect<{
11
+ siteConfig: {
12
+ /**
13
+ * Retrieves the site configuration.
14
+ *
15
+ * @returns An effect that yields the site configuration entry or undefined if not found, or a database error.
16
+ */
17
+ get: () => Effect.Effect<DynamicConfigEntry<StudioCMSSiteConfig> | undefined, DBCallbackFailure | DatabaseError, never>;
18
+ /**
19
+ * Updates the site configuration.
20
+ *
21
+ * @param data - The new site configuration data to store.
22
+ * @returns An effect that yields the updated site configuration entry or a database error.
23
+ */
24
+ update: (data: ConfigFinal<StudioCMSSiteConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSSiteConfig>, DBCallbackFailure | DatabaseError, never>;
25
+ /**
26
+ * Initializes the site configuration.
27
+ *
28
+ * @param data - The site configuration data to store.
29
+ * @returns An effect that yields the created site configuration entry or a database error.
30
+ */
31
+ init: (data: ConfigFinal<StudioCMSSiteConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSSiteConfig>, DBCallbackFailure | DatabaseError, never>;
32
+ };
33
+ mailerConfig: {
34
+ /**
35
+ * Retrieves the mailer configuration.
36
+ *
37
+ * @returns An effect that yields the mailer configuration entry or undefined if not found, or a database error.
38
+ */
39
+ get: () => Effect.Effect<DynamicConfigEntry<StudioCMSMailerConfig> | undefined, DBCallbackFailure | DatabaseError, never>;
40
+ /**
41
+ * Updates the mailer configuration.
42
+ *
43
+ * @param data - The new mailer configuration data to store.
44
+ * @returns An effect that yields the updated mailer configuration entry or a database error.
45
+ */
46
+ update: (data: ConfigFinal<StudioCMSMailerConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSMailerConfig>, DBCallbackFailure | DatabaseError, never>;
47
+ /**
48
+ * Initializes the mailer configuration.
49
+ *
50
+ * @param data - The mailer configuration data to store.
51
+ * @returns An effect that yields the created mailer configuration entry or a database error.
52
+ */
53
+ init: (data: ConfigFinal<StudioCMSMailerConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSMailerConfig>, DBCallbackFailure | DatabaseError, never>;
54
+ };
55
+ notificationConfig: {
56
+ /**
57
+ * Retrieves the notification settings configuration.
58
+ *
59
+ * @returns An effect that yields the notification settings configuration entry or undefined if not found, or a database error.
60
+ */
61
+ get: () => Effect.Effect<DynamicConfigEntry<StudioCMSNotificationSettings> | undefined, DBCallbackFailure | DatabaseError, never>;
62
+ /**
63
+ * Updates the notification settings configuration.
64
+ *
65
+ * @param data - The new notification settings configuration data to store.
66
+ * @returns An effect that yields the updated notification settings configuration entry or a database error.
67
+ */
68
+ update: (data: ConfigFinal<StudioCMSNotificationSettings>) => Effect.Effect<DynamicConfigEntry<StudioCMSNotificationSettings>, DBCallbackFailure | DatabaseError, never>;
69
+ /**
70
+ * Initializes the notification settings configuration.
71
+ *
72
+ * @param data - The notification settings configuration data to store.
73
+ * @returns An effect that yields the created notification settings configuration entry or a database error.
74
+ */
75
+ init: (data: ConfigFinal<StudioCMSNotificationSettings>) => Effect.Effect<DynamicConfigEntry<StudioCMSNotificationSettings>, DBCallbackFailure | DatabaseError, never>;
76
+ };
77
+ templateConfig: {
78
+ /**
79
+ * Retrieves the template configuration.
80
+ *
81
+ * @returns An effect that yields the template configuration entry or undefined if not found, or a database error.
82
+ */
83
+ get: () => Effect.Effect<DynamicConfigEntry<StudioCMSTemplateConfig> | undefined, DBCallbackFailure | DatabaseError, never>;
84
+ /**
85
+ * Updates the template configuration by merging with existing data.
86
+ *
87
+ * @param data - The new template configuration data to merge and store.
88
+ * @returns An effect that yields the updated template configuration entry or a database error.
89
+ */
90
+ update: (data: ConfigFinal<StudioCMSTemplateConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSTemplateConfig>, Error, never>;
91
+ /**
92
+ * Initializes the template configuration.
93
+ *
94
+ * @param data - The template configuration data to store.
95
+ * @returns An effect that yields the created template configuration entry or a database error.
96
+ */
97
+ init: (data: ConfigFinal<StudioCMSTemplateConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSTemplateConfig>, DBCallbackFailure | DatabaseError, never>;
98
+ };
99
+ }, never, DBClientLive | CacheService | Deepmerge>;
100
+ export default SDKConfigModule;