memi-board 0.47.0 → 0.47.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.
- package/README.md +85 -17
- package/dist/index.js +130 -84
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +3 -1
- package/docs/firebase-setup.md +8 -9
- package/docs/firestore.rules.example +39 -1
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -156,8 +156,10 @@ export interface BoardUserModel {
|
|
|
156
156
|
displayName?: string | null;
|
|
157
157
|
photoURL?: string | null;
|
|
158
158
|
moderationBlockCount?: number;
|
|
159
|
-
/** AI 글쓰기 도우미 24시간 사용 횟수. */
|
|
159
|
+
/** AI 글쓰기 도우미 24시간 확정 사용 횟수. 성공한 호출만 올라가고 줄지 않는다. */
|
|
160
160
|
aiWritingCount?: number;
|
|
161
|
+
/** 아직 결과가 나지 않은 AI 글쓰기 예약. 실패하면 줄고, 성공하면 확정 횟수로 넘어간다. */
|
|
162
|
+
aiWritingPending?: number;
|
|
161
163
|
/** AI 글쓰기 도우미 현재 24시간 구간 시작 시각. */
|
|
162
164
|
aiWritingWindowAt?: Timestamp;
|
|
163
165
|
updatedAt?: Timestamp;
|
package/docs/firebase-setup.md
CHANGED
|
@@ -157,15 +157,14 @@ Google보다 손이 더 간다:
|
|
|
157
157
|
|
|
158
158
|
## 8. App Check 설정 (AI Logic Enforce 시 사실상 필수)
|
|
159
159
|
|
|
160
|
-
AI Logic / `firebaseml` 이 **Enforce** 이면 App Check 토큰 없이 검열 API가 실패한다. memi-board는 App Check를 초기화하지
|
|
161
|
-
|
|
162
|
-
1. Firebase 콘솔
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
5. (선택) Firestore/Storage Enforce — 켜면 토큰 없는 요청 거부. AI Logic 과 별개 토글이다.
|
|
160
|
+
AI Logic / `firebaseml` 이 **Enforce** 이면 App Check 토큰 없이 검열 API가 실패한다. memi-board는 App Check를 초기화하지 않는다. **호스트 책임**이다. 기본값은 한 번만 쓰는 토큰(`useLimitedUseAppCheckTokens: true`)이라 reCAPTCHA v3 공급자로는 맞지 않는다. 플러그인 예시는 [README App Check 절](../README.md#app-check-ai-enforce-시-사실상-필수)을 따른다.
|
|
161
|
+
|
|
162
|
+
1. reCAPTCHA Enterprise **점수형** 웹 키를 만들고, Firebase 콘솔 App Check의 웹 앱에 그 사이트 키를 등록한다. 등록하는 웹 앱의 **appId** 가 호스트 `vuefire.config.appId` 와 같아야 한다. 시크릿 키는 클라이언트에 넣지 않는다.
|
|
163
|
+
2. 브라우저 API 키 제한에 **Firebase App Check API** 를 포함한다. 이미 허용한 API는 유지한다.
|
|
164
|
+
3. SPA는 `app:mounted` 이후에 `enterprise.execute` 로 토큰을 만들어 `exchangeRecaptchaEnterpriseToken` 에 `limited_use: true` 로 교환한다. `ReCaptchaEnterpriseProvider` 는 마운트 전 빈 `document.body` 에 숨은 위젯을 그리다 `appCheck/recaptcha-error` 가 난다.
|
|
165
|
+
4. **로컬:** `self.FIREBASE_APPCHECK_DEBUG_TOKEN = true`(콘솔에 UUID 출력 후 App Check → 디버그 토큰 등록) 또는 등록된 고정 UUID.
|
|
166
|
+
5. **프로덕션:** 디버그 토큰 사용 금지. reCAPTCHA 도메인에 실제 호스트 도메인 등록.
|
|
167
|
+
6. 적용은 **AI Logic만** 켠다. Cloud Storage와 Cloud Firestore는 모니터링으로 둔다. 한 번용 토큰은 AI Logic만 받는다. Storage나 Firestore에 적용하면 이미지 업로드와 글 쓰기가 거절된다.
|
|
169
168
|
|
|
170
169
|
## 9. Firestore 복합 인덱스
|
|
171
170
|
|
|
@@ -202,13 +202,14 @@ service cloud.firestore {
|
|
|
202
202
|
&& request.resource.data.role == resource.data.role
|
|
203
203
|
&& (
|
|
204
204
|
!request.resource.data.diff(resource.data).affectedKeys()
|
|
205
|
-
.hasAny(['moderationBlockCount', 'moderationBlockAt', 'aiWritingCount', 'aiWritingWindowAt'])
|
|
205
|
+
.hasAny(['moderationBlockCount', 'moderationBlockAt', 'aiWritingCount', 'aiWritingPending', 'aiWritingWindowAt'])
|
|
206
206
|
|| (
|
|
207
207
|
request.resource.data.diff(resource.data).affectedKeys()
|
|
208
208
|
.hasOnly(['moderationBlockCount', 'moderationBlockAt', 'updatedAt'])
|
|
209
209
|
&& request.resource.data.moderationBlockCount
|
|
210
210
|
== resource.data.get('moderationBlockCount', 0) + 1
|
|
211
211
|
)
|
|
212
|
+
// 0.47.0 이하: 호출 전에 확정 횟수를 1 올린다.
|
|
212
213
|
|| (
|
|
213
214
|
request.resource.data.diff(resource.data).affectedKeys()
|
|
214
215
|
.hasOnly(['aiWritingCount', 'aiWritingWindowAt', 'updatedAt'])
|
|
@@ -229,6 +230,43 @@ service cloud.firestore {
|
|
|
229
230
|
)
|
|
230
231
|
)
|
|
231
232
|
)
|
|
233
|
+
// 0.47.1+: 호출 전에 예약만 잡고, 성공하면 확정한다. 실패하면 예약만 내린다.
|
|
234
|
+
// 확정 횟수는 1씩만 오르고, 클라이언트가 내리지는 못한다.
|
|
235
|
+
|| (
|
|
236
|
+
request.resource.data.diff(resource.data).affectedKeys()
|
|
237
|
+
.hasOnly(['aiWritingPending', 'updatedAt'])
|
|
238
|
+
&& 'aiWritingWindowAt' in resource.data
|
|
239
|
+
&& request.time < resource.data.aiWritingWindowAt + duration.value(24, 'h')
|
|
240
|
+
&& (
|
|
241
|
+
(
|
|
242
|
+
request.resource.data.aiWritingPending == resource.data.get('aiWritingPending', 0) + 1
|
|
243
|
+
&& resource.data.get('aiWritingCount', 0) + request.resource.data.aiWritingPending <= 10
|
|
244
|
+
)
|
|
245
|
+
|| (
|
|
246
|
+
resource.data.get('aiWritingPending', 0) >= 1
|
|
247
|
+
&& request.resource.data.aiWritingPending == resource.data.get('aiWritingPending', 0) - 1
|
|
248
|
+
)
|
|
249
|
+
)
|
|
250
|
+
)
|
|
251
|
+
|| (
|
|
252
|
+
request.resource.data.diff(resource.data).affectedKeys()
|
|
253
|
+
.hasOnly(['aiWritingCount', 'aiWritingPending', 'updatedAt'])
|
|
254
|
+
&& 'aiWritingWindowAt' in resource.data
|
|
255
|
+
&& request.time < resource.data.aiWritingWindowAt + duration.value(24, 'h')
|
|
256
|
+
&& resource.data.get('aiWritingPending', 0) >= 1
|
|
257
|
+
&& request.resource.data.aiWritingPending == resource.data.get('aiWritingPending', 0) - 1
|
|
258
|
+
&& request.resource.data.aiWritingCount == resource.data.get('aiWritingCount', 0) + 1
|
|
259
|
+
&& request.resource.data.aiWritingCount <= 10
|
|
260
|
+
)
|
|
261
|
+
|| (
|
|
262
|
+
request.resource.data.diff(resource.data).affectedKeys()
|
|
263
|
+
.hasOnly(['aiWritingCount', 'aiWritingPending', 'aiWritingWindowAt', 'updatedAt'])
|
|
264
|
+
&& (!('aiWritingWindowAt' in resource.data)
|
|
265
|
+
|| request.time >= resource.data.aiWritingWindowAt + duration.value(24, 'h'))
|
|
266
|
+
&& request.resource.data.aiWritingWindowAt == request.time
|
|
267
|
+
&& request.resource.data.aiWritingCount == 0
|
|
268
|
+
&& request.resource.data.aiWritingPending == 1
|
|
269
|
+
)
|
|
232
270
|
));
|
|
233
271
|
|
|
234
272
|
// 다른 작성자에 대해 나만 보는 개인 메모. 문서 ID가 targetUid라 대상당 하나로
|