@hello-bill/node 2.1.1 → 2.1.2-beta.1

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.
@@ -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 token = await tokenManager.getAccessToken();
135
+ const m2mToken = await tokenManager.getAccessToken();
136
+ const bearerToken = opts.sessionBearer ?? m2mToken;
136
137
  const headers = {
137
- Authorization: `Bearer ${token}`,
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: async () => {
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 });