Skip to content

Commit 8cf3009

Browse files
authored
Merge pull request #74 from Callgent/blog
Blog
2 parents 31aac90 + 9e502a2 commit 8cf3009

26 files changed

Lines changed: 23477 additions & 18 deletions

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Set the production url of your site here
44
SITE_URL=http://localhost:3030
5+
APP_URL=http://localhost:8000
56
SITE_BASE_PATH=/
67
SITE_SIGNUP_URL=http://localhost:3030/signup
78

blog/2024-03-16-nestjs+prisma-transaction-propagation-and-test-rollback-and-tenancy.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ RLS is only applicable in `postgreSQL`
170170
171171
### How to implement
172172
173-
1. in `schema.prisma` file, set db column `tenant_id` default value to context variable `tenancy.tenantPk`,
173+
1. in `schema.prisma` file, set db column `tenant_id` default value to context variable `abac.tenantPk`,
174174
175175
```prisma
176-
tenant_id Int @default(dbgenerated("(current_setting('tenancy.tenantPk'))::int"))
176+
tenant_id Int @default(dbgenerated("(current_setting('abac.tenantPk'))::int"))
177177
```
178178
179179
2. enable postgres row level security(RLS), so that we can filter data by `tenant_id` automatically:
@@ -189,27 +189,27 @@ RLS is only applicable in `postgreSQL`
189189
4. extend `PrismaClient` to set `tenant_id` before any query, refer to [prisma-tenancy.provider.ts](https://github.com/Callgent/callgent-api/blob/main/src/infra/repo/tenancy/prisma-tenancy.provider.ts),
190190
191191
```sql
192-
SELECT set_config('tenancy.tenantPk', cls.get('TENANT_ID') ...
192+
SELECT set_config('abac.tenantPk', cls.get('TENANT_ID') ...
193193
```
194194
195195
5. if you want to bypass rls, for example, by admin, or looking up the logon user to determine their tenant ID:
196196
197197
```sql
198-
CREATE POLICY bypass_rls_policy ON "User" USING (current_setting('tenancy.bypass_rls', TRUE)::text = 'on');
198+
CREATE POLICY bypass_rls_policy ON "User" USING (current_setting('abac.bypass_rls', TRUE)::text = 'on');
199199
```
200200
201-
then when you want to bypass rls, you must set `tenancy.bypass_rls` to `on` before running the query, refer to [prisma-tenancy.service.ts](https://github.com/Callgent/callgent-api/blob/main/src/infra/repo/tenancy/prisma-tenancy.service.ts),
201+
then when you want to bypass rls, you must set `abac.bypass_rls` to `on` before running the query, refer to [prisma-tenancy.service.ts](https://github.com/Callgent/callgent-api/blob/main/src/infra/repo/tenancy/prisma-tenancy.service.ts),
202202
203203
```js
204-
await prisma.$executeRaw`SELECT set_config('tenancy.bypass_rls', 'on', TRUE)`;
204+
await prisma.$executeRaw`SELECT set_config('abac.bypass_rls', 'on', TRUE)`;
205205
```
206206
207207
### how it works
208208
209209
1. `tenantPk` is set into `cls` context on each request from current user.
210-
2. `PrismaClient` is extended on `$allOperations` to set `tenantPk` into db variable `tenancy.tenantPk` before any query.
211-
3. postgreSQL RLS is enabled, so that all queries will be filtered by `tenancy.tenantPk` automatically.
212-
4. on db `insert` operation, `tenancy.tenantPk` is set into `tenant_id` column as default value.
210+
2. `PrismaClient` is extended on `$allOperations` to set `tenantPk` into db variable `abac.tenantPk` before any query.
211+
3. postgreSQL RLS is enabled, so that all queries will be filtered by `abac.tenantPk` automatically.
212+
4. on db `insert` operation, `abac.tenantPk` is set into `tenant_id` column as default value.
213213
214214
## Integrate them all
215215

docs/quick-start/pricing.mdx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
sidebar_position: 5
3+
tags: [Demo, Getting Started, Monetization]
4+
---
5+
6+
# Easily Monetize with Callgent
7+
8+
Callgent offers simple and flexible monetization options! With just a few minutes of configuration, your Callgent can start generating revenue!
9+
10+
## 🚀 Start Monetizing in 3 Easy Steps
11+
12+
:::tip
13+
This article assumes you already know [how to create a Callgent](/docs/quick-start/create-a-new-callgent)
14+
:::
15+
16+
import SelectCallgent from "@site/src/components/module/select-callgent"
17+
import Publish from "@site/src/components/quick-start/publish"
18+
19+
### 1. Select Your Callgent
20+
21+
<pre>
22+
<SelectCallgent />
23+
</pre>
24+
25+
### 2. Configure Authentication
26+
Set up authentication to ensure service security and specify who pays for the request. Different types of locks indicate different roles.
27+
28+
**Client Entries**: Used for identity verification. If the lock is open, the creator pays; if closed, the caller pays by default. Of cause you may specify a fixed payer.
29+
30+
**Service Adaptors**: Indicate how the current request will be charged.
31+
32+
![Authentication Setup](/img/tutorials/auth.jpg)
33+
34+
## 💸 Flexible Pricing Models
35+
36+
![Pricing Options](/img/tutorials/pricing.jpg)
37+
38+
### Option 1: Per-Call Billing (Ideal for Beginners)
39+
Charge a fixed amount per API call. Suitable for standardized services.
40+
41+
- **Use Case**: Fixed, predictable query services
42+
- **Example**: $0.01 per call
43+
- **How to Set**: Simply input the amount in the pricing field
44+
45+
### Option 2: Per-Token Billing (Great for Content Services)
46+
Charge based on token usage. Best for dynamic content services like text generation or translation.
47+
48+
- **Use Case**: Services with variable-length output
49+
- **Example Code**:
50+
```javascript
51+
// Charge $0.0002 per token
52+
function calcPrice(req) {
53+
return req.tokenUsage * 0.0002;
54+
}
55+
```
56+
57+
### 3. Enable Monetization
58+
In Figure 1 **test**, find the newly imported API. Click the lock icon, choose your authentication method, and confirm the lock is closed to complete the setup.
59+
<a href="/solutions/showcase/user-as-a-service/service-design" target="_blank">How to import an API?</a>
60+
61+
## 🔗 Test Your Monetized Callgent
62+
Once setup is complete, you can <Publish name='publish' /> your Callgent service for users to call.
63+
64+
Learn more: [Call the Callgent](/docs/quick-start/call-the-callgent)
65+
66+
## 🌟 Benefits of Monetizing with Callgent
67+
68+
- **Zero Coding Required**: Start monetizing without writing any code
69+
- **Instant Activation**: Monetization takes effect immediately upon setup
70+
- **Full Transparency**: Users can clearly see the cost breakdown
71+
- **Flexible Options**: Choose the billing method that best fits your service
72+
- **[Transaction Details](/redirect?app=billing)**: View your income and expense records
73+
74+
![Transaction Details](/img/tutorials/billing.png)
75+
76+
## 🎉 Start Your Monetization Journey Today!
77+
With Callgent's powerful monetization tools, turn your AI agent into a revenue-generating machine. Get started now! 🚀
78+
79+
80+
The next step is how to promote my cg service based on the interface/tag on the hub.
81+
82+
:::success
83+
How to promote my CG service on the hub based on interface or tag.
84+
:::

docusaurus.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const config: Config = {
1717
signupUrl: process.env.SITE_SIGNUP_URL,
1818
apiSiteUrl: process.env.API_SITE_URL,
1919
cookieDomain: process.env.SITE_URL_DOMAIN,
20+
siteUrl: process.env.SITE_URL,
21+
appUrl: process.env.APP_URL,
2022
},
2123

2224
// Set the production url of your site here

0 commit comments

Comments
 (0)