@hello-bill/node 2.1.3 → 2.1.4-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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { T as TokenStorage, L as Logger } from './index-jK9cEnEY.js';
2
- export { C as CreateHellobillHandlerOptions, H as HellobillHandlerSet, a as HellobillRequest, b as HellobillResponse, I as InMemoryTokenStorage, c as InMemoryWebhookDedupeStore, d as TokenManager, e as TokenManagerOptions, U as UnknownWebhookEventError, V as VerifyWebhookOptions, W as WebhookDedupeStore, f as WebhookHandlerContext, g as WebhookHandlerOptions, h as WebhookHandlers, i as WebhookVerificationError, j as createHellobillHandler, k as createWebhookHandler, v as verifyWebhook, l as verifyWebhookSignature } from './index-jK9cEnEY.js';
1
+ import { T as TokenStorage, L as Logger } from './index-DnEk4Y5R.js';
2
+ export { C as CreateHellobillHandlerOptions, H as HellobillHandlerSet, a as HellobillRequest, b as HellobillResponse, I as InMemoryTokenStorage, c as InMemoryWebhookDedupeStore, d as TokenManager, e as TokenManagerOptions, U as UnknownWebhookEventError, V as VerifyWebhookOptions, W as WebhookDedupeStore, f as WebhookHandlerContext, g as WebhookHandlerOptions, h as WebhookHandlers, i as WebhookVerificationError, j as createHellobillHandler, k as createWebhookHandler, v as verifyWebhook, l as verifyWebhookSignature } from './index-DnEk4Y5R.js';
3
3
  import { R as RequestId, S as SessionPayload, a as SessionResponse, b as SessionGetResponse, P as ProductsQuery, c as ProductsResponse, d as PropertyDetailResponse, L as LoaListResponse, C as CreateCustomerInput, e as CustomerCreateResponse, f as CustomerId, g as CustomerStatusResponse, B as BankDetailsRequest, h as BankDetailsResponse } from './webhooks-DePW-Bjp.js';
4
4
  export { A as Address, i as AddressObject, j as AddressesObject, k as ApiVersion, l as AppDeeplinks, m as BankDetailsCollected, n as BankDetailsConsent, o as BankDetailsObject, p as BankDetailsStatus, q as BillType, r as BreakdownCoverProduct, s as BroadbandProduct, t as BuildingStyle, u as BuildingType, v as CacheStatus, w as ClientMode, x as Consent, y as ContextEntry, z as CouncilTaxProduct, D as CreditCheckAddress, E as CreditCheckObject, F as Customer, G as CustomerType, H as DataCompleteness, I as DiscoveryStatus, J as Email, K as EnergyProduct, M as Environment, N as EpcRating, O as FinalRead, Q as FuelType, T as HeatingType, U as HomeInsuranceProduct, V as IdempotencyKey, W as IsoDate, X as IsoDateTime, Y as LoASignature, Z as LoaId, _ as LoaRecord, $ as LocationRole, a0 as MaskedSortCode, a1 as Meters, a2 as MobileProduct, a3 as MoveIn, a4 as MoveObject, a5 as MoveOut, a6 as MoveOutNotificationFailed, a7 as MoveOutNotificationSent, a8 as MoveOutNotifyFlags, a9 as MoveOutReason, aa as MoveOutStatus, ab as NearbyPoi, ac as OccupantObject, ad as OccupantType, ae as OnboardingInfo, af as OverallStatus, ag as Paginated, ah as Person, ai as PhoneNumber, aj as Postcode, ak as Product, al as ProductBase, am as ProductCategory, an as ProductConfidence, ao as ProductId, ap as ProductSetup, aq as PropertyDetailObject, ar as PropertyLocation, as as PropertyObject, at as PropertyType, au as PropertyTypeCode, av as PropertyTypeSubcode, aw as ProvidedFieldPath, ax as SESSION_IDEMPOTENCY_TTL_MS, ay as SavingsSummaryResponse, az as SelectedProduct, aA as SessionAccountCreated, aB as SessionAppDeferred, aC as SessionAppInstalled, aD as SessionDetailsConfirmed, aE as SessionEmbedOpened, aF as SessionLoaSigned, aG as SessionProductsSelected, aH as SetupStatus, aI as SetupStatusChanged, aJ as SignatureImage, aK as StoredBankDetails, aL as SubscriptionChanged, aM as SubscriptionStatus, aN as Title, aO as TvLicenceProduct, aP as Url, aQ as WaterProduct, aR as WebhookEvent, aS as WebhookEventBase, aT as WebhookEventId, aU as WebhookEventType } from './webhooks-DePW-Bjp.js';
5
5
  import { ErrorEnvelope } from './types/index.js';
package/dist/index.js CHANGED
@@ -133,9 +133,10 @@ function buildQueryString(query) {
133
133
  async function callUpstream(apiBaseUrl, tokenManager, opts, fetchImpl) {
134
134
  const base = apiBaseUrl.replace(/\/$/, "");
135
135
  const url = `${base}${opts.path}${buildQueryString(opts.query)}`;
136
- const token = await tokenManager.getAccessToken();
136
+ const m2mToken = await tokenManager.getAccessToken();
137
+ const bearerToken = opts.sessionBearer ?? m2mToken;
137
138
  const headers = {
138
- Authorization: `Bearer ${token}`,
139
+ Authorization: `Bearer ${bearerToken}`,
139
140
  Accept: "application/json"
140
141
  };
141
142
  if (opts.body !== void 0) headers["Content-Type"] = "application/json";
@@ -145,14 +146,15 @@ async function callUpstream(apiBaseUrl, tokenManager, opts, fetchImpl) {
145
146
  headers
146
147
  };
147
148
  if (opts.body !== void 0) init.body = JSON.stringify(opts.body);
149
+ const onTokenExpired = opts.sessionBearer ? void 0 : async () => {
150
+ await tokenManager.invalidate();
151
+ const fresh = await tokenManager.getAccessToken();
152
+ headers.Authorization = `Bearer ${fresh}`;
153
+ };
148
154
  const res = await retryFetch(url, init, {
149
155
  fetch: fetchImpl,
150
156
  timeoutMs: opts.timeoutMs,
151
- onTokenExpired: async () => {
152
- await tokenManager.invalidate();
153
- const fresh = await tokenManager.getAccessToken();
154
- headers.Authorization = `Bearer ${fresh}`;
155
- }
157
+ onTokenExpired
156
158
  });
157
159
  let body = null;
158
160
  const text = await res.text();
@@ -972,6 +974,27 @@ function createHellobillHandler(opts) {
972
974
  if (!result2) return;
973
975
  passthroughUpstream(res, result2.status, result2.body, result2.requestId, result2.headers);
974
976
  };
977
+ const loaDocument = async (req, res) => {
978
+ const rawLoa = req.query.loa_id ?? req.params?.id;
979
+ const loaId = Array.isArray(rawLoa) ? rawLoa[0] : rawLoa;
980
+ if (!loaId) {
981
+ sendError(res, 400, "validation.missing_required_field", "loa_id query parameter required");
982
+ return;
983
+ }
984
+ const sessionBearer = extractBearer(req);
985
+ if (!sessionBearer) {
986
+ sendError(res, 401, "auth.token_malformed", "Missing Authorization bearer token");
987
+ return;
988
+ }
989
+ const result2 = await safeCallUpstream(res, {
990
+ method: "GET",
991
+ path: `/partner/loa/${encodeURIComponent(loaId)}/document`,
992
+ sessionBearer,
993
+ logger
994
+ });
995
+ if (!result2) return;
996
+ passthroughUpstream(res, result2.status, result2.body, result2.requestId, result2.headers);
997
+ };
975
998
  const webhookHandler = opts.webhook ? createWebhookHandler({ ...opts.webhook, logger: opts.webhook.logger ?? opts.logger }) : void 0;
976
999
  const result = {
977
1000
  session,
@@ -983,7 +1006,8 @@ function createHellobillHandler(opts) {
983
1006
  property,
984
1007
  sessions: { list: sessionsList, get: sessionsGet },
985
1008
  savingsSummary,
986
- serviceSlots
1009
+ serviceSlots,
1010
+ loaDocument
987
1011
  };
988
1012
  if (webhookHandler !== void 0) {
989
1013
  result.webhook = webhookHandler;