@tellescope/sdk 1.255.5 → 1.255.6

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.
@@ -3,10 +3,12 @@ require('source-map-support').install();
3
3
  import axios from "axios"
4
4
  import { Session } from "../../sdk"
5
5
  import {
6
+ assert,
6
7
  async_test,
7
8
  log_header,
8
9
  wait,
9
10
  } from "@tellescope/testing"
11
+ import { evaluate_conditional_logic_for_enduser_fields } from "@tellescope/utilities"
10
12
  import { setup_tests } from "../setup"
11
13
  import { BUILT_INS_FOR_SET_FIELDS, HEALTHIE_TITLE } from "@tellescope/constants"
12
14
 
@@ -33,6 +35,43 @@ export const healthie_multi_integration_tests = async ({ sdk, sdkNonAdmin } : {
33
35
  }
34
36
  console.log("✅ healthieIntegrationId exposed in BUILT_INS_FOR_SET_FIELDS")
35
37
 
38
+ // ── Conditional logic evaluation (pure — resolves via the generic built-in field fallback) ──
39
+ const conditionPlaceholders = {
40
+ businessId: '', creator: '', hashedPassword: '', lastActive: '', lastLogout: '', updatedAt: new Date(),
41
+ }
42
+ const taggedForConditions = { ...conditionPlaceholders, healthieIntegrationId: TAG } as any
43
+ const untaggedForConditions = { ...conditionPlaceholders } as any
44
+
45
+ assert(
46
+ evaluate_conditional_logic_for_enduser_fields(taggedForConditions, { $and: [{ condition: { healthieIntegrationId: TAG } }] }),
47
+ 'Conditional logic error', 'healthieIntegrationId equality matches a tagged patient',
48
+ )
49
+ assert(
50
+ !evaluate_conditional_logic_for_enduser_fields(taggedForConditions, { $and: [{ condition: { healthieIntegrationId: 'other-clinic' } }] }),
51
+ 'Conditional logic error', 'healthieIntegrationId equality rejects a different id',
52
+ )
53
+ assert(
54
+ !evaluate_conditional_logic_for_enduser_fields(untaggedForConditions, { $and: [{ condition: { healthieIntegrationId: TAG } }] }),
55
+ 'Conditional logic error', 'healthieIntegrationId equality rejects an unset (primary) patient',
56
+ )
57
+ assert(
58
+ evaluate_conditional_logic_for_enduser_fields(taggedForConditions, { $and: [{ condition: { healthieIntegrationId: { $isSet: true } } }] }),
59
+ 'Conditional logic error', 'healthieIntegrationId $isSet matches a tagged patient',
60
+ )
61
+ assert(
62
+ evaluate_conditional_logic_for_enduser_fields(untaggedForConditions, { $and: [{ condition: { healthieIntegrationId: { $isNotSet: true } } }] }),
63
+ 'Conditional logic error', 'healthieIntegrationId $isNotSet matches an unset (primary) patient',
64
+ )
65
+ assert(
66
+ !evaluate_conditional_logic_for_enduser_fields(taggedForConditions, { $and: [{ condition: { healthieIntegrationId: { $ne: TAG } } }] }),
67
+ 'Conditional logic error', 'healthieIntegrationId $ne rejects the matching tag',
68
+ )
69
+ assert(
70
+ evaluate_conditional_logic_for_enduser_fields(untaggedForConditions, { $and: [{ condition: { healthieIntegrationId: { $ne: TAG } } }] }),
71
+ 'Conditional logic error', 'healthieIntegrationId $ne matches an unset (primary) patient',
72
+ )
73
+ console.log("✅ healthieIntegrationId evaluates in conditional logic (equality, $isSet/$isNotSet, $ne)")
74
+
36
75
  // ── Create primary (untagged, sandbox-style key) + additional (tagged, production-style key)
37
76
  // via the standard REST create endpoint — the real creation path for additional connections ──
38
77
  const primary = await sdk.api.integrations.createOne({
@@ -80,6 +119,15 @@ export const healthie_multi_integration_tests = async ({ sdk, sdkNonAdmin } : {
80
119
  { onResult: i => !i.pushAddedTags },
81
120
  )
82
121
 
122
+ // ── Invalid API key surfaces as an actionable 400 (fake key → Healthie rejects the request) ──
123
+ await async_test(
124
+ "proxy_read webhooks with an invalid API key returns a clear error",
125
+ () => sdk.api.integrations.proxy_read({
126
+ integration: HEALTHIE_TITLE, type: 'webhooks', healthieIntegrationId: TAG,
127
+ }),
128
+ { shouldError: true, onError: (e: any) => (e?.message || '').includes('API Key is Invalid') },
129
+ )
130
+
83
131
  // ── Organization.healthieIntegrationIds pushed by create side effect ──
84
132
  await wait(undefined, 2000) // side effects are async
85
133
  await async_test(
@@ -129,21 +177,21 @@ export const healthie_multi_integration_tests = async ({ sdk, sdkNonAdmin } : {
129
177
  // link the patient to Healthie (reference with a Healthie patient id)
130
178
  await sdk.api.endusers.updateOne(enduserId, { references: [{ type: HEALTHIE_TITLE, id: '12345' }] } as any, { replaceObjectFields: true })
131
179
 
180
+ // no lock: linked patients stay editable so customers can self-serve fix or migrate them
132
181
  await async_test(
133
- "healthieIntegrationId locked once a Healthie patient ID exists",
182
+ "healthieIntegrationId changeable while linked (self-serve fix/migrate)",
134
183
  () => sdk.api.endusers.updateOne(enduserId, { healthieIntegrationId: 'somewhere-else' }),
135
- { shouldError: true, onError: (e: any) => (e?.message || e?.toString() || '').includes('healthieIntegrationId') },
184
+ { onResult: e => e.healthieIntegrationId === 'somewhere-else' },
136
185
  )
137
186
  await async_test(
138
- "no-op write of the same value still allowed while locked",
187
+ "healthieIntegrationId revertible while linked",
139
188
  () => sdk.api.endusers.updateOne(enduserId, { healthieIntegrationId: TAG }),
140
189
  { onResult: e => e.healthieIntegrationId === TAG },
141
190
  )
142
191
 
143
- // unlink → changeable again
144
192
  await sdk.api.endusers.updateOne(enduserId, { references: [] } as any, { replaceObjectFields: true })
145
193
  await async_test(
146
- "healthieIntegrationId changeable again after unlinking",
194
+ "healthieIntegrationId clearable",
147
195
  () => sdk.api.endusers.updateOne(enduserId, { healthieIntegrationId: '' }),
148
196
  { onResult: e => !e.healthieIntegrationId },
149
197
  )
@@ -174,7 +222,7 @@ export const healthie_multi_integration_tests = async ({ sdk, sdkNonAdmin } : {
174
222
  }},
175
223
  )
176
224
 
177
- // link the formsort enduser, then attempt a relink via formsort field change must be dropped
225
+ // linked endusers are re-routable via formsort too (self-serve fix/migrate)
178
226
  await sdk.api.endusers.updateOne(formsortEnduserId, { references: [{ type: HEALTHIE_TITLE, id: '6789' }] } as any, { replaceObjectFields: true })
179
227
  await postToFormsort([
180
228
  { key: 'email', value: formsortEmail },
@@ -183,16 +231,9 @@ export const healthie_multi_integration_tests = async ({ sdk, sdkNonAdmin } : {
183
231
  await wait(undefined, 1000)
184
232
 
185
233
  await async_test(
186
- "formsort relink attempt on linked enduser is dropped",
234
+ "formsort updates healthieIntegrationId on a linked enduser",
187
235
  () => sdk.api.endusers.getOne(formsortEnduserId),
188
- { onResult: e => e.healthieIntegrationId === TAG },
189
- )
190
- await async_test(
191
- "formsort relink attempt logs a customer-visible background error",
192
- () => sdk.api.background_errors.getSome(),
193
- { onResult: errors => errors.some(e =>
194
- e.title === "Healthie Integration Change Blocked" && e.enduserId === formsortEnduserId
195
- )},
236
+ { onResult: e => e.healthieIntegrationId === 'somewhere-else' },
196
237
  )
197
238
 
198
239
  // ── Removing the primary must not affect the tagged integration; org list recomputes on delete ──
Binary file