briyah 2.0.2 → 2.0.4
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/LICENSE +216 -0
- package/README.md +43 -7
- package/data/common/config/LICENSE-model-prices.md +65 -0
- package/data/common/config/markup +1 -1
- package/data/common/config/model_prices.json +47443 -46295
- package/data/common/prompts/narrator/create_story.prompt +2 -0
- package/data/packs/dnd5e/agents/player.json +11 -11
- package/data/packs/dnd5e/prompts/character_creator/defaults_config.json +21 -20
- package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +19 -12
- package/data/packs/dnd5e/prompts/dnd_player/perceive.prompt +10 -6
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
- package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
- package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +102 -3
- package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
- package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
- package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
- package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
- package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
- package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/openai.service.js +80 -2
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +44 -2
- package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
- package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
- package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
- package/dist-sdk/server/src/ai/agent-factory.js +20 -0
- package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
- package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
- package/dist-sdk/server/src/ai/agent-store.service.js +166 -5
- package/dist-sdk/server/src/ai/agent.d.ts +196 -0
- package/dist-sdk/server/src/ai/agent.js +224 -11
- package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
- package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
- package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
- package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
- package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
- package/dist-sdk/server/src/ai/artifact.service.js +148 -3
- package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
- package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
- package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
- package/dist-sdk/server/src/ai/model_prices.js +91 -5
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
- package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
- package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
- package/dist-sdk/server/src/app/balance-message.service.js +24 -0
- package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
- package/dist-sdk/server/src/app/balance.module.js +4 -0
- package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
- package/dist-sdk/server/src/app/balance.service.js +54 -0
- package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
- package/dist-sdk/server/src/app/stripe.controller.js +35 -0
- package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
- package/dist-sdk/server/src/app/stripe.service.js +62 -0
- package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
- package/dist-sdk/server/src/app/transaction.service.js +36 -0
- package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
- package/dist-sdk/server/src/app/user-service-factory.js +38 -1
- package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
- package/dist-sdk/server/src/app/user-service-manager.js +43 -0
- package/dist-sdk/server/src/app.controller.d.ts +87 -0
- package/dist-sdk/server/src/app.controller.js +272 -12
- package/dist-sdk/server/src/app.module.js +28 -6
- package/dist-sdk/server/src/app.service.d.ts +1662 -0
- package/dist-sdk/server/src/app.service.js +1862 -6
- package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
- package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
- package/dist-sdk/server/src/auth/auth.controller.js +46 -0
- package/dist-sdk/server/src/auth/auth.module.js +3 -2
- package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
- package/dist-sdk/server/src/auth/auth.service.js +39 -3
- package/dist-sdk/server/src/auth/jwt-auth.guard.js +18 -0
- package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
- package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
- package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
- package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
- package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
- package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
- package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
- package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
- package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
- package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
- package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
- package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
- package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
- package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
- package/dist-sdk/server/src/auth/session.guard.js +8 -0
- package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
- package/dist-sdk/server/src/auth/twilio.service.js +30 -4
- package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
- package/dist-sdk/server/src/auth/users.service.js +42 -0
- package/dist-sdk/server/src/common/errors.d.ts +20 -0
- package/dist-sdk/server/src/common/errors.js +21 -0
- package/dist-sdk/server/src/config/env-config.d.ts +7 -0
- package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
- package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
- package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
- package/dist-sdk/server/src/config/user-config.service.js +57 -0
- package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
- package/dist-sdk/server/src/config/user-paths.service.js +67 -0
- package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
- package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +99 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +58 -0
- package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
- package/dist-sdk/server/src/packs/pack.service.js +98 -1
- package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
- package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
- package/dist-sdk/server/src/room/artifact.d.ts +18 -0
- package/dist-sdk/server/src/room/message.d.ts +64 -0
- package/dist-sdk/server/src/room/message.js +77 -2
- package/dist-sdk/server/src/room/nickname.d.ts +27 -0
- package/dist-sdk/server/src/room/nickname.js +41 -0
- package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
- package/dist-sdk/server/src/room/room-config.d.ts +26 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
- package/dist-sdk/server/src/room/room-factory.js +14 -0
- package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
- package/dist-sdk/server/src/room/room-message.service.js +28 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +177 -0
- package/dist-sdk/server/src/room/room-store.service.js +242 -5
- package/dist-sdk/server/src/room/room.d.ts +906 -1
- package/dist-sdk/server/src/room/room.js +1525 -34
- package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
- package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +38 -3
- package/dist-sdk/server/src/rpg/rpg-roster.js +49 -49
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +108 -5
- package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
- package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
- package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
- package/dist-sdk/server/src/sdk/briyah.js +285 -7
- package/dist-sdk/server/src/sdk/index.d.ts +0 -1
- package/dist-sdk/server/src/sdk/index.js +24 -3
- package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
- package/dist-sdk/server/src/shared/shared.module.js +13 -5
- package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
- package/dist-sdk/server/src/story/story-message.service.js +43 -0
- package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
- package/dist-sdk/server/src/story/story-progress.service.js +23 -0
- package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
- package/dist-sdk/server/src/story/story-store.service.js +136 -1
- package/dist-sdk/server/src/story/story.service.d.ts +398 -0
- package/dist-sdk/server/src/story/story.service.js +829 -25
- package/dist-sdk/server/src/tools/core/index.d.ts +25 -0
- package/dist-sdk/server/src/tools/core/index.js +31 -0
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +10 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +72 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +186 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +192 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +164 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +125 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
- package/dist-sdk/server/src/tools/packs/index.d.ts +52 -2
- package/dist-sdk/server/src/tools/packs/index.js +83 -9
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +73 -0
- package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
- package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
- package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
- package/dist-sdk/shared/types/app.types.d.ts +285 -14
- package/dist-sdk/shared/types/app.types.js +3 -0
- package/package.json +167 -139
- package/data/common/config/random_words.txt +0 -2241
- package/data/common/story_ideas/biblical.json +0 -122
- package/data/common/story_ideas/fantasy.json +0 -82
- package/data/common/story_ideas/historical_fiction.json +0 -82
- package/data/common/story_ideas/science_fiction.json +0 -82
- package/data/packs/acts/agents/character-guide.json +0 -6
- package/data/packs/acts/agents/discipleship-mentor.json +0 -6
- package/data/packs/acts/agents/mentor-coach.json +0 -6
- package/data/packs/acts/agents/student.json +0 -13
- package/data/packs/acts/agents/table-moderator.json +0 -6
- package/data/packs/acts/artifacts/chapter-01-acts-1.md +0 -405
- package/data/packs/acts/artifacts/chapter-02-acts-2.md +0 -443
- package/data/packs/acts/artifacts/chapter-03-acts-3.md +0 -409
- package/data/packs/acts/artifacts/chapter-04-acts-4.md +0 -438
- package/data/packs/acts/artifacts/chapter-05-acts-5.md +0 -434
- package/data/packs/acts/artifacts/chapter-06-acts-6.md +0 -441
- package/data/packs/acts/artifacts/chapter-07-acts-7.md +0 -472
- package/data/packs/acts/artifacts/chapter-08-acts-8.md +0 -512
- package/data/packs/acts/artifacts/chapter-09-acts-9.md +0 -346
- package/data/packs/acts/artifacts/chapter-10-acts-10.md +0 -367
- package/data/packs/acts/artifacts/chapter-11-acts-11.md +0 -391
- package/data/packs/acts/artifacts/chapter-12-acts-12.md +0 -390
- package/data/packs/acts/artifacts/chapter-13-acts-13.md +0 -388
- package/data/packs/acts/artifacts/chapter-14-acts-14.md +0 -466
- package/data/packs/acts/artifacts/chapter-15-acts-15.md +0 -413
- package/data/packs/acts/artifacts/chapter-16-acts-16.md +0 -585
- package/data/packs/acts/artifacts/chapter-17-acts-17.md +0 -428
- package/data/packs/acts/artifacts/chapter-18-acts-18.md +0 -486
- package/data/packs/acts/artifacts/chapter-19-acts-19.md +0 -461
- package/data/packs/acts/artifacts/chapter-20-acts-20.md +0 -389
- package/data/packs/acts/artifacts/chapter-21-acts-21.md +0 -452
- package/data/packs/acts/artifacts/chapter-22-acts-22.md +0 -424
- package/data/packs/acts/artifacts/chapter-23-acts-23.md +0 -395
- package/data/packs/acts/artifacts/chapter-24-acts-24.md +0 -446
- package/data/packs/acts/artifacts/chapter-25-acts-25.md +0 -391
- package/data/packs/acts/artifacts/chapter-26-acts-26.md +0 -431
- package/data/packs/acts/artifacts/chapter-27-acts-27.md +0 -530
- package/data/packs/acts/artifacts/chapter-28-acts-28.md +0 -1871
- package/data/packs/acts/artifacts/chapters.manifest.json +0 -170
- package/data/packs/acts/artifacts/character_guide-creation.md +0 -112
- package/data/packs/acts/artifacts/discipleship_mentor-procedure.md +0 -154
- package/data/packs/acts/artifacts/discipleship_mentor-systems.md +0 -72
- package/data/packs/acts/artifacts/manifest.json +0 -197
- package/data/packs/acts/artifacts/stage-guide.md +0 -94
- package/data/packs/acts/pack.json +0 -6
- package/data/packs/acts/prompts/acts_player/defaults_config.json +0 -5
- package/data/packs/acts/prompts/acts_player/perceive.json +0 -29
- package/data/packs/acts/prompts/acts_player/perceive.prompt +0 -87
- package/data/packs/acts/prompts/acts_player/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/acts_room_moderator/defaults_config.json +0 -9
- package/data/packs/acts/prompts/acts_room_moderator/moderate.json +0 -34
- package/data/packs/acts/prompts/acts_room_moderator/moderate.prompt +0 -70
- package/data/packs/acts/prompts/acts_room_moderator/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/character_guide/defaults_config.json +0 -18
- package/data/packs/acts/prompts/character_guide/perceive.json +0 -29
- package/data/packs/acts/prompts/character_guide/perceive.prompt +0 -140
- package/data/packs/acts/prompts/character_guide/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/discipleship_mentor/defaults_config.json +0 -23
- package/data/packs/acts/prompts/discipleship_mentor/perceive.json +0 -33
- package/data/packs/acts/prompts/discipleship_mentor/perceive.prompt +0 -245
- package/data/packs/acts/prompts/discipleship_mentor/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/mentor_coach/defaults_config.json +0 -13
- package/data/packs/acts/prompts/mentor_coach/perceive.json +0 -29
- package/data/packs/acts/prompts/mentor_coach/perceive.prompt +0 -87
- package/data/packs/acts/prompts/mentor_coach/system_instruction.prompt +0 -0
- package/data/packs/acts/rooms/session.json +0 -14
- package/data/packs/acts/rooms/training.json +0 -58
- package/dist-sdk/server/src/tools/packs/acts/data/cards.d.ts +0 -53
- package/dist-sdk/server/src/tools/packs/acts/data/cards.js +0 -54
- package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.js +0 -185
- package/dist-sdk/server/src/tools/packs/acts/data/encounters.d.ts +0 -12
- package/dist-sdk/server/src/tools/packs/acts/data/encounters.js +0 -102
- package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.js +0 -196
- package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.js +0 -1311
- package/dist-sdk/server/src/tools/packs/acts/engine/cards.d.ts +0 -5
- package/dist-sdk/server/src/tools/packs/acts/engine/cards.js +0 -27
- package/dist-sdk/server/src/tools/packs/acts/engine/challenge.d.ts +0 -37
- package/dist-sdk/server/src/tools/packs/acts/engine/challenge.js +0 -120
- package/dist-sdk/server/src/tools/packs/acts/engine/dice.d.ts +0 -20
- package/dist-sdk/server/src/tools/packs/acts/engine/dice.js +0 -41
- package/dist-sdk/server/src/tools/packs/acts/engine/sheet.d.ts +0 -54
- package/dist-sdk/server/src/tools/packs/acts/engine/sheet.js +0 -200
- package/dist-sdk/server/src/tools/packs/acts/index.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/index.js +0 -24
- package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.js +0 -184
- package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.js +0 -107
- package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.d.ts +0 -3
- package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.js +0 -146
- package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.d.ts +0 -4
- package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.js +0 -241
- package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.d.ts +0 -3
- package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.js +0 -72
- package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.js +0 -75
- package/dist-sdk/server/src/tools/packs/acts/tools/shared.d.ts +0 -20
- package/dist-sdk/server/src/tools/packs/acts/tools/shared.js +0 -70
- package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.d.ts +0 -4
- package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.js +0 -215
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -113
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1648
- package/docs/classes/Agent.html +0 -801
- package/docs/classes/Briyah.html +0 -296
- package/docs/classes/BriyahConfigService.html +0 -119
- package/docs/classes/NativeToolRegistry.html +0 -166
- package/docs/classes/PackInstantiationService.html +0 -157
- package/docs/classes/PackService.html +0 -247
- package/docs/classes/Room.html +0 -1338
- package/docs/classes/RoomMessage.html +0 -290
- package/docs/enums/MessageAction.html +0 -136
- package/docs/functions/actsTools.html +0 -44
- package/docs/functions/availableToolPacks.html +0 -41
- package/docs/functions/buildMarkdown.html +0 -54
- package/docs/functions/dnd5eTools.html +0 -44
- package/docs/functions/installToolPacks.html +0 -48
- package/docs/functions/pageMarker.html +0 -45
- package/docs/functions/registerToolPacks.html +0 -54
- package/docs/functions/splitMarkdownIntoPages.html +0 -51
- package/docs/functions/stripWrappingFence.html +0 -52
- package/docs/hierarchy.html +0 -46
- package/docs/index.html +0 -595
- package/docs/interfaces/AgentCreationOptions.html +0 -125
- package/docs/interfaces/AgentInfo.html +0 -218
- package/docs/interfaces/AgentMessagesResponse.html +0 -74
- package/docs/interfaces/AppService.html +0 -3337
- package/docs/interfaces/Artifact.html +0 -95
- package/docs/interfaces/ArtifactMetadata.html +0 -112
- package/docs/interfaces/ArtifactWriteOptions.html +0 -90
- package/docs/interfaces/AttachDocumentResponse.html +0 -62
- package/docs/interfaces/BriyahConfigOptions.html +0 -124
- package/docs/interfaces/ChapterInfo.html +0 -62
- package/docs/interfaces/Character.html +0 -86
- package/docs/interfaces/ConversionAgent.html +0 -78
- package/docs/interfaces/CreateAgentResponse.html +0 -56
- package/docs/interfaces/CreateRoomResponse.html +0 -62
- package/docs/interfaces/CreateStoryResponse.html +0 -56
- package/docs/interfaces/FileList.html +0 -56
- package/docs/interfaces/FileMetadata.html +0 -89
- package/docs/interfaces/IConfigService.html +0 -79
- package/docs/interfaces/InstantiateModels.html +0 -64
- package/docs/interfaces/InstantiateRoomResult.html +0 -70
- package/docs/interfaces/LoadedPack.html +0 -131
- package/docs/interfaces/LoggingOptions.html +0 -92
- package/docs/interfaces/Message.html +0 -84
- package/docs/interfaces/ModelChoice.html +0 -73
- package/docs/interfaces/ModelInfo.html +0 -74
- package/docs/interfaces/NativeToolDefinition.html +0 -107
- package/docs/interfaces/PackAgentTemplate.html +0 -101
- package/docs/interfaces/PackRoomTemplate.html +0 -108
- package/docs/interfaces/PackView.html +0 -172
- package/docs/interfaces/PdfConversionOptions.html +0 -102
- package/docs/interfaces/PdfConversionResult.html +0 -97
- package/docs/interfaces/PdfMarkdownOptions.html +0 -198
- package/docs/interfaces/PdfMarkdownResult.html +0 -106
- package/docs/interfaces/PdfPageMarkdown.html +0 -94
- package/docs/interfaces/PreparedPromptResponse.html +0 -62
- package/docs/interfaces/ProcessTextResponse.html +0 -86
- package/docs/interfaces/PromptFile.html +0 -70
- package/docs/interfaces/PromptFileContent.html +0 -76
- package/docs/interfaces/PromptFilesResponse.html +0 -56
- package/docs/interfaces/PromptFolder.html +0 -80
- package/docs/interfaces/PromptFolderDefaults.html +0 -155
- package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
- package/docs/interfaces/PromptFoldersResponse.html +0 -56
- package/docs/interfaces/RoomDetails.html +0 -151
- package/docs/interfaces/RoomErrorUpdate.html +0 -82
- package/docs/interfaces/RoomInfo.html +0 -88
- package/docs/interfaces/RoomMessageUpdate.html +0 -113
- package/docs/interfaces/RoomMessagesResponse.html +0 -62
- package/docs/interfaces/SendMessageResult.html +0 -62
- package/docs/interfaces/StoryErrorEvent.html +0 -84
- package/docs/interfaces/StoryIdea.html +0 -74
- package/docs/interfaces/StoryInfo.html +0 -198
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
- package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
- package/docs/interfaces/StoryState.html +0 -108
- package/docs/interfaces/StoryStateEvent.html +0 -76
- package/docs/interfaces/ToolArtifact.html +0 -85
- package/docs/interfaces/ToolCaller.html +0 -77
- package/docs/interfaces/ToolDefinition.html +0 -80
- package/docs/interfaces/ToolHelpers.html +0 -105
- package/docs/interfaces/ToolPackDocuments.html +0 -100
- package/docs/interfaces/ToolParameter.html +0 -74
- package/docs/interfaces/ToolRoomAccess.html +0 -227
- package/docs/interfaces/ToolSummary.html +0 -74
- package/docs/interfaces/ToolsResponse.html +0 -68
- package/docs/interfaces/Transaction.html +0 -104
- package/docs/interfaces/TransactionHistoryResponse.html +0 -62
- package/docs/modules.html +0 -53
- package/docs/types/PackOrigin.html +0 -34
- package/docs/types/PromptScope.html +0 -34
- package/docs/types/RoomTurnMode.html +0 -42
- package/docs/types/RoomUpdate.html +0 -36
- package/docs/types/RosterOverrides.html +0 -42
- package/docs/types/ToolContext.html +0 -40
- package/docs/types/ToolRunResult.html +0 -34
- package/src/tools/packs/dnd5e/README.md +0 -867
|
@@ -9,8 +9,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.BalanceMessageService = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const events_1 = require("events");
|
|
12
|
+
/**
|
|
13
|
+
* Service for managing SSE connections for user balance updates
|
|
14
|
+
* Uses event-driven updates triggered by balance changes (no polling)
|
|
15
|
+
*/
|
|
12
16
|
let BalanceMessageService = class BalanceMessageService {
|
|
13
17
|
messageEmitters = new Map();
|
|
18
|
+
/**
|
|
19
|
+
* Gets or creates a message emitter for a user
|
|
20
|
+
* @param userId The user ID
|
|
21
|
+
* @returns The event emitter for this user
|
|
22
|
+
*/
|
|
14
23
|
getOrCreateEmitter(userId) {
|
|
15
24
|
let emitter = this.messageEmitters.get(userId);
|
|
16
25
|
if (!emitter) {
|
|
@@ -19,9 +28,20 @@ let BalanceMessageService = class BalanceMessageService {
|
|
|
19
28
|
}
|
|
20
29
|
return emitter;
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the message emitter for a user
|
|
33
|
+
* @param userId The user ID
|
|
34
|
+
* @returns The event emitter or undefined if not found
|
|
35
|
+
*/
|
|
22
36
|
getEmitter(userId) {
|
|
23
37
|
return this.messageEmitters.get(userId);
|
|
24
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Emits a balance update event for a user
|
|
41
|
+
* Called when user's balance changes
|
|
42
|
+
* @param userId The user ID
|
|
43
|
+
* @param balance The updated balance
|
|
44
|
+
*/
|
|
25
45
|
emitUpdate(userId, balance) {
|
|
26
46
|
const emitter = this.messageEmitters.get(userId);
|
|
27
47
|
if (emitter) {
|
|
@@ -31,6 +51,10 @@ let BalanceMessageService = class BalanceMessageService {
|
|
|
31
51
|
});
|
|
32
52
|
}
|
|
33
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Cleans up the message emitter for a user
|
|
56
|
+
* @param userId The user ID
|
|
57
|
+
*/
|
|
34
58
|
cleanup(userId) {
|
|
35
59
|
const emitter = this.messageEmitters.get(userId);
|
|
36
60
|
if (emitter) {
|
|
@@ -9,6 +9,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.BalanceModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const balance_message_service_1 = require("./balance-message.service");
|
|
12
|
+
/**
|
|
13
|
+
* Module providing balance-related services
|
|
14
|
+
* Provides BalanceMessageService for SSE balance updates
|
|
15
|
+
*/
|
|
12
16
|
let BalanceModule = class BalanceModule {
|
|
13
17
|
};
|
|
14
18
|
exports.BalanceModule = BalanceModule;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { UserPathsService } from '../config/user-paths.service';
|
|
2
2
|
import { BalanceMessageService } from './balance-message.service';
|
|
3
|
+
/**
|
|
4
|
+
* Service for managing user balance
|
|
5
|
+
* Tracks AI usage costs and enforces spending limits
|
|
6
|
+
*/
|
|
3
7
|
export declare class BalanceService {
|
|
4
8
|
private userId;
|
|
5
9
|
private userPaths;
|
|
@@ -8,11 +12,44 @@ export declare class BalanceService {
|
|
|
8
12
|
private startingBalance;
|
|
9
13
|
private balanceMessageService?;
|
|
10
14
|
constructor(userId: string, userPaths: UserPathsService, balanceMessageService?: BalanceMessageService);
|
|
15
|
+
/**
|
|
16
|
+
* Get current balance (loads from file)
|
|
17
|
+
* @returns Current balance as number
|
|
18
|
+
* @throws If balance file is corrupted
|
|
19
|
+
*/
|
|
11
20
|
getBalance(): number;
|
|
21
|
+
/**
|
|
22
|
+
* Get current markup (loads from file)
|
|
23
|
+
* @returns Current markup total
|
|
24
|
+
* @throws If markup file is corrupted
|
|
25
|
+
*/
|
|
12
26
|
getMarkup(): number;
|
|
27
|
+
/**
|
|
28
|
+
* Check if user has sufficient balance to make AI calls
|
|
29
|
+
* @returns true if balance >= 0, false otherwise
|
|
30
|
+
*/
|
|
13
31
|
hasSufficientBalance(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Decrement balance by specified amount
|
|
34
|
+
* @param amount Amount to subtract from balance
|
|
35
|
+
* @param markup Amount to add to markup total
|
|
36
|
+
* @throws If amount is negative
|
|
37
|
+
*/
|
|
14
38
|
decrementBalance(amount: number, markup?: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* Add funds to balance
|
|
41
|
+
* @param amount Amount to add to balance
|
|
42
|
+
* @throws If amount is negative or zero
|
|
43
|
+
*/
|
|
15
44
|
addBalance(amount: number): void;
|
|
45
|
+
/**
|
|
46
|
+
* Save balance to file
|
|
47
|
+
* @param balance New balance value
|
|
48
|
+
*/
|
|
16
49
|
private saveBalance;
|
|
50
|
+
/**
|
|
51
|
+
* Save markup to file
|
|
52
|
+
* @param markup
|
|
53
|
+
*/
|
|
17
54
|
private saveMarkup;
|
|
18
55
|
}
|
|
@@ -37,6 +37,10 @@ exports.BalanceService = void 0;
|
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const logger_1 = require("../common/logger");
|
|
40
|
+
/**
|
|
41
|
+
* Service for managing user balance
|
|
42
|
+
* Tracks AI usage costs and enforces spending limits
|
|
43
|
+
*/
|
|
40
44
|
class BalanceService {
|
|
41
45
|
userId;
|
|
42
46
|
userPaths;
|
|
@@ -48,6 +52,7 @@ class BalanceService {
|
|
|
48
52
|
this.userId = userId;
|
|
49
53
|
this.userPaths = userPaths;
|
|
50
54
|
this.balanceMessageService = balanceMessageService;
|
|
55
|
+
// Validate and load STARTING_BALANCE from environment
|
|
51
56
|
if (!process.env.STARTING_BALANCE) {
|
|
52
57
|
throw new Error('STARTING_BALANCE environment variable is required');
|
|
53
58
|
}
|
|
@@ -58,18 +63,28 @@ class BalanceService {
|
|
|
58
63
|
if (this.startingBalance < 0) {
|
|
59
64
|
throw new Error('STARTING_BALANCE must be non-negative');
|
|
60
65
|
}
|
|
66
|
+
// Set balance file path in user's userconfig directory
|
|
61
67
|
const userconfigPath = this.userPaths.getUserConfigDir();
|
|
62
68
|
this.balanceFilePath = path.join(userconfigPath, 'balance');
|
|
63
69
|
const commonConfigPath = this.userPaths.getCommonConfigDir();
|
|
64
70
|
this.markupFilePath = path.join(commonConfigPath, 'markup');
|
|
65
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Get current balance (loads from file)
|
|
74
|
+
* @returns Current balance as number
|
|
75
|
+
* @throws If balance file is corrupted
|
|
76
|
+
*/
|
|
66
77
|
getBalance() {
|
|
67
78
|
try {
|
|
79
|
+
// Check if balance file exists
|
|
68
80
|
if (!fs.existsSync(this.balanceFilePath)) {
|
|
81
|
+
// Create with starting balance for new users
|
|
69
82
|
this.saveBalance(this.startingBalance);
|
|
70
83
|
return this.startingBalance;
|
|
71
84
|
}
|
|
85
|
+
// Read balance file
|
|
72
86
|
const balanceStr = fs.readFileSync(this.balanceFilePath, 'utf-8').trim();
|
|
87
|
+
// Parse number
|
|
73
88
|
const balance = parseFloat(balanceStr);
|
|
74
89
|
if (isNaN(balance)) {
|
|
75
90
|
logger_1.logger.error(`Balance file corrupted for user ${this.userId}, resetting to starting balance`);
|
|
@@ -80,16 +95,26 @@ class BalanceService {
|
|
|
80
95
|
}
|
|
81
96
|
catch (error) {
|
|
82
97
|
logger_1.logger.error(`Error reading balance for user ${this.userId}:`, error);
|
|
98
|
+
// Return starting balance as fallback
|
|
83
99
|
return this.startingBalance;
|
|
84
100
|
}
|
|
85
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Get current markup (loads from file)
|
|
104
|
+
* @returns Current markup total
|
|
105
|
+
* @throws If markup file is corrupted
|
|
106
|
+
*/
|
|
86
107
|
getMarkup() {
|
|
87
108
|
try {
|
|
109
|
+
// Check if balance file exists
|
|
88
110
|
if (!fs.existsSync(this.markupFilePath)) {
|
|
111
|
+
// Create with starting markup
|
|
89
112
|
this.saveMarkup(0);
|
|
90
113
|
return 0;
|
|
91
114
|
}
|
|
115
|
+
// Read balance file
|
|
92
116
|
const markupStr = fs.readFileSync(this.markupFilePath, 'utf-8').trim();
|
|
117
|
+
// Parse number
|
|
93
118
|
const markup = parseFloat(markupStr);
|
|
94
119
|
if (isNaN(markup)) {
|
|
95
120
|
logger_1.logger.error(`Markup file corrupted, resetting to 0`);
|
|
@@ -100,13 +125,24 @@ class BalanceService {
|
|
|
100
125
|
}
|
|
101
126
|
catch (error) {
|
|
102
127
|
logger_1.logger.error(`Error reading markup:`, error);
|
|
128
|
+
// Return starting balance as fallback
|
|
103
129
|
return 0;
|
|
104
130
|
}
|
|
105
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if user has sufficient balance to make AI calls
|
|
134
|
+
* @returns true if balance >= 0, false otherwise
|
|
135
|
+
*/
|
|
106
136
|
hasSufficientBalance() {
|
|
107
137
|
const balance = this.getBalance();
|
|
108
138
|
return balance >= 0;
|
|
109
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Decrement balance by specified amount
|
|
142
|
+
* @param amount Amount to subtract from balance
|
|
143
|
+
* @param markup Amount to add to markup total
|
|
144
|
+
* @throws If amount is negative
|
|
145
|
+
*/
|
|
110
146
|
decrementBalance(amount, markup = 0) {
|
|
111
147
|
if (amount < 0) {
|
|
112
148
|
throw new Error('Amount must be positive');
|
|
@@ -118,6 +154,11 @@ class BalanceService {
|
|
|
118
154
|
const newMarkup = currentMarkup + markup;
|
|
119
155
|
this.saveMarkup(newMarkup);
|
|
120
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Add funds to balance
|
|
159
|
+
* @param amount Amount to add to balance
|
|
160
|
+
* @throws If amount is negative or zero
|
|
161
|
+
*/
|
|
121
162
|
addBalance(amount) {
|
|
122
163
|
if (amount <= 0) {
|
|
123
164
|
throw new Error('Amount must be positive');
|
|
@@ -126,13 +167,20 @@ class BalanceService {
|
|
|
126
167
|
const newBalance = currentBalance + amount;
|
|
127
168
|
this.saveBalance(newBalance);
|
|
128
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Save balance to file
|
|
172
|
+
* @param balance New balance value
|
|
173
|
+
*/
|
|
129
174
|
saveBalance(balance) {
|
|
130
175
|
try {
|
|
176
|
+
// Ensure userconfig directory exists
|
|
131
177
|
const userconfigPath = this.userPaths.getUserConfigDir();
|
|
132
178
|
if (!fs.existsSync(userconfigPath)) {
|
|
133
179
|
fs.mkdirSync(userconfigPath, { recursive: true });
|
|
134
180
|
}
|
|
181
|
+
// Write balance to file as plain text
|
|
135
182
|
fs.writeFileSync(this.balanceFilePath, balance.toString(), 'utf-8');
|
|
183
|
+
// Emit SSE update if service is available
|
|
136
184
|
if (this.balanceMessageService) {
|
|
137
185
|
this.balanceMessageService.emitUpdate(this.userId, balance);
|
|
138
186
|
}
|
|
@@ -142,12 +190,18 @@ class BalanceService {
|
|
|
142
190
|
throw error;
|
|
143
191
|
}
|
|
144
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Save markup to file
|
|
195
|
+
* @param markup
|
|
196
|
+
*/
|
|
145
197
|
saveMarkup(markup) {
|
|
146
198
|
try {
|
|
199
|
+
// Ensure userconfig directory exists
|
|
147
200
|
const commonConfigPath = this.userPaths.getCommonConfigDir();
|
|
148
201
|
if (!fs.existsSync(commonConfigPath)) {
|
|
149
202
|
fs.mkdirSync(commonConfigPath, { recursive: true });
|
|
150
203
|
}
|
|
204
|
+
// Write balance to file as plain text
|
|
151
205
|
fs.writeFileSync(this.markupFilePath, markup.toString(), 'utf-8');
|
|
152
206
|
}
|
|
153
207
|
catch (error) {
|
|
@@ -7,25 +7,46 @@ export declare class StripeController {
|
|
|
7
7
|
private readonly stripeService;
|
|
8
8
|
private readonly userServiceManager;
|
|
9
9
|
constructor(stripeService: StripeService, userServiceManager: UserServiceManager);
|
|
10
|
+
/**
|
|
11
|
+
* Create a Payment Intent for adding credit
|
|
12
|
+
*/
|
|
10
13
|
createPaymentIntent(req: ExpressRequest & {
|
|
11
14
|
user: {
|
|
12
15
|
userId: string;
|
|
13
16
|
};
|
|
14
17
|
}, body: CreatePaymentIntentRequest): Promise<CreatePaymentIntentResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a Checkout Session for adding credit via Discord
|
|
20
|
+
*/
|
|
15
21
|
createCheckoutSession(req: ExpressRequest & {
|
|
16
22
|
user: {
|
|
17
23
|
userId: string;
|
|
18
24
|
};
|
|
19
25
|
}, body: CreateCheckoutSessionRequest): Promise<CreateCheckoutSessionResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Get user balance for a completed Stripe checkout session
|
|
28
|
+
* Public endpoint — no JWT required, used by the payment-success page
|
|
29
|
+
*/
|
|
20
30
|
getCheckoutSessionBalance(sessionId: string): Promise<{
|
|
21
31
|
balance: number;
|
|
22
32
|
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Get Stripe configuration (publishable key)
|
|
35
|
+
* This endpoint is authenticated and returns the publishable key needed for Stripe.js initialization
|
|
36
|
+
*/
|
|
23
37
|
getStripeConfig(): Promise<{
|
|
24
38
|
publishableKey: string;
|
|
25
39
|
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Stripe webhook endpoint
|
|
42
|
+
* Handles payment_intent.succeeded and payment_intent.payment_failed events
|
|
43
|
+
*/
|
|
26
44
|
handleWebhook(req: RawBodyRequest<ExpressRequest>, signature: string): Promise<{
|
|
27
45
|
received: boolean;
|
|
28
46
|
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Get transaction history
|
|
49
|
+
*/
|
|
29
50
|
getTransactionHistory(req: ExpressRequest & {
|
|
30
51
|
user: {
|
|
31
52
|
userId: string;
|
|
@@ -27,42 +27,67 @@ let StripeController = class StripeController {
|
|
|
27
27
|
this.stripeService = stripeService;
|
|
28
28
|
this.userServiceManager = userServiceManager;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a Payment Intent for adding credit
|
|
32
|
+
*/
|
|
30
33
|
async createPaymentIntent(req, body) {
|
|
31
34
|
const userId = req.user.userId;
|
|
32
35
|
const { amount } = body;
|
|
36
|
+
// Get user's AppService
|
|
33
37
|
const appService = this.userServiceManager.getAppService(userId);
|
|
38
|
+
// Create Payment Intent
|
|
34
39
|
const result = await this.stripeService.createPaymentIntent(userId, amount, appService);
|
|
35
40
|
return result;
|
|
36
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a Checkout Session for adding credit via Discord
|
|
44
|
+
*/
|
|
37
45
|
async createCheckoutSession(req, body) {
|
|
38
46
|
const userId = req.user.userId;
|
|
39
47
|
const { amount } = body;
|
|
48
|
+
// Get user's AppService
|
|
40
49
|
const appService = this.userServiceManager.getAppService(userId);
|
|
50
|
+
// Create Checkout Session
|
|
41
51
|
const result = await this.stripeService.createCheckoutSession(userId, amount, appService);
|
|
42
52
|
return result;
|
|
43
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Get user balance for a completed Stripe checkout session
|
|
56
|
+
* Public endpoint — no JWT required, used by the payment-success page
|
|
57
|
+
*/
|
|
44
58
|
async getCheckoutSessionBalance(sessionId) {
|
|
45
59
|
const { userId } = await this.stripeService.getCheckoutSessionUser(sessionId);
|
|
46
60
|
const appService = this.userServiceManager.getAppService(userId);
|
|
47
61
|
return { balance: appService.getBalance() };
|
|
48
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Get Stripe configuration (publishable key)
|
|
65
|
+
* This endpoint is authenticated and returns the publishable key needed for Stripe.js initialization
|
|
66
|
+
*/
|
|
49
67
|
async getStripeConfig() {
|
|
50
68
|
return this.stripeService.getStripeConfig();
|
|
51
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Stripe webhook endpoint
|
|
72
|
+
* Handles payment_intent.succeeded and payment_intent.payment_failed events
|
|
73
|
+
*/
|
|
52
74
|
async handleWebhook(req, signature) {
|
|
53
75
|
logger_1.logger.log('[Stripe Webhook] Received webhook request');
|
|
54
76
|
if (!signature) {
|
|
55
77
|
logger_1.logger.error('[Stripe Webhook] Missing stripe-signature header');
|
|
56
78
|
throw new common_1.BadRequestException('Missing stripe-signature header');
|
|
57
79
|
}
|
|
80
|
+
// Get raw body for signature verification
|
|
58
81
|
const rawBody = req.rawBody;
|
|
59
82
|
if (!rawBody) {
|
|
60
83
|
logger_1.logger.error('[Stripe Webhook] Missing request body');
|
|
61
84
|
throw new common_1.BadRequestException('Missing request body');
|
|
62
85
|
}
|
|
63
86
|
logger_1.logger.log('[Stripe Webhook] Verifying webhook signature...');
|
|
87
|
+
// Verify webhook signature
|
|
64
88
|
const event = this.stripeService.verifyWebhookSignature(rawBody, signature);
|
|
65
89
|
logger_1.logger.log(`[Stripe Webhook] Event type: ${event.type}, Event ID: ${event.id}`);
|
|
90
|
+
// Handle event
|
|
66
91
|
switch (event.type) {
|
|
67
92
|
case 'payment_intent.succeeded': {
|
|
68
93
|
logger_1.logger.log('[Stripe Webhook] Matched payment_intent.succeeded case');
|
|
@@ -72,7 +97,9 @@ let StripeController = class StripeController {
|
|
|
72
97
|
logger_1.logger.error('Payment Intent missing userId in metadata');
|
|
73
98
|
return { received: true };
|
|
74
99
|
}
|
|
100
|
+
// Get user's AppService
|
|
75
101
|
const appService = this.userServiceManager.getAppService(userId);
|
|
102
|
+
// Handle successful payment
|
|
76
103
|
await this.stripeService.handlePaymentIntentSucceeded(paymentIntent, appService);
|
|
77
104
|
break;
|
|
78
105
|
}
|
|
@@ -84,7 +111,9 @@ let StripeController = class StripeController {
|
|
|
84
111
|
logger_1.logger.error('[Stripe Webhook] Payment Intent missing userId in metadata');
|
|
85
112
|
return { received: true };
|
|
86
113
|
}
|
|
114
|
+
// Get user's AppService
|
|
87
115
|
const appService = this.userServiceManager.getAppService(userId);
|
|
116
|
+
// Handle failed payment
|
|
88
117
|
await this.stripeService.handlePaymentIntentFailed(paymentIntent, appService);
|
|
89
118
|
break;
|
|
90
119
|
}
|
|
@@ -94,11 +123,17 @@ let StripeController = class StripeController {
|
|
|
94
123
|
logger_1.logger.log('[Stripe Webhook] Webhook processed successfully');
|
|
95
124
|
return { received: true };
|
|
96
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Get transaction history
|
|
128
|
+
*/
|
|
97
129
|
async getTransactionHistory(req, limit, offset) {
|
|
98
130
|
const userId = req.user.userId;
|
|
131
|
+
// Parse query parameters
|
|
99
132
|
const parsedLimit = limit ? parseInt(limit, 10) : 50;
|
|
100
133
|
const parsedOffset = offset ? parseInt(offset, 10) : 0;
|
|
134
|
+
// Get user's AppService
|
|
101
135
|
const appService = this.userServiceManager.getAppService(userId);
|
|
136
|
+
// Get transactions
|
|
102
137
|
const result = await appService.getTransactions(parsedLimit, parsedOffset);
|
|
103
138
|
return result;
|
|
104
139
|
}
|
|
@@ -3,6 +3,9 @@ import { AppService } from '../app.service';
|
|
|
3
3
|
type StripeInstance = ReturnType<typeof Stripe>;
|
|
4
4
|
type StripeEvent = ReturnType<StripeInstance['webhooks']['constructEvent']>;
|
|
5
5
|
type StripePaymentIntent = Awaited<ReturnType<StripeInstance['paymentIntents']['retrieve']>>;
|
|
6
|
+
/**
|
|
7
|
+
* Service for managing Stripe payment operations
|
|
8
|
+
*/
|
|
6
9
|
export declare class StripeService {
|
|
7
10
|
private stripe;
|
|
8
11
|
private minPaymentAmount;
|
|
@@ -10,22 +13,62 @@ export declare class StripeService {
|
|
|
10
13
|
private publishableKey;
|
|
11
14
|
private webhookSecret;
|
|
12
15
|
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Create a Payment Intent for adding credit
|
|
18
|
+
* @param userId User ID
|
|
19
|
+
* @param amount Amount in dollars
|
|
20
|
+
* @param appService App service for the user
|
|
21
|
+
* @returns Client secret and publishable key
|
|
22
|
+
*/
|
|
13
23
|
createPaymentIntent(userId: string, amount: number, appService: AppService): Promise<{
|
|
14
24
|
clientSecret: string;
|
|
15
25
|
publishableKey: string;
|
|
16
26
|
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Create a Checkout Session for adding credit via Discord
|
|
29
|
+
* @param userId User ID
|
|
30
|
+
* @param amount Amount in dollars
|
|
31
|
+
* @param appService App service for the user
|
|
32
|
+
* @returns Checkout session URL
|
|
33
|
+
*/
|
|
17
34
|
createCheckoutSession(userId: string, amount: number, appService: AppService): Promise<{
|
|
18
35
|
url: string;
|
|
19
36
|
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieve a checkout session and return the userId from its metadata
|
|
39
|
+
* Used by the payment-success page to look up the user's balance without a JWT
|
|
40
|
+
* @param sessionId Stripe checkout session ID
|
|
41
|
+
* @returns userId and payment status
|
|
42
|
+
*/
|
|
20
43
|
getCheckoutSessionUser(sessionId: string): Promise<{
|
|
21
44
|
userId: string;
|
|
22
45
|
paymentStatus: string;
|
|
23
46
|
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Get Stripe configuration
|
|
49
|
+
* @returns Stripe publishable key for frontend initialization
|
|
50
|
+
*/
|
|
24
51
|
getStripeConfig(): {
|
|
25
52
|
publishableKey: string;
|
|
26
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Verify webhook signature from Stripe
|
|
56
|
+
* @param rawBody Raw request body
|
|
57
|
+
* @param signature Stripe signature from header
|
|
58
|
+
* @returns Stripe event
|
|
59
|
+
*/
|
|
27
60
|
verifyWebhookSignature(rawBody: Buffer | string, signature: string): StripeEvent;
|
|
61
|
+
/**
|
|
62
|
+
* Handle successful payment
|
|
63
|
+
* @param paymentIntent Payment Intent
|
|
64
|
+
* @param appService App service for the user
|
|
65
|
+
*/
|
|
28
66
|
handlePaymentIntentSucceeded(paymentIntent: StripePaymentIntent, appService: AppService): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Handle failed payment
|
|
69
|
+
* @param paymentIntent Payment Intent
|
|
70
|
+
* @param appService App service for the user
|
|
71
|
+
*/
|
|
29
72
|
handlePaymentIntentFailed(paymentIntent: StripePaymentIntent, appService: AppService): Promise<void>;
|
|
30
73
|
}
|
|
31
74
|
export {};
|
|
@@ -16,6 +16,9 @@ exports.StripeService = void 0;
|
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const stripe_1 = __importDefault(require("stripe"));
|
|
18
18
|
const logger_1 = require("../common/logger");
|
|
19
|
+
/**
|
|
20
|
+
* Service for managing Stripe payment operations
|
|
21
|
+
*/
|
|
19
22
|
let StripeService = class StripeService {
|
|
20
23
|
stripe;
|
|
21
24
|
minPaymentAmount;
|
|
@@ -23,6 +26,7 @@ let StripeService = class StripeService {
|
|
|
23
26
|
publishableKey;
|
|
24
27
|
webhookSecret;
|
|
25
28
|
constructor() {
|
|
29
|
+
// Validate environment variables
|
|
26
30
|
if (!process.env.STRIPE_SECRET_KEY) {
|
|
27
31
|
throw new Error('STRIPE_SECRET_KEY environment variable is required');
|
|
28
32
|
}
|
|
@@ -32,15 +36,25 @@ let StripeService = class StripeService {
|
|
|
32
36
|
if (!process.env.STRIPE_WEBHOOK_SECRET) {
|
|
33
37
|
throw new Error('STRIPE_WEBHOOK_SECRET environment variable is required');
|
|
34
38
|
}
|
|
39
|
+
// Initialize Stripe
|
|
35
40
|
this.stripe = (0, stripe_1.default)(process.env.STRIPE_SECRET_KEY, {
|
|
36
41
|
apiVersion: '2026-03-25.dahlia',
|
|
37
42
|
});
|
|
38
43
|
this.publishableKey = process.env.STRIPE_PUBLISHABLE_KEY;
|
|
39
44
|
this.webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
|
|
45
|
+
// Load payment limits
|
|
40
46
|
this.minPaymentAmount = parseFloat(process.env.MIN_PAYMENT_AMOUNT || '5.00');
|
|
41
47
|
this.maxPaymentAmount = parseFloat(process.env.MAX_PAYMENT_AMOUNT || '500.00');
|
|
42
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Create a Payment Intent for adding credit
|
|
51
|
+
* @param userId User ID
|
|
52
|
+
* @param amount Amount in dollars
|
|
53
|
+
* @param appService App service for the user
|
|
54
|
+
* @returns Client secret and publishable key
|
|
55
|
+
*/
|
|
43
56
|
async createPaymentIntent(userId, amount, appService) {
|
|
57
|
+
// Validate amount
|
|
44
58
|
if (!amount || amount <= 0) {
|
|
45
59
|
throw new common_1.BadRequestException('Amount must be greater than 0');
|
|
46
60
|
}
|
|
@@ -51,7 +65,9 @@ let StripeService = class StripeService {
|
|
|
51
65
|
throw new common_1.BadRequestException(`Amount must not exceed $${this.maxPaymentAmount.toFixed(2)}`);
|
|
52
66
|
}
|
|
53
67
|
try {
|
|
68
|
+
// Convert dollars to cents
|
|
54
69
|
const amountInCents = Math.round(amount * 100);
|
|
70
|
+
// Create Payment Intent with userId in metadata
|
|
55
71
|
const paymentIntent = await this.stripe.paymentIntents.create({
|
|
56
72
|
amount: amountInCents,
|
|
57
73
|
currency: 'usd',
|
|
@@ -62,6 +78,7 @@ let StripeService = class StripeService {
|
|
|
62
78
|
enabled: true,
|
|
63
79
|
},
|
|
64
80
|
});
|
|
81
|
+
// Record pending transaction
|
|
65
82
|
await appService.recordTransaction(amount, paymentIntent.id, 'pending');
|
|
66
83
|
return {
|
|
67
84
|
clientSecret: paymentIntent.client_secret,
|
|
@@ -73,7 +90,15 @@ let StripeService = class StripeService {
|
|
|
73
90
|
throw new common_1.InternalServerErrorException('Failed to create payment intent');
|
|
74
91
|
}
|
|
75
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a Checkout Session for adding credit via Discord
|
|
95
|
+
* @param userId User ID
|
|
96
|
+
* @param amount Amount in dollars
|
|
97
|
+
* @param appService App service for the user
|
|
98
|
+
* @returns Checkout session URL
|
|
99
|
+
*/
|
|
76
100
|
async createCheckoutSession(userId, amount, appService) {
|
|
101
|
+
// Validate amount (same validation as payment intent)
|
|
77
102
|
if (!amount || amount <= 0) {
|
|
78
103
|
throw new common_1.BadRequestException('Amount must be greater than 0');
|
|
79
104
|
}
|
|
@@ -84,7 +109,9 @@ let StripeService = class StripeService {
|
|
|
84
109
|
throw new common_1.BadRequestException(`Amount must not exceed $${this.maxPaymentAmount.toFixed(2)}`);
|
|
85
110
|
}
|
|
86
111
|
try {
|
|
112
|
+
// Convert dollars to cents
|
|
87
113
|
const amountInCents = Math.round(amount * 100);
|
|
114
|
+
// Create Checkout Session
|
|
88
115
|
const session = await this.stripe.checkout.sessions.create({
|
|
89
116
|
payment_method_types: ['card'],
|
|
90
117
|
line_items: [
|
|
@@ -112,6 +139,7 @@ let StripeService = class StripeService {
|
|
|
112
139
|
},
|
|
113
140
|
},
|
|
114
141
|
});
|
|
142
|
+
// Record pending transaction
|
|
115
143
|
if (session.payment_intent) {
|
|
116
144
|
await appService.recordTransaction(amount, session.payment_intent, 'pending');
|
|
117
145
|
}
|
|
@@ -124,6 +152,12 @@ let StripeService = class StripeService {
|
|
|
124
152
|
throw new common_1.InternalServerErrorException('Failed to create checkout session');
|
|
125
153
|
}
|
|
126
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Retrieve a checkout session and return the userId from its metadata
|
|
157
|
+
* Used by the payment-success page to look up the user's balance without a JWT
|
|
158
|
+
* @param sessionId Stripe checkout session ID
|
|
159
|
+
* @returns userId and payment status
|
|
160
|
+
*/
|
|
127
161
|
async getCheckoutSessionUser(sessionId) {
|
|
128
162
|
try {
|
|
129
163
|
const session = await this.stripe.checkout.sessions.retrieve(sessionId);
|
|
@@ -140,11 +174,21 @@ let StripeService = class StripeService {
|
|
|
140
174
|
throw new common_1.BadRequestException('Invalid or expired session ID');
|
|
141
175
|
}
|
|
142
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Get Stripe configuration
|
|
179
|
+
* @returns Stripe publishable key for frontend initialization
|
|
180
|
+
*/
|
|
143
181
|
getStripeConfig() {
|
|
144
182
|
return {
|
|
145
183
|
publishableKey: this.publishableKey,
|
|
146
184
|
};
|
|
147
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Verify webhook signature from Stripe
|
|
188
|
+
* @param rawBody Raw request body
|
|
189
|
+
* @param signature Stripe signature from header
|
|
190
|
+
* @returns Stripe event
|
|
191
|
+
*/
|
|
148
192
|
verifyWebhookSignature(rawBody, signature) {
|
|
149
193
|
try {
|
|
150
194
|
return this.stripe.webhooks.constructEvent(rawBody, signature, this.webhookSecret);
|
|
@@ -154,6 +198,11 @@ let StripeService = class StripeService {
|
|
|
154
198
|
throw new common_1.BadRequestException('Invalid webhook signature');
|
|
155
199
|
}
|
|
156
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Handle successful payment
|
|
203
|
+
* @param paymentIntent Payment Intent
|
|
204
|
+
* @param appService App service for the user
|
|
205
|
+
*/
|
|
157
206
|
async handlePaymentIntentSucceeded(paymentIntent, appService) {
|
|
158
207
|
try {
|
|
159
208
|
const userId = paymentIntent.metadata.userId;
|
|
@@ -162,22 +211,29 @@ let StripeService = class StripeService {
|
|
|
162
211
|
logger_1.logger.error('Payment Intent missing userId in metadata:', paymentIntent.id);
|
|
163
212
|
return;
|
|
164
213
|
}
|
|
214
|
+
// Convert cents to dollars
|
|
165
215
|
const amount = paymentIntent.amount / 100;
|
|
166
216
|
logger_1.logger.log(`[Stripe Webhook] Amount: $${amount.toFixed(2)}`);
|
|
217
|
+
// Check if transaction already processed
|
|
167
218
|
const existingTransaction = await appService.getTransactionByPaymentId(paymentIntent.id);
|
|
168
219
|
logger_1.logger.log(`[Stripe Webhook] Existing transaction:`, existingTransaction);
|
|
169
220
|
if (existingTransaction?.status === 'succeeded') {
|
|
170
221
|
logger_1.logger.log(`Transaction ${paymentIntent.id} already processed, skipping`);
|
|
171
222
|
return;
|
|
172
223
|
}
|
|
224
|
+
// Get balance before
|
|
173
225
|
const balanceBefore = await appService.getBalance();
|
|
174
226
|
logger_1.logger.log(`[Stripe Webhook] Balance before: $${balanceBefore.toFixed(2)}`);
|
|
227
|
+
// Add balance
|
|
175
228
|
logger_1.logger.log(`[Stripe Webhook] Adding $${amount.toFixed(2)} to balance`);
|
|
176
229
|
await appService.addBalance(amount);
|
|
230
|
+
// Get balance after
|
|
177
231
|
const balanceAfter = await appService.getBalance();
|
|
178
232
|
logger_1.logger.log(`[Stripe Webhook] Balance after: $${balanceAfter.toFixed(2)}`);
|
|
233
|
+
// Update transaction status
|
|
179
234
|
logger_1.logger.log(`[Stripe Webhook] Updating transaction status to 'succeeded'`);
|
|
180
235
|
await appService.updateTransactionStatus(paymentIntent.id, 'succeeded');
|
|
236
|
+
// Resume any paused stories now that balance is positive
|
|
181
237
|
logger_1.logger.log(`[Stripe Webhook] Checking for paused stories to resume...`);
|
|
182
238
|
const resumedCount = await appService.resumePausedStories();
|
|
183
239
|
if (resumedCount > 0) {
|
|
@@ -190,6 +246,11 @@ let StripeService = class StripeService {
|
|
|
190
246
|
throw error;
|
|
191
247
|
}
|
|
192
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Handle failed payment
|
|
251
|
+
* @param paymentIntent Payment Intent
|
|
252
|
+
* @param appService App service for the user
|
|
253
|
+
*/
|
|
193
254
|
async handlePaymentIntentFailed(paymentIntent, appService) {
|
|
194
255
|
try {
|
|
195
256
|
const userId = paymentIntent.metadata.userId;
|
|
@@ -197,6 +258,7 @@ let StripeService = class StripeService {
|
|
|
197
258
|
logger_1.logger.error('Payment Intent missing userId in metadata:', paymentIntent.id);
|
|
198
259
|
return;
|
|
199
260
|
}
|
|
261
|
+
// Update transaction status
|
|
200
262
|
await appService.updateTransactionStatus(paymentIntent.id, 'failed');
|
|
201
263
|
logger_1.logger.log(`Payment failed for user ${userId}: ${paymentIntent.id}`);
|
|
202
264
|
}
|