Skip to content

Commit

Permalink
Feature: Add getPluginPreparations function (#294)
Browse files Browse the repository at this point in the history
* add prepared plugins query

* update commons

* update changelog and example

* Update modules/client/src/types.ts

Co-authored-by: Michael Heuer <[email protected]>

* fix formatting

* fix tests

---------

Co-authored-by: Michael Heuer <[email protected]>
  • Loading branch information
josemarinas and heueristik authored Oct 25, 2023
1 parent a9570ea commit 76b4fc8
Show file tree
Hide file tree
Showing 14 changed files with 478 additions and 22 deletions.
5 changes: 5 additions & 0 deletions modules/client-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ TEMPLATE:
-->

## [UPCOMING]
### Added

- Add new class error `InvalidPermissionOperationType`

## [1.7.1]
### Fixed

- ENS name Regex
Expand Down
2 changes: 1 addition & 1 deletion modules/client-common/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aragon/sdk-client-common",
"author": "Aragon Association",
"version": "1.7.1",
"version": "1.8.0",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client-common.esm.js",
Expand Down
6 changes: 6 additions & 0 deletions modules/client-common/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,9 @@ export class InvalidTimeoutError extends SdkError {
);
}
}

export class InvalidPermissionOperationType extends SdkError {
constructor(cause?: any) {
super("Invalid permission operation", cause);
}
}
4 changes: 4 additions & 0 deletions modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ TEMPLATE:
-->

## [UPCOMING]
### Added

- `getPluginPreparations` function to `Client`

## [1.16.3]
### Fixed

- Required ensSubdomain in createDao
Expand Down
77 changes: 77 additions & 0 deletions modules/client/examples/01-client/20-get-plugin-preparations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* MARKDOWN
---
title: Get Plugin Preparations
---
## Get Plugin Preparations
Returns plugin preparations filtered by:
- pluginAddress
- daoAddressOrEns
- pluginRepoAddress
- type(Installation or Update)
*/

import {
Client,
PluginPreparationListItem,
PluginPreparationQueryParams,
PluginPreparationSortBy,
} from "@aragon/sdk-client";
import { SortDirection } from "@aragon/sdk-client-common";
import { context } from "../index";

// Instantiate the general purpose client from the Aragon OSx SDK context.
const client: Client = new Client(context);

const params: PluginPreparationQueryParams = {
limit: 10,
skip: 0,
direction: SortDirection.ASC,
sortBy: PluginPreparationSortBy.ID,
pluginAddress: "0x1234567890123456789012345678901234567890",
daoAddressOrEns: "0x1234567890123456789012345678901234567890",
pluginRepoAddress: "0x1234567890123456789012345678901234567890",
};

// Get a list of DAOs from the Aragon DAO registry.
const pluginPreparations: PluginPreparationListItem[] = await client.methods
.getPluginPreparations(params);
console.log(pluginPreparations);

/* MARKDOWN
Returns:
```json
[
{
id: string,
type: "Installation",
creator: "0x1234567890123456789012345678901234567890",
dao: "0x1234567890123456789012345678901234567890",
pluginRepo: {
id: "0x1234567890123456789012345678901234567890",
subdomain: "multisig"
},
versionTag: {
build: 1,
release: 1
},
pluginAddress: "0x1234567890123456789012345678901234567890",
permissions: [
{
who: "0x1234567890123456789012345678901234567890",
where: "0x1234567890123456789012345678901234567890",
permissionId: "0x12345678",
condition: "0x1234567890123456789012345678901234567890"
}
]
helpers: ["0x1234567890123456789012345678901234567890"],;
data: new Uint8Array()
}
]
```
*/
4 changes: 2 additions & 2 deletions modules/client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aragon/sdk-client",
"author": "Aragon Association",
"version": "1.16.3",
"version": "1.17.0",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client.esm.js",
Expand Down Expand Up @@ -62,7 +62,7 @@
},
"dependencies": {
"@aragon/osx-ethers": "1.3.0-rc0.3",
"@aragon/sdk-client-common": "^1.7.1",
"@aragon/sdk-client-common": "^1.8.0",
"@aragon/sdk-ipfs": "^1.1.0",
"@ethersproject/abstract-signer": "^5.5.0",
"@ethersproject/bignumber": "^5.6.0",
Expand Down
67 changes: 67 additions & 0 deletions modules/client/src/internal/client/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
QueryIPlugin,
QueryPlugin,
QueryPluginPreparations,
QueryPluginPreparationsExtended,
QueryPlugins,
QueryTokenBalances,
QueryTokenTransfers,
Expand Down Expand Up @@ -54,6 +55,9 @@ import {
HasPermissionParams,
IsDaoUpdateValidParams,
IsPluginUpdateValidParams,
PluginPreparationListItem,
PluginPreparationQueryParams,
PluginPreparationSortBy,
PluginQueryParams,
PluginRepo,
PluginRepoBuildMetadata,
Expand All @@ -75,6 +79,7 @@ import {
SubgraphDao,
SubgraphDaoListItem,
SubgraphPluginInstallation,
SubgraphPluginPreparationListItem,
SubgraphPluginRepo,
SubgraphPluginRepoListItem,
SubgraphPluginRepoRelease,
Expand All @@ -93,6 +98,7 @@ import {
toAssetBalance,
toDaoDetails,
toDaoListItem,
toPluginPreparationListItem,
toPluginRepo,
toTokenTransfer,
} from "../utils";
Expand Down Expand Up @@ -168,6 +174,7 @@ import {
HasPermissionSchema,
IsDaoUpdateValidSchema,
IsPluginUpdateValidSchema,
PluginPreparationQuerySchema,
PluginQuerySchema,
} from "../schemas";

Expand Down Expand Up @@ -1527,4 +1534,64 @@ export class ClientMethods extends ClientCore implements IClientMethods {
);
return daoFactoryImplementation.daoBase();
}

public async getPluginPreparations(
{
type,
pluginAddress,
pluginRepoAddress,
daoAddressOrEns,
limit = 10,
skip = 0,
direction = SortDirection.ASC,
sortBy = PluginPreparationSortBy.ID,
}: PluginPreparationQueryParams,
): Promise<PluginPreparationListItem[]> {
await PluginPreparationQuerySchema.strict().validate({
type,
pluginAddress,
pluginRepoAddress,
daoAddressOrEns,
limit,
skip,
direction,
sortBy,
});

let where = {};
if (type) {
where = { ...where, type };
}
if (pluginAddress) {
where = { ...where, pluginAddress: pluginAddress.toLowerCase() };
}
if (pluginRepoAddress) {
where = { ...where, pluginRepoAddress: pluginRepoAddress.toLowerCase() };
}
if (daoAddressOrEns) {
where = { ...where, dao: daoAddressOrEns.toLowerCase() };
}
const query = QueryPluginPreparationsExtended;
const params = {
where,
limit,
skip,
direction,
sortBy,
};
const name = "plugin preparations";
type T = { pluginPreparations: SubgraphPluginPreparationListItem[] };
const { pluginPreparations } = await this.graphql.request<T>({
query,
params,
name,
});
return Promise.all(
pluginPreparations.map(
(pluginPreparation: SubgraphPluginPreparationListItem) => {
return toPluginPreparationListItem(pluginPreparation);
},
),
);
}
}
33 changes: 33 additions & 0 deletions modules/client/src/internal/graphql-queries/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,36 @@ query PluginPreparations($where: PluginUpdatePreparation_filter!) {
}
}
`;

export const QueryPluginPreparationsExtended = gql`
query PluginPreparations($where: PluginUpdatePreparation_filter!, limit: Int!, skip: Int!, direction: OrderDirection!, sortBy: PluginUpdatePreparation_orderBy!) {
pluginPreparations(where: $where, first: $limit, skip: $skip, orderDirection: $direction, orderBy: $sortBy){
id
type
creator
dao {
id
}
pluginRepo {
id
subdomain
}
pluginVersion{
build
release{
release
}
}
pluginAddress
permissions {
id
operation
where
who
condition
}
helpers
data
}
}
`;
14 changes: 10 additions & 4 deletions modules/client/src/internal/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// This file contains the definitions of the general purpose DAO client
import {
ApplyInstallationParams,
ApplyUninstallationParams,
ApplyUpdateParams,
DaoAction,
DecodedApplyInstallationParams,
DecodedApplyUninstallationParams,
DecodedApplyUpdateParams,
GasFeeEstimation,
InterfaceParams,
PrepareInstallationParams,
PrepareInstallationStepValue,
PrepareUninstallationParams,
PrepareUninstallationStepValue,
PrepareUpdateParams,
PrepareUpdateStepValue,
} from "@aragon/sdk-client-common";
import {
ApplyUninstallationParams,
AssetBalance,
CreateDaoParams,
DaoBalancesQueryParams,
Expand All @@ -26,20 +29,19 @@ import {
DaoUpdateDecodedParams,
DaoUpdateParams,
DaoUpdateProposalValidity,
DecodedApplyUninstallationParams,
DepositParams,
GrantPermissionDecodedParams,
GrantPermissionParams,
GrantPermissionWithConditionParams,
HasPermissionParams,
InitializeFromParams,
IsDaoUpdateValidParams,
PluginPreparationListItem,
PluginPreparationQueryParams,
PluginQueryParams,
PluginRepo,
PluginRepoListItem,
PluginUpdateProposalValidity,
PrepareUninstallationParams,
PrepareUninstallationStepValue,
RegisterStandardCallbackParams,
RevokePermissionDecodedParams,
RevokePermissionParams,
Expand Down Expand Up @@ -114,6 +116,10 @@ export interface IClientMethods {
getDaoImplementation: (
daoFactoryAddress: string,
) => Promise<string>;

getPluginPreparations(
params: PluginPreparationQueryParams,
): Promise<PluginPreparationListItem[]>;
}

export interface IClientEncoding {
Expand Down
11 changes: 11 additions & 0 deletions modules/client/src/internal/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Uint8ArraySchema,
} from "@aragon/sdk-client-common";
import { array, mixed, number, object, string } from "yup";
import { PluginPreparationSortBy, PluginPreparationType } from "../types";

export const CreateDaoSchema = object({
metadataUri: IpfsUriSchema.required(),
Expand Down Expand Up @@ -187,3 +188,13 @@ export const IsDaoUpdateValidSchema = object({
daoAddress: AddressOrEnsSchema.required(),
version: array().of(number()).length(3).notRequired(),
});
export const PluginPreparationQuerySchema = PaginationSchema.concat(object({
sortBy: string().notRequired().oneOf([PluginPreparationSortBy.ID]),
type: string().notRequired().oneOf([
PluginPreparationType.INSTALLATION,
PluginPreparationType.UPDATE,
]),
daoAddressOrEns: AddressOrEnsSchema.notRequired(),
pluginAddress: AddressOrEnsSchema.notRequired(),
pluginRepoAddress: AddressOrEnsSchema.notRequired(),
}));
Loading

0 comments on commit 76b4fc8

Please sign in to comment.