@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.
@@ -1,4 +1,4 @@
1
- import { C as CreateHellobillHandlerOptions } from '../index-D5WlUYVZ.cjs';
1
+ import { C as CreateHellobillHandlerOptions } from '../index-C_gIXrzG.cjs';
2
2
  import '../webhooks-DePW-Bjp.cjs';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { C as CreateHellobillHandlerOptions } from '../index-jK9cEnEY.js';
1
+ import { C as CreateHellobillHandlerOptions } from '../index-DnEk4Y5R.js';
2
2
  import '../webhooks-DePW-Bjp.js';
3
3
 
4
4
  /**
@@ -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 token = await tokenManager.getAccessToken();
138
+ const m2mToken = await tokenManager.getAccessToken();
139
+ const bearerToken = opts.sessionBearer ?? m2mToken;
139
140
  const headers = {
140
- Authorization: `Bearer ${token}`,
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: async () => {
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 });