@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/LICENSE +1 -1
- package/README.md +22 -8
- package/dist/index.cjs +103 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +181 -16
- package/dist/index.d.ts +181 -16
- package/dist/index.js +103 -7
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.d.cts
CHANGED
|
@@ -561,7 +561,7 @@ interface TransportOptions {
|
|
|
561
561
|
* building, body serialisation, dispatch through the {@link HttpClient} seam,
|
|
562
562
|
* envelope decoding, and the mapping from HTTP status to error class. Resources
|
|
563
563
|
* never see a `Request`, a `Response`, or a line of JSON - that separation is
|
|
564
|
-
* what keeps
|
|
564
|
+
* what keeps eighteen resource classes trivial and testable.
|
|
565
565
|
*
|
|
566
566
|
* The 401-retry protocol is built in. On a 401 the transport calls
|
|
567
567
|
* `onUnauthorized` once, which in the production wiring refreshes the token, and
|
|
@@ -609,7 +609,7 @@ declare class Transport {
|
|
|
609
609
|
* Resource classes extend this and call `this.transport.send()` to dispatch every
|
|
610
610
|
* outbound request. A resource never builds a request, touches a header, or
|
|
611
611
|
* decodes JSON - all of that belongs to `Transport` alone. That is what keeps
|
|
612
|
-
*
|
|
612
|
+
* eighteen resource classes small enough to read at a glance and testable
|
|
613
613
|
* without a network.
|
|
614
614
|
*/
|
|
615
615
|
declare abstract class AbstractResource {
|
|
@@ -626,9 +626,10 @@ interface CartWriteOptions {
|
|
|
626
626
|
/** The session the cart belongs to. */
|
|
627
627
|
session: string;
|
|
628
628
|
/**
|
|
629
|
-
* The cart's full contents. Each entry
|
|
630
|
-
*
|
|
631
|
-
* delta - see the API reference in your AsterMD
|
|
629
|
+
* The cart's full contents. Each entry requires `product_id`, `name`, and
|
|
630
|
+
* `qty`, plus an optional `variant_id` when the product has variants. This is
|
|
631
|
+
* the complete list, not a delta - see the API reference in your AsterMD
|
|
632
|
+
* dashboard for the fields.
|
|
632
633
|
*/
|
|
633
634
|
items: Record<string, unknown>[];
|
|
634
635
|
}
|
|
@@ -870,7 +871,13 @@ declare class CheckoutEvents extends AbstractResource {
|
|
|
870
871
|
* Send one call per state the visitor reaches: an upsell offered, then accepted
|
|
871
872
|
* or declined, then the order placed or declined. The payload carries whatever
|
|
872
873
|
* context that state needs, but it can never override `event` - the state
|
|
873
|
-
* recorded is always the one you passed explicitly.
|
|
874
|
+
* recorded is always the one you passed explicitly. For an `OrderPlaced` event,
|
|
875
|
+
* `data` may include an optional `payment` object describing the settled
|
|
876
|
+
* payment method: `type` (`paypal` | `apple_pay` | `gpay` | `credit_card` |
|
|
877
|
+
* `pre_paid`), `pre_auth` (boolean), `pre_auth_qa` and `pre_auth_amount`
|
|
878
|
+
* (optional), and an optional `card` object (`type` - `amex` | `visa` |
|
|
879
|
+
* `mastercard` | `discover` | `diners_club` | `jcb`, optional `bin`, required
|
|
880
|
+
* `exp`).
|
|
874
881
|
*
|
|
875
882
|
* @param options The session, the new state, and any context for it.
|
|
876
883
|
* @returns The updated checkout-event record.
|
|
@@ -882,6 +889,97 @@ declare class CheckoutEvents extends AbstractResource {
|
|
|
882
889
|
update<T = Record<string, unknown>>(options: CheckoutEventUpdateOptions): Promise<Response$1<T>>;
|
|
883
890
|
}
|
|
884
891
|
|
|
892
|
+
/**
|
|
893
|
+
* One cart line for {@link Coupons.validate}: either a subscription plan, or a
|
|
894
|
+
* product with its variant - never both. Never an amount; AsterMD prices the
|
|
895
|
+
* line itself.
|
|
896
|
+
*/
|
|
897
|
+
type CouponCartItem = {
|
|
898
|
+
/** The subscription plan the line is sold on. Priced at the plan's first payment. */
|
|
899
|
+
plan_id: string;
|
|
900
|
+
/** Units of the line, an integer from 1 to 999. */
|
|
901
|
+
quantity: number;
|
|
902
|
+
} | {
|
|
903
|
+
/** The AsterMD product. */
|
|
904
|
+
product_id: string;
|
|
905
|
+
/** The product's variant; the product id again for a product without variants. */
|
|
906
|
+
variant_id: string;
|
|
907
|
+
/** Units of the line, an integer from 1 to 999. */
|
|
908
|
+
quantity: number;
|
|
909
|
+
};
|
|
910
|
+
/** Options for {@link Coupons.validate}. */
|
|
911
|
+
interface CouponValidateOptions {
|
|
912
|
+
/** The code the shopper typed. Not case sensitive. */
|
|
913
|
+
code: string;
|
|
914
|
+
/** The cart, main item first. Between 1 and 6 lines. */
|
|
915
|
+
items: CouponCartItem[];
|
|
916
|
+
/**
|
|
917
|
+
* The AsterMD patient id of the shopper, when already a patient. Sent only
|
|
918
|
+
* when provided. When several of `patientId`, `email` and `opportunityId` are
|
|
919
|
+
* given, the server uses them in that order.
|
|
920
|
+
*/
|
|
921
|
+
patientId?: string;
|
|
922
|
+
/** The shopper's email; used when `patientId` is not sent. Sent only when provided. */
|
|
923
|
+
email?: string;
|
|
924
|
+
/**
|
|
925
|
+
* The shopper's opportunity id; used when neither `patientId` nor `email` is
|
|
926
|
+
* sent. Sent only when provided.
|
|
927
|
+
*/
|
|
928
|
+
opportunityId?: string;
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Coupons - checking a code the shopper typed against their cart.
|
|
932
|
+
*
|
|
933
|
+
* Use this resource just before creating the payment: it tells the storefront
|
|
934
|
+
* whether a coupon code can be used on the current cart, and what it takes off.
|
|
935
|
+
* AsterMD prices the cart itself from its catalogue, so callers send product,
|
|
936
|
+
* variant or plan identifiers and quantities - never amounts.
|
|
937
|
+
*
|
|
938
|
+
* The call applies to a channel whose payment provider is a storefront gateway.
|
|
939
|
+
* Nothing is counted against the coupon by a check; redemption is recorded later,
|
|
940
|
+
* when the order is synced.
|
|
941
|
+
*
|
|
942
|
+
* ```ts
|
|
943
|
+
* const { discount_cents, amount_cents } = (
|
|
944
|
+
* await client.coupons().validate<{ discount_cents: number; amount_cents: number }>({
|
|
945
|
+
* code: 'WELCOME20',
|
|
946
|
+
* items: [{ plan_id: planId, quantity: 1 }],
|
|
947
|
+
* email: 'jane.doe@example.com',
|
|
948
|
+
* })
|
|
949
|
+
* ).data();
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
declare class Coupons extends AbstractResource {
|
|
953
|
+
/**
|
|
954
|
+
* @param transport The shared transport.
|
|
955
|
+
*/
|
|
956
|
+
constructor(transport: Transport);
|
|
957
|
+
/**
|
|
958
|
+
* Checks a coupon code against a cart without redeeming it.
|
|
959
|
+
*
|
|
960
|
+
* Call this when the shopper applies a code at checkout, before the payment is
|
|
961
|
+
* created. The server validates the coupon's status, validity window, patient,
|
|
962
|
+
* products, budget, scope and redemption limits, and prices the cart. The check
|
|
963
|
+
* has no side effects. Inspect `data()` on the response for the coupon terms,
|
|
964
|
+
* the price before and after the discount, and the discounted lines. A shopper
|
|
965
|
+
* who is not a patient yet only fits a coupon open to anyone.
|
|
966
|
+
*
|
|
967
|
+
* @param options The code, the cart, and optionally who the shopper is
|
|
968
|
+
* (`patientId`, `email` or `opportunityId`). Each optional identifier is sent
|
|
969
|
+
* only when provided.
|
|
970
|
+
* @returns The coupon check; `data()` holds `coupon_id`, `name`,
|
|
971
|
+
* `discount_type`, `value`, `tiers`, `default_scope`, `gross_amount_cents`,
|
|
972
|
+
* `discount_cents`, `amount_cents`, `currency` and the discounted `items`.
|
|
973
|
+
* @throws {NotFoundError} If no coupon exists with this code.
|
|
974
|
+
* @throws {ValidationError} If the coupon cannot be used on this cart, or the
|
|
975
|
+
* cart cannot be priced.
|
|
976
|
+
* @throws {AuthenticationError} If the credentials are refused.
|
|
977
|
+
* @throws {ApiError} On any other non-2xx status.
|
|
978
|
+
* @throws {TransportError} If the request never completed.
|
|
979
|
+
*/
|
|
980
|
+
validate<T = Record<string, unknown>>(options: CouponValidateOptions): Promise<Response$1<T>>;
|
|
981
|
+
}
|
|
982
|
+
|
|
885
983
|
/**
|
|
886
984
|
* Doctors' networks - handing a case to the clinicians who will review it.
|
|
887
985
|
*
|
|
@@ -1535,7 +1633,7 @@ interface SubmitHealthInformationOptions {
|
|
|
1535
1633
|
*
|
|
1536
1634
|
* Handling this data does not by itself make your application HIPAA compliant -
|
|
1537
1635
|
* that depends on your own infrastructure, policies, and agreements. Contact
|
|
1538
|
-
*
|
|
1636
|
+
* hello@astermd.com regarding a Business Associate Agreement.
|
|
1539
1637
|
*/
|
|
1540
1638
|
declare class Patients extends AbstractResource {
|
|
1541
1639
|
/**
|
|
@@ -1698,7 +1796,11 @@ interface SessionCreateOptions {
|
|
|
1698
1796
|
/**
|
|
1699
1797
|
* Attribution and context to record against the session - UTM parameters,
|
|
1700
1798
|
* referrer, landing page. Forwarded unmodified; see the API reference in your
|
|
1701
|
-
* AsterMD dashboard for the recognised keys.
|
|
1799
|
+
* AsterMD dashboard for the recognised keys. May include an optional
|
|
1800
|
+
* `verification` object recording identity/contact verification already
|
|
1801
|
+
* performed by the caller - every field inside it is optional too: `email`
|
|
1802
|
+
* (boolean), `address` (boolean), and `id` (`verified` boolean, `method` -
|
|
1803
|
+
* `ssn` | `dob` | `cross_check` | `document_upload`, `value` string).
|
|
1702
1804
|
*/
|
|
1703
1805
|
data?: Record<string, unknown>;
|
|
1704
1806
|
/** The visitor's user agent, forwarded as the `User-Agent` header. */
|
|
@@ -1786,7 +1888,8 @@ declare class Sessions extends AbstractResource {
|
|
|
1786
1888
|
*
|
|
1787
1889
|
* @param session The session identifier to update.
|
|
1788
1890
|
* @param data Fields to record. Forwarded unmodified; see the API reference in
|
|
1789
|
-
* your AsterMD dashboard for the recognised keys.
|
|
1891
|
+
* your AsterMD dashboard for the recognised keys. Accepts the same optional
|
|
1892
|
+
* `verification` object documented on {@link Sessions.create}.
|
|
1790
1893
|
* @returns The updated session.
|
|
1791
1894
|
* @throws {NotFoundError} If the session does not exist.
|
|
1792
1895
|
* @throws {ValidationError} If the payload is rejected.
|
|
@@ -1903,16 +2006,70 @@ declare class Teleforms extends AbstractResource {
|
|
|
1903
2006
|
view<T = Record<string, unknown>>(id: string): Promise<Response$1<T>>;
|
|
1904
2007
|
}
|
|
1905
2008
|
|
|
2009
|
+
/** The card network for {@link TreatmentCardOptions.type}. */
|
|
2010
|
+
type TreatmentCardType = 'amex' | 'visa' | 'mastercard' | 'discover' | 'diners_club' | 'jcb';
|
|
2011
|
+
/** The settled payment method for {@link TreatmentPaymentOptions.type}. */
|
|
2012
|
+
type TreatmentPaymentType = 'paypal' | 'apple_pay' | 'gpay' | 'credit_card' | 'pre_paid';
|
|
2013
|
+
/** The identity check performed for {@link TreatmentIdVerificationOptions.method}. */
|
|
2014
|
+
type TreatmentIdVerificationMethod = 'ssn' | 'dob' | 'cross_check' | 'document_upload';
|
|
2015
|
+
/** Card details nested inside {@link TreatmentPaymentOptions.card}. */
|
|
2016
|
+
interface TreatmentCardOptions {
|
|
2017
|
+
/** The card network. */
|
|
2018
|
+
type: TreatmentCardType;
|
|
2019
|
+
/** The card's last four digits, when available. */
|
|
2020
|
+
last_4?: string;
|
|
2021
|
+
/** The card's expiry, in the format your integration agreed with AsterMD. */
|
|
2022
|
+
exp: string;
|
|
2023
|
+
}
|
|
2024
|
+
/** The settled payment method for {@link Treatments.sync}. */
|
|
2025
|
+
interface TreatmentPaymentOptions {
|
|
2026
|
+
/** How the order was paid for. */
|
|
2027
|
+
type: TreatmentPaymentType;
|
|
2028
|
+
/** Whether the payment was a pre-authorisation rather than a capture. */
|
|
2029
|
+
preAuth: boolean;
|
|
2030
|
+
/** Whether the pre-authorisation was a quality-assurance hold rather than a real charge. */
|
|
2031
|
+
preAuthQa?: boolean;
|
|
2032
|
+
/** The pre-authorised amount, when `preAuth` is true. */
|
|
2033
|
+
preAuthAmount?: number;
|
|
2034
|
+
/** Card details, when the payment method is card-based. */
|
|
2035
|
+
card?: TreatmentCardOptions;
|
|
2036
|
+
}
|
|
2037
|
+
/** The identity check nested inside {@link TreatmentVerificationOptions.id}. */
|
|
2038
|
+
interface TreatmentIdVerificationOptions {
|
|
2039
|
+
/** Whether the check passed. */
|
|
2040
|
+
verified: boolean;
|
|
2041
|
+
/** Which identity check was performed. */
|
|
2042
|
+
method: TreatmentIdVerificationMethod;
|
|
2043
|
+
/** The value that was checked, e.g. the SSN or date of birth submitted. */
|
|
2044
|
+
value: string;
|
|
2045
|
+
}
|
|
2046
|
+
/** Identity/contact verification already performed by the caller, for {@link Treatments.sync}. */
|
|
2047
|
+
interface TreatmentVerificationOptions {
|
|
2048
|
+
/** Whether the patient's email was verified. */
|
|
2049
|
+
email: boolean;
|
|
2050
|
+
/** Whether the patient's address was verified. */
|
|
2051
|
+
address: boolean;
|
|
2052
|
+
/** The identity check performed, if any. */
|
|
2053
|
+
id?: TreatmentIdVerificationOptions;
|
|
2054
|
+
}
|
|
1906
2055
|
/** Options for {@link Treatments.sync}. */
|
|
1907
2056
|
interface TreatmentSyncOptions {
|
|
1908
2057
|
/** The session the orders belong to. */
|
|
1909
2058
|
session: string;
|
|
1910
2059
|
/** Order identifiers from your own commerce system. */
|
|
1911
2060
|
orderIds: string[];
|
|
2061
|
+
/**
|
|
2062
|
+
* The visitor's user agent, forwarded as the required `User-Agent` header.
|
|
2063
|
+
* Since the SDK runs server-to-server, only the consuming application knows
|
|
2064
|
+
* the real value - read it from the incoming request and pass it here.
|
|
2065
|
+
*/
|
|
2066
|
+
userAgent: string;
|
|
1912
2067
|
/** Campaign attribution to record alongside the orders. */
|
|
1913
2068
|
utmSource?: string;
|
|
1914
|
-
/** The
|
|
1915
|
-
|
|
2069
|
+
/** The settled payment method for the order. */
|
|
2070
|
+
payment?: TreatmentPaymentOptions;
|
|
2071
|
+
/** Identity/contact verification already performed by the caller. */
|
|
2072
|
+
verification?: TreatmentVerificationOptions;
|
|
1916
2073
|
}
|
|
1917
2074
|
/**
|
|
1918
2075
|
* Treatments - the order, once money has actually changed hands.
|
|
@@ -1991,10 +2148,15 @@ declare class Treatments extends AbstractResource {
|
|
|
1991
2148
|
* The alternative to {@link Treatments.create} for flows where checkout happens
|
|
1992
2149
|
* outside your storefront: hand over the session and your order identifiers and
|
|
1993
2150
|
* the server creates the treatments and attributes them to that session's
|
|
1994
|
-
* journey. Several orders can be reconciled in one call.
|
|
2151
|
+
* journey. Several orders can be reconciled in one call. `payment`, when
|
|
2152
|
+
* supplied, carries the settled payment method for the order; `verification`,
|
|
2153
|
+
* when supplied, records identity/contact verification already performed by
|
|
2154
|
+
* the caller.
|
|
1995
2155
|
*
|
|
1996
|
-
* @param options The session, your order identifiers,
|
|
2156
|
+
* @param options The session, your order identifiers, the required user agent,
|
|
2157
|
+
* and optional attribution, payment, and verification details.
|
|
1997
2158
|
* @returns The created treatments.
|
|
2159
|
+
* @throws {TypeError} If `userAgent` is missing or empty.
|
|
1998
2160
|
* @throws {ValidationError} If the session or an order identifier is rejected.
|
|
1999
2161
|
* @throws {NotFoundError} If the session does not exist.
|
|
2000
2162
|
* @throws {ApiError} On any other non-2xx status.
|
|
@@ -2164,7 +2326,7 @@ interface AsterMDClientOptions {
|
|
|
2164
2326
|
debugRetentionDays?: number;
|
|
2165
2327
|
}
|
|
2166
2328
|
/**
|
|
2167
|
-
* The SDK's entry point: one client,
|
|
2329
|
+
* The SDK's entry point: one client, eighteen resources.
|
|
2168
2330
|
*
|
|
2169
2331
|
* Construct it once at application start and share it. It holds the credentials,
|
|
2170
2332
|
* caches the bearer token, and owns the single transport every resource dispatches
|
|
@@ -2245,6 +2407,8 @@ declare class AsterMDClient {
|
|
|
2245
2407
|
opportunities(): Opportunities;
|
|
2246
2408
|
/** Treatments - the order, once payment has settled. */
|
|
2247
2409
|
treatments(): Treatments;
|
|
2410
|
+
/** Coupons - checking a code the shopper typed against their cart. */
|
|
2411
|
+
coupons(): Coupons;
|
|
2248
2412
|
/** Doctors' networks - handing a case to the clinicians who review it. */
|
|
2249
2413
|
doctorsNetworks(): DoctorsNetworks;
|
|
2250
2414
|
/** Channels - the storefront's own server-side configuration. */
|
|
@@ -2772,7 +2936,7 @@ declare class ChannelDetail {
|
|
|
2772
2936
|
*
|
|
2773
2937
|
* The AES key is **never** stored in this SDK. Supply it at every call site from
|
|
2774
2938
|
* your own configuration - an environment variable, a secrets manager - and keep
|
|
2775
|
-
* it in step with whichever service mints the tokens. Contact
|
|
2939
|
+
* it in step with whichever service mints the tokens. Contact hello@astermd.com to
|
|
2776
2940
|
* obtain or rotate the key for your organisation.
|
|
2777
2941
|
*
|
|
2778
2942
|
* **On integrity:** AES-CBC provides confidentiality but not authentication, so a
|
|
@@ -2822,4 +2986,5 @@ declare class QueryParamCipher {
|
|
|
2822
2986
|
static encrypt(params: Record<string, string>, keyHex: string): string;
|
|
2823
2987
|
}
|
|
2824
2988
|
|
|
2825
|
-
export { AbstractResource, ApiError, AsterMDClient,
|
|
2989
|
+
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, Response$1 as Response, Sessions, Shippings, Teleforms, Token, TransportError, Treatments, ValidationError, Verification };
|
|
2990
|
+
export type { AsterMDClientOptions, CartWriteOptions, ChannelDetailView, ChannelPaymentProcessor, ChannelProduct, ChannelProductMapping, ChannelProductSingle, ChannelProductVariant, CheckoutEventUpdateOptions, ConfigOptions, CouponCartItem, CouponValidateOptions, DailyFileLogSinkOptions, DebugSink, FileUploadFromContentsOptions, FileUploadFromPathOptions, FinishMultipartOptions, HttpClient, InitiateMultipartOptions, IntakeViewOptions, IntakeWriteOptions, MultipartPart, ResponseOptions, SessionCreateOptions, SessionViewOptions, SubmitHealthInformationOptions, TokenStore, TreatmentCardOptions, TreatmentCardType, TreatmentIdVerificationMethod, TreatmentIdVerificationOptions, TreatmentPaymentOptions, TreatmentPaymentType, TreatmentSyncOptions, TreatmentVerificationOptions, UploadFileOptions, UploadLargeFileOptions, UploadPartOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -561,7 +561,7 @@ interface TransportOptions {
|
|
|
561
561
|
* building, body serialisation, dispatch through the {@link HttpClient} seam,
|
|
562
562
|
* envelope decoding, and the mapping from HTTP status to error class. Resources
|
|
563
563
|
* never see a `Request`, a `Response`, or a line of JSON - that separation is
|
|
564
|
-
* what keeps
|
|
564
|
+
* what keeps eighteen resource classes trivial and testable.
|
|
565
565
|
*
|
|
566
566
|
* The 401-retry protocol is built in. On a 401 the transport calls
|
|
567
567
|
* `onUnauthorized` once, which in the production wiring refreshes the token, and
|
|
@@ -609,7 +609,7 @@ declare class Transport {
|
|
|
609
609
|
* Resource classes extend this and call `this.transport.send()` to dispatch every
|
|
610
610
|
* outbound request. A resource never builds a request, touches a header, or
|
|
611
611
|
* decodes JSON - all of that belongs to `Transport` alone. That is what keeps
|
|
612
|
-
*
|
|
612
|
+
* eighteen resource classes small enough to read at a glance and testable
|
|
613
613
|
* without a network.
|
|
614
614
|
*/
|
|
615
615
|
declare abstract class AbstractResource {
|
|
@@ -626,9 +626,10 @@ interface CartWriteOptions {
|
|
|
626
626
|
/** The session the cart belongs to. */
|
|
627
627
|
session: string;
|
|
628
628
|
/**
|
|
629
|
-
* The cart's full contents. Each entry
|
|
630
|
-
*
|
|
631
|
-
* delta - see the API reference in your AsterMD
|
|
629
|
+
* The cart's full contents. Each entry requires `product_id`, `name`, and
|
|
630
|
+
* `qty`, plus an optional `variant_id` when the product has variants. This is
|
|
631
|
+
* the complete list, not a delta - see the API reference in your AsterMD
|
|
632
|
+
* dashboard for the fields.
|
|
632
633
|
*/
|
|
633
634
|
items: Record<string, unknown>[];
|
|
634
635
|
}
|
|
@@ -870,7 +871,13 @@ declare class CheckoutEvents extends AbstractResource {
|
|
|
870
871
|
* Send one call per state the visitor reaches: an upsell offered, then accepted
|
|
871
872
|
* or declined, then the order placed or declined. The payload carries whatever
|
|
872
873
|
* context that state needs, but it can never override `event` - the state
|
|
873
|
-
* recorded is always the one you passed explicitly.
|
|
874
|
+
* recorded is always the one you passed explicitly. For an `OrderPlaced` event,
|
|
875
|
+
* `data` may include an optional `payment` object describing the settled
|
|
876
|
+
* payment method: `type` (`paypal` | `apple_pay` | `gpay` | `credit_card` |
|
|
877
|
+
* `pre_paid`), `pre_auth` (boolean), `pre_auth_qa` and `pre_auth_amount`
|
|
878
|
+
* (optional), and an optional `card` object (`type` - `amex` | `visa` |
|
|
879
|
+
* `mastercard` | `discover` | `diners_club` | `jcb`, optional `bin`, required
|
|
880
|
+
* `exp`).
|
|
874
881
|
*
|
|
875
882
|
* @param options The session, the new state, and any context for it.
|
|
876
883
|
* @returns The updated checkout-event record.
|
|
@@ -882,6 +889,97 @@ declare class CheckoutEvents extends AbstractResource {
|
|
|
882
889
|
update<T = Record<string, unknown>>(options: CheckoutEventUpdateOptions): Promise<Response$1<T>>;
|
|
883
890
|
}
|
|
884
891
|
|
|
892
|
+
/**
|
|
893
|
+
* One cart line for {@link Coupons.validate}: either a subscription plan, or a
|
|
894
|
+
* product with its variant - never both. Never an amount; AsterMD prices the
|
|
895
|
+
* line itself.
|
|
896
|
+
*/
|
|
897
|
+
type CouponCartItem = {
|
|
898
|
+
/** The subscription plan the line is sold on. Priced at the plan's first payment. */
|
|
899
|
+
plan_id: string;
|
|
900
|
+
/** Units of the line, an integer from 1 to 999. */
|
|
901
|
+
quantity: number;
|
|
902
|
+
} | {
|
|
903
|
+
/** The AsterMD product. */
|
|
904
|
+
product_id: string;
|
|
905
|
+
/** The product's variant; the product id again for a product without variants. */
|
|
906
|
+
variant_id: string;
|
|
907
|
+
/** Units of the line, an integer from 1 to 999. */
|
|
908
|
+
quantity: number;
|
|
909
|
+
};
|
|
910
|
+
/** Options for {@link Coupons.validate}. */
|
|
911
|
+
interface CouponValidateOptions {
|
|
912
|
+
/** The code the shopper typed. Not case sensitive. */
|
|
913
|
+
code: string;
|
|
914
|
+
/** The cart, main item first. Between 1 and 6 lines. */
|
|
915
|
+
items: CouponCartItem[];
|
|
916
|
+
/**
|
|
917
|
+
* The AsterMD patient id of the shopper, when already a patient. Sent only
|
|
918
|
+
* when provided. When several of `patientId`, `email` and `opportunityId` are
|
|
919
|
+
* given, the server uses them in that order.
|
|
920
|
+
*/
|
|
921
|
+
patientId?: string;
|
|
922
|
+
/** The shopper's email; used when `patientId` is not sent. Sent only when provided. */
|
|
923
|
+
email?: string;
|
|
924
|
+
/**
|
|
925
|
+
* The shopper's opportunity id; used when neither `patientId` nor `email` is
|
|
926
|
+
* sent. Sent only when provided.
|
|
927
|
+
*/
|
|
928
|
+
opportunityId?: string;
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Coupons - checking a code the shopper typed against their cart.
|
|
932
|
+
*
|
|
933
|
+
* Use this resource just before creating the payment: it tells the storefront
|
|
934
|
+
* whether a coupon code can be used on the current cart, and what it takes off.
|
|
935
|
+
* AsterMD prices the cart itself from its catalogue, so callers send product,
|
|
936
|
+
* variant or plan identifiers and quantities - never amounts.
|
|
937
|
+
*
|
|
938
|
+
* The call applies to a channel whose payment provider is a storefront gateway.
|
|
939
|
+
* Nothing is counted against the coupon by a check; redemption is recorded later,
|
|
940
|
+
* when the order is synced.
|
|
941
|
+
*
|
|
942
|
+
* ```ts
|
|
943
|
+
* const { discount_cents, amount_cents } = (
|
|
944
|
+
* await client.coupons().validate<{ discount_cents: number; amount_cents: number }>({
|
|
945
|
+
* code: 'WELCOME20',
|
|
946
|
+
* items: [{ plan_id: planId, quantity: 1 }],
|
|
947
|
+
* email: 'jane.doe@example.com',
|
|
948
|
+
* })
|
|
949
|
+
* ).data();
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
declare class Coupons extends AbstractResource {
|
|
953
|
+
/**
|
|
954
|
+
* @param transport The shared transport.
|
|
955
|
+
*/
|
|
956
|
+
constructor(transport: Transport);
|
|
957
|
+
/**
|
|
958
|
+
* Checks a coupon code against a cart without redeeming it.
|
|
959
|
+
*
|
|
960
|
+
* Call this when the shopper applies a code at checkout, before the payment is
|
|
961
|
+
* created. The server validates the coupon's status, validity window, patient,
|
|
962
|
+
* products, budget, scope and redemption limits, and prices the cart. The check
|
|
963
|
+
* has no side effects. Inspect `data()` on the response for the coupon terms,
|
|
964
|
+
* the price before and after the discount, and the discounted lines. A shopper
|
|
965
|
+
* who is not a patient yet only fits a coupon open to anyone.
|
|
966
|
+
*
|
|
967
|
+
* @param options The code, the cart, and optionally who the shopper is
|
|
968
|
+
* (`patientId`, `email` or `opportunityId`). Each optional identifier is sent
|
|
969
|
+
* only when provided.
|
|
970
|
+
* @returns The coupon check; `data()` holds `coupon_id`, `name`,
|
|
971
|
+
* `discount_type`, `value`, `tiers`, `default_scope`, `gross_amount_cents`,
|
|
972
|
+
* `discount_cents`, `amount_cents`, `currency` and the discounted `items`.
|
|
973
|
+
* @throws {NotFoundError} If no coupon exists with this code.
|
|
974
|
+
* @throws {ValidationError} If the coupon cannot be used on this cart, or the
|
|
975
|
+
* cart cannot be priced.
|
|
976
|
+
* @throws {AuthenticationError} If the credentials are refused.
|
|
977
|
+
* @throws {ApiError} On any other non-2xx status.
|
|
978
|
+
* @throws {TransportError} If the request never completed.
|
|
979
|
+
*/
|
|
980
|
+
validate<T = Record<string, unknown>>(options: CouponValidateOptions): Promise<Response$1<T>>;
|
|
981
|
+
}
|
|
982
|
+
|
|
885
983
|
/**
|
|
886
984
|
* Doctors' networks - handing a case to the clinicians who will review it.
|
|
887
985
|
*
|
|
@@ -1535,7 +1633,7 @@ interface SubmitHealthInformationOptions {
|
|
|
1535
1633
|
*
|
|
1536
1634
|
* Handling this data does not by itself make your application HIPAA compliant -
|
|
1537
1635
|
* that depends on your own infrastructure, policies, and agreements. Contact
|
|
1538
|
-
*
|
|
1636
|
+
* hello@astermd.com regarding a Business Associate Agreement.
|
|
1539
1637
|
*/
|
|
1540
1638
|
declare class Patients extends AbstractResource {
|
|
1541
1639
|
/**
|
|
@@ -1698,7 +1796,11 @@ interface SessionCreateOptions {
|
|
|
1698
1796
|
/**
|
|
1699
1797
|
* Attribution and context to record against the session - UTM parameters,
|
|
1700
1798
|
* referrer, landing page. Forwarded unmodified; see the API reference in your
|
|
1701
|
-
* AsterMD dashboard for the recognised keys.
|
|
1799
|
+
* AsterMD dashboard for the recognised keys. May include an optional
|
|
1800
|
+
* `verification` object recording identity/contact verification already
|
|
1801
|
+
* performed by the caller - every field inside it is optional too: `email`
|
|
1802
|
+
* (boolean), `address` (boolean), and `id` (`verified` boolean, `method` -
|
|
1803
|
+
* `ssn` | `dob` | `cross_check` | `document_upload`, `value` string).
|
|
1702
1804
|
*/
|
|
1703
1805
|
data?: Record<string, unknown>;
|
|
1704
1806
|
/** The visitor's user agent, forwarded as the `User-Agent` header. */
|
|
@@ -1786,7 +1888,8 @@ declare class Sessions extends AbstractResource {
|
|
|
1786
1888
|
*
|
|
1787
1889
|
* @param session The session identifier to update.
|
|
1788
1890
|
* @param data Fields to record. Forwarded unmodified; see the API reference in
|
|
1789
|
-
* your AsterMD dashboard for the recognised keys.
|
|
1891
|
+
* your AsterMD dashboard for the recognised keys. Accepts the same optional
|
|
1892
|
+
* `verification` object documented on {@link Sessions.create}.
|
|
1790
1893
|
* @returns The updated session.
|
|
1791
1894
|
* @throws {NotFoundError} If the session does not exist.
|
|
1792
1895
|
* @throws {ValidationError} If the payload is rejected.
|
|
@@ -1903,16 +2006,70 @@ declare class Teleforms extends AbstractResource {
|
|
|
1903
2006
|
view<T = Record<string, unknown>>(id: string): Promise<Response$1<T>>;
|
|
1904
2007
|
}
|
|
1905
2008
|
|
|
2009
|
+
/** The card network for {@link TreatmentCardOptions.type}. */
|
|
2010
|
+
type TreatmentCardType = 'amex' | 'visa' | 'mastercard' | 'discover' | 'diners_club' | 'jcb';
|
|
2011
|
+
/** The settled payment method for {@link TreatmentPaymentOptions.type}. */
|
|
2012
|
+
type TreatmentPaymentType = 'paypal' | 'apple_pay' | 'gpay' | 'credit_card' | 'pre_paid';
|
|
2013
|
+
/** The identity check performed for {@link TreatmentIdVerificationOptions.method}. */
|
|
2014
|
+
type TreatmentIdVerificationMethod = 'ssn' | 'dob' | 'cross_check' | 'document_upload';
|
|
2015
|
+
/** Card details nested inside {@link TreatmentPaymentOptions.card}. */
|
|
2016
|
+
interface TreatmentCardOptions {
|
|
2017
|
+
/** The card network. */
|
|
2018
|
+
type: TreatmentCardType;
|
|
2019
|
+
/** The card's last four digits, when available. */
|
|
2020
|
+
last_4?: string;
|
|
2021
|
+
/** The card's expiry, in the format your integration agreed with AsterMD. */
|
|
2022
|
+
exp: string;
|
|
2023
|
+
}
|
|
2024
|
+
/** The settled payment method for {@link Treatments.sync}. */
|
|
2025
|
+
interface TreatmentPaymentOptions {
|
|
2026
|
+
/** How the order was paid for. */
|
|
2027
|
+
type: TreatmentPaymentType;
|
|
2028
|
+
/** Whether the payment was a pre-authorisation rather than a capture. */
|
|
2029
|
+
preAuth: boolean;
|
|
2030
|
+
/** Whether the pre-authorisation was a quality-assurance hold rather than a real charge. */
|
|
2031
|
+
preAuthQa?: boolean;
|
|
2032
|
+
/** The pre-authorised amount, when `preAuth` is true. */
|
|
2033
|
+
preAuthAmount?: number;
|
|
2034
|
+
/** Card details, when the payment method is card-based. */
|
|
2035
|
+
card?: TreatmentCardOptions;
|
|
2036
|
+
}
|
|
2037
|
+
/** The identity check nested inside {@link TreatmentVerificationOptions.id}. */
|
|
2038
|
+
interface TreatmentIdVerificationOptions {
|
|
2039
|
+
/** Whether the check passed. */
|
|
2040
|
+
verified: boolean;
|
|
2041
|
+
/** Which identity check was performed. */
|
|
2042
|
+
method: TreatmentIdVerificationMethod;
|
|
2043
|
+
/** The value that was checked, e.g. the SSN or date of birth submitted. */
|
|
2044
|
+
value: string;
|
|
2045
|
+
}
|
|
2046
|
+
/** Identity/contact verification already performed by the caller, for {@link Treatments.sync}. */
|
|
2047
|
+
interface TreatmentVerificationOptions {
|
|
2048
|
+
/** Whether the patient's email was verified. */
|
|
2049
|
+
email: boolean;
|
|
2050
|
+
/** Whether the patient's address was verified. */
|
|
2051
|
+
address: boolean;
|
|
2052
|
+
/** The identity check performed, if any. */
|
|
2053
|
+
id?: TreatmentIdVerificationOptions;
|
|
2054
|
+
}
|
|
1906
2055
|
/** Options for {@link Treatments.sync}. */
|
|
1907
2056
|
interface TreatmentSyncOptions {
|
|
1908
2057
|
/** The session the orders belong to. */
|
|
1909
2058
|
session: string;
|
|
1910
2059
|
/** Order identifiers from your own commerce system. */
|
|
1911
2060
|
orderIds: string[];
|
|
2061
|
+
/**
|
|
2062
|
+
* The visitor's user agent, forwarded as the required `User-Agent` header.
|
|
2063
|
+
* Since the SDK runs server-to-server, only the consuming application knows
|
|
2064
|
+
* the real value - read it from the incoming request and pass it here.
|
|
2065
|
+
*/
|
|
2066
|
+
userAgent: string;
|
|
1912
2067
|
/** Campaign attribution to record alongside the orders. */
|
|
1913
2068
|
utmSource?: string;
|
|
1914
|
-
/** The
|
|
1915
|
-
|
|
2069
|
+
/** The settled payment method for the order. */
|
|
2070
|
+
payment?: TreatmentPaymentOptions;
|
|
2071
|
+
/** Identity/contact verification already performed by the caller. */
|
|
2072
|
+
verification?: TreatmentVerificationOptions;
|
|
1916
2073
|
}
|
|
1917
2074
|
/**
|
|
1918
2075
|
* Treatments - the order, once money has actually changed hands.
|
|
@@ -1991,10 +2148,15 @@ declare class Treatments extends AbstractResource {
|
|
|
1991
2148
|
* The alternative to {@link Treatments.create} for flows where checkout happens
|
|
1992
2149
|
* outside your storefront: hand over the session and your order identifiers and
|
|
1993
2150
|
* the server creates the treatments and attributes them to that session's
|
|
1994
|
-
* journey. Several orders can be reconciled in one call.
|
|
2151
|
+
* journey. Several orders can be reconciled in one call. `payment`, when
|
|
2152
|
+
* supplied, carries the settled payment method for the order; `verification`,
|
|
2153
|
+
* when supplied, records identity/contact verification already performed by
|
|
2154
|
+
* the caller.
|
|
1995
2155
|
*
|
|
1996
|
-
* @param options The session, your order identifiers,
|
|
2156
|
+
* @param options The session, your order identifiers, the required user agent,
|
|
2157
|
+
* and optional attribution, payment, and verification details.
|
|
1997
2158
|
* @returns The created treatments.
|
|
2159
|
+
* @throws {TypeError} If `userAgent` is missing or empty.
|
|
1998
2160
|
* @throws {ValidationError} If the session or an order identifier is rejected.
|
|
1999
2161
|
* @throws {NotFoundError} If the session does not exist.
|
|
2000
2162
|
* @throws {ApiError} On any other non-2xx status.
|
|
@@ -2164,7 +2326,7 @@ interface AsterMDClientOptions {
|
|
|
2164
2326
|
debugRetentionDays?: number;
|
|
2165
2327
|
}
|
|
2166
2328
|
/**
|
|
2167
|
-
* The SDK's entry point: one client,
|
|
2329
|
+
* The SDK's entry point: one client, eighteen resources.
|
|
2168
2330
|
*
|
|
2169
2331
|
* Construct it once at application start and share it. It holds the credentials,
|
|
2170
2332
|
* caches the bearer token, and owns the single transport every resource dispatches
|
|
@@ -2245,6 +2407,8 @@ declare class AsterMDClient {
|
|
|
2245
2407
|
opportunities(): Opportunities;
|
|
2246
2408
|
/** Treatments - the order, once payment has settled. */
|
|
2247
2409
|
treatments(): Treatments;
|
|
2410
|
+
/** Coupons - checking a code the shopper typed against their cart. */
|
|
2411
|
+
coupons(): Coupons;
|
|
2248
2412
|
/** Doctors' networks - handing a case to the clinicians who review it. */
|
|
2249
2413
|
doctorsNetworks(): DoctorsNetworks;
|
|
2250
2414
|
/** Channels - the storefront's own server-side configuration. */
|
|
@@ -2772,7 +2936,7 @@ declare class ChannelDetail {
|
|
|
2772
2936
|
*
|
|
2773
2937
|
* The AES key is **never** stored in this SDK. Supply it at every call site from
|
|
2774
2938
|
* your own configuration - an environment variable, a secrets manager - and keep
|
|
2775
|
-
* it in step with whichever service mints the tokens. Contact
|
|
2939
|
+
* it in step with whichever service mints the tokens. Contact hello@astermd.com to
|
|
2776
2940
|
* obtain or rotate the key for your organisation.
|
|
2777
2941
|
*
|
|
2778
2942
|
* **On integrity:** AES-CBC provides confidentiality but not authentication, so a
|
|
@@ -2822,4 +2986,5 @@ declare class QueryParamCipher {
|
|
|
2822
2986
|
static encrypt(params: Record<string, string>, keyHex: string): string;
|
|
2823
2987
|
}
|
|
2824
2988
|
|
|
2825
|
-
export { AbstractResource, ApiError, AsterMDClient,
|
|
2989
|
+
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, Response$1 as Response, Sessions, Shippings, Teleforms, Token, TransportError, Treatments, ValidationError, Verification };
|
|
2990
|
+
export type { AsterMDClientOptions, CartWriteOptions, ChannelDetailView, ChannelPaymentProcessor, ChannelProduct, ChannelProductMapping, ChannelProductSingle, ChannelProductVariant, CheckoutEventUpdateOptions, ConfigOptions, CouponCartItem, CouponValidateOptions, DailyFileLogSinkOptions, DebugSink, FileUploadFromContentsOptions, FileUploadFromPathOptions, FinishMultipartOptions, HttpClient, InitiateMultipartOptions, IntakeViewOptions, IntakeWriteOptions, MultipartPart, ResponseOptions, SessionCreateOptions, SessionViewOptions, SubmitHealthInformationOptions, TokenStore, TreatmentCardOptions, TreatmentCardType, TreatmentIdVerificationMethod, TreatmentIdVerificationOptions, TreatmentPaymentOptions, TreatmentPaymentType, TreatmentSyncOptions, TreatmentVerificationOptions, UploadFileOptions, UploadLargeFileOptions, UploadPartOptions };
|