import type { ProviderId, IdentityId, IdentityData, IdentitySignedClaim, ProviderToken, ProviderTokens, ProviderAuthenticateRequest, ProviderIdentityClaimId, ProviderPaginationToken } from './types.js'; import type { SignedClaim } from '../claims/types.js'; import type { ClaimLinkIdentity } from '../claims/payloads/claimLinkIdentity.js'; type GetTokens = () => Promise; type GetToken = (identityId: IdentityId) => Promise; type PutToken = (identityId: IdentityId, providerToken: ProviderToken) => Promise; type DelToken = (identityId: IdentityId) => Promise; declare abstract class Provider { /** * Set to the unique hostname of the provider */ abstract readonly id: ProviderId; /** * Set to true if getClaimsPage method should be preferred instead claim iteration operations. * This could be useful if the Provider subclass has a getClaimsPage implentation that is able to * obtain both Claims and ClaimsIds with a single HTTP request. For example, if the Provider were to * supply a GraphQL API, or if the webscraped page were to contain the contents of both. */ readonly preferGetClaimsPage: boolean; getTokens: GetTokens; getToken: GetToken; putToken: PutToken; delToken: DelToken; /** * Setting up token database functions * This must be called before the provider starts to be used */ setTokenDb(getTokens: GetTokens, getToken: GetToken, putToken: PutToken, delToken: DelToken): void; /** * Checks that the token is still valid * If the access token has expired, and there is no refresh token then this * will throw the ErrorProviderUnauthenticated exception * If the refresh token exists but has expired then this will throw the * ErrorProviderUnauthenticated exception * If the refresh token exists, and is still valid, then it will attempt to * refresh the token. * If you pass in identityId, expect that the new token will be persisted. * If either `providerToken.accessTokenExpiresIn` or `providerToken.refreshTokenExpiresIn` is set to 0, * their related tokens will be treated as never-expiring. */ checkToken(providerToken: ProviderToken, identityId?: IdentityId): Promise; /** * This verifies that the claim's JSON data fits our schema * This does not verify whether the signature is correct */ parseClaim(signedClaimEncodedJSON: string): SignedClaim | undefined; /** * Authenticates to an identity id, acquiring the token * This token must be stored on the token database. * This is a generator that only has 1 step. * This is because we require the caller to perform an authorisation action. * The final return value is the identity ID. */ abstract authenticate(timeout?: number): AsyncGenerator; /** * Refreshes the token * If identity is passed in, this function should update the token db */ abstract refreshToken(providerToken: ProviderToken, identityId?: IdentityId): Promise; /** * Gets an array of authenticated identity ids */ abstract getAuthIdentityIds(): Promise>; /** * Gets the corresponding identity ID to a token key */ abstract getIdentityId(providerToken: ProviderToken): Promise; /** * Gets the identity data for a given identity */ abstract getIdentityData(authIdentityId: IdentityId, identityId: IdentityId, options?: { signal?: AbortSignal; }): Promise; /** * Stream connected identity infos to a particular identity * This is intended to find "friends", "followers", "contacts"... etc * Some social providers do not have this concept * In such a case, one stream other random identities that exist on the network * Search terms are provider-implementation specific */ abstract getConnectedIdentityDatas(authIdentityId: IdentityId, searchTerms?: Array): AsyncGenerator; /** * Publishes an identity claim on the authenticated identity. * Returns an `IdentitySignedClaim`, wrapping the `SignedClaim` itself with extra * metadata from the published claim (e.g. URL, claim ID on provider) */ abstract publishClaim(authIdentityId: IdentityId, identityClaim: SignedClaim): Promise; /** * Gets the identity claim given the claim's ID on the provider */ abstract getClaim(authIdentityId: IdentityId, claimId: ProviderIdentityClaimId): Promise; /** * Stream a page of identity claimIds from an identity */ abstract getClaimIdsPage(authIdentityId: IdentityId, identityId: IdentityId, paginationToken?: ProviderPaginationToken): AsyncGenerator<{ claimId: ProviderIdentityClaimId; nextPaginationToken?: ProviderPaginationToken; }>; /** * Stream identity claimIds from an identity */ getClaimIds(authIdentityId: IdentityId, identityId: IdentityId): AsyncGenerator; /** * Stream a page of identity claims from an identity */ getClaimsPage(authIdentityId: IdentityId, identityId: IdentityId, paginationToken?: ProviderPaginationToken): AsyncGenerator<{ claim: IdentitySignedClaim; nextPaginationToken?: ProviderPaginationToken; }>; /** * Stream identity claims from an identity */ getClaims(authIdentityId: IdentityId, identityId: IdentityId): AsyncGenerator; } export default Provider;