Skip to content

Commit

Permalink
Add API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
NSeydoux committed Dec 17, 2024
1 parent aae7cdb commit 496b877
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/gConsent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export {
CredentialResult,
CredentialStatus,
CredentialType,
DURATION,
query,
} from "./query/query";

Expand Down
39 changes: 39 additions & 0 deletions src/gConsent/query/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export type CredentialType =
| "SolidAccessGrant"
| "SolidAccessDenial";

export const DURATION = {
ONE_DAY: "P1D",
ONE_WEEK: "P7D",
ONE_MONTH: "P1M",
THREE_MONTHS: "P3M",
} as const;

export type CredentialFilter = {
type?: CredentialType;
status?: CredentialStatus;
Expand Down Expand Up @@ -147,6 +154,38 @@ function toQueryUrl(endpoint: URL, filter: CredentialFilter): URL {
return result;
}

/**
* Query for Access Requests or Access Grants based on a given filter.
*
* @param filter the query filter
* @param options query options
* @returns a paginated set of Access Credential matching the given filter
* @since unreleased
*
* @example
* ```
* // Get the first results page.
* const activeGrantsToday = await query(
* {
* type: "SolidAccessGrant",
* status: "Active",
* issuedWithin: DURATION.ONE_DAY,
* },
* {
* fetch: session.fetch,
* queryEndpoint: config.queryEndpoint,
* },
* );
* // Get the next results page.
* const activeGrantsToday2 = await query(
* activeGrantsToday.next,
* {
* fetch: session.fetch,
* queryEndpoint: config.queryEndpoint,
* },
* );
* ```
*/
export async function query(
filter: CredentialFilter,
options: {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export {
CredentialStatus,
CredentialType,
denyAccessRequest,
DURATION,
getAccessApiEndpoint,
getAccessGrant,
getAccessGrantAll,
Expand Down

0 comments on commit 496b877

Please sign in to comment.