@photonhealth/client 2.0.0-rc.1 → 2.0.0-rc.2

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.
Files changed (152) hide show
  1. package/README.md +150 -5
  2. package/dist/analytics/lifecycleEvents.d.ts +29 -0
  3. package/dist/analytics/lifecycleEvents.d.ts.map +1 -0
  4. package/dist/analytics/lifecycleEvents.js +72 -0
  5. package/dist/analytics/lifecycleEvents.js.map +1 -0
  6. package/dist/api/client.d.ts +6 -1
  7. package/dist/api/client.d.ts.map +1 -1
  8. package/dist/api/client.js +47 -33
  9. package/dist/api/client.js.map +1 -1
  10. package/dist/api/index.d.ts +2 -0
  11. package/dist/api/index.d.ts.map +1 -1
  12. package/dist/api/index.js +2 -0
  13. package/dist/api/index.js.map +1 -1
  14. package/dist/api/me.d.ts +37 -0
  15. package/dist/api/me.d.ts.map +1 -0
  16. package/dist/api/me.js +6 -0
  17. package/dist/api/me.js.map +1 -0
  18. package/dist/api/orders.d.ts +1047 -0
  19. package/dist/api/orders.d.ts.map +1 -0
  20. package/dist/api/orders.js +7 -0
  21. package/dist/api/orders.js.map +1 -0
  22. package/dist/api/patient.d.ts +5 -2
  23. package/dist/api/patient.d.ts.map +1 -1
  24. package/dist/api/patient.js +1 -1
  25. package/dist/api/patient.js.map +1 -1
  26. package/dist/api/prescription.d.ts +7 -1
  27. package/dist/api/prescription.d.ts.map +1 -1
  28. package/dist/api/prescription.js +10 -1
  29. package/dist/api/prescription.js.map +1 -1
  30. package/dist/gql/gql.d.ts +11 -3
  31. package/dist/gql/gql.d.ts.map +1 -1
  32. package/dist/gql/gql.js +5 -3
  33. package/dist/gql/gql.js.map +1 -1
  34. package/dist/gql/graphql.d.ts +10507 -1563
  35. package/dist/gql/graphql.d.ts.map +1 -1
  36. package/dist/gql/graphql.js +2984 -435
  37. package/dist/gql/graphql.js.map +1 -1
  38. package/dist/index.d.ts +1 -1
  39. package/dist/index.js +1 -1
  40. package/dist/meta/version.d.ts +2 -0
  41. package/dist/meta/version.d.ts.map +1 -0
  42. package/dist/meta/version.js +2 -0
  43. package/dist/meta/version.js.map +1 -0
  44. package/dist/photon/analytics.d.ts +39 -0
  45. package/dist/photon/analytics.d.ts.map +1 -0
  46. package/dist/photon/analytics.js +91 -0
  47. package/dist/photon/analytics.js.map +1 -0
  48. package/dist/photon/auth.d.ts +9 -5
  49. package/dist/photon/auth.d.ts.map +1 -1
  50. package/dist/photon/auth.js +2 -6
  51. package/dist/photon/auth.js.map +1 -1
  52. package/dist/photon/choices.d.ts +1 -1
  53. package/dist/photon/choices.js +2 -2
  54. package/dist/photon/choices.js.map +1 -1
  55. package/dist/photon/environments.d.ts +2 -1
  56. package/dist/photon/environments.d.ts.map +1 -1
  57. package/dist/photon/environments.js +2 -1
  58. package/dist/photon/environments.js.map +1 -1
  59. package/dist/photon/index.d.ts +6 -3
  60. package/dist/photon/index.d.ts.map +1 -1
  61. package/dist/photon/index.js +2 -1
  62. package/dist/photon/index.js.map +1 -1
  63. package/dist/photon/machine.d.ts +28 -0
  64. package/dist/photon/machine.d.ts.map +1 -0
  65. package/dist/photon/machine.js +53 -0
  66. package/dist/photon/machine.js.map +1 -0
  67. package/dist/photon/map.d.ts +6 -2
  68. package/dist/photon/map.d.ts.map +1 -1
  69. package/dist/photon/map.js +133 -33
  70. package/dist/photon/map.js.map +1 -1
  71. package/dist/photon/order.d.ts +21 -1
  72. package/dist/photon/order.d.ts.map +1 -1
  73. package/dist/photon/order.js +79 -12
  74. package/dist/photon/order.js.map +1 -1
  75. package/dist/photon/orders.d.ts +5 -0
  76. package/dist/photon/orders.d.ts.map +1 -0
  77. package/dist/photon/orders.js +39 -0
  78. package/dist/photon/orders.js.map +1 -0
  79. package/dist/photon/patient.d.ts +8 -6
  80. package/dist/photon/patient.d.ts.map +1 -1
  81. package/dist/photon/patient.js +61 -30
  82. package/dist/photon/patient.js.map +1 -1
  83. package/dist/photon/photon.d.ts +39 -1
  84. package/dist/photon/photon.d.ts.map +1 -1
  85. package/dist/photon/photon.js +85 -5
  86. package/dist/photon/photon.js.map +1 -1
  87. package/dist/photon/prescription.d.ts +17 -4
  88. package/dist/photon/prescription.d.ts.map +1 -1
  89. package/dist/photon/prescription.js +48 -11
  90. package/dist/photon/prescription.js.map +1 -1
  91. package/dist/photon/session.d.ts +15 -10
  92. package/dist/photon/session.d.ts.map +1 -1
  93. package/dist/photon/session.js +5 -3
  94. package/dist/photon/session.js.map +1 -1
  95. package/dist/photon/types.d.ts +278 -46
  96. package/dist/photon/types.d.ts.map +1 -1
  97. package/dist/test-utils/msw.d.ts +2 -2
  98. package/dist/test-utils/msw.d.ts.map +1 -1
  99. package/dist/test-utils/msw.js +5 -5
  100. package/dist/test-utils/msw.js.map +1 -1
  101. package/dist/testing/{scriptedClient.d.ts → fakeNetworkApiClient.d.ts} +5 -4
  102. package/dist/testing/fakeNetworkApiClient.d.ts.map +1 -0
  103. package/dist/testing/{scriptedClient.js → fakeNetworkApiClient.js} +8 -4
  104. package/dist/testing/fakeNetworkApiClient.js.map +1 -0
  105. package/dist/testing/fixtures.d.ts +1047 -0
  106. package/dist/testing/fixtures.d.ts.map +1 -1
  107. package/dist/testing/fixtures.js +47 -13
  108. package/dist/testing/fixtures.js.map +1 -1
  109. package/dist/testing.d.ts +4 -4
  110. package/dist/testing.d.ts.map +1 -1
  111. package/dist/testing.js +4 -4
  112. package/dist/testing.js.map +1 -1
  113. package/package.json +2 -2
  114. package/src/analytics/lifecycleEvents.test.ts +417 -0
  115. package/src/analytics/lifecycleEvents.ts +155 -0
  116. package/src/api/client.ts +71 -46
  117. package/src/api/index.ts +2 -0
  118. package/src/api/me.ts +7 -0
  119. package/src/api/orders.ts +8 -0
  120. package/src/api/patient.ts +11 -2
  121. package/src/api/prescription.ts +18 -0
  122. package/src/gql/gql.ts +21 -9
  123. package/src/gql/graphql.ts +4280 -597
  124. package/src/index.ts +1 -1
  125. package/src/meta/version.test.ts +10 -0
  126. package/src/meta/version.ts +1 -0
  127. package/src/operations/fragments.graphql +166 -20
  128. package/src/operations/me.graphql +38 -0
  129. package/src/operations/orders.graphql +35 -0
  130. package/src/operations/patient.graphql +29 -3
  131. package/src/operations/prescription.graphql +20 -0
  132. package/src/photon/analytics.ts +129 -0
  133. package/src/photon/auth.ts +9 -10
  134. package/src/photon/choices.ts +2 -2
  135. package/src/photon/environments.ts +3 -1
  136. package/src/photon/index.ts +16 -2
  137. package/src/photon/machine.ts +90 -0
  138. package/src/photon/map.ts +151 -35
  139. package/src/photon/order.test.ts +142 -0
  140. package/src/photon/order.ts +92 -12
  141. package/src/photon/orders.ts +42 -0
  142. package/src/photon/patient.ts +73 -33
  143. package/src/photon/photon.ts +139 -6
  144. package/src/photon/prescription.ts +71 -12
  145. package/src/photon/session.ts +18 -9
  146. package/src/photon/types.ts +280 -26
  147. package/src/test-utils/msw.ts +16 -5
  148. package/src/testing/{scriptedClient.ts → fakeNetworkApiClient.ts} +8 -4
  149. package/src/testing/fixtures.ts +55 -13
  150. package/src/testing.ts +6 -3
  151. package/dist/testing/scriptedClient.d.ts.map +0 -1
  152. package/dist/testing/scriptedClient.js.map +0 -1
package/README.md CHANGED
@@ -37,15 +37,19 @@ await order.submit(); // the patient chooses a pharmacy
37
37
 
38
38
  ## The instance and auth
39
39
 
40
- `photon({ environment, auth, organization?, appUrl? })` returns an instance. Every URL is inferred from
40
+ `photon({ environment, auth, organization?, appUrl?, disableAnalytics? })` returns an instance. Every URL is inferred from
41
41
  `environment`: `neutron` (sandbox) or `photon` (production). `auth` is one of:
42
42
 
43
43
  - **`{ clientId }`**: the client signs the prescriber in, in the browser (Auth0 authorization code with PKCE).
44
44
  `ph.session` is a live object with `status`, `user`, `start()`, `signIn()` and `signOut()`. The access token stays
45
45
  in memory; `localStorage` keeps the refresh token so a reload signs back in. A script on your page can read that
46
46
  refresh token, so treat XSS on the page as a token leak. Auth0's refresh token rotation is the guard.
47
- - **`{ getToken: () => Promise<string> }`**: you sign the prescriber in yourself. The client calls it before each
48
- request. `ph.session` is `null`.
47
+ - **`{ getToken: () => Promise<string> }`**: the host supplies a token accepted by network-api, including a
48
+ patient token for patient-authorized reads and writes. The client calls it before each request. `ph.session` is `null`.
49
+ - **`{ clientId, clientSecret, organizationId }`**: your backend's own credentials, the machine (M2M) client Photon
50
+ made for your organization. The client gets a token by client credentials, keeps it until shortly before it
51
+ expires, and gets a new one if network-api refuses it. Servers only: `photon()` throws if a client secret is
52
+ passed in a browser. A token for another organization than `organizationId` is refused (`unauthorized`).
49
53
 
50
54
  An instance built on a person's token is for that person. On a server, make one per request, never at module level.
51
55
  `ph.ping()` checks the token without touching a record.
@@ -74,6 +78,147 @@ An instance built on a person's token is for that person. On a server, make one
74
78
  methods (`rx.sign()`, `order.submit()`, …). An instance holds one object per record: the same patient opened twice,
75
79
  or through an order, is the same object.
76
80
 
81
+ An order's record exposes `fulfillment`: its pharmacy-reported `state`, routing `history` (oldest first),
82
+ `routability` (`allowed` and a blocking `reason`), and open `exceptions`. Fulfillment is `null` for drafts or when
83
+ it couldn't be read. Its state is `null` until reported, and routability is `null` when it couldn't be determined;
84
+ routability reflects the order's state only, not organization settings.
85
+
86
+ A new order looks for its patient's draft orders once it has the patient, before any prescription on it has a
87
+ record (the read-only `Orders` query, once per patient). One draft is `order.snapshot.draft`: nothing is saved until
88
+ the prescriber decides. `order.continueDraft()` makes the order that draft. `order.startNew()` takes the draft's
89
+ prescriptions off it (not canceled) and starts over on it: network-api continues a patient's draft whenever an order is
90
+ saved, so an emptied draft is how a new order starts. Several drafts are `candidates`, picked with `order.pick(id)`.
91
+
92
+ In client 0.8.0, `order.state.exceptions` moves to `order.state.fulfillment.exceptions`. Use
93
+ `order.state?.fulfillment?.exceptions ?? []` when rendering exceptions. React 0.3.0 supports this contract.
94
+
95
+ ## Read orders and pharmacy choices
96
+
97
+ `ph.orders(input?)` calls network-api's read-only `Orders` query. It returns
98
+ `{ orders, candidates, reason }`: order **snapshots**, or patient candidates when a patient filter is ambiguous.
99
+ It does not open, refresh or subscribe live objects, read prescriptions separately, or assign a pharmacy.
100
+
101
+ ```ts
102
+ const ph = photon({ environment: "boson", auth: { getToken: async () => patientToken } });
103
+ const result = await ph.orders({
104
+ filter: { state: "SUBMITTED" }, // patient tokens are scoped to their own patient by the server
105
+ limit: 25,
106
+ routablePharmacies: {
107
+ pharmacy: { near: { address: { postalCode: "10001" } }, fulfillmentType: "PICK_UP" },
108
+ page: { limit: 20, offset: 0 },
109
+ },
110
+ });
111
+ const record = result.orders[0];
112
+ const page = record?.routablePharmacies;
113
+ const option = page?.options[0];
114
+ // After the patient explicitly chooses:
115
+ if (record && option?.pharmacy) {
116
+ await ph.order.update(record.id, { pharmacy: { pharmacy: { id: option.pharmacy.id } } });
117
+ }
118
+ ```
119
+
120
+ Omit `routablePharmacies` to skip the search. Pass `{}` to read marketplace choices. A sole match remains an
121
+ option: only an explicit write assigns it. Pages carry `options`, `totalCount` and `nextOffset`; sponsored additions
122
+ are excluded from `totalCount`. Keep the same search arguments when paging and restart at offset zero when they
123
+ change. `ChangeOption.matchReasons[].value` preserves distance as `{ displayValue, value, unit }`.
124
+
125
+ Order filters accept `id`, `patient` (id or demographic reference) and `state`; every supplied filter must match.
126
+ Read a specific order with `ph.orders({ filter: { id: "ord_…" }, routablePharmacies: {} })`, including its pharmacy
127
+ choices. An id with no order in the caller's scope returns an empty `orders` array. ID filtering is available in
128
+ client 0.9.1.
129
+
130
+ Results are newest first, default to 25 and cap at 100. The backend has no order-list pagination.
131
+ `ph.order.get(id)` still uses the id-only `GetOrder` mutation. Pharmacy searches through `sync` or `update` retain
132
+ their existing behavior and can assign a sole match.
133
+
134
+ ## Shop records and preferred pharmacy
135
+
136
+ - `PrescriptionRecord.prescriber`: the assigned prescriber's id and structured name, or `null`. It does not attest
137
+ who signed. `fulfillment` carries state, `pharmacyEstimatedReadyAt` and unresolved prescription exceptions.
138
+ - `Pharmacy`: `logo`, `phone`, `hours`, `isOpen`, and `nextEvents`, all nullable when unknown. Hours include an IANA
139
+ timezone. Events are `{ type: "open" | "close", datetime }` or `{ type: "24hr" }`; keep serialized instants for
140
+ conversion to the viewer's timezone.
141
+ - `OrderRecord.organization`: customer identity and branding/patient UX settings, or `null` if unavailable.
142
+ `enablePatientRerouting` is separate from the order's routability. `enableAutomatedOps` is the backend's support
143
+ behavior setting. There is no featured-pharmacy setting in this contract.
144
+ - `PharmacyOffer`: **one price, one source, one prescription**. A source pricing a two-drug order reports two
145
+ offers, each with its own `prescriptionId`, `priceType`, `price` (`amount`, `retailAmount`, `promotions`),
146
+ `deliveryEstimate` and discount card. Nothing on it is a per-pharmacy total.
147
+ - **Totals and ranking are the caller's.** network-api supplies no rank, and this package deliberately ships
148
+ no rollup: aggregation is display policy and belongs with the screen that renders it. When you do sum,
149
+ group by `source` + `priceType` first — mixing price types or sources gives a number no patient can pay —
150
+ and sum only over the offers that quote the field you are summing. `amount` and `retailAmount` can cover
151
+ different prescriptions, so a savings figure derived from two independent sums can come out negative.
152
+ - A source mints **one card per prescription**, so a two-drug order carries two cards from the same source;
153
+ render per drug rather than one card for the order.
154
+ - `OrderRecord.offers.atPharmacy`: the offers priced at the pharmacy this order is routed to — `null` until one
155
+ is chosen, `[]` when one is chosen but nothing applies. Each offer carries `redemptionMethods`: what the patient
156
+ presents at the counter, tagged `{ type: "discountCard", bin, pcn, group, memberId, externalUrl }`. Read
157
+ `redemptionState` before treating an empty list as "nothing to present" — only `SETTLED` means final.
158
+ `SKIPPED` means nothing was attempted and none is coming; `PENDING` means one may still arrive, which is
159
+ what a pharmacy search reports for a discount-card source, since the card is minted when the order routes
160
+ there.
161
+ - `Change.after`: the resolved choice with its pharmacy and offers, including when a mutation applies a match
162
+ immediately. `resolvedId` remains available. Order reads and pharmacy options preserve any offers the backend
163
+ returns; the SDK does not manufacture pricing when the backend returns none.
164
+
165
+ Save a preferred pharmacy with `ph.patient.update(patientId, { preferredPharmacy: { id } })`.
166
+ A pharmacy reference can also use a name or location. Ambiguous results remain choices; pass a selected option
167
+ to `patient.choose(option)`. The saved value is `patient.state.preferredPharmacy`.
168
+
169
+ Client 0.9.0 adds required nullable fields to record types and `after` to `Change`; hosts constructing typed test
170
+ records should update them or use the fixtures in `@photonhealth/client/testing`. React 0.4.0 takes client `^0.9.0`.
171
+ Coupon/discount-card details (TECH-1171) will follow in a later release.
172
+
173
+ ## Analytics
174
+
175
+ `ph.analytics.track(event, properties)` sends one event to Photon's analytics (`analytics-api.<env>.health`) as the
176
+ signed-in prescriber, with their token:
177
+
178
+ ```ts
179
+ await ph.analytics?.track("Order Sent", { orderId: order.id, integration: "mcp" });
180
+ ```
181
+
182
+ - Each event carries `providerId` (the prescriber's `usr_` id, asked of network-api once per signed-in user), `orgId`,
183
+ `environment`, `clientName`, `clientVersion` and `timestamp`. Your properties can set `timestamp` and add their own,
184
+ but `providerId`, `orgId` and `environment` always come from the instance.
185
+ - An instance made with `source: "MCP_CONNECTOR"` tags every event `integration: "mcp"`. An event's own `integration`
186
+ property wins (React's cards send `"react"`).
187
+ - **Never PHI.** Send ids, enums, booleans, counts and durations, never what a prescriber or patient typed. An event is
188
+ dropped unless its name is Title Case and every value is a string of at most 128 characters, a number, a boolean,
189
+ `null`, or a list of at most 50 such strings (ids, e.g. an order's `prescriptionIds`). These checks catch mistakes, not abuse.
190
+ - `track` never throws and never rejects. It resolves once the event is sent, or once it's dropped (the token isn't a
191
+ prescriber's, network-api can't say who they are, or analytics-api fails). Await it, or don't.
192
+ - `ph.analytics` is `null` for M2M credentials, without an `environment`, and with `photon({ disableAnalytics: true })`.
193
+ Analytics is on by default.
194
+
195
+ ### Lifecycle events
196
+
197
+ `ph.analytics` sends the prescribing milestones by name, so every surface (React, MCP, Node) sends the same events and
198
+ properties as `<photon-prescribe-workflow>`. Each method takes the record and derives every property from ids, counts
199
+ and which fields are filled, never their values. Like `track`, each never rejects:
200
+
201
+ ```ts
202
+ await ph.analytics?.orderSent(order.state!);
203
+ await ph.analytics?.orderSent(order.state!, { sessionId });
204
+ ```
205
+
206
+ A surface's own properties (the last argument) ride along, but never replace what the record says.
207
+
208
+ Each method takes only the fields it reads (`PatientForLifecycleAnalytics`, `DraftPrescriptionForLifecycleAnalytics`, `PrescriptionForLifecycleAnalytics`,
209
+ `OrderForLifecycleAnalytics`), so a core record fits, and so does a surface's own record type with those fields.
210
+
211
+ | Method | Event | Properties (all `category: "ctaClicked"`) |
212
+ | ------------------------------------------------ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------- |
213
+ | `patientCreated(patient)` | Patient Created | `patientId`, `snap_*` for each patient form field |
214
+ | `patientUpdated(patient)` | Patient Updated | `patientId`, `snap_*` |
215
+ | `draftPrescriptionAdded(prescription, source)` | Draft Prescription Added | `prescriptionId`, `draftPrescriptionSource`, `snap_*` |
216
+ | `draftPrescriptionDeleted(prescriptionId)` | Draft Prescription Deleted | `prescriptionId` |
217
+ | `screeningAlertAcknowledged(alerts, buttonText)` | Screening Alert Acknowledged | `screeningAlertCount`, `buttonText` |
218
+ | `screeningAlertCanceled(alerts, buttonText)` | Screening Alert Canceled | `screeningAlertCount`, `buttonText` |
219
+ | `prescriptionSigned(prescription)` | Prescription Signed | `prescriptionId` |
220
+ | `orderSent(order)` | Order Sent | `orderId`, `prescriptionCount`, `prescriptionIds`, `fulfillmentType` (`SEND_TO_PATIENT` when the patient chooses) |
221
+
77
222
  ## Errors
78
223
 
79
224
  Anything the server answers about the data is a result, not an exception. Only failures that different data can't
@@ -82,8 +227,8 @@ fix throw a `PhotonError`, with `kind`: `network` (retryable), `unauthorized`, `
82
227
 
83
228
  ## Testing
84
229
 
85
- `@photonhealth/client/testing` is for your own tests: `photonOver(scriptedClient(...))` is an instance over a
86
- scripted network client, with fixtures (`patient`, `rx`, `order`, …) to script it with. It may change before 2.0.0.
230
+ `@photonhealth/client/testing` is for your own tests: `photonOver(fakeNetworkApiClient(...))` is an instance over a
231
+ fake network-api client, with fixtures (`patient`, `rx`, `order`, …) to script it with. It may change before 2.0.0.
87
232
 
88
233
  ## License
89
234
 
@@ -0,0 +1,29 @@
1
+ import type { AnalyticsProperties } from "../photon/analytics.ts";
2
+ import type { OrderRecord, PatientRecord, PrescriptionRecord, ScreeningAlert } from "../photon/types.ts";
3
+ export type LifecycleEventName = "Patient Created" | "Patient Updated" | "Draft Prescription Added" | "Draft Prescription Deleted" | "Screening Alert Acknowledged" | "Screening Alert Canceled" | "Prescription Signed" | "Order Sent";
4
+ export type DraftPrescriptionSource = "form" | "template_prefill" | "prescription_id_prefill";
5
+ export type PatientForLifecycleAnalytics = Pick<PatientRecord, "id" | "demographic" | "contact" | "preferredPharmacy">;
6
+ export type DraftPrescriptionForLifecycleAnalytics = Pick<PrescriptionRecord, "id" | "treatment" | "dispense" | "instructions"> & {
7
+ clinical: {
8
+ notes: string | null;
9
+ } | null;
10
+ };
11
+ export type PrescriptionForLifecycleAnalytics = Pick<PrescriptionRecord, "id">;
12
+ export type OrderForLifecycleAnalytics = Pick<OrderRecord, "id"> & {
13
+ prescriptions: readonly PrescriptionForLifecycleAnalytics[];
14
+ pharmacy: Pick<NonNullable<OrderRecord["pharmacy"]>, "fulfillmentType"> | null;
15
+ };
16
+ export interface LifecycleAnalytics {
17
+ patientCreated(patient: PatientForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
18
+ patientUpdated(patient: PatientForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
19
+ draftPrescriptionAdded(prescription: DraftPrescriptionForLifecycleAnalytics, source: DraftPrescriptionSource, properties?: AnalyticsProperties): Promise<void>;
20
+ draftPrescriptionDeleted(prescriptionId: string, properties?: AnalyticsProperties): Promise<void>;
21
+ screeningAlertAcknowledged(alerts: readonly ScreeningAlert[], buttonText: string, properties?: AnalyticsProperties): Promise<void>;
22
+ screeningAlertCanceled(alerts: readonly ScreeningAlert[], buttonText: string, properties?: AnalyticsProperties): Promise<void>;
23
+ prescriptionSigned(prescription: PrescriptionForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
24
+ orderSent(order: OrderForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
25
+ }
26
+ type Track = (event: string, properties?: AnalyticsProperties) => Promise<void>;
27
+ export declare function lifecycleAnalyticsSentWith(track: Track): LifecycleAnalytics;
28
+ export {};
29
+ //# sourceMappingURL=lifecycleEvents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycleEvents.d.ts","sourceRoot":"","sources":["../../src/analytics/lifecycleEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzG,MAAM,MAAM,kBAAkB,GAC1B,iBAAiB,GACjB,iBAAiB,GACjB,0BAA0B,GAC1B,4BAA4B,GAC5B,8BAA8B,GAC9B,0BAA0B,GAC1B,qBAAqB,GACrB,YAAY,CAAC;AAEjB,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG,kBAAkB,GAAG,yBAAyB,CAAC;AAE9F,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,aAAa,GAAG,SAAS,GAAG,mBAAmB,CAAC,CAAC;AAEvH,MAAM,MAAM,sCAAsC,GAAG,IAAI,CACvD,kBAAkB,EAClB,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,cAAc,CACjD,GAAG;IACF,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;AAE/E,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG;IACjE,aAAa,EAAE,SAAS,iCAAiC,EAAE,CAAC;IAC5D,QAAQ,EAAE,IAAI,CAAC,WAAW,C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AK,EAAE,KAAK,GAAG,kBAAkB,CAwC3E"}
@@ -0,0 +1,72 @@
1
+ const SEND_TO_PATIENT = "SEND_TO_PATIENT";
2
+ export function lifecycleAnalyticsSentWith(track) {
3
+ const sendCtaClicked = (event, derivedProperties, callerProperties = {}) => track(event, { ...callerProperties, category: "ctaClicked", ...derivedProperties });
4
+ return {
5
+ patientCreated: (patient, properties) => sendCtaClicked("Patient Created", patientProperties(patient), properties),
6
+ patientUpdated: (patient, properties) => sendCtaClicked("Patient Updated", patientProperties(patient), properties),
7
+ draftPrescriptionAdded: (prescription, source, properties) => sendCtaClicked("Draft Prescription Added", {
8
+ prescriptionId: prescription.id,
9
+ draftPrescriptionSource: source,
10
+ ...prescriptionFormSnapshot(prescription),
11
+ }, properties),
12
+ draftPrescriptionDeleted: (prescriptionId, properties) => sendCtaClicked("Draft Prescription Deleted", { prescriptionId }, properties),
13
+ screeningAlertAcknowledged: (alerts, buttonText, properties) => sendCtaClicked("Screening Alert Acknowledged", { screeningAlertCount: alerts.length, buttonText }, properties),
14
+ screeningAlertCanceled: (alerts, buttonText, properties) => sendCtaClicked("Screening Alert Canceled", { screeningAlertCount: alerts.length, buttonText }, properties),
15
+ prescriptionSigned: (prescription, properties) => sendCtaClicked("Prescription Signed", { prescriptionId: prescription.id }, properties),
16
+ orderSent: (order, properties) => sendCtaClicked("Order Sent", {
17
+ orderId: order.id,
18
+ prescriptionCount: order.prescriptions.length,
19
+ prescriptionIds: order.prescriptions.map((prescription) => prescription.id),
20
+ fulfillmentType: fulfillmentTypeOf(order),
21
+ }, properties),
22
+ };
23
+ }
24
+ function patientProperties(patient) {
25
+ return { patientId: patient.id, ...patientFormSnapshot(patient) };
26
+ }
27
+ function fulfillmentTypeOf(order) {
28
+ if (!order.pharmacy)
29
+ return SEND_TO_PATIENT;
30
+ const offeredTypes = order.pharmacy.fulfillmentType ?? [];
31
+ return offeredTypes.length === 1 ? offeredTypes[0] : null;
32
+ }
33
+ function patientFormSnapshot(patient) {
34
+ const { demographic, contact, preferredPharmacy } = patient;
35
+ return completedFieldSnapshot({
36
+ firstName: demographic?.name.first,
37
+ lastName: demographic?.name.last,
38
+ dateOfBirth: demographic?.dateOfBirth,
39
+ phone: contact?.phone,
40
+ sex: demographic?.sex,
41
+ gender: demographic?.gender,
42
+ email: contact?.email,
43
+ address_street1: contact?.address?.street1,
44
+ address_street2: contact?.address?.street2,
45
+ address_city: contact?.address?.city,
46
+ address_state: contact?.address?.state,
47
+ address_zip: contact?.address?.postalCode,
48
+ preferredPharmacy,
49
+ });
50
+ }
51
+ function prescriptionFormSnapshot(prescription) {
52
+ const { treatment, dispense, instructions, clinical } = prescription;
53
+ return completedFieldSnapshot({
54
+ treatment,
55
+ dispenseQuantity: dispense?.quantity,
56
+ dispenseUnit: dispense?.unit,
57
+ daysSupply: dispense?.daysSupply,
58
+ refills: dispense?.refillsAllowed,
59
+ instructions,
60
+ notes: clinical?.notes,
61
+ });
62
+ }
63
+ function completedFieldSnapshot(valuesByFieldName) {
64
+ return Object.fromEntries(Object.entries(valuesByFieldName).map(([fieldName, value]) => [snapshotPropertyName(fieldName), isFilled(value)]));
65
+ }
66
+ function snapshotPropertyName(fieldName) {
67
+ return `snap_${fieldName.replace(/([A-Z])/g, "_$1").toLowerCase()}`;
68
+ }
69
+ function isFilled(value) {
70
+ return value !== undefined && value !== null && value !== "" && value !== false;
71
+ }
72
+ //# sourceMappingURL=lifecycleEvents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycleEvents.js","sourceRoot":"","sources":["../../src/analytics/lifecycleEvents.ts"],"names":[],"mappings":"AAwDA,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAE1C,MAAM,UAAU,0BAA0B,CAAC,KAAY;IACrD,MAAM,cAAc,GAAG,CACrB,KAAyB,EACzB,iBAAsC,EACtC,mBAAwC,EAAE,EAC1C,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,GAAG,gBAAgB,EAAE,QAAQ,EAAE,YAAY,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graphql.ts";
9
9
  interface NetworkClientOptions {
10
10
  /** e.g. https://network.boson.health/graphql */
11
11
  url: string;
12
- /** Returns an Auth0 access token for the prescriber (audience https://api.<env>.health). */
12
+ /** Returns a token accepted by network-api, including a patient token or a prescriber's access token. */
13
13
  getToken: () => Promise<string>;
14
14
  /** How this client is surfaced. Embeds should pass EMBEDDABLE_COMPONENT. */
15
15
  source?: RequestSource;
@@ -17,6 +17,11 @@ interface NetworkClientOptions {
17
17
  clientName?: string;
18
18
  sourceVersion?: string;
19
19
  fetch?: typeof fetch;
20
+ /**
21
+ * When network-api refuses the token (401, UNAUTHENTICATED): drop it — the call is then tried once more, with a new one. For a
22
+ * token core gets itself (client credentials); a host's `getToken` or a prescriber's session doesn't retry.
23
+ */
24
+ onUnauthorized?: () => void;
20
25
  }
21
26
  /** Variables for an operation, minus the metadata the client fills in. */
22
27
  export type OperationVariables<V> = Omit<V, "metadata">;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D;;;;;GAKG;AAEH,UAAU,oBAAoB;IAC5B,gDAAgD;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,4FAA4F;IAC5F,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,4EAA4E;IAC5E,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,kGAAkG;IAClG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,0EAA0E;AAC1E,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AAExD,MAAM,WAAW,aA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EAAE,oBAAoB,GAAG,aAAa,CA2EhF"}
@@ -36,42 +36,56 @@ export function createNetworkClient(options) {
36
36
  // like MSW's, a polyfill) is the one used.
37
37
  const doFetch = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
38
38
  const clientName = options.clientName ?? "photon-rx";
39
- return {
39
+ const client = {
40
40
  async execute(document, variables, { signal } = {}) {
41
- const operationName = operationNameOf(document);
42
- const metadata = {
43
- source: options.source ?? "WEB_APP",
44
- client: `${clientName}/${operationName}`,
45
- sourceVersion: options.sourceVersion,
46
- requestId: requestId(),
47
- };
48
- const token = await options.getToken();
49
- const response = await doFetch(options.url, {
50
- method: "POST",
51
- signal,
52
- headers: {
53
- "content-type": "application/json",
54
- accept: "application/graphql-response+json, application/json",
55
- // Standard Bearer (network-api also still takes x-photon-auth-token). CORS allows only
56
- // Authorization, Content-Type and x-photon-auth-token — any other custom header fails preflight.
57
- authorization: `Bearer ${token}`,
58
- },
59
- body: JSON.stringify({
60
- operationName,
61
- query: document.toString(),
62
- // Every mutation takes RequestMetadata; queries (Ping) just ignore it.
63
- variables: document.toString().includes("$metadata")
64
- ? { ...trimStrings(variables), metadata }
65
- : trimStrings(variables),
66
- }),
67
- });
68
- const body = (await response.json().catch(() => null));
69
- if (body?.errors?.length || !body?.data) {
70
- const first = body?.errors?.[0];
71
- throw new NetworkTransportError(first?.message ?? `network-api responded ${response.status}`, operationName, response.status, first?.extensions?.code, body?.errors);
41
+ try {
42
+ return await once(document, variables, signal);
43
+ }
44
+ catch (e) {
45
+ if (!options.onUnauthorized ||
46
+ !(e instanceof NetworkTransportError) ||
47
+ (e.status !== 401 && e.code !== "UNAUTHENTICATED"))
48
+ throw e;
49
+ options.onUnauthorized();
50
+ return once(document, variables, signal);
72
51
  }
73
- return body.data;
74
52
  },
75
53
  };
54
+ return client;
55
+ async function once(document, variables, signal) {
56
+ const operationName = operationNameOf(document);
57
+ const metadata = {
58
+ source: options.source ?? "WEB_APP",
59
+ client: `${clientName}/${operationName}`,
60
+ sourceVersion: options.sourceVersion,
61
+ requestId: requestId(),
62
+ };
63
+ const token = await options.getToken();
64
+ const response = await doFetch(options.url, {
65
+ method: "POST",
66
+ signal,
67
+ headers: {
68
+ "content-type": "application/json",
69
+ accept: "application/graphql-response+json, application/json",
70
+ // Standard Bearer (network-api also still takes x-photon-auth-token). CORS allows only
71
+ // Authorization, Content-Type and x-photon-auth-token — any other custom header fails preflight.
72
+ authorization: `Bearer ${token}`,
73
+ },
74
+ body: JSON.stringify({
75
+ operationName,
76
+ query: document.toString(),
77
+ // Every mutation takes RequestMetadata; queries (Ping) just ignore it.
78
+ variables: document.toString().includes("$metadata")
79
+ ? { ...trimStrings(variables), metadata }
80
+ : trimStrings(variables),
81
+ }),
82
+ });
83
+ const body = (await response.json().catch(() => null));
84
+ if (body?.errors?.length || !body?.data) {
85
+ const first = body?.errors?.[0];
86
+ throw new NetworkTransportError(first?.message ?? `network-api responded ${response.status}`, operationName, response.status, first?.extensions?.code, body?.errors);
87
+ }
88
+ return body.data;
89
+ }
76
90
  }
77
91
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAkCA,oFAAoF;AACpF,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAGnC;IACA;IACA;IACA;IALX,YACE,OAAe,EACN,aAAqB,EACrB,MAAe,EACf,IAAa,EACb,MAAkB;QAE3B,KAAK,CAAC,OAAO,CAAC,CAAC;QALN,kBAAa,GAAb,aAAa,CAAQ;QACrB,WAAM,GAAN,MAAM,CAAS;QACf,SAAI,GAAJ,IAAI,CAAS;QACb,WAAM,GAAN,MAAM,CAAY;QAG3B,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,cAAc,GAAG,8DAA8D,CAAC;AAEtF,MAAM,UAAU,eAAe,CAAC,QAAgC;IAC9D,OAAO,cAAc,CAAC,IAAI,CAAC,QAAQ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AC,IAAI,EAAE,IAAI,EAAE,CAAC;YACxC,MAAM,KAAK,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;YAChC,MAAM,IAAI,qBAAqB,CAC7B,KAAK,EAAE,OAAO,IAAI,yBAAyB,QAAQ,CAAC,MAAM,EAAE,EAC5D,aAAa,EACb,QAAQ,CAAC,MAAM,EACf,KAAK,EAAE,UAAU,EAAE,IAAI,EACvB,IAAI,EAAE,MAAM,CACb,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,IAAa,CAAC;IAC5B,CAAC;AACH,CAAC"}
@@ -14,9 +14,11 @@
14
14
  export * from "./client.ts";
15
15
  export * from "./results.ts";
16
16
  export * from "./health.ts";
17
+ export * from "./me.ts";
17
18
  export * from "./patient.ts";
18
19
  export * from "./prescription.ts";
19
20
  export * from "./order.ts";
21
+ export * from "./orders.ts";
20
22
  export * from "./changes/index.ts";
21
23
  export type * from "../gql/graphql.ts";
22
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AAEnC,mBAAmB,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AAEnC,mBAAmB,mBAAmB,CAAC"}
package/dist/api/index.js CHANGED
@@ -14,8 +14,10 @@
14
14
  export * from "./client.js";
15
15
  export * from "./results.js";
16
16
  export * from "./health.js";
17
+ export * from "./me.js";
17
18
  export * from "./patient.js";
18
19
  export * from "./prescription.js";
19
20
  export * from "./order.js";
21
+ export * from "./orders.js";
20
22
  export * from "./changes/index.js";
21
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { NetworkClient } from "./client.ts";
2
+ export declare function me(client: NetworkClient): Promise<{
3
+ __typename: "Machine";
4
+ permissions: Array<string>;
5
+ organization: {
6
+ __typename: "OperationError";
7
+ } | {
8
+ __typename: "Organization";
9
+ id: string;
10
+ name: string;
11
+ };
12
+ } | {
13
+ __typename: "Patient";
14
+ id: string;
15
+ name: {
16
+ __typename: "HumanName";
17
+ first: string | null;
18
+ last: string | null;
19
+ };
20
+ } | {
21
+ __typename: "User";
22
+ id: string;
23
+ permissions: Array<string>;
24
+ name: {
25
+ __typename: "HumanName";
26
+ first: string | null;
27
+ last: string | null;
28
+ };
29
+ organization: {
30
+ __typename: "OperationError";
31
+ } | {
32
+ __typename: "Organization";
33
+ id: string;
34
+ name: string;
35
+ };
36
+ }>;
37
+ //# sourceMappingURL=me.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"me.d.ts","sourceRoot":"","sources":["../../src/api/me.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD,wBAAsB,EAAE,CAAC,MAAM,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAE7C"}
package/dist/api/me.js ADDED
@@ -0,0 +1,6 @@
1
+ import { MeDocument } from "../gql/graphql.js";
2
+ import { assertNotOperationError } from "./results.js";
3
+ export async function me(client) {
4
+ return assertNotOperationError((await client.execute(MeDocument, {})).me);
5
+ }
6
+ //# sourceMappingURL=me.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"me.js","sourceRoot":"","sources":["../../src/api/me.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAgB,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,MAAqB;IAC5C,OAAO,uBAAuB,CAAgB,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC3F,CAAC"}