@astermd-hq/sdk 0.0.2 → 0.0.5

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.js CHANGED
@@ -1339,7 +1339,13 @@ var CheckoutEvents = class extends AbstractResource {
1339
1339
  * Send one call per state the visitor reaches: an upsell offered, then accepted
1340
1340
  * or declined, then the order placed or declined. The payload carries whatever
1341
1341
  * context that state needs, but it can never override `event` - the state
1342
- * recorded is always the one you passed explicitly.
1342
+ * recorded is always the one you passed explicitly. For an `OrderPlaced` event,
1343
+ * `data` may include an optional `payment` object describing the settled
1344
+ * payment method: `type` (`paypal` | `apple_pay` | `gpay` | `credit_card` |
1345
+ * `pre_paid`), `pre_auth` (boolean), `pre_auth_qa` and `pre_auth_amount`
1346
+ * (optional), and an optional `card` object (`type` - `amex` | `visa` |
1347
+ * `mastercard` | `discover` | `diners_club` | `jcb`, optional `bin`, required
1348
+ * `exp`).
1343
1349
  *
1344
1350
  * @param options The session, the new state, and any context for it.
1345
1351
  * @returns The updated checkout-event record.
@@ -1359,6 +1365,60 @@ var CheckoutEvents = class extends AbstractResource {
1359
1365
  }
1360
1366
  };
1361
1367
 
1368
+ // src/resource/coupons.ts
1369
+ var Coupons = class extends AbstractResource {
1370
+ /**
1371
+ * @param transport The shared transport.
1372
+ */
1373
+ constructor(transport) {
1374
+ super(transport);
1375
+ }
1376
+ /**
1377
+ * Checks a coupon code against a cart without redeeming it.
1378
+ *
1379
+ * Call this when the shopper applies a code at checkout, before the payment is
1380
+ * created. The server validates the coupon's status, validity window, patient,
1381
+ * products, budget, scope and redemption limits, and prices the cart. The check
1382
+ * has no side effects. Inspect `data()` on the response for the coupon terms,
1383
+ * the price before and after the discount, and the discounted lines. A shopper
1384
+ * who is not a patient yet only fits a coupon open to anyone.
1385
+ *
1386
+ * @param options The code, the cart, and optionally who the shopper is
1387
+ * (`patientId`, `email` or `opportunityId`). Each optional identifier is sent
1388
+ * only when provided.
1389
+ * @returns The coupon check; `data()` holds `coupon_id`, `name`,
1390
+ * `discount_type`, `value`, `tiers`, `default_scope`, `gross_amount_cents`,
1391
+ * `discount_cents`, `amount_cents`, `currency` and the discounted `items`.
1392
+ * @throws {NotFoundError} If no coupon exists with this code.
1393
+ * @throws {ValidationError} If the coupon cannot be used on this cart, or the
1394
+ * cart cannot be priced.
1395
+ * @throws {AuthenticationError} If the credentials are refused.
1396
+ * @throws {ApiError} On any other non-2xx status.
1397
+ * @throws {TransportError} If the request never completed.
1398
+ */
1399
+ async validate(options) {
1400
+ const body = {
1401
+ code: options.code,
1402
+ items: options.items
1403
+ };
1404
+ if (options.patientId !== void 0) {
1405
+ body.patient_id = options.patientId;
1406
+ }
1407
+ if (options.email !== void 0) {
1408
+ body.email = options.email;
1409
+ }
1410
+ if (options.opportunityId !== void 0) {
1411
+ body.opportunity_id = options.opportunityId;
1412
+ }
1413
+ return await this.transport.send({
1414
+ service: "sales",
1415
+ method: "POST",
1416
+ path: "/coupons/validate",
1417
+ body
1418
+ });
1419
+ }
1420
+ };
1421
+
1362
1422
  // src/resource/doctors-networks.ts
1363
1423
  var DoctorsNetworks = class extends AbstractResource {
1364
1424
  /**
@@ -2413,7 +2473,8 @@ var Sessions = class extends AbstractResource {
2413
2473
  *
2414
2474
  * @param session The session identifier to update.
2415
2475
  * @param data Fields to record. Forwarded unmodified; see the API reference in
2416
- * your AsterMD dashboard for the recognised keys.
2476
+ * your AsterMD dashboard for the recognised keys. Accepts the same optional
2477
+ * `verification` object documented on {@link Sessions.create}.
2417
2478
  * @returns The updated session.
2418
2479
  * @throws {NotFoundError} If the session does not exist.
2419
2480
  * @throws {ValidationError} If the payload is rejected.
@@ -2628,16 +2689,24 @@ var Treatments = class extends AbstractResource {
2628
2689
  * The alternative to {@link Treatments.create} for flows where checkout happens
2629
2690
  * outside your storefront: hand over the session and your order identifiers and
2630
2691
  * the server creates the treatments and attributes them to that session's
2631
- * journey. Several orders can be reconciled in one call.
2692
+ * journey. Several orders can be reconciled in one call. `payment`, when
2693
+ * supplied, carries the settled payment method for the order; `verification`,
2694
+ * when supplied, records identity/contact verification already performed by
2695
+ * the caller.
2632
2696
  *
2633
- * @param options The session, your order identifiers, and optional attribution.
2697
+ * @param options The session, your order identifiers, the required user agent,
2698
+ * and optional attribution, payment, and verification details.
2634
2699
  * @returns The created treatments.
2700
+ * @throws {TypeError} If `userAgent` is missing or empty.
2635
2701
  * @throws {ValidationError} If the session or an order identifier is rejected.
2636
2702
  * @throws {NotFoundError} If the session does not exist.
2637
2703
  * @throws {ApiError} On any other non-2xx status.
2638
2704
  * @throws {TransportError} If the request never completed.
2639
2705
  */
2640
2706
  async sync(options) {
2707
+ if (options.userAgent === void 0 || options.userAgent === "") {
2708
+ throw new TypeError("Treatments.sync requires a non-empty userAgent.");
2709
+ }
2641
2710
  const body = {
2642
2711
  session_id: options.session,
2643
2712
  order_ids: options.orderIds
@@ -2645,13 +2714,35 @@ var Treatments = class extends AbstractResource {
2645
2714
  if (options.utmSource !== void 0) {
2646
2715
  body.utm_source = options.utmSource;
2647
2716
  }
2648
- const headers = options.userAgent !== void 0 && options.userAgent !== "" ? { "User-Agent": options.userAgent } : {};
2717
+ if (options.payment !== void 0) {
2718
+ const payment = {
2719
+ type: options.payment.type,
2720
+ pre_auth: options.payment.preAuth
2721
+ };
2722
+ if (options.payment.preAuthQa !== void 0) {
2723
+ payment.pre_auth_qa = options.payment.preAuthQa;
2724
+ }
2725
+ if (options.payment.preAuthAmount !== void 0) {
2726
+ payment.pre_auth_amount = options.payment.preAuthAmount;
2727
+ }
2728
+ if (options.payment.card !== void 0) {
2729
+ payment.card = options.payment.card;
2730
+ }
2731
+ body.payment = payment;
2732
+ }
2733
+ if (options.verification !== void 0) {
2734
+ body.verification = {
2735
+ email: options.verification.email,
2736
+ address: options.verification.address,
2737
+ ...options.verification.id !== void 0 ? { id: options.verification.id } : {}
2738
+ };
2739
+ }
2649
2740
  return await this.transport.send({
2650
2741
  service: "sales",
2651
2742
  method: "POST",
2652
2743
  path: "/treatments/sync",
2653
2744
  body,
2654
- headers
2745
+ headers: { "User-Agent": options.userAgent }
2655
2746
  });
2656
2747
  }
2657
2748
  };
@@ -2771,6 +2862,7 @@ var AsterMDClient = class {
2771
2862
  #patients;
2772
2863
  #opportunities;
2773
2864
  #treatments;
2865
+ #coupons;
2774
2866
  #doctorsNetworks;
2775
2867
  #channels;
2776
2868
  #products;
@@ -2884,6 +2976,10 @@ var AsterMDClient = class {
2884
2976
  treatments() {
2885
2977
  return this.#treatments ??= new Treatments(this.#transport);
2886
2978
  }
2979
+ /** Coupons - checking a code the shopper typed against their cart. */
2980
+ coupons() {
2981
+ return this.#coupons ??= new Coupons(this.#transport);
2982
+ }
2887
2983
  /** Doctors' networks - handing a case to the clinicians who review it. */
2888
2984
  doctorsNetworks() {
2889
2985
  return this.#doctorsNetworks ??= new DoctorsNetworks(this.#transport);
@@ -3293,6 +3389,6 @@ function phpString(value) {
3293
3389
  return String(value);
3294
3390
  }
3295
3391
 
3296
- export { AbstractResource, ApiError, AsterMDClient, AsterMDError, AuthenticationError, Carts, Categories, ChannelDetail, Channels, CheckoutEvent, CheckoutEvents, Config, DailyFileLogSink, DoctorsNetworks, Event, FetchHttpClient, FileTokenStore, FileUpload, Geo, IdentityCheck, InMemoryTokenStore, IntakeSubmissions, LabTests, Medications, NotFoundError, Opportunities, Patients, Products, QueryParamCipher, RateLimitError, Response2 as Response, Sessions, Shippings, Teleforms, Token, TransportError, Treatments, ValidationError, Verification };
3392
+ export { AbstractResource, ApiError, AsterMDClient, AsterMDError, AuthenticationError, Carts, Categories, ChannelDetail, Channels, CheckoutEvent, CheckoutEvents, Config, Coupons, DailyFileLogSink, DoctorsNetworks, Event, FetchHttpClient, FileTokenStore, FileUpload, Geo, IdentityCheck, InMemoryTokenStore, IntakeSubmissions, LabTests, Medications, NotFoundError, Opportunities, Patients, Products, QueryParamCipher, RateLimitError, Response2 as Response, Sessions, Shippings, Teleforms, Token, TransportError, Treatments, ValidationError, Verification };
3297
3393
  //# sourceMappingURL=index.js.map
3298
3394
  //# sourceMappingURL=index.js.map