@withstudiocms/sdk 0.0.0-beta.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) 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 +37 -0
  6. package/dist/consts.js +35 -0
  7. package/dist/context.d.ts +208 -0
  8. package/dist/context.js +40 -0
  9. package/dist/errors.d.ts +9 -0
  10. package/dist/errors.js +6 -0
  11. package/dist/index.d.ts +1024 -0
  12. package/dist/index.js +24 -0
  13. package/dist/lib/diff.d.ts +39 -0
  14. package/dist/lib/diff.js +29 -0
  15. package/dist/lib/logger.d.ts +31 -0
  16. package/dist/lib/logger.js +131 -0
  17. package/dist/lib/pluginUtils.d.ts +222 -0
  18. package/dist/lib/pluginUtils.js +87 -0
  19. package/dist/lib/storage-manager.d.ts +10 -0
  20. package/dist/lib/storage-manager.js +17 -0
  21. package/dist/migrations/20251025T040912_init.d.ts +17 -0
  22. package/dist/migrations/20251025T040912_init.js +260 -0
  23. package/dist/migrations/20251130T150847_drop_deprecated.d.ts +13 -0
  24. package/dist/migrations/20251130T150847_drop_deprecated.js +262 -0
  25. package/dist/migrations/20251221T002125_url-mapping.d.ts +13 -0
  26. package/dist/migrations/20251221T002125_url-mapping.js +228 -0
  27. package/dist/migrator.d.ts +25 -0
  28. package/dist/migrator.js +21 -0
  29. package/dist/modules/auth/index.d.ts +419 -0
  30. package/dist/modules/auth/index.js +436 -0
  31. package/dist/modules/clear/index.d.ts +72 -0
  32. package/dist/modules/clear/index.js +52 -0
  33. package/dist/modules/config/consts.d.ts +32 -0
  34. package/dist/modules/config/consts.js +18 -0
  35. package/dist/modules/config/index.d.ts +100 -0
  36. package/dist/modules/config/index.js +224 -0
  37. package/dist/modules/config/templates/mailer.d.ts +36 -0
  38. package/dist/modules/config/templates/mailer.js +218 -0
  39. package/dist/modules/config/type-utils.d.ts +13 -0
  40. package/dist/modules/config/type-utils.js +11 -0
  41. package/dist/modules/delete/index.d.ts +141 -0
  42. package/dist/modules/delete/index.js +279 -0
  43. package/dist/modules/diffTracking/index.d.ts +188 -0
  44. package/dist/modules/diffTracking/index.js +277 -0
  45. package/dist/modules/get/index.d.ts +372 -0
  46. package/dist/modules/get/index.js +579 -0
  47. package/dist/modules/index.d.ts +883 -0
  48. package/dist/modules/index.js +37 -0
  49. package/dist/modules/init/index.d.ts +60 -0
  50. package/dist/modules/init/index.js +38 -0
  51. package/dist/modules/middleware/index.d.ts +56 -0
  52. package/dist/modules/middleware/index.js +50 -0
  53. package/dist/modules/notificationSettings/index.d.ts +57 -0
  54. package/dist/modules/notificationSettings/index.js +39 -0
  55. package/dist/modules/plugins/index.d.ts +167 -0
  56. package/dist/modules/plugins/index.js +272 -0
  57. package/dist/modules/post/index.d.ts +306 -0
  58. package/dist/modules/post/index.js +337 -0
  59. package/dist/modules/resetTokenBucket/index.d.ts +91 -0
  60. package/dist/modules/resetTokenBucket/index.js +96 -0
  61. package/dist/modules/rest_api/index.d.ts +92 -0
  62. package/dist/modules/rest_api/index.js +117 -0
  63. package/dist/modules/update/index.d.ts +184 -0
  64. package/dist/modules/update/index.js +192 -0
  65. package/dist/modules/util/collectors.d.ts +125 -0
  66. package/dist/modules/util/collectors.js +168 -0
  67. package/dist/modules/util/folderTree.d.ts +100 -0
  68. package/dist/modules/util/folderTree.js +176 -0
  69. package/dist/modules/util/generators.d.ts +83 -0
  70. package/dist/modules/util/generators.js +106 -0
  71. package/dist/modules/util/getFromNPM.d.ts +199 -0
  72. package/dist/modules/util/getFromNPM.js +106 -0
  73. package/dist/modules/util/index.d.ts +100 -0
  74. package/dist/modules/util/index.js +20 -0
  75. package/dist/modules/util/parsers.d.ts +60 -0
  76. package/dist/modules/util/parsers.js +43 -0
  77. package/dist/modules/util/slugify.d.ts +22 -0
  78. package/dist/modules/util/slugify.js +19 -0
  79. package/dist/modules/util/users.d.ts +99 -0
  80. package/dist/modules/util/users.js +78 -0
  81. package/dist/tables.d.ts +433 -0
  82. package/dist/tables.js +169 -0
  83. package/dist/types.d.ts +359 -0
  84. package/dist/types.js +10 -0
  85. package/package.json +67 -7
@@ -0,0 +1,436 @@
1
+ import { Effect, Schema } from "@withstudiocms/effect";
2
+ import { DBClientLive, SDKDefaults } from "../../context.js";
3
+ import {
4
+ StudioCMSEmailVerificationTokens,
5
+ StudioCMSOAuthAccounts,
6
+ StudioCMSPermissions,
7
+ StudioCMSSessionTable,
8
+ StudioCMSUsersTable
9
+ } from "../../tables.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.transaction().execute(async (trx) => {
38
+ await trx.insertInto("StudioCMSEmailVerificationTokens").values(data).executeTakeFirstOrThrow();
39
+ return await trx.selectFrom("StudioCMSEmailVerificationTokens").selectAll().where("id", "=", data.id).executeTakeFirstOrThrow();
40
+ })
41
+ )
42
+ });
43
+ const _createNewOAuthAccount = withCodec({
44
+ encoder: StudioCMSOAuthAccounts.Insert,
45
+ decoder: StudioCMSOAuthAccounts.Select,
46
+ callbackFn: (db, data) => db(
47
+ (client) => client.transaction().execute(async (trx) => {
48
+ await trx.insertInto("StudioCMSOAuthAccounts").values(data).executeTakeFirstOrThrow();
49
+ return await trx.selectFrom("StudioCMSOAuthAccounts").selectAll().where(
50
+ (eb) => eb.and([eb("userId", "=", data.userId), eb("provider", "=", data.provider)])
51
+ ).executeTakeFirstOrThrow();
52
+ })
53
+ )
54
+ });
55
+ const _deleteOAuthUserAccount = withEncoder({
56
+ encoder: Schema.Struct({
57
+ userId: Schema.String,
58
+ provider: Schema.String
59
+ }),
60
+ callbackFn: (db, { userId, provider }) => db(
61
+ (client) => client.deleteFrom("StudioCMSOAuthAccounts").where((eb) => eb.and([eb("userId", "=", userId), eb("provider", "=", provider)])).executeTakeFirst()
62
+ )
63
+ });
64
+ const _searchOAuthAccountByProviderId = withCodec({
65
+ encoder: Schema.Struct({
66
+ providerUserId: Schema.String,
67
+ userId: Schema.String
68
+ }),
69
+ decoder: Schema.UndefinedOr(StudioCMSOAuthAccounts.Select),
70
+ callbackFn: (db, { providerUserId, userId }) => db(
71
+ (client) => client.selectFrom("StudioCMSOAuthAccounts").selectAll().where(
72
+ (eb) => eb.and([eb("providerUserId", "=", providerUserId), eb("userId", "=", userId)])
73
+ ).executeTakeFirst()
74
+ )
75
+ });
76
+ const _searchOauthProvidersForId = withCodec({
77
+ encoder: Schema.Struct({
78
+ providerId: Schema.String,
79
+ userId: Schema.String
80
+ }),
81
+ decoder: Schema.UndefinedOr(StudioCMSOAuthAccounts.Select),
82
+ callbackFn: (db, { providerId, userId }) => db(
83
+ (client) => client.selectFrom("StudioCMSOAuthAccounts").selectAll().where((eb) => eb.and([eb("provider", "=", providerId), eb("userId", "=", userId)])).executeTakeFirst()
84
+ )
85
+ });
86
+ const _getCurrentPermission = withCodec({
87
+ encoder: Schema.String,
88
+ decoder: Schema.UndefinedOr(StudioCMSPermissions.Select),
89
+ callbackFn: (db, id) => db(
90
+ (client) => client.selectFrom("StudioCMSPermissions").selectAll().where("user", "=", id).executeTakeFirst()
91
+ )
92
+ });
93
+ const _createNewSession = withCodec({
94
+ encoder: StudioCMSSessionTable.Insert,
95
+ decoder: StudioCMSSessionTable.Select,
96
+ callbackFn: (db, data) => db(
97
+ (client) => client.transaction().execute(async (trx) => {
98
+ await trx.insertInto("StudioCMSSessionTable").values(data).executeTakeFirstOrThrow();
99
+ return await trx.selectFrom("StudioCMSSessionTable").selectAll().where("id", "=", data.id).executeTakeFirstOrThrow();
100
+ })
101
+ )
102
+ });
103
+ const _getUserById = withCodec({
104
+ encoder: Schema.String,
105
+ decoder: Schema.UndefinedOr(StudioCMSUsersTable.Select),
106
+ callbackFn: (db, id) => db(
107
+ (client) => client.selectFrom("StudioCMSUsersTable").selectAll().where("id", "=", id).executeTakeFirst()
108
+ )
109
+ });
110
+ const _getSessionById = withCodec({
111
+ encoder: Schema.String,
112
+ decoder: Schema.UndefinedOr(StudioCMSSessionTable.Select),
113
+ callbackFn: (db, id) => db(
114
+ (client) => client.selectFrom("StudioCMSSessionTable").selectAll().where("id", "=", id).executeTakeFirst()
115
+ )
116
+ });
117
+ const _deleteSession = withEncoder({
118
+ encoder: Schema.String,
119
+ callbackFn: (db, id) => db(
120
+ (client) => client.deleteFrom("StudioCMSSessionTable").where("id", "=", id).executeTakeFirst()
121
+ )
122
+ });
123
+ const _updateSession = withCodec({
124
+ encoder: Schema.Struct({
125
+ id: Schema.String,
126
+ newDate: Schema.Date
127
+ }),
128
+ decoder: StudioCMSSessionTable.Select,
129
+ callbackFn: (db, { id, newDate }) => db(
130
+ (client) => client.transaction().execute(async (trx) => {
131
+ await trx.updateTable("StudioCMSSessionTable").set({ expiresAt: newDate }).where("id", "=", id).executeTakeFirstOrThrow();
132
+ return await trx.selectFrom("StudioCMSSessionTable").selectAll().where("id", "=", id).executeTakeFirstOrThrow();
133
+ })
134
+ )
135
+ });
136
+ const _createNewUser = withCodec({
137
+ encoder: StudioCMSUsersTable.Insert,
138
+ decoder: StudioCMSUsersTable.Select,
139
+ callbackFn: (db, data) => db(
140
+ (client) => client.transaction().execute(async (trx) => {
141
+ await trx.insertInto("StudioCMSUsersTable").values(data).executeTakeFirstOrThrow();
142
+ return await trx.selectFrom("StudioCMSUsersTable").selectAll().where("id", "=", data.id).executeTakeFirstOrThrow();
143
+ })
144
+ )
145
+ });
146
+ const _createUserPermission = withCodec({
147
+ encoder: StudioCMSPermissions.Insert,
148
+ decoder: StudioCMSPermissions.Select,
149
+ callbackFn: (db, data) => db(
150
+ (client) => client.transaction().execute(async (trx) => {
151
+ await trx.insertInto("StudioCMSPermissions").values(data).executeTakeFirstOrThrow();
152
+ return await trx.selectFrom("StudioCMSPermissions").selectAll().where("user", "=", data.user).executeTakeFirstOrThrow();
153
+ })
154
+ )
155
+ });
156
+ const _updateUserData = withCodec({
157
+ encoder: Schema.Struct({
158
+ userId: Schema.String,
159
+ userData: StudioCMSUsersTable.Update
160
+ }),
161
+ decoder: StudioCMSUsersTable.Select,
162
+ callbackFn: (db, { userId, userData }) => db(
163
+ (client) => client.transaction().execute(async (trx) => {
164
+ await trx.updateTable("StudioCMSUsersTable").set(userData).where("id", "=", userId).executeTakeFirstOrThrow();
165
+ return await trx.selectFrom("StudioCMSUsersTable").selectAll().where("id", "=", userId).executeTakeFirstOrThrow();
166
+ })
167
+ )
168
+ });
169
+ const _searchForUsername = withCodec({
170
+ encoder: Schema.String,
171
+ decoder: Schema.Array(StudioCMSUsersTable.Select),
172
+ callbackFn: (db, username) => db(
173
+ (client) => client.selectFrom("StudioCMSUsersTable").selectAll().where("username", "=", username).execute()
174
+ )
175
+ });
176
+ const _searchForEmail = withCodec({
177
+ encoder: Schema.String,
178
+ decoder: Schema.Array(StudioCMSUsersTable.Select),
179
+ callbackFn: (db, email) => db(
180
+ (client) => client.selectFrom("StudioCMSUsersTable").selectAll().where("email", "=", email).execute()
181
+ )
182
+ });
183
+ const _pippedInsertToken = (userId) => Effect.fn(
184
+ (token) => _insertVerificationToken({
185
+ id: crypto.randomUUID(),
186
+ userId,
187
+ token,
188
+ expiresAt: new Date(Date.now() + 1e3 * 60 * 60 * 24).toISOString()
189
+ })
190
+ );
191
+ const _createVerificationToken = Effect.fn(
192
+ (userId) => generateToken(userId).pipe(
193
+ Effect.tap(() => _deleteVerificationToken(userId)),
194
+ Effect.flatMap(_pippedInsertToken(userId))
195
+ )
196
+ );
197
+ const _getSessionWithUserById = Effect.fn(function* (sessionId) {
198
+ const session2 = yield* _getSessionById(sessionId);
199
+ if (!session2) return void 0;
200
+ const user2 = yield* _getUserById(session2.userId);
201
+ if (!user2) return void 0;
202
+ return {
203
+ session: session2,
204
+ user: user2
205
+ };
206
+ });
207
+ const _createNewUserWithPermission = Effect.fn(
208
+ (userData, rank) => _createNewUser(userData).pipe(
209
+ Effect.tap(
210
+ ({ id: user2 }) => _createUserPermission({
211
+ user: user2,
212
+ rank
213
+ })
214
+ )
215
+ )
216
+ );
217
+ const _searchForUsernameOrEmail = Effect.fn(function* (username, email) {
218
+ const usernameSearch = [];
219
+ const emailSearch = [];
220
+ if (username) {
221
+ const results = yield* _searchForUsername(username);
222
+ usernameSearch.push(...results);
223
+ }
224
+ if (email) {
225
+ const results = yield* _searchForEmail(email);
226
+ emailSearch.push(...results);
227
+ }
228
+ return { usernameSearch, emailSearch };
229
+ });
230
+ const _verifyGhostUserExists = Effect.fn(
231
+ () => _getUserById(GhostUserDefaults.id).pipe(Effect.map((user2) => !!user2))
232
+ );
233
+ const _createGhostUser = Effect.fn(
234
+ () => _getUserById(GhostUserDefaults.id).pipe(
235
+ Effect.flatMap(
236
+ (user2) => user2 ? Effect.succeed(user2) : _createNewUser({
237
+ ...GhostUserDefaults,
238
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
239
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
240
+ emailVerified: false
241
+ })
242
+ )
243
+ )
244
+ );
245
+ const _getGhostUser = Effect.fn(
246
+ () => _getUserById(GhostUserDefaults.id).pipe(
247
+ Effect.flatMap((user2) => user2 ? Effect.succeed(user2) : _createGhostUser())
248
+ )
249
+ );
250
+ const _CatchErrs = (capt) => Effect.catchTags(
251
+ AuthErrorTagsEntries.reduce(
252
+ (acc, tag) => {
253
+ acc[tag] = () => Effect.succeed({
254
+ status: "error",
255
+ message: `An error occurred while deleting ${capt}`
256
+ });
257
+ return acc;
258
+ },
259
+ {}
260
+ )
261
+ );
262
+ const verifyEmail = {
263
+ /**
264
+ * Retrieves an email verification token by its ID.
265
+ *
266
+ * @param id - The ID of the email verification token to retrieve.
267
+ * @returns A promise that resolves to the email verification token if found, otherwise undefined.
268
+ */
269
+ get: _getVerificationToken,
270
+ /**
271
+ * Creates a new email verification token in the database.
272
+ *
273
+ * @param userId - The ID of the user to create the token for.
274
+ * @returns A promise that resolves to the created email verification token.
275
+ */
276
+ create: _createVerificationToken,
277
+ /**
278
+ * Deletes an email verification token from the database.
279
+ *
280
+ * @param userId - The ID of the user associated with the token.
281
+ * @returns A promise that resolves to the deletion response.
282
+ */
283
+ delete: _deleteVerificationToken
284
+ };
285
+ const oAuth = {
286
+ /**
287
+ * Creates a new OAuth account in the database.
288
+ *
289
+ * @param input - The OAuth account data to create.
290
+ * @returns A promise that resolves to the created OAuth account.
291
+ */
292
+ create: _createNewOAuthAccount,
293
+ /**
294
+ * Deletes an OAuth user account from the database.
295
+ *
296
+ * @param input - An object containing the userId and provider of the OAuth account to delete.
297
+ * @returns A promise that resolves to a status and message indicating the result of the deletion.
298
+ */
299
+ delete: (input) => _deleteOAuthUserAccount(input).pipe(
300
+ Effect.flatMap(
301
+ () => Effect.succeed({
302
+ status: "success",
303
+ message: "OAuth account deleted successfully"
304
+ })
305
+ ),
306
+ _CatchErrs("OAuth account")
307
+ ),
308
+ /**
309
+ * Searches for an OAuth account by provider user ID and user ID.
310
+ *
311
+ * @param input - An object containing the providerUserId and userId to search for.
312
+ * @returns A promise that resolves to the found OAuth account if it exists, otherwise undefined.
313
+ */
314
+ searchByProviderId: _searchOAuthAccountByProviderId,
315
+ /**
316
+ * Searches for OAuth providers for a given user ID.
317
+ *
318
+ * @param input - An object containing the providerId and userId to search for.
319
+ * @returns A promise that resolves to the found OAuth account if it exists, otherwise undefined.
320
+ */
321
+ searchProvidersForId: _searchOauthProvidersForId
322
+ };
323
+ const permission = {
324
+ /**
325
+ * Retrieves the current permission for a user by their ID.
326
+ *
327
+ * @param id - The ID of the user whose permission is to be retrieved.
328
+ * @returns A promise that resolves to the user's permission if found, otherwise undefined.
329
+ */
330
+ currentStatus: _getCurrentPermission
331
+ };
332
+ const session = {
333
+ /**
334
+ * Creates a new session for a user.
335
+ *
336
+ * @param data - The session data to create.
337
+ * @returns A promise that resolves to the created session.
338
+ */
339
+ create: _createNewSession,
340
+ /**
341
+ * Retrieves a user's Session by its ID.
342
+ *
343
+ * @param id - The ID of the session to retrieve.
344
+ * @returns A promise that resolves to the session if found, otherwise undefined.
345
+ */
346
+ getById: _getSessionById,
347
+ /**
348
+ * Retrieves a session along with its associated user by session ID.
349
+ *
350
+ * @param sessionId - The ID of the session to retrieve.
351
+ * @returns A promise that resolves to an object containing the session and user if found, otherwise undefined.
352
+ */
353
+ sessionWithUser: _getSessionWithUserById,
354
+ /**
355
+ * Deletes a session by its ID.
356
+ *
357
+ * @param input - The ID of the session to delete.
358
+ * @returns A promise that resolves to a status and message indicating the result of the deletion.
359
+ */
360
+ delete: (input) => _deleteSession(input).pipe(
361
+ Effect.flatMap(
362
+ () => Effect.succeed({ status: "success", message: "Session deleted successfully" })
363
+ ),
364
+ _CatchErrs("Session")
365
+ ),
366
+ /**
367
+ * Updates a session's expiration date.
368
+ *
369
+ * @param input - An object containing the session ID and the new expiration date.
370
+ * @returns A promise that resolves to the updated session.
371
+ */
372
+ update: _updateSession
373
+ };
374
+ const user = {
375
+ /**
376
+ * Creates a new user with the specified permissions.
377
+ *
378
+ * @param userData - The data for the new user.
379
+ * @param rank - The permission rank for the new user.
380
+ * @returns A promise that resolves to the created user.
381
+ */
382
+ create: _createNewUserWithPermission,
383
+ /**
384
+ * Updates user data for a specified user.
385
+ *
386
+ * @param input - An object containing the userId and the userData to update.
387
+ * @returns A promise that resolves to the updated user.
388
+ */
389
+ update: _updateUserData,
390
+ /**
391
+ * Searches for users by username.
392
+ *
393
+ * @param username - The username to search for.
394
+ * @param email - The email to search for.
395
+ * @returns A promise that resolves to an array of users matching the username.
396
+ */
397
+ searchUsersForUsernameOrEmail: _searchForUsernameOrEmail,
398
+ /**
399
+ * Verifies the existence of the ghost user.
400
+ *
401
+ * @returns A promise that resolves to true if the ghost user exists, otherwise false.
402
+ */
403
+ ghost: {
404
+ /**
405
+ * Verifies the existence of the ghost user.
406
+ *
407
+ * @returns A promise that resolves to true if the ghost user exists, otherwise false.
408
+ */
409
+ verifyExists: _verifyGhostUserExists,
410
+ /**
411
+ * Creates the ghost user if it does not already exist.
412
+ *
413
+ * @returns A promise that resolves to the ghost user.
414
+ */
415
+ create: _createGhostUser,
416
+ /**
417
+ * Retrieves the ghost user.
418
+ *
419
+ * @returns A promise that resolves to the ghost user.
420
+ */
421
+ get: _getGhostUser
422
+ }
423
+ };
424
+ return {
425
+ verifyEmail,
426
+ oAuth,
427
+ permission,
428
+ session,
429
+ user
430
+ };
431
+ });
432
+ var auth_default = SDKAuthModule;
433
+ export {
434
+ SDKAuthModule,
435
+ auth_default as default
436
+ };
@@ -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
+ };