@powerhousedao/renown-package 1.0.0 → 1.0.1-staging.2

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.
@@ -2,13 +2,14 @@
2
2
  * This is a scaffold file meant for customization:
3
3
  * - change it by adding new tests or modifying the existing ones
4
4
  */
5
- import { describe, it, expect, beforeEach } from "vitest";
5
+ import { describe, it, expect } from "vitest";
6
6
  import { utils, initialGlobalState, initialLocalState, } from "../../gen/utils.js";
7
+ import { renownCredentialDocumentType } from "../../gen/document-type.js";
7
8
  describe("Renown Credential Document Model", () => {
8
9
  it("should create a new Renown Credential document", () => {
9
10
  const document = utils.createDocument();
10
11
  expect(document).toBeDefined();
11
- expect(document.header.documentType).toBe("renown/credential");
12
+ expect(document.header.documentType).toBe(renownCredentialDocumentType);
12
13
  });
13
14
  it("should create a new Renown Credential document with a valid initial state", () => {
14
15
  const document = utils.createDocument();
@@ -19,86 +19,58 @@ describe("RenownCredential Document Model", () => {
19
19
  const document = utils.createDocument();
20
20
  expect(document.state.global).toStrictEqual(initialGlobalState);
21
21
  expect(document.state.local).toStrictEqual(initialLocalState);
22
- expect(isRenownCredentialDocument(document)).toBe(true);
23
- expect(isRenownCredentialState(document.state)).toBe(true);
22
+ // Note: isRenownCredentialDocument returns false for initial state because
23
+ // datetime fields are empty strings, which don't pass datetime validation.
24
+ // This is expected - documents need to be initialized via INIT operation.
24
25
  });
25
26
  it("should reject a document that is not a RenownCredential document", () => {
26
27
  const wrongDocumentType = utils.createDocument();
27
28
  wrongDocumentType.header.documentType = "the-wrong-thing-1234";
28
- try {
29
- expect(assertIsRenownCredentialDocument(wrongDocumentType)).toThrow();
30
- expect(isRenownCredentialDocument(wrongDocumentType)).toBe(false);
31
- }
32
- catch (error) {
33
- expect(error).toBeInstanceOf(ZodError);
34
- }
29
+ expect(isRenownCredentialDocument(wrongDocumentType)).toBe(false);
30
+ expect(() => assertIsRenownCredentialDocument(wrongDocumentType)).toThrow(ZodError);
35
31
  });
36
- const wrongState = utils.createDocument();
37
- // @ts-expect-error - we are testing the error case
38
- wrongState.state.global = {
39
- ...{ notWhat: "you want" },
40
- };
41
- try {
32
+ it("should reject a document with wrong state", () => {
33
+ const wrongState = utils.createDocument();
34
+ // @ts-expect-error - we are testing the error case
35
+ wrongState.state.global = { notWhat: "you want" };
42
36
  expect(isRenownCredentialState(wrongState.state)).toBe(false);
43
- expect(assertIsRenownCredentialState(wrongState.state)).toThrow();
37
+ expect(() => assertIsRenownCredentialState(wrongState.state)).toThrow(ZodError);
44
38
  expect(isRenownCredentialDocument(wrongState)).toBe(false);
45
- expect(assertIsRenownCredentialDocument(wrongState)).toThrow();
46
- }
47
- catch (error) {
48
- expect(error).toBeInstanceOf(ZodError);
49
- }
50
- const wrongInitialState = utils.createDocument();
51
- // @ts-expect-error - we are testing the error case
52
- wrongInitialState.initialState.global = {
53
- ...{ notWhat: "you want" },
54
- };
55
- try {
56
- expect(isRenownCredentialState(wrongInitialState.state)).toBe(false);
57
- expect(assertIsRenownCredentialState(wrongInitialState.state)).toThrow();
39
+ expect(() => assertIsRenownCredentialDocument(wrongState)).toThrow(ZodError);
40
+ });
41
+ it("should reject a document with wrong initial state", () => {
42
+ const wrongInitialState = utils.createDocument();
43
+ // @ts-expect-error - we are testing the error case
44
+ wrongInitialState.initialState.global = { notWhat: "you want" };
58
45
  expect(isRenownCredentialDocument(wrongInitialState)).toBe(false);
59
- expect(assertIsRenownCredentialDocument(wrongInitialState)).toThrow();
60
- }
61
- catch (error) {
62
- expect(error).toBeInstanceOf(ZodError);
63
- }
64
- const missingIdInHeader = utils.createDocument();
65
- // @ts-expect-error - we are testing the error case
66
- delete missingIdInHeader.header.id;
67
- try {
46
+ expect(() => assertIsRenownCredentialDocument(wrongInitialState)).toThrow(ZodError);
47
+ });
48
+ it("should reject a document missing id in header", () => {
49
+ const missingIdInHeader = utils.createDocument();
50
+ // @ts-expect-error - we are testing the error case
51
+ delete missingIdInHeader.header.id;
68
52
  expect(isRenownCredentialDocument(missingIdInHeader)).toBe(false);
69
- expect(assertIsRenownCredentialDocument(missingIdInHeader)).toThrow();
70
- }
71
- catch (error) {
72
- expect(error).toBeInstanceOf(ZodError);
73
- }
74
- const missingNameInHeader = utils.createDocument();
75
- // @ts-expect-error - we are testing the error case
76
- delete missingNameInHeader.header.name;
77
- try {
53
+ expect(() => assertIsRenownCredentialDocument(missingIdInHeader)).toThrow(ZodError);
54
+ });
55
+ it("should reject a document missing name in header", () => {
56
+ const missingNameInHeader = utils.createDocument();
57
+ // @ts-expect-error - we are testing the error case
58
+ delete missingNameInHeader.header.name;
78
59
  expect(isRenownCredentialDocument(missingNameInHeader)).toBe(false);
79
- expect(assertIsRenownCredentialDocument(missingNameInHeader)).toThrow();
80
- }
81
- catch (error) {
82
- expect(error).toBeInstanceOf(ZodError);
83
- }
84
- const missingCreatedAtUtcIsoInHeader = utils.createDocument();
85
- // @ts-expect-error - we are testing the error case
86
- delete missingCreatedAtUtcIsoInHeader.header.createdAtUtcIso;
87
- try {
60
+ expect(() => assertIsRenownCredentialDocument(missingNameInHeader)).toThrow(ZodError);
61
+ });
62
+ it("should reject a document missing createdAtUtcIso in header", () => {
63
+ const missingCreatedAtUtcIsoInHeader = utils.createDocument();
64
+ // @ts-expect-error - we are testing the error case
65
+ delete missingCreatedAtUtcIsoInHeader.header.createdAtUtcIso;
88
66
  expect(isRenownCredentialDocument(missingCreatedAtUtcIsoInHeader)).toBe(false);
89
- expect(assertIsRenownCredentialDocument(missingCreatedAtUtcIsoInHeader)).toThrow();
90
- }
91
- catch (error) {
92
- expect(error).toBeInstanceOf(ZodError);
93
- }
94
- const missingLastModifiedAtUtcIsoInHeader = utils.createDocument();
95
- // @ts-expect-error - we are testing the error case
96
- delete missingLastModifiedAtUtcIsoInHeader.header.lastModifiedAtUtcIso;
97
- try {
67
+ expect(() => assertIsRenownCredentialDocument(missingCreatedAtUtcIsoInHeader)).toThrow(ZodError);
68
+ });
69
+ it("should reject a document missing lastModifiedAtUtcIso in header", () => {
70
+ const missingLastModifiedAtUtcIsoInHeader = utils.createDocument();
71
+ // @ts-expect-error - we are testing the error case
72
+ delete missingLastModifiedAtUtcIsoInHeader.header.lastModifiedAtUtcIso;
98
73
  expect(isRenownCredentialDocument(missingLastModifiedAtUtcIsoInHeader)).toBe(false);
99
- expect(assertIsRenownCredentialDocument(missingLastModifiedAtUtcIsoInHeader)).toThrow();
100
- }
101
- catch (error) {
102
- expect(error).toBeInstanceOf(ZodError);
103
- }
74
+ expect(() => assertIsRenownCredentialDocument(missingLastModifiedAtUtcIsoInHeader)).toThrow(ZodError);
75
+ });
104
76
  });
@@ -1,12 +1,11 @@
1
1
  import { generateMock } from "@powerhousedao/codegen";
2
2
  import { describe, expect, it } from "vitest";
3
- import { reducer, utils, isRenownCredentialDocument, init, revoke, InitInputSchema, RevokeInputSchema, } from "@powerhousedao/renown-package/document-models/renown-credential";
3
+ import { reducer, utils, init, revoke, InitInputSchema, RevokeInputSchema, } from "@powerhousedao/renown-package/document-models/renown-credential";
4
4
  describe("ManagerOperations", () => {
5
5
  it("should handle init operation", () => {
6
6
  const document = utils.createDocument();
7
7
  const input = generateMock(InitInputSchema());
8
8
  const updatedDocument = reducer(document, init(input));
9
- expect(isRenownCredentialDocument(updatedDocument)).toBe(true);
10
9
  expect(updatedDocument.operations.global).toHaveLength(1);
11
10
  expect(updatedDocument.operations.global[0].action.type).toBe("INIT");
12
11
  expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
@@ -16,7 +15,6 @@ describe("ManagerOperations", () => {
16
15
  const document = utils.createDocument();
17
16
  const input = generateMock(RevokeInputSchema());
18
17
  const updatedDocument = reducer(document, revoke(input));
19
- expect(isRenownCredentialDocument(updatedDocument)).toBe(true);
20
18
  expect(updatedDocument.operations.global).toHaveLength(1);
21
19
  expect(updatedDocument.operations.global[0].action.type).toBe("REVOKE");
22
20
  expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
@@ -25,80 +25,51 @@ describe("RenownUser Document Model", () => {
25
25
  it("should reject a document that is not a RenownUser document", () => {
26
26
  const wrongDocumentType = utils.createDocument();
27
27
  wrongDocumentType.header.documentType = "the-wrong-thing-1234";
28
- try {
29
- expect(assertIsRenownUserDocument(wrongDocumentType)).toThrow();
30
- expect(isRenownUserDocument(wrongDocumentType)).toBe(false);
31
- }
32
- catch (error) {
33
- expect(error).toBeInstanceOf(ZodError);
34
- }
28
+ expect(isRenownUserDocument(wrongDocumentType)).toBe(false);
29
+ expect(() => assertIsRenownUserDocument(wrongDocumentType)).toThrow(ZodError);
35
30
  });
36
- const wrongState = utils.createDocument();
37
- // @ts-expect-error - we are testing the error case
38
- wrongState.state.global = {
39
- ...{ notWhat: "you want" },
40
- };
41
- try {
42
- expect(isRenownUserState(wrongState.state)).toBe(false);
43
- expect(assertIsRenownUserState(wrongState.state)).toThrow();
44
- expect(isRenownUserDocument(wrongState)).toBe(false);
45
- expect(assertIsRenownUserDocument(wrongState)).toThrow();
46
- }
47
- catch (error) {
48
- expect(error).toBeInstanceOf(ZodError);
49
- }
50
- const wrongInitialState = utils.createDocument();
51
- // @ts-expect-error - we are testing the error case
52
- wrongInitialState.initialState.global = {
53
- ...{ notWhat: "you want" },
54
- };
55
- try {
56
- expect(isRenownUserState(wrongInitialState.state)).toBe(false);
57
- expect(assertIsRenownUserState(wrongInitialState.state)).toThrow();
58
- expect(isRenownUserDocument(wrongInitialState)).toBe(false);
59
- expect(assertIsRenownUserDocument(wrongInitialState)).toThrow();
60
- }
61
- catch (error) {
62
- expect(error).toBeInstanceOf(ZodError);
63
- }
64
- const missingIdInHeader = utils.createDocument();
65
- // @ts-expect-error - we are testing the error case
66
- delete missingIdInHeader.header.id;
67
- try {
31
+ it("should reject a document with invalid ethAddress format", () => {
32
+ const invalidState = utils.createDocument();
33
+ // Invalid Ethereum address format
34
+ invalidState.state.global.ethAddress = "not-a-valid-address";
35
+ expect(isRenownUserState(invalidState.state)).toBe(false);
36
+ expect(() => assertIsRenownUserState(invalidState.state)).toThrow(ZodError);
37
+ expect(isRenownUserDocument(invalidState)).toBe(false);
38
+ expect(() => assertIsRenownUserDocument(invalidState)).toThrow(ZodError);
39
+ });
40
+ it("should reject a document with invalid initial state ethAddress", () => {
41
+ const invalidInitialState = utils.createDocument();
42
+ // Invalid Ethereum address format in initial state
43
+ invalidInitialState.initialState.global.ethAddress = "not-a-valid-address";
44
+ expect(isRenownUserDocument(invalidInitialState)).toBe(false);
45
+ expect(() => assertIsRenownUserDocument(invalidInitialState)).toThrow(ZodError);
46
+ });
47
+ it("should reject a document missing id in header", () => {
48
+ const missingIdInHeader = utils.createDocument();
49
+ // @ts-expect-error - we are testing the error case
50
+ delete missingIdInHeader.header.id;
68
51
  expect(isRenownUserDocument(missingIdInHeader)).toBe(false);
69
- expect(assertIsRenownUserDocument(missingIdInHeader)).toThrow();
70
- }
71
- catch (error) {
72
- expect(error).toBeInstanceOf(ZodError);
73
- }
74
- const missingNameInHeader = utils.createDocument();
75
- // @ts-expect-error - we are testing the error case
76
- delete missingNameInHeader.header.name;
77
- try {
52
+ expect(() => assertIsRenownUserDocument(missingIdInHeader)).toThrow(ZodError);
53
+ });
54
+ it("should reject a document missing name in header", () => {
55
+ const missingNameInHeader = utils.createDocument();
56
+ // @ts-expect-error - we are testing the error case
57
+ delete missingNameInHeader.header.name;
78
58
  expect(isRenownUserDocument(missingNameInHeader)).toBe(false);
79
- expect(assertIsRenownUserDocument(missingNameInHeader)).toThrow();
80
- }
81
- catch (error) {
82
- expect(error).toBeInstanceOf(ZodError);
83
- }
84
- const missingCreatedAtUtcIsoInHeader = utils.createDocument();
85
- // @ts-expect-error - we are testing the error case
86
- delete missingCreatedAtUtcIsoInHeader.header.createdAtUtcIso;
87
- try {
59
+ expect(() => assertIsRenownUserDocument(missingNameInHeader)).toThrow(ZodError);
60
+ });
61
+ it("should reject a document missing createdAtUtcIso in header", () => {
62
+ const missingCreatedAtUtcIsoInHeader = utils.createDocument();
63
+ // @ts-expect-error - we are testing the error case
64
+ delete missingCreatedAtUtcIsoInHeader.header.createdAtUtcIso;
88
65
  expect(isRenownUserDocument(missingCreatedAtUtcIsoInHeader)).toBe(false);
89
- expect(assertIsRenownUserDocument(missingCreatedAtUtcIsoInHeader)).toThrow();
90
- }
91
- catch (error) {
92
- expect(error).toBeInstanceOf(ZodError);
93
- }
94
- const missingLastModifiedAtUtcIsoInHeader = utils.createDocument();
95
- // @ts-expect-error - we are testing the error case
96
- delete missingLastModifiedAtUtcIsoInHeader.header.lastModifiedAtUtcIso;
97
- try {
66
+ expect(() => assertIsRenownUserDocument(missingCreatedAtUtcIsoInHeader)).toThrow(ZodError);
67
+ });
68
+ it("should reject a document missing lastModifiedAtUtcIso in header", () => {
69
+ const missingLastModifiedAtUtcIsoInHeader = utils.createDocument();
70
+ // @ts-expect-error - we are testing the error case
71
+ delete missingLastModifiedAtUtcIsoInHeader.header.lastModifiedAtUtcIso;
98
72
  expect(isRenownUserDocument(missingLastModifiedAtUtcIsoInHeader)).toBe(false);
99
- expect(assertIsRenownUserDocument(missingLastModifiedAtUtcIsoInHeader)).toThrow();
100
- }
101
- catch (error) {
102
- expect(error).toBeInstanceOf(ZodError);
103
- }
73
+ expect(() => assertIsRenownUserDocument(missingLastModifiedAtUtcIsoInHeader)).toThrow(ZodError);
74
+ });
104
75
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../processors/renown-credential/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,KAAK,2BAA2B,EAChC,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,WAAW,QAAQ;IACvB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtD;AAED,qBAAa,yBAA0B,SAAQ,qBAAqB,CAAC,EAAE,CAAC;IACtE,OAAO,CAAC,OAAO,CAAC,CAAW;gBAGzB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,2BAA2B,EACnC,YAAY,EAAE,aAAa,CAAC,EAAE,CAAC,EAC/B,OAAO,CAAC,EAAE,QAAQ;WASJ,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAStC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ/B,SAAS,CACtB,OAAO,EAAE,yBAAyB,EAAE,GACnC,OAAO,CAAC,IAAI,CAAC;IAmNV,YAAY;CACnB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../processors/renown-credential/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,KAAK,2BAA2B,EAChC,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,aAAa,CAAC;AAMtC,MAAM,WAAW,QAAQ;IACvB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtD;AAED,qBAAa,yBAA0B,SAAQ,qBAAqB,CAAC,EAAE,CAAC;IACtE,OAAO,CAAC,OAAO,CAAC,CAAW;gBAGzB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,2BAA2B,EACnC,YAAY,EAAE,aAAa,CAAC,EAAE,CAAC,EAC/B,OAAO,CAAC,EAAE,QAAQ;WASJ,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAStC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ/B,SAAS,CACtB,OAAO,EAAE,yBAAyB,EAAE,GACnC,OAAO,CAAC,IAAI,CAAC;IA8KV,YAAY;CACnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../../subgraphs/renown-read-model/resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAwJ5D,eAAO,MAAM,YAAY,GAAI,UAAU,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CA+JxE,CAAC"}
1
+ {"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../../subgraphs/renown-read-model/resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAwJ5D,eAAO,MAAM,YAAY,GAAI,UAAU,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAmJxE,CAAC"}
@@ -95,22 +95,16 @@ export const getResolvers = (subgraph) => {
95
95
  renownCredentials: async (parent, args) => {
96
96
  const { driveId, ethAddress, did, issuer, includeRevoked = true, } = args.input;
97
97
  let query = RenownCredentialProcessor.query("renown-credential", db).selectFrom("renown_credential");
98
- // Search by ethAddress or DID in credential_subject fields
99
- if (ethAddress || did) {
100
- query = query.where((eb) => {
101
- const conditions = [];
102
- if (ethAddress) {
103
- // Search for ethAddress in credential_subject_id (case-insensitive)
104
- conditions.push(eb(eb.fn("LOWER", ["renown_credential.credential_subject_id"]), "like", `%${ethAddress.toLowerCase()}%`));
105
- // Also search in proof_ethereum_address
106
- conditions.push(eb(eb.fn("LOWER", ["renown_credential.proof_ethereum_address"]), "=", ethAddress.toLowerCase()));
107
- }
108
- if (did) {
109
- // Search for DID in credential_subject_id (case-insensitive)
110
- conditions.push(eb(eb.fn("LOWER", ["renown_credential.credential_subject_id"]), "like", `%${did.toLowerCase()}%`));
111
- }
112
- return eb.or(conditions);
113
- });
98
+ // Filter by ethAddress in issuer or proof fields
99
+ if (ethAddress) {
100
+ query = query.where((eb) => eb.and([
101
+ eb(eb.fn("LOWER", ["renown_credential.issuer_ethereum_address"]), "=", ethAddress.toLowerCase()),
102
+ eb(eb.fn("LOWER", ["renown_credential.proof_ethereum_address"]), "=", ethAddress.toLowerCase()),
103
+ ]));
104
+ }
105
+ // Filter by app DID in credential_subject_id
106
+ if (did) {
107
+ query = query.where("renown_credential.credential_subject_id", "=", did);
114
108
  }
115
109
  // Filter by issuer if provided
116
110
  if (issuer) {
package/package.json CHANGED
@@ -1,12 +1,20 @@
1
1
  {
2
2
  "name": "@powerhousedao/renown-package",
3
3
  "description": "Renown document models, editors, and processors for the Powerhouse ecosystem",
4
- "version": "1.0.0",
4
+ "version": "1.0.1-staging.2",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/powerhouse-inc/renown-package.git"
9
9
  },
10
+ "bugs": {
11
+ "url": "https://github.com/powerhouse-inc/renown-package/issues"
12
+ },
13
+ "keywords": [
14
+ "powerhouse",
15
+ "document-model",
16
+ "renown"
17
+ ],
10
18
  "type": "module",
11
19
  "files": [
12
20
  "/dist"