add .npmignore, genJsonProfile return string instead of object.
diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..5a808ed --- /dev/null +++ b/.npmignore
@@ -0,0 +1,11 @@ +# dependencies +node_modules/ + +# Src and test suites +src/ + +.idea/ +package-lock.json +yarn.lock + +npm-debug.log \ No newline at end of file
diff --git a/package.json b/package.json index b755892..f873a25 100644 --- a/package.json +++ b/package.json
@@ -1,6 +1,6 @@ { "name": "casbinjs-server-tool", - "version": "0.0.1", + "version": "0.0.3", "description": "This package provides the facilities to generate permission tokens on node-casbin service.", "main": "./lib/index.js", "typings": "./lib/index.d.ts",
diff --git a/src/CasbinJsServerTool.ts b/src/CasbinJsServerTool.ts index 0eea018..f92f515 100644 --- a/src/CasbinJsServerTool.ts +++ b/src/CasbinJsServerTool.ts
@@ -64,13 +64,13 @@ "ps": "p,a,b,c\np,a,c,b\n..." } */ - async genJsonProfile(subject: string): Promise<Object> { + async genJsonProfile(subject: string): Promise<string> { const jsonProfile: Record<string, string> = {}; jsonProfile["r"] = utils.getRawRequestString(this.enforcer); jsonProfile["p"] = utils.getRawPolicyString(this.enforcer); jsonProfile["e"] = utils.getRawEffectString(this.enforcer); jsonProfile["m"] = await this.genMatcher(); jsonProfile["ps"] = await this.genPolicies(subject); - return Object(jsonProfile); + return JSON.stringify(jsonProfile); } }
diff --git a/src/__test__/index.test.ts b/src/__test__/index.test.ts index e3fec2b..caa9312 100644 --- a/src/__test__/index.test.ts +++ b/src/__test__/index.test.ts
@@ -7,7 +7,8 @@ const e = await newEnforcer(`${examplesPath}/basic_model.conf`, `${examplesPath}/basic_policy.csv`); const svrTool = new CasbinJsServerTool(e); - const profile = await svrTool.genJsonProfile("alice"); + const profileStr = await svrTool.genJsonProfile("alice"); + const profile = JSON.parse(profileStr); expect(profile.hasOwnProperty("ps")).toBe(true); const policies = profile["ps"].split("\n"); @@ -24,7 +25,8 @@ const e = await newEnforcer(`${examplesPath}/rbac_model.conf`, `${examplesPath}/rbac_policy.csv`); const svrTool = new CasbinJsServerTool(e); - const profile = await svrTool.genJsonProfile("alice"); + const profileStr = await svrTool.genJsonProfile("alice"); + const profile = JSON.parse(profileStr); const policies = profile["ps"].split("\n"); expect(profile.hasOwnProperty("ps")).toBe(true); expect(policies.length).toBe(3); @@ -36,5 +38,5 @@ const conf = profile["m"]; expect(conf).toBe("m = r_obj == p_obj && r_act == p_act"); - console.log(await svrTool.genJsonProfile("alice")); + console.log(profile); });