Skip to content

Commit c5a71bc

Browse files
feat(backend): Artifacts API + __experimental_getPoppyJson (#10810)
1 parent d09bc82 commit c5a71bc

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎.changeset/artifacts-api.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/backend": minor
3+
---
4+
5+
Fetch the Poppy JSON artifact with the Clerk-defined `clerkClient.artifacts.__experimental_getPoppyJson()` method.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { http, HttpResponse } from 'msw';
2+
import { describe, expect, it } from 'vitest';
3+
4+
import { server } from '../../mock-server';
5+
import { createBackendApiClient } from '../factory';
6+
7+
describe('ArtifactsAPI', () => {
8+
it('fetches the Poppy artifact and returns its data unchanged', async () => {
9+
const data = { arbitrary_key: 'value', nested: { another_key: [1, true, null] } };
10+
server.use(
11+
http.get('https://api.clerk.test/v1/artifacts/well-known-poppy', ({ request }) => {
12+
expect(request.headers.get('Authorization')).toBe('Bearer sk_live_example');
13+
expect(new URL(request.url).search).toBe('');
14+
return HttpResponse.json({ object: 'artifact', data });
15+
}),
16+
);
17+
const { artifacts } = createBackendApiClient({
18+
apiUrl: 'https://api.clerk.test',
19+
secretKey: 'sk_live_example',
20+
});
21+
await expect(artifacts.__experimental_getPoppyJson()).resolves.toEqual(data);
22+
});
23+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { AbstractAPI } from './AbstractApi';
2+
3+
export type PoppyMetadata = unknown;
4+
5+
export class ArtifactsAPI extends AbstractAPI {
6+
public async __experimental_getPoppyJson() {
7+
const artifact = await this.request<{ object: 'artifact'; data: PoppyMetadata }>({
8+
method: 'GET',
9+
path: '/artifacts/well-known-poppy',
10+
});
11+
return artifact.data;
12+
}
13+
}

‎packages/backend/src/api/factory.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
WaitlistEntryAPI,
3636
WebhookAPI,
3737
} from './endpoints';
38+
import { ArtifactsAPI } from './endpoints/ArtifactsApi';
3839
import { BillingAPI } from './endpoints/BillingApi';
3940
import { buildRequest } from './request';
4041

@@ -63,6 +64,7 @@ export function createBackendApiClient(options: CreateBackendApiOptions) {
6364
skipApiVersionInUrl: true,
6465
}),
6566
),
67+
artifacts: new ArtifactsAPI(request),
6668
betaFeatures: new BetaFeaturesAPI(request),
6769
blocklistIdentifiers: new BlocklistIdentifierAPI(request),
6870
/**

0 commit comments

Comments
 (0)