Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/skills/hypercerts-api/references/endpoint-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Inspect the exact operation in the bundled OpenAPI contract before constructing
| Load one actor's organization sidecar | `app.certified.actor.getOrganization` | `actor` is a DID. If no indexed sidecar exists, this single lookup declares `RecordNotFound`; unlike `getOrganizations`, it does not return a nullable organization per actor. |
| Load organization context for known actors | `app.certified.actor.getOrganizations` | `actors` is a repeated DID array; results preserve request order and an absent organization is null per result. |
| Browse/filter organizations | `app.certified.actor.listOrganizations` | Use for organization-type/visibility filters and pagination. |
| Find organizations by text | `app.certified.actor.searchOrganizations` | Searches associated profile text, with optional organization filters. |
| Find organizations by text | `app.certified.actor.searchOrganizations` | Searches organization legal name and associated profile text, with optional organization filters. |

Use `getProfiles`/`getOrganizations` for known DID sets; use `list` or `search` for discovery. A missing optional profile inside an organization view is not the same as a missing organization record. Organization actor views from these four endpoints include `location` (the resolved, raw indexed location record, or null; `organization.record.location` stays the strong reference); use it instead of a second `getLocation` call. Organization views nested in other endpoints' author or actor views do not include it.

Expand Down
4 changes: 2 additions & 2 deletions .agents/skills/hypercerts-api/references/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,13 @@
"get": {
"operationId": "app_certified_actor_searchOrganizations",
"tags": ["app.certified.actor"],
"description": "Searches organizations by associated profile text and optional filters. Filters combine with AND, and values within each array filter are ORed. Authentication is not required.",
"description": "Searches organizations by legal name, profile text and optional filters. Filters combine with AND, and values within each array filter are ORed. Authentication is not required.",
"parameters": [
{
"name": "search",
"in": "query",
"required": true,
"description": "Trimmed text is matched literally and case-insensitively as a substring in either displayName or description. Blank text is unrestricted; nonblank text requires an associated profile.",
"description": "Trimmed text is matched literally and case-insensitively as a substring in the organization's legalName or in the associated profile's displayName or description. Organizations without a profile match on legalName alone. Blank text is unrestricted.",
"schema": { "type": "string" }
},
{
Expand Down
6 changes: 6 additions & 0 deletions .changeset/search-organizations-legal-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hypercerts-org/happyview-modules': minor
'@hypercerts-org/api': patch
---

`app.certified.actor.searchOrganizations` now also searches an organization's legal name. Organizations without a profile can now be found by legal name; before, they never appeared in search results.
4 changes: 2 additions & 2 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,13 @@
"tags": [
"app.certified.actor"
],
"description": "Searches organizations by associated profile text and optional filters. Filters combine with AND, and values within each array filter are ORed. Authentication is not required.",
"description": "Searches organizations by legal name, profile text and optional filters. Filters combine with AND, and values within each array filter are ORed. Authentication is not required.",
"parameters": [
{
"name": "search",
"in": "query",
"required": true,
"description": "Trimmed text is matched literally and case-insensitively as a substring in either displayName or description. Blank text is unrestricted; nonblank text requires an associated profile.",
"description": "Trimmed text is matched literally and case-insensitively as a substring in the organization's legalName or in the associated profile's displayName or description. Organizations without a profile match on legalName alone. Blank text is unrestricted.",
"schema": {
"type": "string"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"defs": {
"main": {
"type": "query",
"description": "Searches organizations by associated profile text and optional filters. Filters combine with AND, and values within each array filter are ORed. Authentication is not required.",
"description": "Searches organizations by legal name, profile text and optional filters. Filters combine with AND, and values within each array filter are ORed. Authentication is not required.",
"parameters": {
"type": "params",
"required": [
Expand All @@ -13,7 +13,7 @@
"properties": {
"search": {
"type": "string",
"description": "Trimmed text is matched literally and case-insensitively as a substring in either displayName or description. Blank text is unrestricted; nonblank text requires an associated profile."
"description": "Trimmed text is matched literally and case-insensitively as a substring in the organization's legalName or in the associated profile's displayName or description. Organizations without a profile match on legalName alone. Blank text is unrestricted."
},
"actors": {
"type": "array",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"defs": {
"main": {
"type": "query",
"description": "Searches organizations by associated profile text and optional filters. Filters combine with AND, and values within each array filter are ORed. Authentication is not required.",
"description": "Searches organizations by legal name, profile text and optional filters. Filters combine with AND, and values within each array filter are ORed. Authentication is not required.",
"parameters": {
"type": "params",
"required": ["search"],
"properties": {
"search": {
"type": "string",
"description": "Trimmed text is matched literally and case-insensitively as a substring in either displayName or description. Blank text is unrestricted; nonblank text requires an associated profile."
"description": "Trimmed text is matched literally and case-insensitively as a substring in the organization's legalName or in the associated profile's displayName or description. Organizations without a profile match on legalName alone. Blank text is unrestricted."
},
"actors": {
"type": "array",
Expand Down
5 changes: 3 additions & 2 deletions happyview-modules/lua/endpoints/listOrganizations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,12 @@ local function query_organizations(actors, organization_types, visibility, searc
local search_parameter = "$" .. #values
values[#values + 1] = PROFILE
local profile_collection = "$" .. #values
where[#where + 1] = "EXISTS (SELECT 1 FROM happyview_records AS profile " ..
where[#where + 1] = "(strpos(lower(COALESCE(organization.record::jsonb->>'legalName', '')), lower(" ..
search_parameter .. ")) > 0 OR EXISTS (SELECT 1 FROM happyview_records AS profile " ..
"WHERE profile.collection = " .. profile_collection .. " AND profile.did = organization.did " ..
"AND profile.rkey = 'self' AND (strpos(lower(COALESCE(profile.record::jsonb->>'displayName', '')), lower(" ..
search_parameter .. ")) > 0 OR strpos(lower(COALESCE(profile.record::jsonb->>'description', '')), lower(" ..
search_parameter .. ")) > 0))"
search_parameter .. ")) > 0)))"
end
if cursor then
values[#values + 1] = cursor.t
Expand Down
5 changes: 3 additions & 2 deletions happyview-modules/lua/endpoints/searchOrganizations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,12 @@ local function query_organizations(actors, organization_types, visibility, searc
local search_parameter = "$" .. #values
values[#values + 1] = PROFILE
local profile_collection = "$" .. #values
where[#where + 1] = "EXISTS (SELECT 1 FROM happyview_records AS profile " ..
where[#where + 1] = "(strpos(lower(COALESCE(organization.record::jsonb->>'legalName', '')), lower(" ..
search_parameter .. ")) > 0 OR EXISTS (SELECT 1 FROM happyview_records AS profile " ..
"WHERE profile.collection = " .. profile_collection .. " AND profile.did = organization.did " ..
"AND profile.rkey = 'self' AND (strpos(lower(COALESCE(profile.record::jsonb->>'displayName', '')), lower(" ..
search_parameter .. ")) > 0 OR strpos(lower(COALESCE(profile.record::jsonb->>'description', '')), lower(" ..
search_parameter .. ")) > 0))"
search_parameter .. ")) > 0)))"
end
if cursor then
values[#values + 1] = cursor.t
Expand Down
5 changes: 3 additions & 2 deletions happyview-modules/lua/shared/organizationList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ local function query_organizations(actors, organization_types, visibility, searc
local search_parameter = "$" .. #values
values[#values + 1] = PROFILE
local profile_collection = "$" .. #values
where[#where + 1] = "EXISTS (SELECT 1 FROM happyview_records AS profile " ..
where[#where + 1] = "(strpos(lower(COALESCE(organization.record::jsonb->>'legalName', '')), lower(" ..
search_parameter .. ")) > 0 OR EXISTS (SELECT 1 FROM happyview_records AS profile " ..
"WHERE profile.collection = " .. profile_collection .. " AND profile.did = organization.did " ..
"AND profile.rkey = 'self' AND (strpos(lower(COALESCE(profile.record::jsonb->>'displayName', '')), lower(" ..
search_parameter .. ")) > 0 OR strpos(lower(COALESCE(profile.record::jsonb->>'description', '')), lower(" ..
search_parameter .. ")) > 0))"
search_parameter .. ")) > 0)))"
end
if cursor then
values[#values + 1] = cursor.t
Expand Down
29 changes: 26 additions & 3 deletions happyview-modules/tests/http/actor-organizations.http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ test("listOrganizations combines exact type and visibility filters and leaves om
);
});

test("searchOrganizations matches full trimmed literal profile text and excludes organizations without profiles", async () => {
test("searchOrganizations matches full trimmed literal profile text", async () => {
const result = await get("app.certified.actor.searchOrganizations", {
search: " Forest %_ Commons ",
actors: [unlistedOrganization.did],
Expand All @@ -204,12 +204,35 @@ test("searchOrganizations matches full trimmed literal profile text and excludes
assert.equal(result.actors[0].did, unlistedOrganization.did);
assert.equal(result.actors[0].profile.record.displayName, "Forest %_ Commons");
assert.deepEqual(result.actors[0].organization.record, unlistedOrganization.record);
});

test("searchOrganizations matches legalName case-insensitively, including organizations without a profile", async () => {
// legalName is absent from the river profile's displayName and description.
const legalNameOnly = await get("app.certified.actor.searchOrganizations", {
search: "CATCHMENT trust",
actors: [actorFixtureDids.river],
});
assert.deepEqual(
legalNameOnly.actors.map(({ did }) => did),
[actorFixtureDids.river],
);
assert.ok(legalNameOnly.actors[0].profile);

const profileless = await get("app.certified.actor.searchOrganizations", {
search: "weavers coop",
actors: [profilelessOrganization.did],
});
assert.deepEqual(
profileless.actors.map(({ did }) => did),
[profilelessOrganization.did],
);
assert.equal(profileless.actors[0].profile, null);

const absentProfile = await get("app.certified.actor.searchOrganizations", {
const noMatch = await get("app.certified.actor.searchOrganizations", {
search: "community",
actors: [profilelessOrganization.did],
});
assert.deepEqual(absentProfile.actors, []);
assert.deepEqual(noMatch.actors, []);
});

test("listOrganizations paginates stably in both directions without skipping equal-timestamp records", async () => {
Expand Down
2 changes: 2 additions & 0 deletions happyview-modules/tests/http/fixtures/actors.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const records = [
collection: organizationCollection,
rkey: "self",
record: {
legalName: "Chhu Catchment Trust",
organizationType: ["nonprofit"],
location: locationRefs.river,
visibility: "public",
Expand All @@ -117,6 +118,7 @@ const records = [
collection: organizationCollection,
rkey: "self",
record: {
legalName: "Bumthang Weavers Cooperative",
organizationType: ["community"],
createdAt,
},
Expand Down
5 changes: 3 additions & 2 deletions happyview-modules/tests/unit/tooling/organization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ assert(#calls == 2 and calls[2].values[1] == '${profileCollection}' and calls[2]
});
});

test("searchOrganizations binds the complete trimmed literal and excludes actors without a profile", () => {
test("searchOrganizations binds the complete trimmed literal and also matches legalName without requiring a profile", () => {
const organization = organizationRow(actor, "search", {
organizationType: ["nonprofit"],
createdAt: "2025-01-01T00:00:00Z",
Expand All @@ -490,7 +490,8 @@ test("searchOrganizations binds the complete trimmed literal and excludes actors
assertions: `
assert(#result.actors == 1 and result.actors[1].did == '${actor}', 'actor result')
assert(calls[1].sql:find('strpos(lower', 1, true), 'literal substring SQL')
assert(calls[1].sql:find('EXISTS', 1, true) and calls[1].sql:find('profile.did = organization.did', 1, true), 'profile existence predicate')
assert(calls[1].sql:find("organization.record::jsonb->>'legalName'", 1, true), 'legalName predicate')
assert(calls[1].sql:find(') > 0 OR EXISTS (SELECT 1', 1, true) and calls[1].sql:find('profile.did = organization.did', 1, true), 'profile alternative predicate')
assert(not calls[1].sql:find('Forest', 1, true), 'search text must be a bound SQL value')
assert(calls[1].sql:find('organization.did IN ($2)', 1, true), 'search retains its actors filter')
assert(calls[1].values[2] == '${actor}' and calls[1].values[3] == 'nonprofit' and calls[1].values[4] == 'Forest %_ Restoration', table.concat(calls[1].values, '|'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const $output = /*#__PURE__*/ l.payload("application/json", /*#__PURE__*/
export type $Output<B = l.BinaryData> = l.InferPayload<typeof $output, B>;
export type $OutputBody<B = l.BinaryData> = l.InferPayloadBody<typeof $output, B>;

/** Searches organizations by associated profile text and optional filters. Filters combine with AND, and values within each array filter are ORed. Authentication is not required. */
/** Searches organizations by legal name, profile text and optional filters. Filters combine with AND, and values within each array filter are ORed. Authentication is not required. */
const main = /*#__PURE__*/ l.query($nsid, $params, $output, ["InvalidRequest","OrganizationQueryFailed"]);

export { main };
Expand Down
Loading