@respectify/astro 1.0.1 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@respectify/astro",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Respectify-powered commenting for Astro \u2014 AI moderation, spam filtering, and beautiful UX out of the box.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -57,8 +57,7 @@
57
57
  "astro": "^5.0.0 || ^6.0.0 || ^7.0.0",
58
58
  "drizzle-orm": "^0.45.0",
59
59
  "pg": "^8.0.0",
60
- "vitest": "^3.0.0",
61
- "zod": "^3.0.0"
60
+ "vitest": "^3.0.0 || ^4.0.0 || ^5.0.0"
62
61
  },
63
62
  "peerDependenciesMeta": {
64
63
  "@libsql/client": {
@@ -75,7 +74,7 @@
75
74
  }
76
75
  },
77
76
  "dependencies": {
78
- "zod": "^3.24.0"
77
+ "zod": "^4.6.6"
79
78
  },
80
79
  "scripts": {
81
80
  "typecheck": "tsc --noEmit",
@@ -90,6 +89,6 @@
90
89
  "drizzle-kit": "^0.31.11",
91
90
  "drizzle-orm": "^0.45.4",
92
91
  "typescript": "^5.4.3",
93
- "vitest": "^3.2.4"
92
+ "vitest": "^5.0.5"
94
93
  }
95
94
  }
package/src/lib/config.ts CHANGED
@@ -22,14 +22,13 @@ const BELOW_FLOOR_TOLERANCE_LEVELS: readonly ToleranceLevel[] = ['off', 'permiss
22
22
  /** A floored category's level, rejecting "permissive", "relaxed" and "off" with the same wording the API uses. */
23
23
  function flooredToleranceLevelSchema(
24
24
  category: FlooredModerationCategory,
25
- ): z.ZodEnum<z.Writeable<typeof FLOORED_TOLERANCE_LEVELS>> {
25
+ ): z.ZodEnum<{ [Level in FlooredToleranceLevel]: Level }> {
26
26
  return z.enum(FLOORED_TOLERANCE_LEVELS, {
27
- errorMap: (_issue, ctx) => ({
28
- message:
29
- BELOW_FLOOR_TOLERANCE_LEVELS.includes(ctx.data)
30
- ? `${category} can be made stricter but not relaxed or turned off`
31
- : ctx.defaultError,
32
- }),
27
+ // Returning undefined falls through to Zod's default message for any other invalid value
28
+ error: (issue) =>
29
+ BELOW_FLOOR_TOLERANCE_LEVELS.includes(issue.input as ToleranceLevel)
30
+ ? `${category} can be made stricter but not relaxed or turned off`
31
+ : undefined,
33
32
  });
34
33
  }
35
34
 
@@ -38,7 +37,7 @@ function flooredToleranceLevelSchema(
38
37
  * quality). Items not named are "standard". Unknown items are rejected.
39
38
  */
40
39
  const ModerationTolerancesSchema = z
41
- .object({
40
+ .strictObject({
42
41
  threat: flooredToleranceLevelSchema('threat').optional(),
43
42
  identity_attack: flooredToleranceLevelSchema('identity_attack').optional(),
44
43
  sexual_content: flooredToleranceLevelSchema('sexual_content').optional(),
@@ -49,8 +48,7 @@ const ModerationTolerancesSchema = z
49
48
  logical_fallacy: ToleranceLevelSchema.optional(),
50
49
  low_effort: ToleranceLevelSchema.optional(),
51
50
  quality: ToleranceLevelSchema.optional(),
52
- })
53
- .strict() satisfies z.ZodType<ModerationTolerances>;
51
+ }) satisfies z.ZodType<ModerationTolerances>;
54
52
 
55
53
  const MegacallConfigSchema = z
56
54
  .object({
@@ -67,11 +65,11 @@ const MegacallConfigSchema = z
67
65
 
68
66
  const ClientConfigSchema = z
69
67
  .object({
70
- baseUrl: z.string().url().optional(),
68
+ baseUrl: z.url().optional(),
71
69
  version: z.string().optional(),
72
70
  timeout: z.number().positive().optional(),
73
71
  website: z.string().optional(),
74
- email: z.string().email().optional(),
72
+ email: z.email().optional(),
75
73
  apiKey: z.string().optional(),
76
74
  })
77
75
  .optional();
@@ -79,7 +77,7 @@ const ClientConfigSchema = z
79
77
  const RespectifyConfigSchema = z.object({
80
78
  enabled: z.boolean(),
81
79
  /** @deprecated Prefer `client.baseUrl` — still accepted and mapped to the client base URL */
82
- apiEndpoint: z.string().url().optional(),
80
+ apiEndpoint: z.url().optional(),
83
81
  requiresAuth: z.boolean().optional(),
84
82
  autoPublish: z
85
83
  .object({
package/src/options.ts CHANGED
@@ -22,29 +22,25 @@ const RUNTIME_ONLY_OPTIONS = ['getPostUrl', 'getPostContent'] as const;
22
22
  /** Credentials are never serialized into the server bundle. */
23
23
  const CREDENTIAL_CLIENT_OPTIONS = ['email', 'apiKey'] as const;
24
24
 
25
- const clientConfigSchema = z
26
- .object({
27
- baseUrl: z.string().url().optional(),
28
- version: z.string().optional(),
29
- timeout: z.number().positive().optional(),
30
- website: z.string().optional(),
31
- })
32
- .strict() satisfies z.ZodType<RespectifyIntegrationClientConfig>;
25
+ const clientConfigSchema = z.strictObject({
26
+ baseUrl: z.url().optional(),
27
+ version: z.string().optional(),
28
+ timeout: z.number().positive().optional(),
29
+ website: z.string().optional(),
30
+ }) satisfies z.ZodType<RespectifyIntegrationClientConfig>;
33
31
 
34
- const megacallConfigSchema = z
35
- .object({
36
- includeSpam: z.boolean().optional(),
37
- includeRelevance: z.boolean().optional(),
38
- includeCommentScore: z.boolean().optional(),
39
- includeDogwhistle: z.boolean().optional(),
40
- includePerspectiveAnalyzeComment: z.boolean().optional(),
41
- bannedTopics: z.array(z.string()).optional(),
42
- sensitiveTopics: z.array(z.string()).optional(),
43
- dogwhistleExamples: z.array(z.string()).optional(),
44
- replyToComment: z.string().optional(),
45
- contextComments: z.array(z.string()).optional(),
46
- })
47
- .strict() satisfies z.ZodType<RespectifyMegacallConfig>;
32
+ const megacallConfigSchema = z.strictObject({
33
+ includeSpam: z.boolean().optional(),
34
+ includeRelevance: z.boolean().optional(),
35
+ includeCommentScore: z.boolean().optional(),
36
+ includeDogwhistle: z.boolean().optional(),
37
+ includePerspectiveAnalyzeComment: z.boolean().optional(),
38
+ bannedTopics: z.array(z.string()).optional(),
39
+ sensitiveTopics: z.array(z.string()).optional(),
40
+ dogwhistleExamples: z.array(z.string()).optional(),
41
+ replyToComment: z.string().optional(),
42
+ contextComments: z.array(z.string()).optional(),
43
+ }) satisfies z.ZodType<RespectifyMegacallConfig>;
48
44
 
49
45
  /** Tolerances are checked by the Respectify client's own validator, so the wording matches the API. */
50
46
  const tolerancesSchema = z.custom<ModerationTolerances>().superRefine((tolerances, ctx) => {
@@ -52,31 +48,28 @@ const tolerancesSchema = z.custom<ModerationTolerances>().superRefine((tolerance
52
48
  validateModerationTolerances(tolerances);
53
49
  } catch (error) {
54
50
  if (!(error instanceof RespectifyError)) throw error;
55
- ctx.addIssue({ code: z.ZodIssueCode.custom, message: `Invalid Respectify tolerances: ${error.message}` });
51
+ ctx.addIssue({ code: 'custom', message: `Invalid Respectify tolerances: ${error.message}` });
56
52
  }
57
53
  });
58
54
 
59
- const integrationOptionsSchema = z
60
- .object({
61
- runtime: z.string().min(1, 'runtime must name the module that calls defineRespectifyRuntime()'),
62
- configPath: z.string().min(1).default(DEFAULT_INTEGRATION_OPTIONS.configPath),
63
- commentsApiPath: z
64
- .string()
65
- .startsWith('/', 'commentsApiPath must be a path starting with "/"')
66
- .default(DEFAULT_INTEGRATION_OPTIONS.commentsApiPath),
67
- showBranding: z.boolean().default(DEFAULT_INTEGRATION_OPTIONS.showBranding),
68
- rateLimit: z
69
- .object({
70
- windowMs: z.number().int().positive(),
71
- maxRequests: z.number().int().positive(),
72
- })
73
- .strict()
74
- .default(DEFAULT_INTEGRATION_OPTIONS.rateLimit),
75
- client: clientConfigSchema.optional(),
76
- megacall: megacallConfigSchema.optional(),
77
- tolerances: tolerancesSchema.optional(),
78
- })
79
- .strict();
55
+ const integrationOptionsSchema = z.strictObject({
56
+ runtime: z.string().min(1, 'runtime must name the module that calls defineRespectifyRuntime()'),
57
+ configPath: z.string().min(1).default(DEFAULT_INTEGRATION_OPTIONS.configPath),
58
+ commentsApiPath: z
59
+ .string()
60
+ .startsWith('/', 'commentsApiPath must be a path starting with "/"')
61
+ .default(DEFAULT_INTEGRATION_OPTIONS.commentsApiPath),
62
+ showBranding: z.boolean().default(DEFAULT_INTEGRATION_OPTIONS.showBranding),
63
+ rateLimit: z
64
+ .strictObject({
65
+ windowMs: z.number().int().positive(),
66
+ maxRequests: z.number().int().positive(),
67
+ })
68
+ .default(DEFAULT_INTEGRATION_OPTIONS.rateLimit),
69
+ client: clientConfigSchema.optional(),
70
+ megacall: megacallConfigSchema.optional(),
71
+ tolerances: tolerancesSchema.optional(),
72
+ });
80
73
 
81
74
  /** The validated options: what the server bundle sees, plus the runtime module's specifier. */
82
75
  export type ParsedIntegrationOptions = ResolvedIntegrationOptions & { runtime: string };
@@ -6,22 +6,20 @@ import type { NewComment } from './types';
6
6
  export const commentIdSchema = z.number().int().positive();
7
7
 
8
8
  /** What a store accepts in `create`. Every store validates its input against this. */
9
- export const newCommentSchema = z
10
- .object({
11
- postSlug: z.string().min(1).max(COMMENT_LIMITS.postSlugMax),
12
- author: z.string().min(1).max(COMMENT_LIMITS.authorMax),
13
- email: z.string().email().max(COMMENT_LIMITS.emailMax).optional(),
14
- content: z.string().min(1).max(COMMENT_LIMITS.contentMax),
15
- approved: z.boolean(),
16
- parentId: commentIdSchema.optional(),
17
- })
18
- .strict() satisfies z.ZodType<NewComment>;
9
+ export const newCommentSchema = z.strictObject({
10
+ postSlug: z.string().min(1).max(COMMENT_LIMITS.postSlugMax),
11
+ author: z.string().min(1).max(COMMENT_LIMITS.authorMax),
12
+ email: z.email().max(COMMENT_LIMITS.emailMax).optional(),
13
+ content: z.string().min(1).max(COMMENT_LIMITS.contentMax),
14
+ approved: z.boolean(),
15
+ parentId: commentIdSchema.optional(),
16
+ }) satisfies z.ZodType<NewComment>;
19
17
 
20
18
  /** Thrown by a store when `create` is given input that does not match `newCommentSchema`. */
21
19
  export class CommentValidationError extends Error {
22
- readonly issues: z.ZodIssue[];
20
+ readonly issues: z.core.$ZodIssue[];
23
21
 
24
- constructor(issues: z.ZodIssue[]) {
22
+ constructor(issues: z.core.$ZodIssue[]) {
25
23
  super(`Invalid comment: ${issues.map((issue) => `${issue.path.join('.') || 'input'}: ${issue.message}`).join('; ')}`);
26
24
  this.name = 'CommentValidationError';
27
25
  this.issues = issues;