Skip to content

Commit

Permalink
Update webhook response format
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Nov 4, 2024
1 parent 99ad972 commit 90c3e20
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions packages/sdk/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export class Client {
{
type: DocEventType.AuthError,
value: {
errorMessage: errorMetadataOf(err).message,
reason: errorMetadataOf(err).reason,
method: 'AttachDocument',
},
},
Expand Down Expand Up @@ -562,7 +562,7 @@ export class Client {
{
type: DocEventType.AuthError,
value: {
errorMessage: errorMetadataOf(err).message,
reason: errorMetadataOf(err).reason,
method: 'DetachDocument',
},
},
Expand Down Expand Up @@ -977,7 +977,7 @@ export class Client {
{
type: DocEventType.AuthError,
value: {
errorMessage: errorMetadataOf(err).message,
reason: errorMetadataOf(err).reason,
method: 'WatchDocuments',
},
},
Expand Down Expand Up @@ -1117,7 +1117,7 @@ export class Client {
{
type: DocEventType.AuthError,
value: {
errorMessage: errorMetadataOf(err).message,
reason: errorMetadataOf(err).reason,
method: 'PushPull',
},
},
Expand Down Expand Up @@ -1169,7 +1169,7 @@ export class Client {
if (errorCodeOf(err) === Code.ErrUnauthenticated) {
const token =
this.authTokenInjector &&
(await this.authTokenInjector(errorMetadataOf(err).message));
(await this.authTokenInjector(errorMetadataOf(err).reason));

this.rpcClient = createPromiseClient(
YorkieService,
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/document/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ export interface LocalBroadcastEvent extends BaseDocEvent {
export interface AuthErrorEvent extends BaseDocEvent {
type: DocEventType.AuthError;
value: {
errorMessage: string;
reason: string;
method: 'AttachDocument' | 'DetachDocument' | 'PushPull' | 'WatchDocuments';
};
}
Expand Down
34 changes: 17 additions & 17 deletions packages/sdk/test/integration/webhook_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,29 @@ webhookServer.post('/auth-webhook', express.json(), (req, res) => {
if (authToken.startsWith('token')) {
const expireTime = authToken.split('-')[1];
if (Number(expireTime) < Date.now()) {
res.status(200).send({
code: 401,
message: ExpiredTokenErrorMessage,
res.status(401).send({
allowed: false,
reason: ExpiredTokenErrorMessage,
});
return;
}
res.status(200).send({
code: 200,
allowed: true,
});
return;
}

if (authToken === NotAllowedToken) {
res.status(200).send({
code: 403,
res.status(403).send({
allowed: false,
});
return;
}

// invalid token
res.status(200).send({
code: 401,
message: InvalidTokenErrorMessage,
res.status(401).send({
allowed: false,
reason: InvalidTokenErrorMessage,
});
});

Expand Down Expand Up @@ -237,7 +237,7 @@ describe('Auth Webhook', () => {
toDocKey(`${task.name}-${new Date().getTime()}`),
);
const authErrorEventCollector = new EventCollector<{
errorMessage: string;
reason: string;
method: string;
}>();
doc.subscribe('auth-error', (event) => {
Expand All @@ -250,7 +250,7 @@ describe('Auth Webhook', () => {
expect(authTokenInjector).toBeCalledTimes(3);
expect(authTokenInjector).nthCalledWith(3, ExpiredTokenErrorMessage);
await authErrorEventCollector.waitAndVerifyNthEvent(1, {
errorMessage: ExpiredTokenErrorMessage,
reason: ExpiredTokenErrorMessage,
method: 'AttachDocument',
});

Expand All @@ -263,7 +263,7 @@ describe('Auth Webhook', () => {
expect(authTokenInjector).toBeCalledTimes(4);
expect(authTokenInjector).nthCalledWith(4, ExpiredTokenErrorMessage);
await authErrorEventCollector.waitAndVerifyNthEvent(2, {
errorMessage: ExpiredTokenErrorMessage,
reason: ExpiredTokenErrorMessage,
method: 'PushPull',
});

Expand All @@ -273,7 +273,7 @@ describe('Auth Webhook', () => {
expect(authTokenInjector).toBeCalledTimes(5);
expect(authTokenInjector).nthCalledWith(5, ExpiredTokenErrorMessage);
await authErrorEventCollector.waitAndVerifyNthEvent(3, {
errorMessage: ExpiredTokenErrorMessage,
reason: ExpiredTokenErrorMessage,
method: 'DetachDocument',
});

Expand Down Expand Up @@ -338,7 +338,7 @@ describe('Auth Webhook', () => {
syncEventCollector.add(event.value);
});
const authErrorEventCollector = new EventCollector<{
errorMessage: string;
reason: string;
method: string;
}>();
doc.subscribe('auth-error', (event) => {
Expand All @@ -351,7 +351,7 @@ describe('Auth Webhook', () => {

await syncEventCollector.waitFor(DocumentSyncStatus.Synced);
await authErrorEventCollector.waitFor({
errorMessage: ExpiredTokenErrorMessage,
reason: ExpiredTokenErrorMessage,
method: 'PushPull',
});
expect(authTokenInjector).toBeCalledTimes(2);
Expand Down Expand Up @@ -408,7 +408,7 @@ describe('Auth Webhook', () => {
const doc = new yorkie.Document<{ k1: string }>(docKey);

const authErrorEventCollector = new EventCollector<{
errorMessage: string;
reason: string;
method: string;
}>();
doc.subscribe('auth-error', (event) => {
Expand Down Expand Up @@ -436,7 +436,7 @@ describe('Auth Webhook', () => {
await new Promise((res) => setTimeout(res, TokenExpirationMs));
await client.attach(doc);
await authErrorEventCollector.waitFor({
errorMessage: ExpiredTokenErrorMessage,
reason: ExpiredTokenErrorMessage,
method: 'WatchDocuments',
});
expect(authTokenInjector).toBeCalledTimes(2);
Expand Down

0 comments on commit 90c3e20

Please sign in to comment.