Skip to content

Commit 062fd97

Browse files
committedJul 15, 2024·
fix lint
1 parent 2608301 commit 062fd97

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed
 

‎lib/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ type Payload = {
3636
};
3737
declare class APIToolkit {
3838
#private;
39-
constructor(pubsub: PubSub, topic: string, project_id: string, fastify: FastifyInstance, redactHeaders: string[], redactReqBody: string[], redactRespBody: string[], service_version: string | undefined, tags: string[], debug: boolean, monitorAxios: AxiosInstance | undefined);
39+
constructor(pubsub: PubSub | undefined, topic: string | undefined, project_id: string | undefined, fastify: FastifyInstance, redactHeaders: string[], redactReqBody: string[], redactRespBody: string[], service_version: string | undefined, tags: string[], debug: boolean, monitorAxios: AxiosInstance | undefined);
4040
static NewClient({ apiKey, fastify, rootURL, redactHeaders, redactRequestBody, redactResponseBody, service_version, debug, tags, monitorAxios, }: Config): APIToolkit;
4141
private getStringValue;
4242
private getQuery;
4343
publishMessage(payload: Payload): void;
4444
getConfig(): {
45-
project_id: string;
45+
project_id: string | undefined;
4646
config: {
4747
service_version: string | undefined;
4848
tags: string[];

‎lib/index.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,15 @@ class APIToolkit {
5959
Accept: "application/json",
6060
},
6161
});
62-
if (!resp.ok)
63-
throw new Error(`Error getting apitoolkit client_metadata ${resp.status}`);
62+
if (!resp.ok) {
63+
if (resp.status === 401) {
64+
throw new Error("APIToolkit: Invalid API Key");
65+
}
66+
else {
67+
console.log(`Error getting apitoolkit client_metadata ${resp.status}`);
68+
}
69+
return new APIToolkit(undefined, undefined, undefined, fastify, redactHeaders, redactRequestBody, redactResponseBody, service_version, tags, debug, monitorAxios);
70+
}
6471
const clientMetadata = resp.json();
6572
const { pubsub_project_id, topic_id, project_id, pubsub_push_service_account, } = clientMetadata;
6673
const pubsubClient = new pubsub_1.PubSub({
@@ -103,7 +110,9 @@ class APIToolkit {
103110
console.log("apitoolkit: publishing message");
104111
console.log(payload);
105112
}
106-
__classPrivateFieldGet(this, _APIToolkit_pubsub, "f").topic(__classPrivateFieldGet(this, _APIToolkit_topic, "f")).publishMessage({ json: payload });
113+
if (__classPrivateFieldGet(this, _APIToolkit_pubsub, "f") && __classPrivateFieldGet(this, _APIToolkit_topic, "f")) {
114+
__classPrivateFieldGet(this, _APIToolkit_pubsub, "f").topic(__classPrivateFieldGet(this, _APIToolkit_topic, "f")).publishMessage({ json: payload });
115+
}
107116
}
108117
getConfig() {
109118
return {
@@ -154,6 +163,9 @@ class APIToolkit {
154163
if (__classPrivateFieldGet(this, _APIToolkit_debug, "f")) {
155164
console.log("apitoolkit: onSend hook called");
156165
}
166+
if (!__classPrivateFieldGet(this, _APIToolkit_project_id, "f")) {
167+
return data;
168+
}
157169
try {
158170
const reqBody = this.getStringValue(request.body);
159171
const resBody = this.getStringValue(data);

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"format": "npx prettier --write .",
1212
"prepare": "npm run build",
1313
"prepublishOnly": "npm run lint",
14-
"preversion": "npm lint",
14+
"preversion": "npm run lint",
1515
"version": "git add -A src",
1616
"postversion": "git push && git push --tags",
1717
"updates": "npx npm-check-updates",

0 commit comments

Comments
 (0)
Please sign in to comment.