@respectify/astro 0.1.9 → 1.0.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.
package/src/types.ts CHANGED
@@ -1,4 +1,10 @@
1
- import type { MegacallOptions, RespectifyClientOptions } from '@respectify/client';
1
+ import type {
2
+ HealthItemScores,
3
+ MegacallOptions,
4
+ ModerationTolerances,
5
+ RespectifyClientOptions,
6
+ } from '@respectify/client';
7
+ import type { ICommentStore } from './store/types';
2
8
 
3
9
  /**
4
10
  * Options forwarded to `RespectifyClient`.
@@ -8,24 +14,32 @@ export type RespectifyClientConfig = Partial<RespectifyClientOptions>;
8
14
 
9
15
  /**
10
16
  * Options forwarded to every `megacall`.
11
- * `comment` and `articleId` are set automatically by the integration.
17
+ * `comment` and `articleId` are set automatically by the integration, and
18
+ * `tolerances` comes from the top-level `tolerances` option.
12
19
  */
13
- export type RespectifyMegacallConfig = Omit<MegacallOptions, 'comment' | 'articleId'>;
20
+ export type RespectifyMegacallConfig = Omit<MegacallOptions, 'comment' | 'articleId' | 'tolerances'>;
14
21
 
15
- export interface RespectifyIntegrationOptions {
16
- /** Path to respectify.config.json (default: ./respectify.config.json) */
17
- configPath?: string;
18
-
19
- /** Build the canonical URL for a post — used to initialize Respectify topics */
20
- getPostUrl?: (slug: string, site: string) => string;
22
+ /**
23
+ * Client options the integration accepts in astro.config. Credentials are not among them:
24
+ * options are serialized into the server bundle, so credentials come from the
25
+ * `RESPECTIFY_EMAIL` / `RESPECTIFY_API_KEY` env vars (or respectify.config.json) instead.
26
+ */
27
+ export type RespectifyIntegrationClientConfig = Omit<RespectifyClientConfig, 'email' | 'apiKey'>;
21
28
 
29
+ /**
30
+ * Options for `respectify()` in astro.config. Every option must be serializable: they are
31
+ * passed to the server bundle as JSON. Functions and the comment store belong in the
32
+ * runtime module (see `defineRespectifyRuntime`).
33
+ */
34
+ export interface RespectifyIntegrationOptions {
22
35
  /**
23
- * Provide a post's raw text content directly instead of having Respectify fetch
24
- * `getPostUrl`. Useful when the URL isn't publicly fetchable (staged/preview content,
25
- * auth-gated pages, or timing issues right after deploy). Takes priority over
26
- * `getPostUrl` for topic initialization when provided.
36
+ * The runtime module: a file whose default export is `defineRespectifyRuntime({ store, ... })`.
37
+ * A relative path is resolved against the project root; a package specifier is left to Vite.
27
38
  */
28
- getPostContent?: (slug: string) => string | Promise<string>;
39
+ runtime: string;
40
+
41
+ /** Path to respectify.config.json (default: ./respectify.config.json) */
42
+ configPath?: string;
29
43
 
30
44
  /** API route path for fetching comments (default: /api/respectify/comments) */
31
45
  commentsApiPath?: string;
@@ -40,10 +54,9 @@ export interface RespectifyIntegrationOptions {
40
54
  };
41
55
 
42
56
  /**
43
- * Options forwarded to the Respectify API client
44
- * (`baseUrl`, `timeout`, `version`, `website`, optional credential overrides).
57
+ * Options forwarded to the Respectify API client (`baseUrl`, `timeout`, `version`, `website`).
45
58
  */
46
- client?: RespectifyClientConfig;
59
+ client?: RespectifyIntegrationClientConfig;
47
60
 
48
61
  /**
49
62
  * Options forwarded to every Respectify megacall
@@ -51,6 +64,48 @@ export interface RespectifyIntegrationOptions {
51
64
  * `bannedTopics`, `sensitiveTopics`, `dogwhistleExamples`, `replyToComment`).
52
65
  */
53
66
  megacall?: RespectifyMegacallConfig;
67
+
68
+ /**
69
+ * Comment-health tolerances sent with every megacall, merged per item over the
70
+ * `tolerances` in respectify.config.json (these win). Items not named are "standard".
71
+ * Floored categories (threat, identity_attack, sexual_content, harassment) can never
72
+ * be "permissive", "relaxed" or "off".
73
+ */
74
+ tolerances?: ModerationTolerances;
75
+ }
76
+
77
+ /** The integration options as the server bundle sees them, with defaults applied. */
78
+ export interface ResolvedIntegrationOptions {
79
+ configPath: string;
80
+ commentsApiPath: string;
81
+ showBranding: boolean;
82
+ rateLimit: {
83
+ windowMs: number;
84
+ maxRequests: number;
85
+ };
86
+ client?: RespectifyIntegrationClientConfig;
87
+ megacall?: RespectifyMegacallConfig;
88
+ tolerances?: ModerationTolerances;
89
+ }
90
+
91
+ /**
92
+ * What the runtime module provides: the parts of the integration that are not serializable.
93
+ * It is loaded in the server bundle, so it may hold database clients and functions.
94
+ */
95
+ export interface RespectifyRuntime {
96
+ /** Where comments are kept */
97
+ store: ICommentStore;
98
+
99
+ /** Build the canonical URL for a post, used to initialize Respectify topics (default: `${site}/posts/${slug}/`) */
100
+ getPostUrl?: (slug: string, site: string) => string;
101
+
102
+ /**
103
+ * Provide a post's raw text content directly instead of having Respectify fetch
104
+ * `getPostUrl`. Useful when the URL isn't publicly fetchable (staged/preview content,
105
+ * auth-gated pages, or timing issues right after deploy). Takes priority over
106
+ * `getPostUrl` for topic initialization when provided.
107
+ */
108
+ getPostContent?: (slug: string) => string | Promise<string>;
54
109
  }
55
110
 
56
111
  export interface AnalyzeCommentOptions {
@@ -63,6 +118,21 @@ export interface RespectifyAnalysisResult {
63
118
  approved: boolean;
64
119
  feedback: string;
65
120
  suggestion?: string;
121
+ /** True when the comment is spam: it is rejected */
66
122
  isSpam?: boolean;
67
123
  spamConfidence?: number;
124
+ /**
125
+ * True when the comment looks like spam but is not certain. It is not approved (never,
126
+ * even with `allowOverride`), but it is not rejected as spam either: `feedback` carries
127
+ * the server's suggestion so the commenter can revise it. Set when a spam check ran.
128
+ */
129
+ suspectedSpam?: boolean;
130
+ /** The server's suggestion for a suspected-spam comment, such as to remove a link */
131
+ spamSuggestion?: string;
132
+ /** True when the comment score found a problem the site's tolerances do not accept */
133
+ exceedsTolerance?: boolean;
134
+ /** Comment health, 1.0-5.0, when the API returned it */
135
+ healthScore?: number;
136
+ /** Per-item comment-health results (score, minimum, is_acceptable), when the API returned them */
137
+ healthItems?: HealthItemScores;
68
138
  }
package/src/schema.ts DELETED
@@ -1,25 +0,0 @@
1
- import { defineTable, column, NOW } from 'astro:db';
2
- import type { TableConfig } from '@astrojs/db/types';
3
-
4
- const respectifyCommentColumns = {
5
- id: column.number({ primaryKey: true }),
6
- postSlug: column.text(),
7
- author: column.text(),
8
- email: column.text({ optional: true }),
9
- content: column.text(),
10
- createdAt: column.date({ default: NOW }),
11
- approved: column.boolean({ default: false }),
12
- parentId: column.number({ optional: true }),
13
- };
14
-
15
- /** Astro DB table definition for Respectify comments. Merge into your db/config.ts. */
16
- export const RespectifyComment: TableConfig<typeof respectifyCommentColumns> = defineTable({
17
- columns: respectifyCommentColumns,
18
- indexes: [
19
- { on: ['postSlug'], unique: false },
20
- { on: ['approved'], unique: false },
21
- ],
22
- });
23
-
24
- /** Alias for backwards compatibility with existing schemas */
25
- export const Comment = RespectifyComment;