From b1cd867fa3cc24ec84d3cabb79665a50e50abc57 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Tue, 28 Nov 2023 13:24:06 +0900 Subject: [PATCH 1/4] fix: remove root path rule --- src/constants.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 9921d87..a91ba69 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -31,14 +31,6 @@ export const Path = { export const defaultAppRules = (appName: string): { [type: string]: { ref: string, value: object } } => { const rootRef = Path.app(appName).root(); return { - root: { - ref: rootRef, - value: { - ".rule": { - write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true" - }, - }, - }, deposit: { ref: `${Path.app(appName).depositOfUser("$userAddress")}/$transferKey`, value: { @@ -56,7 +48,7 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin }, }, balanceHistory: { - ref: `${rootRef}/balance/$userAddress/history/$timestamp_and_type`, + ref: `${rootRef}/balance/$userAddress/history/$timestamp`, value: { ".rule": { write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isNumber(newData.amount) && (newData.type === 'DEPOSIT' || newData.type === 'USAGE')" From 8d902a2e3f6a014bb8f8086a0b1f8a3a802e78ab Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Tue, 28 Nov 2023 13:32:32 +0900 Subject: [PATCH 2/4] fix: request without charge when minCost is 0 --- src/constants.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index a91ba69..2c22618 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -60,7 +60,8 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin value: { ".rule": { write: - "auth.addr === $userAddress && getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) !== null && " + + "auth.addr === $userAddress && " + + "(getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`) === 0 || " + "(getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`))" }, }, From 309bf00ecb540ff71315cb91e80ae77ac8efbb5a Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Tue, 28 Nov 2023 13:33:47 +0900 Subject: [PATCH 3/4] fix: limit minCost to positive numbers --- src/constants.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 2c22618..1f9c9ca 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -78,9 +78,12 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin ref: Path.app(appName).billingConfig(), value: { ".rule": { - write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isString(newData.depositAddress) && " + - "util.isDict(newData) && util.isNumber(newData.costPerToken) && util.isNumber(newData.minCost) && " + - "util.isEmpty(newData.maxCost) || (util.isNumber(newData.maxCost) && newData.maxCost >= newData.minCost)", + write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && " + + "util.isDict(newData) && " + + "util.isString(newData.depositAddress) && " + + "util.isNumber(newData.costPerToken) && " + + "util.isNumber(newData.minCost) && newData.minCost >= 0" + + "(util.isEmpty(newData.maxCost) || (util.isNumber(newData.maxCost) && newData.maxCost >= newData.minCost))", }, }, }, From d874493fe5cbd2d6bb010f93277be6fbac3cfa88 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Tue, 28 Nov 2023 13:34:29 +0900 Subject: [PATCH 4/4] docs: readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d7d0a8..8348bf1 100644 --- a/README.md +++ b/README.md @@ -62,5 +62,5 @@ const balance = await service.getCreditBalance(); If you have enough credit, you can use the service. ```typescript -const result = await service.use(); +const result = await service.request(); ```