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
25 changes: 25 additions & 0 deletions .changeset/fuzzy-chefs-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'@clerk/backend': minor
---

Adds the Blocklist Identifier endpoints to the Backend API client.

```ts
import { createClerkClient } from '@clerk/backend';

const clerkClient = createClerkClient(...);
await clerkClient.blocklistIdentifiers.getBlocklistIdentifierList();
await clerkClient.blocklistIdentifiers.createBlocklistIdentifier({ identifier });
await clerkClient.blocklistIdentifiers.deleteBlocklistIdentifier('blocklistIdentifierId');
```

Updates the ability paginate Allowlist Identifier reponses and access `identifierType` and `instanceId` from the response.

```ts
import { createClerkClient } from '@clerk/backend';

const clerkClient = createClerkClient(...);
const res = await clerkClient.blocklistIdentifiers.getAllowlistIdentifierList({ limit, offset });
```

Corrects the type of the Allowlist Identifier `DeletedObject`
9 changes: 6 additions & 3 deletions packages/backend/src/api/endpoints/AllowlistIdentifierApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { ClerkPaginationRequest } from '@clerk/types';

import { joinPaths } from '../../util/path';
import type { AllowlistIdentifier } from '../resources/AllowlistIdentifier';
import type { DeletedObject } from '../resources/DeletedObject';
import type { PaginatedResourceResponse } from '../resources/Deserializer';
import { AbstractAPI } from './AbstractApi';

Expand All @@ -11,11 +14,11 @@ type AllowlistIdentifierCreateParams = {
};

export class AllowlistIdentifierAPI extends AbstractAPI {
public async getAllowlistIdentifierList() {
public async getAllowlistIdentifierList(params: ClerkPaginationRequest = {}) {
return this.request<PaginatedResourceResponse<AllowlistIdentifier[]>>({
method: 'GET',
path: basePath,
queryParams: { paginated: true },
queryParams: { ...params, paginated: true },
});
}

Expand All @@ -29,7 +32,7 @@ export class AllowlistIdentifierAPI extends AbstractAPI {

public async deleteAllowlistIdentifier(allowlistIdentifierId: string) {
this.requireId(allowlistIdentifierId);
return this.request<AllowlistIdentifier>({
return this.request<DeletedObject>({
method: 'DELETE',
path: joinPaths(basePath, allowlistIdentifierId),
});
Expand Down
39 changes: 39 additions & 0 deletions packages/backend/src/api/endpoints/BlocklistIdentifierApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { ClerkPaginationRequest } from '@clerk/types';

import { joinPaths } from '../../util/path';
import type { BlocklistIdentifier } from '../resources/BlocklistIdentifier';
import type { DeletedObject } from '../resources/DeletedObject';
import type { PaginatedResourceResponse } from '../resources/Deserializer';
import { AbstractAPI } from './AbstractApi';

const basePath = '/blocklist_identifiers';

type BlocklistIdentifierCreateParams = {
identifier: string;
};

export class BlocklistIdentifierAPI extends AbstractAPI {
public async getBlocklistIdentifierList(params: ClerkPaginationRequest = {}) {
return this.request<PaginatedResourceResponse<BlocklistIdentifier[]>>({
method: 'GET',
path: basePath,
queryParams: params,
});
}

public async createBlocklistIdentifier(params: BlocklistIdentifierCreateParams) {
return this.request<BlocklistIdentifier>({
method: 'POST',
path: basePath,
bodyParams: params,
});
}

public async deleteBlocklistIdentifier(blocklistIdentifierId: string) {
this.requireId(blocklistIdentifierId);
return this.request<DeletedObject>({
method: 'DELETE',
path: joinPaths(basePath, blocklistIdentifierId),
});
}
}
1 change: 1 addition & 0 deletions packages/backend/src/api/endpoints/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './AccountlessApplicationsAPI';
export * from './AbstractApi';
export * from './AllowlistIdentifierApi';
export * from './BlocklistIdentifierApi';
export * from './ClientApi';
export * from './DomainApi';
export * from './EmailAddressApi';
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/api/factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
AccountlessApplicationAPI,
AllowlistIdentifierAPI,
BlocklistIdentifierAPI,
ClientAPI,
DomainAPI,
EmailAddressAPI,
Expand Down Expand Up @@ -31,6 +32,7 @@ export function createBackendApiClient(options: CreateBackendApiOptions) {
buildRequest({ ...options, requireSecretKey: false }),
),
allowlistIdentifiers: new AllowlistIdentifierAPI(request),
blocklistIdentifiers: new BlocklistIdentifierAPI(request),
clients: new ClientAPI(request),
emailAddresses: new EmailAddressAPI(request),
invitations: new InvitationAPI(request),
Expand Down
13 changes: 12 additions & 1 deletion packages/backend/src/api/resources/AllowlistIdentifier.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import type { AllowlistIdentifierType } from './Enums';
import type { AllowlistIdentifierJSON } from './JSON';

export class AllowlistIdentifier {
constructor(
readonly id: string,
readonly identifier: string,
readonly identifierType: AllowlistIdentifierType,
readonly createdAt: number,
readonly updatedAt: number,
readonly instanceId?: string,
readonly invitationId?: string,
) {}

static fromJSON(data: AllowlistIdentifierJSON): AllowlistIdentifier {
return new AllowlistIdentifier(data.id, data.identifier, data.created_at, data.updated_at, data.invitation_id);
return new AllowlistIdentifier(
data.id,
data.identifier,
data.identifier_type,
data.created_at,
data.updated_at,
data.instance_id,
data.invitation_id,
);
}
}
24 changes: 24 additions & 0 deletions packages/backend/src/api/resources/BlocklistIdentifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { BlocklistIdentifierType } from './Enums';
import type { BlocklistIdentifierJSON } from './JSON';

export class BlocklistIdentifier {
constructor(
readonly id: string,
readonly identifier: string,
readonly identifierType: BlocklistIdentifierType,
readonly createdAt: number,
readonly updatedAt: number,
readonly instanceId?: string,
) {}

static fromJSON(data: BlocklistIdentifierJSON): BlocklistIdentifier {
return new BlocklistIdentifier(
data.id,
data.identifier,
data.identifier_type,
data.created_at,
data.updated_at,
data.instance_id,
);
}
}
3 changes: 3 additions & 0 deletions packages/backend/src/api/resources/Deserializer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
AllowlistIdentifier,
BlocklistIdentifier,
Client,
Cookies,
DeletedObject,
Expand Down Expand Up @@ -73,6 +74,8 @@ function jsonToObject(item: any): any {
return AccountlessApplication.fromJSON(item);
case ObjectType.AllowlistIdentifier:
return AllowlistIdentifier.fromJSON(item);
case ObjectType.BlocklistIdentifier:
return BlocklistIdentifier.fromJSON(item);
case ObjectType.Client:
return Client.fromJSON(item);
case ObjectType.Cookies:
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/api/resources/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ export type SignInStatus = 'needs_identifier' | 'needs_factor_one' | 'needs_fact
export type SignUpStatus = 'missing_requirements' | 'complete' | 'abandoned';

export type InvitationStatus = 'pending' | 'accepted' | 'revoked' | 'expired';

export type AllowlistIdentifierType = 'email_address' | 'phone_number' | 'web3_wallet';

export type BlocklistIdentifierType = AllowlistIdentifierType;
16 changes: 15 additions & 1 deletion packages/backend/src/api/resources/JSON.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type {
AllowlistIdentifierType,
BlocklistIdentifierType,
InvitationStatus,
OrganizationDomainVerificationStatus,
OrganizationDomainVerificationStrategy,
Expand All @@ -12,6 +14,7 @@ import type {
export const ObjectType = {
AccountlessApplication: 'accountless_application',
AllowlistIdentifier: 'allowlist_identifier',
BlocklistIdentifier: 'blocklist_identifier',
Client: 'client',
Cookies: 'cookies',
Email: 'email',
Expand Down Expand Up @@ -73,9 +76,20 @@ export interface AccountlessApplicationJSON extends ClerkResourceJSON {
export interface AllowlistIdentifierJSON extends ClerkResourceJSON {
object: typeof ObjectType.AllowlistIdentifier;
identifier: string;
identifier_type: AllowlistIdentifierType;
instance_id?: string;
invitation_id?: string;
created_at: number;
updated_at: number;
}

export interface BlocklistIdentifierJSON extends ClerkResourceJSON {
object: typeof ObjectType.BlocklistIdentifier;
identifier: string;
identifier_type: BlocklistIdentifierType;
instance_id?: string;
created_at: number;
updated_at: number;
invitation_id?: string;
}

export interface ClientJSON extends ClerkResourceJSON {
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/api/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './AccountlessApplication';
export * from './AllowlistIdentifier';
export * from './BlocklistIdentifier';
export * from './Client';
export * from './Cookies';
export * from './DeletedObject';
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type {
ClerkResourceJSON,
TokenJSON,
AllowlistIdentifierJSON,
BlocklistIdentifierJSON,
ClientJSON,
EmailJSON,
EmailAddressJSON,
Expand Down Expand Up @@ -96,6 +97,7 @@ export type {
export type {
AccountlessApplication,
AllowlistIdentifier,
BlocklistIdentifier,
Client,
EmailAddress,
ExternalAccount,
Expand Down