@hello-bill/node 2.1.1 → 2.1.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/express/index.d.cts +1 -1
- package/dist/express/index.d.ts +1 -1
- package/dist/express/index.js +35 -8
- package/dist/express/index.js.map +1 -1
- package/dist/express/index.mjs +35 -8
- package/dist/express/index.mjs.map +1 -1
- package/dist/hono/index.d.cts +1 -1
- package/dist/hono/index.d.ts +1 -1
- package/dist/hono/index.js +35 -8
- package/dist/hono/index.js.map +1 -1
- package/dist/hono/index.mjs +35 -8
- package/dist/hono/index.mjs.map +1 -1
- package/dist/{index-D5WlUYVZ.d.cts → index-C_gIXrzG.d.cts} +7 -0
- package/dist/{index-jK9cEnEY.d.ts → index-DnEk4Y5R.d.ts} +7 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +32 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -8
- package/dist/index.mjs.map +1 -1
- package/dist/koa/index.d.cts +1 -1
- package/dist/koa/index.d.ts +1 -1
- package/dist/koa/index.js +35 -8
- package/dist/koa/index.js.map +1 -1
- package/dist/koa/index.mjs +35 -8
- package/dist/koa/index.mjs.map +1 -1
- package/dist/next/index.d.cts +1 -1
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.js +38 -8
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +38 -8
- package/dist/next/index.mjs.map +1 -1
- package/dist/webhook/index.d.cts +1 -1
- package/dist/webhook/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/express/index.mjs
CHANGED
|
@@ -132,9 +132,10 @@ function buildQueryString(query) {
|
|
|
132
132
|
async function callUpstream(apiBaseUrl, tokenManager, opts, fetchImpl) {
|
|
133
133
|
const base = apiBaseUrl.replace(/\/$/, "");
|
|
134
134
|
const url = `${base}${opts.path}${buildQueryString(opts.query)}`;
|
|
135
|
-
const
|
|
135
|
+
const m2mToken = await tokenManager.getAccessToken();
|
|
136
|
+
const bearerToken = opts.sessionBearer ?? m2mToken;
|
|
136
137
|
const headers = {
|
|
137
|
-
Authorization: `Bearer ${
|
|
138
|
+
Authorization: `Bearer ${bearerToken}`,
|
|
138
139
|
Accept: "application/json"
|
|
139
140
|
};
|
|
140
141
|
if (opts.body !== void 0) headers["Content-Type"] = "application/json";
|
|
@@ -144,14 +145,15 @@ async function callUpstream(apiBaseUrl, tokenManager, opts, fetchImpl) {
|
|
|
144
145
|
headers
|
|
145
146
|
};
|
|
146
147
|
if (opts.body !== void 0) init.body = JSON.stringify(opts.body);
|
|
148
|
+
const onTokenExpired = opts.sessionBearer ? void 0 : async () => {
|
|
149
|
+
await tokenManager.invalidate();
|
|
150
|
+
const fresh = await tokenManager.getAccessToken();
|
|
151
|
+
headers.Authorization = `Bearer ${fresh}`;
|
|
152
|
+
};
|
|
147
153
|
const res = await retryFetch(url, init, {
|
|
148
154
|
fetch: fetchImpl,
|
|
149
155
|
timeoutMs: opts.timeoutMs,
|
|
150
|
-
onTokenExpired
|
|
151
|
-
await tokenManager.invalidate();
|
|
152
|
-
const fresh = await tokenManager.getAccessToken();
|
|
153
|
-
headers.Authorization = `Bearer ${fresh}`;
|
|
154
|
-
}
|
|
156
|
+
onTokenExpired
|
|
155
157
|
});
|
|
156
158
|
let body = null;
|
|
157
159
|
const text = await res.text();
|
|
@@ -929,6 +931,27 @@ function createHellobillHandler(opts) {
|
|
|
929
931
|
if (!result2) return;
|
|
930
932
|
passthroughUpstream(res, result2.status, result2.body, result2.requestId, result2.headers);
|
|
931
933
|
};
|
|
934
|
+
const loaDocument = async (req, res) => {
|
|
935
|
+
const rawLoa = req.query.loa_id ?? req.params?.id;
|
|
936
|
+
const loaId = Array.isArray(rawLoa) ? rawLoa[0] : rawLoa;
|
|
937
|
+
if (!loaId) {
|
|
938
|
+
sendError(res, 400, "validation.missing_required_field", "loa_id query parameter required");
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
const sessionBearer = extractBearer(req);
|
|
942
|
+
if (!sessionBearer) {
|
|
943
|
+
sendError(res, 401, "auth.token_malformed", "Missing Authorization bearer token");
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
const result2 = await safeCallUpstream(res, {
|
|
947
|
+
method: "GET",
|
|
948
|
+
path: `/partner/loa/${encodeURIComponent(loaId)}/document`,
|
|
949
|
+
sessionBearer,
|
|
950
|
+
logger
|
|
951
|
+
});
|
|
952
|
+
if (!result2) return;
|
|
953
|
+
passthroughUpstream(res, result2.status, result2.body, result2.requestId, result2.headers);
|
|
954
|
+
};
|
|
932
955
|
const webhookHandler = opts.webhook ? createWebhookHandler({ ...opts.webhook, logger: opts.webhook.logger ?? opts.logger }) : void 0;
|
|
933
956
|
const result = {
|
|
934
957
|
session,
|
|
@@ -940,7 +963,8 @@ function createHellobillHandler(opts) {
|
|
|
940
963
|
property,
|
|
941
964
|
sessions: { list: sessionsList, get: sessionsGet },
|
|
942
965
|
savingsSummary,
|
|
943
|
-
serviceSlots
|
|
966
|
+
serviceSlots,
|
|
967
|
+
loaDocument
|
|
944
968
|
};
|
|
945
969
|
if (webhookHandler !== void 0) {
|
|
946
970
|
result.webhook = webhookHandler;
|
|
@@ -1029,6 +1053,9 @@ function createHellobillRouter(opts) {
|
|
|
1029
1053
|
router.get("/property", asyncWrap(handlers.property));
|
|
1030
1054
|
router.get("/sessions", asyncWrap(handlers.sessions.list));
|
|
1031
1055
|
router.get("/sessions/:id", asyncWrap(handlers.sessions.get));
|
|
1056
|
+
router.get("/service-slots", asyncWrap(handlers.serviceSlots));
|
|
1057
|
+
router.get("/savings-summary", asyncWrap(handlers.savingsSummary));
|
|
1058
|
+
router.get("/loa-document", asyncWrap(handlers.loaDocument));
|
|
1032
1059
|
router.use(
|
|
1033
1060
|
(err, _req, res, _next) => {
|
|
1034
1061
|
opts.logger?.error?.("hellobill.router_error", { message: err?.message });
|