@hello-bill/node 2.1.2 → 2.1.3-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.
package/dist/index.mjs CHANGED
@@ -131,9 +131,10 @@ function buildQueryString(query) {
131
131
  async function callUpstream(apiBaseUrl, tokenManager, opts, fetchImpl) {
132
132
  const base = apiBaseUrl.replace(/\/$/, "");
133
133
  const url = `${base}${opts.path}${buildQueryString(opts.query)}`;
134
- const token = await tokenManager.getAccessToken();
134
+ const m2mToken = await tokenManager.getAccessToken();
135
+ const bearerToken = opts.sessionBearer ?? m2mToken;
135
136
  const headers = {
136
- Authorization: `Bearer ${token}`,
137
+ Authorization: `Bearer ${bearerToken}`,
137
138
  Accept: "application/json"
138
139
  };
139
140
  if (opts.body !== void 0) headers["Content-Type"] = "application/json";
@@ -143,14 +144,15 @@ async function callUpstream(apiBaseUrl, tokenManager, opts, fetchImpl) {
143
144
  headers
144
145
  };
145
146
  if (opts.body !== void 0) init.body = JSON.stringify(opts.body);
147
+ const onTokenExpired = opts.sessionBearer ? void 0 : async () => {
148
+ await tokenManager.invalidate();
149
+ const fresh = await tokenManager.getAccessToken();
150
+ headers.Authorization = `Bearer ${fresh}`;
151
+ };
146
152
  const res = await retryFetch(url, init, {
147
153
  fetch: fetchImpl,
148
154
  timeoutMs: opts.timeoutMs,
149
- onTokenExpired: async () => {
150
- await tokenManager.invalidate();
151
- const fresh = await tokenManager.getAccessToken();
152
- headers.Authorization = `Bearer ${fresh}`;
153
- }
155
+ onTokenExpired
154
156
  });
155
157
  let body = null;
156
158
  const text = await res.text();
@@ -970,6 +972,27 @@ function createHellobillHandler(opts) {
970
972
  if (!result2) return;
971
973
  passthroughUpstream(res, result2.status, result2.body, result2.requestId, result2.headers);
972
974
  };
975
+ const loaDocument = async (req, res) => {
976
+ const rawLoa = req.query.loa_id ?? req.params?.id;
977
+ const loaId = Array.isArray(rawLoa) ? rawLoa[0] : rawLoa;
978
+ if (!loaId) {
979
+ sendError(res, 400, "validation.missing_required_field", "loa_id query parameter required");
980
+ return;
981
+ }
982
+ const sessionBearer = extractBearer(req);
983
+ if (!sessionBearer) {
984
+ sendError(res, 401, "auth.token_malformed", "Missing Authorization bearer token");
985
+ return;
986
+ }
987
+ const result2 = await safeCallUpstream(res, {
988
+ method: "GET",
989
+ path: `/partner/loa/${encodeURIComponent(loaId)}/document`,
990
+ sessionBearer,
991
+ logger
992
+ });
993
+ if (!result2) return;
994
+ passthroughUpstream(res, result2.status, result2.body, result2.requestId, result2.headers);
995
+ };
973
996
  const webhookHandler = opts.webhook ? createWebhookHandler({ ...opts.webhook, logger: opts.webhook.logger ?? opts.logger }) : void 0;
974
997
  const result = {
975
998
  session,
@@ -981,7 +1004,8 @@ function createHellobillHandler(opts) {
981
1004
  property,
982
1005
  sessions: { list: sessionsList, get: sessionsGet },
983
1006
  savingsSummary,
984
- serviceSlots
1007
+ serviceSlots,
1008
+ loaDocument
985
1009
  };
986
1010
  if (webhookHandler !== void 0) {
987
1011
  result.webhook = webhookHandler;