@hello-bill/node 2.1.1-beta.7 → 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.d.cts
CHANGED
package/dist/express/index.d.ts
CHANGED
package/dist/express/index.js
CHANGED
|
@@ -135,9 +135,10 @@ function buildQueryString(query) {
|
|
|
135
135
|
async function callUpstream(apiBaseUrl, tokenManager, opts, fetchImpl) {
|
|
136
136
|
const base = apiBaseUrl.replace(/\/$/, "");
|
|
137
137
|
const url = `${base}${opts.path}${buildQueryString(opts.query)}`;
|
|
138
|
-
const
|
|
138
|
+
const m2mToken = await tokenManager.getAccessToken();
|
|
139
|
+
const bearerToken = opts.sessionBearer ?? m2mToken;
|
|
139
140
|
const headers = {
|
|
140
|
-
Authorization: `Bearer ${
|
|
141
|
+
Authorization: `Bearer ${bearerToken}`,
|
|
141
142
|
Accept: "application/json"
|
|
142
143
|
};
|
|
143
144
|
if (opts.body !== void 0) headers["Content-Type"] = "application/json";
|
|
@@ -147,14 +148,15 @@ async function callUpstream(apiBaseUrl, tokenManager, opts, fetchImpl) {
|
|
|
147
148
|
headers
|
|
148
149
|
};
|
|
149
150
|
if (opts.body !== void 0) init.body = JSON.stringify(opts.body);
|
|
151
|
+
const onTokenExpired = opts.sessionBearer ? void 0 : async () => {
|
|
152
|
+
await tokenManager.invalidate();
|
|
153
|
+
const fresh = await tokenManager.getAccessToken();
|
|
154
|
+
headers.Authorization = `Bearer ${fresh}`;
|
|
155
|
+
};
|
|
150
156
|
const res = await retryFetch(url, init, {
|
|
151
157
|
fetch: fetchImpl,
|
|
152
158
|
timeoutMs: opts.timeoutMs,
|
|
153
|
-
onTokenExpired
|
|
154
|
-
await tokenManager.invalidate();
|
|
155
|
-
const fresh = await tokenManager.getAccessToken();
|
|
156
|
-
headers.Authorization = `Bearer ${fresh}`;
|
|
157
|
-
}
|
|
159
|
+
onTokenExpired
|
|
158
160
|
});
|
|
159
161
|
let body = null;
|
|
160
162
|
const text = await res.text();
|
|
@@ -932,6 +934,27 @@ function createHellobillHandler(opts) {
|
|
|
932
934
|
if (!result2) return;
|
|
933
935
|
passthroughUpstream(res, result2.status, result2.body, result2.requestId, result2.headers);
|
|
934
936
|
};
|
|
937
|
+
const loaDocument = async (req, res) => {
|
|
938
|
+
const rawLoa = req.query.loa_id ?? req.params?.id;
|
|
939
|
+
const loaId = Array.isArray(rawLoa) ? rawLoa[0] : rawLoa;
|
|
940
|
+
if (!loaId) {
|
|
941
|
+
sendError(res, 400, "validation.missing_required_field", "loa_id query parameter required");
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
const sessionBearer = extractBearer(req);
|
|
945
|
+
if (!sessionBearer) {
|
|
946
|
+
sendError(res, 401, "auth.token_malformed", "Missing Authorization bearer token");
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
const result2 = await safeCallUpstream(res, {
|
|
950
|
+
method: "GET",
|
|
951
|
+
path: `/partner/loa/${encodeURIComponent(loaId)}/document`,
|
|
952
|
+
sessionBearer,
|
|
953
|
+
logger
|
|
954
|
+
});
|
|
955
|
+
if (!result2) return;
|
|
956
|
+
passthroughUpstream(res, result2.status, result2.body, result2.requestId, result2.headers);
|
|
957
|
+
};
|
|
935
958
|
const webhookHandler = opts.webhook ? createWebhookHandler({ ...opts.webhook, logger: opts.webhook.logger ?? opts.logger }) : void 0;
|
|
936
959
|
const result = {
|
|
937
960
|
session,
|
|
@@ -943,7 +966,8 @@ function createHellobillHandler(opts) {
|
|
|
943
966
|
property,
|
|
944
967
|
sessions: { list: sessionsList, get: sessionsGet },
|
|
945
968
|
savingsSummary,
|
|
946
|
-
serviceSlots
|
|
969
|
+
serviceSlots,
|
|
970
|
+
loaDocument
|
|
947
971
|
};
|
|
948
972
|
if (webhookHandler !== void 0) {
|
|
949
973
|
result.webhook = webhookHandler;
|
|
@@ -1032,6 +1056,9 @@ function createHellobillRouter(opts) {
|
|
|
1032
1056
|
router.get("/property", asyncWrap(handlers.property));
|
|
1033
1057
|
router.get("/sessions", asyncWrap(handlers.sessions.list));
|
|
1034
1058
|
router.get("/sessions/:id", asyncWrap(handlers.sessions.get));
|
|
1059
|
+
router.get("/service-slots", asyncWrap(handlers.serviceSlots));
|
|
1060
|
+
router.get("/savings-summary", asyncWrap(handlers.savingsSummary));
|
|
1061
|
+
router.get("/loa-document", asyncWrap(handlers.loaDocument));
|
|
1035
1062
|
router.use(
|
|
1036
1063
|
(err, _req, res, _next) => {
|
|
1037
1064
|
opts.logger?.error?.("hellobill.router_error", { message: err?.message });
|