Skip to content

Commit 0ee396a

Browse files
committed
chore(webhooks): make private methods really private
1 parent 586d5da commit 0ee396a

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/resources/webhooks.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,6 @@ export class Webhooks extends APIResource {
1919
return JSON.parse(payload) as UnwrapWebhookEvent;
2020
}
2121

22-
private validateSecret(secret: string | null | undefined): asserts secret is string {
23-
if (typeof secret !== 'string' || secret.length === 0) {
24-
throw new Error(
25-
`The webhook secret must either be set using the env var, OPENAI_WEBHOOK_SECRET, on the client class, OpenAI({ webhookSecret: '123' }), or passed to this function`,
26-
);
27-
}
28-
}
29-
30-
private getRequiredHeader(headers: Headers, name: string): string {
31-
if (!headers) {
32-
throw new Error(`Headers are required`);
33-
}
34-
35-
const value = headers.get(name);
36-
37-
if (value === null || value === undefined) {
38-
throw new Error(`Missing required header: ${name}`);
39-
}
40-
41-
return value;
42-
}
43-
4422
/**
4523
* Validates whether or not the webhook payload was sent by OpenAI.
4624
*
@@ -65,12 +43,12 @@ export class Webhooks extends APIResource {
6543
throw new Error('Webhook signature verification is only supported when the `crypto` global is defined');
6644
}
6745

68-
this.validateSecret(secret);
46+
this.#validateSecret(secret);
6947

7048
const headersObj = buildHeaders([headers]).values;
71-
const signatureHeader = this.getRequiredHeader(headersObj, 'webhook-signature');
72-
const timestamp = this.getRequiredHeader(headersObj, 'webhook-timestamp');
73-
const webhookId = this.getRequiredHeader(headersObj, 'webhook-id');
49+
const signatureHeader = this.#getRequiredHeader(headersObj, 'webhook-signature');
50+
const timestamp = this.#getRequiredHeader(headersObj, 'webhook-timestamp');
51+
const webhookId = this.#getRequiredHeader(headersObj, 'webhook-id');
7452

7553
// Validate timestamp to prevent replay attacks
7654
const timestampSeconds = parseInt(timestamp, 10);
@@ -137,6 +115,28 @@ export class Webhooks extends APIResource {
137115
'The given webhook signature does not match the expected signature',
138116
);
139117
}
118+
119+
#validateSecret(secret: string | null | undefined): asserts secret is string {
120+
if (typeof secret !== 'string' || secret.length === 0) {
121+
throw new Error(
122+
`The webhook secret must either be set using the env var, OPENAI_WEBHOOK_SECRET, on the client class, OpenAI({ webhookSecret: '123' }), or passed to this function`,
123+
);
124+
}
125+
}
126+
127+
#getRequiredHeader(headers: Headers, name: string): string {
128+
if (!headers) {
129+
throw new Error(`Headers are required`);
130+
}
131+
132+
const value = headers.get(name);
133+
134+
if (value === null || value === undefined) {
135+
throw new Error(`Missing required header: ${name}`);
136+
}
137+
138+
return value;
139+
}
140140
}
141141

142142
/**

0 commit comments

Comments
 (0)