Skip to content

Commit 2b5634d

Browse files
committed
silent errors plus github actions
1 parent d339348 commit 2b5634d

File tree

6 files changed

+159
-11
lines changed

6 files changed

+159
-11
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ""
5+
labels: ""
6+
assignees: ""
7+
---
8+
9+
**Describe the bug**
10+
A clear and concise description of what the bug is.
11+
12+
**To Reproduce**
13+
Steps to reproduce the behavior:
14+
15+
1.
16+
2.
17+
3.
18+
19+
**Expected behavior**
20+
A clear and concise description of what you expected to happen.
21+
22+
**Screenshots**
23+
If applicable, add screenshots to help explain your problem.
24+
25+
**Desktop (please complete the following information):**
26+
27+
- OS: [e.g. Ubuntu 22.04, macOS 11.4]
28+
- Node version [e.g 16.4.2]
29+
- Code Version [e.g. 1.1.0]
30+
31+
**Additional context**
32+
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: GitHub Discussions
4+
url: https://github.com/apitoolkit/apitoolkit-express/discussions
5+
about: Please discuss non bug-related topics there
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ""
5+
labels: ""
6+
assignees: ""
7+
---
8+
9+
**Is your feature request related to a problem? Please describe.**
10+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
11+
12+
**Describe the solution you'd like**
13+
A clear and concise description of what you want to happen.
14+
15+
**Describe alternatives you've considered**
16+
A clear and concise description of any alternative solutions or features you've considered.
17+
18+
**Additional context**
19+
Add any other context or screenshots about the feature request here.

.github/dependabot.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "npm" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"

.github/workflows/release_package.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Release package
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
jobs:
7+
release:
8+
runs-on: ubuntu-latest
9+
steps:
10+
# Checkout project repository
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
14+
# Setup Node.js environment
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: "16"
19+
registry-url: "https://registry.npmjs.org"
20+
21+
- name: Install dependencies
22+
run: npm install
23+
24+
- run: npm run build
25+
26+
# Configure Git
27+
- name: Git configuration
28+
run: |
29+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
30+
git config --global user.name "GitHub Actions"
31+
32+
# Extract version from tag
33+
- name: Get version from tag
34+
run: echo "NEW_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
35+
36+
# Determine if it's a pre-release
37+
- name: Check if pre-release
38+
run: |
39+
if [[ ${{ env.NEW_VERSION }} == *"-"* ]]; then
40+
echo "RELEASE_TAG=beta" >> $GITHUB_ENV
41+
else
42+
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
43+
fi
44+
45+
# Bump version in package.json
46+
- name: Bump version
47+
run: npm version ${{ env.NEW_VERSION }} --no-git-tag-version
48+
49+
# Push repository changes
50+
- name: Push changes to repository
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
run: |
54+
git push origin temp-branch:master
55+
56+
# Publish version to npmdd
57+
- name: Publish
58+
run: yarn publish --verbose --access public --tag ${{ env.RELEASE_TAG }}
59+
env:
60+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

src/index.ts

+32-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fetch from "sync-fetch";
22
import { PubSub, Topic } from "@google-cloud/pubsub";
33
import { hrtime } from "node:process";
44
import { v4 as uuidv4 } from "uuid";
5-
import axios, { AxiosInstance, AxiosStatic } from "axios";
5+
import { AxiosInstance, AxiosStatic } from "axios";
66
import { FastifyInstance } from "fastify";
77
import {
88
buildPayload,
@@ -55,9 +55,9 @@ type Payload = {
5555
};
5656

5757
class APIToolkit {
58-
#topic: string;
59-
#pubsub: PubSub;
60-
#project_id: string;
58+
#topic: string | undefined;
59+
#pubsub: PubSub | undefined;
60+
#project_id: string | undefined;
6161
#redactHeaders: string[];
6262
#redactRequestBody: string[];
6363
#redactResponseBody: string[];
@@ -69,9 +69,9 @@ class APIToolkit {
6969
#axios: AxiosInstance | undefined;
7070

7171
constructor(
72-
pubsub: PubSub,
73-
topic: string,
74-
project_id: string,
72+
pubsub: PubSub | undefined,
73+
topic: string | undefined,
74+
project_id: string | undefined,
7575
fastify: FastifyInstance,
7676
redactHeaders: string[],
7777
redactReqBody: string[],
@@ -114,10 +114,26 @@ class APIToolkit {
114114
Accept: "application/json",
115115
},
116116
});
117-
if (!resp.ok)
118-
throw new Error(
119-
`Error getting apitoolkit client_metadata ${resp.status}`
117+
if (!resp.ok) {
118+
if (resp.status === 401) {
119+
throw new Error("APIToolkit: Invalid API Key");
120+
} else {
121+
console.log(`Error getting apitoolkit client_metadata ${resp.status}`);
122+
}
123+
return new APIToolkit(
124+
undefined,
125+
undefined,
126+
undefined,
127+
fastify,
128+
redactHeaders,
129+
redactRequestBody,
130+
redactResponseBody,
131+
service_version,
132+
tags,
133+
debug,
134+
monitorAxios
120135
);
136+
}
121137

122138
const clientMetadata = resp.json() as ClientMetadata;
123139
const {
@@ -176,7 +192,9 @@ class APIToolkit {
176192
console.log("apitoolkit: publishing message");
177193
console.log(payload);
178194
}
179-
this.#pubsub.topic(this.#topic).publishMessage({ json: payload });
195+
if (this.#pubsub && this.#topic) {
196+
this.#pubsub.topic(this.#topic).publishMessage({ json: payload });
197+
}
180198
}
181199

182200
public getConfig() {
@@ -253,6 +271,9 @@ class APIToolkit {
253271
if (this.#debug) {
254272
console.log("apitoolkit: onSend hook called");
255273
}
274+
if (!this.#project_id) {
275+
return data;
276+
}
256277

257278
try {
258279
const reqBody = this.getStringValue(request.body);

0 commit comments

Comments
 (0)